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

@@ -2438,8 +2438,7 @@ namespace SabreTools.Library.DatFiles
if (fileinfo == null)
continue;
// If we have partial, just ensure we are sorted correctly
if (outputFormat == OutputFormat.Folder && Header.ForcePacking == PackingFlag.Partial)
// Ensure we are sorted correctly (some other calls can change this)
Items.BucketBy(Field.DatItem_SHA1, DedupeType.None);
// If there are no items in the hash, we continue
@@ -2798,9 +2797,17 @@ namespace SabreTools.Library.DatFiles
// Get the output archive, if possible
Folder outputArchive = Folder.Create(outputFormat);
if (outputArchive is BaseArchive baseArchive && date)
baseArchive.UseDates = date;
// Set the depth fields where appropriate
if (outputArchive is GZipArchive gzipArchive)
gzipArchive.Depth = Header.OutputDepot.Depth;
else if (outputArchive is XZArchive xzArchive)
xzArchive.Depth = Header.OutputDepot.Depth;
// Now rebuild to the output file
outputArchive.Write(fileStream, outDir, item as Rom, date: date, depth: Header.OutputDepot.Depth);
outputArchive.Write(fileStream, outDir, item as Rom);
}
// Close the input stream
@@ -2865,10 +2872,18 @@ namespace SabreTools.Library.DatFiles
// Get the output archive, if possible
Folder outputArchive = Folder.Create(outputFormat);
if (outputArchive is BaseArchive baseArchive && date)
baseArchive.UseDates = date;
// Set the depth fields where appropriate
if (outputArchive is GZipArchive gzipArchive)
gzipArchive.Depth = Header.OutputDepot.Depth;
else if (outputArchive is XZArchive xzArchive)
xzArchive.Depth = Header.OutputDepot.Depth;
// Now rebuild to the output file
eitherSuccess |= outputArchive.Write(transformStream, outDir, item as Rom, date: date, depth: Header.OutputDepot.Depth);
eitherSuccess |= outputArchive.Write(fileStream, outDir, datItem as Rom, date: date, depth: Header.OutputDepot.Depth);
eitherSuccess |= outputArchive.Write(transformStream, outDir, item as Rom);
eitherSuccess |= outputArchive.Write(fileStream, outDir, datItem as Rom);
// Now add the success of either rebuild
rebuilt &= eitherSuccess;

View File

@@ -39,6 +39,11 @@ namespace SabreTools.Library.DatFiles
/// </summary>
private ConcurrentDictionary<string, List<DatItem>> items;
/// <summary>
/// Lock for statistics calculation
/// </summary>
private object statsLock = new object();
#endregion
#region Publically available fields
@@ -149,7 +154,7 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Number of Disk items
/// </summary>
[JsonIgnore]
[JsonIgnore, XmlIgnore]
public long DiskCount { get; private set; } = 0;
/// <summary>
@@ -514,6 +519,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <param name="key">Key in the dictionary to remove</param>
public bool Remove(string key)
{
// Explicit lock for some weird corner cases
lock (key)
{
// If the key doesn't exist, return
if (!ContainsKey(key))
@@ -528,6 +536,7 @@ namespace SabreTools.Library.DatFiles
// Remove the key from the dictionary
return items.TryRemove(key, out _);
}
}
/// <summary>
/// Remove the first instance of a value from the file dictionary if it exists
@@ -535,6 +544,9 @@ namespace SabreTools.Library.DatFiles
/// <param name="key">Key in the dictionary to remove from</param>
/// <param name="value">Value to remove from the dictionary</param>
public bool Remove(string key, DatItem value)
{
// Explicit lock for some weird corner cases
lock (key)
{
// If the key and value doesn't exist, return
if (!Contains(key, value))
@@ -545,6 +557,7 @@ namespace SabreTools.Library.DatFiles
return items[key].Remove(value);
}
}
/// <summary>
/// Reset a key from the file dictionary if it exists
@@ -581,6 +594,8 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <param name="item">Item to add info from</param>
private void AddItemStatistics(DatItem item)
{
lock (statsLock)
{
// No matter what the item is, we increment the count
TotalCount++;
@@ -717,6 +732,7 @@ namespace SabreTools.Library.DatFiles
break;
}
}
}
/// <summary>
/// Add statistics from another DatStats object
@@ -749,6 +765,7 @@ namespace SabreTools.Library.DatFiles
SHA256Count += stats.SHA256Count;
SHA384Count += stats.SHA384Count;
SHA512Count += stats.SHA512Count;
SpamSumCount += stats.SpamSumCount;
// Individual status counts
BaddumpCount += stats.BaddumpCount;
@@ -779,6 +796,8 @@ namespace SabreTools.Library.DatFiles
if (item == null)
return;
lock (statsLock)
{
// No matter what the item is, we decrease the count
TotalCount--;
@@ -912,6 +931,7 @@ namespace SabreTools.Library.DatFiles
break;
}
}
}
#endregion
@@ -1226,6 +1246,7 @@ namespace SabreTools.Library.DatFiles
SHA256Count = 0;
SHA384Count = 0;
SHA512Count = 0;
SpamSumCount = 0;
BaddumpCount = 0;
GoodCount = 0;

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();
}