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

Parse PSX/PS2/KP2 exe date from logs #639

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Fix information pulling for CleanRip and UIC
- Add UMD handling for the disc info window
- Detect Photo CD
- Parse PSX/PS2/KP2 exe date from logs (Deterous)

### 3.0.3 (2023-12-04)

Expand Down
73 changes: 73 additions & 0 deletions MPF.Core/Modules/DiscImageCreator/Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, Options options
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? pythonTwoRegion;
info.CommonDiscInfo.EXEDateBuildDate = pythonTwoDate;
}
if (info.CommonDiscInfo!.CommentsSpecialFields!.TryGetValue(SiteCode.InternalSerialName, out string? kp2Serial))
mnadareski marked this conversation as resolved.
Show resolved Hide resolved
info.CommonDiscInfo!.EXEDateBuildDate = GetEXEDate($"{basePath}_volDesc.txt", kp2Serial) ?? info.CommonDiscInfo.EXEDateBuildDate;

info.VersionAndEditions!.Version = InfoTool.GetPlayStation2Version(drive?.Name) ?? string.Empty;
break;
Expand Down Expand Up @@ -792,6 +794,8 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, Options options
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationRegion;
info.CommonDiscInfo.EXEDateBuildDate = playstationDate;
}
if (info.CommonDiscInfo!.CommentsSpecialFields!.TryGetValue(SiteCode.InternalSerialName, out string? psxSerial))
info.CommonDiscInfo!.EXEDateBuildDate = GetEXEDate($"{basePath}_volDesc.txt", psxSerial, true) ?? info.CommonDiscInfo.EXEDateBuildDate;

bool? psEdcStatus = null;
if (File.Exists($"{basePath}.img_EdcEcc.txt"))
Expand All @@ -811,6 +815,8 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, Options options
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationTwoRegion;
info.CommonDiscInfo.EXEDateBuildDate = playstationTwoDate;
}
if (info.CommonDiscInfo!.CommentsSpecialFields!.TryGetValue(SiteCode.InternalSerialName, out string? ps2Serial))
info.CommonDiscInfo!.EXEDateBuildDate = GetEXEDate($"{basePath}_volDesc.txt", ps2Serial) ?? info.CommonDiscInfo.EXEDateBuildDate;

info.VersionAndEditions!.Version = InfoTool.GetPlayStation2Version(drive?.Name) ?? string.Empty;
break;
Expand Down Expand Up @@ -2971,6 +2977,73 @@ private static long GetErrorCount(string edcecc)
}
}

/// <summary>
/// Get the PSX/PS2/KP2 EXE Date from the log, if possible
/// </summary>
/// <param name="log">Log file location</param>
/// <param name="serial">Internal serial</param>
/// <param name="psx">True if PSX disc, false otherwise</param>
/// <returns>EXE date if possible, null otherwise</returns>
public static string? GetEXEDate(string log, string? serial, bool psx = false)
{
// If the file doesn't exist, we can't get the info
if (!File.Exists(log))
return null;

// If the serial is not valid, we can't get the info
if (serial == null || serial.Length != 10)
return null;

// First 11 characters of exe filename follow ABCD_123.45 (corresponds to ABCD-12345)
string filename = $"{serial.Substring(0, 4)}_{serial.Substring(5, 3)}.{serial.Substring(8, 2)}";

try
{
string? exeDate = null;
using var sr = File.OpenText(log);
var line = sr.ReadLine();
while (line != null)
{
// Trim the line for later use
line = line.Trim();

// The exe date is listed in a single line, File Identifier: ABCD_123.45;1
if (line.Length >= "File Identifier: ".Length + 11 &&
line.StartsWith("File Identifier:") &&
line.Substring("File Identifier: ".Length, 11) == filename)
{
// Account for PSX date formatting
if (psx && exeDate != null && exeDate!.Substring(0, 2) == "19")
{
string decade = exeDate!.Substring(2, 1);
if (decade == "0" || decade == "1" || decade == "2" || decade == "3" || decade == "4" || decade == "5" || decade == "6")
exeDate = $"20{exeDate!.Substring(2)}";
}

// Currently stored date is the EXE date, return it
return exeDate;
}

// The exe datetime is listed in a single line
if (line.Length >= "Recording Date and Time: ".Length + 10 &&
line.StartsWith("Recording Date and Time:"))
{
// exe date: ISO datetime (yyyy-MM-ddT.....)
exeDate = line.Substring("Recording Date and Time: ".Length, 10);
}

line = sr.ReadLine();
}

return null;
}
catch
{
// We don't care what the exception is right now
return null;
}
}

