diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index 3c096a4a..a4df3a20 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -2438,9 +2438,8 @@ 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) - Items.BucketBy(Field.DatItem_SHA1, DedupeType.None); + // 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 if (Items[hash] == null || Items[hash].Count == 0) @@ -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; diff --git a/SabreTools.Library/DatFiles/ItemDictionary.cs b/SabreTools.Library/DatFiles/ItemDictionary.cs index 4cc76e31..4522cdbe 100644 --- a/SabreTools.Library/DatFiles/ItemDictionary.cs +++ b/SabreTools.Library/DatFiles/ItemDictionary.cs @@ -39,6 +39,11 @@ namespace SabreTools.Library.DatFiles /// private ConcurrentDictionary> items; + /// + /// Lock for statistics calculation + /// + private object statsLock = new object(); + #endregion #region Publically available fields @@ -149,7 +154,7 @@ namespace SabreTools.Library.DatFiles /// /// Number of Disk items /// - [JsonIgnore] + [JsonIgnore, XmlIgnore] public long DiskCount { get; private set; } = 0; /// @@ -515,18 +520,22 @@ namespace SabreTools.Library.DatFiles /// Key in the dictionary to remove public bool Remove(string key) { - // If the key doesn't exist, return - if (!ContainsKey(key)) - return false; - - // Remove the statistics first - foreach (DatItem item in items[key]) + // Explicit lock for some weird corner cases + lock (key) { - RemoveItemStatistics(item); - } + // If the key doesn't exist, return + if (!ContainsKey(key)) + return false; - // Remove the key from the dictionary - return items.TryRemove(key, out _); + // Remove the statistics first + foreach (DatItem item in items[key]) + { + RemoveItemStatistics(item); + } + + // Remove the key from the dictionary + return items.TryRemove(key, out _); + } } /// @@ -536,14 +545,18 @@ namespace SabreTools.Library.DatFiles /// Value to remove from the dictionary public bool Remove(string key, DatItem value) { - // If the key and value doesn't exist, return - if (!Contains(key, value)) - return false; + // Explicit lock for some weird corner cases + lock (key) + { + // If the key and value doesn't exist, return + if (!Contains(key, value)) + return false; - // Remove the statistics first - RemoveItemStatistics(value); + // Remove the statistics first + RemoveItemStatistics(value); - return items[key].Remove(value); + return items[key].Remove(value); + } } /// @@ -582,139 +595,142 @@ namespace SabreTools.Library.DatFiles /// Item to add info from private void AddItemStatistics(DatItem item) { - // No matter what the item is, we increment the count - TotalCount++; - - // Increment removal count - if (item.Remove) - RemovedCount++; - - // Now we do different things for each item type - switch (item.ItemType) + lock (statsLock) { - case ItemType.Adjuster: - AdjusterCount++; - break; - case ItemType.Analog: - AnalogCount++; - break; - case ItemType.Archive: - ArchiveCount++; - break; - case ItemType.BiosSet: - BiosSetCount++; - break; - case ItemType.Chip: - ChipCount++; - break; - case ItemType.Condition: - ConditionCount++; - break; - case ItemType.Configuration: - ConfigurationCount++; - break; - case ItemType.DataArea: - DataAreaCount++; - break; - case ItemType.Device: - DeviceCount++; - break; - case ItemType.DeviceReference: - DeviceReferenceCount++; - break; - case ItemType.DipSwitch: - DipSwitchCount++; - break; - case ItemType.Disk: - DiskCount++; - if ((item as Disk).ItemStatus != ItemStatus.Nodump) - { - MD5Count += (string.IsNullOrWhiteSpace((item as Disk).MD5) ? 0 : 1); - SHA1Count += (string.IsNullOrWhiteSpace((item as Disk).SHA1) ? 0 : 1); - } + // No matter what the item is, we increment the count + TotalCount++; - BaddumpCount += ((item as Disk).ItemStatus == ItemStatus.BadDump ? 1 : 0); - GoodCount += ((item as Disk).ItemStatus == ItemStatus.Good ? 1 : 0); - NodumpCount += ((item as Disk).ItemStatus == ItemStatus.Nodump ? 1 : 0); - VerifiedCount += ((item as Disk).ItemStatus == ItemStatus.Verified ? 1 : 0); - break; - case ItemType.DiskArea: - DiskAreaCount++; - break; - case ItemType.Display: - DisplayCount++; - break; - case ItemType.Driver: - DriverCount++; - break; - case ItemType.Feature: - FeatureCount++; - break; - case ItemType.Info: - InfoCount++; - break; - case ItemType.Input: - InputCount++; - break; - case ItemType.Media: - MediaCount++; - MD5Count += (string.IsNullOrWhiteSpace((item as Media).MD5) ? 0 : 1); - SHA1Count += (string.IsNullOrWhiteSpace((item as Media).SHA1) ? 0 : 1); - SHA256Count += (string.IsNullOrWhiteSpace((item as Media).SHA256) ? 0 : 1); - SpamSumCount += (string.IsNullOrWhiteSpace((item as Media).SpamSum) ? 0 : 1); - break; - case ItemType.Part: - PartCount++; - break; - case ItemType.PartFeature: - PartFeatureCount++; - break; - case ItemType.Port: - PortCount++; - break; - case ItemType.RamOption: - RamOptionCount++; - break; - case ItemType.Release: - ReleaseCount++; - break; - case ItemType.Rom: - RomCount++; - if ((item as Rom).ItemStatus != ItemStatus.Nodump) - { - TotalSize += (item as Rom).Size ?? 0; - CRCCount += (string.IsNullOrWhiteSpace((item as Rom).CRC) ? 0 : 1); - MD5Count += (string.IsNullOrWhiteSpace((item as Rom).MD5) ? 0 : 1); + // Increment removal count + if (item.Remove) + RemovedCount++; + + // Now we do different things for each item type + switch (item.ItemType) + { + case ItemType.Adjuster: + AdjusterCount++; + break; + case ItemType.Analog: + AnalogCount++; + break; + case ItemType.Archive: + ArchiveCount++; + break; + case ItemType.BiosSet: + BiosSetCount++; + break; + case ItemType.Chip: + ChipCount++; + break; + case ItemType.Condition: + ConditionCount++; + break; + case ItemType.Configuration: + ConfigurationCount++; + break; + case ItemType.DataArea: + DataAreaCount++; + break; + case ItemType.Device: + DeviceCount++; + break; + case ItemType.DeviceReference: + DeviceReferenceCount++; + break; + case ItemType.DipSwitch: + DipSwitchCount++; + break; + case ItemType.Disk: + DiskCount++; + if ((item as Disk).ItemStatus != ItemStatus.Nodump) + { + MD5Count += (string.IsNullOrWhiteSpace((item as Disk).MD5) ? 0 : 1); + SHA1Count += (string.IsNullOrWhiteSpace((item as Disk).SHA1) ? 0 : 1); + } + + BaddumpCount += ((item as Disk).ItemStatus == ItemStatus.BadDump ? 1 : 0); + GoodCount += ((item as Disk).ItemStatus == ItemStatus.Good ? 1 : 0); + NodumpCount += ((item as Disk).ItemStatus == ItemStatus.Nodump ? 1 : 0); + VerifiedCount += ((item as Disk).ItemStatus == ItemStatus.Verified ? 1 : 0); + break; + case ItemType.DiskArea: + DiskAreaCount++; + break; + case ItemType.Display: + DisplayCount++; + break; + case ItemType.Driver: + DriverCount++; + break; + case ItemType.Feature: + FeatureCount++; + break; + case ItemType.Info: + InfoCount++; + break; + case ItemType.Input: + InputCount++; + break; + case ItemType.Media: + MediaCount++; + MD5Count += (string.IsNullOrWhiteSpace((item as Media).MD5) ? 0 : 1); + SHA1Count += (string.IsNullOrWhiteSpace((item as Media).SHA1) ? 0 : 1); + SHA256Count += (string.IsNullOrWhiteSpace((item as Media).SHA256) ? 0 : 1); + SpamSumCount += (string.IsNullOrWhiteSpace((item as Media).SpamSum) ? 0 : 1); + break; + case ItemType.Part: + PartCount++; + break; + case ItemType.PartFeature: + PartFeatureCount++; + break; + case ItemType.Port: + PortCount++; + break; + case ItemType.RamOption: + RamOptionCount++; + break; + case ItemType.Release: + ReleaseCount++; + break; + case ItemType.Rom: + RomCount++; + if ((item as Rom).ItemStatus != ItemStatus.Nodump) + { + TotalSize += (item as Rom).Size ?? 0; + CRCCount += (string.IsNullOrWhiteSpace((item as Rom).CRC) ? 0 : 1); + MD5Count += (string.IsNullOrWhiteSpace((item as Rom).MD5) ? 0 : 1); #if NET_FRAMEWORK - RIPEMD160Count += (string.IsNullOrWhiteSpace((item as Rom).RIPEMD160) ? 0 : 1); + RIPEMD160Count += (string.IsNullOrWhiteSpace((item as Rom).RIPEMD160) ? 0 : 1); #endif - SHA1Count += (string.IsNullOrWhiteSpace((item as Rom).SHA1) ? 0 : 1); - SHA256Count += (string.IsNullOrWhiteSpace((item as Rom).SHA256) ? 0 : 1); - SHA384Count += (string.IsNullOrWhiteSpace((item as Rom).SHA384) ? 0 : 1); - SHA512Count += (string.IsNullOrWhiteSpace((item as Rom).SHA512) ? 0 : 1); - SpamSumCount += (string.IsNullOrWhiteSpace((item as Rom).SpamSum) ? 0 : 1); - } + SHA1Count += (string.IsNullOrWhiteSpace((item as Rom).SHA1) ? 0 : 1); + SHA256Count += (string.IsNullOrWhiteSpace((item as Rom).SHA256) ? 0 : 1); + SHA384Count += (string.IsNullOrWhiteSpace((item as Rom).SHA384) ? 0 : 1); + SHA512Count += (string.IsNullOrWhiteSpace((item as Rom).SHA512) ? 0 : 1); + SpamSumCount += (string.IsNullOrWhiteSpace((item as Rom).SpamSum) ? 0 : 1); + } - BaddumpCount += ((item as Rom).ItemStatus == ItemStatus.BadDump ? 1 : 0); - GoodCount += ((item as Rom).ItemStatus == ItemStatus.Good ? 1 : 0); - NodumpCount += ((item as Rom).ItemStatus == ItemStatus.Nodump ? 1 : 0); - VerifiedCount += ((item as Rom).ItemStatus == ItemStatus.Verified ? 1 : 0); - break; - case ItemType.Sample: - SampleCount++; - break; - case ItemType.SharedFeature: - SharedFeatureCount++; - break; - case ItemType.Slot: - SlotCount++; - break; - case ItemType.SoftwareList: - SoftwareListCount++; - break; - case ItemType.Sound: - SoundCount++; - break; + BaddumpCount += ((item as Rom).ItemStatus == ItemStatus.BadDump ? 1 : 0); + GoodCount += ((item as Rom).ItemStatus == ItemStatus.Good ? 1 : 0); + NodumpCount += ((item as Rom).ItemStatus == ItemStatus.Nodump ? 1 : 0); + VerifiedCount += ((item as Rom).ItemStatus == ItemStatus.Verified ? 1 : 0); + break; + case ItemType.Sample: + SampleCount++; + break; + case ItemType.SharedFeature: + SharedFeatureCount++; + break; + case ItemType.Slot: + SlotCount++; + break; + case ItemType.SoftwareList: + SoftwareListCount++; + break; + case ItemType.Sound: + SoundCount++; + break; + } } } @@ -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,137 +796,140 @@ namespace SabreTools.Library.DatFiles if (item == null) return; - // No matter what the item is, we decrease the count - TotalCount--; - - // Decrement removal count - if (item.Remove) - RemovedCount--; - - // Now we do different things for each item type - switch (item.ItemType) + lock (statsLock) { - case ItemType.Adjuster: - AdjusterCount--; - break; - case ItemType.Analog: - AnalogCount--; - break; - case ItemType.Archive: - ArchiveCount--; - break; - case ItemType.BiosSet: - BiosSetCount--; - break; - case ItemType.Chip: - ChipCount--; - break; - case ItemType.Condition: - ConditionCount--; - break; - case ItemType.Configuration: - ConfigurationCount--; - break; - case ItemType.DataArea: - DataAreaCount--; - break; - case ItemType.Device: - DeviceCount--; - break; - case ItemType.DeviceReference: - DeviceReferenceCount--; - break; - case ItemType.DipSwitch: - DipSwitchCount--; - break; - case ItemType.Disk: - DiskCount--; - if ((item as Disk).ItemStatus != ItemStatus.Nodump) - { - MD5Count -= (string.IsNullOrWhiteSpace((item as Disk).MD5) ? 0 : 1); - SHA1Count -= (string.IsNullOrWhiteSpace((item as Disk).SHA1) ? 0 : 1); - } + // No matter what the item is, we decrease the count + TotalCount--; - BaddumpCount -= ((item as Disk).ItemStatus == ItemStatus.BadDump ? 1 : 0); - GoodCount -= ((item as Disk).ItemStatus == ItemStatus.Good ? 1 : 0); - NodumpCount -= ((item as Disk).ItemStatus == ItemStatus.Nodump ? 1 : 0); - VerifiedCount -= ((item as Disk).ItemStatus == ItemStatus.Verified ? 1 : 0); - break; - case ItemType.DiskArea: - DiskAreaCount--; - break; - case ItemType.Display: - DisplayCount--; - break; - case ItemType.Driver: - DriverCount--; - break; - case ItemType.Feature: - FeatureCount--; - break; - case ItemType.Info: - InfoCount--; - break; - case ItemType.Input: - InputCount--; - break; - case ItemType.Media: - MediaCount--; - MD5Count -= (string.IsNullOrWhiteSpace((item as Media).MD5) ? 0 : 1); - SHA1Count -= (string.IsNullOrWhiteSpace((item as Media).SHA1) ? 0 : 1); - SHA256Count -= (string.IsNullOrWhiteSpace((item as Media).SHA256) ? 0 : 1); - break; - case ItemType.Part: - PartCount--; - break; - case ItemType.PartFeature: - PartFeatureCount--; - break; - case ItemType.Port: - PortCount--; - break; - case ItemType.RamOption: - RamOptionCount--; - break; - case ItemType.Release: - ReleaseCount--; - break; - case ItemType.Rom: - RomCount--; - if ((item as Rom).ItemStatus != ItemStatus.Nodump) - { - TotalSize -= (item as Rom).Size ?? 0; - CRCCount -= (string.IsNullOrWhiteSpace((item as Rom).CRC) ? 0 : 1); - MD5Count -= (string.IsNullOrWhiteSpace((item as Rom).MD5) ? 0 : 1); + // Decrement removal count + if (item.Remove) + RemovedCount--; + + // Now we do different things for each item type + switch (item.ItemType) + { + case ItemType.Adjuster: + AdjusterCount--; + break; + case ItemType.Analog: + AnalogCount--; + break; + case ItemType.Archive: + ArchiveCount--; + break; + case ItemType.BiosSet: + BiosSetCount--; + break; + case ItemType.Chip: + ChipCount--; + break; + case ItemType.Condition: + ConditionCount--; + break; + case ItemType.Configuration: + ConfigurationCount--; + break; + case ItemType.DataArea: + DataAreaCount--; + break; + case ItemType.Device: + DeviceCount--; + break; + case ItemType.DeviceReference: + DeviceReferenceCount--; + break; + case ItemType.DipSwitch: + DipSwitchCount--; + break; + case ItemType.Disk: + DiskCount--; + if ((item as Disk).ItemStatus != ItemStatus.Nodump) + { + MD5Count -= (string.IsNullOrWhiteSpace((item as Disk).MD5) ? 0 : 1); + SHA1Count -= (string.IsNullOrWhiteSpace((item as Disk).SHA1) ? 0 : 1); + } + + BaddumpCount -= ((item as Disk).ItemStatus == ItemStatus.BadDump ? 1 : 0); + GoodCount -= ((item as Disk).ItemStatus == ItemStatus.Good ? 1 : 0); + NodumpCount -= ((item as Disk).ItemStatus == ItemStatus.Nodump ? 1 : 0); + VerifiedCount -= ((item as Disk).ItemStatus == ItemStatus.Verified ? 1 : 0); + break; + case ItemType.DiskArea: + DiskAreaCount--; + break; + case ItemType.Display: + DisplayCount--; + break; + case ItemType.Driver: + DriverCount--; + break; + case ItemType.Feature: + FeatureCount--; + break; + case ItemType.Info: + InfoCount--; + break; + case ItemType.Input: + InputCount--; + break; + case ItemType.Media: + MediaCount--; + MD5Count -= (string.IsNullOrWhiteSpace((item as Media).MD5) ? 0 : 1); + SHA1Count -= (string.IsNullOrWhiteSpace((item as Media).SHA1) ? 0 : 1); + SHA256Count -= (string.IsNullOrWhiteSpace((item as Media).SHA256) ? 0 : 1); + break; + case ItemType.Part: + PartCount--; + break; + case ItemType.PartFeature: + PartFeatureCount--; + break; + case ItemType.Port: + PortCount--; + break; + case ItemType.RamOption: + RamOptionCount--; + break; + case ItemType.Release: + ReleaseCount--; + break; + case ItemType.Rom: + RomCount--; + if ((item as Rom).ItemStatus != ItemStatus.Nodump) + { + TotalSize -= (item as Rom).Size ?? 0; + CRCCount -= (string.IsNullOrWhiteSpace((item as Rom).CRC) ? 0 : 1); + MD5Count -= (string.IsNullOrWhiteSpace((item as Rom).MD5) ? 0 : 1); #if NET_FRAMEWORK RIPEMD160Count -= (string.IsNullOrWhiteSpace((item as Rom).RIPEMD160) ? 0 : 1); #endif - SHA1Count -= (string.IsNullOrWhiteSpace((item as Rom).SHA1) ? 0 : 1); - SHA256Count -= (string.IsNullOrWhiteSpace((item as Rom).SHA256) ? 0 : 1); - SHA384Count -= (string.IsNullOrWhiteSpace((item as Rom).SHA384) ? 0 : 1); - SHA512Count -= (string.IsNullOrWhiteSpace((item as Rom).SHA512) ? 0 : 1); - } + SHA1Count -= (string.IsNullOrWhiteSpace((item as Rom).SHA1) ? 0 : 1); + SHA256Count -= (string.IsNullOrWhiteSpace((item as Rom).SHA256) ? 0 : 1); + SHA384Count -= (string.IsNullOrWhiteSpace((item as Rom).SHA384) ? 0 : 1); + SHA512Count -= (string.IsNullOrWhiteSpace((item as Rom).SHA512) ? 0 : 1); + } - BaddumpCount -= ((item as Rom).ItemStatus == ItemStatus.BadDump ? 1 : 0); - GoodCount -= ((item as Rom).ItemStatus == ItemStatus.Good ? 1 : 0); - NodumpCount -= ((item as Rom).ItemStatus == ItemStatus.Nodump ? 1 : 0); - VerifiedCount -= ((item as Rom).ItemStatus == ItemStatus.Verified ? 1 : 0); - break; - case ItemType.Sample: - SampleCount--; - break; - case ItemType.SharedFeature: - SharedFeatureCount--; - break; - case ItemType.Slot: - SlotCount--; - break; - case ItemType.SoftwareList: - SoftwareListCount--; - break; - case ItemType.Sound: - SoundCount--; - break; + BaddumpCount -= ((item as Rom).ItemStatus == ItemStatus.BadDump ? 1 : 0); + GoodCount -= ((item as Rom).ItemStatus == ItemStatus.Good ? 1 : 0); + NodumpCount -= ((item as Rom).ItemStatus == ItemStatus.Nodump ? 1 : 0); + VerifiedCount -= ((item as Rom).ItemStatus == ItemStatus.Verified ? 1 : 0); + break; + case ItemType.Sample: + SampleCount--; + break; + case ItemType.SharedFeature: + SharedFeatureCount--; + break; + case ItemType.Slot: + SlotCount--; + break; + case ItemType.SoftwareList: + SoftwareListCount--; + break; + case ItemType.Sound: + SoundCount--; + break; + } } } @@ -1226,6 +1246,7 @@ namespace SabreTools.Library.DatFiles SHA256Count = 0; SHA384Count = 0; SHA512Count = 0; + SpamSumCount = 0; BaddumpCount = 0; GoodCount = 0; diff --git a/SabreTools.Library/FileTypes/BaseArchive.cs b/SabreTools.Library/FileTypes/BaseArchive.cs index af504f3f..8eb278d9 100644 --- a/SabreTools.Library/FileTypes/BaseArchive.cs +++ b/SabreTools.Library/FileTypes/BaseArchive.cs @@ -9,11 +9,25 @@ namespace SabreTools.Library.FileTypes { public abstract class BaseArchive : Folder { + #region Fields + + /// + /// Determines if archives pull information from headers alone + /// + public bool QuickScan { get; set; } = false; + + /// + /// Determines if dates are read or written + /// + public bool UseDates { get; set; } = false; + + #endregion + #region Protected instance variables - protected bool QuickScan { get; set; } = false; - - // Buffer size used by archives + /// + /// Buffer size used by archives + /// protected const int _bufferSize = 4096 * 128; #endregion @@ -42,8 +56,9 @@ namespace SabreTools.Library.FileTypes /// /// Name of the file to create the archive from /// True to use archive header values, false otherwise + /// True to use dates for read and write, false otherwise /// Archive object representing the inputs - 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 /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the archive was written properly, false otherwise - 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); /// /// Write an input stream to an archive @@ -189,10 +202,8 @@ namespace SabreTools.Library.FileTypes /// Input stream to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the archive was written properly, false otherwise - 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); /// /// Write a set of input files to an archive (assuming the same output archive name) @@ -200,10 +211,8 @@ namespace SabreTools.Library.FileTypes /// Input files to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public override abstract bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false); + public override abstract bool Write(List inputFiles, string outDir, List roms); #endregion } diff --git a/SabreTools.Library/FileTypes/Folder.cs b/SabreTools.Library/FileTypes/Folder.cs index 1b7d9a37..c0b07741 100644 --- a/SabreTools.Library/FileTypes/Folder.cs +++ b/SabreTools.Library/FileTypes/Folder.cs @@ -298,14 +298,12 @@ namespace SabreTools.Library.FileTypes /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the write was a success, false otherwise /// 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. - 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); } /// @@ -314,11 +312,9 @@ namespace SabreTools.Library.FileTypes /// Input stream to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the write was a success, false otherwise /// 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. - 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 /// Input files to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public virtual bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false) + public virtual bool Write(List inputFiles, string outDir, List roms) { throw new NotImplementedException(); } diff --git a/SabreTools.Library/FileTypes/GZipArchive.cs b/SabreTools.Library/FileTypes/GZipArchive.cs index 07b39174..d25279d6 100644 --- a/SabreTools.Library/FileTypes/GZipArchive.cs +++ b/SabreTools.Library/FileTypes/GZipArchive.cs @@ -19,6 +19,15 @@ namespace SabreTools.Library.FileTypes /// public class GZipArchive : BaseArchive { + #region Fields + + /// + /// Positive value for depth of the output depot, defaults to 4 + /// + public int Depth { get; set; } = 4; + + #endregion + #region Constructors /// @@ -408,11 +417,9 @@ namespace SabreTools.Library.FileTypes /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the write was a success, false otherwise /// 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. - 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); } /// @@ -433,11 +440,9 @@ namespace SabreTools.Library.FileTypes /// Input stream to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the write was a success, false otherwise /// 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. - 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 /// Input files to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public override bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false) + public override bool Write(List inputFiles, string outDir, List roms) { throw new NotImplementedException(); } diff --git a/SabreTools.Library/FileTypes/LRZipArchive.cs b/SabreTools.Library/FileTypes/LRZipArchive.cs index 4a184527..f28b9c29 100644 --- a/SabreTools.Library/FileTypes/LRZipArchive.cs +++ b/SabreTools.Library/FileTypes/LRZipArchive.cs @@ -111,11 +111,9 @@ namespace SabreTools.Library.FileTypes /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the write was a success, false otherwise /// 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. - 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 /// Input stream to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the write was a success, false otherwise /// 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. - 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 /// Input files to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public override bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false) + public override bool Write(List inputFiles, string outDir, List roms) { throw new NotImplementedException(); } diff --git a/SabreTools.Library/FileTypes/LZ4Archive.cs b/SabreTools.Library/FileTypes/LZ4Archive.cs index 2f3dc069..10e4c662 100644 --- a/SabreTools.Library/FileTypes/LZ4Archive.cs +++ b/SabreTools.Library/FileTypes/LZ4Archive.cs @@ -111,11 +111,9 @@ namespace SabreTools.Library.FileTypes /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the write was a success, false otherwise /// 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. - 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 /// Input stream to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the write was a success, false otherwise /// 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. - 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 /// Input files to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public override bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false) + public override bool Write(List inputFiles, string outDir, List roms) { throw new NotImplementedException(); } diff --git a/SabreTools.Library/FileTypes/RarArchive.cs b/SabreTools.Library/FileTypes/RarArchive.cs index 81a5afc1..6e479b3b 100644 --- a/SabreTools.Library/FileTypes/RarArchive.cs +++ b/SabreTools.Library/FileTypes/RarArchive.cs @@ -281,13 +281,11 @@ namespace SabreTools.Library.FileTypes /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the archive was written properly, false otherwise - 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); } /// @@ -296,10 +294,8 @@ namespace SabreTools.Library.FileTypes /// Input stream to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the archive was written properly, false otherwise - 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 /// Input files to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public override bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false) + public override bool Write(List inputFiles, string outDir, List roms) { throw new NotImplementedException(); } diff --git a/SabreTools.Library/FileTypes/SevenZipArchive.cs b/SabreTools.Library/FileTypes/SevenZipArchive.cs index 078f50b2..c9be1868 100644 --- a/SabreTools.Library/FileTypes/SevenZipArchive.cs +++ b/SabreTools.Library/FileTypes/SevenZipArchive.cs @@ -411,13 +411,11 @@ namespace SabreTools.Library.FileTypes /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the archive was written properly, false otherwise - 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); } /// @@ -426,10 +424,8 @@ namespace SabreTools.Library.FileTypes /// Input stream to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the archive was written properly, false otherwise - 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 /// Input files to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public override bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false) + public override bool Write(List inputFiles, string outDir, List 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); diff --git a/SabreTools.Library/FileTypes/TapeArchive.cs b/SabreTools.Library/FileTypes/TapeArchive.cs index f8679689..eae373dc 100644 --- a/SabreTools.Library/FileTypes/TapeArchive.cs +++ b/SabreTools.Library/FileTypes/TapeArchive.cs @@ -286,13 +286,11 @@ namespace SabreTools.Library.FileTypes /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the archive was written properly, false otherwise - 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); } /// @@ -301,10 +299,8 @@ namespace SabreTools.Library.FileTypes /// Input stream to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the archive was written properly, false otherwise - 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 /// Input files to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public override bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false) + public override bool Write(List inputFiles, string outDir, List 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); diff --git a/SabreTools.Library/FileTypes/XZArchive.cs b/SabreTools.Library/FileTypes/XZArchive.cs index 063778c2..d7040b4c 100644 --- a/SabreTools.Library/FileTypes/XZArchive.cs +++ b/SabreTools.Library/FileTypes/XZArchive.cs @@ -16,6 +16,15 @@ namespace SabreTools.Library.FileTypes /// public class XZArchive : BaseArchive { + #region Fields + + /// + /// Positive value for depth of the output depot, defaults to 4 + /// + public int Depth { get; set; } = 4; + + #endregion + #region Constructors /// @@ -309,11 +318,9 @@ namespace SabreTools.Library.FileTypes /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the write was a success, false otherwise /// 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. - 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); } /// @@ -334,10 +341,8 @@ namespace SabreTools.Library.FileTypes /// Input stream to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the archive was written properly, false otherwise - 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 /// Input files to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public override bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false) + public override bool Write(List inputFiles, string outDir, List roms) { throw new NotImplementedException(); } diff --git a/SabreTools.Library/FileTypes/ZPAQArchive.cs b/SabreTools.Library/FileTypes/ZPAQArchive.cs index 5f4d5a25..528a4d51 100644 --- a/SabreTools.Library/FileTypes/ZPAQArchive.cs +++ b/SabreTools.Library/FileTypes/ZPAQArchive.cs @@ -111,11 +111,9 @@ namespace SabreTools.Library.FileTypes /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the write was a success, false otherwise /// 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. - 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 /// Input stream to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the write was a success, false otherwise /// 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. - 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 /// Input files to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public override bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false) + public override bool Write(List inputFiles, string outDir, List roms) { throw new NotImplementedException(); } diff --git a/SabreTools.Library/FileTypes/ZipArchive.cs b/SabreTools.Library/FileTypes/ZipArchive.cs index 30eab327..e43bf1e0 100644 --- a/SabreTools.Library/FileTypes/ZipArchive.cs +++ b/SabreTools.Library/FileTypes/ZipArchive.cs @@ -416,13 +416,11 @@ namespace SabreTools.Library.FileTypes /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the archive was written properly, false otherwise - 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); } /// @@ -431,10 +429,8 @@ namespace SabreTools.Library.FileTypes /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the archive was written properly, false otherwise - 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 /// Input filenames to be moved /// Output directory to build to /// List of Rom representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public override bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false) + public override bool Write(List inputFiles, string outDir, List 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); diff --git a/SabreTools.Library/FileTypes/ZstdArchive.cs b/SabreTools.Library/FileTypes/ZstdArchive.cs index da0010c4..dc7cc2f8 100644 --- a/SabreTools.Library/FileTypes/ZstdArchive.cs +++ b/SabreTools.Library/FileTypes/ZstdArchive.cs @@ -111,11 +111,9 @@ namespace SabreTools.Library.FileTypes /// Input filename to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the write was a success, false otherwise /// 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. - 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 /// Input stream to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// Positive value for depth of the output depot, defaults to 4 /// True if the write was a success, false otherwise /// 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. - 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 /// Input files to be moved /// Output directory to build to /// DatItem representing the new information - /// True if the date from the DAT should be used if available, false otherwise (default) - /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public override bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false) + public override bool Write(List inputFiles, string outDir, List roms) { throw new NotImplementedException(); }