diff --git a/CHANGELIST.md b/CHANGELIST.md index f2fab581..9520bd82 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -43,6 +43,7 @@ - Fix lines wiped before displayed - Update redumper to build 565 - Close the log archive, if it exists +- Support checking Redumper DAT from zip; add tests ### 3.3.0 (2025-01-03) diff --git a/MPF.Processors.Test/AaruTests.cs b/MPF.Processors.Test/AaruTests.cs index d6b01ca9..fa4a42db 100644 --- a/MPF.Processors.Test/AaruTests.cs +++ b/MPF.Processors.Test/AaruTests.cs @@ -127,6 +127,16 @@ namespace MPF.Processors.Test Assert.True(actual); } + [Fact] + public void FoundAnyFiles_ValidZip_Empty() + { + string? outputDirectory = Path.Combine(Environment.CurrentDirectory, "TestData", "Aaru", "CDROM-zip"); + string outputFilename = "test.aaruf"; + var processor = new Aaru(RedumpSystem.IBMPCcompatible, MediaType.CDROM); + var actual = processor.FoundAnyFiles(outputDirectory, outputFilename); + Assert.True(actual); + } + #endregion #region GenerateArtifacts diff --git a/MPF.Processors.Test/CleanRipTests.cs b/MPF.Processors.Test/CleanRipTests.cs index 721fa1dd..76ade6a6 100644 --- a/MPF.Processors.Test/CleanRipTests.cs +++ b/MPF.Processors.Test/CleanRipTests.cs @@ -112,6 +112,16 @@ namespace MPF.Processors.Test Assert.True(actual); } + [Fact] + public void FoundAnyFiles_ValidZip_Empty() + { + string? outputDirectory = Path.Combine(Environment.CurrentDirectory, "TestData", "CleanRip", "DVD-zip"); + string outputFilename = "test.iso"; + var processor = new CleanRip(RedumpSystem.NintendoGameCube, MediaType.DVD); + var actual = processor.FoundAnyFiles(outputDirectory, outputFilename); + Assert.True(actual); + } + #endregion #region GenerateArtifacts diff --git a/MPF.Processors.Test/DiscImageCreatorTests.cs b/MPF.Processors.Test/DiscImageCreatorTests.cs index 3cdc33c0..3b2327ca 100644 --- a/MPF.Processors.Test/DiscImageCreatorTests.cs +++ b/MPF.Processors.Test/DiscImageCreatorTests.cs @@ -181,6 +181,16 @@ namespace MPF.Processors.Test Assert.True(actual); } + [Fact] + public void FoundAnyFiles_ValidZip_Empty() + { + string? outputDirectory = Path.Combine(Environment.CurrentDirectory, "TestData", "DiscImageCreator", "CDROM-zip"); + string outputFilename = "test.cue"; + var processor = new DiscImageCreator(RedumpSystem.IBMPCcompatible, MediaType.CDROM); + var actual = processor.FoundAnyFiles(outputDirectory, outputFilename); + Assert.True(actual); + } + #endregion #region GenerateArtifacts diff --git a/MPF.Processors.Test/PS3CFWTests.cs b/MPF.Processors.Test/PS3CFWTests.cs index e11b6e82..e37f58c9 100644 --- a/MPF.Processors.Test/PS3CFWTests.cs +++ b/MPF.Processors.Test/PS3CFWTests.cs @@ -91,6 +91,16 @@ namespace MPF.Processors.Test Assert.True(actual); } + [Fact] + public void FoundAnyFiles_ValidZip_Empty() + { + string? outputDirectory = Path.Combine(Environment.CurrentDirectory, "TestData", "PS3CFW", "BluRay-zip"); + string outputFilename = "test.iso"; + var processor = new PS3CFW(RedumpSystem.SonyPlayStation3, MediaType.BluRay); + var actual = processor.FoundAnyFiles(outputDirectory, outputFilename); + Assert.True(actual); + } + #endregion #region GenerateArtifacts diff --git a/MPF.Processors.Test/RedumperTests.cs b/MPF.Processors.Test/RedumperTests.cs index 19982bb0..007824a8 100644 --- a/MPF.Processors.Test/RedumperTests.cs +++ b/MPF.Processors.Test/RedumperTests.cs @@ -29,7 +29,7 @@ namespace MPF.Processors.Test var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM); var actual = processor.GetOutputFiles(outputDirectory, outputFilename); - Assert.Equal(15, actual.Count); + Assert.Equal(16, actual.Count); } [Fact] @@ -100,6 +100,16 @@ namespace MPF.Processors.Test Assert.Empty(actual); } + [Fact] + public void FoundAllFiles_ValidZip_Empty() + { + string? outputDirectory = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM-zip"); + string outputFilename = "test.cue"; + var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM); + var actual = processor.FoundAllFiles(outputDirectory, outputFilename); + Assert.Empty(actual); + } + #endregion #region FoundAnyFiles @@ -145,7 +155,7 @@ namespace MPF.Processors.Test string outputFilename = "test.cue"; var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM); var actual = processor.GenerateArtifacts(outputDirectory, outputFilename); - Assert.Equal(9, actual.Count); + Assert.Equal(10, actual.Count); } #endregion @@ -193,7 +203,7 @@ namespace MPF.Processors.Test string outputFilename = "test.cue"; var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM); var actual = processor.GetZippableFilePaths(outputDirectory, outputFilename); - Assert.Equal(9, actual.Count); + Assert.Equal(10, actual.Count); } #endregion diff --git a/MPF.Processors.Test/TestData/Aaru/CDROM-zip/test.aaruf b/MPF.Processors.Test/TestData/Aaru/CDROM-zip/test.aaruf new file mode 100644 index 00000000..1aa4b5d8 --- /dev/null +++ b/MPF.Processors.Test/TestData/Aaru/CDROM-zip/test.aaruf @@ -0,0 +1 @@ +TEST DATA \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/Aaru/CDROM-zip/test_logs.zip b/MPF.Processors.Test/TestData/Aaru/CDROM-zip/test_logs.zip new file mode 100644 index 00000000..7667316e Binary files /dev/null and b/MPF.Processors.Test/TestData/Aaru/CDROM-zip/test_logs.zip differ diff --git a/MPF.Processors.Test/TestData/CleanRip/DVD-zip/test.iso b/MPF.Processors.Test/TestData/CleanRip/DVD-zip/test.iso new file mode 100644 index 00000000..1aa4b5d8 --- /dev/null +++ b/MPF.Processors.Test/TestData/CleanRip/DVD-zip/test.iso @@ -0,0 +1 @@ +TEST DATA \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/CleanRip/DVD-zip/test_logs.zip b/MPF.Processors.Test/TestData/CleanRip/DVD-zip/test_logs.zip new file mode 100644 index 00000000..99d8fb52 Binary files /dev/null and b/MPF.Processors.Test/TestData/CleanRip/DVD-zip/test_logs.zip differ diff --git a/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test.bin b/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test.bin new file mode 100644 index 00000000..1aa4b5d8 --- /dev/null +++ b/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test.bin @@ -0,0 +1 @@ +TEST DATA \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test.cue b/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test.cue new file mode 100644 index 00000000..1aa4b5d8 --- /dev/null +++ b/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test.cue @@ -0,0 +1 @@ +TEST DATA \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test.img b/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test.img new file mode 100644 index 00000000..1aa4b5d8 --- /dev/null +++ b/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test.img @@ -0,0 +1 @@ +TEST DATA \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test.scm b/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test.scm new file mode 100644 index 00000000..1aa4b5d8 --- /dev/null +++ b/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test.scm @@ -0,0 +1 @@ +TEST DATA \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test_CSSKey.txt b/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test_CSSKey.txt new file mode 100644 index 00000000..1a9b4e84 --- /dev/null +++ b/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test_CSSKey.txt @@ -0,0 +1,3 @@ +<< GetDVDProtection >> +DecryptedDiscKey[020]: No Key +LBA: 0, Filename: FILE, No TitleKey \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test_logs.zip b/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test_logs.zip new file mode 100644 index 00000000..50622e58 Binary files /dev/null and b/MPF.Processors.Test/TestData/DiscImageCreator/CDROM-zip/test_logs.zip differ diff --git a/MPF.Processors.Test/TestData/PS3CFW/BluRay-zip/test.iso b/MPF.Processors.Test/TestData/PS3CFW/BluRay-zip/test.iso new file mode 100644 index 00000000..1aa4b5d8 --- /dev/null +++ b/MPF.Processors.Test/TestData/PS3CFW/BluRay-zip/test.iso @@ -0,0 +1 @@ +TEST DATA \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/PS3CFW/BluRay-zip/test_logs.zip b/MPF.Processors.Test/TestData/PS3CFW/BluRay-zip/test_logs.zip new file mode 100644 index 00000000..4f801f4c Binary files /dev/null and b/MPF.Processors.Test/TestData/PS3CFW/BluRay-zip/test_logs.zip differ diff --git a/MPF.Processors.Test/TestData/Redumper/CDROM-zip/test.cue b/MPF.Processors.Test/TestData/Redumper/CDROM-zip/test.cue new file mode 100644 index 00000000..1aa4b5d8 --- /dev/null +++ b/MPF.Processors.Test/TestData/Redumper/CDROM-zip/test.cue @@ -0,0 +1 @@ +TEST DATA \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/Redumper/CDROM-zip/test.scram b/MPF.Processors.Test/TestData/Redumper/CDROM-zip/test.scram new file mode 100644 index 00000000..1aa4b5d8 --- /dev/null +++ b/MPF.Processors.Test/TestData/Redumper/CDROM-zip/test.scram @@ -0,0 +1 @@ +TEST DATA \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/Redumper/CDROM-zip/test_logs.zip b/MPF.Processors.Test/TestData/Redumper/CDROM-zip/test_logs.zip new file mode 100644 index 00000000..35e29ecc Binary files /dev/null and b/MPF.Processors.Test/TestData/Redumper/CDROM-zip/test_logs.zip differ diff --git a/MPF.Processors.Test/TestData/UmdImageCreator/UMD-zip/test.iso b/MPF.Processors.Test/TestData/UmdImageCreator/UMD-zip/test.iso new file mode 100644 index 00000000..1aa4b5d8 --- /dev/null +++ b/MPF.Processors.Test/TestData/UmdImageCreator/UMD-zip/test.iso @@ -0,0 +1 @@ +TEST DATA \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/UmdImageCreator/UMD-zip/test_logs.zip b/MPF.Processors.Test/TestData/UmdImageCreator/UMD-zip/test_logs.zip new file mode 100644 index 00000000..a84e00ef Binary files /dev/null and b/MPF.Processors.Test/TestData/UmdImageCreator/UMD-zip/test_logs.zip differ diff --git a/MPF.Processors.Test/TestData/XboxBackupCreator/DVD-zip/test.iso b/MPF.Processors.Test/TestData/XboxBackupCreator/DVD-zip/test.iso new file mode 100644 index 00000000..1aa4b5d8 --- /dev/null +++ b/MPF.Processors.Test/TestData/XboxBackupCreator/DVD-zip/test.iso @@ -0,0 +1 @@ +TEST DATA \ No newline at end of file diff --git a/MPF.Processors.Test/TestData/XboxBackupCreator/DVD-zip/test_logs.zip b/MPF.Processors.Test/TestData/XboxBackupCreator/DVD-zip/test_logs.zip new file mode 100644 index 00000000..9bb6b3c7 Binary files /dev/null and b/MPF.Processors.Test/TestData/XboxBackupCreator/DVD-zip/test_logs.zip differ diff --git a/MPF.Processors.Test/UmdImageCreatorTests.cs b/MPF.Processors.Test/UmdImageCreatorTests.cs index 5928a8fa..36bc31dc 100644 --- a/MPF.Processors.Test/UmdImageCreatorTests.cs +++ b/MPF.Processors.Test/UmdImageCreatorTests.cs @@ -67,6 +67,16 @@ namespace MPF.Processors.Test Assert.Empty(actual); } + [Fact] + public void FoundAllFiles_ValidZip_Empty() + { + string? outputDirectory = Path.Combine(Environment.CurrentDirectory, "TestData", "UmdImageCreator", "UMD-zip"); + string outputFilename = "test.iso"; + var processor = new UmdImageCreator(RedumpSystem.SonyPlayStationPortable, MediaType.UMD); + var actual = processor.FoundAllFiles(outputDirectory, outputFilename); + Assert.Empty(actual); + } + #endregion #region FoundAnyFiles diff --git a/MPF.Processors.Test/XboxBackupCreatorTests.cs b/MPF.Processors.Test/XboxBackupCreatorTests.cs index fc407d7c..e75c8bd4 100644 --- a/MPF.Processors.Test/XboxBackupCreatorTests.cs +++ b/MPF.Processors.Test/XboxBackupCreatorTests.cs @@ -67,6 +67,16 @@ namespace MPF.Processors.Test Assert.Empty(actual); } + [Fact] + public void FoundAllFiles_ValidZip_Empty() + { + string? outputDirectory = Path.Combine(Environment.CurrentDirectory, "TestData", "XboxBackupCreator", "DVD-zip"); + string outputFilename = "test.iso"; + var processor = new XboxBackupCreator(RedumpSystem.MicrosoftXbox, MediaType.DVD); + var actual = processor.FoundAllFiles(outputDirectory, outputFilename); + Assert.Empty(actual); + } + #endregion #region FoundAnyFiles diff --git a/MPF.Processors/Redumper.cs b/MPF.Processors/Redumper.cs index 9d18b6d1..1145a0a0 100644 --- a/MPF.Processors/Redumper.cs +++ b/MPF.Processors/Redumper.cs @@ -1,6 +1,10 @@ using System; using System.Collections.Generic; using System.IO; +#if NET452_OR_GREATER || NETCOREAPP +using System.IO.Compression; +using System.Linq; +#endif using System.Text; using System.Text.RegularExpressions; using SabreTools.Hashing; @@ -427,16 +431,21 @@ namespace MPF.Processors case MediaType.CDROM: case MediaType.GDROM: List cdrom = [ + // .asus is obsolete: newer redumper produces .cache instead new($"{outputFilename}.asus", OutputFileFlags.Binary | OutputFileFlags.Zippable, "asus"), new($"{outputFilename}.atip", OutputFileFlags.Binary | OutputFileFlags.Zippable, "atip"), + new($"{outputFilename}.cache", OutputFileFlags.Binary + | OutputFileFlags.Zippable, + "cache"), new($"{outputFilename}.cdtext", OutputFileFlags.Binary | OutputFileFlags.Zippable, "cdtext"), new($"{outputFilename}.cue", OutputFileFlags.Required), + new($"{outputFilename}.flip", OutputFileFlags.None), new($"{outputFilename}.fulltoc", OutputFileFlags.Required | OutputFileFlags.Binary | OutputFileFlags.Zippable, @@ -450,7 +459,6 @@ namespace MPF.Processors new($"{outputFilename}.pma", OutputFileFlags.Binary | OutputFileFlags.Zippable, "pma"), - new([$"{outputFilename}.flip"], OutputFileFlags.None), new([$"{outputFilename}.scram", $"{outputFilename}.scrap"], OutputFileFlags.Required | OutputFileFlags.Deleteable), new($"{outputFilename}.state", OutputFileFlags.Required @@ -625,7 +633,45 @@ namespace MPF.Processors /// /// Log file location private static bool DatfileExists(string log) - => GetDatfile(log) != null; + { + // Uncompressed outputs + if (GetDatfile(log) != null) + return true; + + // Check for the log file + string outputFilename = Path.GetFileName(log); + string? outputDirectory = Path.GetDirectoryName(log); + string basePath = Path.GetFileNameWithoutExtension(outputFilename); + if (!string.IsNullOrEmpty(outputDirectory)) + basePath = Path.Combine(outputDirectory, basePath); + +#if NET20 || NET35 || NET40 + // Assume the zipfile has the file in it + return File.Exists($"{basePath}_logs.zip"); +#else + // If the zipfile doesn't exist + if (!File.Exists($"{basePath}_logs.zip")) + return false; + + try + { + // Try to open the archive + using ZipArchive archive = ZipFile.OpenRead($"{basePath}_logs.zip"); + + // Get the log entry and check it, if possible + var entry = archive.GetEntry(outputFilename); + if (entry == null) + return false; + + using var sr = new StreamReader(entry.Open()); + return GetDatfile(sr) != null; + } + catch + { + return false; + } +#endif + } /// /// Copies a file with the header removed @@ -769,6 +815,24 @@ namespace MPF.Processors try { using var sr = File.OpenText(log); + return GetDatfile(sr); + } + catch + { + // We don't care what the exception is right now + return null; + } + } + + /// + /// Get the datfile from the input file, if possible + /// + /// StreamReader representing the input file + /// Newline-delimited datfile if possible, null on error + internal static string? GetDatfile(StreamReader sr) + { + try + { string? datString = null; // Find all occurrences of the hash information