Less passing down the chain

This commit is contained in:
Matt Nadareski
2020-09-18 11:40:21 -07:00
parent ba253f94e6
commit ea5ef04ab1
3 changed files with 47 additions and 29 deletions

View File

@@ -2178,7 +2178,7 @@ namespace SabreTools.Library.DatFiles
private void ProcessFile(string item, string basePath, TreatAsFile asFiles) private void ProcessFile(string item, string basePath, TreatAsFile asFiles)
{ {
Globals.Logger.Verbose($"'{Path.GetFileName(item)}' treated like a file"); 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); DatItem datItem = DatItem.Create(baseFile);
ProcessFileHelper(item, datItem, basePath, string.Empty); ProcessFileHelper(item, datItem, basePath, string.Empty);
} }
@@ -2508,7 +2508,11 @@ namespace SabreTools.Library.DatFiles
if (File.Exists(input)) if (File.Exists(input))
{ {
Globals.Logger.User($"Checking file: {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 // If the input is a directory
@@ -2518,7 +2522,11 @@ namespace SabreTools.Library.DatFiles
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories)) foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
{ {
Globals.Logger.User($"Checking file: {file}"); 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
/// <param name="outDir">Output directory to use to build to</param> /// <param name="outDir">Output directory to use to build to</param>
/// <param name="quickScan">True to enable external scanning of archives, false otherwise</param> /// <param name="quickScan">True to enable external scanning of archives, false otherwise</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise</param>
/// <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="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="outputFormat">Output format that files should be written to</param>
/// <param name="asFiles">TreatAsFiles representing special format scanning</param> /// <param name="asFiles">TreatAsFiles representing special format scanning</param>
private void RebuildGenericHelper( /// <returns>True if the file was used to rebuild, false otherwise</returns>
private bool RebuildGenericHelper(
string file, string file,
string outDir, string outDir,
bool quickScan, bool quickScan,
bool date, bool date,
bool delete,
bool inverse, bool inverse,
OutputFormat outputFormat, OutputFormat outputFormat,
TreatAsFile asFiles) TreatAsFile asFiles)
{ {
// If we somehow have a null filename, return // If we somehow have a null filename, return
if (file == null) if (file == null)
return; return false;
// Set the deletion variables // Set the deletion variables
bool usedExternally = false, usedInternally = false; bool usedExternally = false, usedInternally = false;
@@ -2598,9 +2605,7 @@ namespace SabreTools.Library.DatFiles
} }
} }
// If we are supposed to delete the file, do so return usedExternally || usedInternally;
if (delete && (usedExternally || usedInternally))
FileExtensions.TryDelete(file);
} }
/// <summary> /// <summary>
@@ -2947,22 +2952,12 @@ namespace SabreTools.Library.DatFiles
/// <summary> /// <summary>
/// Verify a DatFile against a set of inputs, leaving only missing files /// Verify a DatFile against a set of inputs, leaving only missing files
/// </summary> /// </summary>
/// <param name="inputs">List of input directories to compare against</param>
/// <param name="hashOnly">True if only hashes should be checked, false for full file information</param> /// <param name="hashOnly">True if only hashes should be checked, false for full file information</param>
/// <param name="quickScan">True to enable external scanning of archives, false otherwise</param>
/// <param name="asFiles">TreatAsFiles representing CHD and Archive scanning</param>
/// <returns>True if verification was a success, false otherwise</returns> /// <returns>True if verification was a success, false otherwise</returns>
public bool VerifyGeneric(List<string> inputs, bool hashOnly, bool quickScan, TreatAsFile asFiles = 0x00) public bool VerifyGeneric(bool hashOnly)
{ {
bool success = true; 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 // Force bucketing according to the flags
Items.SetBucketedBy(Field.NULL); Items.SetBucketedBy(Field.NULL);
if (hashOnly) if (hashOnly)
@@ -2977,8 +2972,8 @@ namespace SabreTools.Library.DatFiles
List<DatItem> items = Items[key]; List<DatItem> items = Items[key];
for (int i = 0; i < items.Count; i++) for (int i = 0; i < items.Count; i++)
{ {
// Unmatched items will have a source ID of 99, remove all others // Unmatched items will have a source ID of int.MaxValue, remove all others
if (items[i].Source.Index != 99) if (items[i].Source.Index != int.MaxValue)
items[i].Remove = true; items[i].Remove = true;
} }

View File

@@ -90,7 +90,7 @@ namespace SabreTools.Features
foreach (ParentablePath datfile in datfilePaths) foreach (ParentablePath datfile in datfilePaths)
{ {
DatFile datdata = DatFile.Create(); DatFile datdata = DatFile.Create();
datdata.Parse(datfile, 99, keep: true); datdata.Parse(datfile, int.MaxValue, keep: true);
// Set depot information // Set depot information
datdata.Header.InputDepot = Header.InputDepot.Clone() as DepotInformation; datdata.Header.InputDepot = Header.InputDepot.Clone() as DepotInformation;
@@ -128,7 +128,7 @@ namespace SabreTools.Features
DatFile datdata = DatFile.Create(); DatFile datdata = DatFile.Create();
foreach (ParentablePath datfile in datfilePaths) foreach (ParentablePath datfile in datfilePaths)
{ {
datdata.Parse(datfile, 99, keep: true); datdata.Parse(datfile, int.MaxValue, keep: true);
} }
// Set depot information // Set depot information

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles; using SabreTools.Library.DatFiles;
using SabreTools.Library.Help; using SabreTools.Library.Help;
using SabreTools.Library.IO; using SabreTools.Library.IO;
@@ -57,7 +58,7 @@ namespace SabreTools.Features
{ {
// Parse in from the file // Parse in from the file
DatFile datdata = DatFile.Create(); DatFile datdata = DatFile.Create();
datdata.Parse(datfile, 99, keep: true); datdata.Parse(datfile, int.MaxValue, keep: true);
// Perform additional processing steps // Perform additional processing steps
datdata.ApplyExtras(Extras); datdata.ApplyExtras(Extras);
@@ -74,9 +75,20 @@ namespace SabreTools.Features
// If we have the depot flag, respect it // If we have the depot flag, respect it
if (Header.InputDepot?.IsActive ?? false) if (Header.InputDepot?.IsActive ?? false)
{
datdata.VerifyDepot(Inputs); datdata.VerifyDepot(Inputs);
}
else 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 // Now write out if there are any items left
datdata.WriteStatsToConsole(); datdata.WriteStatsToConsole();
@@ -92,7 +104,7 @@ namespace SabreTools.Features
DatFile datdata = DatFile.Create(); DatFile datdata = DatFile.Create();
foreach (ParentablePath datfile in datfilePaths) foreach (ParentablePath datfile in datfilePaths)
{ {
datdata.Parse(datfile, 99, keep: true); datdata.Parse(datfile, int.MaxValue, keep: true);
} }
// Perform additional processing steps // Perform additional processing steps
@@ -112,9 +124,20 @@ namespace SabreTools.Features
// If we have the depot flag, respect it // If we have the depot flag, respect it
if (Header.InputDepot?.IsActive ?? false) if (Header.InputDepot?.IsActive ?? false)
{
datdata.VerifyDepot(Inputs); datdata.VerifyDepot(Inputs);
}
else 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 // Now write out if there are any items left
datdata.WriteStatsToConsole(); datdata.WriteStatsToConsole();