/// <summary>
/// Get the build info from a GD-ROM LD area, if possible
/// </summary>
Expand Down
48 changes: 45 additions & 3 deletions MPF.Core/Modules/Redumper/Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,13 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, Options options
break;

case RedumpSystem.KonamiPython2:
info.CommonDiscInfo!.EXEDateBuildDate = GetEXEDate($"{basePath}.log");
if (InfoTool.GetPlayStationExecutableInfo(drive?.Name, out var pythonTwoSerial, out Region? pythonTwoRegion, out var pythonTwoDate))
{
// Ensure internal serial is pulled from local data
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = pythonTwoSerial ?? string.Empty;
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? pythonTwoRegion;
info.CommonDiscInfo.EXEDateBuildDate = pythonTwoDate;
info.CommonDiscInfo.EXEDateBuildDate ??= pythonTwoDate;
}

info.VersionAndEditions!.Version = InfoTool.GetPlayStation2Version(drive?.Name) ?? string.Empty;
Expand Down Expand Up @@ -477,12 +478,13 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, Options options
break;

case RedumpSystem.SonyPlayStation:
info.CommonDiscInfo!.EXEDateBuildDate = GetEXEDate($"{basePath}.log");
if (InfoTool.GetPlayStationExecutableInfo(drive?.Name, out var playstationSerial, out Region? playstationRegion, out var playstationDate))
{
// Ensure internal serial is pulled from local data
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = playstationSerial ?? string.Empty;
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationRegion;
info.CommonDiscInfo.EXEDateBuildDate = playstationDate;
info.CommonDiscInfo.EXEDateBuildDate ??= playstationDate;
}

info.CopyProtection!.AntiModchip = GetPlayStationAntiModchipDetected($"{basePath}.log").ToYesNo();
Expand All @@ -492,12 +494,13 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, Options options
break;

case RedumpSystem.SonyPlayStation2:
info.CommonDiscInfo!.EXEDateBuildDate = GetEXEDate($"{basePath}.log");
if (InfoTool.GetPlayStationExecutableInfo(drive?.Name, out var playstationTwoSerial, out Region? playstationTwoRegion, out var playstationTwoDate))
{
// Ensure internal serial is pulled from local data
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = playstationTwoSerial ?? string.Empty;
info.CommonDiscInfo.Region = info.CommonDiscInfo.Region ?? playstationTwoRegion;
info.CommonDiscInfo.EXEDateBuildDate = playstationTwoDate;
info.CommonDiscInfo.EXEDateBuildDate ??= playstationTwoDate;
}

info.VersionAndEditions!.Version = InfoTool.GetPlayStation2Version(drive?.Name) ?? string.Empty;
Expand Down Expand Up @@ -1686,6 +1689,45 @@ public static long GetErrorCount(string log)
}
}

/// <summary>
/// Get the EXE Date from the log, if possible
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>EXE date if possible, null otherwise</returns>
public static string? GetEXEDate(string log)
{
// If the file doesn't exist, we can't get the info
if (!File.Exists(log))
return null;

try
{
using var sr = File.OpenText(log);
var line = sr.ReadLine();
while (line != null)
{
// Trim the line for later use
line = line.Trim();

// The exe date is listed in a single line
if (line.StartsWith("EXE date:"))
{
// exe date: yyyy-MM-dd
return line.Substring("EXE date: ".Length);
}

line = sr.ReadLine();
}

return null;
}
catch
{
// We don't care what the exception is right now
return null;
}
}

/// <summary>
/// Get hardware information from the input file, if possible
/// </summary>
Expand Down