Refactor DumpBox to return 1 value

count < 0 implies an error; values >= 0 can be used to indicate actual
dumped count
This commit is contained in:
Kurt 2019-02-09 20:19:55 -08:00
parent 9a93b20515
commit 48e2bbcfed
2 changed files with 22 additions and 20 deletions

View file

@ -17,15 +17,14 @@ namespace PKHeX.Core
/// </summary>
/// <param name="SAV"><see cref="SaveFile"/> that is being dumped from.</param>
/// <param name="path">Folder to store <see cref="PKM"/> files.</param>
/// <param name="result">Result message from the method.</param>
/// <param name="boxFolders">Option to save in child folders with the Box Name as the folder name.</param>
/// <returns></returns>
public static bool DumpBoxes(this SaveFile SAV, string path, out string result, bool boxFolders = false)
/// <returns>-1 if aborted, otherwise the amount of files dumped.</returns>
public static int DumpBoxes(this SaveFile SAV, string path, bool boxFolders = false)
{
var boxdata = SAV.BoxData;
if (boxdata == null)
{ result = MsgSaveBoxExportInvalid; return false; }
if (!SAV.HasBox)
return -1;
var boxdata = SAV.BoxData;
int ctr = 0;
foreach (PKM pk in boxdata)
{
@ -43,9 +42,7 @@ namespace PKHeX.Core
if (!File.Exists(Path.Combine(Path.Combine(path, boxfolder), fileName)))
File.WriteAllBytes(Path.Combine(Path.Combine(path, boxfolder), fileName), pk.DecryptedBoxData);
}
result = string.Format(MsgSaveBoxExportPathCount, ctr) + Environment.NewLine + path;
return true;
return ctr;
}
/// <summary>
@ -53,15 +50,14 @@ namespace PKHeX.Core
/// </summary>
/// <param name="SAV"><see cref="SaveFile"/> that is being dumped from.</param>
/// <param name="path">Folder to store <see cref="PKM"/> files.</param>
/// <param name="result">Result message from the method.</param>
/// <param name="currentBox">Box contents to be dumped.</param>
/// <returns></returns>
public static bool DumpBox(this SaveFile SAV, string path, out string result, int currentBox)
/// <returns>-1 if aborted, otherwise the amount of files dumped.</returns>
public static int DumpBox(this SaveFile SAV, string path, int currentBox)
{
var boxdata = SAV.BoxData;
if (boxdata == null)
{ result = MsgSaveBoxExportInvalid; return false; }
if (!SAV.HasBox)
return -1;
var boxdata = SAV.BoxData;
int ctr = 0;
foreach (PKM pk in boxdata)
{
@ -73,9 +69,7 @@ namespace PKHeX.Core
if (!File.Exists(Path.Combine(path, fileName)))
File.WriteAllBytes(Path.Combine(path, fileName), pk.DecryptedBoxData);
}
result = string.Format(MsgSaveBoxExportPathCount, ctr) + Environment.NewLine + path;
return true;
return ctr;
}
/// <summary>

View file

@ -814,7 +814,11 @@ namespace PKHeX.WinForms.Controls
Directory.CreateDirectory(path);
SAV.DumpBoxes(path, out result, separate);
var count = SAV.DumpBoxes(path, separate);
if (count < 0)
result = MsgSaveBoxExportInvalid;
else
result = string.Format(MsgSaveBoxExportPathCount, count) + Environment.NewLine + path;
return true;
}
@ -828,7 +832,11 @@ namespace PKHeX.WinForms.Controls
Directory.CreateDirectory(path);
SAV.DumpBox(path, out result, Box.CurrentBox);
var count = SAV.DumpBox(path, Box.CurrentBox);
if (count < 0)
result = MsgSaveBoxExportInvalid;
else
result = string.Format(MsgSaveBoxExportPathCount, count) + Environment.NewLine + path;
return true;
}