From 852bd2af209ec606c10827f2deab970e803e8b8c Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 3 Jan 2020 15:53:48 -0800 Subject: [PATCH] Relocate gui-only text files to WinForms project Split up the DataUtil method to load text files so that the caching functionality can be reused --- PKHeX.Core/PKHeX.Core.csproj | 17 -- PKHeX.Core/Util/DataUtil.cs | 25 +- .../Properties/Resources.Designer.cs | 243 +++++++++++++++++- PKHeX.WinForms/Properties/Resources.resx | 24 ++ .../Resources/text}/lang_de.txt | 0 .../Resources/text}/lang_en.txt | 0 .../Resources/text}/lang_es.txt | 0 .../Resources/text}/lang_fr.txt | 0 .../Resources/text}/lang_it.txt | 0 .../Resources/text}/lang_ja.txt | 0 .../Resources/text}/lang_ko.txt | 0 .../Resources/text}/lang_zh.txt | 0 PKHeX.WinForms/Util/WinFormsTranslator.cs | 5 +- 13 files changed, 281 insertions(+), 33 deletions(-) rename {PKHeX.Core/Resources/text/de => PKHeX.WinForms/Resources/text}/lang_de.txt (100%) rename {PKHeX.Core/Resources/text/en => PKHeX.WinForms/Resources/text}/lang_en.txt (100%) rename {PKHeX.Core/Resources/text/es => PKHeX.WinForms/Resources/text}/lang_es.txt (100%) rename {PKHeX.Core/Resources/text/fr => PKHeX.WinForms/Resources/text}/lang_fr.txt (100%) rename {PKHeX.Core/Resources/text/it => PKHeX.WinForms/Resources/text}/lang_it.txt (100%) rename {PKHeX.Core/Resources/text/ja => PKHeX.WinForms/Resources/text}/lang_ja.txt (100%) rename {PKHeX.Core/Resources/text/ko => PKHeX.WinForms/Resources/text}/lang_ko.txt (100%) rename {PKHeX.Core/Resources/text/zh => PKHeX.WinForms/Resources/text}/lang_zh.txt (100%) diff --git a/PKHeX.Core/PKHeX.Core.csproj b/PKHeX.Core/PKHeX.Core.csproj index f4c20dd00..ed0c33bcc 100644 --- a/PKHeX.Core/PKHeX.Core.csproj +++ b/PKHeX.Core/PKHeX.Core.csproj @@ -131,7 +131,6 @@ - @@ -186,7 +185,6 @@ - @@ -241,7 +239,6 @@ - @@ -296,7 +293,6 @@ - @@ -375,7 +371,6 @@ - @@ -430,7 +425,6 @@ - @@ -485,7 +479,6 @@ - @@ -755,7 +748,6 @@ - @@ -923,7 +915,6 @@ - @@ -978,7 +969,6 @@ - @@ -1033,8 +1023,6 @@ - - @@ -1088,7 +1076,6 @@ - @@ -1167,7 +1154,6 @@ - @@ -1222,7 +1208,6 @@ - @@ -1277,7 +1262,6 @@ - @@ -1547,7 +1531,6 @@ - diff --git a/PKHeX.Core/Util/DataUtil.cs b/PKHeX.Core/Util/DataUtil.cs index 825b7a74a..ca8711475 100644 --- a/PKHeX.Core/Util/DataUtil.cs +++ b/PKHeX.Core/Util/DataUtil.cs @@ -126,15 +126,22 @@ public static string[][] GetLanguageStrings10(string fileName) #endregion - public static string[] GetStringList(string f) + public static string[] GetStringList(string fileName) + { + if (IsStringListCached(fileName, out var result)) + return result; + var txt = GetStringResource(fileName); // Fetch File, \n to list. + return LoadStringList(fileName, txt); + } + + public static bool IsStringListCached(string fileName, out string[] result) { lock (getStringListLoadLock) // Make sure only one thread can read the cache - { - if (stringListCache.TryGetValue(f, out var result)) - return (string[])result.Clone(); - } + return stringListCache.TryGetValue(fileName, out result); + } - var txt = GetStringResource(f); // Fetch File, \n to list. + public static string[] LoadStringList(string file, string? txt) + { if (txt == null) return Array.Empty(); string[] rawlist = txt.Split('\n'); @@ -143,14 +150,14 @@ public static string[] GetStringList(string f) lock (getStringListLoadLock) // Make sure only one thread can write to the cache { - if (!stringListCache.ContainsKey(f)) // Check cache again in case of race condition - stringListCache.Add(f, rawlist); + if (!stringListCache.ContainsKey(file)) // Check cache again in case of race condition + stringListCache.Add(file, rawlist); } return (string[])rawlist.Clone(); } - public static string[] GetStringList(string f, string l, string type = "text") => GetStringList($"{type}_{f}_{l}"); + public static string[] GetStringList(string fileName, string lang2char, string type = "text") => GetStringList($"{type}_{fileName}_{lang2char}"); public static byte[] GetBinaryResource(string name) { diff --git a/PKHeX.WinForms/Properties/Resources.Designer.cs b/PKHeX.WinForms/Properties/Resources.Designer.cs index 14ebefcd2..37943ea4d 100644 --- a/PKHeX.WinForms/Properties/Resources.Designer.cs +++ b/PKHeX.WinForms/Properties/Resources.Designer.cs @@ -214,12 +214,13 @@ public class Resources { /// Looks up a localized string similar to PKHeX - By Kaphotics ///http://projectpokemon.org/pkhex/ /// - ///19/11/15 - New Update: - /// - Introducing Sword/Shield support! Thanks @SciresM and @sora10pls for troubleshooting prior to release! - /// - - Initial Legality Checking is provided. Please refer to the forums when reporting legality issues for Generation 8 parsing. - /// - - Bag editing, Pokédex, and Trainer Info editing is provided. - /// - Changed: PKHeX.Core.dll is now merged in with the main executable. - /// - Changed: PKHeX.WinForms spriting has now been split in [rest of string was truncated]";. + ///19/12/26 - New Update: + /// - Legality: + /// - - Added: PP Count verification, Egg TR/StatNature checks, etc. + /// - - Added: More static encounter locations. + /// - - Added: Handling for downleveled raid content, and location crossover comparisons for wild encounters. + /// - - Changed: Encounter yielding pattern for Gen8 is now slightly different from the one used for Gen5-7 (now yields more). + /// - - Fixed: EvolutionTree regressions have been resolved. Please repor [rest of string was truncated]";. /// public static string changelog { get { @@ -507,6 +508,236 @@ public class Resources { } } + /// + /// Looks up a localized string similar to About=About + ///BatchEditor=Batch Editor + ///ErrorWindow=Error + ///KChart=KChart + ///Main=PKHeX + ///MemoryAmie=Memory / Amie Editor + ///RibbonEditor=Ribbon Editor + ///SAV_Apricorn=Apricorn Editor + ///SAV_BerryField=Berry Field Viewer + ///SAV_BoxLayout=Box Layout Editor + ///SAV_BoxList=Storage Viewer + ///SAV_CGearSkin=C-Gear Skin + ///SAV_Database=Database + ///SAV_Encounters=Database + ///SAV_EventFlags=Event Flag Editor + ///SAV_EventReset1=Event Resetter + ///SAV_EventWork=Event Flag Editor + ///SAV_FolderList=Folder List + ///SAV_GameSelect=Game Selection + ///SAV_Hal [rest of string was truncated]";. + /// + public static string lang_de { + get { + return ResourceManager.GetString("lang_de", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to About=About + ///BatchEditor=Batch Editor + ///ErrorWindow=Error + ///KChart=KChart + ///Main=PKHeX + ///MemoryAmie=Memory / Amie Editor + ///RibbonEditor=Ribbon Editor + ///SAV_Apricorn=Apricorn Editor + ///SAV_BerryField=Berry Field Viewer + ///SAV_BoxLayout=Box Layout Editor + ///SAV_BoxList=Storage Viewer + ///SAV_CGearSkin=C-Gear Skin + ///SAV_Database=Database + ///SAV_Encounters=Database + ///SAV_EventFlags=Event Flag Editor + ///SAV_EventReset1=Event Resetter + ///SAV_EventWork=Event Flag Editor + ///SAV_FolderList=Folder List + ///SAV_GameSelect=Game Selection + ///SAV_Hal [rest of string was truncated]";. + /// + public static string lang_en { + get { + return ResourceManager.GetString("lang_en", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to About=Acerca de + ///BatchEditor=Editor por lotes + ///ErrorWindow=Error + ///KChart=KChart + ///Main=PKHeX + ///MemoryAmie=Editor de memorias / Poké Recreo + ///RibbonEditor=Editor de cintas + ///SAV_Apricorn=Editor de Bonguri + ///SAV_BerryField=Visor de campos de bayas + ///SAV_BoxLayout=Editor de fondos de cajas + ///SAV_BoxList=Visor de almacenamiento + ///SAV_CGearSkin=Editor de la apariencia C-Gear + ///SAV_Database=Base de datos + ///SAV_Encounters=Base de datos + ///SAV_EventFlags=Editor de marca de eventos + ///SAV_EventReset1=Reiniciador de eventos + ///SAV_E [rest of string was truncated]";. + /// + public static string lang_es { + get { + return ResourceManager.GetString("lang_es", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to About=À propos + ///BatchEditor=Batch Editor + ///ErrorWindow=Erreur + ///KChart=KChart + ///Main=PKHeX + ///MemoryAmie=Memory / Amie Editor + ///RibbonEditor=Rubans + ///SAV_Apricorn=Noigrumes + ///SAV_BerryField=Champs de Baies + ///SAV_BoxLayout=Fonds de Boîtes + ///SAV_BoxList=Storage Viewer + ///SAV_CGearSkin=Fonds C-Gear + ///SAV_Database=Base de Données + ///SAV_Encounters=Database + ///SAV_EventFlags=Événements dans le Jeu + ///SAV_EventReset1=Réinitialisateur d'événements + ///SAV_EventWork=Event Flag Editor + ///SAV_FolderList=Liste Dossiers + ///SAV_GameSelect=Choix [rest of string was truncated]";. + /// + public static string lang_fr { + get { + return ResourceManager.GetString("lang_fr", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to About=About + ///BatchEditor=Batch Editor + ///ErrorWindow=Error + ///KChart=KChart + ///Main=PKHeX + ///MemoryAmie=Memory / Amie Editor + ///RibbonEditor=Ribbon Editor + ///SAV_Apricorn=Apricorn Editor + ///SAV_BerryField=Berry Field Viewer + ///SAV_BoxLayout=Box Layout Editor + ///SAV_BoxList=Storage Viewer + ///SAV_CGearSkin=C-Gear Skin + ///SAV_Database=Database + ///SAV_Encounters=Database + ///SAV_EventFlags=Event Flag Editor + ///SAV_EventReset1=Event Resetter + ///SAV_EventWork=Event Flag Editor + ///SAV_FolderList=Folder List + ///SAV_GameSelect=Game Selection + ///SAV_Hal [rest of string was truncated]";. + /// + public static string lang_it { + get { + return ResourceManager.GetString("lang_it", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to About=About + ///BatchEditor=バッチエディタ + ///ErrorWindow=エラー + ///KChart=KChart + ///Main=PKHeX + ///MemoryAmie=おもいで + ///RibbonEditor=取得リボン + ///SAV_Apricorn=ぼんぐり + ///SAV_BerryField=きのみ畑 + ///SAV_BoxLayout=ボックスレイアウト + ///SAV_BoxList=ボックスリスト + ///SAV_CGearSkin=Cギア スキン + ///SAV_Database=データベース + ///SAV_Encounters=Database + ///SAV_EventFlags=イベントフラグ + ///SAV_EventReset1=イベントリセット + ///SAV_EventWork=Event Flag Editor + ///SAV_FolderList=フォルダリスト + ///SAV_GameSelect=ゲームバーション + ///SAV_HallOfFame=殿堂入りデータ + ///SAV_HallOfFame7=殿堂入りデータ参照 + ///SAV_HoneyTree=あまいかおりのするき + ///SAV_Inventory=アイテム + ///SAV_Link6=ポケモ [rest of string was truncated]";. + /// + public static string lang_ja { + get { + return ResourceManager.GetString("lang_ja", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to About=About + ///BatchEditor=Batch Editor + ///ErrorWindow=Error + ///KChart=KChart + ///Main=PKHeX + ///MemoryAmie=Memory / Amie Editor + ///RibbonEditor=Ribbon Editor + ///SAV_Apricorn=Apricorn Editor + ///SAV_BerryField=Berry Field Viewer + ///SAV_BoxLayout=Box Layout Editor + ///SAV_BoxList=Storage Viewer + ///SAV_CGearSkin=C-Gear Skin + ///SAV_Database=Database + ///SAV_Encounters=Database + ///SAV_EventFlags=Event Flag Editor + ///SAV_EventReset1=Event Resetter + ///SAV_EventWork=Event Flag Editor + ///SAV_FolderList=Folder List + ///SAV_GameSelect=Game Selection + ///SAV_Hal [rest of string was truncated]";. + /// + public static string lang_ko { + get { + return ResourceManager.GetString("lang_ko", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to About=About + ///BatchEditor=批量编辑器 + ///ErrorWindow=错误 + ///KChart=信息列表 + ///Main=PKHeX + ///MemoryAmie=回忆/清爽乐 + ///RibbonEditor=奖章 + ///SAV_Apricorn=球果编辑 + ///SAV_BerryField=树果田查看器 + ///SAV_BoxLayout=盒子外观 + ///SAV_BoxList=寄放系统 + ///SAV_CGearSkin=C-装置皮肤 + ///SAV_Database=数据库 + ///SAV_Encounters=Database + ///SAV_EventFlags=事件旗标编辑 + ///SAV_EventReset1=事件重置 + ///SAV_EventWork=Event Flag Editor + ///SAV_FolderList=文件夹列表 + ///SAV_GameSelect=游戏选择 + ///SAV_HallOfFame=名人堂 + ///SAV_HallOfFame7=名人堂 + ///SAV_HoneyTree=甜甜蜜树编辑 + ///SAV_Inventory=物品栏 + ///SAV_Link6=宝可梦连接工具 + ///SAV_MailBox=邮箱编辑 + ///SAV_Misc3=训练家数据编辑 /// [rest of string was truncated]";. + /// + public static string lang_zh { + get { + return ResourceManager.GetString("lang_zh", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/PKHeX.WinForms/Properties/Resources.resx b/PKHeX.WinForms/Properties/Resources.resx index 97e0ab4ea..e394935b8 100644 --- a/PKHeX.WinForms/Properties/Resources.resx +++ b/PKHeX.WinForms/Properties/Resources.resx @@ -346,4 +346,28 @@ ..\resources\img\markings\rare_icon_2.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\text\lang_de.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + ..\Resources\text\lang_en.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + ..\Resources\text\lang_es.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + ..\Resources\text\lang_fr.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + ..\Resources\text\lang_it.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + ..\Resources\text\lang_ja.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + ..\Resources\text\lang_ko.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + ..\Resources\text\lang_zh.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + \ No newline at end of file diff --git a/PKHeX.Core/Resources/text/de/lang_de.txt b/PKHeX.WinForms/Resources/text/lang_de.txt similarity index 100% rename from PKHeX.Core/Resources/text/de/lang_de.txt rename to PKHeX.WinForms/Resources/text/lang_de.txt diff --git a/PKHeX.Core/Resources/text/en/lang_en.txt b/PKHeX.WinForms/Resources/text/lang_en.txt similarity index 100% rename from PKHeX.Core/Resources/text/en/lang_en.txt rename to PKHeX.WinForms/Resources/text/lang_en.txt diff --git a/PKHeX.Core/Resources/text/es/lang_es.txt b/PKHeX.WinForms/Resources/text/lang_es.txt similarity index 100% rename from PKHeX.Core/Resources/text/es/lang_es.txt rename to PKHeX.WinForms/Resources/text/lang_es.txt diff --git a/PKHeX.Core/Resources/text/fr/lang_fr.txt b/PKHeX.WinForms/Resources/text/lang_fr.txt similarity index 100% rename from PKHeX.Core/Resources/text/fr/lang_fr.txt rename to PKHeX.WinForms/Resources/text/lang_fr.txt diff --git a/PKHeX.Core/Resources/text/it/lang_it.txt b/PKHeX.WinForms/Resources/text/lang_it.txt similarity index 100% rename from PKHeX.Core/Resources/text/it/lang_it.txt rename to PKHeX.WinForms/Resources/text/lang_it.txt diff --git a/PKHeX.Core/Resources/text/ja/lang_ja.txt b/PKHeX.WinForms/Resources/text/lang_ja.txt similarity index 100% rename from PKHeX.Core/Resources/text/ja/lang_ja.txt rename to PKHeX.WinForms/Resources/text/lang_ja.txt diff --git a/PKHeX.Core/Resources/text/ko/lang_ko.txt b/PKHeX.WinForms/Resources/text/lang_ko.txt similarity index 100% rename from PKHeX.Core/Resources/text/ko/lang_ko.txt rename to PKHeX.WinForms/Resources/text/lang_ko.txt diff --git a/PKHeX.Core/Resources/text/zh/lang_zh.txt b/PKHeX.WinForms/Resources/text/lang_zh.txt similarity index 100% rename from PKHeX.Core/Resources/text/zh/lang_zh.txt rename to PKHeX.WinForms/Resources/text/lang_zh.txt diff --git a/PKHeX.WinForms/Util/WinFormsTranslator.cs b/PKHeX.WinForms/Util/WinFormsTranslator.cs index 524b24be2..beb2c1c1a 100644 --- a/PKHeX.WinForms/Util/WinFormsTranslator.cs +++ b/PKHeX.WinForms/Util/WinFormsTranslator.cs @@ -63,7 +63,10 @@ private static IEnumerable GetTranslationFile(string lang) catch { /* In use? Just return the internal resource. */ } } - return Util.GetStringList(file); + if (Util.IsStringListCached(file, out var result)) + return result; + var txt = (string)Properties.Resources.ResourceManager.GetObject(file); + return Util.LoadStringList(file, txt); } private static IEnumerable GetTranslatableControls(Control f)