From 52a9c3ae1d5fdd5a7c720fba011e5371392ee99f Mon Sep 17 00:00:00 2001 From: Amr Shaheen Date: Mon, 13 Jun 2022 01:36:31 +0200 Subject: [PATCH] changes for v1.5 --- UE4localizationsTool/Commads.cs | 236 +++++++++++++++++- UE4localizationsTool/Program.cs | 27 +- .../Properties/AssemblyInfo.cs | 2 +- UE4localizationsTool/UpdateInfo.txt | 4 +- 4 files changed, 252 insertions(+), 17 deletions(-) diff --git a/UE4localizationsTool/Commads.cs b/UE4localizationsTool/Commads.cs index e1539ea..e229ccd 100644 --- a/UE4localizationsTool/Commads.cs +++ b/UE4localizationsTool/Commads.cs @@ -3,15 +3,27 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text.RegularExpressions; namespace UE4localizationsTool { public class Commads { private List> Strings; - private int SizeOfRecord = 0; - public Commads(string Options, string SourcePath) + private bool usefilter = false; + private bool UseMatching = false; + private bool RegularExpression = false; + private bool ReverseMode = false; + private List ArrayValues; + public Commads(string Options, string SourcePath, bool UseFilter = false) { + usefilter = UseFilter; + + if (usefilter) + { + GetFilterValues(); + } + string[] Paths; string ConsoleText; @@ -25,7 +37,12 @@ public Commads(string Options, string SourcePath) Console.ForegroundColor = ConsoleColor.White; Strings = Export(SourcePath); - SizeOfRecord = Strings.Count; + + if (usefilter) + { + Strings = ApplyFilter(Strings); + } + Console.ForegroundColor = ConsoleColor.Green; Console.SetCursorPosition(ConsoleText.Length, Console.CursorTop - 1); Console.WriteLine("Done"); @@ -90,6 +107,7 @@ private void SaveTextFile(string FilePath) string[] stringsArray = new string[Strings.Count]; int i = 0; + foreach (var item in Strings) { if (item[0] == "[~PATHFile~]") @@ -167,14 +185,20 @@ private void ExportFolder(string FolderPath) ConsoleText = $"[{ i + 1}:{LanguageFiles.Count()}] Exporting... '{Path.GetFileName(LanguageFiles[i])}' "; Console.WriteLine(ConsoleText); Console.ForegroundColor = ConsoleColor.White; - Strings.Add(new List() { "[~PATHFile~]", "", "[~PATHFile~]" }); + int ThisPosition = Strings.Count - 1; try { + List> Souce = Export(LanguageFiles[i]); + + if (usefilter) + { + Souce = ApplyFilter(Souce); + } + + Strings.Add(new List() { "[~PATHFile~]", "[PATH]" + Souce.Count + "*" + LanguageFiles[i].Replace(FolderPath, "") + "[PATH]", "[~PATHFile~]" }); Strings.AddRange(Souce); - SizeOfRecord = Souce.Count; - Strings[ThisPosition][1] = "[PATH]" + SizeOfRecord + "*" + LanguageFiles[i].Replace(FolderPath, "") + "[PATH]"; } catch (Exception EX) { @@ -186,9 +210,6 @@ private void ExportFolder(string FolderPath) Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Can't parse it, the tool will skip this file.\n" + EX.Message); Console.ForegroundColor = ConsoleColor.White; - if (Strings.Count != 0) - Strings.RemoveAt(Strings.Count - 1); - continue; } @@ -202,6 +223,13 @@ private void ExportFolder(string FolderPath) void EditList(List> Strings, string[] StringValues) { + + if (usefilter) + { + ApplyFilter(Strings, StringValues); + return; + } + if (StringValues.Length < Strings.Count) { throw new Exception("Text file is too short"); @@ -331,5 +359,195 @@ private void ImportFolder(string FolderPath, string[] Values, string Option) } + + private void GetFilterValues() + { + + if (!File.Exists("FilterValues.txt")) + { + throw new Exception("Can't find 'FilterValues.txt' file, open the GUI and create new one from (Tool>Filter)"); + } + + try + { + List FV = new List(); + FV.AddRange(File.ReadAllLines("FilterValues.txt")); + string[] Controls = FV[0].Split(new char[] { '|' }); + bool.TryParse(Controls[0], out UseMatching); + bool.TryParse(Controls[1], out RegularExpression); + bool.TryParse(Controls[2], out ReverseMode); + FV.RemoveAt(0); + ArrayValues = FV; + } + catch (Exception ex) + { + throw new Exception("Can't parse 'FilterValues.txt', open the GUI and create new one from (Tool>Filter)\n" + ex.Message); + } + } + + + private List> ApplyFilter(List> Strings) + { + List> FV = new List>(); + for (int x = 0; x < Strings.Count; x++) + { + + bool CanAdd = false; + + + ArrayValues.ForEach(Value => + { + + if (UseMatching) + { + if (RegularExpression) + { + try + { + if (Regex.IsMatch(Strings[x][0], Value)) + { + CanAdd = true; + } + + } + catch { } + } + else + { + if (Strings[x][0] == Value) + { + CanAdd = true; + } + } + } + else + { + if (RegularExpression) + { + try + { + if (Regex.IsMatch(Strings[x][0], Value, RegexOptions.IgnoreCase)) + { + CanAdd = true; + } + } + catch { } + } + else + { + if (Strings[x][0].IndexOf(Value, StringComparison.OrdinalIgnoreCase) >= 0) + { + CanAdd = true; + } + } + } + }); + + if (CanAdd) + { + if (!ReverseMode) + FV.Add(Strings[x]); + } + else if (ReverseMode) + { + FV.Add(Strings[x]); + } + } + return FV; + } + + + private void ApplyFilter(List> Strings, string[] Array) + { + int i = 0; + for (int x = 0; x < Strings.Count; x++) + { + + bool CanAdd = false; + + + ArrayValues.ForEach(Value => + { + + if (UseMatching) + { + if (RegularExpression) + { + try + { + if (Regex.IsMatch(Strings[x][0], Value)) + { + CanAdd = true; + } + + } + catch { } + } + else + { + if (Strings[x][0] == Value) + { + CanAdd = true; + } + } + } + else + { + if (RegularExpression) + { + try + { + if (Regex.IsMatch(Strings[x][0], Value, RegexOptions.IgnoreCase)) + { + CanAdd = true; + } + } + catch { } + } + else + { + if (Strings[x][0].IndexOf(Value, StringComparison.OrdinalIgnoreCase) >= 0) + { + CanAdd = true; + } + } + } + }); + + if (CanAdd) + { + if (!ReverseMode) + { + try + { + Strings[x][1] = Array[i].Split(new char[] { '=' }, 2)[1]; + i++; + } + catch + { + throw new Exception("Can't parse this line from text file: " + Array[i]); + } + } + } + else if (ReverseMode) + { + try + { + Strings[x][1] = Array[i].Split(new char[] { '=' }, 2)[1]; + i++; + } + catch + { + throw new Exception("Can't parse this line from text file: " + Array[i]); + } + } + } + } + + + + } + } + diff --git a/UE4localizationsTool/Program.cs b/UE4localizationsTool/Program.cs index b834909..e5c8664 100644 --- a/UE4localizationsTool/Program.cs +++ b/UE4localizationsTool/Program.cs @@ -18,8 +18,17 @@ internal static class Program $"{AppDomain.CurrentDomain.FriendlyName} exportall \n" + $"{AppDomain.CurrentDomain.FriendlyName} importall \n" + $"{AppDomain.CurrentDomain.FriendlyName} -importall \n\n" + - "- for import without rename file be careful with this command."; + "- for import without rename file be careful with this command.\n\n" + + "To use last filter you applied before in GUI, add (TRUE) after command line\n" + + "filter will apply only in name table (Remember to apply the same filter when importing)\n\n" + + "Examples:\n" + + $"{AppDomain.CurrentDomain.FriendlyName} export Actions.uasset\n" + + $"{AppDomain.CurrentDomain.FriendlyName} import Actions.uasset.txt\n" + + $"{AppDomain.CurrentDomain.FriendlyName} exportall Actions\n" + + $"{AppDomain.CurrentDomain.FriendlyName} exportall Actions True\n" + + $"{AppDomain.CurrentDomain.FriendlyName} importall Actions\n" + + $"{AppDomain.CurrentDomain.FriendlyName} importall Actions True"; [STAThread] @@ -31,7 +40,7 @@ static void Main(string[] args) { AttachConsole(ATTACH_PARENT_PROCESS); Console.SetCursorPosition(0, Console.CursorTop + 1); - + bool UseFilter = false; if (args.Length < 2) { Console.ForegroundColor = ConsoleColor.Red; @@ -49,14 +58,22 @@ static void Main(string[] args) Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid number of arguments.\n" + commandlines); Console.ForegroundColor = ConsoleColor.White; + return; } - - new Commads(args[0], args[1] + "*" + args[2]); + if (args.Length > 3) + { + bool.TryParse(args[3], out UseFilter); + } + new Commads(args[0], args[1] + "*" + args[2], UseFilter); } else { - new Commads(args[0], args[1]); + if (args.Length > 2) + { + bool.TryParse(args[2], out UseFilter); + } + new Commads(args[0], args[1], UseFilter); } } diff --git a/UE4localizationsTool/Properties/AssemblyInfo.cs b/UE4localizationsTool/Properties/AssemblyInfo.cs index 42c445f..f05b610 100644 --- a/UE4localizationsTool/Properties/AssemblyInfo.cs +++ b/UE4localizationsTool/Properties/AssemblyInfo.cs @@ -32,4 +32,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0")] -[assembly: AssemblyFileVersion("1.4")] +[assembly: AssemblyFileVersion("1.5")] diff --git a/UE4localizationsTool/UpdateInfo.txt b/UE4localizationsTool/UpdateInfo.txt index 141f83a..cb7ab42 100644 --- a/UE4localizationsTool/UpdateInfo.txt +++ b/UE4localizationsTool/UpdateInfo.txt @@ -1,3 +1,3 @@ UpdateFile -Tool_UpdateVer = 1.3 -Tool_UpdateSite = https://github.com/amrshaheen61/UE4LocalizationsTool \ No newline at end of file +Tool_UpdateVer = 1.5 +Tool_UpdateSite = https://github.com/amrshaheen61/UE4LocalizationsTool/releases/tag/v1.5 \ No newline at end of file