Add project files.

This commit is contained in:
Syping 2025-10-23 18:16:31 +02:00
parent ff98edeb4e
commit 41861a6fe7
3 changed files with 122 additions and 0 deletions

79
Program.cs Normal file
View file

@ -0,0 +1,79 @@
using RagePhoto;
using System.CommandLine;
using System.Text;
internal static class Program {
private static void Main(String[] args) {
Argument<FileInfo> photoArgument = new("photo") {
Description = "Photo File"
};
Argument<String> dataTypeArgument = new("dataType") {
Description = "Data Type",
DefaultValueFactory = _ => "jpeg"
};
Option<String> outputOption = new("output", "o") {
Description = "Output",
DefaultValueFactory = _ => "-"
};
Command getCommand = new("get", "Get Photo Data") {
photoArgument, dataTypeArgument, outputOption
};
getCommand.SetAction(result => Get(
result.GetRequiredValue(photoArgument),
result.GetRequiredValue(dataTypeArgument),
result.GetRequiredValue(outputOption)));
RootCommand rootCommand = new("ragephoto-cli Application") {
getCommand
};
rootCommand.Parse(args).Invoke();
}
private static void Get(FileInfo photoFile, String dataType, String outputFile) {
try {
using Photo photo = new();
photo.LoadFile(photoFile.FullName);
Byte[] content = [];
switch (dataType.ToLowerInvariant()) {
case "format":
content = Encoding.UTF8.GetBytes(photo.Format switch {
PhotoFormat.GTA5 => "gta5",
PhotoFormat.RDR2 => "rdr2",
_ => "unknown"
});
break;
case "jpeg":
content = photo.Jpeg;
break;
case "json":
content = Encoding.UTF8.GetBytes(photo.Json);
break;
case "sign":
content = Encoding.UTF8.GetBytes($"{photo.Sign}");
break;
case "title":
content = Encoding.UTF8.GetBytes(photo.Title);
break;
default:
Console.Error.WriteLine($"Unknown Content Type: {dataType}");
Environment.Exit(1);
break;
}
Stream output = outputFile == "-" ? Console.OpenStandardOutput() : File.Create(outputFile);
output.Write(content);
}
catch (RagePhotoException exception) {
Console.Error.WriteLine(exception.Message);
Environment.Exit(exception.Photo != null ? (Int32)exception.Error + 2 : -1);
}
catch (Exception exception) {
Console.Error.WriteLine(exception.Message);
Environment.Exit(-1);
}
}
}

18
RagePhotoCli.csproj Normal file
View file

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>ragephoto-cli</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RagePhoto.Core" Version="0.7.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-rc.2.25502.107" />
</ItemGroup>
</Project>

25
RagePhotoCli.sln Normal file
View file

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36616.10 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RagePhotoCli", "RagePhotoCli.csproj", "{E8CD6776-793E-4E73-A60F-DF86E35EDF6B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E8CD6776-793E-4E73-A60F-DF86E35EDF6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8CD6776-793E-4E73-A60F-DF86E35EDF6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8CD6776-793E-4E73-A60F-DF86E35EDF6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8CD6776-793E-4E73-A60F-DF86E35EDF6B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D4BCEAF1-891B-4F6E-8AF9-F0859564C205}
EndGlobalSection
EndGlobal