Fill out DetermineMediaType for Redumper

This commit is contained in:
Matt Nadareski
2025-06-17 11:37:37 -04:00
parent 48e5e01729
commit 9520f58240
8 changed files with 329 additions and 23 deletions

View File

@@ -5,6 +5,7 @@
- Ignore volume labels with path separators
- Reduce media-specific checks where unnecessary
- Add DetermineMediaType scaffolding and tests
- Fill out DetermineMediaType for Redumper
### 3.3.2 (2025-06-12)

View File

@@ -11,27 +11,71 @@ namespace MPF.Processors.Test
#region DetermineMediaType
[Fact]
public void DetermineMediaType_Null_Throws()
public void DetermineMediaType_Null_Null()
{
string? basePath = null;
var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM);
Assert.Throws<NotImplementedException>(() => processor.DetermineMediaType(basePath));
var actual = processor.DetermineMediaType(basePath);
Assert.Null(actual);
}
[Fact]
public void DetermineMediaType_Invalid_Throws()
public void DetermineMediaType_Invalid_Null()
{
string? basePath = "INVALID";
var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM);
Assert.Throws<NotImplementedException>(() => processor.DetermineMediaType(basePath));
var actual = processor.DetermineMediaType(basePath);
Assert.Null(actual);
}
[Fact]
public void DetermineMediaType_Valid_Throws()
public void DetermineMediaType_BD_Filled()
{
string? basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test");
MediaType? expected = MediaType.BluRay;
string basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "BluRay", "test");
var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM);
Assert.Throws<NotImplementedException>(() => processor.DetermineMediaType(basePath));
var actual = processor.DetermineMediaType(basePath);
Assert.Equal(expected, actual);
}
[Fact]
public void DetermineMediaType_BDR_Filled()
{
MediaType? expected = MediaType.BluRay;
string basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "BDR", "test");
var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM);
var actual = processor.DetermineMediaType(basePath);
Assert.Equal(expected, actual);
}
[Fact]
public void DetermineMediaType_CD_Filled()
{
MediaType? expected = MediaType.CDROM;
string basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test");
var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM);
var actual = processor.DetermineMediaType(basePath);
Assert.Equal(expected, actual);
}
[Fact]
public void DetermineMediaType_DVD_Filled()
{
MediaType? expected = MediaType.DVD;
string basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "DVD", "test");
var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM);
var actual = processor.DetermineMediaType(basePath);
Assert.Equal(expected, actual);
}
[Fact]
public void DetermineMediaType_HDDVD_Filled()
{
MediaType? expected = MediaType.HDDVD;
string basePath = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "HDDVD", "test");
var processor = new Redumper(RedumpSystem.IBMPCcompatible, MediaType.CDROM);
var actual = processor.DetermineMediaType(basePath);
Assert.Equal(expected, actual);
}
#endregion
@@ -294,32 +338,154 @@ namespace MPF.Processors.Test
#endregion
#region GetDiscProfile
[Fact]
public void GetDiscProfile_Empty_Null()
{
string log = string.Empty;
bool actual = Redumper.GetDiscProfile(log, out string? discProfile);
Assert.False(actual);
Assert.Null(discProfile);
}
[Fact]
public void GetDiscProfile_Invalid_Null()
{
string log = "INVALID";
bool actual = Redumper.GetDiscProfile(log, out string? discProfile);
Assert.False(actual);
Assert.Null(discProfile);
}
[Fact]
public void GetDiscProfile_Valid_Filled()
{
string? expected = "CD-ROM";
string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test.log");
bool actual = Redumper.GetDiscProfile(log, out string? discProfile);
Assert.True(actual);
Assert.Equal(expected, discProfile);
}
#endregion
#region GetDiscType
[Fact]
public void GetDiscType_Empty_Null()
{
string log = string.Empty;
bool actual = Redumper.GetDiscType(log, out string? discTypeOrBookType);
bool actual = Redumper.GetDiscType(log, out MediaType? discType);
Assert.False(actual);
Assert.Null(discType);
}
[Fact]
public void GetDiscType_Invalid_Null()
{
string log = "INVALID";
bool actual = Redumper.GetDiscType(log, out string? discTypeOrBookType);
bool actual = Redumper.GetDiscType(log, out MediaType? discType);
Assert.False(actual);
Assert.Null(discType);
}
[Fact]
public void GetDiscType_Valid_Filled()
public void GetDiscType_BD_Filled()
{
string? expected = "CD-ROM";
string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test.log");
bool actual = Redumper.GetDiscType(log, out string? discTypeOrBookType);
MediaType? expected = MediaType.BluRay;
string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "BluRay", "test.log");
bool actual = Redumper.GetDiscType(log, out MediaType? discType);
Assert.True(actual);
Assert.Equal(expected, discTypeOrBookType);
Assert.Equal(expected, discType);
}
[Fact]
public void GetDiscType_BDR_Filled()
{
MediaType? expected = MediaType.BluRay;
string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "BDR", "test.log");
bool actual = Redumper.GetDiscType(log, out MediaType? discType);
Assert.True(actual);
Assert.Equal(expected, discType);
}
[Fact]
public void GetDiscType_CD_Filled()
{
MediaType? expected = MediaType.CDROM;
string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test.log");
bool actual = Redumper.GetDiscType(log, out MediaType? discType);
Assert.True(actual);
Assert.Equal(expected, discType);
}
[Fact]
public void GetDiscType_DVD_Filled()
{
MediaType? expected = MediaType.DVD;
string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "DVD", "test.log");
bool actual = Redumper.GetDiscType(log, out MediaType? discType);
Assert.True(actual);
Assert.Equal(expected, discType);
}
[Fact]
public void GetDiscType_HDDVD_Filled()
{
MediaType? expected = MediaType.HDDVD;
string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "HDDVD", "test.log");
bool actual = Redumper.GetDiscType(log, out MediaType? discType);
Assert.True(actual);
Assert.Equal(expected, discType);
}
#endregion
#region GetDiscTypeFromProfile
[Theory]
[InlineData(null, null)]
[InlineData("", null)]
[InlineData("INVALID", null)]
[InlineData("reserved", null)]
[InlineData("non removable disk", null)]
[InlineData("removable disk", null)]
[InlineData("MO erasable", null)]
[InlineData("MO write once", null)]
[InlineData("AS MO", null)]
[InlineData("CD-ROM", MediaType.CDROM)]
[InlineData("CD-R", MediaType.CDROM)]
[InlineData("CD-RW", MediaType.CDROM)]
[InlineData("DVD-ROM", MediaType.DVD)]
[InlineData("DVD-R", MediaType.DVD)]
[InlineData("DVD-RAM", MediaType.DVD)]
[InlineData("DVD-RW RO", MediaType.DVD)]
[InlineData("DVD-RW", MediaType.DVD)]
[InlineData("DVD-R DL", MediaType.DVD)]
[InlineData("DVD-R DL LJR", MediaType.DVD)]
[InlineData("DVD+RW", MediaType.DVD)]
[InlineData("DVD+R", MediaType.DVD)]
[InlineData("DDCD-ROM", MediaType.CDROM)]
[InlineData("DDCD-R", MediaType.CDROM)]
[InlineData("DDCD-RW", MediaType.CDROM)]
[InlineData("DVD+RW DL", MediaType.DVD)]
[InlineData("DVD+R DL", MediaType.DVD)]
[InlineData("BD-ROM", MediaType.BluRay)]
[InlineData("BD-R", MediaType.BluRay)]
[InlineData("BD-R RRM", MediaType.BluRay)]
[InlineData("BD-RW", MediaType.BluRay)]
[InlineData("HD DVD-ROM", MediaType.HDDVD)]
[InlineData("HD DVD-R", MediaType.HDDVD)]
[InlineData("HD DVD-RAM", MediaType.HDDVD)]
[InlineData("HD DVD-RW", MediaType.HDDVD)]
[InlineData("HD DVD-R DL", MediaType.HDDVD)]
[InlineData("HD DVD-RW DL", MediaType.HDDVD)]
[InlineData("NON STANDARD", null)]
public void GetDiscTypeFromProfileTest(string? profile, MediaType? expected)
{
var actual = Redumper.GetDiscTypeFromProfile(profile);
Assert.Equal(expected, actual);
}
#endregion

