From c35b87304f10c9bf85442303c267d9c36d9bbe6b Mon Sep 17 00:00:00 2001 From: Deterous <138427222+Deterous@users.noreply.github.com> Date: Fri, 13 Dec 2024 00:36:46 +0900 Subject: [PATCH 1/4] DumpingParameters for DIC and Redumper --- MPF.Processors.Test/DiscImageCreatorTests.cs | 29 ++++++++++++++ MPF.Processors.Test/RedumperTests.cs | 29 ++++++++++++++ .../TestData/Redumper/CDROM/test.log | 3 ++ MPF.Processors/DiscImageCreator.cs | 28 +++++++++++++ MPF.Processors/Redumper.cs | 39 +++++++++++++++++++ 5 files changed, 128 insertions(+) diff --git a/MPF.Processors.Test/DiscImageCreatorTests.cs b/MPF.Processors.Test/DiscImageCreatorTests.cs index 436dec9f1..68dcfd5b5 100644 --- a/MPF.Processors.Test/DiscImageCreatorTests.cs +++ b/MPF.Processors.Test/DiscImageCreatorTests.cs @@ -257,6 +257,35 @@ public void GetCommandFilePathAndVersion_Valid_Filled() #endregion + #region GetParameters + + [Fact] + public void GetParameters_Empty_Null() + { + string basePath = string.Empty; + string? parameters = DiscImageCreator.GetParameters(basePath); + Assert.Null(parameters); + } + + [Fact] + public void GetParameters_Invalid_Null() + { + string basePath = "INVALID"; + string? parameters = DiscImageCreator.GetParameters(basePath); + Assert.Null(parameters); + } + + [Fact] + public void GetParameters_Valid_Filled() + { + string? expectedParameters = "TEST DATA"; + string basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "DiscImageCreator", "CDROM", "test"); + string? parameters = DiscImageCreator.GetParameters($"{basePath}_19800101T000000.txt"); + Assert.Equal(expectedVersion, parameters); + } + + #endregion + #region GetPlayStationEXEDate // TODO: This... is horrible diff --git a/MPF.Processors.Test/RedumperTests.cs b/MPF.Processors.Test/RedumperTests.cs index ab2b4672e..70c76a455 100644 --- a/MPF.Processors.Test/RedumperTests.cs +++ b/MPF.Processors.Test/RedumperTests.cs @@ -998,6 +998,35 @@ public void GetUniversalHash_Valid_Filled() #endregion + #region GetParameters + + [Fact] + public void GetParameters_Empty_Null() + { + string log = string.Empty; + string? actual = Redumper.GetParameters(log); + Assert.Null(actual); + } + + [Fact] + public void GetParameters_Invalid_Null() + { + string log = "INVALID"; + string? actual = Redumper.GetParameters(log); + Assert.Null(actual); + } + + [Fact] + public void GetParameters_Valid_Filled() + { + string? expected = "v1980.01.01 build_00"; + string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test.log"); + string? actual = Redumper.GetParameters(log); + Assert.Equal(expected, actual); + } + + #endregion + #region GetVersion [Fact] diff --git a/MPF.Processors.Test/TestData/Redumper/CDROM/test.log b/MPF.Processors.Test/TestData/Redumper/CDROM/test.log index a918a0181..f7055db5d 100644 --- a/MPF.Processors.Test/TestData/Redumper/CDROM/test.log +++ b/MPF.Processors.Test/TestData/Redumper/CDROM/test.log @@ -2,6 +2,9 @@ DUMPING DATE (DateTime.Now) redumper v1980.01.01 build_00 [Jan 01 1980, 00:00:00] << GetVersion (above) >> +<< GetParameters >> +arguments: cd --verbose + << GetCuesheet >> CUE [ cuesheet diff --git a/MPF.Processors/DiscImageCreator.cs b/MPF.Processors/DiscImageCreator.cs index 04886f0f9..fafd5bd7a 100644 --- a/MPF.Processors/DiscImageCreator.cs +++ b/MPF.Processors/DiscImageCreator.cs @@ -80,6 +80,7 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, string basePath var dicVersion = GetCommandFilePathAndVersion(basePath, out var dicCmd); info.DumpingInfo!.DumpingProgram ??= string.Empty; info.DumpingInfo.DumpingProgram += $" {dicVersion ?? "Unknown Version"}"; + info.DumpingInfo.DumpingParameters = GetParameters(dicCmd) ?? "Unknown Parameters"; info.DumpingInfo.DumpingDate = ProcessingTool.GetFileModifiedDate(dicCmd)?.ToString("yyyy-MM-dd HH:mm:ss"); // Fill in the hardware data @@ -820,6 +821,33 @@ internal override List GetOutputFiles(string? baseDirectory, string #region Information Extraction Methods + /// + /// Get the dumping parameters from the log, if possible + /// + /// Log file location + /// Dumping parameters if possible, null otherwise + public static string? GetParameters(string? dicCmd) + { + // If the file doesn't exist, we can't get the info + if (string.IsNullOrEmpty(dicCmd)) + return null; + if (!File.Exists(dicCmd)) + return null; + + try + { + // Dumping parameters are on the first line + using var sr = File.OpenText(dicCmd); + var line = sr.ReadLine(); + return line?.Trim(); + } + catch + { + // We don't care what the exception is right now + return null; + } + } + /// /// Get the PSX/PS2/KP2 EXE Date from the log, if possible /// diff --git a/MPF.Processors/Redumper.cs b/MPF.Processors/Redumper.cs index 1627ef920..78b84ad00 100644 --- a/MPF.Processors/Redumper.cs +++ b/MPF.Processors/Redumper.cs @@ -28,6 +28,7 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, string basePath // Get the dumping program and version info.DumpingInfo!.DumpingProgram ??= string.Empty; info.DumpingInfo.DumpingProgram += $" {GetVersion($"{basePath}.log") ?? "Unknown Version"}"; + info.DumpingInfo.DumpingParameters = GetParameters($"{basePath}.log") ?? "Unknown Parameters"; info.DumpingInfo.DumpingDate = ProcessingTool.GetFileModifiedDate($"{basePath}.log")?.ToString("yyyy-MM-dd HH:mm:ss"); // Fill in the hardware data @@ -1818,6 +1819,44 @@ internal static bool GetSaturnBuildInfo(string? segaHeader, out string? buildDat } } + /// + /// Get the dumping parameters, if possible + /// + /// Log file location + /// Dumping parameters if possible, null on error + internal static string? GetParameters(string log) + { + // If the file doesn't exist, we can't get info from it + if (string.IsNullOrEmpty(log)) + return null; + if (!File.Exists(log)) + return null; + + // Samples: + // arguments: cd --verbose --drive=F:\ --speed=24 --retries=200 + // arguments: bd --image-path=ISO\PS3_VOLUME --image-name=PS3_VOLUME + + try + { + // If we find the arguments line, return the arguments + using var sr = File.OpenText(log); + while (!sr.EndOfStream) + { + string? line = sr.ReadLine()?.TrimStart(); + if (line?.StartsWith("arguments: ") == true) + return line.Substring("arguments: ".Length).Trim(); + } + + // We couldn't detect any arguments + return null; + } + catch + { + // We don't care what the exception is right now + return null; + } + } + /// /// Get all Volume Identifiers /// From 45d3aaf7e9000f1fa2ceafc77b7c5ca9011ffff7 Mon Sep 17 00:00:00 2001 From: Deterous <138427222+Deterous@users.noreply.github.com> Date: Fri, 13 Dec 2024 00:39:35 +0900 Subject: [PATCH 2/4] Update changelog --- CHANGELIST.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELIST.md b/CHANGELIST.md index 4a8d98076..c592a9a81 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -70,6 +70,7 @@ - Always omit EA CD-Key - Add packer filtering tests - Simplify prefix filtering +- Add DumpingParameters for DIC and Redumper ### 3.2.4 (2024-11-24) From 82400967a12acff69060618d5e84fe987ab616cb Mon Sep 17 00:00:00 2001 From: Deterous <138427222+Deterous@users.noreply.github.com> Date: Fri, 13 Dec 2024 00:42:20 +0900 Subject: [PATCH 3/4] fix typo --- MPF.Processors.Test/DiscImageCreatorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MPF.Processors.Test/DiscImageCreatorTests.cs b/MPF.Processors.Test/DiscImageCreatorTests.cs index 68dcfd5b5..d7dc53bff 100644 --- a/MPF.Processors.Test/DiscImageCreatorTests.cs +++ b/MPF.Processors.Test/DiscImageCreatorTests.cs @@ -281,7 +281,7 @@ public void GetParameters_Valid_Filled() string? expectedParameters = "TEST DATA"; string basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "DiscImageCreator", "CDROM", "test"); string? parameters = DiscImageCreator.GetParameters($"{basePath}_19800101T000000.txt"); - Assert.Equal(expectedVersion, parameters); + Assert.Equal(expectedParameters, parameters); } #endregion From ac5c5440ef488fd7c91c21cf17444da6e0370bbc Mon Sep 17 00:00:00 2001 From: Deterous <138427222+Deterous@users.noreply.github.com> Date: Fri, 13 Dec 2024 00:45:53 +0900 Subject: [PATCH 4/4] Fix test --- MPF.Processors.Test/RedumperTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MPF.Processors.Test/RedumperTests.cs b/MPF.Processors.Test/RedumperTests.cs index 70c76a455..ba8cd5981 100644 --- a/MPF.Processors.Test/RedumperTests.cs +++ b/MPF.Processors.Test/RedumperTests.cs @@ -1019,7 +1019,7 @@ public void GetParameters_Invalid_Null() [Fact] public void GetParameters_Valid_Filled() { - string? expected = "v1980.01.01 build_00"; + string? expected = "cd --verbose"; string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test.log"); string? actual = Redumper.GetParameters(log); Assert.Equal(expected, actual);