Allow info command to operate in directory
This commit is contained in:
+246
-82
@@ -7,6 +7,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Hashing;
|
using System.IO.Hashing;
|
||||||
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ namespace IRDKit
|
|||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IRD Creation Verb
|
/// IRD Creation command
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Verb("create", HelpText = "Create an IRD from an ISO")]
|
[Verb("create", HelpText = "Create an IRD from an ISO")]
|
||||||
public class CreateOptions
|
public class CreateOptions
|
||||||
@@ -23,10 +24,10 @@ namespace IRDKit
|
|||||||
[Value(0, Required = true, HelpText = "Path to an ISO file, or directory of ISO files")]
|
[Value(0, Required = true, HelpText = "Path to an ISO file, or directory of ISO files")]
|
||||||
public string ISOPath { get; set; }
|
public string ISOPath { get; set; }
|
||||||
|
|
||||||
[Value(1, Required = false, HelpText = "Path to the IRD file to be created")]
|
[Value(1, Required = false, HelpText = "Path to the IRD file to be created (will overwrite)")]
|
||||||
public string IRDPath { get; set; }
|
public string IRDPath { get; set; }
|
||||||
|
|
||||||
[Option('b', "layerbreak", HelpText = "Layerbreak value in bytes (define for BD-Video hybrid discs). Default: 12219392")]
|
[Option('b', "layerbreak", HelpText = "Layerbreak value in bytes (use with BD-Video hybrid discs). Default: 12219392")]
|
||||||
public long? Layerbreak { get; set; }
|
public long? Layerbreak { get; set; }
|
||||||
|
|
||||||
[Option('k', "key", HelpText = "Hexadecimal representation of the disc key")]
|
[Option('k', "key", HelpText = "Hexadecimal representation of the disc key")]
|
||||||
@@ -43,19 +44,22 @@ namespace IRDKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IRD or ISO information verb
|
/// IRD or ISO information command
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Verb("info", HelpText = "Print information from an IRD or ISO")]
|
[Verb("info", HelpText = "Print information from an IRD or ISO")]
|
||||||
public class InfoOptions
|
public class InfoOptions
|
||||||
{
|
{
|
||||||
[Value(0, Required = true, HelpText = "Path to the IRD or ISO file to be printed")]
|
[Value(0, Required = true, HelpText = "Path to an IRD or ISO file, or directory of IRD and/or ISO files")]
|
||||||
public string InPath { get; set; }
|
public string InPath { get; set; }
|
||||||
|
|
||||||
[Value(1, Required = false, HelpText = "Path to the text or json file to be created")]
|
[Value(1, Required = false, HelpText = "Path to the text or json file to be created (will overwrite)")]
|
||||||
public string OutPath { get; set; }
|
public string OutPath { get; set; }
|
||||||
|
|
||||||
[Option('j', "json", HelpText = "Print IRD or ISO information as a JSON object")]
|
[Option('j', "json", HelpText = "Print IRD or ISO information as a JSON object")]
|
||||||
public bool Json { get; set; }
|
public bool Json { get; set; }
|
||||||
|
|
||||||
|
[Option('r', "recurse", HelpText = "Recurse through all subdirectories and print information for all ISOs and IRDs")]
|
||||||
|
public bool Recurse { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -64,21 +68,24 @@ namespace IRDKit
|
|||||||
/// <param name="args">Command line arguments</param>
|
/// <param name="args">Command line arguments</param>
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
// Ensure console prints foreign characters properly
|
||||||
|
Console.OutputEncoding = Encoding.UTF8;
|
||||||
|
|
||||||
|
// Parse arguments
|
||||||
var result = Parser.Default.ParseArguments<CreateOptions, InfoOptions>(args).WithParsed(Run);
|
var result = Parser.Default.ParseArguments<CreateOptions, InfoOptions>(args).WithParsed(Run);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform
|
/// Parse arguments
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj"></param>
|
/// <param name="args">Command-line arguments</param>
|
||||||
/// <exception cref="FileNotFoundException"></exception>
|
/// <exception cref="ArgumentException"></exception>
|
||||||
/// <exception cref="InvalidFileSystemException"></exception>
|
private static void Run(object args)
|
||||||
private static void Run(object obj)
|
|
||||||
{
|
{
|
||||||
switch (obj)
|
switch (args)
|
||||||
{
|
{
|
||||||
|
// Process options from a `create` command
|
||||||
case CreateOptions opt:
|
case CreateOptions opt:
|
||||||
Console.OutputEncoding = Encoding.UTF8;
|
|
||||||
|
|
||||||
// Validate ISO path
|
// Validate ISO path
|
||||||
ArgumentNullException.ThrowIfNull(opt.ISOPath);
|
ArgumentNullException.ThrowIfNull(opt.ISOPath);
|
||||||
@@ -90,48 +97,207 @@ namespace IRDKit
|
|||||||
IEnumerable<string> isoFiles;
|
IEnumerable<string> isoFiles;
|
||||||
if (opt.Recurse)
|
if (opt.Recurse)
|
||||||
{
|
{
|
||||||
|
if (opt.ISOPath == ".")
|
||||||
|
Console.WriteLine($"Recursively searching for ISOs in current directory");
|
||||||
|
else
|
||||||
Console.WriteLine($"Recursively searching for ISOs in {opt.ISOPath}");
|
Console.WriteLine($"Recursively searching for ISOs in {opt.ISOPath}");
|
||||||
isoFiles = Directory.EnumerateFiles(opt.ISOPath, "*.iso", SearchOption.AllDirectories);
|
isoFiles = Directory.EnumerateFiles(opt.ISOPath, "*.iso", SearchOption.AllDirectories);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (opt.ISOPath == ".")
|
||||||
|
Console.WriteLine($"Searching for ISOs in current directory");
|
||||||
|
else
|
||||||
Console.WriteLine($"Searching for ISOs in {opt.ISOPath}");
|
Console.WriteLine($"Searching for ISOs in {opt.ISOPath}");
|
||||||
isoFiles = Directory.EnumerateFiles(opt.ISOPath, "*.iso", SearchOption.TopDirectoryOnly);
|
isoFiles = Directory.EnumerateFiles(opt.ISOPath, "*.iso", SearchOption.TopDirectoryOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Warn if no files are found
|
||||||
|
if (!isoFiles.Any())
|
||||||
|
Console.WriteLine("No ISOs found (ensure .iso extension)");
|
||||||
|
|
||||||
// Create an IRD file for all ISO files found
|
// Create an IRD file for all ISO files found
|
||||||
foreach (string file in isoFiles)
|
foreach (string file in isoFiles)
|
||||||
ProcessISO(opt, file);
|
ISO2IRD(file);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that given file exists
|
||||||
|
if (!File.Exists(opt.ISOPath)) throw new ArgumentException("Not a valid file or directory");
|
||||||
|
|
||||||
// Create a single IRD from an ISO
|
// Create a single IRD from an ISO
|
||||||
if (File.Exists(opt.ISOPath))
|
ISO2IRD(opt.ISOPath, opt.IRDPath, opt.Key, opt.KeyFile, opt.GetKeyLog, opt.Layerbreak);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Process options from an `info` command
|
||||||
|
case InfoOptions opt:
|
||||||
|
|
||||||
|
// Clear the output file path if it exists
|
||||||
|
File.Delete(opt.OutPath);
|
||||||
|
|
||||||
|
// If directory, search for all ISOs in current directory
|
||||||
|
if (Directory.Exists(opt.InPath))
|
||||||
{
|
{
|
||||||
ProcessISO(opt, opt.ISOPath, opt.IRDPath);
|
// If recurse option enabled, search recursively
|
||||||
|
IEnumerable<string> irdFiles;
|
||||||
|
IEnumerable<string> isoFiles;
|
||||||
|
if (opt.Recurse)
|
||||||
|
{
|
||||||
|
if (opt.InPath == ".")
|
||||||
|
Console.WriteLine($"Recursively searching for IRDs and ISOs in current directory");
|
||||||
|
else
|
||||||
|
Console.WriteLine($"Recursively searching for IRDs and ISOs in {opt.InPath}");
|
||||||
|
irdFiles = Directory.EnumerateFiles(opt.InPath, "*.ird", SearchOption.AllDirectories);
|
||||||
|
isoFiles = Directory.EnumerateFiles(opt.InPath, "*.iso", SearchOption.AllDirectories);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (opt.InPath == ".")
|
||||||
|
Console.WriteLine($"Searching for IRDs and ISOs in current directory");
|
||||||
|
else
|
||||||
|
Console.WriteLine($"Searching for IRDs and ISOs in {opt.InPath}");
|
||||||
|
irdFiles = Directory.EnumerateFiles(opt.InPath, "*.ird", SearchOption.TopDirectoryOnly);
|
||||||
|
isoFiles = Directory.EnumerateFiles(opt.InPath, "*.iso", SearchOption.TopDirectoryOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warn if no files are found
|
||||||
|
if (!isoFiles.Any() && !irdFiles.Any())
|
||||||
|
Console.WriteLine("No IRDs or ISOs found (ensure .ird and .iso extensions)");
|
||||||
|
|
||||||
|
// Open JSON object
|
||||||
|
if (opt.Json)
|
||||||
|
{
|
||||||
|
if (opt.OutPath != null)
|
||||||
|
File.AppendAllText(opt.OutPath, "{\n");
|
||||||
|
else
|
||||||
|
Console.WriteLine('{');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print info from all IRDs
|
||||||
|
foreach (string file in irdFiles)
|
||||||
|
{
|
||||||
|
PrintInfo(file, opt.Json, false, opt.OutPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print info from all ISOs
|
||||||
|
foreach (string file in isoFiles)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PrintISO(file, opt.Json);
|
||||||
|
}
|
||||||
|
catch (InvalidFileSystemException)
|
||||||
|
{
|
||||||
|
// Not a valid ISO file despite extension, assume file is an IRD
|
||||||
|
if (!opt.Json)
|
||||||
|
Console.WriteLine($"{file} is not a valid ISO file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close JSON object
|
||||||
|
if (opt.Json)
|
||||||
|
{
|
||||||
|
if (opt.OutPath != null)
|
||||||
|
File.AppendAllText(opt.OutPath, "}\n");
|
||||||
|
else
|
||||||
|
Console.WriteLine('}');
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ArgumentException("Not a valid ISO file or directory");
|
// Check that given file exists
|
||||||
|
if (!File.Exists(opt.InPath)) throw new ArgumentException("Not a valid file or directory");
|
||||||
|
|
||||||
case InfoOptions opt:
|
// Print info from given file
|
||||||
string filetype = Path.GetExtension(opt.InPath);
|
PrintInfo(opt.InPath, opt.Json, true, opt.OutPath);
|
||||||
|
|
||||||
if (String.Compare(filetype, ".iso", StringComparison.OrdinalIgnoreCase) == 0)
|
break;
|
||||||
|
|
||||||
|
// Unknown command
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prints info about a file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="inPath">File to retrieve info from</param>
|
||||||
|
/// <param name="json">Whether to format output as JSON (true) or plain text (false)</param>
|
||||||
|
/// <param name="outPath">File to output info to</param>
|
||||||
|
public static void PrintInfo(string inPath, bool json, bool single = true, string outPath = null)
|
||||||
|
{
|
||||||
|
// Check if file is an ISO
|
||||||
|
bool isISO = String.Compare(Path.GetExtension(inPath), ".iso", StringComparison.OrdinalIgnoreCase) == 0;
|
||||||
|
if (isISO)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PrintISO(inPath, json);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (InvalidFileSystemException)
|
||||||
|
{
|
||||||
|
// Not a valid ISO file despite extension, try open as IRD
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assume it is an IRD file
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (json)
|
||||||
|
{
|
||||||
|
if (outPath != null)
|
||||||
|
File.AppendAllText(outPath, $"\"{inPath}\": ");
|
||||||
|
else
|
||||||
|
Console.Write($"\"{inPath}\": ");
|
||||||
|
IRD.Read(inPath).PrintJson(outPath, single);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
IRD.Read(inPath).Print(outPath, inPath);
|
||||||
|
|
||||||
|
if (isISO)
|
||||||
|
Console.WriteLine($"{inPath} was a valid IRD despite .iso extension");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (InvalidDataException)
|
||||||
|
{
|
||||||
|
// Not a valid IRD file despite extension, give up
|
||||||
|
if (isISO)
|
||||||
|
Console.WriteLine($"{inPath} is not a valid ISO file");
|
||||||
|
else
|
||||||
|
Console.WriteLine($"{inPath} is not a valid IRD file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Print information about ISO file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="isoPath">Path to ISO file</param>
|
||||||
|
/// <param name="json">Whether to format output as JSON (true) or plain text (false)</param>
|
||||||
|
/// <param name="outPath">File to output info to</param>
|
||||||
|
/// <exception cref="FileNotFoundException"></exception>
|
||||||
|
/// <exception cref="InvalidFileSystemException"></exception>
|
||||||
|
public static void PrintISO(string isoPath, bool json, string outPath = null)
|
||||||
{
|
{
|
||||||
// Open ISO file for reading
|
// Open ISO file for reading
|
||||||
using FileStream fs = new FileStream(opt.InPath, FileMode.Open, FileAccess.Read) ?? throw new FileNotFoundException(opt.InPath);
|
using FileStream fs = new FileStream(isoPath, FileMode.Open, FileAccess.Read) ?? throw new FileNotFoundException(isoPath);
|
||||||
// Validate ISO file stream
|
// Validate ISO file stream
|
||||||
if (!CDReader.Detect(fs))
|
if (!CDReader.Detect(fs))
|
||||||
throw new InvalidFileSystemException("Not a valid ISO file");
|
throw new InvalidFileSystemException("Not a valid ISO file");
|
||||||
// Create new ISO reader
|
// Create new ISO reader
|
||||||
CDReader reader = new(fs, true, true);
|
using CDReader reader = new(fs, true, true);
|
||||||
|
|
||||||
if (opt.Json)
|
// Begin JSON object
|
||||||
|
if (json)
|
||||||
{
|
{
|
||||||
if (opt.OutPath != null)
|
if (outPath != null)
|
||||||
File.WriteAllText(opt.OutPath, "{\n");
|
File.AppendAllText(outPath, $"\"{isoPath}\": {{\n");
|
||||||
else
|
else
|
||||||
Console.WriteLine('{');
|
Console.WriteLine($"\"{isoPath}\": {{");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write PS3_DISC.SFB info
|
// Write PS3_DISC.SFB info
|
||||||
@@ -140,20 +306,20 @@ namespace IRDKit
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
PS3_DiscSFB ps3_DiscSFB = new(s);
|
PS3_DiscSFB ps3_DiscSFB = new(s);
|
||||||
if (opt.Json)
|
if (json)
|
||||||
{
|
{
|
||||||
if (opt.OutPath != null)
|
if (outPath != null)
|
||||||
File.AppendAllText(opt.OutPath, "\"PS3_DISC.SFB\": ");
|
File.AppendAllText(outPath, "\"PS3_DISC.SFB\": ");
|
||||||
else
|
else
|
||||||
Console.Write("\"PS3_DISC.SFB\": ");
|
Console.Write("\"PS3_DISC.SFB\": ");
|
||||||
ps3_DiscSFB.PrintJson(opt.OutPath);
|
ps3_DiscSFB.PrintJson(outPath);
|
||||||
if (opt.OutPath != null)
|
if (outPath != null)
|
||||||
File.AppendAllText(opt.OutPath, ",\n");
|
File.AppendAllText(outPath, ",\n");
|
||||||
else
|
else
|
||||||
Console.WriteLine(',');
|
Console.WriteLine(',');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ps3_DiscSFB.Print(opt.OutPath);
|
ps3_DiscSFB.Print(outPath);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -167,16 +333,16 @@ namespace IRDKit
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
ParamSFO paramSFO = new(s);
|
ParamSFO paramSFO = new(s);
|
||||||
if (opt.Json)
|
if (json)
|
||||||
{
|
{
|
||||||
if (opt.OutPath != null)
|
if (outPath != null)
|
||||||
File.AppendAllText(opt.OutPath, "\"PARAM.SFO\": ");
|
File.AppendAllText(outPath, "\"PARAM.SFO\": ");
|
||||||
else
|
else
|
||||||
Console.Write("\"PARAM.SFO\": ");
|
Console.Write("\"PARAM.SFO\": ");
|
||||||
paramSFO.PrintJson(opt.OutPath);
|
paramSFO.PrintJson(outPath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
paramSFO.Print(opt.OutPath);
|
paramSFO.Print(outPath);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -184,28 +350,26 @@ namespace IRDKit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt.Json)
|
// End JSON object
|
||||||
|
if (json)
|
||||||
{
|
{
|
||||||
if (opt.OutPath != null)
|
if (outPath != null)
|
||||||
File.AppendAllText(opt.OutPath, "\n}\n");
|
File.AppendAllText(outPath, "\n},\n");
|
||||||
else
|
else
|
||||||
Console.WriteLine("\n}");
|
Console.WriteLine("\n},");
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Assume it is an IRD file
|
|
||||||
if (opt.Json)
|
|
||||||
IRD.Read(opt.InPath).PrintJson(opt.OutPath);
|
|
||||||
else
|
|
||||||
IRD.Read(opt.InPath).Print(opt.OutPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ProcessISO(CreateOptions opt, string isoPath, string irdPath = null)
|
/// <summary>
|
||||||
|
/// Creates an IRD file from an ISO file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="isoPath">Path to an ISO file</param>
|
||||||
|
/// <param name="irdPath">Path to IRD file to be created (optional)</param>
|
||||||
|
/// <param name="hexKey">Hex string disc key</param>
|
||||||
|
/// <param name="keyPath">Disc key file (overridden by hex string if present)</param>
|
||||||
|
/// <param name="getKeyLog">GetKey log file (overridden by disc key or key file if present)</param>
|
||||||
|
/// <param name="layerbreak">Layerbreak value of disc</param>
|
||||||
|
public static void ISO2IRD(string isoPath, string irdPath = null, string hexKey = null, string keyPath = null, string getKeyLog = null, long? layerbreak = null)
|
||||||
{
|
{
|
||||||
// Check file exists
|
// Check file exists
|
||||||
FileInfo iso = new(isoPath);
|
FileInfo iso = new(isoPath);
|
||||||
@@ -215,28 +379,28 @@ namespace IRDKit
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determin IRD path if none given
|
// Determine IRD path if none given
|
||||||
irdPath ??= Path.GetFileNameWithoutExtension(isoPath) + ".ird";
|
irdPath ??= Path.ChangeExtension(isoPath, ".ird");
|
||||||
|
|
||||||
// Create new reproducible redump-style IRD with a given hex key
|
// Create new reproducible redump-style IRD with a given hex key
|
||||||
if (opt.Key != null)
|
if (hexKey != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Get disc key from hex string
|
// Get disc key from hex string
|
||||||
byte[] discKey = Convert.FromHexString(opt.Key);
|
byte[] discKey = Convert.FromHexString(hexKey);
|
||||||
if (discKey == null || discKey.Length != 16)
|
if (discKey == null || discKey.Length != 16)
|
||||||
throw new ArgumentException(opt.Key);
|
throw new ArgumentException(hexKey);
|
||||||
|
|
||||||
Console.WriteLine($"Creating {irdPath} with Key: {opt.Key}");
|
Console.WriteLine($"Creating {irdPath} with Key: {hexKey}");
|
||||||
IRD ird1 = new ReIRD(isoPath, discKey, opt.Layerbreak);
|
IRD ird1 = new ReIRD(isoPath, discKey, layerbreak);
|
||||||
ird1.Write(irdPath);
|
ird1.Write(irdPath);
|
||||||
ird1.Print();
|
ird1.Print();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine("Given key not valid, detecting key automatically...");
|
Console.Error.WriteLine("Given key not valid, detecting key automatically");
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException)
|
catch (FileNotFoundException)
|
||||||
{
|
{
|
||||||
@@ -246,25 +410,25 @@ namespace IRDKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create new reproducible redump-style IRD with a given key file
|
// Create new reproducible redump-style IRD with a given key file
|
||||||
if (opt.KeyFile != null)
|
if (keyPath != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Read key from .key file
|
// Read key from .key file
|
||||||
byte[] discKey = File.ReadAllBytes(opt.KeyFile);
|
byte[] discKey = File.ReadAllBytes(keyPath);
|
||||||
if (discKey == null || discKey.Length != 16)
|
if (discKey == null || discKey.Length != 16)
|
||||||
throw new ArgumentException(opt.KeyFile);
|
throw new ArgumentException(keyPath);
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine($"Creating {irdPath} with Key: {Convert.ToHexString(discKey)}");
|
Console.WriteLine($"Creating {irdPath} with Key: {Convert.ToHexString(discKey)}");
|
||||||
IRD ird2 = new ReIRD(isoPath, discKey, opt.Layerbreak);
|
IRD ird2 = new ReIRD(isoPath, discKey, layerbreak);
|
||||||
ird2.Write(irdPath);
|
ird2.Write(irdPath);
|
||||||
ird2.Print();
|
ird2.Print();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine("Given key file not valid, detecting key automatically...");
|
Console.Error.WriteLine("Given key file not valid, detecting key automatically");
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException)
|
catch (FileNotFoundException)
|
||||||
{
|
{
|
||||||
@@ -274,12 +438,12 @@ namespace IRDKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create new reproducible redump-style IRD with a given GetKey log
|
// Create new reproducible redump-style IRD with a given GetKey log
|
||||||
if (opt.GetKeyLog != null)
|
if (getKeyLog != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Creating {irdPath} with key from: {opt.GetKeyLog}");
|
Console.WriteLine($"Creating {irdPath} with key from: {getKeyLog}");
|
||||||
IRD ird3 = new ReIRD(isoPath, opt.GetKeyLog);
|
IRD ird3 = new ReIRD(isoPath, getKeyLog);
|
||||||
ird3.Write(irdPath);
|
ird3.Write(irdPath);
|
||||||
ird3.Print();
|
ird3.Print();
|
||||||
return;
|
return;
|
||||||
@@ -292,9 +456,9 @@ namespace IRDKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No key provided, try search for .key file
|
// No key provided, try search for .key file
|
||||||
string keyfilePath = Path.GetFileNameWithoutExtension(isoPath) + ".key";
|
string keyfilePath = Path.ChangeExtension(isoPath, ".key");
|
||||||
FileInfo keyfile = new(keyfilePath);
|
FileInfo keyFile = new(keyfilePath);
|
||||||
if (keyfile.Exists)
|
if (keyFile.Exists)
|
||||||
{
|
{
|
||||||
// Found .key file, try use it
|
// Found .key file, try use it
|
||||||
try
|
try
|
||||||
@@ -302,17 +466,17 @@ namespace IRDKit
|
|||||||
// Read key from .key file
|
// Read key from .key file
|
||||||
byte[] discKey = File.ReadAllBytes(keyfilePath);
|
byte[] discKey = File.ReadAllBytes(keyfilePath);
|
||||||
if (discKey == null || discKey.Length != 16)
|
if (discKey == null || discKey.Length != 16)
|
||||||
throw new ArgumentException(opt.KeyFile);
|
throw new ArgumentException(keyfilePath);
|
||||||
|
|
||||||
Console.WriteLine($"Creating {irdPath} with Key: {Convert.ToHexString(discKey)}");
|
Console.WriteLine($"Creating {irdPath} with Key: {Convert.ToHexString(discKey)}");
|
||||||
IRD ird2 = new ReIRD(isoPath, discKey, opt.Layerbreak);
|
IRD ird2 = new ReIRD(isoPath, discKey, layerbreak);
|
||||||
ird2.Write(irdPath);
|
ird2.Write(irdPath);
|
||||||
ird2.Print();
|
ird2.Print();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine("Given key file not valid, detecting key automatically...");
|
Console.Error.WriteLine("Given key file not valid, detecting key automatically");
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException)
|
catch (FileNotFoundException)
|
||||||
{
|
{
|
||||||
@@ -322,7 +486,7 @@ namespace IRDKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No key provided, try search for .getkey.log file
|
// No key provided, try search for .getkey.log file
|
||||||
string logfilePath = Path.GetFileNameWithoutExtension(isoPath) + ".getkey.log";
|
string logfilePath = Path.ChangeExtension(isoPath, ".getkey.log");
|
||||||
FileInfo logfile = new(logfilePath);
|
FileInfo logfile = new(logfilePath);
|
||||||
if (logfile.Exists)
|
if (logfile.Exists)
|
||||||
{
|
{
|
||||||
@@ -343,7 +507,7 @@ namespace IRDKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No key provided, try get key from redump.org
|
// No key provided, try get key from redump.org
|
||||||
Console.WriteLine("No key provided... Searching for key on redump.org...");
|
Console.WriteLine("No key provided... Searching for key on redump.org");
|
||||||
|
|
||||||
// Compute CRC32 hash
|
// Compute CRC32 hash
|
||||||
byte[] crc32;
|
byte[] crc32;
|
||||||
@@ -363,7 +527,7 @@ namespace IRDKit
|
|||||||
int id;
|
int id;
|
||||||
if (ids.Count == 0)
|
if (ids.Count == 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine("ISO not found in redump, cannot automatically retreive key.");
|
Console.WriteLine("ISO not found in redump, cannot automatically retreive key");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (ids.Count > 1)
|
else if (ids.Count > 1)
|
||||||
@@ -381,7 +545,7 @@ namespace IRDKit
|
|||||||
List<int> ids2 = redump.CheckSingleSitePage("http://redump.org/discs/system/ps3/quicksearch/" + sha1_hash).ConfigureAwait(false).GetAwaiter().GetResult();
|
List<int> ids2 = redump.CheckSingleSitePage("http://redump.org/discs/system/ps3/quicksearch/" + sha1_hash).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||||
if (ids2.Count == 0)
|
if (ids2.Count == 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine("ISO not found in redump, cannot automatically retreive key.");
|
Console.WriteLine("ISO not found in redump, cannot automatically retreive key");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (ids2.Count > 1)
|
else if (ids2.Count > 1)
|
||||||
@@ -405,7 +569,7 @@ namespace IRDKit
|
|||||||
|
|
||||||
// Create IRD with key from redump
|
// Create IRD with key from redump
|
||||||
Console.WriteLine($"Creating {irdPath} with Key: {Convert.ToHexString(key)}");
|
Console.WriteLine($"Creating {irdPath} with Key: {Convert.ToHexString(key)}");
|
||||||
IRD ird = new ReIRD(isoPath, key, opt.Layerbreak);
|
IRD ird = new ReIRD(isoPath, key, layerbreak);
|
||||||
ird.Write(irdPath);
|
ird.Write(irdPath);
|
||||||
ird.Print();
|
ird.Print();
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-4
@@ -6,7 +6,6 @@ using System.IO.Compression;
|
|||||||
using System.IO.Hashing;
|
using System.IO.Hashing;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace LibIRD
|
namespace LibIRD
|
||||||
{
|
{
|
||||||
@@ -1267,11 +1266,14 @@ namespace LibIRD
|
|||||||
/// Prints IRD fields to console
|
/// Prints IRD fields to console
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="printPath">Optional path to save file to</param>
|
/// <param name="printPath">Optional path to save file to</param>
|
||||||
public void Print(string printPath = null)
|
public void Print(string printPath = null, string irdName = null)
|
||||||
{
|
{
|
||||||
// Build string from parameters
|
// Build string from parameters
|
||||||
StringBuilder printText = new();
|
StringBuilder printText = new();
|
||||||
|
if (irdName == null)
|
||||||
printText.AppendLine("IRD Contents:");
|
printText.AppendLine("IRD Contents:");
|
||||||
|
else
|
||||||
|
printText.AppendLine($"IRD Contents: {irdName}");
|
||||||
printText.AppendLine("=============");
|
printText.AppendLine("=============");
|
||||||
|
|
||||||
// Append IRD fields to string builder
|
// Append IRD fields to string builder
|
||||||
@@ -1304,7 +1306,7 @@ namespace LibIRD
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
File.WriteAllText(printPath, printText.ToString());
|
File.AppendAllText(printPath, printText.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1313,7 +1315,7 @@ namespace LibIRD
|
|||||||
/// Prints IRD fields to a json object
|
/// Prints IRD fields to a json object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jsonPath">Optionally print to json file</param>
|
/// <param name="jsonPath">Optionally print to json file</param>
|
||||||
public void PrintJson(string jsonPath = null)
|
public void PrintJson(string jsonPath = null, bool single = true)
|
||||||
{
|
{
|
||||||
// Build string from parameters
|
// Build string from parameters
|
||||||
StringBuilder json = new();
|
StringBuilder json = new();
|
||||||
@@ -1337,7 +1339,10 @@ namespace LibIRD
|
|||||||
json.AppendLine($" \"Data 1 Key\": \"{Convert.ToHexString(Data1Key)}\",");
|
json.AppendLine($" \"Data 1 Key\": \"{Convert.ToHexString(Data1Key)}\",");
|
||||||
json.AppendLine($" \"Data 2 Key\": \"{Convert.ToHexString(Data2Key)}\",");
|
json.AppendLine($" \"Data 2 Key\": \"{Convert.ToHexString(Data2Key)}\",");
|
||||||
json.AppendLine($" \"PIC\": \"{Convert.ToHexString(PIC)}\"");
|
json.AppendLine($" \"PIC\": \"{Convert.ToHexString(PIC)}\"");
|
||||||
|
if (single)
|
||||||
json.AppendLine("}");
|
json.AppendLine("}");
|
||||||
|
else
|
||||||
|
json.AppendLine("},");
|
||||||
|
|
||||||
// If no path given, output to console
|
// If no path given, output to console
|
||||||
if (jsonPath == null)
|
if (jsonPath == null)
|
||||||
|
|||||||
Reference in New Issue
Block a user