2019-02-10 14:47:53 -08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
2020-08-07 21:15:36 -07:00
|
|
|
|
using BurnOutSharp;
|
2021-09-29 11:48:37 -07:00
|
|
|
|
using MPF.Core.Converters;
|
|
|
|
|
|
using MPF.Core.Data;
|
|
|
|
|
|
using MPF.Core.Utilities;
|
2021-09-29 15:05:17 -07:00
|
|
|
|
using MPF.Library;
|
2023-09-05 00:08:09 -04:00
|
|
|
|
using SabreTools.RedumpLib.Data;
|
|
|
|
|
|
using SabreTools.RedumpLib.Web;
|
2019-02-10 14:47:53 -08:00
|
|
|
|
|
2020-11-10 17:43:21 -08:00
|
|
|
|
namespace MPF.Check
|
2019-02-10 14:47:53 -08:00
|
|
|
|
{
|
|
|
|
|
|
public class Program
|
|
|
|
|
|
{
|
|
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
|
{
|
2022-04-12 12:06:45 -07:00
|
|
|
|
// Try processing the standalone arguments
|
2022-04-12 11:27:10 -07:00
|
|
|
|
if (ProcessStandaloneArguments(args))
|
2019-04-04 00:37:17 -07:00
|
|
|
|
return;
|
|
|
|
|
|
|
2022-04-12 12:06:45 -07:00
|
|
|
|
// Try processing the common arguments
|
|
|
|
|
|
(bool success, MediaType mediaType, RedumpSystem? knownSystem) = ProcessCommonArguments(args);
|
|
|
|
|
|
if (!success)
|
2019-04-04 00:37:17 -07:00
|
|
|
|
return;
|
|
|
|
|
|
|
2020-08-07 21:15:36 -07:00
|
|
|
|
// Loop through and process options
|
2023-07-14 12:07:44 -04:00
|
|
|
|
(Core.Data.Options options, string path, int startIndex) = OptionsLoader.LoadFromArguments(args, startIndex: 2);
|
2023-08-15 00:30:30 -04:00
|
|
|
|
if (options.InternalProgram == InternalProgram.NONE)
|
|
|
|
|
|
{
|
|
|
|
|
|
DisplayHelp("A program name needs to be provided");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2019-05-14 01:46:10 -07:00
|
|
|
|
|
2020-08-07 21:15:36 -07:00
|
|
|
|
// Make new Progress objects
|
|
|
|
|
|
var resultProgress = new Progress<Result>();
|
|
|
|
|
|
resultProgress.ProgressChanged += ProgressUpdated;
|
2021-01-22 12:03:12 -08:00
|
|
|
|
var protectionProgress = new Progress<ProtectionProgress>();
|
2020-08-07 21:15:36 -07:00
|
|
|
|
protectionProgress.ProgressChanged += ProgressUpdated;
|
2019-02-10 14:47:53 -08:00
|
|
|
|
|
2022-04-12 11:27:10 -07:00
|
|
|
|
// Validate the supplied credentials
|
2022-07-26 13:47:19 -07:00
|
|
|
|
#if NET48 || NETSTANDARD2_1
|
2022-04-12 12:01:26 -07:00
|
|
|
|
(bool? _, string message) = RedumpWebClient.ValidateCredentials(options?.RedumpUsername, options?.RedumpPassword);
|
2022-07-26 13:47:19 -07:00
|
|
|
|
#else
|
|
|
|
|
|
(bool? _, string message) = RedumpHttpClient.ValidateCredentials(options?.RedumpUsername, options?.RedumpPassword).ConfigureAwait(false).GetAwaiter().GetResult();
|
|
|
|
|
|
#endif
|
2022-04-12 12:01:26 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(message))
|
|
|
|
|
|
Console.WriteLine(message);
|
2020-06-16 11:16:39 -07:00
|
|
|
|
|
2019-02-10 14:47:53 -08:00
|
|
|
|
// Loop through all the rest of the args
|
2019-05-14 01:46:10 -07:00
|
|
|
|
for (int i = startIndex; i < args.Length; i++)
|
2019-02-10 14:47:53 -08:00
|
|
|
|
{
|
2019-03-30 21:44:57 -07:00
|
|
|
|
// Check for a file
|
2020-06-16 13:25:45 -07:00
|
|
|
|
if (!File.Exists(args[i].Trim('"')))
|
2019-02-10 14:47:53 -08:00
|
|
|
|
{
|
2020-06-16 13:25:45 -07:00
|
|
|
|
DisplayHelp($"{args[i].Trim('"')} does not exist");
|
2019-02-10 14:47:53 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-20 22:03:23 -07:00
|
|
|
|
// Get the full file path
|
2020-06-16 13:25:45 -07:00
|
|
|
|
string filepath = Path.GetFullPath(args[i].Trim('"'));
|
2019-04-20 22:03:23 -07:00
|
|
|
|
|
2019-02-10 14:47:53 -08:00
|
|
|
|
// Now populate an environment
|
2020-08-07 21:15:36 -07:00
|
|
|
|
Drive drive = null;
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(path))
|
2022-04-20 13:47:55 -07:00
|
|
|
|
drive = Drive.Create(null, path);
|
2020-08-07 21:15:36 -07:00
|
|
|
|
|
2023-04-11 11:15:53 -04:00
|
|
|
|
var env = new DumpEnvironment(options, filepath, drive, knownSystem, mediaType, internalProgram: null, parameters: null);
|
2019-02-10 14:47:53 -08:00
|
|
|
|
|
|
|
|
|
|
// Finally, attempt to do the output dance
|
2020-08-07 21:15:36 -07:00
|
|
|
|
var result = env.VerifyAndSaveDumpOutput(resultProgress, protectionProgress).ConfigureAwait(false).GetAwaiter().GetResult();
|
2019-02-10 14:47:53 -08:00
|
|
|
|
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>
|
2019-02-10 14:47:53 -08: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> ...");
|
2019-02-10 14:47:53 -08:00
|
|
|
|
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();
|
2022-04-12 11:27:10 -07:00
|
|
|
|
|
2020-08-07 21:15:36 -07:00
|
|
|
|
Console.WriteLine("Check Options:");
|
2022-04-12 11:27:10 -07:00
|
|
|
|
var supportedArguments = OptionsLoader.PrintSupportedArguments();
|
|
|
|
|
|
foreach (string argument in supportedArguments)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(argument);
|
|
|
|
|
|
}
|
2020-05-07 13:56:21 -07:00
|
|
|
|
Console.WriteLine();
|
2019-02-10 14:47:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-04-12 12:06:45 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Process common arguments for all functionality
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>True if all arguments pass, false otherwise</returns>
|
|
|
|
|
|
private static (bool, MediaType, RedumpSystem?) ProcessCommonArguments(string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
// All other use requires at least 3 arguments
|
|
|
|
|
|
if (args.Length < 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
DisplayHelp("Invalid number of arguments");
|
|
|
|
|
|
return (false, MediaType.NONE, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check the MediaType
|
|
|
|
|
|
var mediaType = EnumConverter.ToMediaType(args[0].Trim('"'));
|
|
|
|
|
|
if (mediaType == MediaType.NONE)
|
|
|
|
|
|
{
|
|
|
|
|
|
DisplayHelp($"{args[0]} is not a recognized media type");
|
|
|
|
|
|
return (false, MediaType.NONE, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check the RedumpSystem
|
|
|
|
|
|
var knownSystem = Extensions.ToRedumpSystem(args[1].Trim('"'));
|
|
|
|
|
|
if (knownSystem == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DisplayHelp($"{args[1]} is not a recognized system");
|
|
|
|
|
|
return (false, MediaType.NONE, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (true, mediaType, knownSystem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-04-12 11:27:10 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Process any standalone arguments for the program
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>True if one of the arguments was processed, false otherwise</returns>
|
|
|
|
|
|
private static bool ProcessStandaloneArguments(string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Help options
|
|
|
|
|
|
if (args.Length == 0 || args[0] == "-h" || args[0] == "-?")
|
|
|
|
|
|
{
|
|
|
|
|
|
DisplayHelp();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// List options
|
|
|
|
|
|
if (args[0] == "-lm" || args[0] == "--listmedia")
|
|
|
|
|
|
{
|
2022-04-12 11:51:05 -07:00
|
|
|
|
Console.WriteLine("Supported Media Types:");
|
|
|
|
|
|
foreach (string mediaType in Extensions.ListMediaTypes())
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(mediaType);
|
|
|
|
|
|
}
|
2022-04-12 11:27:10 -07:00
|
|
|
|
Console.ReadLine();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (args[0] == "-lp" || args[0] == "--listprograms")
|
|
|
|
|
|
{
|
2022-04-12 11:51:05 -07:00
|
|
|
|
Console.WriteLine("Supported Programs:");
|
|
|
|
|
|
foreach (string program in EnumExtensions.ListPrograms())
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(program);
|
|
|
|
|
|
}
|
2022-04-12 11:27:10 -07:00
|
|
|
|
Console.ReadLine();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (args[0] == "-ls" || args[0] == "--listsystems")
|
|
|
|
|
|
{
|
2022-04-12 11:51:05 -07:00
|
|
|
|
Console.WriteLine("Supported Systems:");
|
|
|
|
|
|
foreach (string system in Extensions.ListSystems())
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(system);
|
|
|
|
|
|
}
|
2022-04-12 11:27:10 -07:00
|
|
|
|
Console.ReadLine();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-04 00:37:17 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Simple process counter to write to console
|
|
|
|
|
|
/// </summary>
|
2019-02-10 14:47:53 -08:00
|
|
|
|
private static void ProgressUpdated(object sender, Result value)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(value.Message);
|
|
|
|
|
|
}
|
2020-08-07 21:15:36 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Simple process counter to write to console
|
|
|
|
|
|
/// </summary>
|
2021-01-22 12:03:12 -08:00
|
|
|
|
private static void ProgressUpdated(object sender, ProtectionProgress value)
|
2020-08-07 21:15:36 -07:00
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine($"{value.Percentage * 100:N2}%: {value.Filename} - {value.Protection}");
|
|
|
|
|
|
}
|
2019-02-10 14:47:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|