Remove old archive browser

dhcp-server
Pat Hartl 2023-09-11 20:23:36 -05:00
parent 7e4aa07138
commit 3647418004
1 changed files with 0 additions and 232 deletions

View File

@ -1,232 +0,0 @@
@using AntDesign.TableModels;
@using ByteSizeLib;
@using LANCommander.Services;
@using System.IO.Compression;
@inject ArchiveService ArchiveService;
<GridRow Style="position: fixed; height: calc(100vh - 55px - 53px); top: 55px; left: 0; width: 100%">
<GridCol Span="6" Style="height: 100%; overflow-y: scroll; padding: 24px">
<Tree TItem="ArchiveDirectory"
DataSource="Directories"
TitleExpression="x => x.DataItem.Name"
ChildrenExpression="x => x.DataItem.Children"
IsLeafExpression="x => !x.DataItem.HasChildren"
OnClick="(args) => ChangeDirectory(args.Node.DataItem)">
</Tree>
</GridCol>
<GridCol Span="18" Style="height: 100%">
<Table
@ref="FileTable"
TItem="ZipArchiveEntry"
DataSource="CurrentPathEntries"
HidePagination="true"
Loading="Entries == null"
RowSelectable="@(x => CanSelect(x))"
OnRowClick="OnRowClicked"
SelectedRowsChanged="SelectedFilesChanged"
ScrollY="calc(100vh - 55px - 55px - 53px)">
@if (Select)
{
<Selection Key="@context.FullName" Type="@(Multiple ? "checkbox" : "radio")" Disabled="@(!CanSelect(context))" />
}
<Column TData="string" Width="32">
<Icon Type="@GetIcon(context)" Theme="outline" />
</Column>
<PropertyColumn Property="e => e.FullName" Sortable Title="Name">
@GetFileName(context)
</PropertyColumn>
<PropertyColumn Property="e => e.Length" Sortable Title="Size">
@ByteSize.FromBytes(context.Length)
</PropertyColumn>
<PropertyColumn Property="e => e.LastWriteTime" Format="MM/dd/yyyy hh:mm tt" Sortable Title="Modified" />
</Table>
</GridCol>
</GridRow>
<style>
.select-file-button {
opacity: 0;
transition: .1s opacity;
}
.archive-browser tr:hover .select-file-button {
opacity: 1;
}
</style>
@code {
[Parameter] public Guid ArchiveId { get; set; }
[Parameter] public bool Select { get; set; }
[Parameter] public bool Multiple { get; set; } = false;
[Parameter] public bool AllowDirectories { get; set; } = false;
[Parameter] public IEnumerable<ZipArchiveEntry> SelectedFiles { get; set; }
[Parameter] public EventCallback<IEnumerable<ZipArchiveEntry>> SelectedFilesChanged { get; set; }
ITable? FileTable;
private IEnumerable<ZipArchiveEntry> Entries { get; set; }
private IEnumerable<ZipArchiveEntry> CurrentPathEntries { get; set; }
private string CurrentPath { get; set; }
private HashSet<ArchiveDirectory> Directories { get; set; }
private ArchiveDirectory SelectedDirectory { get; set; }
protected override async Task OnInitializedAsync()
{
Entries = await ArchiveService.GetContents(ArchiveId);
Directories = new HashSet<ArchiveDirectory>();
var root = new ArchiveDirectory()
{
Name = "/",
FullName = "",
IsExpanded = true
};
root.PopulateChildren(Entries);
Directories.Add(root);
ChangeDirectory(root);
}
private void OnRowClicked(RowData<ZipArchiveEntry> row)
{
FileTable.SetSelection(new string[] { row.Data.FullName });
}
private void ChangeDirectory(ArchiveDirectory selectedDirectory)
{
SelectedDirectory = selectedDirectory;
if (SelectedDirectory.FullName == "")
CurrentPathEntries = Entries.Where(e => !e.FullName.TrimEnd('/').Contains('/'));
else
CurrentPathEntries = Entries.Where(e => e.FullName.StartsWith(SelectedDirectory.FullName) && e.FullName != SelectedDirectory.FullName);
}
private string GetFileName(ZipArchiveEntry entry)
{
if (String.IsNullOrWhiteSpace(entry.Name) && entry.Length == 0)
{
return entry.FullName.TrimEnd('/').Split('/').Last();
}
else
return entry.Name;
}
private string GetIcon(ZipArchiveEntry entry)
{
switch (Path.GetExtension(entry.FullName))
{
case "":
return "folder";
case ".exe":
return "code";
case ".zip":
case ".rar":
case ".7z":
case ".gz":
case ".tar":
return "file-zip";
case ".wad":
case ".pk3":
case ".pak":
case ".cab":
return "file-zip";
case ".txt":
case ".cfg":
case ".config":
case ".ini":
case ".yml":
case ".yaml":
case ".log":
case ".doc":
case ".nfo":
return "file-text";
case ".bat":
case ".ps1":
case ".json":
return "code";
case ".bik":
case ".avi":
case ".mov":
case ".mp4":
case ".m4v":
case ".mkv":
case ".wmv":
case ".mpg":
case ".mpeg":
case ".flv":
return "video-camera";
case ".dll":
return "api";
case ".hlp":
return "file-unknown";
case ".png":
case ".bmp":
case ".jpeg":
case ".jpg":
case ".gif":
return "file-image";
default:
return "file";
}
}
private bool CanSelect(ZipArchiveEntry entry)
{
if (entry == null || entry.FullName == null)
return false;
var isDirectory = entry.FullName.EndsWith('/');
if (isDirectory && AllowDirectories)
return true;
else if (!isDirectory)
return true;
else
return false;
}
public class ArchiveDirectory
{
public string Name { get; set; }
public string FullName { get; set; }
public bool IsExpanded { get; set; } = false;
public bool HasChildren => Children != null && Children.Count > 0;
public HashSet<ArchiveDirectory> Children { get; set; } = new HashSet<ArchiveDirectory>();
public void PopulateChildren(IEnumerable<ZipArchiveEntry> entries)
{
var childPaths = entries.Where(e => e.FullName.StartsWith(FullName) && e.FullName.EndsWith('/'));
var directChildren = childPaths.Where(p => p.FullName != FullName && p.FullName.Substring(FullName.Length + 1).TrimEnd('/').Split('/').Length == 1);
foreach (var directChild in directChildren)
{
var child = new ArchiveDirectory()
{
FullName = directChild.FullName,
Name = directChild.FullName.Substring(FullName.Length).TrimEnd('/')
};
child.PopulateChildren(entries);
Children.Add(child);
}
}
}
}