From 6fb4569ce384d4c2c6c3b1efd3230fd6fa3fe842 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 16 Oct 2021 16:38:33 -0700 Subject: [PATCH] Design Patterns: Load orders by filename, export prompts for filename format Closes #512 --- .../Resources/text/de/MessageStrings_de.txt | 1 + .../Resources/text/en/MessageStrings_en.txt | 1 + .../Resources/text/es/MessageStrings_es.txt | 1 + .../Resources/text/fr/MessageStrings_fr.txt | 1 + .../Resources/text/it/MessageStrings_it.txt | 1 + .../Resources/text/jp/MessageStrings_jp.txt | 1 + .../Resources/text/ko/MessageStrings_ko.txt | 1 + .../Resources/text/zhs/MessageStrings_zhs.txt | 1 + .../Resources/text/zht/MessageStrings_zht.txt | 1 + NHSE.Core/Structures/GameFileDumper.cs | 51 ++++++++++--------- NHSE.WinForms/Subforms/Map/PatternEditor.cs | 3 +- .../Subforms/Map/PatternEditorPRO.cs | 3 +- NHSE.WinForms/Util/MessageStrings.cs | 1 + 13 files changed, 40 insertions(+), 27 deletions(-) diff --git a/NHSE.Core/Resources/text/de/MessageStrings_de.txt b/NHSE.Core/Resources/text/de/MessageStrings_de.txt index c3d752e..79129f6 100644 --- a/NHSE.Core/Resources/text/de/MessageStrings_de.txt +++ b/NHSE.Core/Resources/text/de/MessageStrings_de.txt @@ -7,6 +7,7 @@ MsgAskUpdateValues=Update values? MsgAskContinue=Continue? MsgAskWriteAnyway=Write anyway? MsgAskExportResultToClipboard=Export results to clipboard? +MsgAskExportResultsWithFileIndex=Export results with file index at the front of the file name? MsgCanceling=Canceling: MsgInvalidHexValue=Bad hex value. MsgImportDirectoryDoesNotExist=Directory does not exist! diff --git a/NHSE.Core/Resources/text/en/MessageStrings_en.txt b/NHSE.Core/Resources/text/en/MessageStrings_en.txt index c3d752e..79129f6 100644 --- a/NHSE.Core/Resources/text/en/MessageStrings_en.txt +++ b/NHSE.Core/Resources/text/en/MessageStrings_en.txt @@ -7,6 +7,7 @@ MsgAskUpdateValues=Update values? MsgAskContinue=Continue? MsgAskWriteAnyway=Write anyway? MsgAskExportResultToClipboard=Export results to clipboard? +MsgAskExportResultsWithFileIndex=Export results with file index at the front of the file name? MsgCanceling=Canceling: MsgInvalidHexValue=Bad hex value. MsgImportDirectoryDoesNotExist=Directory does not exist! diff --git a/NHSE.Core/Resources/text/es/MessageStrings_es.txt b/NHSE.Core/Resources/text/es/MessageStrings_es.txt index e101dad..c8fae55 100644 --- a/NHSE.Core/Resources/text/es/MessageStrings_es.txt +++ b/NHSE.Core/Resources/text/es/MessageStrings_es.txt @@ -7,6 +7,7 @@ MsgAskUpdateValues=¿Actualizar valores? MsgAskContinue=¿Continuar? MsgAskWriteAnyway=¿Escribir de igual manera? MsgAskExportResultToClipboard=¿Exportar resultados al portapapeles? +MsgAskExportResultsWithFileIndex=Export results with file index at the front of the file name? MsgCanceling=Cancelando: MsgInvalidHexValue=Color hex erróneo. MsgImportDirectoryDoesNotExist=¡La dirección no existe! diff --git a/NHSE.Core/Resources/text/fr/MessageStrings_fr.txt b/NHSE.Core/Resources/text/fr/MessageStrings_fr.txt index 5b9267d..0131173 100644 --- a/NHSE.Core/Resources/text/fr/MessageStrings_fr.txt +++ b/NHSE.Core/Resources/text/fr/MessageStrings_fr.txt @@ -7,6 +7,7 @@ MsgAskUpdateValues=Mettre à jour les valeurs? MsgAskContinue=Continuer? MsgAskWriteAnyway=Ecrire quand même? MsgAskExportResultToClipboard=Exporter les résultats dans le presse-papiers? +MsgAskExportResultsWithFileIndex=Export results with file index at the front of the file name? MsgCanceling=Annulation de: MsgInvalidHexValue=Mauvaise valeur hexadécimale. MsgImportDirectoryDoesNotExist=Le répertoire n'existe pas! diff --git a/NHSE.Core/Resources/text/it/MessageStrings_it.txt b/NHSE.Core/Resources/text/it/MessageStrings_it.txt index a6d64c2..5c711fb 100644 --- a/NHSE.Core/Resources/text/it/MessageStrings_it.txt +++ b/NHSE.Core/Resources/text/it/MessageStrings_it.txt @@ -7,6 +7,7 @@ MsgAskUpdateValues=Aggiornare i valori? MsgAskContinue=Continuare? MsgAskWriteAnyway=Vuoi scrivere comunque? MsgAskExportResultToClipboard=Vuoi copiare i risultati sulla tastiera? +MsgAskExportResultsWithFileIndex=Export results with file index at the front of the file name? MsgCanceling=Annullamento: MsgInvalidHexValue=Valore esadecimale sbagliato. MsgImportDirectoryDoesNotExist=La cartella non esiste! diff --git a/NHSE.Core/Resources/text/jp/MessageStrings_jp.txt b/NHSE.Core/Resources/text/jp/MessageStrings_jp.txt index c3d752e..79129f6 100644 --- a/NHSE.Core/Resources/text/jp/MessageStrings_jp.txt +++ b/NHSE.Core/Resources/text/jp/MessageStrings_jp.txt @@ -7,6 +7,7 @@ MsgAskUpdateValues=Update values? MsgAskContinue=Continue? MsgAskWriteAnyway=Write anyway? MsgAskExportResultToClipboard=Export results to clipboard? +MsgAskExportResultsWithFileIndex=Export results with file index at the front of the file name? MsgCanceling=Canceling: MsgInvalidHexValue=Bad hex value. MsgImportDirectoryDoesNotExist=Directory does not exist! diff --git a/NHSE.Core/Resources/text/ko/MessageStrings_ko.txt b/NHSE.Core/Resources/text/ko/MessageStrings_ko.txt index c3d752e..79129f6 100644 --- a/NHSE.Core/Resources/text/ko/MessageStrings_ko.txt +++ b/NHSE.Core/Resources/text/ko/MessageStrings_ko.txt @@ -7,6 +7,7 @@ MsgAskUpdateValues=Update values? MsgAskContinue=Continue? MsgAskWriteAnyway=Write anyway? MsgAskExportResultToClipboard=Export results to clipboard? +MsgAskExportResultsWithFileIndex=Export results with file index at the front of the file name? MsgCanceling=Canceling: MsgInvalidHexValue=Bad hex value. MsgImportDirectoryDoesNotExist=Directory does not exist! diff --git a/NHSE.Core/Resources/text/zhs/MessageStrings_zhs.txt b/NHSE.Core/Resources/text/zhs/MessageStrings_zhs.txt index ff29928..c26506b 100644 --- a/NHSE.Core/Resources/text/zhs/MessageStrings_zhs.txt +++ b/NHSE.Core/Resources/text/zhs/MessageStrings_zhs.txt @@ -7,6 +7,7 @@ MsgAskUpdateValues=更新数值? MsgAskContinue=继续? MsgAskWriteAnyway=强行写入? MsgAskExportResultToClipboard=导出结果到剪贴板? +MsgAskExportResultsWithFileIndex=Export results with file index at the front of the file name? MsgCanceling=取消中: MsgInvalidHexValue=无效的16进制值。 MsgImportDirectoryDoesNotExist=文件夹不存在! diff --git a/NHSE.Core/Resources/text/zht/MessageStrings_zht.txt b/NHSE.Core/Resources/text/zht/MessageStrings_zht.txt index c3d752e..79129f6 100644 --- a/NHSE.Core/Resources/text/zht/MessageStrings_zht.txt +++ b/NHSE.Core/Resources/text/zht/MessageStrings_zht.txt @@ -7,6 +7,7 @@ MsgAskUpdateValues=Update values? MsgAskContinue=Continue? MsgAskWriteAnyway=Write anyway? MsgAskExportResultToClipboard=Export results to clipboard? +MsgAskExportResultsWithFileIndex=Export results with file index at the front of the file name? MsgCanceling=Canceling: MsgInvalidHexValue=Bad hex value. MsgImportDirectoryDoesNotExist=Directory does not exist! diff --git a/NHSE.Core/Structures/GameFileDumper.cs b/NHSE.Core/Structures/GameFileDumper.cs index 717a49d..1d4504b 100644 --- a/NHSE.Core/Structures/GameFileDumper.cs +++ b/NHSE.Core/Structures/GameFileDumper.cs @@ -139,12 +139,13 @@ private static void Dump(this IVillager v, string path) /// /// Save Data to dump from /// Path to dump to - public static void DumpDesigns(this MainSave sav, string path) + /// Export file names prepended with design index + public static void DumpDesigns(this MainSave sav, string path, bool indexed) { for (int i = 0; i < sav.Offsets.PatternCount; i++) { var dp = sav.GetDesign(i); - dp.Dump(path, i); + dp.Dump(path, i, indexed); } } @@ -153,27 +154,25 @@ public static void DumpDesigns(this MainSave sav, string path) /// /// Patterns to dump /// Path to dump to - public static void Dump(this IReadOnlyList patterns, string path) + /// Export file names prepended with design index + public static void Dump(this IReadOnlyList patterns, string path, bool indexed) { for (var index = 0; index < patterns.Count; index++) { var dp = patterns[index]; - dp.Dump(path, index); + dp.Dump(path, index, indexed); } } - private static void Dump(this DesignPattern dp, string path, int index) + private static void Dump(this DesignPattern dp, string path, int index, bool indexed) { - // Dump without index var name = dp.DesignName; - var fn = StringUtil.CleanFileName($"{name}.nhd"); + string fn = indexed + ? $"{index:00} - {name}.nhd" + : $"{name}.nhd"; + fn = StringUtil.CleanFileName(fn); var dest = Path.Combine(path, fn); File.WriteAllBytes(dest, dp.Data); - - // Dump with index - fn = StringUtil.CleanFileName($"{index:00} - {name}.nhd"); - dest = Path.Combine(path, fn); - File.WriteAllBytes(dest, dp.Data); } /// @@ -210,12 +209,13 @@ public static void Load(this DesignPattern[] patterns, string path, bool changeO /// /// Save Data to dump from /// Path to dump to - public static void DumpDesignsPRO(this MainSave sav, string path) + /// Export file names prepended with design index + public static void DumpDesignsPRO(this MainSave sav, string path, bool indexed) { for (int i = 0; i < sav.Offsets.PatternCount; i++) { var dp = sav.GetDesignPRO(i); - dp.Dump(path, i); + dp.Dump(path, i, indexed); } } @@ -224,12 +224,13 @@ public static void DumpDesignsPRO(this MainSave sav, string path) /// /// Patterns to dump /// Path to dump to - public static void Dump(this IReadOnlyList patterns, string path) + /// Export file names prepended with design index + public static void Dump(this IReadOnlyList patterns, string path, bool indexed) { for (var index = 0; index < patterns.Count; index++) { var dp = patterns[index]; - dp.Dump(path, index); + dp.Dump(path, index, indexed); } } @@ -239,12 +240,15 @@ public static void Dump(this IReadOnlyList patterns, string pa /// Patterns to load /// Path to load from /// Change origins of Patterns - public static void Load(this DesignPatternPRO[] patterns, string path, bool changeOrigins) + /// Sort the files by file name instead of depending on the Operating System's return order + public static void Load(this DesignPatternPRO[] patterns, string path, bool changeOrigins, bool sortAlpha = true) { if (patterns.Length == 0) return; var files = Directory.GetFiles(path, "*.nhpd", SearchOption.TopDirectoryOnly); + if (sortAlpha) + Array.Sort(files); int ctr = 0; foreach (var f in files) { @@ -262,18 +266,15 @@ public static void Load(this DesignPatternPRO[] patterns, string path, bool chan } } - private static void Dump(this DesignPatternPRO dp, string path, int index) + private static void Dump(this DesignPatternPRO dp, string path, int index, bool indexed) { - // Dump without index var name = dp.DesignName; - var fn = StringUtil.CleanFileName($"{name}.nhpd"); + string fn = indexed + ? $"{index:00} - {name}.nhd" + : $"{name}.nhd"; + fn = StringUtil.CleanFileName(fn); var dest = Path.Combine(path, fn); File.WriteAllBytes(dest, dp.Data); - - // Dump with index - fn = StringUtil.CleanFileName($"{index:00} - {name}.nhpd"); - dest = Path.Combine(path, fn); - File.WriteAllBytes(dest, dp.Data); } } } diff --git a/NHSE.WinForms/Subforms/Map/PatternEditor.cs b/NHSE.WinForms/Subforms/Map/PatternEditor.cs index 354d35d..2ff1279 100644 --- a/NHSE.WinForms/Subforms/Map/PatternEditor.cs +++ b/NHSE.WinForms/Subforms/Map/PatternEditor.cs @@ -67,7 +67,8 @@ private void B_DumpDesign_Click(object sender, EventArgs e) var dir = Path.GetDirectoryName(fbd.SelectedPath); if (dir == null || !Directory.Exists(dir)) return; - Patterns.Dump(fbd.SelectedPath); + bool indexed = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MessageStrings.MsgAskExportResultsWithFileIndex) == DialogResult.Yes; + Patterns.Dump(fbd.SelectedPath, indexed); return; } diff --git a/NHSE.WinForms/Subforms/Map/PatternEditorPRO.cs b/NHSE.WinForms/Subforms/Map/PatternEditorPRO.cs index 0f76803..77e22a4 100644 --- a/NHSE.WinForms/Subforms/Map/PatternEditorPRO.cs +++ b/NHSE.WinForms/Subforms/Map/PatternEditorPRO.cs @@ -66,7 +66,8 @@ private void B_DumpDesign_Click(object sender, EventArgs e) var dir = Path.GetDirectoryName(fbd.SelectedPath); if (dir == null || !Directory.Exists(dir)) return; - Patterns.Dump(fbd.SelectedPath); + bool indexed = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MessageStrings.MsgAskExportResultsWithFileIndex) == DialogResult.Yes; + Patterns.Dump(fbd.SelectedPath, indexed); return; } diff --git a/NHSE.WinForms/Util/MessageStrings.cs b/NHSE.WinForms/Util/MessageStrings.cs index b4b3755..467afe1 100644 --- a/NHSE.WinForms/Util/MessageStrings.cs +++ b/NHSE.WinForms/Util/MessageStrings.cs @@ -14,6 +14,7 @@ public static class MessageStrings public static string MsgAskContinue { get; set; } = "Continue?"; public static string MsgAskWriteAnyway { get; set; } = "Write anyway?"; public static string MsgAskExportResultToClipboard { get; set; } = "Export results to clipboard?"; + public static string MsgAskExportResultsWithFileIndex { get; set; } = "Export results with file index at the front of the file name?"; public static string MsgCanceling { get; set; } = "Canceling:"; public static string MsgInvalidHexValue { get; set; } = "Bad hex value."; public static string MsgImportDirectoryDoesNotExist { get; set; } = "Directory does not exist!";