Files
MPF/MPF.CLI/Features/InteractiveFeature.cs

197 lines
7.0 KiB
C#
Raw Permalink Normal View History

2025-10-06 10:32:16 -04:00
using System;
using System.IO;
using MPF.Frontend;
using MPF.Frontend.Tools;
using SabreTools.RedumpLib.Data;
namespace MPF.CLI.Features
{
2025-10-06 16:13:51 -04:00
internal sealed class InteractiveFeature : BaseFeature
2025-10-06 10:32:16 -04:00
{
#region Feature Definition
public const string DisplayName = "interactive";
private static readonly string[] _flags = ["i", "interactive"];
private const string _description = "Enable interactive mode";
#endregion
public InteractiveFeature()
: base(DisplayName, _flags, _description)
{
}
/// <inheritdoc/>
2025-10-06 16:13:51 -04:00
public override bool ProcessArgs(string[] args, int index)
2025-10-06 10:32:16 -04:00
{
2025-10-06 16:25:41 -04:00
// Cache all args as inputs
for (int i = 1; i < args.Length; i++)
{
Inputs.Add(args[i]);
}
// Read the options from config, if possible
Options = OptionsLoader.LoadFromConfig();
2025-10-06 10:32:16 -04:00
// Create return values
2025-10-06 17:49:16 -04:00
MediaType = SabreTools.RedumpLib.Data.MediaType.NONE;
2026-01-01 10:21:19 -05:00
string defaultFileName = $"track_{DateTime.Now:yyyyMMdd-HHmm}";
#if NET20 || NET35
FilePath = Path.Combine(Options.Dumping.DefaultOutputPath ?? "ISO", Path.Combine(defaultFileName, $"{defaultFileName}.bin"));
2026-01-01 10:21:19 -05:00
#else
FilePath = Path.Combine(Options.Dumping.DefaultOutputPath ?? "ISO", defaultFileName, $"{defaultFileName}.bin");
2026-01-01 10:21:19 -05:00
#endif
System = Options.Dumping.DefaultSystem;
2025-10-06 10:32:16 -04:00
// Create state values
2025-11-11 15:52:26 -05:00
string? result;
2025-10-06 10:32:16 -04:00
root:
Console.Clear();
Console.WriteLine("MPF.CLI Interactive Mode - Main Menu");
Console.WriteLine("-------------------------");
Console.WriteLine();
Console.WriteLine($"1) Set system (Currently '{System}')");
Console.WriteLine($"2) Set dumping program (Currently '{Options.InternalProgram}')");
2025-10-06 17:49:16 -04:00
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}')");
2025-10-06 10:32:16 -04:00
Console.WriteLine();
Console.WriteLine($"Q) Exit the program");
Console.WriteLine($"X) Start dumping");
Console.Write("> ");
result = Console.ReadLine();
switch (result)
{
case "1":
goto system;
case "2":
goto dumpingProgram;
case "3":
goto mediaType;
case "4":
goto devicePath;
case "5":
goto mountedPath;
case "6":
goto filePath;
case "7":
goto overrideSpeed;
case "8":
goto customParams;
case "q":
case "Q":
Environment.Exit(0);
break;
case "x":
case "X":
Console.Clear();
goto exit;
case "z":
case "Z":
Console.WriteLine("It is pitch black. You are likely to be eaten by a grue.");
Console.Write("> ");
Console.ReadLine();
goto root;
default:
Console.WriteLine($"Invalid selection: {result}");
Console.ReadLine();
goto root;
}
system:
2025-10-07 19:43:34 -04:00
Console.WriteLine();
Console.WriteLine("For possible inputs, use the List Systems commandline option");
2025-10-06 10:32:16 -04:00
Console.WriteLine();
Console.WriteLine("Input the system and press Enter:");
Console.Write("> ");
result = Console.ReadLine();
System = result.ToRedumpSystem();
2025-10-06 10:32:16 -04:00
goto root;
dumpingProgram:
2025-10-07 19:43:34 -04:00
Console.WriteLine();
Console.WriteLine("Options:");
2025-11-11 15:52:26 -05:00
Console.WriteLine($"{InternalProgram.Redumper.ToString().ToLowerInvariant(),-15} => {InternalProgram.Redumper.LongName()}");
Console.WriteLine($"{InternalProgram.DiscImageCreator.ToString().ToLowerInvariant(),-15} => {InternalProgram.DiscImageCreator.LongName()}");
Console.WriteLine($"{InternalProgram.Aaru.ToString().ToLowerInvariant(),-15} => {InternalProgram.Aaru.LongName()}");
2026-01-27 16:16:34 -05:00
// Console.WriteLine($"{InternalProgram.Dreamdump.ToString().ToLowerInvariant(),-15} => {InternalProgram.Dreamdump.LongName()}");
2025-10-06 10:32:16 -04:00
Console.WriteLine();
Console.WriteLine("Input the dumping program and press Enter:");
Console.Write("> ");
result = Console.ReadLine();
Options.InternalProgram = result.ToInternalProgram();
2025-10-06 10:32:16 -04:00
goto root;
mediaType:
2025-10-07 19:43:34 -04:00
Console.WriteLine();
Console.WriteLine("For possible inputs, use the List Media commandline option");
2025-10-06 10:32:16 -04:00
Console.WriteLine();
Console.WriteLine("Input the media type and press Enter:");
Console.Write("> ");
result = Console.ReadLine();
2025-10-06 17:49:16 -04:00
MediaType = OptionsLoader.ToMediaType(result);
2025-10-06 10:32:16 -04:00
goto root;
devicePath:
Console.WriteLine();
Console.WriteLine("Input the device path and press Enter:");
Console.Write("> ");
2025-10-06 17:49:16 -04:00
DevicePath = Console.ReadLine();
2025-10-06 10:32:16 -04:00
goto root;
mountedPath:
Console.WriteLine();
Console.WriteLine("Input the mounted path and press Enter:");
Console.Write("> ");
2025-10-06 17:49:16 -04:00
MountedPath = Console.ReadLine();
2025-10-06 10:32:16 -04:00
goto root;
filePath:
Console.WriteLine();
Console.WriteLine("Input the file path and press Enter:");
Console.Write("> ");
result = Console.ReadLine();
if (!string.IsNullOrEmpty(result))
result = Path.GetFullPath(result!);
2025-10-06 17:49:16 -04:00
FilePath = result;
2025-10-06 10:32:16 -04:00
goto root;
overrideSpeed:
Console.WriteLine();
Console.WriteLine("Input the override speed and press Enter:");
Console.Write("> ");
result = Console.ReadLine();
if (!int.TryParse(result, out int speed))
speed = -1;
2025-10-06 17:49:16 -04:00
DriveSpeed = speed;
2025-10-06 10:32:16 -04:00
goto root;
customParams:
Console.WriteLine();
Console.WriteLine("Input the custom parameters and press Enter:");
Console.Write("> ");
2025-10-06 17:49:16 -04:00
CustomParams = Console.ReadLine();
2025-10-06 10:32:16 -04:00
goto root;
exit:
return true;
}
/// <inheritdoc/>
public override bool VerifyInputs() => true;
}
}