From 41861a6fe7d5f14aa7f5911d70f19d662b1434ee Mon Sep 17 00:00:00 2001 From: Syping Date: Thu, 23 Oct 2025 18:16:31 +0200 Subject: [PATCH] Add project files. --- Program.cs | 79 +++++++++++++++++++++++++++++++++++++++++++++ RagePhotoCli.csproj | 18 +++++++++++ RagePhotoCli.sln | 25 ++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 Program.cs create mode 100644 RagePhotoCli.csproj create mode 100644 RagePhotoCli.sln diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..a677986 --- /dev/null +++ b/Program.cs @@ -0,0 +1,79 @@ +using RagePhoto; +using System.CommandLine; +using System.Text; + +internal static class Program { + + private static void Main(String[] args) { + + Argument photoArgument = new("photo") { + Description = "Photo File" + }; + Argument dataTypeArgument = new("dataType") { + Description = "Data Type", + DefaultValueFactory = _ => "jpeg" + }; + Option 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); + } + } +} diff --git a/RagePhotoCli.csproj b/RagePhotoCli.csproj new file mode 100644 index 0000000..545a6ce --- /dev/null +++ b/RagePhotoCli.csproj @@ -0,0 +1,18 @@ + + + + Exe + net8.0 + ragephoto-cli + enable + enable + true + true + + + + + + + + diff --git a/RagePhotoCli.sln b/RagePhotoCli.sln new file mode 100644 index 0000000..8987bd9 --- /dev/null +++ b/RagePhotoCli.sln @@ -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