Fix rebuild, extract depth to proper places

This commit is contained in:
Matt Nadareski
2020-09-18 15:01:03 -07:00
parent 9c671b488d
commit c533a29bd7
14 changed files with 408 additions and 415 deletions

View File

@@ -9,11 +9,25 @@ namespace SabreTools.Library.FileTypes
{
public abstract class BaseArchive : Folder
{
#region Fields
/// <summary>
/// Determines if archives pull information from headers alone
/// </summary>
public bool QuickScan { get; set; } = false;
/// <summary>
/// Determines if dates are read or written
/// </summary>
public bool UseDates { get; set; } = false;
#endregion
#region Protected instance variables
protected bool QuickScan { get; set; } = false;
// Buffer size used by archives
/// <summary>
/// Buffer size used by archives
/// </summary>
protected const int _bufferSize = 4096 * 128;
#endregion
@@ -42,8 +56,9 @@ namespace SabreTools.Library.FileTypes
/// </summary>
/// <param name="input">Name of the file to create the archive from</param>
/// <param name="quickScan">True to use archive header values, false otherwise</param>
/// <param name="useDates">True to use dates for read and write, false otherwise</param>
/// <returns>Archive object representing the inputs</returns>
public static BaseArchive Create(string input, bool quickScan = false)
public static BaseArchive Create(string input, bool quickScan = false, bool useDates = false)
{
BaseArchive archive = null;
@@ -178,10 +193,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override abstract bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4);
public override abstract bool Write(string inputFile, string outDir, Rom rom);
/// <summary>
/// Write an input stream to an archive
@@ -189,10 +202,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputStream">Input stream to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override abstract bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4);
public override abstract bool Write(Stream inputStream, string outDir, Rom rom);
/// <summary>
/// Write a set of input files to an archive (assuming the same output archive name)
@@ -200,10 +211,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFiles">Input files to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override abstract bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false);
public override abstract bool Write(List<string> inputFiles, string outDir, List<Rom> roms);
#endregion
}

View File

@@ -298,14 +298,12 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public virtual bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
public virtual bool Write(string inputFile, string outDir, Rom rom)
{
FileStream fs = FileExtensions.TryOpenRead(inputFile);
return Write(fs, outDir, rom, date, depth);
return Write(fs, outDir, rom);
}
/// <summary>
@@ -314,11 +312,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputStream">Input stream to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public virtual bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
public virtual bool Write(Stream inputStream, string outDir, Rom rom)
{
bool success = false;
@@ -367,8 +363,8 @@ namespace SabreTools.Library.FileTypes
if (rom.ItemType == ItemType.Rom)
{
if (date && !string.IsNullOrWhiteSpace((rom as Rom).Date))
File.SetCreationTime(fileName, DateTime.Parse((rom as Rom).Date));
if (!string.IsNullOrWhiteSpace(rom.Date))
File.SetCreationTime(fileName, DateTime.Parse(rom.Date));
}
success = true;
@@ -393,10 +389,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFiles">Input files to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public virtual bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
public virtual bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
{
throw new NotImplementedException();
}

View File

@@ -19,6 +19,15 @@ namespace SabreTools.Library.FileTypes
/// </summary>
public class GZipArchive : BaseArchive
{
#region Fields
/// <summary>
/// Positive value for depth of the output depot, defaults to 4
/// </summary>
public int Depth { get; set; } = 4;
#endregion
#region Constructors
/// <summary>
@@ -408,11 +417,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(string inputFile, string outDir, Rom rom = null, bool date = false, int depth = 4)
public override bool Write(string inputFile, string outDir, Rom rom = null)
{
// Check that the input file exists
if (!File.Exists(inputFile))
@@ -424,7 +431,7 @@ namespace SabreTools.Library.FileTypes
inputFile = Path.GetFullPath(inputFile);
// Get the file stream for the file and write out
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date, depth);
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom);
}
/// <summary>
@@ -433,11 +440,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputStream">Input stream to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(Stream inputStream, string outDir, Rom rom = null, bool date = false, int depth = 4)
public override bool Write(Stream inputStream, string outDir, Rom rom = null)
{
bool success = false;
@@ -455,7 +460,7 @@ namespace SabreTools.Library.FileTypes
rom = new Rom(inputStream.GetInfo(keepReadOpen: true));
// Get the output file name
string outfile = Path.Combine(outDir, PathExtensions.GetDepotPath(rom.SHA1, depth));
string outfile = Path.Combine(outDir, PathExtensions.GetDepotPath(rom.SHA1, Depth));
// Check to see if the folder needs to be created
if (!Directory.Exists(Path.GetDirectoryName(outfile)))
@@ -510,10 +515,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFiles">Input files to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
{
throw new NotImplementedException();
}

View File

@@ -111,11 +111,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(string inputFile, string outDir, Rom rom)
{
throw new NotImplementedException();
}
@@ -126,11 +124,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputStream">Input stream to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(Stream inputStream, string outDir, Rom rom)
{
throw new NotImplementedException();
}
@@ -141,10 +137,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFiles">Input files to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
{
throw new NotImplementedException();
}

View File

@@ -111,11 +111,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(string inputFile, string outDir, Rom rom)
{
throw new NotImplementedException();
}
@@ -126,11 +124,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputStream">Input stream to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(Stream inputStream, string outDir, Rom rom)
{
throw new NotImplementedException();
}
@@ -141,10 +137,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFiles">Input files to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
{
throw new NotImplementedException();
}

View File

@@ -281,13 +281,11 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(string inputFile, string outDir, Rom rom)
{
// Get the file stream for the file and write out
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date, depth);
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom);
}
/// <summary>
@@ -296,10 +294,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputStream">Input stream to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(Stream inputStream, string outDir, Rom rom)
{
throw new NotImplementedException();
}
@@ -310,10 +306,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFiles">Input files to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
{
throw new NotImplementedException();
}

