mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Cleanup and overhaul (#21)
* Syntax cleanup * More minor cleanup, use Linq * Fix broken features by using correct values * Feature flags the same * Features are modular * No AlphaFS, more .NET versions * Fix appveyor * Put back identifiers, for some reason * String interpolation, modernization * Better use of GetField * XmlTextWriter to remove possible issues * Fix header for OpenMSX
This commit is contained in:
@@ -1,26 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
#if MONO
|
||||
using System.IO;
|
||||
using Directory = Alphaleonis.Win32.Filesystem.Directory;
|
||||
using PathFormat = Alphaleonis.Win32.Filesystem.PathFormat;
|
||||
#else
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
|
||||
using BinaryReader = System.IO.BinaryReader;
|
||||
using FileStream = System.IO.FileStream;
|
||||
using MemoryStream = System.IO.MemoryStream;
|
||||
using SearchOption = System.IO.SearchOption;
|
||||
using SeekOrigin = System.IO.SeekOrigin;
|
||||
using Stream = System.IO.Stream;
|
||||
#endif
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
/// <summary>
|
||||
@@ -75,7 +61,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Directory.CreateDirectory(this.Filename);
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
Directory.Copy(this.Filename, outDir, true, PathFormat.FullPath);
|
||||
DirectoryCopy(this.Filename, outDir, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -86,6 +72,45 @@ namespace SabreTools.Library.FileTypes
|
||||
return true;
|
||||
}
|
||||
|
||||
// https://docs.microsoft.com/en-us/dotnet/standard/io/how-to-copy-directories
|
||||
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
|
||||
{
|
||||
// Get the subdirectories for the specified directory.
|
||||
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
|
||||
|
||||
if (!dir.Exists)
|
||||
{
|
||||
throw new DirectoryNotFoundException(
|
||||
"Source directory does not exist or could not be found: "
|
||||
+ sourceDirName);
|
||||
}
|
||||
|
||||
DirectoryInfo[] dirs = dir.GetDirectories();
|
||||
// If the destination directory doesn't exist, create it.
|
||||
if (!Directory.Exists(destDirName))
|
||||
{
|
||||
Directory.CreateDirectory(destDirName);
|
||||
}
|
||||
|
||||
// Get the files in the directory and copy them to the new location.
|
||||
FileInfo[] files = dir.GetFiles();
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
string temppath = Path.Combine(destDirName, file.Name);
|
||||
file.CopyTo(temppath, false);
|
||||
}
|
||||
|
||||
// If copying subdirectories, copy them and their contents to new location.
|
||||
if (copySubDirs)
|
||||
{
|
||||
foreach (DirectoryInfo subdir in dirs)
|
||||
{
|
||||
string temppath = Path.Combine(destDirName, subdir.Name);
|
||||
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file from an archive
|
||||
/// </summary>
|
||||
@@ -110,7 +135,7 @@ namespace SabreTools.Library.FileTypes
|
||||
string match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault();
|
||||
|
||||
// If we had a file, copy that over to the new name
|
||||
if (!String.IsNullOrWhiteSpace(match))
|
||||
if (!string.IsNullOrWhiteSpace(match))
|
||||
{
|
||||
realentry = match;
|
||||
File.Copy(match, Path.Combine(outDir, entryName));
|
||||
@@ -149,7 +174,7 @@ namespace SabreTools.Library.FileTypes
|
||||
string match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault();
|
||||
|
||||
// If we had a file, copy that over to the new name
|
||||
if (!String.IsNullOrWhiteSpace(match))
|
||||
if (!string.IsNullOrWhiteSpace(match))
|
||||
{
|
||||
Utilities.TryOpenRead(match).CopyTo(ms);
|
||||
realentry = match;
|
||||
@@ -185,6 +210,7 @@ namespace SabreTools.Library.FileTypes
|
||||
BaseFile nf = Utilities.GetFileInfo(file, omitFromScan: omitFromScan, date: date);
|
||||
_children.Add(nf);
|
||||
}
|
||||
|
||||
foreach (string dir in Directory.EnumerateDirectories(this.Filename, "*", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
Folder fl = new Folder(dir);
|
||||
@@ -285,7 +311,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
if (rom.ItemType == ItemType.Rom)
|
||||
{
|
||||
if (date && !String.IsNullOrWhiteSpace(((Rom)rom).Date))
|
||||
if (date && !string.IsNullOrWhiteSpace(((Rom)rom).Date))
|
||||
{
|
||||
File.SetCreationTime(fileName, DateTime.Parse(((Rom)rom).Date));
|
||||
}
|
||||
|
||||
@@ -1,25 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
#if MONO
|
||||
using System.IO;
|
||||
#else
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
|
||||
using BinaryReader = System.IO.BinaryReader;
|
||||
using BinaryWriter = System.IO.BinaryWriter;
|
||||
using EndOfStreamException = System.IO.EndOfStreamException;
|
||||
using FileStream = System.IO.FileStream;
|
||||
using MemoryStream = System.IO.MemoryStream;
|
||||
using SeekOrigin = System.IO.SeekOrigin;
|
||||
using Stream = System.IO.Stream;
|
||||
#endif
|
||||
using Compress;
|
||||
using Compress.gZip;
|
||||
using Compress.ZipFile.ZLib;
|
||||
@@ -290,21 +277,21 @@ namespace SabreTools.Library.FileTypes
|
||||
// If we have the romba depot files, just skip them gracefully
|
||||
if (datum == ".romba_size" || datum == ".romba_size.backup")
|
||||
{
|
||||
Globals.Logger.Verbose("Romba depot file found, skipping: {0}", this.Filename);
|
||||
Globals.Logger.Verbose($"Romba depot file found, skipping: {this.Filename}");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the name is the right length
|
||||
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz")) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length
|
||||
{
|
||||
Globals.Logger.Warning("Non SHA-1 filename found, skipping: '{0}'", Path.GetFullPath(this.Filename));
|
||||
Globals.Logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the file is at least the minimum length
|
||||
if (filesize < 40 /* bytes */)
|
||||
{
|
||||
Globals.Logger.Warning("Possibly corrupt file '{0}' with size {1}", Path.GetFullPath(this.Filename), Utilities.GetBytesReadable(filesize));
|
||||
Globals.Logger.Warning($"Possibly corrupt file '{Path.GetFullPath(this.Filename)}' with size {Utilities.GetBytesReadable(filesize)}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -357,21 +344,21 @@ namespace SabreTools.Library.FileTypes
|
||||
// If we have the romba depot files, just skip them gracefully
|
||||
if (datum == ".romba_size" || datum == ".romba_size.backup")
|
||||
{
|
||||
Globals.Logger.Verbose("Romba depot file found, skipping: {0}", this.Filename);
|
||||
Globals.Logger.Verbose($"Romba depot file found, skipping: {this.Filename}");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if the name is the right length
|
||||
if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz")) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length
|
||||
{
|
||||
Globals.Logger.Warning("Non SHA-1 filename found, skipping: '{0}'", Path.GetFullPath(this.Filename));
|
||||
Globals.Logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if the file is at least the minimum length
|
||||
if (filesize < 40 /* bytes */)
|
||||
{
|
||||
Globals.Logger.Warning("Possibly corrupt file '{0}' with size {1}", Path.GetFullPath(this.Filename), Utilities.GetBytesReadable(filesize));
|
||||
Globals.Logger.Warning($"Possibly corrupt file '{Path.GetFullPath(this.Filename)}' with size {Utilities.GetBytesReadable(filesize)}");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -439,7 +426,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// Check that the input file exists
|
||||
if (!File.Exists(inputFile))
|
||||
{
|
||||
Globals.Logger.Warning("File '{0}' does not exist!", inputFile);
|
||||
Globals.Logger.Warning($"File '{inputFile}' does not exist!");
|
||||
return false;
|
||||
}
|
||||
inputFile = Path.GetFullPath(inputFile);
|
||||
|
||||
@@ -1,23 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
#if MONO
|
||||
using System.IO;
|
||||
#else
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
|
||||
using BinaryReader = System.IO.BinaryReader;
|
||||
using EndOfStreamException = System.IO.EndOfStreamException;
|
||||
using FileStream = System.IO.FileStream;
|
||||
using MemoryStream = System.IO.MemoryStream;
|
||||
using SeekOrigin = System.IO.SeekOrigin;
|
||||
using Stream = System.IO.Stream;
|
||||
#endif
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Rar;
|
||||
using SharpCompress.Readers;
|
||||
|
||||
@@ -1,23 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
#if MONO
|
||||
using System.IO;
|
||||
#else
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
|
||||
using BinaryWriter = System.IO.BinaryWriter;
|
||||
using EndOfStreamException = System.IO.EndOfStreamException;
|
||||
using FileStream = System.IO.FileStream;
|
||||
using MemoryStream = System.IO.MemoryStream;
|
||||
using SeekOrigin = System.IO.SeekOrigin;
|
||||
using Stream = System.IO.Stream;
|
||||
#endif
|
||||
using Compress;
|
||||
using Compress.SevenZip;
|
||||
using Compress.ZipFile;
|
||||
@@ -85,10 +73,8 @@ namespace SabreTools.Library.FileTypes
|
||||
zr = zf.ZipFileOpenReadStream(i, out Stream readStream, out ulong streamsize);
|
||||
|
||||
// Create the rest of the path, if needed
|
||||
if (!String.IsNullOrWhiteSpace(Path.GetDirectoryName(zf.Filename(i))))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(Path.GetDirectoryName(zf.Filename(i))))
|
||||
Directory.CreateDirectory(Path.Combine(outDir, Path.GetDirectoryName(zf.Filename(i))));
|
||||
}
|
||||
|
||||
// If the entry ends with a directory separator, continue to the next item, if any
|
||||
if (zf.Filename(i).EndsWith(Path.DirectorySeparatorChar.ToString())
|
||||
@@ -304,7 +290,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// If we get a read error, log it and continue
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
{
|
||||
Globals.Logger.Warning("An error occurred while reading archive {0}: Zip Error - {1}", this.Filename, zr);
|
||||
Globals.Logger.Warning($"An error occurred while reading archive {this.Filename}: Zip Error - {zr}");
|
||||
zr = zf.ZipFileCloseReadStream();
|
||||
continue;
|
||||
}
|
||||
@@ -446,7 +432,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool romba = false)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, "tmp" + Guid.NewGuid().ToString());
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either input is null or empty, return
|
||||
if (inputStream == null || rom == null || rom.Name == null)
|
||||
@@ -464,7 +450,7 @@ namespace SabreTools.Library.FileTypes
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(rom.MachineName) + (rom.MachineName.EndsWith(".zip") ? "" : ".zip"));
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(rom.MachineName) + (rom.MachineName.EndsWith(".zip") ? string.Empty : ".zip"));
|
||||
|
||||
// Set internal variables
|
||||
Stream writeStream = null;
|
||||
@@ -490,7 +476,7 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(inputStream.Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (date && !String.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
if (date && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, 0, msDosDateTime, out writeStream);
|
||||
@@ -565,7 +551,7 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(inputStream.Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (date && !String.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
if (date && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, 0, msDosDateTime, out writeStream);
|
||||
@@ -648,7 +634,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, "tmp" + Guid.NewGuid().ToString());
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either list of roms is null or empty, return
|
||||
if (inputFiles == null || roms == null || inputFiles.Count == 0 || roms.Count == 0)
|
||||
@@ -672,7 +658,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(roms[0].MachineName) + (roms[0].MachineName.EndsWith(".zip") ? "" : ".zip"));
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(roms[0].MachineName) + (roms[0].MachineName.EndsWith(".zip") ? string.Empty : ".zip"));
|
||||
|
||||
// Set internal variables
|
||||
Stream writeStream = null;
|
||||
@@ -715,7 +701,7 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[index]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (date && !String.IsNullOrWhiteSpace(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out dt))
|
||||
if (date && !string.IsNullOrWhiteSpace(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, roms[index].Name.Replace('\\', '/'), istreamSize, 0, msDosDateTime, out writeStream);
|
||||
@@ -798,7 +784,7 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[-index - 1]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (date && !String.IsNullOrWhiteSpace(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out dt))
|
||||
if (date && !string.IsNullOrWhiteSpace(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, roms[-index - 1].Name.Replace('\\', '/'), istreamSize, 0, msDosDateTime, out writeStream);
|
||||
|
||||
@@ -1,22 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
#if MONO
|
||||
using System.IO;
|
||||
#else
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
|
||||
using EndOfStreamException = System.IO.EndOfStreamException;
|
||||
using FileStream = System.IO.FileStream;
|
||||
using MemoryStream = System.IO.MemoryStream;
|
||||
using SeekOrigin = System.IO.SeekOrigin;
|
||||
using Stream = System.IO.Stream;
|
||||
#endif
|
||||
using Compress.ZipFile;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Tar;
|
||||
@@ -318,7 +307,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool romba = false)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, "tmp" + Guid.NewGuid().ToString());
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either input is null or empty, return
|
||||
if (inputStream == null || rom == null || rom.Name == null)
|
||||
@@ -333,7 +322,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(rom.MachineName) + (rom.MachineName.EndsWith(".tar") ? "" : ".tar"));
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(rom.MachineName) + (rom.MachineName.EndsWith(".tar") ? string.Empty : ".tar"));
|
||||
|
||||
// Set internal variables
|
||||
TarArchive oldTarFile = TarArchive.Create();
|
||||
@@ -352,7 +341,7 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (date && !String.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt))
|
||||
if (date && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt))
|
||||
{
|
||||
usableDate = dt;
|
||||
}
|
||||
@@ -405,7 +394,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (date && !String.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt))
|
||||
if (date && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt))
|
||||
{
|
||||
usableDate = dt;
|
||||
}
|
||||
@@ -471,7 +460,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, "tmp" + Guid.NewGuid().ToString());
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either list of roms is null or empty, return
|
||||
if (inputFiles == null || roms == null || inputFiles.Count == 0 || roms.Count == 0)
|
||||
@@ -495,7 +484,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(roms[0].MachineName) + (roms[0].MachineName.EndsWith(".tar") ? "" : ".tar"));
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(roms[0].MachineName) + (roms[0].MachineName.EndsWith(".tar") ? string.Empty : ".tar"));
|
||||
|
||||
// Set internal variables
|
||||
TarArchive oldTarFile = TarArchive.Create();
|
||||
@@ -531,7 +520,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (date && !String.IsNullOrWhiteSpace(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out DateTime dt))
|
||||
if (date && !string.IsNullOrWhiteSpace(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out DateTime dt))
|
||||
{
|
||||
usableDate = dt;
|
||||
}
|
||||
@@ -591,7 +580,7 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (date && !String.IsNullOrWhiteSpace(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out DateTime dt))
|
||||
if (date && !string.IsNullOrWhiteSpace(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out DateTime dt))
|
||||
{
|
||||
usableDate = dt;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
#if MONO
|
||||
using System.IO;
|
||||
#else
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
|
||||
using BinaryWriter = System.IO.BinaryWriter;
|
||||
using EndOfStreamException = System.IO.EndOfStreamException;
|
||||
using FileStream = System.IO.FileStream;
|
||||
using MemoryStream = System.IO.MemoryStream;
|
||||
using SeekOrigin = System.IO.SeekOrigin;
|
||||
using Stream = System.IO.Stream;
|
||||
#endif
|
||||
using Compress.ZipFile;
|
||||
using SevenZip;
|
||||
using SharpCompress.Archives;
|
||||
@@ -247,7 +235,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool romba = false)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, "tmp" + Guid.NewGuid().ToString());
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either input is null or empty, return
|
||||
if (inputStream == null || rom == null || rom.Name == null)
|
||||
@@ -265,7 +253,7 @@ namespace SabreTools.Library.FileTypes
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(rom.MachineName) + (rom.MachineName.EndsWith(".xz") ? "" : ".xz"));
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(rom.MachineName) + (rom.MachineName.EndsWith(".xz") ? string.Empty : ".xz"));
|
||||
|
||||
// Set internal variables
|
||||
SevenZipBase.SetLibraryPath("7za.dll");
|
||||
@@ -443,7 +431,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, "tmp" + Guid.NewGuid().ToString());
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either list of roms is null or empty, return
|
||||
if (inputFiles == null || roms == null || inputFiles.Count == 0 || roms.Count == 0)
|
||||
@@ -467,7 +455,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(roms[0].MachineName) + (roms[0].MachineName.EndsWith(".xz") ? "" : ".xz"));
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(roms[0].MachineName) + (roms[0].MachineName.EndsWith(".xz") ? string.Empty : ".xz"));
|
||||
|
||||
// Set internal variables
|
||||
SevenZipBase.SetLibraryPath("7za.dll");
|
||||
|
||||
@@ -1,22 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Library.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
#if MONO
|
||||
using System.IO;
|
||||
#else
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
|
||||
using EndOfStreamException = System.IO.EndOfStreamException;
|
||||
using FileStream = System.IO.FileStream;
|
||||
using MemoryStream = System.IO.MemoryStream;
|
||||
using SeekOrigin = System.IO.SeekOrigin;
|
||||
using Stream = System.IO.Stream;
|
||||
#endif
|
||||
using Compress;
|
||||
using Compress.ZipFile;
|
||||
using NaturalSort;
|
||||
@@ -83,7 +72,7 @@ namespace SabreTools.Library.FileTypes
|
||||
zr = zf.ZipFileOpenReadStream(i, false, out Stream readStream, out ulong streamsize, out ushort cm);
|
||||
|
||||
// Create the rest of the path, if needed
|
||||
if (!String.IsNullOrWhiteSpace(Path.GetDirectoryName(zf.Filename(i))))
|
||||
if (!string.IsNullOrWhiteSpace(Path.GetDirectoryName(zf.Filename(i))))
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(outDir, Path.GetDirectoryName(zf.Filename(i))));
|
||||
}
|
||||
@@ -302,7 +291,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// If we get a read error, log it and continue
|
||||
if (zr != ZipReturn.ZipGood)
|
||||
{
|
||||
Globals.Logger.Warning("An error occurred while reading archive {0}: Zip Error - {1}", this.Filename, zr);
|
||||
Globals.Logger.Warning($"An error occurred while reading archive {this.Filename}: Zip Error - {zr}");
|
||||
zr = zf.ZipFileCloseReadStream();
|
||||
continue;
|
||||
}
|
||||
@@ -448,7 +437,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool romba = false)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, "tmp" + Guid.NewGuid().ToString());
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either input is null or empty, return
|
||||
if (inputStream == null || rom == null || rom.Name == null)
|
||||
@@ -466,7 +455,7 @@ namespace SabreTools.Library.FileTypes
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(rom.MachineName) + (rom.MachineName.EndsWith(".zip") ? "" : ".zip"));
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(rom.MachineName) + (rom.MachineName.EndsWith(".zip") ? string.Empty : ".zip"));
|
||||
|
||||
// Set internal variables
|
||||
Stream writeStream = null;
|
||||
@@ -492,7 +481,7 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(inputStream.Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (date && !String.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
if (date && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
@@ -567,7 +556,7 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(inputStream.Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (date && !String.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
if (date && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
@@ -651,7 +640,7 @@ namespace SabreTools.Library.FileTypes
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, "tmp" + Guid.NewGuid().ToString());
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either list of roms is null or empty, return
|
||||
if (inputFiles == null || roms == null || inputFiles.Count == 0 || roms.Count == 0)
|
||||
@@ -675,7 +664,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(roms[0].MachineName) + (roms[0].MachineName.EndsWith(".zip") ? "" : ".zip"));
|
||||
string archiveFileName = Path.Combine(outDir, Utilities.RemovePathUnsafeCharacters(roms[0].MachineName) + (roms[0].MachineName.EndsWith(".zip") ? string.Empty : ".zip"));
|
||||
|
||||
// Set internal variables
|
||||
Stream writeStream = null;
|
||||
@@ -718,7 +707,7 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[index]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (date && !String.IsNullOrWhiteSpace(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out dt))
|
||||
if (date && !string.IsNullOrWhiteSpace(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, roms[index].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
@@ -801,7 +790,7 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[-index - 1]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (date && !String.IsNullOrWhiteSpace(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out dt))
|
||||
if (date && !string.IsNullOrWhiteSpace(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, roms[-index - 1].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
|
||||
Reference in New Issue
Block a user