2019-02-10 14:47:53 -08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
2020-08-07 21:15:36 -07:00
|
|
|
|
using BurnOutSharp;
|
2019-02-10 14:47:53 -08:00
|
|
|
|
using DICUI.Data;
|
|
|
|
|
|
using DICUI.Utilities;
|
2020-06-16 11:16:39 -07:00
|
|
|
|
using DICUI.Web;
|
2019-02-10 14:47:53 -08:00
|
|
|
|
|
|
|
|
|
|
namespace DICUI.Check
|
|
|
|
|
|
{
|
|
|
|
|
|
public class Program
|
|
|
|
|
|
{
|
|
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
|
{
|
2019-04-04 00:37:17 -07:00
|
|
|
|
// Help options
|
2020-05-07 14:23:49 -07:00
|
|
|
|
if (args.Length == 0 || args[0] == "-h" || args[0] == "-?")
|
2019-02-10 14:47:53 -08:00
|
|
|
|
{
|
2019-04-04 00:37:17 -07:00
|
|
|
|
DisplayHelp();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// List options
|
2020-05-07 14:23:49 -07:00
|
|
|
|
if (args[0] == "-lm" || args[0] == "--listmedia")
|
2019-04-04 00:37:17 -07:00
|
|
|
|
{
|
|
|
|
|
|
ListMediaTypes();
|
|
|
|
|
|
Console.ReadLine();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-05-07 14:23:49 -07:00
|
|
|
|
else if (args[0] == "-lp" || args[0] == "--listprograms")
|
2020-05-07 13:56:21 -07:00
|
|
|
|
{
|
|
|
|
|
|
ListPrograms();
|
|
|
|
|
|
Console.ReadLine();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-05-07 14:23:49 -07:00
|
|
|
|
else if (args[0] == "-ls" || args[0] == "--listsystems")
|
2019-04-04 00:37:17 -07:00
|
|
|
|
{
|
|
|
|
|
|
ListKnownSystems();
|
|
|
|
|
|
Console.ReadLine();
|
2019-02-10 14:47:53 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-04 00:37:17 -07:00
|
|
|
|
// Normal operation check
|
|
|
|
|
|
if (args.Length < 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
DisplayHelp("Invalid number of arguments");
|
|
|
|
|
|
return;
|
2020-04-13 11:55:21 -07:00
|
|
|
|
}
|
2019-04-04 00:37:17 -07:00
|
|
|
|
|
|
|
|
|
|
// Check the MediaType
|
2020-04-13 11:55:21 -07:00
|
|
|
|
var mediaType = Converters.ToMediaType(args[0].Trim('"'));
|
2019-04-04 00:37:17 -07:00
|
|
|
|
if (mediaType == MediaType.NONE)
|
2019-02-10 14:47:53 -08:00
|
|
|
|
{
|
|
|
|
|
|
DisplayHelp($"{args[0]} is not a recognized media type");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-04 00:37:17 -07:00
|
|
|
|
// Check the KnownSystem
|
2020-04-13 11:55:21 -07:00
|
|
|
|
var knownSystem = Converters.ToKnownSystem(args[1].Trim('"'));
|
2019-04-04 00:37:17 -07:00
|
|
|
|
if (knownSystem == KnownSystem.NONE)
|
|
|
|
|
|
{
|
|
|
|
|
|
DisplayHelp($"{args[1]} is not a recognized system");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-07 21:15:36 -07:00
|
|
|
|
// Default values
|
2019-05-14 01:46:10 -07:00
|
|
|
|
string username = null, password = null;
|
2020-04-13 11:55:21 -07:00
|
|
|
|
string internalProgram = "DiscImageCreator";
|
2020-08-07 21:15:36 -07:00
|
|
|
|
string path = string.Empty;
|
|
|
|
|
|
bool scan = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Loop through and process options
|
2019-05-14 01:46:10 -07:00
|
|
|
|
int startIndex = 2;
|
2020-02-06 23:54:49 -08:00
|
|
|
|
for (; startIndex < args.Length; startIndex++)
|
2019-05-14 01:46:10 -07:00
|
|
|
|
{
|
2020-02-06 23:54:49 -08:00
|
|
|
|
// Redump login
|
2020-05-07 14:23:49 -07:00
|
|
|
|
if (args[startIndex].StartsWith("-c=") || args[startIndex].StartsWith("--credentials="))
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] credentials = args[startIndex].Split('=')[1].Split(';');
|
|
|
|
|
|
username = credentials[0];
|
|
|
|
|
|
password = credentials[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (args[startIndex] == "-c" || args[startIndex] == "--credentials")
|
2020-02-06 23:54:49 -08:00
|
|
|
|
{
|
|
|
|
|
|
username = args[startIndex + 1];
|
|
|
|
|
|
password = args[startIndex + 2];
|
|
|
|
|
|
startIndex += 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-13 11:55:21 -07:00
|
|
|
|
// Use specific program
|
|
|
|
|
|
else if (args[startIndex].StartsWith("-u=") || args[startIndex].StartsWith("--use="))
|
2020-02-06 23:54:49 -08:00
|
|
|
|
{
|
2020-04-13 11:55:21 -07:00
|
|
|
|
internalProgram = args[startIndex].Split('=')[1];
|
2020-02-06 23:54:49 -08:00
|
|
|
|
}
|
2020-05-07 14:23:49 -07:00
|
|
|
|
else if (args[startIndex] == "-u" || args[startIndex] == "--use")
|
|
|
|
|
|
{
|
|
|
|
|
|
internalProgram = args[startIndex + 1];
|
|
|
|
|
|
startIndex++;
|
|
|
|
|
|
}
|
2020-02-06 23:54:49 -08:00
|
|
|
|
|
2020-08-07 21:15:36 -07:00
|
|
|
|
// Use a device path for physical checks
|
|
|
|
|
|
else if (args[startIndex].StartsWith("-p=") || args[startIndex].StartsWith("--path="))
|
|
|
|
|
|
{
|
|
|
|
|
|
path = args[startIndex].Split('=')[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (args[startIndex] == "-p" || args[startIndex] == "--path")
|
|
|
|
|
|
{
|
|
|
|
|
|
path = args[startIndex + 1];
|
|
|
|
|
|
startIndex++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Scan for protection (requires device path)
|
|
|
|
|
|
else if (args[startIndex].StartsWith("-s") || args[startIndex].StartsWith("--scan"))
|
|
|
|
|
|
{
|
|
|
|
|
|
scan = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-06 23:54:49 -08:00
|
|
|
|
// Default, we fall out
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
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;
|
|
|
|
|
|
var protectionProgress = new Progress<FileProtection>();
|
|
|
|
|
|
protectionProgress.ProgressChanged += ProgressUpdated;
|
2019-02-10 14:47:53 -08:00
|
|
|
|
|
2020-06-16 11:16:39 -07:00
|
|
|
|
// If credentials are invalid, alert the user
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
|
|
|
|
|
|
{
|
2020-07-22 21:11:40 -07:00
|
|
|
|
using (RedumpWebClient wc = new RedumpWebClient())
|
2020-06-16 11:16:39 -07:00
|
|
|
|
{
|
2020-07-22 21:11:40 -07:00
|
|
|
|
if (wc.Login(username, password))
|
2020-06-16 11:16:39 -07:00
|
|
|
|
Console.WriteLine("Redump username and password accepted!");
|
|
|
|
|
|
else
|
|
|
|
|
|
Console.WriteLine("Redump username and password denied!");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-05-06 15:44:46 -07:00
|
|
|
|
// TODO: Replace this with Dictionary constructor
|
2020-05-06 14:24:37 -07:00
|
|
|
|
var options = new Options
|
2019-02-10 14:47:53 -08:00
|
|
|
|
{
|
2020-05-06 14:24:37 -07:00
|
|
|
|
InternalProgram = internalProgram,
|
2020-08-07 21:15:36 -07:00
|
|
|
|
ScanForProtection = scan && !string.IsNullOrWhiteSpace(path),
|
2019-09-17 20:50:44 -07:00
|
|
|
|
PromptForDiscInformation = false,
|
2019-05-14 01:46:10 -07:00
|
|
|
|
|
|
|
|
|
|
Username = username,
|
|
|
|
|
|
Password = password,
|
2019-02-10 14:47:53 -08:00
|
|
|
|
};
|
2020-05-06 14:24:37 -07:00
|
|
|
|
|
2020-08-07 21:15:36 -07:00
|
|
|
|
Drive drive = null;
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(path))
|
|
|
|
|
|
drive = new Drive(null, new DriveInfo(path));
|
|
|
|
|
|
|
|
|
|
|
|
var env = new DumpEnvironment(options, "", filepath, drive, knownSystem, mediaType, null);
|
2019-02-10 14:47:53 -08:00
|
|
|
|
env.FixOutputPaths();
|
|
|
|
|
|
|
|
|
|
|
|
// 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>
|
|
|
|
|
|
/// Display help for DICUI.Check
|
|
|
|
|
|
/// </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:");
|
2020-02-06 23:54:49 -08:00
|
|
|
|
Console.WriteLine("DICUI.Check.exe <mediatype> <system> [options] </path/to/output.bin> ...");
|
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();
|
2020-08-07 21:15:36 -07:00
|
|
|
|
Console.WriteLine("Check Options:");
|
|
|
|
|
|
Console.WriteLine("-c, --credentials <user> <pw> Redump username and password");
|
|
|
|
|
|
Console.WriteLine("-u, --use <program> Dumping program output type");
|
|
|
|
|
|
Console.WriteLine("-p, --path <drivepath> Physical drive path for additional checks");
|
|
|
|
|
|
Console.WriteLine("-s, --scan Enable copy protection scan (requires --path)");
|
2020-05-07 13:56:21 -07:00
|
|
|
|
Console.WriteLine();
|
2019-02-10 14:47:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-04 00:37:17 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// List all media types with their short usable names
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static void ListMediaTypes()
|
2019-02-10 14:47:53 -08:00
|
|
|
|
{
|
2019-04-04 00:37:17 -07:00
|
|
|
|
Console.WriteLine("Supported Media Types:");
|
|
|
|
|
|
foreach (var val in Enum.GetValues(typeof(MediaType)))
|
2019-02-10 14:47:53 -08:00
|
|
|
|
{
|
2019-04-04 00:37:17 -07:00
|
|
|
|
if (((MediaType)val) == MediaType.NONE)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2019-05-20 22:14:53 -07:00
|
|
|
|
Console.WriteLine($"{((MediaType?)val).ShortName()} - {((MediaType?)val).LongName()}");
|
2019-04-04 00:37:17 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-07 13:56:21 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// List all programs with their short usable names
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static void ListPrograms()
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("Supported Programs:");
|
|
|
|
|
|
foreach (var val in Enum.GetValues(typeof(InternalProgram)))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (((InternalProgram)val) == InternalProgram.NONE)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"{((InternalProgram?)val).LongName()}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-04 00:37:17 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// List all known systems with their short usable names
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static void ListKnownSystems()
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("Supported Known Systems:");
|
|
|
|
|
|
foreach (var val in Enum.GetValues(typeof(KnownSystem)))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (((KnownSystem)val) == KnownSystem.NONE)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2019-05-20 22:14:53 -07:00
|
|
|
|
Console.WriteLine($"{((KnownSystem?)val).ShortName()} - {((KnownSystem?)val).LongName()}");
|
2019-02-10 14:47:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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>
|
|
|
|
|
|
private static void ProgressUpdated(object sender, FileProtection value)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine($"{value.Percentage * 100:N2}%: {value.Filename} - {value.Protection}");
|
|
|
|
|
|
}
|
2019-02-10 14:47:53 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|