Files
MPF/MPF.Check/Program.cs

117 lines
4.6 KiB
C#
Raw Permalink Normal View History

using System;
using System.IO;
2023-10-26 00:57:23 -04:00
using BinaryObjectScanner;
2023-10-06 20:39:59 -04:00
using MPF.Core;
using MPF.Core.Data;
using MPF.Core.Utilities;
2023-09-05 00:08:09 -04:00
using SabreTools.RedumpLib.Data;
using SabreTools.RedumpLib.Web;
2020-11-10 17:43:21 -08:00
namespace MPF.Check
{
public class Program
{
public static void Main(string[] args)
{
// Try processing the standalone arguments
2023-10-11 12:54:40 -04:00
bool? standaloneProcessed = OptionsLoader.ProcessStandaloneArguments(args);
if (standaloneProcessed != false)
2023-10-10 15:15:42 -04:00
{
2023-10-11 12:54:40 -04:00
if (standaloneProcessed == null)
DisplayHelp();
2019-04-04 00:37:17 -07:00
return;
2023-10-10 15:15:42 -04:00
}
2019-04-04 00:37:17 -07:00
// Try processing the common arguments
2023-10-10 23:22:21 -04:00
(bool success, MediaType mediaType, RedumpSystem? knownSystem, var error) = OptionsLoader.ProcessCommonArguments(args);
if (!success)
2023-10-10 15:15:42 -04:00
{
DisplayHelp(error);
2019-04-04 00:37:17 -07:00
return;
2023-10-10 15:15:42 -04:00
}
2019-04-04 00:37:17 -07:00
2020-08-07 21:15:36 -07:00
// Loop through and process options
2023-10-10 23:22:21 -04:00
(var options, var seedInfo, var path, int startIndex) = OptionsLoader.LoadFromArguments(args, startIndex: 2);
if (options.InternalProgram == InternalProgram.NONE)
{
DisplayHelp("A program name needs to be provided");
return;
}
2020-08-07 21:15:36 -07:00
// Make new Progress objects
var resultProgress = new Progress<Result>();
2023-10-10 15:15:42 -04:00
resultProgress.ProgressChanged += ConsoleLogger.ProgressUpdated;
2021-01-22 12:03:12 -08:00
var protectionProgress = new Progress<ProtectionProgress>();
2023-10-10 15:15:42 -04:00
protectionProgress.ProgressChanged += ConsoleLogger.ProgressUpdated;
// Validate the supplied credentials
2023-11-14 23:53:15 -05:00
#if NETFRAMEWORK
(bool? _, string? message) = RedumpWebClient.ValidateCredentials(options.RedumpUsername ?? string.Empty, options.RedumpPassword ?? string.Empty);
#else
2023-10-10 23:22:21 -04:00
(bool? _, string? message) = RedumpHttpClient.ValidateCredentials(options.RedumpUsername ?? string.Empty, options.RedumpPassword ?? string.Empty).ConfigureAwait(false).GetAwaiter().GetResult();
2023-11-14 23:53:15 -05:00
#endif
if (!string.IsNullOrEmpty(message))
2022-04-12 12:01:26 -07:00
Console.WriteLine(message);
// Loop through all the rest of the args
for (int i = startIndex; i < args.Length; i++)
{
// Check for a file
2020-06-16 13:25:45 -07:00
if (!File.Exists(args[i].Trim('"')))
{
2020-06-16 13:25:45 -07:00
DisplayHelp($"{args[i].Trim('"')} does not exist");
return;
}
// Get the full file path
2020-06-16 13:25:45 -07:00
string filepath = Path.GetFullPath(args[i].Trim('"'));
// Now populate an environment
2023-10-10 23:22:21 -04:00
Drive? drive = null;
if (!string.IsNullOrEmpty(path))
2023-11-14 23:53:15 -05:00
drive = Drive.Create(null, path!);
2020-08-07 21:15:36 -07:00
var env = new DumpEnvironment(options, filepath, drive, knownSystem, mediaType, internalProgram: null, parameters: null);
// Finally, attempt to do the output dance
#if NET40
var resultTask = env.VerifyAndSaveDumpOutput(resultProgress, protectionProgress);
resultTask.Wait();
var result = resultTask.Result;
2023-11-21 11:13:58 -05:00
#else
2020-08-07 21:15:36 -07:00
var result = env.VerifyAndSaveDumpOutput(resultProgress, protectionProgress).ConfigureAwait(false).GetAwaiter().GetResult();
2023-11-21 11:13:58 -05:00
#endif
Console.WriteLine(result.Message);
}
}
2019-04-04 00:37:17 -07:00
/// <summary>
2020-11-10 17:43:21 -08:00
/// Display help for MPF.Check
2019-04-04 00:37:17 -07:00
/// </summary>
/// <param name="error">Error string to prefix the help text with</param>
2023-10-10 23:22:21 -04:00
private static void DisplayHelp(string? error = null)
{
if (error != null)
Console.WriteLine(error);
Console.WriteLine("Usage:");
2021-08-09 22:55:17 -07:00
Console.WriteLine("MPF.Check.exe <mediatype> <system> [options] </path/to/output.cue/iso> ...");
Console.WriteLine();
2020-08-07 21:15:36 -07:00
Console.WriteLine("Standalone Options:");
Console.WriteLine("-h, -? Show this help text");
Console.WriteLine("-lm, --listmedia List supported media types");
Console.WriteLine("-ls, --listsystems List supported system types");
Console.WriteLine("-lp, --listprograms List supported dumping program outputs");
2020-05-07 14:23:49 -07:00
Console.WriteLine();
2020-08-07 21:15:36 -07:00
Console.WriteLine("Check Options:");
var supportedArguments = OptionsLoader.PrintSupportedArguments();
foreach (string argument in supportedArguments)
{
Console.WriteLine(argument);
}
Console.WriteLine();
}
}
}