From 50990542fd73f11e14c7362de77fb70b7165cb51 Mon Sep 17 00:00:00 2001 From: rootdarkarchon Date: Wed, 14 Feb 2024 18:57:18 +0100 Subject: [PATCH] add free drive space display, file compactor hint, recalculate size after compacting --- MareSynchronos/FileCache/CacheMonitor.cs | 4 ++++ MareSynchronos/UI/SettingsUi.cs | 24 +++++++++++++++++++----- MareSynchronos/UI/UISharedService.cs | 2 -- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/MareSynchronos/FileCache/CacheMonitor.cs b/MareSynchronos/FileCache/CacheMonitor.cs index abd1549..8a149c5 100644 --- a/MareSynchronos/FileCache/CacheMonitor.cs +++ b/MareSynchronos/FileCache/CacheMonitor.cs @@ -61,6 +61,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase public long CurrentFileProgress => _currentFileProgress; public long FileCacheSize { get; set; } + public long FileCacheDriveFree { get; set; } public ConcurrentDictionary HaltScanLocks { get; set; } = new(StringComparer.Ordinal); public bool IsScanRunning => CurrentFileProgress > 0 || TotalFiles > 0; public long TotalFiles { get; private set; } @@ -369,6 +370,9 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase } }); + DriveInfo di = new DriveInfo(new DirectoryInfo(_configService.Current.CacheFolder).Root.FullName); + FileCacheDriveFree = di.AvailableFreeSpace; + var maxCacheInBytes = (long)(_configService.Current.MaxLocalCacheInGiB * 1024d * 1024d * 1024d); if (FileCacheSize < maxCacheInBytes) return false; diff --git a/MareSynchronos/UI/SettingsUi.cs b/MareSynchronos/UI/SettingsUi.cs index 1315880..4775f47 100644 --- a/MareSynchronos/UI/SettingsUi.cs +++ b/MareSynchronos/UI/SettingsUi.cs @@ -784,10 +784,16 @@ public class SettingsUi : WindowMediatorSubscriberBase } _uiShared.DrawCacheDirectorySetting(); - ImGui.TextUnformatted($"Currently utilized local storage: {UiSharedService.ByteToString(_uiShared.FileCacheSize)}"); - bool isLinux = Util.IsWine(); - if (isLinux) ImGui.BeginDisabled(); + ImGui.AlignTextToFramePadding(); + ImGui.TextUnformatted($"Currently utilized local storage: {UiSharedService.ByteToString(_cacheMonitor.FileCacheSize)}"); + ImGui.TextUnformatted($"Remaining space free on drive: {UiSharedService.ByteToString(_cacheMonitor.FileCacheDriveFree)}"); bool useFileCompactor = _configService.Current.UseCompactor; + bool isLinux = Util.IsWine(); + if (!useFileCompactor && !isLinux) + { + UiSharedService.ColorTextWrapped("Hint: To free up space when using Mare consider enabling the File Compactor", ImGuiColors.DalamudYellow); + } + if (isLinux) ImGui.BeginDisabled(); if (ImGui.Checkbox("Use file compactor", ref useFileCompactor)) { _configService.Current.UseCompactor = useFileCompactor; @@ -800,14 +806,22 @@ public class SettingsUi : WindowMediatorSubscriberBase { if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.FileArchive, "Compact all files in storage")) { - _ = Task.Run(() => _fileCompactor.CompactStorage(compress: true)); + _ = Task.Run(() => + { + _fileCompactor.CompactStorage(compress: true); + _ = _cacheMonitor.RecalculateFileCacheSize(); + }); } UiSharedService.AttachToolTip("This will run compression on all files in your current storage folder." + Environment.NewLine + "You do not need to run this manually if you keep the file compactor enabled."); ImGui.SameLine(); if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.File, "Decompact all files in storage")) { - _ = Task.Run(() => _fileCompactor.CompactStorage(compress: false)); + _ = Task.Run(() => + { + _fileCompactor.CompactStorage(compress: false); + _ = _cacheMonitor.RecalculateFileCacheSize(); + }); } UiSharedService.AttachToolTip("This will run decompression on all files in your current storage folder."); } diff --git a/MareSynchronos/UI/UISharedService.cs b/MareSynchronos/UI/UISharedService.cs index 00b18f2..14e5fd1 100644 --- a/MareSynchronos/UI/UISharedService.cs +++ b/MareSynchronos/UI/UISharedService.cs @@ -123,8 +123,6 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase public bool EditTrackerPosition { get; set; } - public long FileCacheSize => _cacheMonitor.FileCacheSize; - public bool HasValidPenumbraModPath => !(_ipcManager.PenumbraModDirectory ?? string.Empty).IsNullOrEmpty() && Directory.Exists(_ipcManager.PenumbraModDirectory); public bool IsInGpose => _dalamudUtil.IsInCutscene;