From 9bb9d3f407b8d651bac86b4e8675e37ea8ec94c7 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 6 Aug 2020 22:05:16 -0700 Subject: [PATCH] Add progress to protection scan --- DICUI.Library/Utilities/DumpEnvironment.cs | 71 +++++++++++++--------- DICUI.Library/Utilities/Validators.cs | 7 ++- DICUI/Windows/MainWindow.xaml.cs | 26 ++++++-- 3 files changed, 68 insertions(+), 36 deletions(-) diff --git a/DICUI.Library/Utilities/DumpEnvironment.cs b/DICUI.Library/Utilities/DumpEnvironment.cs index 9d2fbec0..5987ae58 100644 --- a/DICUI.Library/Utilities/DumpEnvironment.cs +++ b/DICUI.Library/Utilities/DumpEnvironment.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; +using BurnOutSharp; using DICUI.Data; using DICUI.Web; using Newtonsoft.Json; @@ -478,52 +479,62 @@ namespace DICUI.Utilities /// /// Verify that the current environment has a complete dump and create submission info is possible /// + /// Optional result progress callback + /// Optional protection progress callback + /// True if disc should be ejected after information is gathered, false otherwise + /// True if drive should be reset after information is gathered, false otherwise + /// Optional user prompt to deal with submsision information /// Result instance with the outcome - public async Task VerifyAndSaveDumpOutput(IProgress progress, bool? ejectDisc = null, bool resetDrive = false, Func ShowUserPrompt = null) + public async Task VerifyAndSaveDumpOutput( + IProgress resultProgress = null, + IProgress protectionProgress = null, + bool? ejectDisc = null, + bool resetDrive = false, + Func showUserPrompt = null) { - progress?.Report(Result.Success("Gathering submission information... please wait!")); + resultProgress?.Report(Result.Success("Gathering submission information... please wait!")); // Check to make sure that the output had all the correct files if (!FoundAllFiles()) return Result.Failure("Error! Please check output directory as dump may be incomplete!"); - progress?.Report(Result.Success("Extracting output information from output files...")); - SubmissionInfo submissionInfo = await ExtractOutputInformation(progress); - progress?.Report(Result.Success("Extracting information complete!")); + resultProgress?.Report(Result.Success("Extracting output information from output files...")); + SubmissionInfo submissionInfo = await ExtractOutputInformation(resultProgress, protectionProgress); + resultProgress?.Report(Result.Success("Extracting information complete!")); if (ejectDisc == true) { - progress?.Report(Result.Success($"Ejecting disc in drive {Drive.Letter}")); + resultProgress?.Report(Result.Success($"Ejecting disc in drive {Drive.Letter}")); EjectDisc(); } if (resetDrive) { - progress?.Report(Result.Success($"Resetting drive {Drive.Letter}")); + resultProgress?.Report(Result.Success($"Resetting drive {Drive.Letter}")); ResetDrive(); } - if (PromptForDiscInformation && ShowUserPrompt != null) + if (PromptForDiscInformation && showUserPrompt != null) { - progress?.Report(Result.Success("Waiting for additional disc information...")); - bool? filledInfo = ShowUserPrompt(submissionInfo); - progress?.Report(Result.Success("Additional disc information added!")); + resultProgress?.Report(Result.Success("Waiting for additional disc information...")); + bool? filledInfo = showUserPrompt(submissionInfo); + resultProgress?.Report(Result.Success("Additional disc information added!")); } - progress?.Report(Result.Success("Formatting extracted information...")); + resultProgress?.Report(Result.Success("Formatting extracted information...")); List formattedValues = FormatOutputData(submissionInfo); - progress?.Report(Result.Success("Formatting complete!")); + resultProgress?.Report(Result.Success("Formatting complete!")); - progress?.Report(Result.Success("Writing information to !submissionInfo.txt...")); + resultProgress?.Report(Result.Success("Writing information to !submissionInfo.txt...")); bool success = WriteOutputData(formattedValues); success &= WriteOutputData(submissionInfo); if (success) - progress?.Report(Result.Success("Writing complete!")); + resultProgress?.Report(Result.Success("Writing complete!")); else - progress?.Report(Result.Failure("Writing could not complete!")); + resultProgress?.Report(Result.Failure("Writing could not complete!")); - progress?.Report(Result.Success("All submission information gathered!")); + resultProgress?.Report(Result.Success("All submission information gathered!")); return Result.Success(); } @@ -632,9 +643,12 @@ namespace DICUI.Utilities /// /// Extract all of the possible information from a given input combination /// - /// Drive letter to check + /// Optional result progress callback + /// Optional protection progress callback /// SubmissionInfo populated based on outputs, null on error - private async Task ExtractOutputInformation(IProgress progress) + private async Task ExtractOutputInformation( + IProgress resultProgress = null, + IProgress protectionProgress = null) { // Ensure the current disc combination should exist if (!Validators.GetValidMediaTypes(System).Contains(Type)) @@ -694,7 +708,7 @@ namespace DICUI.Utilities if (wc.Login(this.Username, this.Password)) { // Loop through all of the hashdata to find matching IDs - progress?.Report(Result.Success("Finding disc matches on Redump...")); + resultProgress?.Report(Result.Success("Finding disc matches on Redump...")); string[] splitData = info.TracksAndWriteOffsets.ClrMameProData.Split('\n'); foreach (string hashData in splitData) { @@ -708,14 +722,14 @@ namespace DICUI.Utilities } } - progress?.Report(Result.Success("Match finding complete! " + (info.MatchedIDs.Count > 0 ? "Matched IDs: " + string.Join(",", info.MatchedIDs) : "No matches found"))); + resultProgress?.Report(Result.Success("Match finding complete! " + (info.MatchedIDs.Count > 0 ? "Matched IDs: " + string.Join(",", info.MatchedIDs) : "No matches found"))); // If we have exactly 1 ID, we can grab a bunch of info from it if (info.MatchedIDs.Count == 1) { - progress?.Report(Result.Success($"Filling fields from existing ID {info.MatchedIDs[0]}...")); + resultProgress?.Report(Result.Success($"Filling fields from existing ID {info.MatchedIDs[0]}...")); wc.FillFromId(info, info.MatchedIDs[0]); - progress?.Report(Result.Success("Information filling complete!")); + resultProgress?.Report(Result.Success("Information filling complete!")); } } } @@ -827,9 +841,9 @@ namespace DICUI.Utilities if (string.IsNullOrWhiteSpace(info.CommonDiscInfo.Comments)) info.CommonDiscInfo.Comments += $"[T:ISBN] {(AddPlaceholders ? Template.OptionalValue : "")}"; - progress?.Report(Result.Success("Running copy protection scan... this might take a while!")); - info.CopyProtection.Protection = await GetCopyProtection(); - progress?.Report(Result.Success("Copy protection scan complete!")); + resultProgress?.Report(Result.Success("Running copy protection scan... this might take a while!")); + info.CopyProtection.Protection = await GetCopyProtection(protectionProgress); + resultProgress?.Report(Result.Success("Copy protection scan complete!")); break; @@ -1296,11 +1310,12 @@ namespace DICUI.Utilities /// /// Get the current copy protection scheme, if possible /// + /// Optional progress callback /// Copy protection scheme if possible, null on error - private async Task GetCopyProtection() + private async Task GetCopyProtection(IProgress progress = null) { if (ScanForProtection) - return await Validators.RunProtectionScanOnPath($"{Drive.Letter}:\\"); + return await Validators.RunProtectionScanOnPath($"{Drive.Letter}:\\", progress); return "(CHECK WITH PROTECTIONID)"; } diff --git a/DICUI.Library/Utilities/Validators.cs b/DICUI.Library/Utilities/Validators.cs index d8a14d8f..8b2797f8 100644 --- a/DICUI.Library/Utilities/Validators.cs +++ b/DICUI.Library/Utilities/Validators.cs @@ -1027,16 +1027,17 @@ namespace DICUI.Utilities /// /// Run protection scan on a given dump environment /// - /// DumpEnvirionment containing all required information + /// Path to scan for protection + /// Optional progress callback /// Copy protection detected in the envirionment, if any - public static async Task RunProtectionScanOnPath(string path) + public static async Task RunProtectionScanOnPath(string path, IProgress progress = null) { #if NET_FRAMEWORK try { var found = await Task.Run(() => { - return ProtectionFind.Scan(path); + return ProtectionFind.Scan(path, progress); }); if (found == null || found.Count == 0) diff --git a/DICUI/Windows/MainWindow.xaml.cs b/DICUI/Windows/MainWindow.xaml.cs index 6df41151..01e3097f 100644 --- a/DICUI/Windows/MainWindow.xaml.cs +++ b/DICUI/Windows/MainWindow.xaml.cs @@ -7,6 +7,7 @@ using System.Reflection; using System.Windows; using System.Windows.Controls; using WinForms = System.Windows.Forms; +using BurnOutSharp; using DICUI.Data; using DICUI.Utilities; using DICUI.Web; @@ -189,6 +190,13 @@ namespace DICUI.Windows ViewModels.LoggerViewModel.VerboseLogLn(value.Message); } + private void ProgressUpdated(object sender, FileProtection value) + { + string message = $"{value.Percentage}% - {value.Filename}: {value.Protection}"; + StatusLabel.Content = message; + ViewModels.LoggerViewModel.VerboseLogLn(message); + } + private void MainWindowLocationChanged(object sender, EventArgs e) { if (_logWindow.IsVisible) @@ -516,9 +524,14 @@ namespace DICUI.Windows StatusLabel.Content = "Beginning dumping process"; ViewModels.LoggerViewModel.VerboseLogLn("Starting dumping process.."); - var progress = new Progress(); - progress.ProgressChanged += ProgressUpdated; - Result result = await _env.Run(progress); + // Get progress indicators + var resultProgress = new Progress(); + resultProgress.ProgressChanged += ProgressUpdated; + var protectionProgress = new Progress(); + protectionProgress.ProgressChanged += ProgressUpdated; + + // Run the program with the parameters + Result result = await _env.Run(resultProgress); // If we didn't execute a dumping command we cannot get submission output if (!_env.Parameters.IsDumpingCommand()) @@ -533,7 +546,8 @@ namespace DICUI.Windows if (result) { // Verify dump output and save it - result = await _env.VerifyAndSaveDumpOutput(progress, + result = await _env.VerifyAndSaveDumpOutput(resultProgress, + protectionProgress, EjectWhenDoneCheckBox.IsChecked, _uiOptions.ResetDriveAfterDump, (si) => @@ -646,7 +660,9 @@ namespace DICUI.Windows DiskScanButton.IsEnabled = false; CopyProtectScanButton.IsEnabled = false; - string protections = await Validators.RunProtectionScanOnPath(_env.Drive.Letter + ":\\"); + var progress = new Progress(); + progress.ProgressChanged += ProgressUpdated; + string protections = await Validators.RunProtectionScanOnPath(_env.Drive.Letter + ":\\", progress); // If SmartE is detected on the current disc, remove `/sf` from the flags for DIC only if (_env.InternalProgram == InternalProgram.DiscImageCreator && protections.Contains("SmartE"))