View File

@@ -0,0 +1,3 @@
<< GetDiscType >>
disc type: INVALID
disc type: BLURAY-R

View File

@@ -0,0 +1,3 @@
<< GetDiscType >>
disc type: INVALID
disc type: BLURAY

View File

@@ -13,9 +13,13 @@ CUE [
dat:
<rom name="INVALID" size="12345" crc="00000000" md5="d41d8cd98f00b204e9800998ecf8427e" sha1="da39a3ee5e6b4b0d3255bfef95601890afd80709" />
<< GetDiscType >>
<< GetDiscProfile >>
current profile: CD-ROM
<< GetDiscType >>
disc type: INVALID
disc type: CD
<< GetDVDProtection >>
copyright:
protection system type: none

View File

@@ -0,0 +1,3 @@
<< GetDiscType >>
disc type: INVALID
disc type: DVD

View File

@@ -0,0 +1,3 @@
<< GetDiscType >>
disc type: INVALID
disc type: HD-DVD

View File

@@ -25,7 +25,20 @@ namespace MPF.Processors
/// <inheritdoc/>
public override MediaType? DetermineMediaType(string? basePath)
{
throw new NotImplementedException();
// If the base path is invalid
if (string.IsNullOrEmpty(basePath))
return null;
// Use the log first, if it exists
if (GetDiscType($"{basePath}.log", out MediaType? mediaType))
return mediaType;
// Use the profile for older Redumper versions
if (GetDiscProfile($"{basePath}.log", out string? discProfile))
return GetDiscTypeFromProfile(discProfile);
// The type could not be determined
return null;
}
/// <inheritdoc/>
@@ -49,7 +62,7 @@ namespace MPF.Processors
}
// Fill in the disc type data
if (GetDiscType($"{basePath}.log", out var discTypeOrBookType))
if (GetDiscProfile($"{basePath}.log", out var discTypeOrBookType))
info.DumpingInfo.ReportedDiscType = discTypeOrBookType;
// Get the PVD, if it exists
@@ -873,14 +886,14 @@ namespace MPF.Processors
}
/// <summary>
/// Get reported disc type information, if possible
/// Get reported disc profile information, if possible
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>True if disc type info was set, false otherwise</returns>
internal static bool GetDiscType(string log, out string? discTypeOrBookType)
/// <returns>True if disc profile information was set, false otherwise</returns>
internal static bool GetDiscProfile(string log, out string? discProfile)
{
// Set the default values
discTypeOrBookType = null;
discProfile = null;
// If the file doesn't exist, we can't get the info
if (string.IsNullOrEmpty(log))
@@ -901,7 +914,7 @@ namespace MPF.Processors
if (line.StartsWith("current profile:"))
{
// current profile: <discType>
discTypeOrBookType = line.Substring("current profile: ".Length);
discProfile = line.Substring("current profile: ".Length);
}
line = sr.ReadLine();
@@ -912,11 +925,121 @@ namespace MPF.Processors
catch
{
// We don't care what the exception is right now
discTypeOrBookType = null;
discProfile = null;
return false;
}
}
/// <summary>
/// Get reported disc type, if possible
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>True if disc type was set, false otherwise</returns>
internal static bool GetDiscType(string log, out MediaType? discType)
{
// Set the default values
discType = null;
// If the file doesn't exist, we can't get the info
if (string.IsNullOrEmpty(log))
return false;
if (!File.Exists(log))
return false;
try
{
using var sr = File.OpenText(log);
var line = sr.ReadLine()?.TrimEnd();
while (line != null)
{
// If the line isn't the non-embedded disc type, skip
if (!line.StartsWith("disc type:"))
{
line = sr.ReadLine()?.TrimEnd();
continue;
}
// disc type: <discType>
string discTypeStr = line.Substring("disc type: ".Length);
// Set the media type based on the string
discType = discTypeStr switch
{
"CD" => MediaType.CDROM,
"DVD" => MediaType.DVD,
"BLURAY" => MediaType.BluRay,
"BLURAY-R" => MediaType.BluRay,
"HD-DVD" => MediaType.HDDVD,
_ => null,
};
return discType != null;
}
return false;
}
catch
{
// We don't care what the exception is right now
discType = null;
return false;
}
}
/// <summary>
/// Convert the profile to a media type, if possible
/// </summary>
/// <param name="profile">Profile string to check</param>
/// <returns>Media type on success, null otherwise</returns>
internal static MediaType? GetDiscTypeFromProfile(string? profile)
{
return profile switch
{
"reserved" => null,
"non removable disk" => null,
"removable disk" => null,
"MO erasable" => null,
"MO write once" => null,
"AS MO" => null,
"CD-ROM" => MediaType.CDROM,
"CD-R" => MediaType.CDROM,
"CD-RW" => MediaType.CDROM,
"DVD-ROM" => MediaType.DVD,
"DVD-R" => MediaType.DVD,
"DVD-RAM" => MediaType.DVD,
"DVD-RW RO" => MediaType.DVD,
"DVD-RW" => MediaType.DVD,
"DVD-R DL" => MediaType.DVD,
"DVD-R DL LJR" => MediaType.DVD,
"DVD+RW" => MediaType.DVD,
"DVD+R" => MediaType.DVD,
"DDCD-ROM" => MediaType.CDROM,
"DDCD-R" => MediaType.CDROM,
"DDCD-RW" => MediaType.CDROM,
"DVD+RW DL" => MediaType.DVD,
"DVD+R DL" => MediaType.DVD,
"BD-ROM" => MediaType.BluRay,
"BD-R" => MediaType.BluRay,
"BD-R RRM" => MediaType.BluRay,
"BD-RW" => MediaType.BluRay,
"HD DVD-ROM" => MediaType.HDDVD,
"HD DVD-R" => MediaType.HDDVD,
"HD DVD-RAM" => MediaType.HDDVD,
"HD DVD-RW" => MediaType.HDDVD,
"HD DVD-R DL" => MediaType.HDDVD,
"HD DVD-RW DL" => MediaType.HDDVD,
"NON STANDARD" => null,
_ => null,
};
}
/// <summary>
/// Get the DVD protection information, if possible
/// </summary>