Hacky move of DIC-specific code

This commit is contained in:
Matt Nadareski
2024-05-28 13:00:39 -04:00
parent 12a13a2ffa
commit 3b21fa62a0
3 changed files with 82 additions and 79 deletions

View File

@@ -147,6 +147,7 @@
- Move EnumExtensions to Frontend
- Treat KP2 like PS2 in DIC
- Slight readability cleanup in DIC
- Hacky move of DIC-specific code
### 3.1.9a (2024-05-21)

View File

@@ -105,7 +105,7 @@ namespace MPF.Frontend
ProcessMediaType(info, mediaType, options.AddPlaceholders);
// Extract info based specifically on RedumpSystem
ProcessSystem(info, system, drive, options.AddPlaceholders);
ProcessSystem(info, system, drive, options.AddPlaceholders, processor is DiscImageCreator, combinedBase);
// Run anti-modchip check, if necessary
if (drive != null && SupportsAntiModchipScans(system) && info.CopyProtection!.AntiModchip == YesNo.NULL)
@@ -613,7 +613,7 @@ namespace MPF.Frontend
/// <summary>
/// Processes default data based on system type
/// </summary>
private static bool ProcessSystem(SubmissionInfo info, RedumpSystem? system, Drive? drive, bool addPlaceholders)
private static bool ProcessSystem(SubmissionInfo info, RedumpSystem? system, Drive? drive, bool addPlaceholders, bool isDiscImageCreator, string basePath)
{
// Extract info based specifically on RedumpSystem
switch (system)
@@ -703,6 +703,10 @@ namespace MPF.Frontend
break;
case RedumpSystem.KonamiPython2:
// TODO: Remove this hack
if (isDiscImageCreator)
info.CommonDiscInfo!.EXEDateBuildDate = DiscImageCreator.GetPlayStationEXEDate($"{basePath}_volDesc.txt", drive?.GetPlayStationExecutableName());
if (info.CommonDiscInfo!.CommentsSpecialFields!.TryGetValue(SiteCode.InternalSerialName, out string? kp2Exe) && string.IsNullOrEmpty(kp2Exe))
info.CommonDiscInfo.Region = Drive.GetPlayStationRegion(kp2Exe);
@@ -810,6 +814,10 @@ namespace MPF.Frontend
break;
case RedumpSystem.SonyPlayStation:
// TODO: Remove this hack
if (isDiscImageCreator)
info.CommonDiscInfo!.EXEDateBuildDate = DiscImageCreator.GetPlayStationEXEDate($"{basePath}_volDesc.txt", drive?.GetPlayStationExecutableName(), psx: true);
if (info.CommonDiscInfo!.CommentsSpecialFields!.TryGetValue(SiteCode.InternalSerialName, out string? psxExe) && string.IsNullOrEmpty(psxExe))
info.CommonDiscInfo.Region = Drive.GetPlayStationRegion(psxExe);
@@ -826,6 +834,10 @@ namespace MPF.Frontend
case RedumpSystem.SonyPlayStation2:
info.CommonDiscInfo!.LanguageSelection ??= [];
// TODO: Remove this hack
if (isDiscImageCreator)
info.CommonDiscInfo!.EXEDateBuildDate = DiscImageCreator.GetPlayStationEXEDate($"{basePath}_volDesc.txt", drive?.GetPlayStationExecutableName());
if (info.CommonDiscInfo!.CommentsSpecialFields!.TryGetValue(SiteCode.InternalSerialName, out string? ps2Exe) && string.IsNullOrEmpty(ps2Exe))
info.CommonDiscInfo.Region = Drive.GetPlayStationRegion(ps2Exe);

View File

@@ -450,10 +450,6 @@ namespace MPF.Processors
info.CopyProtection!.Protection = GetDVDProtection($"{basePath}_CSSKey.txt", $"{basePath}_disc.txt", true) ?? string.Empty;
break;
case RedumpSystem.KonamiPython2:
info.CommonDiscInfo!.EXEDateBuildDate = GetPlayStationEXEDate($"{basePath}_volDesc.txt", drive?.GetPlayStationExecutableName());
break;
case RedumpSystem.MicrosoftXbox:
string xmidString;
if (string.IsNullOrEmpty(outputDirectory))
@@ -686,8 +682,6 @@ namespace MPF.Processors
break;
case RedumpSystem.SonyPlayStation:
info.CommonDiscInfo!.EXEDateBuildDate = GetPlayStationEXEDate($"{basePath}_volDesc.txt", drive?.GetPlayStationExecutableName(), true);
bool? psEdcStatus = null;
if (File.Exists($"{basePath}.img_EdcEcc.txt"))
psEdcStatus = GetPlayStationEDCStatus($"{basePath}.img_EdcEcc.txt");
@@ -700,10 +694,6 @@ namespace MPF.Processors
info.CopyProtection.LibCrypt = libCryptDetected;
info.CopyProtection.LibCryptData = libCryptData;
break;
case RedumpSystem.SonyPlayStation2:
info.CommonDiscInfo!.EXEDateBuildDate = GetPlayStationEXEDate($"{basePath}_volDesc.txt", drive?.GetPlayStationExecutableName());
break;
}
}
@@ -923,6 +913,73 @@ namespace MPF.Processors
#region Information Extraction Methods
/// <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? GetPlayStationEXEDate(string log, string? exeName, bool psx = false)
{
// If the file doesn't exist, we can't get the info
if (!File.Exists(log))
return null;
// If the EXE name is not valid, we can't get the info
if (string.IsNullOrEmpty(exeName))
return null;
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) == exeName)
{
// Account for Y2K date problem
if (exeDate != null && exeDate.Substring(0, 2) == "19")
{
string decade = exeDate!.Substring(2, 1);
// Does only PSX need to account for 1920s-60s?
if (decade == "0" || decade == "1" ||
psx && (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 reported disc type information, if possible
/// </summary>
@@ -1579,73 +1636,6 @@ namespace MPF.Processors
}
}
/// <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>
private static string? GetPlayStationEXEDate(string log, string? exeName, bool psx = false)
{
// If the file doesn't exist, we can't get the info
if (!File.Exists(log))
return null;
// If the EXE name is not valid, we can't get the info
if (string.IsNullOrEmpty(exeName))
return null;
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) == exeName)
{
// Account for Y2K date problem
if (exeDate != null && exeDate.Substring(0, 2) == "19")
{
string decade = exeDate!.Substring(2, 1);
// Does only PSX need to account for 1920s-60s?
if (decade == "0" || decade == "1" ||
psx && (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 PVD from the input file, if possible
/// </summary>