From 9856426ccefe13f29b234e4b1a1419e0af98230c Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 31 Oct 2017 16:37:36 -0700 Subject: [PATCH] [SabreTools, DatFile, README.1ST] Remove temp directory from sort and verify --- SabreTools.Library/DatFiles/DatFile.cs | 110 +++---------------------- SabreTools.Library/README.1ST | 20 ----- SabreTools/SabreTools.Help.cs | 10 --- SabreTools/SabreTools.Inits.cs | 23 ++---- SabreTools/SabreTools.cs | 8 +- 5 files changed, 26 insertions(+), 145 deletions(-) diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index df96ed88..e56efa0a 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -3876,7 +3876,6 @@ namespace SabreTools.Library.DatFiles /// /// List of input files/folders to check /// Output directory to use to build to - /// Temporary directory for archive extraction /// 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 @@ -3885,7 +3884,7 @@ namespace SabreTools.Library.DatFiles /// True if the updated DAT should be output, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// True if rebuilding was a success, false otherwise - public bool RebuildDepot(List inputs, string outDir, string tempDir, bool date, bool delete, + public bool RebuildDepot(List inputs, string outDir, bool date, bool delete, bool inverse, OutputFormat outputFormat, bool romba, bool updateDat, string headerToCheckAgainst) { #region Perform setup @@ -3904,22 +3903,6 @@ namespace SabreTools.Library.DatFiles outDir = Path.GetFullPath(outDir); } - // Check the temp directory - if (String.IsNullOrEmpty(tempDir)) - { - tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - } - - // Then create or clean the temp directory - if (!Directory.Exists(tempDir)) - { - Directory.CreateDirectory(tempDir); - } - else - { - FileTools.CleanDirectory(tempDir); - } - // Now we want to get forcepack flag if it's not overridden if (outputFormat == OutputFormat.Folder && ForcePacking != ForcePacking.None) { @@ -4040,7 +4023,7 @@ namespace SabreTools.Library.DatFiles } // Otherwise, we rebuild that file to all locations that we need to - RebuildIndividualFile(fileinfo, foundpath, outDir, tempDir, date, inverse, outputFormat, romba, + RebuildIndividualFile(fileinfo, foundpath, outDir, date, inverse, outputFormat, romba, updateDat, false /* isZip */, headerToCheckAgainst); } @@ -4066,7 +4049,6 @@ namespace SabreTools.Library.DatFiles /// /// List of input files/folders to check /// Output directory to use to build to - /// Temporary directory for archive extraction /// 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 @@ -4078,7 +4060,7 @@ namespace SabreTools.Library.DatFiles /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// True if CHDs should be treated like regular files, false otherwise /// True if rebuilding was a success, false otherwise - public bool RebuildGeneric(List inputs, string outDir, string tempDir, bool quickScan, bool date, + public bool RebuildGeneric(List inputs, string outDir, bool quickScan, bool date, bool delete, bool inverse, OutputFormat outputFormat, bool romba, ArchiveScanLevel archiveScanLevel, bool updateDat, string headerToCheckAgainst, bool ignorechd) { @@ -4098,22 +4080,6 @@ namespace SabreTools.Library.DatFiles outDir = Path.GetFullPath(outDir); } - // Check the temp directory - if (String.IsNullOrEmpty(tempDir)) - { - tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - } - - // Then create or clean the temp directory - if (!Directory.Exists(tempDir)) - { - Directory.CreateDirectory(tempDir); - } - else - { - FileTools.CleanDirectory(tempDir); - } - // Now we want to get forcepack flag if it's not overridden if (outputFormat == OutputFormat.Folder && ForcePacking != ForcePacking.None) { @@ -4175,7 +4141,7 @@ namespace SabreTools.Library.DatFiles if (File.Exists(input)) { Globals.Logger.User("Checking file: {0}", input); - RebuildGenericHelper(input, outDir, tempDir, quickScan, date, delete, inverse, + RebuildGenericHelper(input, outDir, quickScan, date, delete, inverse, outputFormat, romba, archiveScanLevel, updateDat, headerToCheckAgainst, ignorechd); } @@ -4186,7 +4152,7 @@ namespace SabreTools.Library.DatFiles foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories)) { Globals.Logger.User("Checking file: {0}", file); - RebuildGenericHelper(file, outDir, tempDir, quickScan, date, delete, inverse, + RebuildGenericHelper(file, outDir, quickScan, date, delete, inverse, outputFormat, romba, archiveScanLevel, updateDat, headerToCheckAgainst, ignorechd); } } @@ -4214,7 +4180,6 @@ namespace SabreTools.Library.DatFiles /// /// Name of the file to process /// Output directory to use to build to - /// Temporary directory for archive extraction /// 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 @@ -4225,7 +4190,7 @@ namespace SabreTools.Library.DatFiles /// True if the updated DAT should be output, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// True if CHDs should be treated like regular files, false otherwise - private void RebuildGenericHelper(string file, string outDir, string tempDir, bool quickScan, bool date, + private void RebuildGenericHelper(string file, string outDir, bool quickScan, bool date, bool delete, bool inverse, OutputFormat outputFormat, bool romba, ArchiveScanLevel archiveScanLevel, bool updateDat, string headerToCheckAgainst, bool ignorechd) { @@ -4235,9 +4200,6 @@ namespace SabreTools.Library.DatFiles return; } - // Define the temporary directory - string tempSubDir = Path.GetFullPath(Path.Combine(tempDir, Path.GetRandomFileName())) + Path.DirectorySeparatorChar; - // Set the deletion variables bool usedExternally = false; bool usedInternally = false; @@ -4251,7 +4213,7 @@ namespace SabreTools.Library.DatFiles // TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually DatItem fileinfo = FileTools.GetFileInfo(file, omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes), header: headerToCheckAgainst, ignorechd: ignorechd); - usedExternally = RebuildIndividualFile(fileinfo, file, outDir, tempSubDir, date, inverse, outputFormat, + usedExternally = RebuildIndividualFile(fileinfo, file, outDir, date, inverse, outputFormat, romba, updateDat, null /* isZip */, headerToCheckAgainst); } @@ -4282,7 +4244,7 @@ namespace SabreTools.Library.DatFiles { // TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually DatItem fileinfo = FileTools.GetFileInfo(file, omitFromScan: (quickScan ? Hash.SecureHashes : Hash.DeepHashes), ignorechd: ignorechd); - usedExternally = RebuildIndividualFile(fileinfo, file, outDir, tempSubDir, date, inverse, outputFormat, + usedExternally = RebuildIndividualFile(fileinfo, file, outDir, date, inverse, outputFormat, romba, updateDat, null /* isZip */, headerToCheckAgainst); } // Otherwise, loop through the entries and try to match @@ -4290,7 +4252,7 @@ namespace SabreTools.Library.DatFiles { foreach (Rom entry in entries) { - usedInternally &= RebuildIndividualFile(entry, file, outDir, tempSubDir, date, inverse, outputFormat, + usedInternally &= RebuildIndividualFile(entry, file, outDir, date, inverse, outputFormat, romba, updateDat, !isTorrentGzip /* isZip */, headerToCheckAgainst); } } @@ -4301,9 +4263,6 @@ namespace SabreTools.Library.DatFiles { FileTools.TryDeleteFile(file); } - - // Now delete the temp directory - FileTools.TryDeleteDirectory(tempSubDir); } /// @@ -4312,7 +4271,6 @@ namespace SabreTools.Library.DatFiles /// Information for the current file to rebuild from /// Name of the file to process /// Output directory to use to build to - /// Temporary directory for archive extraction /// True if the date from the DAT should be used if available, 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 @@ -4321,7 +4279,7 @@ namespace SabreTools.Library.DatFiles /// True if the input file is an archive, false if the file is TGZ, null otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// True if the file was able to be rebuilt, false otherwise - private bool RebuildIndividualFile(DatItem datItem, string file, string outDir, string tempDir, bool date, + private bool RebuildIndividualFile(DatItem datItem, string file, string outDir, bool date, bool inverse, OutputFormat outputFormat, bool romba, bool updateDat, bool? isZip, string headerToCheckAgainst) { // Set the output value @@ -4696,12 +4654,6 @@ namespace SabreTools.Library.DatFiles fileStream?.Dispose(); } - // And now clear the temp folder to get rid of any transient files if we unzipped - if (isZip == true) - { - FileTools.TryDeleteDirectory(tempDir); - } - return rebuilt; } @@ -4709,29 +4661,10 @@ namespace SabreTools.Library.DatFiles /// Process the DAT and verify from the depots /// /// List of input directories to compare against - /// Temporary directory for archive extraction - /// True if only hashes should be checked, false for full file information - /// True to enable external scanning of archives, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// True if verification was a success, false otherwise - public bool VerifyDepot(List inputs, string tempDir, string headerToCheckAgainst) + public bool VerifyDepot(List inputs, string headerToCheckAgainst) { - // Check the temp directory - if (String.IsNullOrEmpty(tempDir)) - { - tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - } - - // Then create or clean the temp directory - if (!Directory.Exists(tempDir)) - { - Directory.CreateDirectory(tempDir); - } - else - { - FileTools.CleanDirectory(tempDir); - } - bool success = true; InternalStopwatch watch = new InternalStopwatch("Verifying all from supplied depots"); @@ -4817,30 +4750,13 @@ namespace SabreTools.Library.DatFiles /// Process the DAT and verify the output directory /// /// List of input directories to compare against - /// Temporary directory for archive extraction /// True if only hashes should be checked, false for full file information /// True to enable external scanning of archives, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// True if CHDs should be treated like regular files, false otherwise /// True if verification was a success, false otherwise - public bool VerifyGeneric(List inputs, string tempDir, bool hashOnly, bool quickScan, string headerToCheckAgainst, bool ignorechd) + public bool VerifyGeneric(List inputs, bool hashOnly, bool quickScan, string headerToCheckAgainst, bool ignorechd) { - // Check the temp directory exists - if (String.IsNullOrEmpty(tempDir)) - { - tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - } - - // Then create or clean the temp directory - if (!Directory.Exists(tempDir)) - { - Directory.CreateDirectory(tempDir); - } - else - { - FileTools.CleanDirectory(tempDir); - } - // TODO: We want the cross section of what's the folder and what's in the DAT. Right now, it just has what's in the DAT that's not in the folder bool success = true; @@ -4850,7 +4766,7 @@ namespace SabreTools.Library.DatFiles { // TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually PopulateFromDir(input, (quickScan ? Hash.SecureHashes : Hash.DeepHashes) /* omitFromScan */, true /* bare */, false /* archivesAsFiles */, - true /* enableGzip */, SkipFileType.None, false /* addBlanks */, false /* addDate */, tempDir /* tempDir */, false /* copyFiles */, + true /* enableGzip */, SkipFileType.None, false /* addBlanks */, false /* addDate */, "" /* tempDir */, false /* copyFiles */, headerToCheckAgainst, ignorechd); } diff --git a/SabreTools.Library/README.1ST b/SabreTools.Library/README.1ST index a4a6b635..02ec43b9 100644 --- a/SabreTools.Library/README.1ST +++ b/SabreTools.Library/README.1ST @@ -482,11 +482,6 @@ Options: This sets an output folder to be used when the files are created. If a path is not defined, the application directory is used instead. - -t=, --temp= Set the name of the temporary directory - Optionally, a temp folder can be supplied in the case the default - temp directory (inside the running folder) is not preferred. This is - used for any operations that require an archive to be extracted. - -d, --delete Delete fully rebuilt input files Optionally, the input files, once processed and fully matched, can be deleted. This can be useful when the original file structure is @@ -647,11 +642,6 @@ Options: This sets an output folder to be used when the files are created. If a path is not defined, the application directory is used instead. - -t=, --temp= Set the name of the temporary directory - Optionally, a temp folder can be supplied in the case the default - temp directory (inside the running folder) is not preferred. This is - used for any operations that require an archive to be extracted. - -d, --delete Delete fully rebuilt input files Optionally, the input files, once processed and fully matched, can be deleted. This can be useful when the original file structure is @@ -1295,11 +1285,6 @@ Options: The user-supplied DAT used to check which files need to be verified. Multiple occurrences of this flag are allowed. - -t=, --temp= Set the name of the temporary directory - Optionally, a temp folder can be supplied in the case the default - temp directory (inside the running folder) is not preferred. This is - used for any operations that require an archive to be extracted. - -ho, --hash-only Check files by hash only This sets a mode where files are not checked based on name but rather hash alone. This allows verification of (possibly) @@ -1355,11 +1340,6 @@ Options: The user-supplied DAT used to check which files need to be verified. Multiple occurrences of this flag are allowed. - -t=, --temp= Set the name of the temporary directory - Optionally, a temp folder can be supplied in the case the default - temp directory (inside the running folder) is not preferred. This is - used for any operations that require an archive to be extracted. - -h=, --header= Remove headers from hash calculations If this is set, then all files that have copier headers that are detected will have them removed from the hash calculation. This will diff --git a/SabreTools/SabreTools.Help.cs b/SabreTools/SabreTools.Help.cs index a04f2640..8091612a 100644 --- a/SabreTools/SabreTools.Help.cs +++ b/SabreTools/SabreTools.Help.cs @@ -409,11 +409,6 @@ namespace SabreTools "Output directory", FeatureType.String, null)); - sort.AddFeature("temp", new Feature( - new List() { "-temp", "--temp" }, - "Set the temporary directory to use", - FeatureType.String, - null)); sort.AddFeature("delete", new Feature( new List() { "-del", "--delete" }, "Delete fully rebuilt input files", @@ -560,11 +555,6 @@ namespace SabreTools "Output directory", FeatureType.String, null)); - sortDepot.AddFeature("temp", new Feature( - new List() { "-temp", "--temp" }, - "Set the temporary directory to use", - FeatureType.String, - null)); sortDepot.AddFeature("delete", new Feature( new List() { "-del", "--delete" }, "Delete fully rebuilt input files", diff --git a/SabreTools/SabreTools.Inits.cs b/SabreTools/SabreTools.Inits.cs index 8f7996c0..1ffafa41 100644 --- a/SabreTools/SabreTools.Inits.cs +++ b/SabreTools/SabreTools.Inits.cs @@ -320,7 +320,6 @@ namespace SabreTools /// Names of the DATs to compare against /// List of input files/folders to check /// Output directory to use to build to - /// Temporary directory for archive extraction /// 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 @@ -335,7 +334,7 @@ namespace SabreTools /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// Type of the split that should be performed (split, merged, fully merged) /// True if CHDs should be treated like regular files, false otherwise - private static void InitSort(List datfiles, List inputs, string outDir, string tempDir, bool quickScan, bool date, bool delete, + private static void InitSort(List datfiles, List inputs, string outDir, bool quickScan, bool date, bool delete, bool inverse, OutputFormat outputFormat, bool romba, int sevenzip, int gz, int rar, int zip, bool updateDat, string headerToCheckAgainst, SplitType splitType, bool ignorechd) { @@ -356,7 +355,7 @@ namespace SabreTools watch.Stop(); - datdata.RebuildGeneric(inputs, outDir, tempDir, quickScan, date, delete, inverse, outputFormat, romba, asl, + datdata.RebuildGeneric(inputs, outDir, quickScan, date, delete, inverse, outputFormat, romba, asl, updateDat, headerToCheckAgainst, ignorechd); } @@ -366,7 +365,6 @@ namespace SabreTools /// Names of the DATs to compare against /// List of input files/folders to check /// Output directory to use to build to - /// Temporary directory for archive extraction /// 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 @@ -375,7 +373,7 @@ namespace SabreTools /// True if the updated DAT should be output, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// Type of the split that should be performed (split, merged, fully merged) - private static void InitSortDepot(List datfiles, List inputs, string outDir, string tempDir, bool date, bool delete, + private static void InitSortDepot(List datfiles, List inputs, string outDir, bool date, bool delete, bool inverse, OutputFormat outputFormat, bool romba, bool updateDat, string headerToCheckAgainst, SplitType splitType) { InternalStopwatch watch = new InternalStopwatch("Populating internal DAT"); @@ -392,7 +390,7 @@ namespace SabreTools watch.Stop(); - datdata.RebuildDepot(inputs, outDir, tempDir, date, delete, inverse, outputFormat, romba, + datdata.RebuildDepot(inputs, outDir, date, delete, inverse, outputFormat, romba, updateDat, headerToCheckAgainst); } @@ -743,14 +741,13 @@ namespace SabreTools /// /// Names of the DATs to compare against /// Input directories to compare against - /// Temporary directory for archive extraction /// True if only hashes should be checked, false for full file information /// True to enable external scanning of archives, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// Type of the split that should be performed (split, merged, fully merged) /// True if CHDs should be treated like regular files, false otherwise - private static void InitVerify(List datfiles, List inputs, string tempDir, - bool hashOnly, bool quickScan, string headerToCheckAgainst, SplitType splitType, bool ignorechd) + private static void InitVerify(List datfiles, List inputs, bool hashOnly, bool quickScan, + string headerToCheckAgainst, SplitType splitType, bool ignorechd) { // Get the archive scanning level ArchiveScanLevel asl = ArchiveTools.GetArchiveScanLevelFromNumbers(1, 1, 1, 1); @@ -769,7 +766,7 @@ namespace SabreTools watch.Stop(); - datdata.VerifyGeneric(inputs, tempDir, hashOnly, quickScan, headerToCheckAgainst, ignorechd); + datdata.VerifyGeneric(inputs, hashOnly, quickScan, headerToCheckAgainst, ignorechd); } /// @@ -777,11 +774,9 @@ namespace SabreTools /// /// Names of the DATs to compare against /// Input directories to compare against - /// Temporary directory for archive extraction /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise /// Type of the split that should be performed (split, merged, fully merged) - private static void InitVerifyDepot(List datfiles, List inputs, string tempDir, - string headerToCheckAgainst, SplitType splitType) + private static void InitVerifyDepot(List datfiles, List inputs, string headerToCheckAgainst, SplitType splitType) { InternalStopwatch watch = new InternalStopwatch("Populating internal DAT"); @@ -797,7 +792,7 @@ namespace SabreTools watch.Stop(); - datdata.VerifyDepot(inputs, tempDir, headerToCheckAgainst); + datdata.VerifyDepot(inputs, headerToCheckAgainst); } #endregion diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index 9c2c59cb..80a77320 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -1278,14 +1278,14 @@ namespace SabreTools // If we're using the sorter else if (sort) { - InitSort(datfiles, inputs, outDir, tempDir, quickScan, addFileDates, delete, inverse, + InitSort(datfiles, inputs, outDir, quickScan, addFileDates, delete, inverse, outputFormat, romba, sevenzip, gz, rar, zip, updateDat, header, splitType, ignorechd); } // If we're using the sorter from depot else if (sortDepot) { - InitSortDepot(datfiles, inputs, outDir, tempDir, addFileDates, delete, inverse, + InitSortDepot(datfiles, inputs, outDir, addFileDates, delete, inverse, outputFormat, romba, updateDat, header, splitType); } @@ -1331,13 +1331,13 @@ namespace SabreTools // If we're using the verifier else if (verify) { - InitVerify(datfiles, inputs, tempDir, hashOnly, quickScan, header, splitType, ignorechd); + InitVerify(datfiles, inputs, hashOnly, quickScan, header, splitType, ignorechd); } // If we're using the depot verifier else if (verifyDepot) { - InitVerifyDepot(datfiles, inputs, tempDir, header, splitType); + InitVerifyDepot(datfiles, inputs, header, splitType); } // If nothing is set, show the help