2022-11-25 01:42:17 +00:00
|
|
|
#if DEBUG
|
2020-11-28 22:55:09 +00:00
|
|
|
using System;
|
2022-05-06 22:43:51 +00:00
|
|
|
using System.Collections.Generic;
|
2018-04-07 05:06:15 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
2018-04-04 01:46:32 +00:00
|
|
|
using System.Windows.Forms;
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms
|
|
|
|
{
|
|
|
|
public static class DevUtil
|
|
|
|
{
|
2018-06-01 05:40:55 +00:00
|
|
|
public static void AddControl(ToolStripDropDownItem t)
|
|
|
|
{
|
|
|
|
t.DropDownItems.Add(GetTranslationUpdater());
|
|
|
|
}
|
|
|
|
|
2022-11-25 04:03:05 +00:00
|
|
|
private static readonly string[] Languages = {"ja", "fr", "it", "de", "es", "ko", "zh", "zh2"};
|
2020-01-02 03:07:21 +00:00
|
|
|
private const string DefaultLanguage = GameLanguage.DefaultLanguage;
|
2018-04-08 16:19:19 +00:00
|
|
|
|
2019-01-02 04:27:00 +00:00
|
|
|
public static bool IsUpdatingTranslations { get; private set; }
|
|
|
|
|
2018-04-08 16:19:19 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Call this to update all translatable resources (Program Messages, Legality Text, Program GUI)
|
|
|
|
/// </summary>
|
2018-06-01 05:40:55 +00:00
|
|
|
private static void UpdateAll()
|
2018-04-08 16:19:19 +00:00
|
|
|
{
|
2018-06-01 05:40:55 +00:00
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Update translation files with current values?"))
|
|
|
|
return;
|
2019-01-02 04:27:00 +00:00
|
|
|
IsUpdatingTranslations = true;
|
2018-04-08 16:19:19 +00:00
|
|
|
DumpStringsLegality();
|
2018-09-01 21:37:58 +00:00
|
|
|
DumpStringsMessage();
|
2018-04-08 16:19:19 +00:00
|
|
|
UpdateTranslations();
|
2019-01-02 04:27:00 +00:00
|
|
|
IsUpdatingTranslations = false;
|
2018-04-08 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
2018-06-01 05:40:55 +00:00
|
|
|
private static ToolStripMenuItem GetTranslationUpdater()
|
|
|
|
{
|
|
|
|
var ti = new ToolStripMenuItem
|
|
|
|
{
|
|
|
|
ShortcutKeys = Keys.Control | Keys.Alt | Keys.D,
|
2021-08-20 20:49:20 +00:00
|
|
|
Visible = false,
|
2018-06-01 05:40:55 +00:00
|
|
|
};
|
|
|
|
ti.Click += (s, e) => UpdateAll();
|
|
|
|
return ti;
|
|
|
|
}
|
|
|
|
|
2018-04-08 16:19:19 +00:00
|
|
|
private static void UpdateTranslations()
|
2018-04-04 01:46:32 +00:00
|
|
|
{
|
2022-02-27 05:45:31 +00:00
|
|
|
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
|
|
|
|
var types = assembly.GetTypes();
|
2021-04-12 01:09:54 +00:00
|
|
|
// add mode
|
|
|
|
WinFormsTranslator.SetRemovalMode(false);
|
|
|
|
WinFormsTranslator.LoadSettings<PKHeXSettings>(DefaultLanguage);
|
2022-02-27 05:45:31 +00:00
|
|
|
WinFormsTranslator.LoadAllForms(types, LoadBanlist); // populate with every possible control
|
2018-04-04 01:46:32 +00:00
|
|
|
WinFormsTranslator.UpdateAll(DefaultLanguage, Languages); // propagate to others
|
|
|
|
WinFormsTranslator.DumpAll(Banlist); // dump current to file
|
2021-04-12 01:09:54 +00:00
|
|
|
|
|
|
|
// de-populate
|
2018-04-04 01:46:32 +00:00
|
|
|
WinFormsTranslator.SetRemovalMode(); // remove used keys, don't add any
|
2021-04-12 01:09:54 +00:00
|
|
|
WinFormsTranslator.LoadSettings<PKHeXSettings>(DefaultLanguage, false);
|
2022-02-27 05:45:31 +00:00
|
|
|
WinFormsTranslator.LoadAllForms(types, LoadBanlist);
|
2018-04-04 01:46:32 +00:00
|
|
|
WinFormsTranslator.RemoveAll(DefaultLanguage, PurgeBanlist); // remove all lines from above generated files that still remain
|
|
|
|
|
2018-04-08 16:19:19 +00:00
|
|
|
// Move translated files from the debug exe loc to their project location
|
|
|
|
var files = Directory.GetFiles(Application.StartupPath);
|
2021-10-22 05:13:21 +00:00
|
|
|
var dir = GetResourcePath("PKHeX.WinForms", "Resources", "text");
|
2018-04-08 16:19:19 +00:00
|
|
|
foreach (var f in files)
|
|
|
|
{
|
|
|
|
var fn = Path.GetFileName(f);
|
|
|
|
if (!fn.EndsWith(".txt"))
|
|
|
|
continue;
|
|
|
|
if (!fn.StartsWith("lang_"))
|
|
|
|
continue;
|
|
|
|
|
2020-01-26 02:06:04 +00:00
|
|
|
var loc = Path.Combine(dir, fn);
|
2020-01-26 02:12:58 +00:00
|
|
|
if (File.Exists(loc))
|
|
|
|
File.Delete(loc);
|
|
|
|
File.Move(f, loc);
|
|
|
|
// if net framework support is ever removed, use the new overload instead of the stuff above:
|
|
|
|
// File.Move(f, loc, true);
|
2018-04-08 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 01:46:32 +00:00
|
|
|
Application.Exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static readonly string[] LoadBanlist =
|
|
|
|
{
|
|
|
|
nameof(SplashScreen),
|
|
|
|
};
|
|
|
|
|
|
|
|
private static readonly string[] Banlist =
|
|
|
|
{
|
|
|
|
nameof(SplashScreen),
|
|
|
|
"Gender=", // editor gender labels
|
|
|
|
"BTN_Shinytize", // ☆
|
2022-02-05 01:37:13 +00:00
|
|
|
$"{nameof(Main)}.L_SizeH", // height rating
|
|
|
|
$"{nameof(Main)}.L_SizeW", // weight rating
|
2022-11-25 01:42:17 +00:00
|
|
|
$"{nameof(Main)}.L_SizeS", // scale rating
|
2022-02-05 01:37:13 +00:00
|
|
|
$"{nameof(Main)}.B_Box", // << and >> arrows
|
|
|
|
$"{nameof(Main)}.L_Characteristic=", // Characterstic (dynamic)
|
|
|
|
$"{nameof(Main)}.L_Potential", // ★☆☆☆ IV judge evaluation
|
|
|
|
$"{nameof(SAV_HoneyTree)}.L_Tree0", // dynamic, don't bother
|
|
|
|
$"{nameof(SAV_Misc3)}.BTN_Symbol", // symbols should stay as their current character
|
|
|
|
$"{nameof(SAV_GameSelect)}.L_Prompt", // prompt text (dynamic)
|
|
|
|
$"{nameof(SAV_BlockDump8)}.L_BlockName", // Block name (dynamic)
|
|
|
|
$"{nameof(SAV_PokedexResearchEditorLA)}.L_", // Dynamic label
|
2018-04-04 01:46:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private static readonly string[] PurgeBanlist =
|
|
|
|
{
|
|
|
|
nameof(SuperTrainingEditor),
|
|
|
|
nameof(ErrorWindow),
|
|
|
|
nameof(SettingsEditor),
|
|
|
|
};
|
|
|
|
|
2021-10-22 05:13:21 +00:00
|
|
|
private static void DumpStringsMessage() => DumpStrings(typeof(MessageStrings), false, "PKHeX.Core", "Resources", "text", "program");
|
|
|
|
private static void DumpStringsLegality() => DumpStrings(typeof(LegalityCheckStrings), true, "PKHeX.Core", "Resources", "legality", "checks");
|
2018-07-22 02:20:11 +00:00
|
|
|
|
2021-10-22 05:13:21 +00:00
|
|
|
private static void DumpStrings(Type t, bool sorted, params string[] rel)
|
2018-04-04 01:46:32 +00:00
|
|
|
{
|
2021-10-22 05:13:21 +00:00
|
|
|
var dir = GetResourcePath(rel);
|
2018-04-07 05:06:15 +00:00
|
|
|
var langs = new[] {DefaultLanguage}.Concat(Languages);
|
|
|
|
foreach (var lang in langs)
|
|
|
|
{
|
2020-12-22 03:13:18 +00:00
|
|
|
LocalizationUtil.SetLocalization(t, lang);
|
|
|
|
var entries = LocalizationUtil.GetLocalization(t);
|
2022-05-06 22:43:51 +00:00
|
|
|
IEnumerable<string> export = entries.OrderBy(GetName); // sorted lines
|
|
|
|
|
|
|
|
static string GetName(string line)
|
|
|
|
{
|
|
|
|
var index = line.IndexOf('=');
|
|
|
|
if (index == -1)
|
|
|
|
return line;
|
|
|
|
return line[..index];
|
|
|
|
}
|
2018-04-07 05:06:15 +00:00
|
|
|
|
2018-09-01 21:43:26 +00:00
|
|
|
if (!sorted)
|
|
|
|
export = entries;
|
|
|
|
|
2018-04-08 16:19:19 +00:00
|
|
|
var location = GetFileLocationInText(t.Name, dir, lang);
|
|
|
|
File.WriteAllLines(location, export);
|
2020-12-22 03:13:18 +00:00
|
|
|
LocalizationUtil.SetLocalization(t, DefaultLanguage);
|
2018-04-07 05:06:15 +00:00
|
|
|
}
|
2018-04-04 01:46:32 +00:00
|
|
|
}
|
2018-04-08 16:19:19 +00:00
|
|
|
|
|
|
|
private static string GetFileLocationInText(string fileType, string dir, string lang)
|
|
|
|
{
|
|
|
|
var fn = $"{fileType}_{lang}.txt";
|
2021-10-22 05:13:21 +00:00
|
|
|
return Path.Combine(dir, fn);
|
2018-04-08 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 05:13:21 +00:00
|
|
|
private static string GetResourcePath(params string[] subdir)
|
2018-04-08 16:19:19 +00:00
|
|
|
{
|
2022-08-21 08:39:16 +00:00
|
|
|
// Starting from the executable path, crawl upwards until we get to the repository/sln root
|
|
|
|
const string repo = "PKHeX";
|
2018-04-08 16:19:19 +00:00
|
|
|
var path = Application.StartupPath;
|
2022-02-05 01:37:13 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
var parent = Directory.GetParent(path);
|
|
|
|
if (parent is null)
|
|
|
|
throw new DirectoryNotFoundException();
|
|
|
|
path = parent.FullName;
|
2022-08-21 08:39:16 +00:00
|
|
|
if (path.EndsWith(repo))
|
2022-02-05 01:37:13 +00:00
|
|
|
return Path.Combine(path, Path.Combine(subdir));
|
|
|
|
}
|
2018-04-08 16:19:19 +00:00
|
|
|
}
|
2018-04-04 01:46:32 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-28 22:55:09 +00:00
|
|
|
#endif
|