View File

@@ -411,13 +411,11 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(string inputFile, string outDir, Rom rom)
{
// Get the file stream for the file and write out
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date: date);
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom);
}
/// <summary>
@@ -426,10 +424,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputStream">Input stream to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(Stream inputStream, string outDir, Rom rom)
{
bool success = false;
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
@@ -470,7 +466,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 (UseDates && !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);
@@ -545,7 +541,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 (UseDates && !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);
@@ -619,10 +615,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFiles">Input files to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
{
bool success = false;
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
@@ -692,7 +686,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 (UseDates && !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);
@@ -775,7 +769,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 (UseDates && !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);

View File

@@ -286,13 +286,11 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(string inputFile, string outDir, Rom rom)
{
// Get the file stream for the file and write out
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date: date);
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom);
}
/// <summary>
@@ -301,10 +299,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputStream">Input stream to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(Stream inputStream, string outDir, Rom rom)
{
bool success = false;
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
@@ -335,7 +331,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 (UseDates && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt))
usableDate = dt;
// Copy the input stream to the output
@@ -384,7 +380,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 (UseDates && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt))
usableDate = dt;
// If we have the input file, add it now
@@ -440,10 +436,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFiles">Input files to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
{
bool success = false;
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
@@ -506,10 +500,8 @@ 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 (UseDates && !string.IsNullOrWhiteSpace(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out DateTime dt))
usableDate = dt;
}
// Copy the input stream to the output
tarFile.AddEntry(roms[index].Name, FileExtensions.TryOpenRead(inputFiles[index]), size: roms[index].Size ?? 0, modified: usableDate);
@@ -566,10 +558,8 @@ 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 (UseDates && !string.IsNullOrWhiteSpace(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out DateTime dt))
usableDate = dt;
}
// Copy the input file to the output
tarFile.AddEntry(roms[-index - 1].Name, FileExtensions.TryOpenRead(inputFiles[-index - 1]), size: roms[-index - 1].Size ?? 0, modified: usableDate);

View File

@@ -16,6 +16,15 @@ namespace SabreTools.Library.FileTypes
/// </summary>
public class XZArchive : BaseArchive
{
#region Fields
/// <summary>
/// Positive value for depth of the output depot, defaults to 4
/// </summary>
public int Depth { get; set; } = 4;
#endregion
#region Constructors
/// <summary>
@@ -309,11 +318,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(string inputFile, string outDir, Rom rom)
{
// Check that the input file exists
if (!File.Exists(inputFile))
@@ -325,7 +332,7 @@ namespace SabreTools.Library.FileTypes
inputFile = Path.GetFullPath(inputFile);
// Get the file stream for the file and write out
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date, depth);
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom);
}
/// <summary>
@@ -334,10 +341,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputStream">Input stream to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(Stream inputStream, string outDir, Rom rom)
{
bool success = false;
@@ -355,7 +360,7 @@ namespace SabreTools.Library.FileTypes
rom = new Rom(inputStream.GetInfo(keepReadOpen: true));
// Get the output file name
string outfile = Path.Combine(outDir, PathExtensions.GetDepotPath(rom.SHA1, depth));
string outfile = Path.Combine(outDir, PathExtensions.GetDepotPath(rom.SHA1, Depth));
outfile = outfile.Replace(".gz", ".xz");
// Check to see if the folder needs to be created
@@ -382,10 +387,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFiles">Input files to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
{
throw new NotImplementedException();
}

View File

@@ -111,11 +111,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(string inputFile, string outDir, Rom rom)
{
throw new NotImplementedException();
}
@@ -126,11 +124,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputStream">Input stream to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(Stream inputStream, string outDir, Rom rom)
{
throw new NotImplementedException();
}
@@ -141,10 +137,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFiles">Input files to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
{
throw new NotImplementedException();
}

View File

@@ -416,13 +416,11 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(string inputFile, string outDir, Rom rom)
{
// Get the file stream for the file and write out
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date: date);
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom);
}
/// <summary>
@@ -431,10 +429,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputStream">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(Stream inputStream, string outDir, Rom rom)
{
bool success = false;
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
@@ -475,7 +471,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 (UseDates && !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);
@@ -548,7 +544,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 (UseDates && !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);
@@ -623,10 +619,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFile">Input filenames to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">List of Rom representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
{
bool success = false;
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
@@ -696,7 +690,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 (UseDates && !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);
@@ -779,7 +773,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 (UseDates && !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);

View File

@@ -111,11 +111,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(string inputFile, string outDir, Rom rom)
{
throw new NotImplementedException();
}
@@ -126,11 +124,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputStream">Input stream to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
public override bool Write(Stream inputStream, string outDir, Rom rom)
{
throw new NotImplementedException();
}
@@ -141,10 +137,8 @@ namespace SabreTools.Library.FileTypes
/// <param name="inputFiles">Input files to be moved</param>
/// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
{
throw new NotImplementedException();
}