diff --git a/LANCommander/Components/ArchiveBrowser.razor b/LANCommander/Components/ArchiveBrowser.razor deleted file mode 100644 index 9b6dcf1..0000000 --- a/LANCommander/Components/ArchiveBrowser.razor +++ /dev/null @@ -1,232 +0,0 @@ -@using AntDesign.TableModels; -@using ByteSizeLib; -@using LANCommander.Services; -@using System.IO.Compression; -@inject ArchiveService ArchiveService; - - - - - - - - - - - @if (Select) - { - - } - - - - - @GetFileName(context) - - - @ByteSize.FromBytes(context.Length) - - - -
-
-
- - - -@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 SelectedFiles { get; set; } - [Parameter] public EventCallback> SelectedFilesChanged { get; set; } - - ITable? FileTable; - - private IEnumerable Entries { get; set; } - private IEnumerable CurrentPathEntries { get; set; } - private string CurrentPath { get; set; } - private HashSet Directories { get; set; } - private ArchiveDirectory SelectedDirectory { get; set; } - - protected override async Task OnInitializedAsync() - { - Entries = await ArchiveService.GetContents(ArchiveId); - Directories = new HashSet(); - - var root = new ArchiveDirectory() - { - Name = "/", - FullName = "", - IsExpanded = true - }; - - root.PopulateChildren(Entries); - - Directories.Add(root); - - ChangeDirectory(root); - } - - private void OnRowClicked(RowData 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 Children { get; set; } = new HashSet(); - - public void PopulateChildren(IEnumerable 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); - } - } - } -}