From 6ceffce63d7733be7da6a70cd13c1311070478c2 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 12 Jun 2023 13:42:13 -0400 Subject: [PATCH] Fix previous commit, clean up helpers --- CHANGELIST.md | 1 + MPF.Modules/DiscImageCreator/Parameters.cs | 16 ++++-------- MPF.Modules/Redumper/Parameters.cs | 29 +++------------------- RedumpLib/Data/Extensions.cs | 18 ++++++++++++++ 4 files changed, 28 insertions(+), 36 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 3bd84fde..316fac4c 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -67,6 +67,7 @@ - Fix VSCode build - Fix Redumper DAT/layer parsing - Update Redumper PS1 output parsing +- Fix previous commit, clean up helpers ### 2.5 (2023-03-12) diff --git a/MPF.Modules/DiscImageCreator/Parameters.cs b/MPF.Modules/DiscImageCreator/Parameters.cs index e9dd9834..d2f1d66a 100644 --- a/MPF.Modules/DiscImageCreator/Parameters.cs +++ b/MPF.Modules/DiscImageCreator/Parameters.cs @@ -779,14 +779,8 @@ namespace MPF.Modules.DiscImageCreator else if (File.Exists($"{basePath}.img_EccEdc.txt")) psEdcStatus = GetPlayStationEDCStatus($"{basePath}.img_EccEdc.txt"); - if (psEdcStatus == true) - info.EDC.EDC = YesNo.Yes; - else if (psEdcStatus == false) - info.EDC.EDC = YesNo.No; - else - info.EDC.EDC = YesNo.NULL; - - info.CopyProtection.AntiModchip = GetPlayStationAntiModchipDetected($"{basePath}_disc.txt") ? YesNo.Yes : YesNo.No; + info.EDC.EDC = psEdcStatus.ToYesNo(); + info.CopyProtection.AntiModchip = GetPlayStationAntiModchipDetected($"{basePath}_disc.txt").ToYesNo(); break; case RedumpSystem.SonyPlayStation2: @@ -3149,11 +3143,11 @@ namespace MPF.Modules.DiscImageCreator /// /// _disc.txt file location /// Anti-modchip existence if possible, false on error - private static bool GetPlayStationAntiModchipDetected(string disc) + private static bool? GetPlayStationAntiModchipDetected(string disc) { // If the file doesn't exist, we can't get info from it if (!File.Exists(disc)) - return false; + return null; using (StreamReader sr = File.OpenText(disc)) { @@ -3176,7 +3170,7 @@ namespace MPF.Modules.DiscImageCreator catch { // We don't care what the exception is right now - return false; + return null; } } } diff --git a/MPF.Modules/Redumper/Parameters.cs b/MPF.Modules/Redumper/Parameters.cs index 75f7b73b..9307c279 100644 --- a/MPF.Modules/Redumper/Parameters.cs +++ b/MPF.Modules/Redumper/Parameters.cs @@ -383,30 +383,9 @@ namespace MPF.Modules.Redumper info.CommonDiscInfo.EXEDateBuildDate = playstationDate; } - bool? psAntiModchipStatus = GetPlayStationAntiModchipDetected($"{basePath}.log"); - if (psAntiModchipStatus == true) - info.CopyProtection.AntiModchip = YesNo.Yes; - else if (psAntiModchipStatus == false) - info.CopyProtection.AntiModchip = YesNo.No; - else - info.CopyProtection.AntiModchip = YesNo.NULL; - - bool? psEdcStatus = GetPlayStationEDCStatus($"{basePath}.log"); - if (psEdcStatus == true) - info.EDC.EDC = YesNo.Yes; - else if (psEdcStatus == false) - info.EDC.EDC = YesNo.No; - else - info.EDC.EDC = YesNo.NULL; - - bool? psLibCryptStatus = GetPlayStationLibCryptStatus($"{basePath}.log"); - if (psLibCryptStatus == true) - info.CopyProtection.LibCrypt = YesNo.Yes; - else if (psLibCryptStatus == false) - info.CopyProtection.LibCrypt = YesNo.No; - else - info.CopyProtection.LibCrypt = YesNo.NULL; - + info.CopyProtection.AntiModchip = GetPlayStationAntiModchipDetected($"{basePath}.log").ToYesNo(); + info.EDC.EDC = GetPlayStationEDCStatus($"{basePath}.log").ToYesNo(); + info.CopyProtection.LibCrypt = GetPlayStationLibCryptStatus($"{basePath}.log").ToYesNo(); break; case RedumpSystem.SonyPlayStation2: @@ -1420,7 +1399,7 @@ namespace MPF.Modules.Redumper if (line.StartsWith("libcrypt: no")) return false; - else if (line.StartsWith("libcrypt: yes)) + else if (line.StartsWith("libcrypt: yes")) return true; line = sr.ReadLine().Trim(); diff --git a/RedumpLib/Data/Extensions.cs b/RedumpLib/Data/Extensions.cs index 3606373e..6c86f957 100644 --- a/RedumpLib/Data/Extensions.cs +++ b/RedumpLib/Data/Extensions.cs @@ -2135,6 +2135,24 @@ namespace RedumpLib.Data /// public static string LongName(this YesNo? yesno) => AttributeHelper.GetAttribute(yesno)?.LongName ?? "Yes/No"; + /// + /// Get the YesNo enum value for a given nullable boolean + /// + /// Nullable boolean value to convert + /// YesNo represented by the nullable boolean, if possible + public static YesNo? ToYesNo(this bool? yesno) + { + switch (yesno) + { + case false: + return YesNo.No; + case true: + return YesNo.Yes; + default: + return YesNo.NULL; + } + } + /// /// Get the YesNo enum value for a given string ///