Files
MPF/MPF.Check/Program.cs

380 lines
15 KiB
C#
Raw Normal View History

using System;
using System.IO;
2025-10-06 10:32:16 -04:00
using MPF.Check.Features;
2024-07-24 11:45:12 -04:00
#if NET40
using System.Threading.Tasks;
#endif
2024-05-23 15:40:12 -04:00
using MPF.Frontend;
2024-05-28 14:19:59 -04:00
using MPF.Frontend.Tools;
2024-06-25 16:48:24 -04:00
using SabreTools.RedumpLib;
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)
{
// Create a default options object
2025-06-02 10:19:48 -04:00
var options = new Options()
{
// Internal Program
InternalProgram = InternalProgram.NONE,
// Extra Dumping Options
ScanForProtection = false,
AddPlaceholders = true,
PullAllInformation = false,
AddFilenameSuffix = false,
OutputSubmissionJSON = false,
IncludeArtifacts = false,
CompressLogFiles = false,
DeleteUnnecessaryFiles = false,
CreateIRDAfterDumping = false,
// Protection Scanning Options
ScanArchivesForProtection = true,
IncludeDebugProtectionInformation = false,
HideDriveLetters = false,
// Redump Login Information
2025-06-02 09:35:26 -04:00
RetrieveMatchInformation = true,
RedumpUsername = null,
RedumpPassword = null,
};
// 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
2025-04-30 16:49:28 -04:00
// Setup common outputs
CommandOptions opts;
RedumpSystem? knownSystem;
int startIndex;
// Use interactive mode
2025-10-06 10:32:16 -04:00
if (args.Length > 0 && (args[0] == "i" || args[0] == "interactive"))
2023-10-10 15:15:42 -04:00
{
2025-04-30 16:49:28 -04:00
startIndex = 1;
2025-10-06 10:32:16 -04:00
var interactive = new InteractiveFeature();
interactive.Execute();
opts = interactive.CommandOptions;
options = interactive.Options;
knownSystem = interactive.System;
2025-04-30 16:49:28 -04:00
}
// Use normal commandline parameters
else
{
// Try processing the common arguments
bool success = OptionsLoader.ProcessCommonArguments(args, out knownSystem, out var error);
2025-04-30 16:49:28 -04:00
if (!success)
{
DisplayHelp(error);
return;
}
// Loop through and process options
2025-06-17 17:18:12 -04:00
startIndex = 1;
2025-04-30 16:49:28 -04:00
opts = LoadFromArguments(args, options, ref startIndex);
2023-10-10 15:15:42 -04:00
}
2019-04-04 00:37:17 -07:00
if (options.InternalProgram == InternalProgram.NONE)
{
DisplayHelp("A program name needs to be provided");
return;
}
// Validate the supplied credentials
if (options.RetrieveMatchInformation
&& !string.IsNullOrEmpty(options.RedumpUsername)
&& !string.IsNullOrEmpty(options.RedumpPassword))
2024-10-18 13:04:53 -04:00
{
bool? validated = RedumpClient.ValidateCredentials(options.RedumpUsername!, options.RedumpPassword!).GetAwaiter().GetResult();
string message = validated switch
{
true => "Redump username and password accepted!",
false => "Redump username and password denied!",
null => "An error occurred validating your credentials!",
};
2024-10-18 13:04:53 -04: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;
2024-06-25 17:29:32 -04:00
if (!string.IsNullOrEmpty(opts.DevicePath))
drive = Drive.Create(null, opts.DevicePath!);
2020-08-07 21:15:36 -07:00
var env = new DumpEnvironment(options,
filepath,
drive,
knownSystem,
internalProgram: null);
env.SetProcessor();
// Finally, attempt to do the output dance
2024-12-18 22:55:53 -05:00
var result = env.VerifyAndSaveDumpOutput(seedInfo: opts.Seed)
.ConfigureAwait(false).GetAwaiter().GetResult();
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:");
Console.WriteLine("MPF.Check <system> [options] </path/to/output.cue/iso> ...");
Console.WriteLine();
2020-08-07 21:15:36 -07:00
Console.WriteLine("Standalone Options:");
Console.WriteLine("?, h, help Show this help text");
Console.WriteLine("version Print the program version");
Console.WriteLine("lc, listcodes List supported comment/content site codes");
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");
2025-10-06 10:32:16 -04:00
Console.WriteLine("i, interactive Enable interactive mode");
2020-05-07 14:23:49 -07:00
Console.WriteLine();
2020-08-07 21:15:36 -07:00
Console.WriteLine("Check Options:");
2024-06-25 16:48:24 -04:00
Console.WriteLine("-u, --use <program> Dumping program output type [REQUIRED]");
Console.WriteLine(" --load-seed <path> Load a seed submission JSON for user information");
Console.WriteLine(" --no-placeholders Disable placeholder values in submission info");
Console.WriteLine(" --create-ird Create IRD from output files (PS3 only)");
2025-06-02 09:35:26 -04:00
Console.WriteLine(" --no-retrieve Disable retrieving match information from Redump");
Console.WriteLine("-c, --credentials <user> <pw> Redump username and password (incompatible with --no-retrieve)");
Console.WriteLine(" --pull-all Pull all information from Redump (requires --credentials)");
2024-06-25 16:48:24 -04:00
Console.WriteLine("-p, --path <drivepath> Physical drive path for additional checks");
Console.WriteLine("-s, --scan Enable copy protection scan (requires --path)");
Console.WriteLine(" --disable-archives Disable scanning archives (requires --scan)");
Console.WriteLine(" --enable-debug Enable debug protection information (requires --scan)");
Console.WriteLine(" --hide-drive-letters Hide drive letters from scan output (requires --scan)");
2024-06-25 16:48:24 -04:00
Console.WriteLine("-x, --suffix Enable adding filename suffix");
Console.WriteLine("-j, --json Enable submission JSON output");
Console.WriteLine(" --include-artifacts Include artifacts in JSON (requires --json)");
2024-06-25 16:48:24 -04:00
Console.WriteLine("-z, --zip Enable log file compression");
Console.WriteLine("-d, --delete Enable unnecessary file deletion");
Console.WriteLine();
Console.WriteLine("WARNING: Check will overwrite both any existing submission information files as well");
Console.WriteLine("as any log archives. Please make backups of those if you need to before running Check.");
Console.WriteLine();
2024-06-25 16:48:24 -04:00
}
/// <summary>
/// Load the current set of options from application arguments
/// </summary>
2025-06-02 10:19:48 -04:00
private static CommandOptions LoadFromArguments(string[] args, Options options, ref int startIndex)
2024-06-25 16:48:24 -04:00
{
2024-06-25 17:29:32 -04:00
// Create return values
var opts = new CommandOptions();
2024-06-25 16:48:24 -04:00
// These values require multiple parts to be active
bool scan = false,
enableArchives = true,
enableDebug = false,
hideDriveLetters = false;
2024-06-25 16:48:24 -04:00
// If we have no arguments, just return
if (args == null || args.Length == 0)
{
startIndex = 0;
return opts;
}
2024-06-25 16:48:24 -04:00
// If we have an invalid start index, just return
if (startIndex < 0 || startIndex >= args.Length)
return opts;
2024-06-25 16:48:24 -04:00
// Loop through the arguments and parse out values
for (; startIndex < args.Length; startIndex++)
{
// Use specific program
if (args[startIndex].StartsWith("-u=") || args[startIndex].StartsWith("--use="))
{
string internalProgram = args[startIndex].Split('=')[1];
options.InternalProgram = internalProgram.ToInternalProgram();
2024-06-25 16:48:24 -04:00
}
else if (args[startIndex] == "-u" || args[startIndex] == "--use")
{
string internalProgram = args[startIndex + 1];
options.InternalProgram = internalProgram.ToInternalProgram();
2024-06-25 16:48:24 -04:00
startIndex++;
}
// Include seed info file
else if (args[startIndex].StartsWith("--load-seed="))
{
string seedInfo = args[startIndex].Split('=')[1];
opts.Seed = Builder.CreateFromFile(seedInfo);
}
else if (args[startIndex] == "--load-seed")
{
string seedInfo = args[startIndex + 1];
opts.Seed = Builder.CreateFromFile(seedInfo);
startIndex++;
}
// Disable placeholder values in submission info
else if (args[startIndex].Equals("--no-placeholders"))
{
options.AddPlaceholders = false;
}
// Create IRD from output files (PS3 only)
else if (args[startIndex].Equals("--create-ird"))
{
options.CreateIRDAfterDumping = true;
}
2025-06-02 09:35:26 -04:00
// Retrieve Redump match information
else if (args[startIndex] == "--no-retrieve")
{
options.RetrieveMatchInformation = false;
}
2024-06-25 16:48:24 -04:00
// Redump login
else if (args[startIndex].StartsWith("-c=") || args[startIndex].StartsWith("--credentials="))
{
string[] credentials = args[startIndex].Split('=')[1].Split(';');
options.RedumpUsername = credentials[0];
options.RedumpPassword = credentials[1];
2024-06-25 16:48:24 -04:00
}
else if (args[startIndex] == "-c" || args[startIndex] == "--credentials")
{
options.RedumpUsername = args[startIndex + 1];
options.RedumpPassword = args[startIndex + 2];
2024-06-25 16:48:24 -04:00
startIndex += 2;
}
// Pull all information (requires Redump login)
else if (args[startIndex].Equals("--pull-all"))
2024-06-25 16:48:24 -04:00
{
options.PullAllInformation = true;
2024-06-25 16:48:24 -04:00
}
// Use a device path for physical checks
else if (args[startIndex].StartsWith("-p=") || args[startIndex].StartsWith("--path="))
{
2024-06-25 17:29:32 -04:00
opts.DevicePath = args[startIndex].Split('=')[1];
2024-06-25 16:48:24 -04:00
}
else if (args[startIndex] == "-p" || args[startIndex] == "--path")
{
2024-06-25 17:29:32 -04:00
opts.DevicePath = args[startIndex + 1];
2024-06-25 16:48:24 -04:00
startIndex++;
}
// Scan for protection (requires device path)
else if (args[startIndex].Equals("-s") || args[startIndex].Equals("--scan"))
{
scan = true;
}
// Disable scanning archives (requires --scan)
else if (args[startIndex].Equals("--disable-archives"))
{
enableArchives = false;
}
// Enable debug protection information (requires --scan)
else if (args[startIndex].Equals("--enable-debug"))
{
enableDebug = true;
}
// Hide drive letters from scan output (requires --scan)
else if (args[startIndex].Equals("--hide-drive-letters"))
2024-06-25 16:48:24 -04:00
{
hideDriveLetters = true;
}
// Add filename suffix
else if (args[startIndex].Equals("-x") || args[startIndex].Equals("--suffix"))
{
options.AddFilenameSuffix = true;
2024-06-25 16:48:24 -04:00
}
// Output submission JSON
else if (args[startIndex].Equals("-j") || args[startIndex].Equals("--json"))
{
options.OutputSubmissionJSON = true;
2024-06-25 16:48:24 -04:00
}
2025-04-30 16:49:28 -04:00
// Include JSON artifacts
else if (args[startIndex].Equals("--include-artifacts"))
{
options.IncludeArtifacts = true;
}
2024-06-25 16:48:24 -04:00
// Compress log and extraneous files
else if (args[startIndex].Equals("-z") || args[startIndex].Equals("--zip"))
{
options.CompressLogFiles = true;
2024-06-25 16:48:24 -04:00
}
2025-04-30 16:49:28 -04:00
// Delete unnecessary files
2024-06-25 16:48:24 -04:00
else if (args[startIndex].Equals("-d") || args[startIndex].Equals("--delete"))
{
options.DeleteUnnecessaryFiles = true;
2024-06-25 16:48:24 -04:00
}
// Default, we fall out
else
{
break;
}
}
2024-06-25 16:48:24 -04:00
// Now deal with the complex options
options.ScanForProtection = scan && !string.IsNullOrEmpty(opts.DevicePath);
options.ScanArchivesForProtection = enableArchives && scan && !string.IsNullOrEmpty(opts.DevicePath);
options.IncludeDebugProtectionInformation = enableDebug && scan && !string.IsNullOrEmpty(opts.DevicePath);
options.HideDriveLetters = hideDriveLetters && scan && !string.IsNullOrEmpty(opts.DevicePath);
2024-06-25 17:29:32 -04:00
return opts;
2024-06-25 17:29:32 -04:00
}
/// <summary>
/// Represents commandline options
/// </summary>
2025-10-06 10:32:16 -04:00
internal class CommandOptions
2024-06-25 17:29:32 -04:00
{
/// <summary>
/// Seed submission info from an input file
/// </summary>
2024-06-25 17:29:32 -04:00
public SubmissionInfo? Seed { get; set; } = null;
2024-06-25 16:48:24 -04:00
/// <summary>
/// Path to the device to scan
/// </summary>
2024-06-25 17:29:32 -04:00
public string? DevicePath { get; set; } = null;
}
}
}