From 7a510e084bdfca7af5a7be00c98d86f799ddd522 Mon Sep 17 00:00:00 2001
From: Deterous <138427222+Deterous@users.noreply.github.com>
Date: Sat, 4 Nov 2023 16:35:24 +1300
Subject: [PATCH] Pull PS3 Firmware Version (#599)
* Attempt to read PS3 firmware version
* Improve PS3 Firmware Version parsing
* Enable PS3 Firmware Version detection for all 3 Programs
* Big endian byte location
* Contents field not Comments field
---
MPF.Core/InfoTool.cs | 64 +++++++++++++++++++
MPF.Core/Modules/Aaru/Parameters.cs | 6 ++
.../Modules/DiscImageCreator/Parameters.cs | 6 ++
MPF.Core/Modules/Redumper/Parameters.cs | 6 ++
4 files changed, 82 insertions(+)
diff --git a/MPF.Core/InfoTool.cs b/MPF.Core/InfoTool.cs
index f4a6d55a..fe11a01f 100644
--- a/MPF.Core/InfoTool.cs
+++ b/MPF.Core/InfoTool.cs
@@ -760,6 +760,70 @@ namespace MPF.Core
return null;
}
+ ///
+ /// Get the firmware version from a PlayStation 3 disc, if possible
+ ///
+ /// Drive letter to use to check
+ /// Firmware version if possible, null on error
+#if NET48
+ internal static string GetPlayStation3FirmwareVersion(char? driveLetter)
+#else
+ internal static string? GetPlayStation3FirmwareVersion(char? driveLetter)
+#endif
+ {
+ // If there's no drive letter, we can't do this part
+ if (driveLetter == null)
+ return null;
+
+ // If the folder no longer exists, we can't do this part
+ string drivePath = driveLetter + ":\\";
+ return GetPlayStation3FirmwareVersion(drivePath);
+ }
+
+ ///
+ /// Get the firmware version from a PlayStation 3 disc, if possible
+ ///
+ /// Drive path to use to check
+ /// Firmware version if possible, null on error
+#if NET48
+ internal static string GetPlayStation3FirmwareVersion(string drivePath)
+#else
+ internal static string? GetPlayStation3FirmwareVersion(string? drivePath)
+#endif
+ {
+ // If there's no drive path, we can't do this part
+ if (string.IsNullOrWhiteSpace(drivePath))
+ return null;
+
+ // If the folder no longer exists, we can't do this part
+ if (!Directory.Exists(drivePath))
+ return null;
+
+ // Attempt to read from /PS3_UPDATE/PS3UPDAT.PUP
+ string pupPath = Path.Combine(drivePath, "PS3_UPDATE", "PS3UPDAT.PUP");
+ if (!File.Exists(pupPath))
+ return null;
+
+ try
+ {
+ using (var br = new BinaryReader(File.OpenRead(pupPath)))
+ {
+ br.BaseStream.Seek(0x3E, SeekOrigin.Begin);
+ byte[] buf = new byte[2];
+ br.Read(buf, 0, 2);
+ Array.Reverse(buf);
+ short location = BitConverter.ToInt16(buf, 0);
+ br.BaseStream.Seek(location, SeekOrigin.Begin);
+ return new string(br.ReadChars(4));
+ }
+ }
+ catch
+ {
+ // We don't care what the error was
+ return null;
+ }
+ }
+
///
/// Get the internal serial from a PlayStation 4 disc, if possible
///
diff --git a/MPF.Core/Modules/Aaru/Parameters.cs b/MPF.Core/Modules/Aaru/Parameters.cs
index b5457c3c..9dca4db8 100644
--- a/MPF.Core/Modules/Aaru/Parameters.cs
+++ b/MPF.Core/Modules/Aaru/Parameters.cs
@@ -605,9 +605,15 @@ namespace MPF.Core.Modules.Aaru
#if NET48
info.VersionAndEditions.Version = InfoTool.GetPlayStation3Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = InfoTool.GetPlayStation3Serial(drive?.Name) ?? string.Empty;
+ string firmwareVersion = InfoTool.GetPlayStation3FirmwareVersion(drive?.Name);
+ if (firmwareVersion != null)
+ info.CommonDiscInfo.ContentsSpecialFields[SiteCode.Patches] = $"PS3 Firmware {firmwareVersion}";
#else
info.VersionAndEditions!.Version = InfoTool.GetPlayStation3Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = InfoTool.GetPlayStation3Serial(drive?.Name) ?? string.Empty;
+ string? firmwareVersion = InfoTool.GetPlayStation3FirmwareVersion(drive?.Name);
+ if (firmwareVersion != null)
+ info.CommonDiscInfo!.ContentsSpecialFields![SiteCode.Patches] = $"PS3 Firmware {firmwareVersion}";
#endif
break;
diff --git a/MPF.Core/Modules/DiscImageCreator/Parameters.cs b/MPF.Core/Modules/DiscImageCreator/Parameters.cs
index 7604d1d2..617e659e 100644
--- a/MPF.Core/Modules/DiscImageCreator/Parameters.cs
+++ b/MPF.Core/Modules/DiscImageCreator/Parameters.cs
@@ -1032,9 +1032,15 @@ namespace MPF.Core.Modules.DiscImageCreator
#if NET48
info.VersionAndEditions.Version = InfoTool.GetPlayStation3Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = InfoTool.GetPlayStation3Serial(drive?.Name) ?? string.Empty;
+ string firmwareVersion = InfoTool.GetPlayStation3FirmwareVersion(drive?.Name);
+ if (firmwareVersion != null)
+ info.CommonDiscInfo.ContentsSpecialFields[SiteCode.Patches] = $"PS3 Firmware {firmwareVersion}";
#else
info.VersionAndEditions!.Version = InfoTool.GetPlayStation3Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = InfoTool.GetPlayStation3Serial(drive?.Name) ?? string.Empty;
+ string? firmwareVersion = InfoTool.GetPlayStation3FirmwareVersion(drive?.Name);
+ if (firmwareVersion != null)
+ info.CommonDiscInfo!.ContentsSpecialFields![SiteCode.Patches] = $"PS3 Firmware {firmwareVersion}";
#endif
break;
diff --git a/MPF.Core/Modules/Redumper/Parameters.cs b/MPF.Core/Modules/Redumper/Parameters.cs
index 2bac8806..14598458 100644
--- a/MPF.Core/Modules/Redumper/Parameters.cs
+++ b/MPF.Core/Modules/Redumper/Parameters.cs
@@ -605,9 +605,15 @@ namespace MPF.Core.Modules.Redumper
#if NET48
info.VersionAndEditions.Version = InfoTool.GetPlayStation3Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.InternalSerialName] = InfoTool.GetPlayStation3Serial(drive?.Name) ?? string.Empty;
+ string firmwareVersion = InfoTool.GetPlayStation3FirmwareVersion(drive?.Name);
+ if (firmwareVersion != null)
+ info.CommonDiscInfo.ContentsSpecialFields[SiteCode.Patches] = $"PS3 Firmware {firmwareVersion}";
#else
info.VersionAndEditions!.Version = InfoTool.GetPlayStation3Version(drive?.Name) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = InfoTool.GetPlayStation3Serial(drive?.Name) ?? string.Empty;
+ string? firmwareVersion = InfoTool.GetPlayStation3FirmwareVersion(drive?.Name);
+ if (firmwareVersion != null)
+ info.CommonDiscInfo!.ContentsSpecialFields![SiteCode.Patches] = $"PS3 Firmware {firmwareVersion}";
#endif
break;