Simplify only place CreateAndParse was called

This commit is contained in:
Matt Nadareski
2025-01-31 23:03:25 -05:00
parent ebfe71d9c2
commit 3d2e599735
3 changed files with 19 additions and 20 deletions

View File

@@ -23,23 +23,6 @@ namespace SabreTools.DatFiles
#endregion #endregion
/// <summary>
/// Create a DatFile and parse a file into it
/// </summary>
/// <param name="filename">Name of the file to be parsed</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 DatFile CreateAndParse(string? filename, bool statsOnly = false, bool throwOnError = false)
{
// Null filenames are invalid
if (filename == null)
return DatFileTool.CreateDatFile();
DatFile datFile = DatFileTool.CreateDatFile();
ParseInto(datFile, new ParentablePath(filename), statsOnly: statsOnly, throwOnError: throwOnError);
return datFile;
}
/// <summary> /// <summary>
/// Parse a DAT and return all found games and roms within /// Parse a DAT and return all found games and roms within
/// </summary> /// </summary>
@@ -119,6 +102,22 @@ namespace SabreTools.DatFiles
watch.Stop(); watch.Stop();
} }
/// <summary>
/// Create a DatFile and parse statistics into it
/// </summary>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
public static DatFile ParseStatistics(string? filename, bool throwOnError = false)
{
// Null filenames are invalid
if (filename == null)
return DatFileTool.CreateDatFile();
DatFile datFile = DatFileTool.CreateDatFile();
ParseInto(datFile, new ParentablePath(filename), statsOnly: true, throwOnError: throwOnError);
return datFile;
}
/// <summary> /// <summary>
/// Get what type of DAT the input file is /// Get what type of DAT the input file is
/// </summary> /// </summary>

View File

@@ -76,7 +76,7 @@ namespace SabreTools.DatTools
InternalStopwatch watch = new($"Collecting statistics for '{file.CurrentPath}'"); InternalStopwatch watch = new($"Collecting statistics for '{file.CurrentPath}'");
List<string> machines = []; List<string> machines = [];
DatFile datdata = Parser.CreateAndParse(file.CurrentPath, statsOnly: true, throwOnError: throwOnError); DatFile datdata = Parser.ParseStatistics(file.CurrentPath, throwOnError: throwOnError);
// Add single DAT stats (if asked) // Add single DAT stats (if asked)
if (single) if (single)

View File

@@ -37,13 +37,13 @@ namespace SabreTools.Test.DatTools
[InlineData("test-sha384.sha384", DatFormat.RedumpSHA384, 1)] [InlineData("test-sha384.sha384", DatFormat.RedumpSHA384, 1)]
[InlineData("test-sha512.sha512", DatFormat.RedumpSHA512, 1)] [InlineData("test-sha512.sha512", DatFormat.RedumpSHA512, 1)]
[InlineData("test-spamsum.spamsum", DatFormat.RedumpSpamSum, 1)] [InlineData("test-spamsum.spamsum", DatFormat.RedumpSpamSum, 1)]
public void CreateAndParseTest(string? filename, DatFormat datFormat, int totalCount) public void ParseStatisticsTest(string? filename, DatFormat datFormat, int totalCount)
{ {
// For all filenames, add the local path for test data // For all filenames, add the local path for test data
if (filename != null) if (filename != null)
filename = Path.Combine(Environment.CurrentDirectory, "TestData", filename); filename = Path.Combine(Environment.CurrentDirectory, "TestData", filename);
var datFile = Parser.CreateAndParse(filename, throwOnError: true); var datFile = Parser.ParseStatistics(filename, throwOnError: true);
Assert.Equal(datFormat, datFile.Header.GetFieldValue<DatFormat>(DatHeader.DatFormatKey)); Assert.Equal(datFormat, datFile.Header.GetFieldValue<DatFormat>(DatHeader.DatFormatKey));
Assert.Equal(totalCount, datFile.Items.DatStatistics.TotalCount); Assert.Equal(totalCount, datFile.Items.DatStatistics.TotalCount);
Assert.Equal(totalCount, datFile.ItemsDB.DatStatistics.TotalCount); Assert.Equal(totalCount, datFile.ItemsDB.DatStatistics.TotalCount);