diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index 496d84fc..61e9e844 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -2178,7 +2178,7 @@ namespace SabreTools.Library.DatFiles private void ProcessFile(string item, string basePath, TreatAsFile asFiles) { Globals.Logger.Verbose($"'{Path.GetFileName(item)}' treated like a file"); - BaseFile baseFile = FileExtensions.GetInfo(item, date: true, header: Header.HeaderSkipper, asFiles: asFiles); + BaseFile baseFile = FileExtensions.GetInfo(item, header: Header.HeaderSkipper, asFiles: asFiles); DatItem datItem = DatItem.Create(baseFile); ProcessFileHelper(item, datItem, basePath, string.Empty); } @@ -2508,7 +2508,11 @@ namespace SabreTools.Library.DatFiles if (File.Exists(input)) { Globals.Logger.User($"Checking file: {input}"); - RebuildGenericHelper(input, outDir, quickScan, date, delete, inverse, outputFormat, asFiles); + bool rebuilt = RebuildGenericHelper(input, outDir, quickScan, date, inverse, outputFormat, asFiles); + + // If we are supposed to delete the file, do so + if (delete && rebuilt) + FileExtensions.TryDelete(input); } // If the input is a directory @@ -2518,7 +2522,11 @@ namespace SabreTools.Library.DatFiles foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories)) { Globals.Logger.User($"Checking file: {file}"); - RebuildGenericHelper(file, outDir, quickScan, date, delete, inverse, outputFormat, asFiles); + bool rebuilt = RebuildGenericHelper(file, outDir, quickScan, date, inverse, outputFormat, asFiles); + + // If we are supposed to delete the file, do so + if (delete && rebuilt) + FileExtensions.TryDelete(input); } } } @@ -2537,23 +2545,22 @@ namespace SabreTools.Library.DatFiles /// Output directory to use to build to /// True to enable external scanning of archives, false otherwise /// True if the date from the DAT should be used if available, false otherwise - /// True if input files should be deleted, false otherwise /// True if the DAT should be used as a filter instead of a template, false otherwise /// Output format that files should be written to /// TreatAsFiles representing special format scanning - private void RebuildGenericHelper( + /// True if the file was used to rebuild, false otherwise + private bool RebuildGenericHelper( string file, string outDir, bool quickScan, bool date, - bool delete, bool inverse, OutputFormat outputFormat, TreatAsFile asFiles) { // If we somehow have a null filename, return if (file == null) - return; + return false; // Set the deletion variables bool usedExternally = false, usedInternally = false; @@ -2598,9 +2605,7 @@ namespace SabreTools.Library.DatFiles } } - // If we are supposed to delete the file, do so - if (delete && (usedExternally || usedInternally)) - FileExtensions.TryDelete(file); + return usedExternally || usedInternally; } /// @@ -2947,22 +2952,12 @@ namespace SabreTools.Library.DatFiles /// /// Verify a DatFile against a set of inputs, leaving only missing files /// - /// List of input directories to compare against /// True if only hashes should be checked, false for full file information - /// True to enable external scanning of archives, false otherwise - /// TreatAsFiles representing CHD and Archive scanning /// True if verification was a success, false otherwise - public bool VerifyGeneric(List inputs, bool hashOnly, bool quickScan, TreatAsFile asFiles = 0x00) + public bool VerifyGeneric(bool hashOnly) { bool success = true; - // Loop through and check each of the inputs - Globals.Logger.User("Processing files:\n"); - foreach (string input in inputs) - { - PopulateFromDir(input, asFiles: asFiles, quickScan: quickScan); - } - // Force bucketing according to the flags Items.SetBucketedBy(Field.NULL); if (hashOnly) @@ -2977,8 +2972,8 @@ namespace SabreTools.Library.DatFiles List items = Items[key]; for (int i = 0; i < items.Count; i++) { - // Unmatched items will have a source ID of 99, remove all others - if (items[i].Source.Index != 99) + // Unmatched items will have a source ID of int.MaxValue, remove all others + if (items[i].Source.Index != int.MaxValue) items[i].Remove = true; } diff --git a/SabreTools/Features/Sort.cs b/SabreTools/Features/Sort.cs index e340c54a..4a0486bf 100644 --- a/SabreTools/Features/Sort.cs +++ b/SabreTools/Features/Sort.cs @@ -90,7 +90,7 @@ namespace SabreTools.Features foreach (ParentablePath datfile in datfilePaths) { DatFile datdata = DatFile.Create(); - datdata.Parse(datfile, 99, keep: true); + datdata.Parse(datfile, int.MaxValue, keep: true); // Set depot information datdata.Header.InputDepot = Header.InputDepot.Clone() as DepotInformation; @@ -128,7 +128,7 @@ namespace SabreTools.Features DatFile datdata = DatFile.Create(); foreach (ParentablePath datfile in datfilePaths) { - datdata.Parse(datfile, 99, keep: true); + datdata.Parse(datfile, int.MaxValue, keep: true); } // Set depot information diff --git a/SabreTools/Features/Verify.cs b/SabreTools/Features/Verify.cs index 4d27f62a..669d2e01 100644 --- a/SabreTools/Features/Verify.cs +++ b/SabreTools/Features/Verify.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; +using SabreTools.Library.Data; using SabreTools.Library.DatFiles; using SabreTools.Library.Help; using SabreTools.Library.IO; @@ -57,7 +58,7 @@ namespace SabreTools.Features { // Parse in from the file DatFile datdata = DatFile.Create(); - datdata.Parse(datfile, 99, keep: true); + datdata.Parse(datfile, int.MaxValue, keep: true); // Perform additional processing steps datdata.ApplyExtras(Extras); @@ -74,9 +75,20 @@ namespace SabreTools.Features // If we have the depot flag, respect it if (Header.InputDepot?.IsActive ?? false) + { datdata.VerifyDepot(Inputs); + } else - datdata.VerifyGeneric(Inputs, hashOnly, quickScan, asFiles); + { + // Loop through and add the inputs to check against + Globals.Logger.User("Processing files:\n"); + foreach (string input in Inputs) + { + datdata.PopulateFromDir(input, asFiles: asFiles, quickScan: quickScan); + } + + datdata.VerifyGeneric(hashOnly); + } // Now write out if there are any items left datdata.WriteStatsToConsole(); @@ -92,7 +104,7 @@ namespace SabreTools.Features DatFile datdata = DatFile.Create(); foreach (ParentablePath datfile in datfilePaths) { - datdata.Parse(datfile, 99, keep: true); + datdata.Parse(datfile, int.MaxValue, keep: true); } // Perform additional processing steps @@ -112,9 +124,20 @@ namespace SabreTools.Features // If we have the depot flag, respect it if (Header.InputDepot?.IsActive ?? false) + { datdata.VerifyDepot(Inputs); + } else - datdata.VerifyGeneric(Inputs, hashOnly, quickScan, asFiles); + { + // Loop through and add the inputs to check against + Globals.Logger.User("Processing files:\n"); + foreach (string input in Inputs) + { + datdata.PopulateFromDir(input, asFiles: asFiles, quickScan: quickScan); + } + + datdata.VerifyGeneric(hashOnly); + } // Now write out if there are any items left datdata.WriteStatsToConsole();