Start work on CLI tool

This commit is contained in:
Deterous
2023-11-16 11:45:21 +13:00
parent b794ec8f96
commit e665391e47
11 changed files with 217 additions and 100 deletions
+33
View File
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Assembly Properties -->
<OutputType>Exe</OutputType>
<PackAsTool>true</PackAsTool>
<ToolCommandName>irdkit</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
<Version>0.1.0</Version>
<!-- Package Properties -->
<Authors>Deterous</Authors>
<Description>Library for ISO Rebuild Data</Description>
<Copyright>Copyright (c) 2023 Deterous</Copyright>
<!--<PackageReadmeFile>README.md</PackageReadmeFile>-->
<RepositoryUrl>https://github.com/Deterous/LibIRD</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>ps3 iso ird redump</PackageTags>
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
</PropertyGroup>
<ItemGroup>
<None Include="./README.md" Pack="true" PackagePath=""/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibIRD\LibIRD.csproj" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
</ItemGroup>
</Project>
+113
View File
@@ -0,0 +1,113 @@
using LibIRD;
using System;
using System.Collections.Generic;
using CommandLine;
using System.Text;
using System.IO;
namespace IRDKit
{
internal class Program
{
// IRD Creation
[Verb("create")]
public class CreateOptions
{
[Value(0, Required = true, HelpText = "Path to an ISO file, or directory of ISO files")]
public string ISOPath { get; set; }
[Value(1, HelpText = "Path to the IRD file to be created")]
public string IRDPath { get; set; }
[Option('r', "recurse", HelpText = "Recurse through all subdirectories and generate IRDs for all ISOs")]
public bool Recurse { get; set; }
[Option('k', "key", HelpText = "Hexadecimal representation of the disc key")]
public string Key { get; set; }
[Option("key-file", HelpText = "Path to a redump .key file")]
public string KeyFile { get; set; }
[Option('l', "getkey-log", HelpText = "Path to a .getkey.log file")]
public string GetKeyLog { get; set; }
}
// IRD Info
public class InfoOptions
{
[Value(0, Required = true, HelpText = "Path to the IRD file to be printed")]
public string IRDPath { get; set; }
}
public static void Main(string[] args)
{
// Parse command line arguments
var result = Parser.Default.ParseArguments<CreateOptions, InfoOptions>(args)
.WithParsed(Run)
.WithNotParsed(HandleParseError);
}
private static void HandleParseError(IEnumerable<Error> errs)
{
if (errs.IsVersion())
{
// --version
}
else if (errs.IsHelp())
{
// --help
}
else
{
// Parsing error
}
return;
}
private static void Run(object obj)
{
switch (obj)
{
case CreateOptions c:
Console.OutputEncoding = Encoding.UTF8;
// Create new reproducible redump-style IRD with a key file
if (c.KeyFile != null)
{
try
{
// Read key from .key file
byte[] discKey = File.ReadAllBytes(c.KeyFile);
IRD ird1 = new ReIRD(c.ISOPath, discKey);
ird1.Write(c.IRDPath);
ird1.Print();
}
catch (FileNotFoundException)
{
Console.WriteLine("ERROR: File not found");
}
}
// Create new reproducible redump-style IRD with a GetKey log
if (c.GetKeyLog != null)
{
try
{
IRD ird2 = new ReIRD(c.ISOPath, c.GetKeyLog);
ird2.Write(c.IRDPath);
ird2.Print();
}
catch (FileNotFoundException)
{
Console.WriteLine("ERROR: File not found");
}
}
break;
case InfoOptions info:
//
break;
}
}
}
}
+7
View File
@@ -0,0 +1,7 @@
## How to use IRDKit
IRDKit is a tool that allows direct use of LibIRD functionality from the command line interface. The basic usage is:
```
irdkit game.iso game.ird
```
For detailed usage, run `irdkit --help`