Handle SCSI error count (fixes #806)

This commit is contained in:
Matt Nadareski
2024-12-31 23:15:43 -05:00
parent a84904e374
commit 4fb0e38f54
4 changed files with 84 additions and 0 deletions

View File

@@ -159,6 +159,7 @@
- Fix short name test
- Update RedumpLib to 1.6.4
- Fix misunderstanding on perfect offset
- Handle SCSI error count
### 3.2.4 (2024-11-24)

View File

@@ -974,6 +974,37 @@ namespace MPF.Processors.Test
#endregion
#region GetSCSIErrorCount
[Fact]
public void GetSCSIErrorCount_Empty_Null()
{
long expected = -1;
string log = string.Empty;
long actual = Redumper.GetSCSIErrorCount(log);
Assert.Equal(expected, actual);
}
[Fact]
public void GetSCSIErrorCount_Invalid_Null()
{
long expected = -1;
string log = "INVALID";
long actual = Redumper.GetSCSIErrorCount(log);
Assert.Equal(expected, actual);
}
[Fact]
public void GetSCSIErrorCount_Valid_Filled()
{
long expected = 12345;
string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test.log");
long actual = Redumper.GetSCSIErrorCount(log);
Assert.Equal(expected, actual);
}
#endregion
#region GetSecuROMData
[Fact]

View File

@@ -126,6 +126,10 @@ SS [
00E0 TEST DATA
00F0 TEST DATA
<< GetSCSIErrorCount >>
SCSI: 23456 samples
SCSI: 12345
<< GetSecuROMData >>
SecuROM [
version: 0

View File

@@ -111,6 +111,10 @@ namespace MPF.Processors
info.SizeAndChecksums!.Layerbreak3 = !string.IsNullOrEmpty(layerbreak3) ? long.Parse(layerbreak3) : default;
}
// Attempt to get the error count
long scsiErrors = GetSCSIErrorCount($"{basePath}.log");
info.CommonDiscInfo!.ErrorsCount = (scsiErrors == -1 ? "Error retrieving error count" : scsiErrors.ToString());;
// Bluray-specific options
if (Type == MediaType.BluRay)
{
@@ -1757,6 +1761,50 @@ namespace MPF.Processors
}
}
/// <summary>
/// Get the SCSI error count from the input files, if possible
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>SCSI error count on success, -1 on error</returns>
/// TODO: Remove when Redumper adds this to normal errors
internal static long GetSCSIErrorCount(string log)
{
// If the file doesn't exist, we can't get info from it
if (string.IsNullOrEmpty(log))
return -1;
if (!File.Exists(log))
return -1;
try
{
using var sr = File.OpenText(log);
// Find the error counts
while (!sr.EndOfStream)
{
var line = sr.ReadLine()?.Trim();
if (line == null)
break;
// SCSI: <error count>
if (line.StartsWith("SCSI: ") && !line.EndsWith("samples"))
{
string[] parts = line.Split(' ');
if (long.TryParse(parts[1], out long scsiErrors))
return scsiErrors;
}
}
// We couldn't detect it then
return -1;
}
catch
{
// We don't care what the exception is right now
return -1;
}
}
/// <summary>
/// Get the SecuROM data from the input file, if possible
/// </summary>