diff --git a/LANCommander/Pages/Settings/SettingsLayout.razor b/LANCommander/Pages/Settings/SettingsLayout.razor index a6dfe16..7c159d0 100644 --- a/LANCommander/Pages/Settings/SettingsLayout.razor +++ b/LANCommander/Pages/Settings/SettingsLayout.razor @@ -8,6 +8,7 @@ General Users Authentication + Tools diff --git a/LANCommander/Pages/Settings/Tools.razor b/LANCommander/Pages/Settings/Tools.razor new file mode 100644 index 0000000..1d36cd5 --- /dev/null +++ b/LANCommander/Pages/Settings/Tools.razor @@ -0,0 +1,73 @@ +@page "/Settings/Tools" +@using LANCommander.Models; +@layout SettingsLayout +@inject IMessageService MessageService +@inject ArchiveService ArchiveService +@attribute [Authorize(Roles = "Administrator")] + + + +
+

Icon Cache

+

+ If your icons look wrong or need to be refreshed, click the button below to clear the icon cache. Note that icons will only be regenerated when requested. +

+ + + + +

Recalculate File Sizes

+

+ Some file sizes are cached in the database. Click the button below to scan through all files and recalculate their size. +

+ +
+ + +@code { + bool ClearingIconCache = false; + bool RecalculatingFileSizes = false; + + async Task ClearIconCache() + { + ClearingIconCache = true; + + foreach (var icon in Directory.GetFiles("Icon")) + { + try + { + File.Delete(icon); + } + catch { } + } + + ClearingIconCache = false; + + await MessageService.Success("Icon cache cleared!"); + } + + async Task RecalculateFileSizes() + { + RecalculatingFileSizes = true; + + StateHasChanged(); + + var archives = await ArchiveService.Get(); + + foreach (var archive in archives) + { + var path = ArchiveService.GetArchiveFileLocation(archive); + + if (File.Exists(path)) + { + archive.CompressedSize = new FileInfo(path).Length; + + await ArchiveService.Update(archive); + } + } + + await MessageService.Success("File sizes recalculated!"); + + RecalculatingFileSizes = false; + } +}