mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Move TreatAsFile up a library layer
This commit is contained in:
@@ -128,24 +128,24 @@ namespace SabreTools.DatItems
|
||||
/// Create a specific type of DatItem to be used based on a BaseFile
|
||||
/// </summary>
|
||||
/// <param name="baseFile">BaseFile containing information to be created</param>
|
||||
/// <param name="asFiles">TreatAsFiles representing special format scanning</param>
|
||||
/// <param name="asFile">TreatAsFile representing special format scanning</param>
|
||||
/// <returns>DatItem of the specific internal type that corresponds to the inputs</returns>
|
||||
public static DatItem? Create(BaseFile? baseFile, TreatAsFile asFiles = 0x00)
|
||||
public static DatItem? Create(BaseFile? baseFile, TreatAsFile asFile = 0x00)
|
||||
{
|
||||
return baseFile switch
|
||||
{
|
||||
// Disk
|
||||
#if NET20 || NET35
|
||||
FileTypes.CHD.CHDFile when (asFiles & TreatAsFile.CHD) == 0 => new Disk(baseFile),
|
||||
FileTypes.CHD.CHDFile when (asFile & TreatAsFile.CHD) == 0 => new Disk(baseFile),
|
||||
#else
|
||||
FileTypes.CHD.CHDFile when !asFiles.HasFlag(TreatAsFile.CHD) => new Disk(baseFile),
|
||||
FileTypes.CHD.CHDFile when !asFile.HasFlag(TreatAsFile.CHD) => new Disk(baseFile),
|
||||
#endif
|
||||
|
||||
// Media
|
||||
#if NET20 || NET35
|
||||
FileTypes.Aaru.AaruFormat when (asFiles & TreatAsFile.AaruFormat) == 0 => new Media(baseFile),
|
||||
FileTypes.Aaru.AaruFormat when (asFile & TreatAsFile.AaruFormat) == 0 => new Media(baseFile),
|
||||
#else
|
||||
FileTypes.Aaru.AaruFormat when !asFiles.HasFlag(TreatAsFile.AaruFormat) => new Media(baseFile),
|
||||
FileTypes.Aaru.AaruFormat when !asFile.HasFlag(TreatAsFile.AaruFormat) => new Media(baseFile),
|
||||
#endif
|
||||
|
||||
// Rom
|
||||
|
||||
@@ -3,6 +3,21 @@ using SabreTools.Core;
|
||||
|
||||
namespace SabreTools.DatItems
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines what sort of files only use external hashes
|
||||
/// </summary>
|
||||
/// TODO: Can FileType be used instead?
|
||||
[Flags]
|
||||
public enum TreatAsFile
|
||||
{
|
||||
CHD = 1 << 0,
|
||||
Archive = 1 << 1,
|
||||
AaruFormat = 1 << 2,
|
||||
|
||||
NonArchive = CHD | AaruFormat,
|
||||
All = CHD | Archive | AaruFormat,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine the chip type
|
||||
/// </summary>
|
||||
|
||||
@@ -66,8 +66,8 @@ namespace SabreTools.DatTools
|
||||
/// </summary>
|
||||
/// <param name="datFile">Current DatFile object to add to</param>
|
||||
/// <param name="basePath">Base folder to be used in creating the DAT</param>
|
||||
/// <param name="asFiles">TreatAsFiles representing CHD and Archive scanning</param>
|
||||
public bool PopulateFromDir(DatFile datFile, string basePath, TreatAsFile asFiles = 0x00)
|
||||
/// <param name="asFile">TreatAsFile representing CHD and Archive scanning</param>
|
||||
public bool PopulateFromDir(DatFile datFile, string basePath, TreatAsFile asFile = 0x00)
|
||||
{
|
||||
// Set the progress variables
|
||||
long totalSize = 0;
|
||||
@@ -109,7 +109,7 @@ namespace SabreTools.DatTools
|
||||
{
|
||||
currentSize += new FileInfo(item).Length;
|
||||
|
||||
CheckFileForHashes(datFile, item, basePath, asFiles);
|
||||
CheckFileForHashes(datFile, item, basePath, asFile);
|
||||
logger.User(totalSize, currentSize, item);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace SabreTools.DatTools
|
||||
logger.User(totalSize, currentSize);
|
||||
|
||||
string? parentPath = Path.GetDirectoryName(Path.GetDirectoryName(basePath));
|
||||
CheckFileForHashes(datFile, basePath, parentPath, asFiles);
|
||||
CheckFileForHashes(datFile, basePath, parentPath, asFile);
|
||||
logger.User(totalSize, totalSize, basePath);
|
||||
}
|
||||
|
||||
@@ -139,8 +139,8 @@ namespace SabreTools.DatTools
|
||||
/// <param name="datFile">Current DatFile object to add to</param>
|
||||
/// <param name="item">Filename of the item to be checked</param>
|
||||
/// <param name="basePath">Base folder to be used in creating the DAT</param>
|
||||
/// <param name="asFiles">TreatAsFiles representing CHD and Archive scanning</param>
|
||||
private void CheckFileForHashes(DatFile datFile, string item, string? basePath, TreatAsFile asFiles)
|
||||
/// <param name="asFile">TreatAsFile representing CHD and Archive scanning</param>
|
||||
private void CheckFileForHashes(DatFile datFile, string item, string? basePath, TreatAsFile asFile)
|
||||
{
|
||||
// If we're in depot mode, process it separately
|
||||
if (CheckDepotFile(datFile, item))
|
||||
@@ -157,9 +157,9 @@ namespace SabreTools.DatTools
|
||||
|
||||
// Skip if we're treating archives as files and skipping files
|
||||
#if NET20 || NET35
|
||||
if ((asFiles & TreatAsFile.Archive) != 0 && _skipFileType == SkipFileType.File)
|
||||
if ((asFile & TreatAsFile.Archive) != 0 && _skipFileType == SkipFileType.File)
|
||||
#else
|
||||
if (asFiles.HasFlag(TreatAsFile.Archive) && _skipFileType == SkipFileType.File)
|
||||
if (asFile.HasFlag(TreatAsFile.Archive) && _skipFileType == SkipFileType.File)
|
||||
#endif
|
||||
{
|
||||
return;
|
||||
@@ -173,9 +173,9 @@ namespace SabreTools.DatTools
|
||||
|
||||
// Process as archive if we're not treating archives as files
|
||||
#if NET20 || NET35
|
||||
else if ((asFiles & TreatAsFile.Archive) == 0)
|
||||
else if ((asFile & TreatAsFile.Archive) == 0)
|
||||
#else
|
||||
else if (!asFiles.HasFlag(TreatAsFile.Archive))
|
||||
else if (!asFile.HasFlag(TreatAsFile.Archive))
|
||||
#endif
|
||||
{
|
||||
var extracted = archive.GetChildren();
|
||||
@@ -192,7 +192,7 @@ namespace SabreTools.DatTools
|
||||
// Process as file if we're treating archives as files
|
||||
else
|
||||
{
|
||||
ProcessFile(datFile, item, basePath, asFiles);
|
||||
ProcessFile(datFile, item, basePath, asFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ namespace SabreTools.DatTools
|
||||
|
||||
// Process as file
|
||||
else
|
||||
ProcessFile(datFile, item, basePath, asFiles);
|
||||
ProcessFile(datFile, item, basePath, asFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,13 +401,13 @@ namespace SabreTools.DatTools
|
||||
/// <param name="datFile">Current DatFile object to add to</param>
|
||||
/// <param name="item">File to be added</param>
|
||||
/// <param name="basePath">Path the represents the parent directory</param>
|
||||
/// <param name="asFiles">TreatAsFiles representing CHD and Archive scanning</param>
|
||||
private void ProcessFile(DatFile datFile, string item, string? basePath, TreatAsFile asFiles)
|
||||
/// <param name="asFile">TreatAsFile representing CHD and Archive scanning</param>
|
||||
private void ProcessFile(DatFile datFile, string item, string? basePath, TreatAsFile asFile)
|
||||
{
|
||||
logger.Verbose($"'{Path.GetFileName(item)}' treated like a file");
|
||||
var header = datFile.Header.GetStringFieldValue(Models.Metadata.Header.HeaderKey);
|
||||
BaseFile? baseFile = FileTypeTool.GetInfo(item, header, _hashes);
|
||||
DatItem? datItem = DatItem.Create(baseFile, asFiles);
|
||||
DatItem? datItem = DatItem.Create(baseFile, asFile);
|
||||
if (datItem != null)
|
||||
ProcessFileHelper(datFile, item, datItem, basePath, string.Empty);
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace SabreTools.DatTools
|
||||
/// <param name="delete">True if input files should be deleted, false otherwise</param>
|
||||
/// <param name="inverse">True if the DAT should be used as a filter instead of a template, false otherwise</param>
|
||||
/// <param name="outputFormat">Output format that files should be written to</param>
|
||||
/// <param name="asFiles">TreatAsFiles representing special format scanning</param>
|
||||
/// <param name="asFile">TreatAsFile representing special format scanning</param>
|
||||
/// <returns>True if rebuilding was a success, false otherwise</returns>
|
||||
public static bool RebuildGeneric(
|
||||
DatFile datFile,
|
||||
@@ -199,7 +199,7 @@ namespace SabreTools.DatTools
|
||||
bool delete = false,
|
||||
bool inverse = false,
|
||||
OutputFormat outputFormat = OutputFormat.Folder,
|
||||
TreatAsFile asFiles = 0x00)
|
||||
TreatAsFile asFile = 0x00)
|
||||
{
|
||||
#region Perform setup
|
||||
|
||||
@@ -239,7 +239,7 @@ namespace SabreTools.DatTools
|
||||
if (System.IO.File.Exists(input))
|
||||
{
|
||||
logger.User($"Checking file: {input}");
|
||||
bool rebuilt = RebuildGenericHelper(datFile, input, outDir, quickScan, date, inverse, outputFormat, asFiles);
|
||||
bool rebuilt = RebuildGenericHelper(datFile, input, outDir, quickScan, date, inverse, outputFormat, asFile);
|
||||
|
||||
// If we are supposed to delete the file, do so
|
||||
if (delete && rebuilt)
|
||||
@@ -257,7 +257,7 @@ namespace SabreTools.DatTools
|
||||
#endif
|
||||
{
|
||||
logger.User($"Checking file: {file}");
|
||||
bool rebuilt = RebuildGenericHelper(datFile, file, outDir, quickScan, date, inverse, outputFormat, asFiles);
|
||||
bool rebuilt = RebuildGenericHelper(datFile, file, outDir, quickScan, date, inverse, outputFormat, asFile);
|
||||
|
||||
// If we are supposed to delete the file, do so
|
||||
if (delete && rebuilt)
|
||||
@@ -283,7 +283,7 @@ namespace SabreTools.DatTools
|
||||
/// <param name="date">True if the date from the DAT should be used if available, false otherwise</param>
|
||||
/// <param name="inverse">True if the DAT should be used as a filter instead of a template, false otherwise</param>
|
||||
/// <param name="outputFormat">Output format that files should be written to</param>
|
||||
/// <param name="asFiles">TreatAsFiles representing special format scanning</param>
|
||||
/// <param name="asFile">TreatAsFile representing special format scanning</param>
|
||||
/// <returns>True if the file was used to rebuild, false otherwise</returns>
|
||||
private static bool RebuildGenericHelper(
|
||||
DatFile datFile,
|
||||
@@ -293,7 +293,7 @@ namespace SabreTools.DatTools
|
||||
bool date,
|
||||
bool inverse,
|
||||
OutputFormat outputFormat,
|
||||
TreatAsFile asFiles)
|
||||
TreatAsFile asFile)
|
||||
{
|
||||
// If we somehow have a null filename, return
|
||||
if (file == null)
|
||||
@@ -331,15 +331,15 @@ namespace SabreTools.DatTools
|
||||
if (internalFileInfo == null)
|
||||
internalDatItem = null;
|
||||
#if NET20 || NET35
|
||||
else if (internalFileInfo is FileTypes.Aaru.AaruFormat && (asFiles & TreatAsFile.AaruFormat) == 0)
|
||||
else if (internalFileInfo is FileTypes.Aaru.AaruFormat && (asFile & TreatAsFile.AaruFormat) == 0)
|
||||
#else
|
||||
else if (internalFileInfo is FileTypes.Aaru.AaruFormat && !asFiles.HasFlag(TreatAsFile.AaruFormat))
|
||||
else if (internalFileInfo is FileTypes.Aaru.AaruFormat && !asFile.HasFlag(TreatAsFile.AaruFormat))
|
||||
#endif
|
||||
internalDatItem = new Media(internalFileInfo);
|
||||
#if NET20 || NET35
|
||||
else if (internalFileInfo is FileTypes.CHD.CHDFile && (asFiles & TreatAsFile.CHD) == 0)
|
||||
else if (internalFileInfo is FileTypes.CHD.CHDFile && (asFile & TreatAsFile.CHD) == 0)
|
||||
#else
|
||||
else if (internalFileInfo is FileTypes.CHD.CHDFile && !asFiles.HasFlag(TreatAsFile.CHD))
|
||||
else if (internalFileInfo is FileTypes.CHD.CHDFile && !asFile.HasFlag(TreatAsFile.CHD))
|
||||
#endif
|
||||
internalDatItem = new Disk(internalFileInfo);
|
||||
else
|
||||
|
||||
@@ -1245,19 +1245,4 @@ namespace SabreTools.FileTypes
|
||||
Torrent7Zip,
|
||||
TorrentRar,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines what sort of files get externally hashed
|
||||
/// </summary>
|
||||
/// TODO: Can FileType be used instead?
|
||||
[Flags]
|
||||
public enum TreatAsFile
|
||||
{
|
||||
CHD = 1 << 0,
|
||||
Archive = 1 << 1,
|
||||
AaruFormat = 1 << 2,
|
||||
|
||||
NonArchive = CHD | AaruFormat,
|
||||
All = CHD | Archive | AaruFormat,
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Core.Filter;
|
||||
using SabreTools.Core.Tools;
|
||||
using SabreTools.DatItems;
|
||||
using SabreTools.DatFiles;
|
||||
using SabreTools.DatTools;
|
||||
using SabreTools.FileTypes;
|
||||
@@ -1882,7 +1882,7 @@ Some special strings that can be used:
|
||||
// Set threading flag, if necessary
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
if (features.ContainsKey(ThreadsInt32Value))
|
||||
Globals.MaxThreads = GetInt32(features, ThreadsInt32Value);
|
||||
Core.Globals.MaxThreads = GetInt32(features, ThreadsInt32Value);
|
||||
#endif
|
||||
|
||||
// Failure conditions
|
||||
@@ -1996,19 +1996,19 @@ Some special strings that can be used:
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get TreatAsFiles from feature list
|
||||
/// Get TreatAsFile from feature list
|
||||
/// </summary>
|
||||
protected static TreatAsFile GetTreatAsFiles(Dictionary<string, Feature?> features)
|
||||
protected static TreatAsFile GetTreatAsFile(Dictionary<string, Feature?> features)
|
||||
{
|
||||
TreatAsFile asFiles = 0x00;
|
||||
TreatAsFile asFile = 0x00;
|
||||
if (GetBoolean(features, AaruFormatsAsFilesValue))
|
||||
asFiles |= TreatAsFile.AaruFormat;
|
||||
asFile |= TreatAsFile.AaruFormat;
|
||||
if (GetBoolean(features, ArchivesAsFilesValue))
|
||||
asFiles |= TreatAsFile.Archive;
|
||||
asFile |= TreatAsFile.Archive;
|
||||
if (GetBoolean(features, ChdsAsFilesValue))
|
||||
asFiles |= TreatAsFile.CHD;
|
||||
asFile |= TreatAsFile.CHD;
|
||||
|
||||
return asFiles;
|
||||
return asFile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using SabreTools.DatFiles;
|
||||
using SabreTools.DatItems;
|
||||
using SabreTools.DatTools;
|
||||
using SabreTools.FileTypes;
|
||||
using SabreTools.Help;
|
||||
|
||||
namespace SabreTools.Features
|
||||
@@ -60,7 +60,7 @@ namespace SabreTools.Features
|
||||
// Get feature flags
|
||||
bool addBlankFiles = GetBoolean(features, AddBlankFilesValue);
|
||||
bool addFileDates = GetBoolean(features, AddDateValue);
|
||||
TreatAsFile asFiles = GetTreatAsFiles(features);
|
||||
TreatAsFile asFile = GetTreatAsFile(features);
|
||||
bool noAutomaticDate = GetBoolean(features, NoAutomaticDateValue);
|
||||
var includeInScan = GetIncludeInScan(features);
|
||||
var skipFileType = GetSkipFileType(features);
|
||||
@@ -91,7 +91,7 @@ namespace SabreTools.Features
|
||||
datdata.FillHeaderFromPath(basePath, noAutomaticDate);
|
||||
|
||||
// Now populate from the path
|
||||
bool success = dfd.PopulateFromDir(datdata, basePath, asFiles);
|
||||
bool success = dfd.PopulateFromDir(datdata, basePath, asFile);
|
||||
if (success)
|
||||
{
|
||||
// Perform additional processing steps
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using SabreTools.DatFiles;
|
||||
using SabreTools.DatItems;
|
||||
using SabreTools.DatTools;
|
||||
using SabreTools.FileTypes;
|
||||
using SabreTools.Help;
|
||||
@@ -59,7 +60,7 @@ namespace SabreTools.Features
|
||||
return false;
|
||||
|
||||
// Get feature flags
|
||||
TreatAsFile asFiles = GetTreatAsFiles(features);
|
||||
TreatAsFile asFile = GetTreatAsFile(features);
|
||||
bool date = GetBoolean(features, AddDateValue);
|
||||
bool delete = GetBoolean(features, DeleteValue);
|
||||
bool inverse = GetBoolean(features, InverseValue);
|
||||
@@ -112,7 +113,7 @@ namespace SabreTools.Features
|
||||
if (inputDepot?.IsActive ?? false)
|
||||
success = Rebuilder.RebuildDepot(datdata, Inputs, Path.Combine(OutputDir!, datdata.Header.GetStringFieldValue(DatHeader.FileNameKey)!), date, delete, inverse, outputFormat);
|
||||
else
|
||||
success = Rebuilder.RebuildGeneric(datdata, Inputs, Path.Combine(OutputDir!, datdata.Header.GetStringFieldValue(DatHeader.FileNameKey)!), quickScan, date, delete, inverse, outputFormat, asFiles);
|
||||
success = Rebuilder.RebuildGeneric(datdata, Inputs, Path.Combine(OutputDir!, datdata.Header.GetStringFieldValue(DatHeader.FileNameKey)!), quickScan, date, delete, inverse, outputFormat, asFile);
|
||||
|
||||
// If we have a success and we're updating the DAT, write it out
|
||||
if (success && updateDat)
|
||||
@@ -155,7 +156,7 @@ namespace SabreTools.Features
|
||||
if (inputDepot?.IsActive ?? false)
|
||||
success = Rebuilder.RebuildDepot(datdata, Inputs, OutputDir!, date, delete, inverse, outputFormat);
|
||||
else
|
||||
success = Rebuilder.RebuildGeneric(datdata, Inputs, OutputDir!, quickScan, date, delete, inverse, outputFormat, asFiles);
|
||||
success = Rebuilder.RebuildGeneric(datdata, Inputs, OutputDir!, quickScan, date, delete, inverse, outputFormat, asFile);
|
||||
|
||||
// If we have a success and we're updating the DAT, write it out
|
||||
if (success && updateDat)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using SabreTools.DatFiles;
|
||||
using SabreTools.DatItems;
|
||||
using SabreTools.DatTools;
|
||||
using SabreTools.FileTypes;
|
||||
using SabreTools.Hashing;
|
||||
using SabreTools.Help;
|
||||
using SabreTools.IO;
|
||||
@@ -50,7 +50,7 @@ namespace SabreTools.Features
|
||||
var datfilePaths = PathTool.GetFilesOnly(datfiles);
|
||||
|
||||
// Get feature flags
|
||||
TreatAsFile asFiles = GetTreatAsFiles(features);
|
||||
TreatAsFile asFile = GetTreatAsFile(features);
|
||||
bool hashOnly = GetBoolean(features, HashOnlyValue);
|
||||
bool quickScan = GetBoolean(features, QuickValue);
|
||||
HashType[] hashes = quickScan ? [HashType.CRC32] : [HashType.CRC32, HashType.MD5, HashType.SHA1];
|
||||
@@ -93,7 +93,7 @@ namespace SabreTools.Features
|
||||
logger.User("Processing files:\n");
|
||||
foreach (string input in Inputs)
|
||||
{
|
||||
dfd.PopulateFromDir(datdata, input, asFiles);
|
||||
dfd.PopulateFromDir(datdata, input, asFile);
|
||||
}
|
||||
|
||||
Verification.VerifyGeneric(datdata, hashOnly);
|
||||
@@ -147,7 +147,7 @@ namespace SabreTools.Features
|
||||
logger.User("Processing files:\n");
|
||||
foreach (string input in Inputs)
|
||||
{
|
||||
dfd.PopulateFromDir(datdata, input, asFiles);
|
||||
dfd.PopulateFromDir(datdata, input, asFile);
|
||||
}
|
||||
|
||||
Verification.VerifyGeneric(datdata, hashOnly);
|
||||
|
||||
Reference in New Issue
Block a user