diff --git a/CHANGELIST.md b/CHANGELIST.md
index 808a25ff..ce0292c1 100644
--- a/CHANGELIST.md
+++ b/CHANGELIST.md
@@ -8,6 +8,7 @@
- Ensure SS.bin only required for DVD
- Update tests to account for new file count
- Add tests around some Aaru helpers
+- Add tests around CleanRip helpers
### 3.2.4 (2024-11-24)
diff --git a/MPF.Processors.Test/CleanRipTests.cs b/MPF.Processors.Test/CleanRipTests.cs
index 910d2ef1..48c44fd0 100644
--- a/MPF.Processors.Test/CleanRipTests.cs
+++ b/MPF.Processors.Test/CleanRipTests.cs
@@ -153,5 +153,137 @@ namespace MPF.Processors.Test
}
#endregion
+
+ #region GenerateCleanripDatafile
+
+ [Fact]
+ public void GenerateCleanripDatafile_NoIsoNoDumpinfo_Null()
+ {
+ string iso = "INVALID";
+ string dumpinfo = "INVALID";
+
+ var actual = CleanRip.GenerateCleanripDatafile(iso, dumpinfo);
+ Assert.Null(actual);
+ }
+
+ [Fact]
+ public void GenerateCleanripDatafile_IsoOnly_Filled()
+ {
+ string iso = Path.Combine(Environment.CurrentDirectory, "TestData", "CleanRip", "DVD", "test.iso");
+ string dumpinfo = "INVALID";
+
+ var actual = CleanRip.GenerateCleanripDatafile(iso, dumpinfo);
+ Assert.NotNull(actual);
+
+ Assert.NotNull(actual.Game);
+ var game = Assert.Single(actual.Game);
+
+ Assert.NotNull(game.Rom);
+ var rom = Assert.Single(game.Rom);
+ Assert.Equal("9", rom.Size);
+ Assert.Equal("560b9f59", rom.CRC);
+ Assert.Equal("edbb6676247e65c2245dd4883ed9fc24", rom.MD5);
+ Assert.Equal("1b33ad54d78085be5ecb1cf1b3e9da821e708075", rom.SHA1);
+ }
+
+ [Fact]
+ public void GenerateCleanripDatafile_DumpinfoOnly_Filled()
+ {
+ string iso = "INVALID";
+ string dumpinfo = Path.Combine(Environment.CurrentDirectory, "TestData", "CleanRip", "DVD", "test-dumpinfo.txt");
+
+ var actual = CleanRip.GenerateCleanripDatafile(iso, dumpinfo);
+ Assert.NotNull(actual);
+
+ Assert.NotNull(actual.Game);
+ var game = Assert.Single(actual.Game);
+
+ Assert.NotNull(game.Rom);
+ var rom = Assert.Single(game.Rom);
+ Assert.Equal("-1", rom.Size);
+ Assert.Equal("00000000", rom.CRC);
+ Assert.Equal("d41d8cd98f00b204e9800998ecf8427e", rom.MD5);
+ Assert.Equal("da39a3ee5e6b4b0d3255bfef95601890afd80709", rom.SHA1);
+ }
+
+ [Fact]
+ public void GenerateCleanripDatafile_BothValid_Filled()
+ {
+ string iso = Path.Combine(Environment.CurrentDirectory, "TestData", "CleanRip", "DVD", "test.iso");
+ string dumpinfo = Path.Combine(Environment.CurrentDirectory, "TestData", "CleanRip", "DVD", "test-dumpinfo.txt");
+
+ var actual = CleanRip.GenerateCleanripDatafile(iso, dumpinfo);
+ Assert.NotNull(actual);
+
+ Assert.NotNull(actual.Game);
+ var game = Assert.Single(actual.Game);
+
+ Assert.NotNull(game.Rom);
+ var rom = Assert.Single(game.Rom);
+ Assert.Equal("9", rom.Size);
+ Assert.Equal("00000000", rom.CRC);
+ Assert.Equal("d41d8cd98f00b204e9800998ecf8427e", rom.MD5);
+ Assert.Equal("da39a3ee5e6b4b0d3255bfef95601890afd80709", rom.SHA1);
+ }
+
+ #endregion
+
+ #region GetBCA
+
+ [Fact]
+ public void GetBCA_InvalidPath_Null()
+ {
+ string bcaPath = "INVALID";
+ string? actual = CleanRip.GetBCA(bcaPath);
+ Assert.Null(actual);
+ }
+
+ [Fact]
+ public void GetBCA_ValidPath_Formatted()
+ {
+ string expected = "0001 0203 0405 0607 0809 0A0B 0C0D 0E0F\n0001 0203 0405 0607 0809 0A0B 0C0D 0E0F\n0001 0203 0405 0607 0809 0A0B 0C0D 0E0F\n0001 0203 0405 0607 0809 0A0B 0C0D 0E0F\n0001 0203 0405 0607 0809 0A0B 0C0D 0E0F\n0001 0203 0405 0607 0809 0A0B 0C0D 0E0F\n0001 0203 0405 0607 0809 0A0B 0C0D 0E0F\n0001 0203 0405 0607 0809 0A0B 0C0D 0E0F\n0001 0203 0405 0607 0809 0A0B 0C0D 0E0F\n0001 0203 0405 0607 0809 0A0B 0C0D 0E0F\n";
+ string bcaPath = Path.Combine(Environment.CurrentDirectory, "TestData", "CleanRip", "DVD", "test.bca");
+
+ string? actual = CleanRip.GetBCA(bcaPath);
+ Assert.NotNull(actual);
+ Assert.Equal(expected, actual);
+ }
+
+ #endregion
+
+ #region GetGameCubeWiiInformation
+
+ [Fact]
+ public void GetGameCubeWiiInformation_NoFile_False()
+ {
+ string dumpinfo = string.Empty;
+ bool actual = CleanRip.GetGameCubeWiiInformation(dumpinfo, out Region? region, out string? version, out string? name, out string? serial);
+
+ Assert.False(actual);
+ Assert.Null(region);
+ Assert.Null(version);
+ Assert.Null(name);
+ Assert.Null(serial);
+ }
+
+ [Fact]
+ public void GetGameCubeWiiInformation_Filled_True()
+ {
+ Region? expectedRegion = Region.World;
+ string? expectedVersion = "version";
+ string? expectedName = "name";
+ string? expectedSerial = "000A00";
+
+ string dumpinfo = Path.Combine(Environment.CurrentDirectory, "TestData", "CleanRip", "DVD", "test-dumpinfo.txt");
+ bool actual = CleanRip.GetGameCubeWiiInformation(dumpinfo, out Region? region, out string? version, out string? name, out string? serial);
+
+ Assert.True(actual);
+ Assert.Equal(expectedRegion, region);
+ Assert.Equal(expectedVersion, version);
+ Assert.Equal(expectedName, name);
+ Assert.Equal(expectedSerial, serial);
+ }
+
+ #endregion
}
}
\ No newline at end of file
diff --git a/MPF.Processors.Test/TestData/CleanRip/DVD/test-dumpinfo.txt b/MPF.Processors.Test/TestData/CleanRip/DVD/test-dumpinfo.txt
index 1aa4b5d8..0c78def6 100644
--- a/MPF.Processors.Test/TestData/CleanRip/DVD/test-dumpinfo.txt
+++ b/MPF.Processors.Test/TestData/CleanRip/DVD/test-dumpinfo.txt
@@ -1 +1,7 @@
-TEST DATA
\ No newline at end of file
+--File Generated by CleanRip
+CRC32: 00000000
+MD5: d41d8cd98f00b204e9800998ecf8427e
+SHA-1: da39a3ee5e6b4b0d3255bfef95601890afd80709
+Version: version
+Internal Name: name
+Filename: 000A00
\ No newline at end of file
diff --git a/MPF.Processors.Test/TestData/CleanRip/DVD/test.bca b/MPF.Processors.Test/TestData/CleanRip/DVD/test.bca
index 1aa4b5d8..1c3094c6 100644
Binary files a/MPF.Processors.Test/TestData/CleanRip/DVD/test.bca and b/MPF.Processors.Test/TestData/CleanRip/DVD/test.bca differ
diff --git a/MPF.Processors/CleanRip.cs b/MPF.Processors/CleanRip.cs
index 1d59a2a0..65eafb52 100644
--- a/MPF.Processors/CleanRip.cs
+++ b/MPF.Processors/CleanRip.cs
@@ -100,13 +100,14 @@ namespace MPF.Processors
/// Path to ISO file
/// Path to discinfo file
///
- private static Datafile? GenerateCleanripDatafile(string iso, string dumpinfo)
+ internal static Datafile? GenerateCleanripDatafile(string iso, string dumpinfo)
{
- // If the files don't exist, we can't get info from it
- if (!File.Exists(iso) || !File.Exists(dumpinfo))
- return null;
+ // Get the size from the ISO, if possible
+ long size = iso.Length > 0 && File.Exists(iso)
+ ? new FileInfo(iso).Length
+ : -1;
- long size = new FileInfo(iso).Length;
+ // Setup the hashes
string crc = string.Empty;
string md5 = string.Empty;
string sha1 = string.Empty;
@@ -114,22 +115,25 @@ namespace MPF.Processors
try
{
// Make sure this file is a dumpinfo
- using var sr = File.OpenText(dumpinfo);
- if (sr.ReadLine()?.Contains("--File Generated by CleanRip") != true)
- return null;
-
- // Read all lines and gather dat information
- while (!sr.EndOfStream)
+ if (dumpinfo.Length > 0 && File.Exists(dumpinfo))
{
- var line = sr.ReadLine()?.Trim();
- if (string.IsNullOrEmpty(line))
- continue;
- else if (line!.StartsWith("CRC32"))
- crc = line.Substring(7).ToLowerInvariant();
- else if (line.StartsWith("MD5"))
- md5 = line.Substring(5);
- else if (line.StartsWith("SHA-1"))
- sha1 = line.Substring(7);
+ using var sr = File.OpenText(dumpinfo);
+ if (sr.ReadLine()?.Contains("--File Generated by CleanRip") != true)
+ return null;
+
+ // Read all lines and gather dat information
+ while (!sr.EndOfStream)
+ {
+ var line = sr.ReadLine()?.Trim();
+ if (string.IsNullOrEmpty(line))
+ continue;
+ else if (line!.StartsWith("CRC32"))
+ crc = line.Substring(7).ToLowerInvariant();
+ else if (line.StartsWith("MD5"))
+ md5 = line.Substring(5);
+ else if (line.StartsWith("SHA-1"))
+ sha1 = line.Substring(7);
+ }
}
// Ensure all checksums were found in log
@@ -143,6 +147,10 @@ namespace MPF.Processors
}
}
+ // If no information could be found
+ if (size == -1 && crc == string.Empty && md5 == string.Empty && sha1 == string.Empty)
+ return null;
+
return new Datafile
{
Game = [new Game() { Rom = [new Rom { Name = Path.GetFileName(iso), Size = size.ToString(), CRC = crc, MD5 = md5, SHA1 = sha1 }] }]