Remove CommandOptions implementations

This commit is contained in:
Matt Nadareski
2025-10-06 17:49:16 -04:00
parent 0a60fe5a37
commit fe76387f6a
9 changed files with 98 additions and 130 deletions

View File

@@ -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)

View File

@@ -15,11 +15,6 @@ namespace MPF.CLI.Features
{
#region Properties
/// <summary>
/// Progrma-specific options
/// </summary>
public Program.CommandOptions CommandOptions { get; protected set; }
/// <summary>
/// User-defined options
/// </summary>
@@ -30,12 +25,45 @@ namespace MPF.CLI.Features
/// </summary>
public RedumpSystem? System { get; protected set; }
/// <summary>
/// Media type to dump
/// </summary>
/// <remarks>Required for DIC and if custom parameters not set</remarks>
public MediaType? MediaType { get; protected set; }
/// <summary>
/// Path to the device to dump
/// </summary>
/// <remarks>Required if custom parameters are not set</remarks>
public string? DevicePath { get; protected set; }
/// <summary>
/// Path to the mounted filesystem to check
/// </summary>
/// <remarks>Should only be used when the device path is not readable</remarks>
public string? MountedPath { get; protected set; }
/// <summary>
/// Path to the output file
/// </summary>
/// <remarks>Required if custom parameters are not set</remarks>
public string? FilePath { get; protected set; }
/// <summary>
/// Override drive speed
/// </summary>
public int? DriveSpeed { get; protected set; }
/// <summary>
/// Custom parameters for dumping
/// </summary>
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();
}

View File

@@ -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:

View File

@@ -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

View File

@@ -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();
}
/// <summary>
/// Represents commandline options
/// </summary>
internal class CommandOptions
{
/// <summary>
/// Media type to dump
/// </summary>
/// <remarks>Required for DIC and if custom parameters not set</remarks>
public MediaType? MediaType { get; set; } = null;
/// <summary>
/// Path to the device to dump
/// </summary>
/// <remarks>Required if custom parameters are not set</remarks>
public string? DevicePath { get; set; } = null;
/// <summary>
/// Path to the mounted filesystem to check
/// </summary>
/// <remarks>Should only be used when the device path is not readable</remarks>
public string? MountedPath { get; set; } = null;
/// <summary>
/// Path to the output file
/// </summary>
/// <remarks>Required if custom parameters are not set</remarks>
public string? FilePath { get; set; } = null;
/// <summary>
/// Override drive speed
/// </summary>
public int? DriveSpeed { get; set; } = null;
/// <summary>
/// Custom parameters for dumping
/// </summary>
public string? CustomParams { get; set; } = null;
}
}
}

View File

@@ -14,11 +14,6 @@ namespace MPF.Check.Features
{
#region Properties
/// <summary>
/// Progrma-specific options
/// </summary>
public Program.CommandOptions CommandOptions { get; protected set; }
/// <summary>
/// User-defined options
/// </summary>
@@ -29,12 +24,21 @@ namespace MPF.Check.Features
/// </summary>
public RedumpSystem? System { get; protected set; }
/// <summary>
/// Seed submission info from an input file
/// </summary>
public SubmissionInfo? Seed { get; protected set; }
/// <summary>
/// Path to the device to scan
/// </summary>
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);
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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();
}
/// <summary>
/// Represents commandline options
/// </summary>
internal class CommandOptions
{
/// <summary>
/// Seed submission info from an input file
/// </summary>
public SubmissionInfo? Seed { get; set; } = null;
/// <summary>
/// Path to the device to scan
/// </summary>
public string? DevicePath { get; set; } = null;
}
}
}