impl. image processing and rename update-sign option to update-json

This commit is contained in:
Syping 2025-11-23 03:33:46 +01:00
parent 9a70c45c7a
commit 89b37b6ede
8 changed files with 232 additions and 390 deletions

73
Commands.Win32.cs Normal file
View file

@ -0,0 +1,73 @@
using Microsoft.Win32;
using System.CommandLine;
using System.Runtime.Versioning;
namespace RagePhoto.Cli;
internal static partial class Commands {
[SupportedOSPlatform("Windows")]
internal static Int32 PathFunction(String command) {
try {
if (command == "register" || command == "unregister") {
String appPath = Path.GetDirectoryName(Environment.ProcessPath) ??
throw new Exception("Application Path can not be found");
String fullAppPath = Path.TrimEndingDirectorySeparator(Path.GetFullPath(appPath));
using RegistryKey environmentKey = Registry.LocalMachine.OpenSubKey(
@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", true) ??
throw new Exception("Environment Registry Key can not be opened");
String? path = environmentKey.GetValue(
"Path", null, RegistryValueOptions.DoNotExpandEnvironmentNames) as String ??
throw new Exception("Path Registry Value is invalid");
List<String> paths = [.. path.Split(';', StringSplitOptions.RemoveEmptyEntries)];
for (Int32 i = 0; i < paths.Count; i++) {
if (!String.Equals(
fullAppPath,
Path.TrimEndingDirectorySeparator(Path.GetFullPath(paths[i])),
StringComparison.OrdinalIgnoreCase))
continue;
if (command == "register")
return 0;
paths.RemoveAt(i);
environmentKey.SetValue("Path", String.Join(";", paths), RegistryValueKind.ExpandString);
return 0;
}
if (command == "unregister")
return 0;
paths.Add(fullAppPath);
environmentKey.SetValue("Path", String.Join(";", paths), RegistryValueKind.ExpandString);
return 0;
}
Console.Error.WriteLine("Invalid Path Command");
return 1;
}
catch (Exception exception) {
Console.Error.WriteLine(exception.Message);
return -1;
}
}
[SupportedOSPlatform("Windows")]
internal static Command PathCommand {
get {
Argument<String> commandArgument = new("command") {
Description = "Path Command"
};
commandArgument.CompletionSources.Add(_ => [
new ("register"),
new ("unregister")]);
commandArgument.Validators.Add(result => {
String[] commands = ["register", "unregister"];
String command = result.GetValueOrDefault<String>();
if (!commands.Contains(command, StringComparer.InvariantCultureIgnoreCase))
result.AddError("Invalid Path Command.");
});
Command pathCommand = new("path", "Register/Unregister Path") {
commandArgument
};
pathCommand.Hidden = true;
pathCommand.SetAction(result => Environment.ExitCode = PathFunction(
result.GetRequiredValue(commandArgument)));
return pathCommand;
}
}
}

View file

@ -1,58 +1,46 @@
using Microsoft.Win32; using SixLabors.ImageSharp;
using System.CommandLine; using System.CommandLine;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
namespace RagePhoto.Cli; namespace RagePhoto.Cli;
internal static class Commands { internal static partial class Commands {
internal static Int32 CreateFunction(String format, String? jpegFile, String? description, String? json, String? title, String outputFile) { internal static Int32 CreateFunction(String format, String? imageFile, String? description, String? json, String? title, String outputFile) {
try { try {
using Photo photo = new(); using Photo photo = new();
photo.Format = format.ToLowerInvariant() switch { switch (format.ToLowerInvariant()) {
"gta5" => PhotoFormat.GTA5, case "gta5":
"rdr2" => PhotoFormat.RDR2, photo.Format = PhotoFormat.GTA5;
_ => throw new ArgumentException("Invalid Photo Format", nameof(format)) photo.SetHeader("PHOTO - 10/26/25 02:28:08", 798615001, 0);
}; break;
case "rdr2":
if (photo.Format == PhotoFormat.GTA5) { photo.Format = PhotoFormat.RDR2;
photo.SetHeader("PHOTO - 10/26/25 02:28:08", 798615001, 0); photo.SetHeader("PHOTO - 10/26/25 02:31:34", 3077307752, 2901366738);
} break;
else { default:
photo.SetHeader("PHOTO - 10/26/25 02:31:34", 3077307752, 2901366738); throw new ArgumentException("Invalid Format", nameof(format));
} }
if (String.IsNullOrEmpty(jpegFile)) { Size size;
photo.Jpeg = Properties.Resources.EmptyJpeg; if (String.IsNullOrEmpty(imageFile)) {
photo.Jpeg = Jpeg.GetEmptyJpeg(photo.Format, out size);
} }
else { else {
using MemoryStream jpegStream = new(); using Stream input = imageFile == "-" ? Console.OpenStandardInput() : File.OpenRead(imageFile);
using Stream input = jpegFile == "-" ? Console.OpenStandardInput() : File.OpenRead(jpegFile); photo.Jpeg = Jpeg.GetJpeg(input, out size);
input.CopyTo(jpegStream);
photo.Jpeg = jpegStream.ToArray();
} }
if (photo.Format == PhotoFormat.GTA5) { photo.Json = json == null ?
photo.Json = json == null ? Json.Initialize(photo, size, out Int32 uid) :
Json.Initialize(PhotoFormat.GTA5, photo, Random.Shared.Next(), Json.Update(photo, size, photo.Json, out uid);
DateTimeOffset.FromUnixTimeSeconds(Random.Shared.Next(1356998400, 1388534399))) :
Json.UpdateSign(photo, photo.Json);
}
else {
photo.Json = json == null ?
Json.Initialize(PhotoFormat.RDR2, photo, Random.Shared.Next(),
DateTimeOffset.FromUnixTimeSeconds(Random.Shared.NextInt64(-2240524800, -2208988801))) :
Json.UpdateSign(photo, photo.Json);
}
photo.Description = description ?? String.Empty; photo.Description = description ?? String.Empty;
photo.Title = title ?? "Custom Photo"; photo.Title = title ?? "Custom Photo";
if (outputFile == "-" || outputFile == String.Empty) { if (outputFile == "-" || outputFile == String.Empty) {
using MemoryStream photoStream = new(photo.Save());
using Stream output = Console.OpenStandardOutput(); using Stream output = Console.OpenStandardOutput();
photoStream.CopyTo(output); output.Write(photo.Save());
} }
else { else {
String tempFile = Path.GetTempFileName(); String tempFile = Path.GetTempFileName();
@ -100,7 +88,7 @@ internal static class Commands {
content = Encoding.UTF8.GetBytes($"{photo.Format switch { content = Encoding.UTF8.GetBytes($"{photo.Format switch {
PhotoFormat.GTA5 => "gta5", PhotoFormat.GTA5 => "gta5",
PhotoFormat.RDR2 => "rdr2", PhotoFormat.RDR2 => "rdr2",
_ => "unknown" _ => throw new ArgumentException("Invalid Format")
}}\n"); }}\n");
break; break;
case "i": case "i":
@ -126,15 +114,13 @@ internal static class Commands {
} }
if (outputFile == "-" || outputFile == String.Empty) { if (outputFile == "-" || outputFile == String.Empty) {
using MemoryStream contentStream = new(content);
using Stream output = Console.OpenStandardOutput(); using Stream output = Console.OpenStandardOutput();
contentStream.CopyTo(output); output.Write(content);
} }
else { else {
String tempFile = Path.GetTempFileName(); String tempFile = Path.GetTempFileName();
using (MemoryStream contentStream = new(content)) { using (FileStream output = File.Create(tempFile)) {
using FileStream output = File.Create(tempFile); output.Write(content);
contentStream.CopyTo(output);
} }
File.Move(tempFile, outputFile, true); File.Move(tempFile, outputFile, true);
} }
@ -150,18 +136,16 @@ internal static class Commands {
} }
} }
internal static Int32 SetFunction(String inputFile, String? format, String? jpegFile, String? description, String? json, String? title, bool updateSign, String? outputFile) { internal static Int32 SetFunction(String inputFile, String? format, String? imageFile, String? description, String? json, String? title, bool updateJson, String? outputFile) {
if (format == null && jpegFile == null && description == null
&& json == null && title == null && !updateSign) {
Console.Error.WriteLine("No value has being set");
return 1;
}
else if (inputFile == "-" && jpegFile == "-") {
Console.Error.WriteLine("Multiple pipes are not supported");
return 1;
}
try { try {
if (format == null && imageFile == null && description == null
&& json == null && title == null && !updateJson) {
throw new ArgumentException("No Value has being set");
}
else if ((inputFile == "-" || inputFile == String.Empty) && imageFile == "-") {
throw new ArgumentException("Multiple Pipes are not supported");
}
using Photo photo = new(); using Photo photo = new();
if (inputFile == "-" || inputFile == String.Empty) { if (inputFile == "-" || inputFile == String.Empty) {
@ -178,7 +162,7 @@ internal static class Commands {
photo.Format = format.ToLowerInvariant() switch { photo.Format = format.ToLowerInvariant() switch {
"gta5" => PhotoFormat.GTA5, "gta5" => PhotoFormat.GTA5,
"rdr2" => PhotoFormat.RDR2, "rdr2" => PhotoFormat.RDR2,
_ => throw new ArgumentException("Invalid Photo Format", nameof(format)) _ => throw new ArgumentException("Invalid Format", nameof(format))
}; };
} }
@ -191,25 +175,24 @@ internal static class Commands {
if (title != null) if (title != null)
photo.Title = title; photo.Title = title;
if (jpegFile == String.Empty) { Size size;
photo.Jpeg = Properties.Resources.EmptyJpeg; if (imageFile == String.Empty) {
photo.Json = Json.UpdateSign(photo, photo.Json); photo.Jpeg = Jpeg.GetEmptyJpeg(photo.Format, out size);
photo.Json = Json.Update(photo, size, photo.Json, out Int32 uid);
} }
else if (jpegFile != null) { else if (imageFile != null) {
using MemoryStream jpegStream = new(); using Stream input = imageFile == "-" ? Console.OpenStandardInput() : File.OpenRead(imageFile);
using Stream input = jpegFile == "-" ? Console.OpenStandardInput() : File.OpenRead(jpegFile); photo.Jpeg = Jpeg.GetJpeg(input, out size);
input.CopyTo(jpegStream); photo.Json = Json.Update(photo, size, photo.Json, out Int32 uid);
photo.Jpeg = jpegStream.ToArray();
photo.Json = Json.UpdateSign(photo, photo.Json);
} }
else if (updateSign) { else if (updateJson) {
photo.Json = Json.UpdateSign(photo, photo.Json); size = Jpeg.GetSize(photo.Jpeg);
photo.Json = Json.Update(photo, size, photo.Json, out Int32 uid);
} }
if (outputFile == "-") { if (outputFile == "-") {
using MemoryStream photoStream = new(photo.Save());
using Stream output = Console.OpenStandardOutput(); using Stream output = Console.OpenStandardOutput();
photoStream.CopyTo(output); output.Write(photo.Save());
} }
else { else {
String tempFile = Path.GetTempFileName(); String tempFile = Path.GetTempFileName();
@ -232,52 +215,10 @@ internal static class Commands {
} }
} }
internal static Int32 PathFunction(String command) {
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return 0;
try {
if (command == "register" || command == "unregister") {
String appPath = Path.GetDirectoryName(Environment.ProcessPath) ??
throw new Exception("Application Path can not be found");
String fullAppPath = Path.TrimEndingDirectorySeparator(Path.GetFullPath(appPath));
using RegistryKey environmentKey = Registry.LocalMachine.OpenSubKey(
@"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", true) ??
throw new Exception("Environment Registry Key can not be opened");
String? path = environmentKey.GetValue(
"Path", null, RegistryValueOptions.DoNotExpandEnvironmentNames) as String ??
throw new Exception("Path Registry Value is invalid");
List<String> paths = [.. path.Split(';', StringSplitOptions.RemoveEmptyEntries)];
for (Int32 i = 0; i < paths.Count; i++) {
if (!String.Equals(
fullAppPath,
Path.TrimEndingDirectorySeparator(Path.GetFullPath(paths[i])),
StringComparison.OrdinalIgnoreCase))
continue;
if (command == "register")
return 0;
paths.RemoveAt(i);
environmentKey.SetValue("Path", String.Join(";", paths), RegistryValueKind.ExpandString);
return 0;
}
if (command == "unregister")
return 0;
paths.Add(fullAppPath);
environmentKey.SetValue("Path", String.Join(";", paths), RegistryValueKind.ExpandString);
return 0;
}
Console.Error.WriteLine("Invalid Path Command");
return 1;
}
catch (Exception exception) {
Console.Error.WriteLine(exception.Message);
return -1;
}
}
internal static Command CreateCommand { internal static Command CreateCommand {
get { get {
Argument<String> formatArgument = new("format") { Argument<String> formatArgument = new("format") {
Description = "Photo Format" Description = "Format"
}; };
formatArgument.CompletionSources.Add(_ => [ formatArgument.CompletionSources.Add(_ => [
new("gta5"), new("gta5"),
@ -286,30 +227,30 @@ internal static class Commands {
String[] formats = ["gta5", "rdr2"]; String[] formats = ["gta5", "rdr2"];
String format = result.GetValueOrDefault<String>(); String format = result.GetValueOrDefault<String>();
if (!formats.Contains(format, StringComparer.InvariantCultureIgnoreCase)) if (!formats.Contains(format, StringComparer.InvariantCultureIgnoreCase))
result.AddError("Invalid Photo Format."); result.AddError("Invalid Format.");
}); });
Option<String?> jpegOption = new("--jpeg", "--image", "-i") { Option<String?> imageOption = new("--image", "-i", "--jpeg") {
Description = "JPEG File" Description = "Image File"
}; };
Option<String?> descriptionOption = new("--description", "-d") { Option<String?> descriptionOption = new("--description", "-d") {
Description = "Photo Description" Description = "Description"
}; };
Option<String?> jsonOption = new("--json", "-j") { Option<String?> jsonOption = new("--json", "-j") {
Description = "Photo JSON" Description = "JSON"
}; };
Option<String?> titleOption = new("--title", "-t") { Option<String?> titleOption = new("--title", "-t") {
Description = "Photo Title" Description = "Title"
}; };
Option<String> outputOption = new("--output", "-o") { Option<String> outputOption = new("--output", "-o") {
Description = "Output File", Description = "Output File",
DefaultValueFactory = _ => "-" DefaultValueFactory = _ => "-"
}; };
Command createCommand = new("create", "Create a new Photo") { Command createCommand = new("create", "Create a new Photo") {
formatArgument, jpegOption, descriptionOption, jsonOption, titleOption, outputOption formatArgument, imageOption, descriptionOption, jsonOption, titleOption, outputOption
}; };
createCommand.SetAction(result => Environment.ExitCode = CreateFunction( createCommand.SetAction(result => Environment.ExitCode = CreateFunction(
result.GetRequiredValue(formatArgument), result.GetRequiredValue(formatArgument),
result.GetValue(jpegOption), result.GetValue(imageOption),
result.GetValue(descriptionOption), result.GetValue(descriptionOption),
result.GetValue(jsonOption), result.GetValue(jsonOption),
result.GetValue(titleOption), result.GetValue(titleOption),
@ -323,39 +264,39 @@ internal static class Commands {
Argument<String> inputArgument = new("input") { Argument<String> inputArgument = new("input") {
Description = "Input File" Description = "Input File"
}; };
Argument<String> dataTypeArgument = new("dataType") { Argument<String> typeArgument = new("type") {
Description = "Data Type", Description = "Data Type",
DefaultValueFactory = _ => "jpeg" DefaultValueFactory = _ => "jpeg"
}; };
dataTypeArgument.CompletionSources.Add(_ => [ typeArgument.CompletionSources.Add(_ => [
new("description"), new("description"),
new("format"), new("format"),
new("jpeg"), new("jpeg"),
new("json"), new("json"),
new("sign"), new("sign"),
new("title")]); new("title")]);
dataTypeArgument.Validators.Add(result => { typeArgument.Validators.Add(result => {
String[] dataTypes = [ String[] types = [
"d", "description", "d", "description",
"f", "format", "f", "format",
"i", "image", "jpeg", "i", "image", "jpeg",
"j", "json", "j", "json",
"s", "sign", "s", "sign",
"t", "title"]; "t", "title"];
String dataType = result.GetValueOrDefault<String>(); String type = result.GetValueOrDefault<String>();
if (!dataTypes.Contains(dataType, StringComparer.InvariantCultureIgnoreCase)) if (!types.Contains(type, StringComparer.InvariantCultureIgnoreCase))
result.AddError($"Unknown Data Type: {dataType}."); result.AddError($"Unknown Data Type: {type}.");
}); });
Option<String> outputOption = new("--output", "-o") { Option<String> outputOption = new("--output", "-o") {
Description = "Output File", Description = "Output File",
DefaultValueFactory = _ => "-" DefaultValueFactory = _ => "-"
}; };
Command getCommand = new("get", "Get Data from a Photo") { Command getCommand = new("get", "Get Data from a Photo") {
inputArgument, dataTypeArgument, outputOption inputArgument, typeArgument, outputOption
}; };
getCommand.SetAction(result => Environment.ExitCode = GetFunction( getCommand.SetAction(result => Environment.ExitCode = GetFunction(
result.GetRequiredValue(inputArgument), result.GetRequiredValue(inputArgument),
result.GetRequiredValue(dataTypeArgument), result.GetRequiredValue(typeArgument),
result.GetRequiredValue(outputOption))); result.GetRequiredValue(outputOption)));
return getCommand; return getCommand;
} }
@ -367,63 +308,39 @@ internal static class Commands {
Description = "Input File" Description = "Input File"
}; };
Option<String?> formatOption = new("--format", "-f") { Option<String?> formatOption = new("--format", "-f") {
Description = "Photo Format" Description = "Format"
}; };
Option<String?> jpegOption = new("--jpeg", "--image", "-i") { Option<String?> imageOption = new("--image", "-i", "--jpeg") {
Description = "JPEG File" Description = "Image File"
}; };
Option<String?> descriptionOption = new("--description", "-d") { Option<String?> descriptionOption = new("--description", "-d") {
Description = "Photo Description" Description = "Description"
}; };
Option<String?> jsonOption = new("--json", "-j") { Option<String?> jsonOption = new("--json", "-j") {
Description = "Photo JSON" Description = "JSON"
}; };
Option<String?> titleOption = new("--title", "-t") { Option<String?> titleOption = new("--title", "-t") {
Description = "Photo Title" Description = "Title"
}; };
Option<bool> updateSignOption = new("--update-sign", "-u") { Option<bool> updateJsonOption = new("--update-json", "-u") {
Description = "Update Photo Signature" Description = "Update JSON"
}; };
Option<String?> outputOption = new("--output", "-o") { Option<String?> outputOption = new("--output", "-o") {
Description = "Output File" Description = "Output File"
}; };
Command setCommand = new("set", "Set Data from a Photo") { Command setCommand = new("set", "Set Data from a Photo") {
inputArgument, formatOption, jpegOption, descriptionOption, jsonOption, titleOption, updateSignOption, outputOption inputArgument, formatOption, imageOption, descriptionOption, jsonOption, titleOption, updateJsonOption, outputOption
}; };
setCommand.SetAction(result => Environment.ExitCode = SetFunction( setCommand.SetAction(result => Environment.ExitCode = SetFunction(
result.GetRequiredValue(inputArgument), result.GetRequiredValue(inputArgument),
result.GetValue(formatOption), result.GetValue(formatOption),
result.GetValue(jpegOption), result.GetValue(imageOption),
result.GetValue(descriptionOption), result.GetValue(descriptionOption),
result.GetValue(jsonOption), result.GetValue(jsonOption),
result.GetValue(titleOption), result.GetValue(titleOption),
result.GetValue(updateSignOption), result.GetValue(updateJsonOption),
result.GetValue(outputOption))); result.GetValue(outputOption)));
return setCommand; return setCommand;
} }
} }
internal static Command PathCommand {
get {
Argument<String> commandArgument = new("command") {
Description = "Path Command"
};
commandArgument.CompletionSources.Add(_ => [
new ("register"),
new ("unregister")]);
commandArgument.Validators.Add(result => {
String[] commands = ["register", "unregister"];
String command = result.GetValueOrDefault<String>();
if (!commands.Contains(command, StringComparer.InvariantCultureIgnoreCase))
result.AddError("Invalid Path Command.");
});
Command pathCommand = new("path", "Register/Unregister Path") {
commandArgument
};
pathCommand.Hidden = true;
pathCommand.SetAction(result => Environment.ExitCode = PathFunction(
result.GetRequiredValue(commandArgument)));
return pathCommand;
}
}
} }

42
Jpeg.cs Normal file
View file

@ -0,0 +1,42 @@
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.PixelFormats;
namespace RagePhoto.Cli;
internal class Jpeg {
internal static Byte[] GetEmptyJpeg(PhotoFormat format, out Size size) {
size = format == PhotoFormat.GTA5 ? new(960, 536) : new(1920, 1080);
using Image<Rgb24> image = new(size.Width, size.Height);
image.ProcessPixelRows(static pixelAccessor => {
for (Int32 y = 0; y < pixelAccessor.Height; y++) {
Span<Rgb24> pixelRow = pixelAccessor.GetRowSpan(y);
for (Int32 x = 0; x < pixelRow.Length; x++) {
pixelRow[x] = Color.Black;
}
}
});
using MemoryStream output = new();
image.SaveAsJpeg(output, new() {
Quality = 100,
ColorType = JpegEncodingColor.YCbCrRatio444
});
return output.ToArray();
}
internal static Byte[] GetJpeg(Stream stream, out Size size) {
using Image image = Image.Load(stream);
size = image.Size;
image.Metadata.ExifProfile = null;
using MemoryStream output = new();
image.SaveAsJpeg(output, new() {
Quality = 100,
ColorType = JpegEncodingColor.YCbCrRatio444
});
return output.ToArray();
}
internal static Size GetSize(ReadOnlySpan<Byte> jpeg) {
return Image.Identify(jpeg).Size;
}
}

55
Json.cs
View file

@ -1,25 +1,32 @@
using System.Text.Encodings.Web; using SixLabors.ImageSharp;
using System.Text.Encodings.Web;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Nodes; using System.Text.Json.Nodes;
namespace RagePhoto.Cli; namespace RagePhoto.Cli;
internal class Json { internal class Json {
internal static String Initialize(PhotoFormat format, Photo photo, Int32 photoUid, DateTimeOffset photoTime) { internal static String Initialize(Photo photo, Size size, out Int32 uid) {
JsonObject jsonLocation = new() { JsonObject jsonLocation = new() {
["x"] = 0, ["x"] = 0,
["y"] = 0, ["y"] = 0,
["z"] = 0 ["z"] = 0
}; };
DateTimeOffset time = DateTimeOffset.FromUnixTimeSeconds(photo.Format switch {
PhotoFormat.GTA5 => Random.Shared.Next(1356998400, 1388534399),
PhotoFormat.RDR2 => Random.Shared.NextInt64(-2240524800, -2208988801),
_ => throw new ArgumentException("Invalid Format")
});
JsonObject jsonTime = new() { JsonObject jsonTime = new() {
["hour"] = photoTime.Hour, ["hour"] = time.Hour,
["minute"] = photoTime.Minute, ["minute"] = time.Minute,
["second"] = photoTime.Second, ["second"] = time.Second,
["day"] = photoTime.Day, ["day"] = time.Day,
["month"] = photoTime.Month, ["month"] = time.Month,
["year"] = photoTime.Year ["year"] = time.Year
}; };
JsonObject json = format switch { uid = Random.Shared.Next();
JsonObject json = photo.Format switch {
PhotoFormat.GTA5 => new() { PhotoFormat.GTA5 => new() {
["loc"] = jsonLocation, ["loc"] = jsonLocation,
["area"] = "SANAND", ["area"] = "SANAND",
@ -32,7 +39,7 @@ internal class Json {
["mid"] = String.Empty, ["mid"] = String.Empty,
["mode"] = "FREEMODE", ["mode"] = "FREEMODE",
["meme"] = false, ["meme"] = false,
["uid"] = photoUid, ["uid"] = uid,
["time"] = jsonTime, ["time"] = jsonTime,
["creat"] = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), ["creat"] = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
["slf"] = true, ["slf"] = true,
@ -54,7 +61,7 @@ internal class Json {
["mode"] = "SP", ["mode"] = "SP",
["meme"] = false, ["meme"] = false,
["mug"] = false, ["mug"] = false,
["uid"] = photoUid, ["uid"] = uid,
["time"] = jsonTime, ["time"] = jsonTime,
["creat"] = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), ["creat"] = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
["slf"] = false, ["slf"] = false,
@ -62,26 +69,40 @@ internal class Json {
["rsedtr"] = false, ["rsedtr"] = false,
["inphotomode"] = true, ["inphotomode"] = true,
["advanced"] = false, ["advanced"] = false,
["width"] = 1920, ["width"] = size.Width,
["height"] = 1080, ["height"] = size.Height,
["size"] = photo.JpegSize, ["size"] = photo.JpegSize,
["sign"] = photo.Sign, ["sign"] = photo.Sign,
["meta"] = new JsonObject() ["meta"] = new JsonObject()
}, },
_ => throw new ArgumentException("Invalid format", nameof(format)), _ => throw new ArgumentException("Invalid Format")
}; };
return json.ToJsonString(SerializerOptions); return json.ToJsonString(SerializerOptions);
} }
internal static String UpdateSign(Photo photo, String json) { internal static String Update(Photo photo, Size size, String json, out Int32 uid) {
try { try {
if (JsonNode.Parse(json) is not JsonObject jsonObject) if (JsonNode.Parse(json) is not JsonObject jsonObject)
throw new ArgumentException("Invalid json", nameof(json)); throw new ArgumentException("Invalid JSON", nameof(json));
if (jsonObject["uid"] is not JsonValue uidValue ||
uidValue.GetValueKind() != JsonValueKind.Number) {
uid = Random.Shared.Next();
jsonObject["uid"] = uid;
}
else {
uid = uidValue.GetValue<Int32>();
}
if (photo.Format == PhotoFormat.RDR2) {
jsonObject["width"] = size.Width;
jsonObject["height"] = size.Height;
}
jsonObject["sign"] = photo.Sign; jsonObject["sign"] = photo.Sign;
jsonObject["size"] = photo.JpegSize;
return jsonObject.ToJsonString(SerializerOptions); return jsonObject.ToJsonString(SerializerOptions);
} }
catch (Exception exception) { catch (Exception exception) {
Console.Error.WriteLine($"Failed to update sign: {exception.Message}"); Console.Error.WriteLine($"Failed to update JSON: {exception.Message}");
uid = 0;
return json; return json;
} }
} }

View file

@ -1,73 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace RagePhoto.Cli.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RagePhoto.Cli.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] EmptyJpeg {
get {
object obj = ResourceManager.GetObject("EmptyJpeg", resourceCulture);
return ((byte[])(obj));
}
}
}
}

View file

@ -1,124 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="EmptyJpeg" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\empty.jpg;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 518 B

View file

@ -16,23 +16,9 @@
<PublishAot>true</PublishAot> <PublishAot>true</PublishAot>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="RagePhoto.Core" Version="0.8.1" /> <PackageReference Include="RagePhoto.Core" Version="0.8.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.12" />
<PackageReference Include="System.CommandLine" Version="2.0.0" /> <PackageReference Include="System.CommandLine" Version="2.0.0" />
</ItemGroup> </ItemGroup>