From 396996c4ab89b28d216ad3085ddd06db95165b8f Mon Sep 17 00:00:00 2001 From: Raymonf Date: Sat, 4 Mar 2023 14:47:15 -0500 Subject: [PATCH] Add crappy settings support I should fix this lol --- WTT/WTT/Exceptions/DuplicateKeyException.cs | 2 +- WTT/WTT/Exceptions/MissingKeyException.cs | 2 +- WTT/WTT/Exceptions/UnhandledTomlError.cs | 2 +- .../Exceptions/UnsupportedAssetException.cs | 2 +- WTT/WTT/ExportSettings.cs | 2 +- WTT/WTT/ImportSettings.cs | 13 ++++ WTT/WTT/Language.cs | 2 + WTT/WTT/Program.cs | 76 +++++++++++++++++-- WTT/WTT/Table.cs | 3 +- WTT/WTT/TableExporter.cs | 19 +++-- WTT/WTT/TableImporter.cs | 10 +-- WTT/WTT/YesNoPrompt.cs | 2 +- 12 files changed, 110 insertions(+), 25 deletions(-) create mode 100644 WTT/WTT/ImportSettings.cs diff --git a/WTT/WTT/Exceptions/DuplicateKeyException.cs b/WTT/WTT/Exceptions/DuplicateKeyException.cs index 991564f..0a7abad 100644 --- a/WTT/WTT/Exceptions/DuplicateKeyException.cs +++ b/WTT/WTT/Exceptions/DuplicateKeyException.cs @@ -1,4 +1,4 @@ -namespace WhackTranslationTool.Exceptions; +namespace WTT.Exceptions; public class DuplicateKeyException : Exception { diff --git a/WTT/WTT/Exceptions/MissingKeyException.cs b/WTT/WTT/Exceptions/MissingKeyException.cs index 7bcddfb..40419b9 100644 --- a/WTT/WTT/Exceptions/MissingKeyException.cs +++ b/WTT/WTT/Exceptions/MissingKeyException.cs @@ -1,4 +1,4 @@ -namespace WhackTranslationTool.Exceptions; +namespace WTT.Exceptions; public class MissingKeyException : Exception { diff --git a/WTT/WTT/Exceptions/UnhandledTomlError.cs b/WTT/WTT/Exceptions/UnhandledTomlError.cs index 2ad4bae..449c81d 100644 --- a/WTT/WTT/Exceptions/UnhandledTomlError.cs +++ b/WTT/WTT/Exceptions/UnhandledTomlError.cs @@ -1,4 +1,4 @@ -namespace WhackTranslationTool.Exceptions; +namespace WTT.Exceptions; public class UnhandledTomlError : Exception { diff --git a/WTT/WTT/Exceptions/UnsupportedAssetException.cs b/WTT/WTT/Exceptions/UnsupportedAssetException.cs index 78beba5..9ac2580 100644 --- a/WTT/WTT/Exceptions/UnsupportedAssetException.cs +++ b/WTT/WTT/Exceptions/UnsupportedAssetException.cs @@ -1,4 +1,4 @@ -namespace WhackTranslationTool.Exceptions; +namespace WTT.Exceptions; public class UnsupportedAssetException : Exception { diff --git a/WTT/WTT/ExportSettings.cs b/WTT/WTT/ExportSettings.cs index 7135d97..35a6676 100644 --- a/WTT/WTT/ExportSettings.cs +++ b/WTT/WTT/ExportSettings.cs @@ -1,4 +1,4 @@ -namespace WhackTranslationTool; +namespace WTT; public class ExportSettings { diff --git a/WTT/WTT/ImportSettings.cs b/WTT/WTT/ImportSettings.cs new file mode 100644 index 0000000..a7675e2 --- /dev/null +++ b/WTT/WTT/ImportSettings.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WTT +{ + internal class ImportSettings + { + public Language Language { get; set; } = Language.EnglishUSA; + } +} diff --git a/WTT/WTT/Language.cs b/WTT/WTT/Language.cs index faa0055..bb1e8a8 100644 --- a/WTT/WTT/Language.cs +++ b/WTT/WTT/Language.cs @@ -2,10 +2,12 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Json.Serialization; using System.Threading.Tasks; namespace WTT { + [JsonConverter(typeof(JsonStringEnumConverter))] public enum Language { Japanese, diff --git a/WTT/WTT/Program.cs b/WTT/WTT/Program.cs index 15276c1..b4b04b4 100644 --- a/WTT/WTT/Program.cs +++ b/WTT/WTT/Program.cs @@ -1,4 +1,5 @@ -using WhackTranslationTool; +using System.Text.Json; +using WTT; string? basePath = null; // @"WindowsNoEditor\Mercury\Content\Message"; bool? overwrite = null; @@ -33,9 +34,74 @@ static string GetAssetFilename(string path) return Path.GetFileNameWithoutExtension(path) + ".uasset"; } +const string ExportSettingsFilename = "ExportSettings.json"; +const string ImportSettingsFilename = "ImportSettings.json"; + while (true) { Console.WriteLine("[whack Translation Tool]"); + + // fuck it, hacked in settings! + var exportSettings = new ExportSettings(); + if (File.Exists(ExportSettingsFilename)) + { + using var settingsStream = File.OpenRead(ExportSettingsFilename); + try + { + var result = JsonSerializer.Deserialize(settingsStream); + if (result != null) + exportSettings = result; + } + catch (Exception ex) + { + Console.WriteLine("Unable to read export settings:"); + Console.WriteLine(ex); + } + } + else + { + try + { + File.WriteAllText(ExportSettingsFilename, JsonSerializer.Serialize(exportSettings)); + } + catch (Exception ex) + { + Console.WriteLine("Unable to write export settings:"); + Console.WriteLine(ex); + exportSettings = new(); + } + } + + var importSettings = new ImportSettings(); + if (File.Exists(ImportSettingsFilename)) + { + using var settingsStream = File.OpenRead(ImportSettingsFilename); + try + { + var result = JsonSerializer.Deserialize(settingsStream); + if (result != null) + importSettings = result; + } + catch (Exception ex) + { + Console.WriteLine("Unable to read import settings:"); + Console.WriteLine(ex); + importSettings = new(); + } + } + else + { + try + { + File.WriteAllText(ImportSettingsFilename, JsonSerializer.Serialize(importSettings)); + } + catch (Exception ex) + { + Console.WriteLine("Unable to write import settings:"); + Console.WriteLine(ex); + } + } + while (basePath == null || !Directory.Exists(basePath)) { if (basePath != null) @@ -71,7 +137,7 @@ while (true) var files = Directory.GetFiles(basePath, "*.uasset"); foreach (var tableName in files) { - var exporter = new TableExporter(Path.Combine(basePath, tableName)); + var exporter = new TableExporter(Path.Combine(basePath, tableName), exportSettings); var targetPath = Path.GetFileName(Path.ChangeExtension(tableName, "toml")); if (File.Exists(targetPath)) @@ -116,7 +182,7 @@ while (true) foreach (var tableName in files) { var assetFilename = GetAssetFilename(tableName); - var importer = new TableImporter(tableName, Path.Combine(assetFolder, assetFilename)); + var importer = new TableImporter(tableName, Path.Combine(assetFolder, assetFilename), importSettings.Language); var outputPath = Path.Combine(outputFolder, assetFilename); Console.WriteLine($"Exporting to {outputPath}"); importer.Write(outputPath); @@ -134,7 +200,7 @@ while (true) break; } - var exporter = new TableExporter(Path.Combine(basePath, tableName)); + var exporter = new TableExporter(Path.Combine(basePath, tableName), exportSettings); var targetPath = Path.ChangeExtension(tableName, "toml"); if (File.Exists(targetPath)) { @@ -155,7 +221,7 @@ while (true) var assetPath = Console.ReadLine()!.Trim(); if (assetPath.Length < 1) assetPath = Path.Combine(basePath, GetAssetFilename(importPath)); - var importer = new TableImporter(importPath, assetPath); + var importer = new TableImporter(importPath, assetPath, importSettings.Language); Console.Write("Enter the output path or folder: "); var output = Console.ReadLine()!.Trim(); if (Directory.Exists(output)) diff --git a/WTT/WTT/Table.cs b/WTT/WTT/Table.cs index 54ba5d8..04d636f 100644 --- a/WTT/WTT/Table.cs +++ b/WTT/WTT/Table.cs @@ -1,8 +1,7 @@ using UAssetAPI.PropertyTypes.Structs; using UAssetAPI.UnrealTypes; -using WTT; -namespace WhackTranslationTool; +namespace WTT; public class Table { diff --git a/WTT/WTT/TableExporter.cs b/WTT/WTT/TableExporter.cs index b295579..c0d13e3 100644 --- a/WTT/WTT/TableExporter.cs +++ b/WTT/WTT/TableExporter.cs @@ -1,12 +1,9 @@ using Tommy; using UAssetAPI; using UAssetAPI.PropertyTypes.Structs; -using UAssetAPI.UnrealTypes; -using WhackTranslationTool.Exceptions; -using WTT; - -namespace WhackTranslationTool; +using WTT.Exceptions; +namespace WTT; public class TableExporter { @@ -38,6 +35,12 @@ public class TableExporter tomlTable.AddMessage(entry, 0, "JapaneseMessage"); if (_settings.ExportEnglishUSAMessage) tomlTable.AddMessage(entry, 1, "EnglishMessageUSA"); + if (_settings.ExportEnglishSGMessage) + tomlTable.AddMessage(entry, 2, "EnglishMessageSG"); + if (_settings.ExportTChineseTWMessage) + tomlTable.AddMessage(entry, 3, "TraditionalChineseMessageTW"); + if (_settings.ExportTChineseHKMessage) + tomlTable.AddMessage(entry, 4, "TraditionalChineseMessageHK"); if (_settings.ExportSChineseMessage) tomlTable.AddMessage(entry, 5, "SimplifiedChineseMessage"); if (_settings.ExportKoreanMessage) @@ -53,6 +56,12 @@ public class TableExporter tomlTable.AddMessage(entry, 3, "JapaneseMessage"); if (_settings.ExportEnglishUSAMessage) tomlTable.AddMessage(entry, 4, "EnglishMessageUSA"); + if (_settings.ExportEnglishSGMessage) + tomlTable.AddMessage(entry, 5, "EnglishMessageSG"); + if (_settings.ExportTChineseTWMessage) + tomlTable.AddMessage(entry, 6, "TraditionalChineseMessageTW"); + if (_settings.ExportTChineseHKMessage) + tomlTable.AddMessage(entry, 7, "TraditionalChineseMessageHK"); if (_settings.ExportSChineseMessage) tomlTable.AddMessage(entry, 8, "SimplifiedChineseMessage"); if (_settings.ExportKoreanMessage) diff --git a/WTT/WTT/TableImporter.cs b/WTT/WTT/TableImporter.cs index 3bceb12..37e4285 100644 --- a/WTT/WTT/TableImporter.cs +++ b/WTT/WTT/TableImporter.cs @@ -1,13 +1,9 @@ -using System.Text; using Tommy; using UAssetAPI; -using UAssetAPI.Kismet.Bytecode.Expressions; -using UAssetAPI.PropertyTypes.Structs; using UAssetAPI.UnrealTypes; -using WhackTranslationTool.Exceptions; -using WTT; +using WTT.Exceptions; -namespace WhackTranslationTool; +namespace WTT; public class TableImporter { @@ -21,7 +17,7 @@ public class TableImporter /// Path to the toml source import file /// Path to the target uasset file /// When UAssetAPI fails to reconstruct the asset file - public TableImporter(string tomlPath, string assetPath, Language language = Language.EnglishUSA) + public TableImporter(string tomlPath, string assetPath, Language language) { this.language = language; diff --git a/WTT/WTT/YesNoPrompt.cs b/WTT/WTT/YesNoPrompt.cs index 75881d5..a39c6f6 100644 --- a/WTT/WTT/YesNoPrompt.cs +++ b/WTT/WTT/YesNoPrompt.cs @@ -1,6 +1,6 @@ using System; -namespace WhackTranslationTool +namespace WTT { internal class YesNoPrompt {