From fe76387f6a58f76bb63b39956fae6d1ef23af3b6 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 6 Oct 2025 17:49:16 -0400 Subject: [PATCH] Remove CommandOptions implementations --- CHANGELIST.md | 1 + MPF.CLI/Features/BaseFeature.cs | 72 ++++++++++++++++-------- MPF.CLI/Features/InteractiveFeature.cs | 32 +++++------ MPF.CLI/Features/MainFeature.cs | 13 ++--- MPF.CLI/Program.cs | 41 -------------- MPF.Check/Features/BaseFeature.cs | 22 +++++--- MPF.Check/Features/InteractiveFeature.cs | 17 +++--- MPF.Check/Features/MainFeature.cs | 13 ++--- MPF.Check/Program.cs | 17 ------ 9 files changed, 98 insertions(+), 130 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index ae96ad62..6f77ced6 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -15,6 +15,7 @@ - Assign inputs for interactive modes - Remove duplicate input declarations - Fix strange invocations of extension methods +- Remove CommandOptions implementations ### 3.4.2 (2025-09-30) diff --git a/MPF.CLI/Features/BaseFeature.cs b/MPF.CLI/Features/BaseFeature.cs index 87128e92..001368c1 100644 --- a/MPF.CLI/Features/BaseFeature.cs +++ b/MPF.CLI/Features/BaseFeature.cs @@ -15,11 +15,6 @@ namespace MPF.CLI.Features { #region Properties - /// - /// Progrma-specific options - /// - public Program.CommandOptions CommandOptions { get; protected set; } - /// /// User-defined options /// @@ -30,12 +25,45 @@ namespace MPF.CLI.Features /// public RedumpSystem? System { get; protected set; } + /// + /// Media type to dump + /// + /// Required for DIC and if custom parameters not set + public MediaType? MediaType { get; protected set; } + + /// + /// Path to the device to dump + /// + /// Required if custom parameters are not set + public string? DevicePath { get; protected set; } + + /// + /// Path to the mounted filesystem to check + /// + /// Should only be used when the device path is not readable + public string? MountedPath { get; protected set; } + + /// + /// Path to the output file + /// + /// Required if custom parameters are not set + public string? FilePath { get; protected set; } + + /// + /// Override drive speed + /// + public int? DriveSpeed { get; protected set; } + + /// + /// Custom parameters for dumping + /// + public string? CustomParams { get; protected set; } + #endregion protected BaseFeature(string name, string[] flags, string description, string? detailed = null) : base(name, flags, description, detailed) { - CommandOptions = new Program.CommandOptions(); Options = new Options() { // Internal Program @@ -116,49 +144,49 @@ namespace MPF.CLI.Features } // Ensure we have the values we need - if (CommandOptions.CustomParams == null && (CommandOptions.DevicePath == null || CommandOptions.FilePath == null)) + if (CustomParams == null && (DevicePath == null || FilePath == null)) { Program.DisplayHelp("Both a device path and file path need to be supplied, exiting..."); return false; } if (Options.InternalProgram == InternalProgram.DiscImageCreator - && CommandOptions.CustomParams == null - && (CommandOptions.MediaType == null || CommandOptions.MediaType == MediaType.NONE)) + && CustomParams == null + && (MediaType == null || MediaType == SabreTools.RedumpLib.Data.MediaType.NONE)) { Program.DisplayHelp("Media type is required for DiscImageCreator, exiting..."); return false; } // Normalize the file path - if (CommandOptions.FilePath != null) - CommandOptions.FilePath = FrontendTool.NormalizeOutputPaths(CommandOptions.FilePath, getFullPath: true); + if (FilePath != null) + FilePath = FrontendTool.NormalizeOutputPaths(FilePath, getFullPath: true); // Get the speed from the options - int speed = CommandOptions.DriveSpeed ?? FrontendTool.GetDefaultSpeedForMediaType(CommandOptions.MediaType, Options); + int speed = DriveSpeed ?? FrontendTool.GetDefaultSpeedForMediaType(MediaType, Options); // Populate an environment - var drive = Drive.Create(null, CommandOptions.DevicePath ?? string.Empty); + var drive = Drive.Create(null, DevicePath ?? string.Empty); var env = new DumpEnvironment(Options, - CommandOptions.FilePath, + FilePath, drive, System, Options.InternalProgram); - env.SetExecutionContext(CommandOptions.MediaType, null); + env.SetExecutionContext(MediaType, null); env.SetProcessor(); // Process the parameters - string? paramStr = CommandOptions.CustomParams ?? env.GetFullParameters(CommandOptions.MediaType, speed); + string? paramStr = CustomParams ?? env.GetFullParameters(MediaType, speed); if (string.IsNullOrEmpty(paramStr)) { Program.DisplayHelp("No valid environment could be created, exiting..."); return false; } - env.SetExecutionContext(CommandOptions.MediaType, paramStr); + env.SetExecutionContext(MediaType, paramStr); // Invoke the dumping program Console.WriteLine($"Invoking {Options.InternalProgram} using '{paramStr}'"); - var dumpResult = env.Run(CommandOptions.MediaType).GetAwaiter().GetResult(); + var dumpResult = env.Run(MediaType).GetAwaiter().GetResult(); Console.WriteLine(dumpResult.Message); if (!dumpResult) return false; @@ -171,15 +199,15 @@ namespace MPF.CLI.Features } // If we have a mounted path, replace the environment - if (CommandOptions.MountedPath != null && Directory.Exists(CommandOptions.MountedPath)) + if (MountedPath != null && Directory.Exists(MountedPath)) { - drive = Drive.Create(null, CommandOptions.MountedPath); + drive = Drive.Create(null, MountedPath); env = new DumpEnvironment(Options, - CommandOptions.FilePath, + FilePath, drive, System, internalProgram: null); - env.SetExecutionContext(CommandOptions.MediaType, null); + env.SetExecutionContext(MediaType, null); env.SetProcessor(); } diff --git a/MPF.CLI/Features/InteractiveFeature.cs b/MPF.CLI/Features/InteractiveFeature.cs index 81d8ec57..b2581d26 100644 --- a/MPF.CLI/Features/InteractiveFeature.cs +++ b/MPF.CLI/Features/InteractiveFeature.cs @@ -22,7 +22,6 @@ namespace MPF.CLI.Features public InteractiveFeature() : base(DisplayName, _flags, _description) { - CommandOptions = new Program.CommandOptions(); Options = OptionsLoader.LoadFromConfig(); } @@ -36,11 +35,8 @@ namespace MPF.CLI.Features } // Create return values - CommandOptions = new Program.CommandOptions - { - MediaType = MediaType.NONE, - FilePath = Path.Combine(Options.DefaultOutputPath ?? "ISO", "track.bin"), - }; + MediaType = SabreTools.RedumpLib.Data.MediaType.NONE; + FilePath = Path.Combine(Options.DefaultOutputPath ?? "ISO", "track.bin"); System = Options.DefaultSystem; // Create state values @@ -53,12 +49,12 @@ namespace MPF.CLI.Features Console.WriteLine(); Console.WriteLine($"1) Set system (Currently '{System}')"); Console.WriteLine($"2) Set dumping program (Currently '{Options.InternalProgram}')"); - Console.WriteLine($"3) Set media type (Currently '{CommandOptions.MediaType}')"); - Console.WriteLine($"4) Set device path (Currently '{CommandOptions.DevicePath}')"); - Console.WriteLine($"5) Set mounted path (Currently '{CommandOptions.MountedPath}')"); - Console.WriteLine($"6) Set file path (Currently '{CommandOptions.FilePath}')"); - Console.WriteLine($"7) Set override speed (Currently '{CommandOptions.DriveSpeed}')"); - Console.WriteLine($"8) Set custom parameters (Currently '{CommandOptions.CustomParams}')"); + Console.WriteLine($"3) Set media type (Currently '{MediaType}')"); + Console.WriteLine($"4) Set device path (Currently '{DevicePath}')"); + Console.WriteLine($"5) Set mounted path (Currently '{MountedPath}')"); + Console.WriteLine($"6) Set file path (Currently '{FilePath}')"); + Console.WriteLine($"7) Set override speed (Currently '{DriveSpeed}')"); + Console.WriteLine($"8) Set custom parameters (Currently '{CustomParams}')"); Console.WriteLine(); Console.WriteLine($"Q) Exit the program"); Console.WriteLine($"X) Start dumping"); @@ -125,21 +121,21 @@ namespace MPF.CLI.Features Console.WriteLine("Input the media type and press Enter:"); Console.Write("> "); result = Console.ReadLine(); - CommandOptions.MediaType = OptionsLoader.ToMediaType(result); + MediaType = OptionsLoader.ToMediaType(result); goto root; devicePath: Console.WriteLine(); Console.WriteLine("Input the device path and press Enter:"); Console.Write("> "); - CommandOptions.DevicePath = Console.ReadLine(); + DevicePath = Console.ReadLine(); goto root; mountedPath: Console.WriteLine(); Console.WriteLine("Input the mounted path and press Enter:"); Console.Write("> "); - CommandOptions.MountedPath = Console.ReadLine(); + MountedPath = Console.ReadLine(); goto root; filePath: @@ -151,7 +147,7 @@ namespace MPF.CLI.Features if (!string.IsNullOrEmpty(result)) result = Path.GetFullPath(result!); - CommandOptions.FilePath = result; + FilePath = result; goto root; overrideSpeed: @@ -163,14 +159,14 @@ namespace MPF.CLI.Features if (!int.TryParse(result, out int speed)) speed = -1; - CommandOptions.DriveSpeed = speed; + DriveSpeed = speed; goto root; customParams: Console.WriteLine(); Console.WriteLine("Input the custom parameters and press Enter:"); Console.Write("> "); - CommandOptions.CustomParams = Console.ReadLine(); + CustomParams = Console.ReadLine(); goto root; exit: diff --git a/MPF.CLI/Features/MainFeature.cs b/MPF.CLI/Features/MainFeature.cs index 5cb7a2a5..1f169ed0 100644 --- a/MPF.CLI/Features/MainFeature.cs +++ b/MPF.CLI/Features/MainFeature.cs @@ -48,7 +48,6 @@ namespace MPF.CLI.Features public MainFeature() : base(DisplayName, _flags, _description) { - CommandOptions = new Program.CommandOptions(); Options = new Options() { // Internal Program @@ -104,27 +103,27 @@ namespace MPF.CLI.Features // Set a media type else if (MediaTypeInput.ProcessInput(args, ref index)) - CommandOptions.MediaType = OptionsLoader.ToMediaType(MediaTypeInput.Value?.Trim('"')); + MediaType = OptionsLoader.ToMediaType(MediaTypeInput.Value?.Trim('"')); // Use a device path else if (DeviceInput.ProcessInput(args, ref index)) - CommandOptions.DevicePath = DeviceInput.Value; + DevicePath = DeviceInput.Value; // Use a mounted path for physical checks else if (MountedInput.ProcessInput(args, ref index)) - CommandOptions.MountedPath = MountedInput.Value; + MountedPath = MountedInput.Value; // Use a file path else if (FileInput.ProcessInput(args, ref index)) - CommandOptions.FilePath = FileInput.Value; + FilePath = FileInput.Value; // Set an override speed else if (SpeedInput.ProcessInput(args, ref index)) - CommandOptions.DriveSpeed = SpeedInput.Value; + DriveSpeed = SpeedInput.Value; // Use a custom parameters else if (CustomInput.ProcessInput(args, ref index)) - CommandOptions.CustomParams = CustomInput.Value; + CustomParams = CustomInput.Value; // Default, add to inputs else diff --git a/MPF.CLI/Program.cs b/MPF.CLI/Program.cs index 62318efb..cb32fbb9 100644 --- a/MPF.CLI/Program.cs +++ b/MPF.CLI/Program.cs @@ -9,7 +9,6 @@ using MPF.Frontend.Features; using MPF.Frontend.Tools; using SabreTools.CommandLine; using SabreTools.CommandLine.Features; -using SabreTools.RedumpLib.Data; namespace MPF.CLI { @@ -172,45 +171,5 @@ namespace MPF.CLI Console.WriteLine("device dumping, usually Linux and macOS."); Console.WriteLine(); } - - /// - /// Represents commandline options - /// - internal class CommandOptions - { - /// - /// Media type to dump - /// - /// Required for DIC and if custom parameters not set - public MediaType? MediaType { get; set; } = null; - - /// - /// Path to the device to dump - /// - /// Required if custom parameters are not set - public string? DevicePath { get; set; } = null; - - /// - /// Path to the mounted filesystem to check - /// - /// Should only be used when the device path is not readable - public string? MountedPath { get; set; } = null; - - /// - /// Path to the output file - /// - /// Required if custom parameters are not set - public string? FilePath { get; set; } = null; - - /// - /// Override drive speed - /// - public int? DriveSpeed { get; set; } = null; - - /// - /// Custom parameters for dumping - /// - public string? CustomParams { get; set; } = null; - } } } diff --git a/MPF.Check/Features/BaseFeature.cs b/MPF.Check/Features/BaseFeature.cs index e6da5ded..7b451f4f 100644 --- a/MPF.Check/Features/BaseFeature.cs +++ b/MPF.Check/Features/BaseFeature.cs @@ -14,11 +14,6 @@ namespace MPF.Check.Features { #region Properties - /// - /// Progrma-specific options - /// - public Program.CommandOptions CommandOptions { get; protected set; } - /// /// User-defined options /// @@ -29,12 +24,21 @@ namespace MPF.Check.Features /// public RedumpSystem? System { get; protected set; } + /// + /// Seed submission info from an input file + /// + public SubmissionInfo? Seed { get; protected set; } + + /// + /// Path to the device to scan + /// + public string? DevicePath { get; protected set; } + #endregion protected BaseFeature(string name, string[] flags, string description, string? detailed = null) : base(name, flags, description, detailed) { - CommandOptions = new Program.CommandOptions(); Options = new Options() { // Internal Program @@ -103,8 +107,8 @@ namespace MPF.Check.Features // Now populate an environment Drive? drive = null; - if (!string.IsNullOrEmpty(CommandOptions.DevicePath)) - drive = Drive.Create(null, CommandOptions.DevicePath!); + if (!string.IsNullOrEmpty(DevicePath)) + drive = Drive.Create(null, DevicePath!); var env = new DumpEnvironment(Options, filepath, @@ -114,7 +118,7 @@ namespace MPF.Check.Features env.SetProcessor(); // Finally, attempt to do the output dance - var result = env.VerifyAndSaveDumpOutput(seedInfo: CommandOptions.Seed) + var result = env.VerifyAndSaveDumpOutput(seedInfo: Seed) .ConfigureAwait(false).GetAwaiter().GetResult(); Console.WriteLine(result.Message); } diff --git a/MPF.Check/Features/InteractiveFeature.cs b/MPF.Check/Features/InteractiveFeature.cs index 4645f6a5..18af9ff0 100644 --- a/MPF.Check/Features/InteractiveFeature.cs +++ b/MPF.Check/Features/InteractiveFeature.cs @@ -33,7 +33,6 @@ namespace MPF.Check.Features } // Create return values - CommandOptions = new Program.CommandOptions(); System = null; // These values require multiple parts to be active @@ -52,13 +51,13 @@ namespace MPF.Check.Features Console.WriteLine(); Console.WriteLine($"1) Set system (Currently '{System}')"); Console.WriteLine($"2) Set dumping program (Currently '{Options.InternalProgram}')"); - Console.WriteLine($"3) Set seed path (Currently '{CommandOptions.Seed}')"); + Console.WriteLine($"3) Set seed path (Currently '{Seed}')"); Console.WriteLine($"4) Add placeholders (Currently '{Options.AddPlaceholders}')"); Console.WriteLine($"5) Create IRD (Currently '{Options.CreateIRDAfterDumping}')"); Console.WriteLine($"6) Attempt Redump matches (Currently '{Options.RetrieveMatchInformation}')"); Console.WriteLine($"7) Redump credentials (Currently '{Options.RedumpUsername}')"); Console.WriteLine($"8) Pull all information (Currently '{Options.PullAllInformation}')"); - Console.WriteLine($"9) Set device path (Currently '{CommandOptions.DevicePath}')"); + Console.WriteLine($"9) Set device path (Currently '{DevicePath}')"); Console.WriteLine($"A) Scan for protection (Currently '{scan}')"); Console.WriteLine($"B) Scan archives for protection (Currently '{enableArchives}')"); Console.WriteLine($"C) Debug protection scan output (Currently '{enableDebug}')"); @@ -176,7 +175,7 @@ namespace MPF.Check.Features Console.WriteLine("Input the seed path and press Enter:"); Console.Write("> "); result = Console.ReadLine(); - CommandOptions.Seed = Builder.CreateFromFile(result); + Seed = Builder.CreateFromFile(result); goto root; redumpCredentials: @@ -203,15 +202,15 @@ namespace MPF.Check.Features Console.WriteLine(); Console.WriteLine("Input the device path and press Enter:"); Console.Write("> "); - CommandOptions.DevicePath = Console.ReadLine(); + DevicePath = Console.ReadLine(); goto root; exit: // Now deal with the complex options - Options.ScanForProtection = scan && !string.IsNullOrEmpty(CommandOptions.DevicePath); - Options.ScanArchivesForProtection = enableArchives && scan && !string.IsNullOrEmpty(CommandOptions.DevicePath); - Options.IncludeDebugProtectionInformation = enableDebug && scan && !string.IsNullOrEmpty(CommandOptions.DevicePath); - Options.HideDriveLetters = hideDriveLetters && scan && !string.IsNullOrEmpty(CommandOptions.DevicePath); + Options.ScanForProtection = scan && !string.IsNullOrEmpty(DevicePath); + Options.ScanArchivesForProtection = enableArchives && scan && !string.IsNullOrEmpty(DevicePath); + Options.IncludeDebugProtectionInformation = enableDebug && scan && !string.IsNullOrEmpty(DevicePath); + Options.HideDriveLetters = hideDriveLetters && scan && !string.IsNullOrEmpty(DevicePath); return true; } diff --git a/MPF.Check/Features/MainFeature.cs b/MPF.Check/Features/MainFeature.cs index aaa02a5a..2d15359c 100644 --- a/MPF.Check/Features/MainFeature.cs +++ b/MPF.Check/Features/MainFeature.cs @@ -74,7 +74,6 @@ namespace MPF.Check.Features public MainFeature() : base(DisplayName, _flags, _description) { - CommandOptions = new Program.CommandOptions(); Options = new Options() { // Internal Program @@ -146,7 +145,7 @@ namespace MPF.Check.Features // Include seed info file else if (LoadSeedInput.ProcessInput(args, ref index)) - CommandOptions.Seed = Builder.CreateFromFile(LoadSeedInput.Value); + Seed = Builder.CreateFromFile(LoadSeedInput.Value); // Disable placeholder values in submission info else if (NoPlaceholdersInput.ProcessInput(args, ref index)) @@ -180,7 +179,7 @@ namespace MPF.Check.Features // Use a device path for physical checks else if (PathInput.ProcessInput(args, ref index)) - CommandOptions.DevicePath = PathInput.Value; + DevicePath = PathInput.Value; // Scan for protection (requires device path) else if (ScanInput.ProcessInput(args, ref index)) @@ -224,10 +223,10 @@ namespace MPF.Check.Features } // Now deal with the complex options - Options.ScanForProtection = scan && !string.IsNullOrEmpty(CommandOptions.DevicePath); - Options.ScanArchivesForProtection = enableArchives && scan && !string.IsNullOrEmpty(CommandOptions.DevicePath); - Options.IncludeDebugProtectionInformation = enableDebug && scan && !string.IsNullOrEmpty(CommandOptions.DevicePath); - Options.HideDriveLetters = hideDriveLetters && scan && !string.IsNullOrEmpty(CommandOptions.DevicePath); + Options.ScanForProtection = scan && !string.IsNullOrEmpty(DevicePath); + Options.ScanArchivesForProtection = enableArchives && scan && !string.IsNullOrEmpty(DevicePath); + Options.IncludeDebugProtectionInformation = enableDebug && scan && !string.IsNullOrEmpty(DevicePath); + Options.HideDriveLetters = hideDriveLetters && scan && !string.IsNullOrEmpty(DevicePath); return true; } diff --git a/MPF.Check/Program.cs b/MPF.Check/Program.cs index 19e396b4..9ccb5311 100644 --- a/MPF.Check/Program.cs +++ b/MPF.Check/Program.cs @@ -7,7 +7,6 @@ using MPF.Check.Features; using MPF.Frontend.Features; using SabreTools.CommandLine; using SabreTools.CommandLine.Features; -using SabreTools.RedumpLib.Data; namespace MPF.Check { @@ -150,21 +149,5 @@ namespace MPF.Check Console.WriteLine("as any log archives. Please make backups of those if you need to before running Check."); Console.WriteLine(); } - - /// - /// Represents commandline options - /// - internal class CommandOptions - { - /// - /// Seed submission info from an input file - /// - public SubmissionInfo? Seed { get; set; } = null; - - /// - /// Path to the device to scan - /// - public string? DevicePath { get; set; } = null; - } } }