mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Add flag for DFD filtering (archive / file)
This commit is contained in:
@@ -243,6 +243,16 @@
|
||||
Unzip,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines which files should be skipped in DFD
|
||||
/// </summary>
|
||||
public enum SkipFileType
|
||||
{
|
||||
None = 0,
|
||||
Archive,
|
||||
File,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines how the current dictionary is sorted by
|
||||
/// </summary>
|
||||
|
||||
@@ -30,14 +30,15 @@ namespace SabreTools.Helper.Dats
|
||||
/// <param name="bare">True if the date should be omitted from the DAT, false otherwise</param>
|
||||
/// <param name="archivesAsFiles">True if archives should be treated as files, false otherwise</param>
|
||||
/// <param name="enableGzip">True if GZIP archives should be treated as files, false otherwise</param>
|
||||
/// <param name="skipFileType">Type of files that should be skipped</param>
|
||||
/// <param name="addBlanks">True if blank items should be created for empty folders, false otherwise</param>
|
||||
/// <param name="addDate">True if dates should be archived for all files, false otherwise</param>
|
||||
/// <param name="tempDir">Name of the directory to create a temp folder in (blank is current directory)</param>
|
||||
/// <param name="outDir">Output directory to </param>
|
||||
/// <param name="copyFiles">True if files should be copied to the temp directory before hashing, false otherwise</param>
|
||||
/// <param name="headerToCheckAgainst">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param>
|
||||
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<string> 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<string> 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
|
||||
/// <param name="bare">True if the date should be omitted from the DAT, false otherwise</param>
|
||||
/// <param name="archivesAsFiles">True if archives should be treated as files, false otherwise</param>
|
||||
/// <param name="enableGzip">True if GZIP archives should be treated as files, false otherwise</param>
|
||||
/// <param name="skipFileType">Type of files that should be skipped</param>
|
||||
/// <param name="addBlanks">True if blank items should be created for empty folders, false otherwise</param>
|
||||
/// <param name="addDate">True if dates should be archived for all files, false otherwise</param>
|
||||
/// <param name="tempDir">Name of the directory to create a temp folder in (blank is current directory)</param>
|
||||
/// <param name="copyFiles">True if files should be copied to the temp directory before hashing, false otherwise</param>
|
||||
/// <param name="headerToCheckAgainst">Populated string representing the name of the skipper to use, a blank string to use the first available checker, null otherwise</param>
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -185,6 +185,16 @@ namespace SabreTools
|
||||
"Read files from a Romba input",
|
||||
FeatureType.Flag,
|
||||
null));
|
||||
datFromDir.AddFeature("skiparc", new Feature(
|
||||
new List<string>() { "-ska", "--skiparc" },
|
||||
"Skip any files that are treated like archives",
|
||||
FeatureType.Flag,
|
||||
null));
|
||||
datFromDir.AddFeature("skipfile", new Feature(
|
||||
new List<string>() { "-skf", "--skipfile" },
|
||||
"Skip any files that are not treated like archives",
|
||||
FeatureType.Flag,
|
||||
null));
|
||||
datFromDir.AddFeature("filename", new Feature(
|
||||
new List<string>() { "-f", "--filename" },
|
||||
"Set the external name of the DAT",
|
||||
|
||||
@@ -45,6 +45,7 @@ namespace SabreTools
|
||||
/// <param name="removeDateFromAutomaticName">True if the date should be omitted from the DAT, false otherwise</param>
|
||||
/// <param name="parseArchivesAsFiles">True if archives should be treated as files, false otherwise</param>
|
||||
/// <param name="enableGzip">True if GZIP archives should be treated as files, false otherwise</param>
|
||||
/// <param name="skipFileType">Type of files that should be skipped on scan</param>
|
||||
/// <param name="addBlankFilesForEmptyFolder">True if blank items should be created for empty folders, false otherwise</param>
|
||||
/// <param name="addFileDates">True if dates should be archived for all files, false otherwise</param>
|
||||
/// /* 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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user