From f28cfe3d69c805d8fd776670ed28c93ecf8be3a6 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 29 Sep 2021 12:17:34 -0700 Subject: [PATCH] Segment out protection checks a bit more --- MPF.Library/Aaru/Parameters.cs | 1 - MPF.Library/DD/Parameters.cs | 1 - MPF.Library/Data/BaseParameters.cs | 38 ----------------------------- MPF.Library/Data/DumpEnvironment.cs | 19 ++++++++++++++- MPF.Library/Utilities/Protection.cs | 31 +++++++++++++++++++++++ MPF/ViewModels/MainViewModel.cs | 2 +- 6 files changed, 50 insertions(+), 42 deletions(-) diff --git a/MPF.Library/Aaru/Parameters.cs b/MPF.Library/Aaru/Parameters.cs index ab90181a..82a98360 100644 --- a/MPF.Library/Aaru/Parameters.cs +++ b/MPF.Library/Aaru/Parameters.cs @@ -328,7 +328,6 @@ namespace MPF.Aaru info.CommonDiscInfo.EXEDateBuildDate = playstationDate; } - info.CopyProtection.AntiModchip = GetPlayStationAntiModchipDetected(drive?.Letter) ? YesNo.Yes : YesNo.No; break; case RedumpSystem.SonyPlayStation2: diff --git a/MPF.Library/DD/Parameters.cs b/MPF.Library/DD/Parameters.cs index 8e387eee..a4a0e03e 100644 --- a/MPF.Library/DD/Parameters.cs +++ b/MPF.Library/DD/Parameters.cs @@ -107,7 +107,6 @@ namespace MPF.DD info.CommonDiscInfo.EXEDateBuildDate = playstationDate; } - info.CopyProtection.AntiModchip = GetPlayStationAntiModchipDetected(drive?.Letter) ? YesNo.Yes : YesNo.No; break; case RedumpSystem.SonyPlayStation2: diff --git a/MPF.Library/Data/BaseParameters.cs b/MPF.Library/Data/BaseParameters.cs index f281653f..7c291bd9 100644 --- a/MPF.Library/Data/BaseParameters.cs +++ b/MPF.Library/Data/BaseParameters.cs @@ -6,8 +6,6 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; -using BurnOutSharp.ProtectionType; -using MPF.Core; using MPF.Core.Data; using MPF.Core.Hashing; using MPF.Core.Utilities; @@ -1160,42 +1158,6 @@ namespace MPF.Data } } - /// - /// Get the existance of an anti-modchip string from a PlayStation disc, if possible - /// - /// Drive letter to use to check - /// Anti-modchip existance if possible, false on error - protected static bool GetPlayStationAntiModchipDetected(char? driveLetter) - { - // If there's no drive letter, we can't do this part - if (driveLetter == null) - return false; - - // If the folder no longer exists, we can't do this part - string drivePath = driveLetter + ":\\"; - if (!Directory.Exists(drivePath)) - return false; - - // Scan through each file to check for the anti-modchip strings - var antiModchip = new PSXAntiModchip(); - foreach (string path in Directory.EnumerateFiles(drivePath, "*", SearchOption.AllDirectories)) - { - try - { - byte[] fileContent = File.ReadAllBytes(path); - string protection = antiModchip.CheckContents(path, fileContent, false, null, null); - if (!string.IsNullOrWhiteSpace(protection)) - return true; - } - catch - { - // No-op, we don't care what the error was - } - } - - return false; - } - /// /// Get the EXE date from a PlayStation disc, if possible /// diff --git a/MPF.Library/Data/DumpEnvironment.cs b/MPF.Library/Data/DumpEnvironment.cs index 3451a26d..706c9075 100644 --- a/MPF.Library/Data/DumpEnvironment.cs +++ b/MPF.Library/Data/DumpEnvironment.cs @@ -12,6 +12,7 @@ using BurnOutSharp; using MPF.Core.Converters; using MPF.Core.Data; using MPF.Core.Utilities; +using MPF.Utilities; using Newtonsoft.Json; using RedumpLib.Data; using RedumpLib.Web; @@ -936,6 +937,12 @@ namespace MPF.Data info.CommonDiscInfo.EXEDateBuildDate = (Options.AddPlaceholders ? Template.RequiredValue : ""); break; + case RedumpSystem.SonyPlayStation: + resultProgress?.Report(Result.Success("Checking for anti-modchip strings... this might take a while!")); + info.CopyProtection.AntiModchip = await GetPlayStationAntiModchipDetected(protectionProgress) ? YesNo.Yes : YesNo.No; + resultProgress?.Report(Result.Success("Anti-modchip string scan complete!")); + break; + case RedumpSystem.SonyPlayStation2: info.CommonDiscInfo.LanguageSelection = new LanguageSelection?[] { LanguageSelection.BiosSettings, LanguageSelection.LanguageSelector, LanguageSelection.OptionsMenu }; break; @@ -1374,7 +1381,7 @@ namespace MPF.Data { if (Options.ScanForProtection) { - (bool success, string output) = await Validators.RunProtectionScanOnPath($"{Drive.Letter}:\\", this.Options, progress); + (bool success, string output) = await Protection.RunProtectionScanOnPath($"{Drive.Letter}:\\", this.Options, progress); if (success) return output; else @@ -1384,6 +1391,16 @@ namespace MPF.Data return "(CHECK WITH PROTECTIONID)"; } + /// + /// Get the existance of an anti-modchip string from a PlayStation disc, if possible + /// + /// Path to scan for anti-modchip strings + /// Anti-modchip existance if possible, false on error + private async Task GetPlayStationAntiModchipDetected(IProgress progress = null) + { + return await Protection.GetPlayStationAntiModchipDetected($"{Drive.Letter}:\\", progress); + } + /// /// Get the split values for ISO-based media /// diff --git a/MPF.Library/Utilities/Protection.cs b/MPF.Library/Utilities/Protection.cs index 4dffea6e..1d2a8e7c 100644 --- a/MPF.Library/Utilities/Protection.cs +++ b/MPF.Library/Utilities/Protection.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using BurnOutSharp; +using BurnOutSharp.ProtectionType; using MPF.Core.Data; namespace MPF.Utilities @@ -53,6 +55,35 @@ namespace MPF.Utilities } } + /// + /// Get the existance of an anti-modchip string from a PlayStation disc, if possible + /// + /// Path to scan for anti-modchip strings + /// Anti-modchip existance if possible, false on error + public static async Task GetPlayStationAntiModchipDetected(string path, IProgress progress = null) + { + return await Task.Run(() => + { + var antiModchip = new PSXAntiModchip(); + foreach (string file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)) + { + try + { + byte[] fileContent = File.ReadAllBytes(file); + string protection = antiModchip.CheckContents(file, fileContent, false, null, null); + if (!string.IsNullOrWhiteSpace(protection)) + return true; + } + catch + { + // No-op, we don't care what the error was + } + } + + return false; + }); + } + /// /// Sanitize unnecessary protection duplication from output /// diff --git a/MPF/ViewModels/MainViewModel.cs b/MPF/ViewModels/MainViewModel.cs index 42fe9c70..58a2f301 100644 --- a/MPF/ViewModels/MainViewModel.cs +++ b/MPF/ViewModels/MainViewModel.cs @@ -914,7 +914,7 @@ namespace MPF.GUI.ViewModels var progress = new Progress(); progress.ProgressChanged += ProgressUpdated; - (bool success, string output) = await Validators.RunProtectionScanOnPath(drive.Letter + ":\\", App.Options, progress); + (bool success, string output) = await Protection.RunProtectionScanOnPath(drive.Letter + ":\\", App.Options, progress); // If SmartE is detected on the current disc, remove `/sf` from the flags for DIC only if (Env.Options.InternalProgram == InternalProgram.DiscImageCreator && output.Contains("SmartE"))