Design Patterns: Load orders by filename, export prompts for filename format

Closes #512
This commit is contained in:
Kurt
2021-10-16 16:38:33 -07:00
parent 9594e61d27
commit 6fb4569ce3
13 changed files with 40 additions and 27 deletions

View File

@@ -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!

View File

@@ -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!

View File

@@ -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!

View File

@@ -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!

View File

@@ -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!

View File

@@ -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!

View File

@@ -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!

View File

@@ -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=文件夹不存在!

View File

@@ -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!

View File

@@ -139,12 +139,13 @@ private static void Dump(this IVillager v, string path)
/// </summary>
/// <param name="sav">Save Data to dump from</param>
/// <param name="path">Path to dump to</param>
public static void DumpDesigns(this MainSave sav, string path)
/// <param name="indexed">Export file names prepended with design index</param>
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)
/// </summary>
/// <param name="patterns">Patterns to dump</param>
/// <param name="path">Path to dump to</param>
public static void Dump(this IReadOnlyList<DesignPattern> patterns, string path)
/// <param name="indexed">Export file names prepended with design index</param>
public static void Dump(this IReadOnlyList<DesignPattern> 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);
}
/// <summary>
@@ -210,12 +209,13 @@ public static void Load(this DesignPattern[] patterns, string path, bool changeO
/// </summary>
/// <param name="sav">Save Data to dump from</param>
/// <param name="path">Path to dump to</param>
public static void DumpDesignsPRO(this MainSave sav, string path)
/// <param name="indexed">Export file names prepended with design index</param>
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)
/// </summary>
/// <param name="patterns">Patterns to dump</param>
/// <param name="path">Path to dump to</param>
public static void Dump(this IReadOnlyList<DesignPatternPRO> patterns, string path)
/// <param name="indexed">Export file names prepended with design index</param>
public static void Dump(this IReadOnlyList<DesignPatternPRO> 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<DesignPatternPRO> patterns, string pa
/// <param name="patterns">Patterns to load</param>
/// <param name="path">Path to load from</param>
/// <param name="changeOrigins">Change origins of Patterns</param>
public static void Load(this DesignPatternPRO[] patterns, string path, bool changeOrigins)
/// <param name="sortAlpha">Sort the files by file name instead of depending on the Operating System's return order</param>
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);
}
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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!";