From 068f362d9f2af31e8fc2c9e05253876266dcf4f1 Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Wed, 21 Oct 2020 22:20:59 +0200 Subject: [PATCH] cleanup error handling --- Code/Main/MainForm.cs | 3 +-- Code/Main/Program.cs | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Code/Main/MainForm.cs b/Code/Main/MainForm.cs index 7745f97..b955b25 100644 --- a/Code/Main/MainForm.cs +++ b/Code/Main/MainForm.cs @@ -454,8 +454,7 @@ public void AfterFirstUpscale () private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { - try { Program.Cleanup(); } - catch { } // This is fine if it fails due to locks, runs on startup anyway. + Program.Cleanup(); } public void SetHasPreview (bool state) diff --git a/Code/Main/Program.cs b/Code/Main/Program.cs index 666f8e7..61c2f3e 100644 --- a/Code/Main/Program.cs +++ b/Code/Main/Program.cs @@ -54,16 +54,23 @@ public static MsgBox ShowMessage (string msg, string title = "Message") public static void Cleanup () { - IOUtils.ClearDir(Paths.previewPath); - IOUtils.ClearDir(Paths.previewOutPath); - IOUtils.ClearDir(Paths.clipboardFolderPath); - IOUtils.ClearDir(Paths.imgInPath); - IOUtils.ClearDir(Paths.imgOutPath); - IOUtils.ClearDir(Paths.imgOutNcnnPath); - IOUtils.ClearDir(Paths.tempImgPath.GetParentDir()); - IOUtils.ClearDir(Path.Combine(IOUtils.GetAppDataDir(), "giftemp")); - IOUtils.DeleteIfExists(Path.Combine(Paths.presetsPath, "lastUsed")); - IOUtils.ClearDir(Paths.compositionOut); + try + { + IOUtils.ClearDir(Paths.previewPath); + IOUtils.ClearDir(Paths.previewOutPath); + IOUtils.ClearDir(Paths.clipboardFolderPath); + IOUtils.ClearDir(Paths.imgInPath); + IOUtils.ClearDir(Paths.imgOutPath); + IOUtils.ClearDir(Paths.imgOutNcnnPath); + IOUtils.ClearDir(Paths.tempImgPath.GetParentDir()); + IOUtils.ClearDir(Path.Combine(IOUtils.GetAppDataDir(), "giftemp")); + IOUtils.DeleteIfExists(Path.Combine(Paths.presetsPath, "lastUsed")); + IOUtils.ClearDir(Paths.compositionOut); + } + catch (Exception e) + { + Logger.Log("Error during cleanup: " + e.Message); + } } public static void CloseTempForms ()