mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Simplify ParseInto invocations
This commit is contained in:
@@ -1486,7 +1486,7 @@ namespace SabreTools.DatFiles
|
||||
var input = inputs[i];
|
||||
_staticLogger.User($"Adding DAT: {input.CurrentPath}");
|
||||
datFiles[i] = CreateDatFile(datFile.Header.CloneFormat(), datFile.Modifiers);
|
||||
Parser.ParseInto(datFiles[i], input, i, keep: true);
|
||||
Parser.ParseInto(datFiles[i], input.CurrentPath, i, keep: true);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
|
||||
@@ -42,61 +42,35 @@ namespace SabreTools.DatFiles
|
||||
bool statsOnly = false,
|
||||
bool throwOnError = false)
|
||||
{
|
||||
var path = new ParentablePath(filename.Trim('"'));
|
||||
ParseInto(datFile, path, indexId, keep, keepext, statsOnly, throwOnError);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a DAT and return all found games and roms within
|
||||
/// </summary>
|
||||
/// <param name="datFile">Current DatFile object to add to</param>
|
||||
/// <param name="input">Name of the file to be parsed</param>
|
||||
/// <param name="indexId">Index ID for the DAT</param>
|
||||
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
||||
/// <param name="keepext">True if original extension should be kept, false otherwise (default)</param>
|
||||
/// <param name="statsOnly">True to only add item statistics while parsing, false otherwise</param>
|
||||
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||
public static void ParseInto(
|
||||
DatFile datFile,
|
||||
ParentablePath input,
|
||||
int indexId = 0,
|
||||
bool keep = false,
|
||||
bool keepext = false,
|
||||
bool statsOnly = false,
|
||||
bool throwOnError = false)
|
||||
{
|
||||
// Get the current path from the filename
|
||||
string currentPath = input.CurrentPath;
|
||||
|
||||
// Check the file extension first as a safeguard
|
||||
if (!Utilities.HasValidDatExtension(currentPath))
|
||||
if (!Utilities.HasValidDatExtension(filename))
|
||||
return;
|
||||
|
||||
// If the output filename isn't set already, get the internal filename
|
||||
datFile.Header.SetFieldValue<string?>(DatHeader.FileNameKey, string.IsNullOrEmpty(datFile.Header.GetStringFieldValue(DatHeader.FileNameKey))
|
||||
? (keepext
|
||||
? Path.GetFileName(currentPath)
|
||||
: Path.GetFileNameWithoutExtension(currentPath))
|
||||
? Path.GetFileName(filename)
|
||||
: Path.GetFileNameWithoutExtension(filename))
|
||||
: datFile.Header.GetStringFieldValue(DatHeader.FileNameKey));
|
||||
|
||||
// If the output type isn't set already, get the internal output type
|
||||
DatFormat datFormat = GetDatFormat(currentPath);
|
||||
DatFormat datFormat = GetDatFormat(filename);
|
||||
datFile.Header.SetFieldValue<DatFormat>(DatHeader.DatFormatKey, datFile.Header.GetFieldValue<DatFormat>(DatHeader.DatFormatKey) == 0
|
||||
? datFormat
|
||||
: datFile.Header.GetFieldValue<DatFormat>(DatHeader.DatFormatKey));
|
||||
datFile.Items.SetBucketedBy(ItemKey.CRC); // Setting this because it can reduce issues later
|
||||
|
||||
InternalStopwatch watch = new($"Parsing '{currentPath}' into internal DAT");
|
||||
InternalStopwatch watch = new($"Parsing '{filename}' into internal DAT");
|
||||
|
||||
// Now parse the correct type of DAT
|
||||
try
|
||||
{
|
||||
DatFile parsingDatFile = DatFileTool.CreateDatFile(datFormat, datFile);
|
||||
parsingDatFile.ParseFile(currentPath, indexId, keep, statsOnly: statsOnly, throwOnError: throwOnError);
|
||||
parsingDatFile.ParseFile(filename, indexId, keep, statsOnly: statsOnly, throwOnError: throwOnError);
|
||||
}
|
||||
catch (Exception ex) when (!throwOnError)
|
||||
{
|
||||
_staticLogger.Error(ex, $"Error with file '{currentPath}'");
|
||||
_staticLogger.Error(ex, $"Error with file '{filename}'");
|
||||
}
|
||||
|
||||
watch.Stop();
|
||||
@@ -114,7 +88,7 @@ namespace SabreTools.DatFiles
|
||||
return DatFileTool.CreateDatFile();
|
||||
|
||||
DatFile datFile = DatFileTool.CreateDatFile();
|
||||
ParseInto(datFile, new ParentablePath(filename), statsOnly: true, throwOnError: throwOnError);
|
||||
ParseInto(datFile, filename, statsOnly: true, throwOnError: throwOnError);
|
||||
return datFile;
|
||||
}
|
||||
|
||||
|
||||
@@ -525,7 +525,7 @@ Reset the internal state: reset();";
|
||||
// Assume there could be multiple
|
||||
foreach (ParentablePath datFilePath in datFilePaths)
|
||||
{
|
||||
Parser.ParseInto(batchState.DatFile, datFilePath, batchState.Index++);
|
||||
Parser.ParseInto(batchState.DatFile, datFilePath.CurrentPath, batchState.Index++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace SabreTools.Features
|
||||
foreach (ParentablePath datfile in datfilePaths)
|
||||
{
|
||||
DatFile datdata = DatFileTool.CreateDatFile();
|
||||
Parser.ParseInto(datdata, datfile, int.MaxValue, keep: true);
|
||||
Parser.ParseInto(datdata, datfile.CurrentPath, int.MaxValue, keep: true);
|
||||
|
||||
// Skip if nothing was parsed
|
||||
if (datdata.DatStatistics.TotalCount == 0) // datdata.ItemsDB.SortedKeys.Length == 0
|
||||
@@ -136,7 +136,7 @@ namespace SabreTools.Features
|
||||
DatFile datdata = DatFileTool.CreateDatFile();
|
||||
foreach (ParentablePath datfile in datfilePaths)
|
||||
{
|
||||
Parser.ParseInto(datdata, datfile, int.MaxValue, keep: true);
|
||||
Parser.ParseInto(datdata, datfile.CurrentPath, int.MaxValue, keep: true);
|
||||
}
|
||||
|
||||
// Set depot information
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace SabreTools.Features
|
||||
{
|
||||
// Create and fill the new DAT
|
||||
DatFile internalDat = DatFileTool.CreateDatFile(Header!, Modifiers!);
|
||||
Parser.ParseInto(internalDat, file);
|
||||
Parser.ParseInto(internalDat, file.CurrentPath);
|
||||
|
||||
// Get the output directory
|
||||
OutputDir = OutputDir.Ensure();
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace SabreTools.Features
|
||||
|| currentFormat.HasFlag(DatFormat.TSV);
|
||||
#endif
|
||||
|
||||
Parser.ParseInto(datFile, inputPath, keep: true, keepext: isSeparatedFile);
|
||||
Parser.ParseInto(datFile, inputPath.CurrentPath, keep: true, keepext: isSeparatedFile);
|
||||
|
||||
// Perform additional processing steps
|
||||
Extras!.ApplyExtras(datFile);
|
||||
@@ -392,7 +392,7 @@ namespace SabreTools.Features
|
||||
{
|
||||
// Parse the path to a new DatFile
|
||||
DatFile repDat = DatFileTool.CreateDatFile(Header!, Modifiers);
|
||||
Parser.ParseInto(repDat, inputPath, indexId: 1, keep: true);
|
||||
Parser.ParseInto(repDat, inputPath.CurrentPath, indexId: 1, keep: true);
|
||||
|
||||
// Perform additional processing steps
|
||||
Extras.ApplyExtras(repDat);
|
||||
@@ -433,7 +433,7 @@ namespace SabreTools.Features
|
||||
{
|
||||
// Parse the path to a new DatFile
|
||||
DatFile repDat = DatFileTool.CreateDatFile(Header!, Modifiers);
|
||||
Parser.ParseInto(repDat, inputPath, indexId: 1, keep: true);
|
||||
Parser.ParseInto(repDat, inputPath.CurrentPath, indexId: 1, keep: true);
|
||||
|
||||
// Perform additional processing steps
|
||||
Extras.ApplyExtras(repDat);
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace SabreTools.Features
|
||||
{
|
||||
// Parse in from the file
|
||||
DatFile datdata = DatFileTool.CreateDatFile();
|
||||
Parser.ParseInto(datdata, datfile, int.MaxValue, keep: true);
|
||||
Parser.ParseInto(datdata, datfile.CurrentPath, int.MaxValue, keep: true);
|
||||
|
||||
// Perform additional processing steps
|
||||
Extras!.ApplyExtras(datdata);
|
||||
@@ -114,7 +114,7 @@ namespace SabreTools.Features
|
||||
DatFile datdata = DatFileTool.CreateDatFile();
|
||||
foreach (ParentablePath datfile in datfilePaths)
|
||||
{
|
||||
Parser.ParseInto(datdata, datfile, int.MaxValue, keep: true);
|
||||
Parser.ParseInto(datdata, datfile.CurrentPath, int.MaxValue, keep: true);
|
||||
}
|
||||
|
||||
// Perform additional processing steps
|
||||
|
||||
Reference in New Issue
Block a user