Fix blank DAT writing

This commit is contained in:
Matt Nadareski
2020-08-29 23:09:25 -07:00
parent eb028f4010
commit 04eabc83ac

View File

@@ -3405,6 +3405,9 @@ namespace SabreTools.Library.DatFiles
/// <returns>True if the DAT was written correctly, false otherwise</returns>
public bool Write(string outDir, bool norename = true, bool stats = false, bool ignoreblanks = false, bool overwrite = true)
{
// Force a statistics recheck, just in case
Items.RecalculateStats();
// If there's nothing there, abort
if (Items.TotalCount == 0)
{
@@ -3412,6 +3415,20 @@ namespace SabreTools.Library.DatFiles
return false;
}
// Get a count of all removed items
long removed = 0;
foreach (string key in Items.Keys)
{
removed += Items[key].Count(i => i.Remove);
}
// If every item is removed, abort
if (Items.TotalCount == removed)
{
Globals.Logger.User("There were no items to write out!");
return false;
}
// Ensure the output directory is set and created
outDir = DirectoryExtensions.Ensure(outDir, create: true);