From d812ea7e2b35d40f86170860968f3333e7642734 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 31 May 2024 10:41:56 -0400 Subject: [PATCH] Add PS3 info extraction for DIC --- CHANGELIST.md | 1 + MPF.Processors/DiscImageCreator.cs | 110 +++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) diff --git a/CHANGELIST.md b/CHANGELIST.md index 8fbbb34d..c2f44cf5 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -167,6 +167,7 @@ - Fix setting PS1-5 version on invalid - Fix setting Python 2 version on invalid - Clean up some ProcessSystem cases +- Add PS3 info extraction for DIC ### 3.1.9a (2024-05-21) diff --git a/MPF.Processors/DiscImageCreator.cs b/MPF.Processors/DiscImageCreator.cs index 1652d61e..2f13f5b0 100644 --- a/MPF.Processors/DiscImageCreator.cs +++ b/MPF.Processors/DiscImageCreator.cs @@ -693,6 +693,17 @@ namespace MPF.Processors info.CopyProtection.LibCrypt = libCryptDetected; info.CopyProtection.LibCryptData = libCryptData; break; + + case RedumpSystem.SonyPlayStation3: + if (GetPlayStation3Info($"{basePath}_disc.txt", out string? ps3Serial, out string? ps3Version, out string? ps3FirmwareVersion)) + { + info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = ps3Serial ?? string.Empty; + info.VersionAndEditions!.Version = ps3Version ?? string.Empty; + if (ps3FirmwareVersion != null) + info.CommonDiscInfo!.ContentsSpecialFields![SiteCode.Patches] = $"PS3 Firmware {ps3FirmwareVersion}"; + } + + break; } } @@ -1580,6 +1591,105 @@ namespace MPF.Processors } } + /// + /// Get the info from a PlayStation 3 disc, if possible + /// + /// _disc.txt file location + /// True if section found, null on error + private static bool GetPlayStation3Info(string disc, out string? serial, out string? version, out string? firmwareVersion) + { + // Set the default values + serial = null; version = null; firmwareVersion = null; + + // If the file doesn't exist, we can't get info from it + if (!File.Exists(disc)) + return false; + + try + { + using var sr = File.OpenText(disc); + var line = sr.ReadLine()?.Trim(); + if (line == null) + return false; + + string section = string.Empty; + while (!sr.EndOfStream) + { + if (line == null) + return false; + + // Determine the section we are in + if (line.EndsWith("PS3_DISC.SFB ==========")) + { + section = "SFB"; + } + else if (line.EndsWith("PARAM.SFO ==========")) + { + section = "SFO"; + } + else if (line.EndsWith("PS3UPDAT.PUP ==========")) + { + section = "UPDATE"; + } + + // If we're in a section already + else if (!string.IsNullOrEmpty(section)) + { + // Firmware Version + if (line.StartsWith("version") && section == "UPDATE") + { + firmwareVersion = line.Substring("version: ".Length); + } + + // Internal Serial + else if (line.StartsWith("TITLE_ID")) + { + // Always use the SFB if it exists + if (section == "SFB") + serial = line.Substring("TITLE_ID: ".Length); + else if (section == "SFO" && string.IsNullOrEmpty(version)) + serial = line.Substring("TITLE_ID: ".Length).Insert(4, "-"); + } + + // Version + else if (line.StartsWith("VERSION")) + { + // Always use the SFB if it exists + if (section == "SFB") + version = line.Substring("VERSION: ".Length); + else if (section == "SFO" && string.IsNullOrEmpty(version)) + version = line.Substring("VERSION: ".Length); + } + + // Set the section, if needed + if (line.EndsWith("PS3_DISC.SFB ==========")) + section = "SFB"; + else if (line.EndsWith("PARAM.SFO ==========")) + section = "SFO"; + else if (line.EndsWith("PS3UPDAT.PUP ==========")) + section = "UPDATE"; + else if (line.StartsWith("==========")) + section = string.Empty; + } + + // Everything else resets the section + else + { + section = string.Empty; + } + + line = sr.ReadLine()?.Trim(); + } + + return true; + } + catch + { + // We don't care what the exception is right now + return false; + } + } + /// /// Get the detected missing EDC count from the input files, if possible ///