From 04eabc83ac4f00053719d8b6a325fbb4b888d0c3 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sat, 29 Aug 2020 23:09:25 -0700 Subject: [PATCH] Fix blank DAT writing --- SabreTools.Library/DatFiles/DatFile.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index 3faea580..77cdcac1 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -3405,6 +3405,9 @@ namespace SabreTools.Library.DatFiles /// True if the DAT was written correctly, false otherwise 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);