Disable browse button if archive file is missing

This commit is contained in:
Pat Hartl 2023-08-02 18:54:57 -05:00
parent fef2171588
commit 0e9f8b612c
2 changed files with 19 additions and 1 deletions

View file

@ -1,6 +1,7 @@
@using LANCommander.Models;
@using System.IO.Compression;
@inject ModalService ModalService
@inject ArchiveService ArchiveService
<Space Style="display: flex">
<SpaceItem Style="flex-grow: 1">
@ -8,7 +9,7 @@
</SpaceItem>
@if (ArchiveId != Guid.Empty) {
<SpaceItem>
<Button OnClick="() => BrowseForFile()" Type="@ButtonType.Primary" Icon="@IconType.Outline.FolderOpen" />
<Button OnClick="() => BrowseForFile()" Type="@ButtonType.Primary" Icon="@IconType.Outline.FolderOpen" Disabled="!ArchiveExists" />
</SpaceItem>
}
</Space>
@ -20,6 +21,14 @@
[Parameter] public string ArchiveBrowserTitle { get; set; } = "Choose File";
[Parameter] public bool AllowDirectories { get; set; } = false;
bool ArchiveExists { get; set; } = false;
protected override async Task OnInitializedAsync()
{
if (ArchiveId != Guid.Empty)
ArchiveExists = await ArchiveService.Exists(ArchiveId);
}
private async void BrowseForFile()
{
var modalOptions = new ModalOptions()

View file

@ -88,6 +88,15 @@ namespace LANCommander.Services
}
}
public async Task<bool> Exists(Guid archiveId)
{
var archive = await Get(archiveId);
var path = GetArchiveFileLocation(archive);
return File.Exists(path);
}
public async Task<IEnumerable<ZipArchiveEntry>> GetContents(Guid archiveId)
{
var archive = await Get(archiveId);