calculate and display local cache size on cache changes, add clear cache button
This commit is contained in:
@@ -4,6 +4,7 @@ using Dalamud.Interface.Windowing;
|
||||
using ImGuiNET;
|
||||
using MareSynchronos.WebAPI;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MareSynchronos.Utils;
|
||||
@@ -190,7 +191,18 @@ namespace MareSynchronos.UI
|
||||
{
|
||||
_uiShared.DrawFileScanState();
|
||||
_uiShared.DrawCacheDirectorySetting();
|
||||
_uiShared.DrawParallelScansSetting();
|
||||
ImGui.Text($"Local cache size: {UiShared.ByteToString(_uiShared.FileCacheSize)}");
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("Clear local cache"))
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
foreach (var file in Directory.GetFiles(_configuration.CacheFolder))
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
ImGui.TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace MareSynchronos.UI
|
||||
private readonly ApiController _apiController;
|
||||
private readonly FileCacheManager _fileCacheManager;
|
||||
private readonly Configuration _pluginConfiguration;
|
||||
public long FileCacheSize => _fileCacheManager.FileCacheSize;
|
||||
|
||||
public UiShared(IpcManager ipcManager, ApiController apiController, FileCacheManager fileCacheManager, Configuration pluginConfiguration)
|
||||
{
|
||||
@@ -115,16 +116,15 @@ namespace MareSynchronos.UI
|
||||
|
||||
public static string ByteToString(long bytes)
|
||||
{
|
||||
double output = bytes;
|
||||
var suffix = new[] { "B", "KiB", "MiB", "GiB" };
|
||||
var suffixIdx = 0;
|
||||
while (output / 1024.0 > 1024)
|
||||
string[] suffix = { "B", "KiB", "MiB", "GiB", "TiB" };
|
||||
int i;
|
||||
double dblSByte = bytes;
|
||||
for (i = 0; i < suffix.Length && bytes >= 1024; i++, bytes /= 1024)
|
||||
{
|
||||
output /= 1024.0;
|
||||
suffixIdx++;
|
||||
dblSByte = bytes / 1024.0;
|
||||
}
|
||||
|
||||
return output.ToString("0.00") + " " + suffix[suffixIdx];
|
||||
return $"{dblSByte:0.00} {suffix[i]}";
|
||||
}
|
||||
|
||||
private int _serverSelectionIndex = 0;
|
||||
|
||||
Reference in New Issue
Block a user