using System; using System.IO; using MPF.Frontend; using MPF.Frontend.Tools; using SabreTools.RedumpLib.Data; namespace MPF.CLI.Features { internal sealed class InteractiveFeature : BaseFeature { #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) { } /// public override bool ProcessArgs(string[] args, int index) { // 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(); // Create return values MediaType = SabreTools.RedumpLib.Data.MediaType.NONE; string defaultFileName = $"track_{DateTime.Now:yyyyMMdd-HHmm}"; #if NET20 || NET35 FilePath = Path.Combine(Options.Dumping.DefaultOutputPath ?? "ISO", Path.Combine(defaultFileName, $"{defaultFileName}.bin")); #else FilePath = Path.Combine(Options.Dumping.DefaultOutputPath ?? "ISO", defaultFileName, $"{defaultFileName}.bin"); #endif System = Options.Dumping.DefaultSystem; // Create state values string? result; 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}')"); 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"); 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: Console.WriteLine(); Console.WriteLine("For possible inputs, use the List Systems commandline option"); Console.WriteLine(); Console.WriteLine("Input the system and press Enter:"); Console.Write("> "); result = Console.ReadLine(); System = result.ToRedumpSystem(); goto root; dumpingProgram: Console.WriteLine(); Console.WriteLine("Options:"); 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()}"); // Console.WriteLine($"{InternalProgram.Dreamdump.ToString().ToLowerInvariant(),-15} => {InternalProgram.Dreamdump.LongName()}"); Console.WriteLine(); Console.WriteLine("Input the dumping program and press Enter:"); Console.Write("> "); result = Console.ReadLine(); Options.InternalProgram = result.ToInternalProgram(); goto root; mediaType: Console.WriteLine(); Console.WriteLine("For possible inputs, use the List Media commandline option"); Console.WriteLine(); Console.WriteLine("Input the media type and press Enter:"); Console.Write("> "); result = Console.ReadLine(); MediaType = OptionsLoader.ToMediaType(result); goto root; devicePath: Console.WriteLine(); Console.WriteLine("Input the device path and press Enter:"); Console.Write("> "); DevicePath = Console.ReadLine(); goto root; mountedPath: Console.WriteLine(); Console.WriteLine("Input the mounted path and press Enter:"); Console.Write("> "); MountedPath = Console.ReadLine(); 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!); FilePath = result; 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; DriveSpeed = speed; goto root; customParams: Console.WriteLine(); Console.WriteLine("Input the custom parameters and press Enter:"); Console.Write("> "); CustomParams = Console.ReadLine(); goto root; exit: return true; } /// public override bool VerifyInputs() => true; } }