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

+ These archives are missing their backing file in the "Upload" directory of your server. This may result in broken downloads for clients. To fix, either upload a new file or delete the offending archive. +

+ + + + + + + @context.CreatedBy?.UserName + + + + +
+ + +
+ + + @code { + ICollection Archives; + bool Loading = true; + + ArchiveUploader Uploader; + + protected override async Task OnInitializedAsync() + { + await LoadData(); + } + + async Task LoadData() + { + Loading = true; + + Archives = new List(); + + foreach (var archive in await ArchiveService.Get()) + { + var archivePath = ArchiveService.GetArchiveFileLocation(archive); + var exists = await ArchiveService.Exists(archive.Id); + + if (!exists) + Archives.Add(archive); + else if (new FileInfo(archivePath).Length == 0) + Archives.Add(archive); + } + + Loading = false; + } + + async Task Upload(Archive archive) + { + var archiveFilePath = ArchiveService.GetArchiveFileLocation(archive); + + if (await ArchiveService.Exists(archive.Id)) + File.Delete(archiveFilePath); + + System.IO.File.Create(archiveFilePath).Close(); + + await Uploader.Open(archive); + } + + async Task OnArchiveUploaded(Archive archive) + { + try + { + await ArchiveService.Update(archive); + + await LoadData(); + } + catch (Exception ex) + { + await MessageService.Error("Archive could not be updated."); + } + } + + async Task Delete(Archive archive) + { + try + { + await ArchiveService.Delete(archive); + + await LoadData(); + + await MessageService.Success("Archive deleted!"); + } + catch (Exception ex) + { + await MessageService.Error("Archive could not be deleted."); + } + } +} diff --git a/LANCommander/Pages/Settings/Tools.razor b/LANCommander/Pages/Settings/ToolsIndex.razor similarity index 89% rename from LANCommander/Pages/Settings/Tools.razor rename to LANCommander/Pages/Settings/ToolsIndex.razor index 1d36cd5..63219f0 100644 --- a/LANCommander/Pages/Settings/Tools.razor +++ b/LANCommander/Pages/Settings/ToolsIndex.razor @@ -21,6 +21,12 @@ Some file sizes are cached in the database. Click the button below to scan through all files and recalculate their size.

+ + + +

Missing Archives

+

List and fix all archives that are missing their backing files.

+ View Missing Archives