add support for description and ability to delete jpeg

This commit is contained in:
Syping 2025-10-24 15:29:09 +02:00
parent 00b4ba8c89
commit 89b86c6407
3 changed files with 23 additions and 10 deletions

View file

@ -18,6 +18,9 @@ internal static class Program {
Byte[] content = []; Byte[] content = [];
switch (dataType.ToLowerInvariant()) { switch (dataType.ToLowerInvariant()) {
case "description":
content = Encoding.UTF8.GetBytes(photo.Description);
break;
case "format": case "format":
content = Encoding.UTF8.GetBytes(photo.Format switch { content = Encoding.UTF8.GetBytes(photo.Format switch {
PhotoFormat.GTA5 => "gta5", PhotoFormat.GTA5 => "gta5",
@ -56,9 +59,9 @@ internal static class Program {
} }
} }
private static void Set(FileInfo photoFile, String? format, String? jpegFile, String? json, String? title, FileInfo? outputFile) { private static void Set(FileInfo photoFile, String? format, String? jpegFile, String? description, String? json, String? title, FileInfo? outputFile) {
if (String.IsNullOrEmpty(format) && String.IsNullOrEmpty(jpegFile) && if (format == null && jpegFile == null &&
json == null && title == null) { description == null && json == null && title == null) {
Console.Error.WriteLine("No value has being set"); Console.Error.WriteLine("No value has being set");
Environment.Exit(1); Environment.Exit(1);
} }
@ -67,7 +70,7 @@ internal static class Program {
using Photo photo = new(); using Photo photo = new();
photo.LoadFile(photoFile.FullName); photo.LoadFile(photoFile.FullName);
if (!String.IsNullOrEmpty(format)) { if (format != null) {
photo.Format = format.ToLowerInvariant() switch { photo.Format = format.ToLowerInvariant() switch {
"gta5" => PhotoFormat.GTA5, "gta5" => PhotoFormat.GTA5,
"rdr2" => PhotoFormat.RDR2, "rdr2" => PhotoFormat.RDR2,
@ -75,13 +78,19 @@ internal static class Program {
}; };
} }
if (description != null)
photo.Description = description;
if (json != null) if (json != null)
photo.Json = json; photo.Json = json;
if (title != null) if (title != null)
photo.Title = title; photo.Title = title;
if (!String.IsNullOrEmpty(jpegFile)) { if (jpegFile == string.Empty) {
photo.Jpeg = new Byte[1];
}
else if (jpegFile != null) {
using MemoryStream jpegStream = new(); using MemoryStream jpegStream = new();
using Stream input = jpegFile == "-" ? Console.OpenStandardInput() : File.OpenRead(jpegFile); using Stream input = jpegFile == "-" ? Console.OpenStandardInput() : File.OpenRead(jpegFile);
input.CopyTo(jpegStream); input.CopyTo(jpegStream);
@ -138,10 +147,13 @@ internal static class Program {
Option<String?> formatOption = new("--format", "-f") { Option<String?> formatOption = new("--format", "-f") {
Description = "Photo Format" Description = "Photo Format"
}; };
Option<String?> jpegOption = new("--jpeg") { Option<String?> jpegOption = new("--jpeg", "--image", "-i") {
Description = "JPEG File" Description = "JPEG File"
}; };
Option<String?> jsonOption = new("--json") { Option<String?> descriptionOption = new("--description", "-d") {
Description = "Photo Description"
};
Option<String?> jsonOption = new("--json", "-j") {
Description = "Photo JSON" Description = "Photo JSON"
}; };
Option<String?> titleOption = new("--title", "-t") { Option<String?> titleOption = new("--title", "-t") {
@ -151,12 +163,13 @@ internal static class Program {
Description = "Output File" Description = "Output File"
}; };
Command setCommand = new("set", "Set Photo Data") { Command setCommand = new("set", "Set Photo Data") {
photoArgument, formatOption, jpegOption, jsonOption, titleOption, outputOption photoArgument, formatOption, jpegOption, descriptionOption, jsonOption, titleOption, outputOption
}; };
setCommand.SetAction(result => Set( setCommand.SetAction(result => Set(
result.GetRequiredValue(photoArgument), result.GetRequiredValue(photoArgument),
result.GetValue(formatOption), result.GetValue(formatOption),
result.GetValue(jpegOption), result.GetValue(jpegOption),
result.GetValue(descriptionOption),
result.GetValue(jsonOption), result.GetValue(jsonOption),
result.GetValue(titleOption), result.GetValue(titleOption),
result.GetValue(outputOption))); result.GetValue(outputOption)));

View file

@ -1,9 +1,9 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.14.36616.10 d17.14 VisualStudioVersion = 17.14.36616.10
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RagePhotoCli", "RagePhotoCli.csproj", "{E8CD6776-793E-4E73-A60F-DF86E35EDF6B}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ragephoto-cli", "ragephoto-cli.csproj", "{E8CD6776-793E-4E73-A60F-DF86E35EDF6B}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution