From 31986c6da14b787f9eedae35b7121fc4e1ee4ddc Mon Sep 17 00:00:00 2001 From: NBKRedSpy <54865934+NBKRedSpy@users.noreply.github.com> Date: Mon, 15 Jan 2024 17:21:32 -0500 Subject: [PATCH] Unicode Auto Detect escaping. Fixes Unicode format thinking a file was escaped due to incorrect RegEx pattern. --- .../CardSurvival-Localization.csproj | 4 +- CardSurvival-Localization/Program.cs | 2 +- .../Properties/launchSettings.json | 2 +- .../ProcessModTests.cs | 68 +++++++++++++++++++ README.md | 5 +- README.txt | 5 +- 6 files changed, 80 insertions(+), 6 deletions(-) diff --git a/CardSurvival-Localization/CardSurvival-Localization.csproj b/CardSurvival-Localization/CardSurvival-Localization.csproj index 9085866..982e493 100644 --- a/CardSurvival-Localization/CardSurvival-Localization.csproj +++ b/CardSurvival-Localization/CardSurvival-Localization.csproj @@ -6,8 +6,8 @@ CardSurvival_Localization enable enable - 3.3.0 - 3.3.0 + 3.3.1 + 3.3.1 $(AssemblyName) diff --git a/CardSurvival-Localization/Program.cs b/CardSurvival-Localization/Program.cs index 9c96915..a47695f 100644 --- a/CardSurvival-Localization/Program.cs +++ b/CardSurvival-Localization/Program.cs @@ -221,7 +221,7 @@ static int Main(string[] args) /// private static bool IsUnicodeEscaped(string json) { - return Regex.IsMatch(json, @"u[a-f0-9]", RegexOptions.IgnoreCase); + return Regex.IsMatch(json, @"\\u[a-f0-9]", RegexOptions.IgnoreCase); } private static string GetErrorsAndWarnings(LocalizationKeyExtrator localizationKeyExtractor) diff --git a/CardSurvival-Localization/Properties/launchSettings.json b/CardSurvival-Localization/Properties/launchSettings.json index b91d7be..7d46fdd 100644 --- a/CardSurvival-Localization/Properties/launchSettings.json +++ b/CardSurvival-Localization/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "CardSurvival-Localization": { "commandName": "Project", - "commandLineArgs": "\"E:\\Downloads\\Games\\Card Survival\\Raft-100-3-8-1703246519\\木筏求生\"" + "commandLineArgs": "\"C:\\work\\localization\\work\"" } } } \ No newline at end of file diff --git a/CardSurvival-LocalizationTests/ProcessModTests.cs b/CardSurvival-LocalizationTests/ProcessModTests.cs index 98d05b4..8029457 100644 --- a/CardSurvival-LocalizationTests/ProcessModTests.cs +++ b/CardSurvival-LocalizationTests/ProcessModTests.cs @@ -1033,6 +1033,74 @@ public void UnicodeEscape_AutoDetect_WithEscaped_Escaped() Assert.Equal(expected, actual); } + + [Fact] + public void UnicodeEscape_AutoDetect_has_u_with_no_backslash_Not() + { + MockFileSystem fs = new MockFileSystem(new Dictionary() + { + {@"x:\test\ModInfo.json", new MockFileData(@"{}") }, + {@"x:\test\test.json", new MockFileData( +""" +{ + 'DefaultStatusName-Existing': { + 'DefaultText': 'u4e00u9635u98d3u98ce', + }, + 'DefaultStatusName-Existing2': { + 'DefaultText': '一阵飓风', + } +} +""" +) + }, + + }, "X:\\test"); + + //Reset date for check for write changes later + SetWriteTimeToMin(fs); + + CardSurvival_Localization.Program.ProcessMod("X:\\test", fs, UnicodeEscapeMode.AutoDetect, true); + + + var expectedFiles = new List() + { + @"x:\test\ModInfo.json", + "x:\\test\\test.json", + "x:\\test\\Localization\\SimpEn.psv", + "x:\\test\\Localization\\SimpEn_Errors.txt" + }; + + Assert.Equal(fs.AllFiles.OrderBy(x => x), expectedFiles.OrderBy(x => x)); + + const string engPath = "x:\\test\\Localization\\SimpEn.psv"; + string actual = fs.File.ReadAllText(engPath); + string expected = +""" +T-mDA3fJ+/j7ZSIYmR2spKmdU2RSs=||u4e00u9635u98d3u98ce +T-COd+NfxU19P/4TdHpGQTg4J8E/k=||一阵飓风 + +"""; + + Assert.Equal(expected, actual); + + actual = fs.File.ReadAllText("x:\\test\\test.json"); + expected = +""" +{ + "DefaultStatusName-Existing": { + "DefaultText": "u4e00u9635u98d3u98ce", + "LocalizationKey": "T-mDA3fJ+/j7ZSIYmR2spKmdU2RSs=" + }, + "DefaultStatusName-Existing2": { + "DefaultText": "一阵飓风", + "LocalizationKey": "T-COd+NfxU19P/4TdHpGQTg4J8E/k=" + } +} +"""; + + Assert.Equal(expected, actual); + } + [Fact] public void UnicodeEscape_AutoDetect_Mixed_Escaped() { diff --git a/README.md b/README.md index 1db3872..d08f022 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ This is not the CSTI-ModLoader. This utility creates an English translation fil See the [Observations From Current Mods](#observations-from-current-mods) section. # Video -A simple tutorial video can be found here: https://youtu.be/svdUEJXaGnY +A simple tutorial video can be found here: https://youtu.be/ABbwkaBecCg ## What Does This Utility Do? @@ -154,6 +154,9 @@ https://github.com/dop-lm/CSTI-ModLoader (Currently the NoReflection branch has # Change Log +## 3.3.1 +* Corrects Unicode format Auto Detection error due to bad match string. + ## 3.3.0 * Added uppercase text for escaped Unicode. By default the ModEditor will uppercase the values. This is optional via the 'u' parameter. * This simplifies comparing the original files to the modified files. diff --git a/README.txt b/README.txt index 74f24d6..2627ffb 100644 --- a/README.txt +++ b/README.txt @@ -14,7 +14,7 @@ See the [Observations From Current Mods](#observations-from-current-mods) sectio [size=3][b]Video[/b][/size] -A simple tutorial video can be found here: https://youtu.be/svdUEJXaGnY +A simple tutorial video can be found here: https://youtu.be/ABbwkaBecCg [size=3][b]What Does This Utility Do?[/b][/size] @@ -185,6 +185,9 @@ https://github.com/dop-lm/CSTI-ModLoader (Currently the NoReflection branch has [size=4][b]Change Log[/b][/size] +[size=3][b]3.3.1[/b][/size] +* Corrects Unicode format Auto Detection error due to bad match string. + [size=3][b]3.3.0[/b][/size] * Added uppercase text for escaped Unicode. By default the ModEditor will uppercase the values. This is optional via the 'u' parameter.