From a4dad289a367fc026cb28fbe2143645a7147fc19 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 3 May 2017 14:11:38 -0700 Subject: [PATCH] [DatFile] Add flag for DFD filtering (archive / file) --- SabreTools.Helper/Data/Enums.cs | 10 +++++++ .../Dats/Partials/DatFile.DFD.cs | 27 ++++++++++++------- SabreTools.Helper/README.1ST | 6 +++++ SabreTools/Partials/SabreTools.Help.cs | 10 +++++++ SabreTools/Partials/SabreTools.Inits.cs | 4 ++- SabreTools/SabreTools.cs | 11 +++++++- 6 files changed, 57 insertions(+), 11 deletions(-) diff --git a/SabreTools.Helper/Data/Enums.cs b/SabreTools.Helper/Data/Enums.cs index 3792aeab..6bc1efc6 100644 --- a/SabreTools.Helper/Data/Enums.cs +++ b/SabreTools.Helper/Data/Enums.cs @@ -243,6 +243,16 @@ Unzip, } + /// + /// Determines which files should be skipped in DFD + /// + public enum SkipFileType + { + None = 0, + Archive, + File, + } + /// /// Determines how the current dictionary is sorted by /// diff --git a/SabreTools.Helper/Dats/Partials/DatFile.DFD.cs b/SabreTools.Helper/Dats/Partials/DatFile.DFD.cs index 9c91ef7c..a6c26230 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.DFD.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.DFD.cs @@ -30,14 +30,15 @@ namespace SabreTools.Helper.Dats /// True if the date should be omitted from the DAT, false otherwise /// True if archives should be treated as files, false otherwise /// True if GZIP archives should be treated as files, false otherwise + /// Type of files that should be skipped /// True if blank items should be created for empty folders, false otherwise /// True if dates should be archived for all files, false otherwise /// Name of the directory to create a temp folder in (blank is current directory) /// Output directory to /// True if files should be copied to the temp directory before hashing, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise - public bool PopulateFromDir(string basePath, Hash omitFromScan, bool bare, bool archivesAsFiles, - bool enableGzip, bool addBlanks, bool addDate, string tempDir, bool copyFiles, string headerToCheckAgainst) + public bool PopulateFromDir(string basePath, Hash omitFromScan, bool bare, bool archivesAsFiles, bool enableGzip, + SkipFileType skipFileType, bool addBlanks, bool addDate, string tempDir, bool copyFiles, string headerToCheckAgainst) { // If the description is defined but not the name, set the name from the description if (String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Description)) @@ -67,8 +68,8 @@ namespace SabreTools.Helper.Dats List files = Directory.EnumerateFiles(basePath, "*", SearchOption.TopDirectoryOnly).ToList(); Parallel.ForEach(files, Globals.ParallelOptions, item => { - PopulateFromDirCheckFile(item, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate, - tempDir, copyFiles, headerToCheckAgainst); + PopulateFromDirCheckFile(item, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, skipFileType, + addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst); }); // Find all top-level subfolders @@ -78,8 +79,8 @@ namespace SabreTools.Helper.Dats List subfiles = Directory.EnumerateFiles(item, "*", SearchOption.AllDirectories).ToList(); Parallel.ForEach(subfiles, Globals.ParallelOptions, subitem => { - PopulateFromDirCheckFile(subitem, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate, - tempDir, copyFiles, headerToCheckAgainst); + PopulateFromDirCheckFile(subitem, basePath, omitFromScan, bare, archivesAsFiles, enableGzip, skipFileType, + addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst); }); }); @@ -135,8 +136,8 @@ namespace SabreTools.Helper.Dats } else if (File.Exists(basePath)) { - PopulateFromDirCheckFile(basePath, Path.GetDirectoryName(Path.GetDirectoryName(basePath)), omitFromScan, bare, archivesAsFiles, enableGzip, addBlanks, addDate, - tempDir, copyFiles, headerToCheckAgainst); + PopulateFromDirCheckFile(basePath, Path.GetDirectoryName(Path.GetDirectoryName(basePath)), omitFromScan, bare, archivesAsFiles, enableGzip, + skipFileType, addBlanks, addDate, tempDir, copyFiles, headerToCheckAgainst); } // Now that we're done, delete the temp folder (if it's not the default) @@ -158,13 +159,14 @@ namespace SabreTools.Helper.Dats /// True if the date should be omitted from the DAT, false otherwise /// True if archives should be treated as files, false otherwise /// True if GZIP archives should be treated as files, false otherwise + /// Type of files that should be skipped /// True if blank items should be created for empty folders, false otherwise /// True if dates should be archived for all files, false otherwise /// Name of the directory to create a temp folder in (blank is current directory) /// True if files should be copied to the temp directory before hashing, false otherwise /// Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise private void PopulateFromDirCheckFile(string item, string basePath, Hash omitFromScan, bool bare, bool archivesAsFiles, - bool enableGzip, bool addBlanks, bool addDate, string tempDir, bool copyFiles, string headerToCheckAgainst) + bool enableGzip, SkipFileType skipFileType, bool addBlanks, bool addDate, string tempDir, bool copyFiles, string headerToCheckAgainst) { // Define the temporary directory string tempSubDir = Path.GetFullPath(Path.Combine(tempDir, Path.GetRandomFileName())) + Path.DirectorySeparatorChar; @@ -225,6 +227,13 @@ namespace SabreTools.Helper.Dats } } + // If the file should be skipped based on type, do so now + if ((extracted != null && skipFileType == SkipFileType.Archive) + || (extracted == null && skipFileType == SkipFileType.File)) + { + return; + } + // If the extracted list is null, just scan the item itself if (extracted == null || archivesAsFiles) { diff --git a/SabreTools.Helper/README.1ST b/SabreTools.Helper/README.1ST index 432412d0..e8dcbbb0 100644 --- a/SabreTools.Helper/README.1ST +++ b/SabreTools.Helper/README.1ST @@ -248,6 +248,12 @@ Options: implies that the files will be in the TorrentGZ format as well, including naming convention. + -ska, --skiparc Skip archive files + Skip any files that are treated like archives + + -skf, --skipfile Skip non-archive files + Skip any files that are not treated like archives + -f=, --filename= Set the external name of the DAT Set the base filename for the output DAT(s) [default is folder name plus date] diff --git a/SabreTools/Partials/SabreTools.Help.cs b/SabreTools/Partials/SabreTools.Help.cs index e7b54133..c2707988 100644 --- a/SabreTools/Partials/SabreTools.Help.cs +++ b/SabreTools/Partials/SabreTools.Help.cs @@ -185,6 +185,16 @@ namespace SabreTools "Read files from a Romba input", FeatureType.Flag, null)); + datFromDir.AddFeature("skiparc", new Feature( + new List() { "-ska", "--skiparc" }, + "Skip any files that are treated like archives", + FeatureType.Flag, + null)); + datFromDir.AddFeature("skipfile", new Feature( + new List() { "-skf", "--skipfile" }, + "Skip any files that are not treated like archives", + FeatureType.Flag, + null)); datFromDir.AddFeature("filename", new Feature( new List() { "-f", "--filename" }, "Set the external name of the DAT", diff --git a/SabreTools/Partials/SabreTools.Inits.cs b/SabreTools/Partials/SabreTools.Inits.cs index 822ada29..bf380e0f 100644 --- a/SabreTools/Partials/SabreTools.Inits.cs +++ b/SabreTools/Partials/SabreTools.Inits.cs @@ -45,6 +45,7 @@ namespace SabreTools /// True if the date should be omitted from the DAT, false otherwise /// True if archives should be treated as files, false otherwise /// True if GZIP archives should be treated as files, false otherwise + /// Type of files that should be skipped on scan /// True if blank items should be created for empty folders, false otherwise /// True if dates should be archived for all files, false otherwise /// /* Output DAT info */ @@ -75,6 +76,7 @@ namespace SabreTools bool removeDateFromAutomaticName, bool parseArchivesAsFiles, bool enableGzip, + SkipFileType skipFileType, bool addBlankFilesForEmptyFolder, bool addFileDates, @@ -133,7 +135,7 @@ namespace SabreTools string basePath = Path.GetFullPath(path); bool success = datdata.PopulateFromDir(basePath, omitFromScan, removeDateFromAutomaticName, parseArchivesAsFiles, enableGzip, - addBlankFilesForEmptyFolder, addFileDates, tempDir, copyFiles, headerToCheckAgainst); + skipFileType, addBlankFilesForEmptyFolder, addFileDates, tempDir, copyFiles, headerToCheckAgainst); // If it was a success, write the DAT out if (success) diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index 2e8d2c78..be466791 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -126,6 +126,7 @@ namespace SabreTools Hash omitFromScan = Hash.SHA256 | Hash.SHA384 | Hash.SHA512; // Should be set to 0x0 later Hash stripHash = 0x0; OutputFormat outputFormat = OutputFormat.Folder; + SkipFileType skipFileType = SkipFileType.None; SplitType splitType = SplitType.None; StatDatFormat statDatFormat = 0x0; @@ -562,6 +563,14 @@ namespace SabreTools case "--single": single = true; break; + case "-ska": + case "--skiparc": + skipFileType = SkipFileType.Archive; + break; + case "-skf": + case "--skipfile": + skipFileType = SkipFileType.File; + break; case "-t7z": case "--t7z": outputFormat = OutputFormat.Torrent7Zip; @@ -1209,7 +1218,7 @@ namespace SabreTools { InitDatFromDir(inputs, filename, name, description, category, version, author, email, homepage, url, comment, forcepack, excludeOf, datFormat, romba, superdat, omitFromScan, removeDateFromAutomaticName, parseArchivesAsFiles, - enableGzip, addBlankFilesForEmptyFolder, addFileDates, tempDir, outDir, copyFiles, header); + enableGzip, skipFileType, addBlankFilesForEmptyFolder, addFileDates, tempDir, outDir, copyFiles, header); } // If we're in header extract and remove mode