Skip to content

Commit

Permalink
Partially clean up PS3CFW
Browse files Browse the repository at this point in the history
  • Loading branch information
mnadareski committed Dec 28, 2024
1 parent 6b8cfb4 commit d3e208a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 75 deletions.
1 change: 1 addition & 0 deletions CHANGELIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
- Improve PS4/PS5 parsing
- Don't add special field keys with no reason
- Add pure-getkey output names for PS3CFW
- Partially clean up PS3CFW

### 3.2.4 (2024-11-24)

Expand Down
29 changes: 0 additions & 29 deletions MPF.Processors.Test/PS3CFWTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,34 +195,5 @@ public void GeneratePS3CFWDatafile_Valid_Filled()
}

#endregion

#region GetCFWBasePath

[Fact]
public void GetCFWBasePath_Empty_Null()
{
string iso = string.Empty;
string? actual = PS3CFW.GetCFWBasePath(iso);
Assert.Null(actual);
}

[Fact]
public void GetCFWBasePath_Invalid_Null()
{
string iso = "INVALID";
string? actual = PS3CFW.GetCFWBasePath(iso);
Assert.Null(actual);
}

[Fact]
public void GetCFWBasePath_Valid_Filled()
{
string iso = Path.Combine(Environment.CurrentDirectory, "TestData", "PS3CFW", "BluRay", "test.iso");
string? actual = PS3CFW.GetCFWBasePath(iso);

Assert.NotNull(actual);
}

#endregion
}
}
71 changes: 25 additions & 46 deletions MPF.Processors/PS3CFW.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, string basePath
// Ensure that required sections exist
info = Builder.EnsureAllSections(info);

// Try to determine the ISO file
string isoPath = string.Empty;
if (File.Exists($"{basePath}.iso"))
isoPath = $"{basePath}.iso";
else if (File.Exists($"{basePath}.ISO"))
isoPath = $"{basePath}.ISO";

// TODO: Determine if there's a CFW version anywhere
info.DumpingInfo!.DumpingDate = ProcessingTool.GetFileModifiedDate(basePath + ".iso")?.ToString("yyyy-MM-dd HH:mm:ss");
info.DumpingInfo!.DumpingDate = ProcessingTool.GetFileModifiedDate(isoPath)?.ToString("yyyy-MM-dd HH:mm:ss");

// Get the Datafile information
Datafile? datafile = GeneratePS3CFWDatafile(basePath + ".iso");
Datafile? datafile = GeneratePS3CFWDatafile(isoPath);

// Fill in the hash data
info.TracksAndWriteOffsets!.ClrMameProData = ProcessingTool.GenerateDatfile(datafile);
Expand All @@ -42,25 +49,31 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, string basePath
}

// Get the PVD from the ISO
if (GetPVD(basePath + ".iso", out string? pvd))
if (GetPVD(isoPath, out string? pvd))
info.Extras!.PVD = pvd;

// Try to determine the name of the GetKey file(s)
string? getKeyBasePath = GetCFWBasePath(basePath);
// Get the base directory
string baseDir = Path.GetDirectoryName(basePath) ?? string.Empty;

// If GenerateSubmissionInfo is run, getkey.log existence should already be checked
if (!File.Exists(getKeyBasePath + "getkey.log"))
return;
// Try to determine the name of the GetKey file
string getKeyPath = string.Empty;
if (File.Exists($"{basePath}.getkey.log"))
getKeyPath = $"{basePath}.getkey.log";
else if (File.Exists(Path.Combine(baseDir, "getkey.log")))
getKeyPath = Path.Combine(baseDir, "getkey.log");

// Get dumping date from GetKey log date
info.DumpingInfo.DumpingDate = ProcessingTool.GetFileModifiedDate(getKeyBasePath + "getkey.log")?.ToString("yyyy-MM-dd HH:mm:ss");
if (!string.IsNullOrEmpty(getKeyPath))
info.DumpingInfo.DumpingDate = ProcessingTool.GetFileModifiedDate(getKeyPath)?.ToString("yyyy-MM-dd HH:mm:ss");

// TODO: Put info about abnormal PIC info beyond 132 bytes in comments?
if (File.Exists(getKeyBasePath + "disc.pic"))
info.Extras!.PIC = GetPIC(getKeyBasePath + "disc.pic", 264);
if (File.Exists($"{basePath}.disc.pic"))
info.Extras!.PIC = GetPIC($"{basePath}.disc.pic", 264);
else if (File.Exists(Path.Combine(baseDir, "disc.pic")))
info.Extras!.PIC = GetPIC(Path.Combine(baseDir, "disc.pic"), 264);

// Parse Disc Key, Disc ID, and PIC from the getkey.log file
if (ProcessingTool.ParseGetKeyLog(getKeyBasePath + "getkey.log", out string? key, out string? id, out string? pic))
if (ProcessingTool.ParseGetKeyLog(getKeyPath, out string? key, out string? id, out string? pic))
{
if (key != null)
info.Extras!.DiscKey = key.ToUpperInvariant();
Expand Down Expand Up @@ -130,39 +143,5 @@ internal override List<OutputFile> GetOutputFiles(string? baseDirectory, string
}

#endregion

#region Helper Functions

/// <summary>
/// Estimate the base filename of the getkey.log file associated with the dump
/// </summary>
/// <param name="iso">Path to ISO file</param>
/// <returns>Base filename, null if not found</returns>
internal static string? GetCFWBasePath(string iso)
{
// If the ISO file doesn't exist
if (string.IsNullOrEmpty(iso))
return null;
if (!File.Exists(iso))
return null;

try
{
string dir = Path.GetDirectoryName(iso) ?? ".";
string[] files = Directory.GetFiles(dir, "*getkey.log");

if (files.Length != 1)
return null;

return files[0].Substring(0, files[0].Length - 10);
}
catch
{
// We don't care what the exception is right now
return null;
}
}

#endregion
}
}

0 comments on commit d3e208a

Please sign in to comment.