make storage size calculation asynchronous and running in parallel

This commit is contained in:
rootdarkarchon
2024-02-15 02:38:41 +01:00
committed by Loporrit
parent 50990542fd
commit e1ca5dd6f8
9 changed files with 105 additions and 35 deletions

View File

@@ -62,7 +62,9 @@ public sealed class DtrEntry : IDisposable, IHostedService
public Task StartAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Starting DtrEntry");
_runTask = Task.Run(RunAsync, _cancellationTokenSource.Token);
_logger.LogInformation("Started DtrEntry");
return Task.CompletedTask;
}
@@ -144,7 +146,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
{
visiblePairs = _pairManager.GetOnlineUserPairs()
.Where(x => x.IsVisible)
.Select(x => string.Format("{0} ({1})", _configService.Current.PreferNoteInDtrTooltip ? x.GetNoteOrName() : x.PlayerName, x.UserData.AliasOrUID ));
.Select(x => string.Format("{0} ({1})", _configService.Current.PreferNoteInDtrTooltip ? x.GetNoteOrName() : x.PlayerName, x.UserData.AliasOrUID));
}
else
{

View File

@@ -785,7 +785,10 @@ public class SettingsUi : WindowMediatorSubscriberBase
_uiShared.DrawCacheDirectorySetting();
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted($"Currently utilized local storage: {UiSharedService.ByteToString(_cacheMonitor.FileCacheSize)}");
if (_cacheMonitor.FileCacheSize >= 0)
ImGui.TextUnformatted($"Currently utilized local storage: {UiSharedService.ByteToString(_cacheMonitor.FileCacheSize)}");
else
ImGui.TextUnformatted($"Currently utilized local storage: Calculating...");
ImGui.TextUnformatted($"Remaining space free on drive: {UiSharedService.ByteToString(_cacheMonitor.FileCacheDriveFree)}");
bool useFileCompactor = _configService.Current.UseCompactor;
bool isLinux = Util.IsWine();
@@ -793,7 +796,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
{
UiSharedService.ColorTextWrapped("Hint: To free up space when using Mare consider enabling the File Compactor", ImGuiColors.DalamudYellow);
}
if (isLinux) ImGui.BeginDisabled();
if (isLinux || !_cacheMonitor.StorageisNTFS) ImGui.BeginDisabled();
if (ImGui.Checkbox("Use file compactor", ref useFileCompactor))
{
_configService.Current.UseCompactor = useFileCompactor;
@@ -809,7 +812,8 @@ public class SettingsUi : WindowMediatorSubscriberBase
_ = Task.Run(() =>
{
_fileCompactor.CompactStorage(compress: true);
_ = _cacheMonitor.RecalculateFileCacheSize();
CancellationTokenSource cts = new();
_cacheMonitor.RecalculateFileCacheSize(cts.Token);
});
}
UiSharedService.AttachToolTip("This will run compression on all files in your current storage folder." + Environment.NewLine
@@ -820,7 +824,8 @@ public class SettingsUi : WindowMediatorSubscriberBase
_ = Task.Run(() =>
{
_fileCompactor.CompactStorage(compress: false);
_ = _cacheMonitor.RecalculateFileCacheSize();
CancellationTokenSource cts = new();
_cacheMonitor.RecalculateFileCacheSize(cts.Token);
});
}
UiSharedService.AttachToolTip("This will run decompression on all files in your current storage folder.");
@@ -829,10 +834,10 @@ public class SettingsUi : WindowMediatorSubscriberBase
{
UiSharedService.ColorText($"File compactor currently running ({_fileCompactor.Progress})", ImGuiColors.DalamudYellow);
}
if (isLinux)
if (isLinux || !_cacheMonitor.StorageisNTFS)
{
ImGui.EndDisabled();
ImGui.TextUnformatted("The file compactor is only available on Windows.");
ImGui.TextUnformatted("The file compactor is only available on Windows and NTFS drives.");
}
ImGuiHelpers.ScaledDummy(new Vector2(10, 10));