Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DumpingParameters for DIC and Redumper #778

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- Add packer filtering tests
- Simplify prefix filtering
- Fix issue with odd quoting
- Add DumpingParameters for DIC and Redumper

### 3.2.4 (2024-11-24)

Expand Down
29 changes: 29 additions & 0 deletions MPF.Processors.Test/DiscImageCreatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(expectedParameters, parameters);
}

#endregion

#region GetPlayStationEXEDate

// TODO: This... is horrible
Expand Down
29 changes: 29 additions & 0 deletions MPF.Processors.Test/RedumperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "cd --verbose";
string log = Path.Combine(Environment.CurrentDirectory, "TestData", "Redumper", "CDROM", "test.log");
string? actual = Redumper.GetParameters(log);
Assert.Equal(expected, actual);
}

#endregion

#region GetVersion

[Fact]
Expand Down
3 changes: 3 additions & 0 deletions MPF.Processors.Test/TestData/Redumper/CDROM/test.log
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions MPF.Processors/DiscImageCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -820,6 +821,33 @@ internal override List<OutputFile> GetOutputFiles(string? baseDirectory, string

#region Information Extraction Methods

/// <summary>
/// Get the dumping parameters from the log, if possible
/// </summary>
/// <param name="dicCmd">Log file location</param>
/// <returns>Dumping parameters if possible, null otherwise</returns>
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();
mnadareski marked this conversation as resolved.
Show resolved Hide resolved
return line?.Trim();
}
catch
{
// We don't care what the exception is right now
return null;
}
}

/// <summary>
/// Get the PSX/PS2/KP2 EXE Date from the log, if possible
/// </summary>
Expand Down
39 changes: 39 additions & 0 deletions MPF.Processors/Redumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1818,6 +1819,44 @@ internal static bool GetSaturnBuildInfo(string? segaHeader, out string? buildDat
}
}

/// <summary>
/// Get the dumping parameters, if possible
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Dumping parameters if possible, null on error</returns>
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;
}
}

/// <summary>
/// Get all Volume Identifiers
/// </summary>
Expand Down
Loading