diff --git a/CHANGELIST.md b/CHANGELIST.md index 7b03b996..0e380ab7 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -33,6 +33,7 @@ - Add user-selectable Language Selection via dropdown in disc submission window for PS2 - Separate out Aaru- and DIC-specific settings - Add new options based on original "Paranoid Mode" mega-option +- Internal overhaul of options and dump environment ### 1.18 (2020-11-10) - Add more information extraction and generation for Aaru diff --git a/MPF.Check/Program.cs b/MPF.Check/Program.cs index d8980ae3..7362db44 100644 --- a/MPF.Check/Program.cs +++ b/MPF.Check/Program.cs @@ -158,7 +158,7 @@ namespace MPF.Check // TODO: Replace this with Dictionary constructor var options = new Options { - InternalProgram = internalProgram, + InternalProgram = Converters.ToInternalProgram(internalProgram), ScanForProtection = scan && !string.IsNullOrWhiteSpace(path), PromptForDiscInformation = false, diff --git a/MPF.Library/Data/Options.cs b/MPF.Library/Data/Options.cs index fe5494c9..4ee1ee2a 100644 --- a/MPF.Library/Data/Options.cs +++ b/MPF.Library/Data/Options.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using MPF.Utilities; namespace MPF.Data { @@ -40,10 +41,18 @@ namespace MPF.Data /// /// Currently selected dumping program /// - public string InternalProgram + public InternalProgram InternalProgram { - get { return GetStringSetting(_settings, "InternalProgram", Data.InternalProgram.DiscImageCreator.ToString()); } - set { _settings["InternalProgram"] = value; } + get + { + string valueString = GetStringSetting(_settings, "InternalProgram", InternalProgram.DiscImageCreator.ToString()); + var valueEnum = Converters.ToInternalProgram(valueString); + return valueEnum == InternalProgram.NONE ? InternalProgram.DiscImageCreator : valueEnum; + } + set + { + _settings["InternalProgram"] = value.ToString(); + } } #endregion diff --git a/MPF.Library/Utilities/DumpEnvironment.cs b/MPF.Library/Utilities/DumpEnvironment.cs index b9c27998..219bac49 100644 --- a/MPF.Library/Utilities/DumpEnvironment.cs +++ b/MPF.Library/Utilities/DumpEnvironment.cs @@ -50,11 +50,6 @@ namespace MPF.Utilities /// public MediaType? Type { get; set; } - /// - /// Internal program to run - /// - public InternalProgram InternalProgram { get; set; } - /// /// Options object representing user-defined options /// @@ -97,13 +92,9 @@ namespace MPF.Utilities this.System = system; this.Type = type; - this.InternalProgram = Converters.ToInternalProgram(options.InternalProgram); - SetParameters(parameters); this.Parameters.System = system; this.Parameters.Type = type; - - SetInternalToolPath(); } #region Public Functionality @@ -114,77 +105,43 @@ namespace MPF.Utilities /// String representation of the parameters public void SetParameters(string parameters) { - switch (this.InternalProgram) + switch (Options.InternalProgram) { // Dumping support case InternalProgram.Aaru: this.Parameters = new Aaru.Parameters(parameters); - break; - - case InternalProgram.DD: - this.Parameters = new DD.Parameters(parameters); - break; - - case InternalProgram.DiscImageCreator: - this.Parameters = new DiscImageCreator.Parameters(parameters); - break; - - // Verification support only - case InternalProgram.CleanRip: - this.Parameters = new CleanRip.Parameters(parameters); - break; - - case InternalProgram.DCDumper: - this.Parameters = null; // TODO: Create correct parameter type when supported - break; - - case InternalProgram.UmdImageCreator: - this.Parameters = new UmdImageCreator.Parameters(parameters); - break; - - // This should never happen, but it needs a fallback - default: - this.Parameters = new DiscImageCreator.Parameters(parameters); - break; - } - } - - /// - /// Set the path on the parameters object based on the intermal program - /// - public void SetInternalToolPath() - { - switch (this.InternalProgram) - { - // Dumping support - case InternalProgram.Aaru: this.Parameters.ExecutablePath = Options.AaruPath; break; case InternalProgram.DD: + this.Parameters = new DD.Parameters(parameters); this.Parameters.ExecutablePath = Options.DDPath; break; case InternalProgram.DiscImageCreator: + this.Parameters = new DiscImageCreator.Parameters(parameters); this.Parameters.ExecutablePath = Options.DiscImageCreatorPath; break; // Verification support only case InternalProgram.CleanRip: + this.Parameters = new CleanRip.Parameters(parameters); this.Parameters.ExecutablePath = null; break; case InternalProgram.DCDumper: + this.Parameters = null; // TODO: Create correct parameter type when supported this.Parameters.ExecutablePath = null; break; case InternalProgram.UmdImageCreator: + this.Parameters = new UmdImageCreator.Parameters(parameters); this.Parameters.ExecutablePath = null; break; // This should never happen, but it needs a fallback default: - this.InternalProgram = InternalProgram.DiscImageCreator; + this.Parameters = new DiscImageCreator.Parameters(parameters); this.Parameters.ExecutablePath = Options.DiscImageCreatorPath; break; } @@ -309,7 +266,7 @@ namespace MPF.Utilities /// public string GetExtension(MediaType? mediaType) { - switch (this.InternalProgram) + switch (Options.InternalProgram) { case InternalProgram.Aaru: return Aaru.Converters.Extension(mediaType); @@ -342,7 +299,7 @@ namespace MPF.Utilities // Set the proper parameters string filename = OutputDirectory + Path.DirectorySeparatorChar + OutputFilename; - switch (InternalProgram) + switch (Options.InternalProgram) { case InternalProgram.Aaru: Parameters = new Aaru.Parameters(System, Type, Drive.Letter, filename, driveSpeed, Options); @@ -411,10 +368,10 @@ namespace MPF.Utilities return result; // Execute internal tool - progress?.Report(Result.Success($"Executing {this.InternalProgram}... please wait!")); + progress?.Report(Result.Success($"Executing {Options.InternalProgram}... please wait!")); Directory.CreateDirectory(OutputDirectory); await Task.Run(() => Parameters.ExecuteInternalProgram()); - progress?.Report(Result.Success($"{this.InternalProgram} has finished!")); + progress?.Report(Result.Success($"{Options.InternalProgram} has finished!")); // Execute additional tools progress?.Report(Result.Success("Running any additional tools... please wait!")); @@ -455,7 +412,7 @@ namespace MPF.Utilities } // Reset the drive automatically if confugured to - if (InternalProgram == InternalProgram.DiscImageCreator && Options.DICResetDriveAfterDump) + if (Options.InternalProgram == InternalProgram.DiscImageCreator && Options.DICResetDriveAfterDump) { resultProgress?.Report(Result.Success($"Resetting drive {Drive.Letter}")); ResetDrive(); diff --git a/MPF.Test/Utilities/DumpEnvironmentTest.cs b/MPF.Test/Utilities/DumpEnvironmentTest.cs index 6b913f1f..5c2e54b3 100644 --- a/MPF.Test/Utilities/DumpEnvironmentTest.cs +++ b/MPF.Test/Utilities/DumpEnvironmentTest.cs @@ -16,7 +16,7 @@ namespace MPF.Test [InlineData("stop D", 'D', false, MediaType.DVD, true)] public void ParametersValidTest(string parameters, char letter, bool isFloppy, MediaType? mediaType, bool expected) { - var options = new Options() { InternalProgram = "dic" }; + var options = new Options() { InternalProgram = InternalProgram.DiscImageCreator }; var drive = isFloppy ? new Drive(InternalDriveType.Floppy, new DriveInfo(letter.ToString())) : new Drive(InternalDriveType.Optical, new DriveInfo(letter.ToString())); @@ -38,7 +38,7 @@ namespace MPF.Test [InlineData("superhero", "blah&foo.bin", "superhero", "blah&foo.bin")] public void FixOutputPathsTest(string outputDirectory, string outputFilename, string expectedOutputDirectory, string expectedOutputFilename) { - var options = new Options() { InternalProgram = "dic" }; + var options = new Options() { InternalProgram = InternalProgram.DiscImageCreator }; var env = new DumpEnvironment(options, outputDirectory, outputFilename, null, KnownSystem.IBMPCCompatible, MediaType.CDROM, string.Empty); env.FixOutputPaths(); diff --git a/MPF/Windows/MainWindow.xaml.cs b/MPF/Windows/MainWindow.xaml.cs index a7fb0127..c3778f06 100644 --- a/MPF/Windows/MainWindow.xaml.cs +++ b/MPF/Windows/MainWindow.xaml.cs @@ -459,7 +459,7 @@ namespace MPF.Windows string protections = await Validators.RunProtectionScanOnPath(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")) + if (Env.Options.InternalProgram == InternalProgram.DiscImageCreator && protections.Contains("SmartE")) { ((DiscImageCreator.Parameters)Env.Parameters)[DiscImageCreator.Flag.ScanFileProtect] = false; LogOutput.VerboseLogLn($"SmartE detected, removing {DiscImageCreator.FlagStrings.ScanFileProtect} from parameters"); @@ -748,8 +748,7 @@ namespace MPF.Windows /// /// Handler for DiscInformationWindow OnUpdated event /// - /// Identical to MediaScanButtonClick - public void OnOptionsUpdated() + private void OnOptionsUpdated(object sender, EventArgs e) { InitializeUIValues(removeEventHandlers: true, rescanDrives: true); } @@ -760,10 +759,10 @@ namespace MPF.Windows private void OptionsMenuItemClick(object sender, RoutedEventArgs e) { // Show the window and wait for the response - var optionsWindow = new OptionsWindow(); - optionsWindow.UIOptions = UIOptions; + var optionsWindow = new OptionsWindow(UIOptions); optionsWindow.Owner = this; optionsWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner; + optionsWindow.Closed += OnOptionsUpdated; optionsWindow.Refresh(); optionsWindow.Show(); } diff --git a/MPF/Windows/OptionsWindow.xaml b/MPF/Windows/OptionsWindow.xaml index d9d47174..8d155bd3 100644 --- a/MPF/Windows/OptionsWindow.xaml +++ b/MPF/Windows/OptionsWindow.xaml @@ -39,7 +39,7 @@