From c3ae4b51a03ff00bffe7d0fe570c12820241063c Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Sun, 9 May 2021 16:03:18 +0200 Subject: [PATCH] Pause interp at low disk space, only cancel if very low --- Code/OS/AiProcessSuspend.cs | 12 ++++++++++++ Code/Program.cs | 26 +++++++++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Code/OS/AiProcessSuspend.cs b/Code/OS/AiProcessSuspend.cs index d62e14e..9d67b78 100644 --- a/Code/OS/AiProcessSuspend.cs +++ b/Code/OS/AiProcessSuspend.cs @@ -26,6 +26,18 @@ namespace Flowframes.OS Program.mainForm.GetPauseBtn().Visible = running; } + public static void SuspendIfRunning () + { + if(!aiProcFrozen) + SuspendResumeAi(true); + } + + public static void ResumeIfPaused() + { + if (aiProcFrozen) + SuspendResumeAi(false); + } + public static void SuspendResumeAi(bool freeze, bool excludeCmd = true) { if (AiProcess.lastAiProcess == null || AiProcess.lastAiProcess.HasExited) diff --git a/Code/Program.cs b/Code/Program.cs index 49ab539..05b2363 100644 --- a/Code/Program.cs +++ b/Code/Program.cs @@ -1,5 +1,6 @@ using Flowframes.Data; using Flowframes.IO; +using Flowframes.OS; using System; using System.Collections.Generic; using System.Threading; @@ -73,7 +74,7 @@ namespace Flowframes { try { - if (Interpolate.current.tempFolder.Length < 3) + if (Interpolate.current == null || Interpolate.current.tempFolder.Length < 3) return; string drivePath = Interpolate.current.tempFolder.Substring(0, 2); @@ -81,12 +82,27 @@ namespace Flowframes Logger.Log($"Disk space check for '{drivePath}/': {(mb / 1024f).ToString("0.0")} GB free.", true); - if (!Interpolate.canceled && mb < (Config.GetInt("minDiskSpaceGb", 5) * 1024)) - Interpolate.Cancel("Running out of disk space!"); + bool lowDiskSpace = mb < (Config.GetInt("lowDiskSpacePauseGb", 5) * 1024 * 1000); + bool tooLowDiskSpace = mb < (Config.GetInt("lowDiskSpaceCancelGb", 2) * 1024); + string spaceGb = (mb / 1024f).ToString("0.0"); + + if (!Interpolate.canceled && (AiProcess.lastAiProcess != null && !AiProcess.lastAiProcess.HasExited) && lowDiskSpace) + { + if (tooLowDiskSpace) + { + Interpolate.Cancel($"Not enough disk space on '{drivePath}/' ({spaceGb} GB)!"); + } + else + { + AiProcessSuspend.SuspendIfRunning(); + MessageBox.Show($"Interpolation has been paused because you are running out of disk space on '{drivePath}/' ({spaceGb} GB)!\n\n" + + $"Please either clear up some disk space or cancel the interpolation.", "Warning"); + } + } } - catch + catch (Exception e) { - // Disk space check failed, this is not critical and might just be caused by a null ref + Logger.Log($"Disk space check failed: {e.Message}", true); } }