mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 09:01:10 +00:00
Adds hidden elements option to file system browser directories and paths
This commit is contained in:
1 parent
15a1881495
commit
b3db46ed5f
18 files changed
+217
-59
No files matched your search
+18
-14
@@ -67,7 +67,7 @@ public class GetDirectoryTreeQueryHandler : IRequestHandler<GetDirectoryTreeQuer
|
||||
|
||||
List<PathSegment> pathParts = pathPartsResults.Value.ToList();
|
||||
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> buildDirectoryTreeResult = BuildDirectoryTree(result, pathParts, out FileSystemTreeNodeResponse? currentNode);
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> buildDirectoryTreeResult = BuildDirectoryTree(result, pathParts, out FileSystemTreeNodeResponse? currentNode, request.IncludeHiddenElements);
|
||||
if (buildDirectoryTreeResult.IsError)
|
||||
return buildDirectoryTreeResult.Errors;
|
||||
|
||||
@@ -97,10 +97,11 @@ public class GetDirectoryTreeQueryHandler : IRequestHandler<GetDirectoryTreeQuer
|
||||
/// </summary>
|
||||
/// <param name="drives">The list of available drives.</param>
|
||||
/// <param name="pathParts">The list of parsed path segments (directories).</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing a list of <see cref="FileSystemTreeNodeResponse"/> representing the directory tree, or an error message.
|
||||
/// </returns>
|
||||
private ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> BuildDirectoryTree(List<FileSystemTreeNodeResponse> drives, List<PathSegment> pathParts, out FileSystemTreeNodeResponse currentNode)
|
||||
private ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> BuildDirectoryTree(List<FileSystemTreeNodeResponse> drives, List<PathSegment> pathParts, out FileSystemTreeNodeResponse currentNode, bool includeHiddenElements = true)
|
||||
{
|
||||
// find the root drive that matches the first part of the path
|
||||
FileSystemTreeNodeResponse drive = drives.First(drive => drive.Name.Contains(pathParts[0].Name));
|
||||
@@ -114,18 +115,21 @@ public class GetDirectoryTreeQueryHandler : IRequestHandler<GetDirectoryTreeQuer
|
||||
ErrorOr<string> combinedPathResult = _pathService.CombinePath(currentPath, pathParts[i].Name);
|
||||
if (combinedPathResult.IsError)
|
||||
return combinedPathResult.Errors;
|
||||
|
||||
currentPath = combinedPathResult.Value;
|
||||
// create a new node for the directory and add it as a child of the current node
|
||||
FileSystemTreeNodeResponse newNode = new()
|
||||
if (_pathService.Exists(combinedPathResult.Value, includeHiddenElements))
|
||||
{
|
||||
Path = currentPath,
|
||||
Name = pathParts[i].Name,
|
||||
ItemType = FileSystemItemType.Directory,
|
||||
IsExpanded = true
|
||||
};
|
||||
currentNode.Children.Add(newNode);
|
||||
currentNode = newNode; // move to the new node
|
||||
|
||||
currentPath = combinedPathResult.Value;
|
||||
// create a new node for the directory and add it as a child of the current node
|
||||
FileSystemTreeNodeResponse newNode = new()
|
||||
{
|
||||
Path = currentPath,
|
||||
Name = pathParts[i].Name,
|
||||
ItemType = FileSystemItemType.Directory,
|
||||
IsExpanded = true
|
||||
};
|
||||
currentNode.Children.Add(newNode);
|
||||
currentNode = newNode; // move to the new node
|
||||
}
|
||||
}
|
||||
return new List<FileSystemTreeNodeResponse> { drive };
|
||||
}
|
||||
@@ -143,7 +147,7 @@ public class GetDirectoryTreeQueryHandler : IRequestHandler<GetDirectoryTreeQuer
|
||||
if (subDirectoriesResult.IsError)
|
||||
return subDirectoriesResult.Errors;
|
||||
// add each subdirectory as a child node of the current directory
|
||||
foreach (Directory subDirectory in subDirectoriesResult.Value)
|
||||
foreach (Directory subDirectory in subDirectoriesResult.Value ?? [])
|
||||
{
|
||||
FileSystemTreeNodeResponse subDirNode = new()
|
||||
{
|
||||
|
||||
+3
-2
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Mediator;
|
||||
#endregion
|
||||
@@ -9,4 +9,5 @@ namespace Lumina.Application.Core.FileManagement.Paths.Queries.CheckPathExists;
|
||||
/// Query for retrieving the existence of a file system path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to check the existence.</param>
|
||||
public record CheckPathExistsQuery(string Path) : IRequest<PathExistsResponse>;
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
public record CheckPathExistsQuery(string Path, bool IncludeHiddenElements) : IRequest<PathExistsResponse>;
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Mediator;
|
||||
@@ -39,7 +39,7 @@ public class CheckPathExistsQueryHandler : IRequestHandler<CheckPathExistsQuery,
|
||||
/// </returns>
|
||||
public ValueTask<PathExistsResponse> Handle(CheckPathExistsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return ValueTask.FromResult(new PathExistsResponse(_pathService.Exists(request.Path)));
|
||||
return ValueTask.FromResult(new PathExistsResponse(_pathService.Exists(request.Path, request.IncludeHiddenElements)));
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
@@ -30,8 +30,9 @@ public interface IPathService
|
||||
/// Checks if <paramref name="path"/> exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be checked.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> exists, <see langword="false"/> otherwise.</returns>
|
||||
bool Exists(string path);
|
||||
bool Exists(string path, bool includeHiddenElements = true);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to combine <paramref name="path"/> with <paramref name="name"/>.
|
||||
@@ -68,4 +69,4 @@ public interface IPathService
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the root of <paramref name="path"/>, or an error.</returns>
|
||||
ErrorOr<PathSegment> GetPathRoot(string path);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -53,13 +53,14 @@ public class PathService : IPathService
|
||||
/// Checks if <paramref name="path"/> exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be checked.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> exists, <see langword="false"/> otherwise.</returns>
|
||||
public bool Exists(string path)
|
||||
public bool Exists(string path, bool includeHiddenElements = true)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
if (newPathResult.IsError)
|
||||
return false;
|
||||
return _platformContext.PathStrategy.Exists(newPathResult.Value);
|
||||
return _platformContext.PathStrategy.Exists(newPathResult.Value, includeHiddenElements);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+4
-3
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
@@ -27,8 +27,9 @@ public interface IPathStrategy
|
||||
/// Checks if <paramref name="path"/> exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be checked.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> exists, <see langword="false"/> otherwise.</returns>
|
||||
bool Exists(FileSystemPathId path);
|
||||
bool Exists(FileSystemPathId path, bool includeHiddenElements = true);
|
||||
|
||||
/// <summary>
|
||||
/// Tries to combine <paramref name="path"/> with <paramref name="name"/>.
|
||||
@@ -65,4 +66,4 @@ public interface IPathStrategy
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing the root of <paramref name="path"/>, or an error.</returns>
|
||||
ErrorOr<PathSegment> GetPathRoot(FileSystemPathId path);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+19
-2
@@ -4,6 +4,7 @@ using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -58,10 +59,26 @@ public class UnixPathStrategy : IUnixPathStrategy
|
||||
/// Checks if <paramref name="path"/> exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be checked.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> exists, <see langword="false"/> otherwise.</returns>
|
||||
public bool Exists(FileSystemPathId path)
|
||||
public bool Exists(FileSystemPathId path, bool includeHiddenElements = true)
|
||||
{
|
||||
return _fileSystem.Path.Exists(path.Path);
|
||||
if (!_fileSystem.Path.Exists(path.Path))
|
||||
return false;
|
||||
bool isHidden;
|
||||
if (_fileSystem.Directory.Exists(path.Path))
|
||||
{
|
||||
IDirectoryInfo dirInfo = _fileSystem.DirectoryInfo.New(path.Path);
|
||||
isHidden = (dirInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
|
||||
}
|
||||
else if (_fileSystem.File.Exists(path.Path))
|
||||
{
|
||||
IFileInfo fileInfo = _fileSystem.FileInfo.New(path.Path);
|
||||
isHidden = (fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
|
||||
}
|
||||
else // path exists but is neither a file nor a directory (drive, etc)
|
||||
return true;
|
||||
return includeHiddenElements || !isHidden;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+19
-2
@@ -4,6 +4,7 @@ using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -57,10 +58,26 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
/// Checks if <paramref name="path"/> exists.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be checked.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <returns><see langword="true"/> if <paramref name="path"/> exists, <see langword="false"/> otherwise.</returns>
|
||||
public bool Exists(FileSystemPathId path)
|
||||
public bool Exists(FileSystemPathId path, bool includeHiddenElements = true)
|
||||
{
|
||||
return _fileSystem.Path.Exists(path.Path);
|
||||
if (!_fileSystem.Path.Exists(path.Path))
|
||||
return false;
|
||||
bool isHidden;
|
||||
if (_fileSystem.Directory.Exists(path.Path))
|
||||
{
|
||||
IDirectoryInfo dirInfo = _fileSystem.DirectoryInfo.New(path.Path);
|
||||
isHidden = (dirInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
|
||||
}
|
||||
else if (_fileSystem.File.Exists(path.Path))
|
||||
{
|
||||
IFileInfo fileInfo = _fileSystem.FileInfo.New(path.Path);
|
||||
isHidden = (fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
|
||||
}
|
||||
else // path exists but is neither a file nor a directory (drive, etc)
|
||||
return true;
|
||||
return includeHiddenElements || !isHidden;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -118,11 +118,12 @@ public class PathController : ApiController
|
||||
/// Checks whether <paramref name="path"/> exists or not.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be checked.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("check-path-exists")]
|
||||
public async Task<IActionResult> CheckPathExists([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, CancellationToken cancellationToken)
|
||||
public async Task<IActionResult> CheckPathExists([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
|
||||
{
|
||||
PathExistsResponse result = await _mediator.Send(new CheckPathExistsQuery(path), cancellationToken).ConfigureAwait(false);
|
||||
PathExistsResponse result = await _mediator.Send(new CheckPathExistsQuery(path, includeHiddenElements), cancellationToken).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -94,11 +94,12 @@ public class PathController : Controller
|
||||
/// Checks whether <paramref name="path"/> exists or not.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to be checked.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("check-path-exists")]
|
||||
public async Task<IActionResult> CheckPathExists([FromQuery] string path, CancellationToken cancellationToken)
|
||||
public async Task<IActionResult> CheckPathExists([FromQuery] string path, [FromQuery] bool includeHiddenElements, CancellationToken cancellationToken)
|
||||
{
|
||||
PathExistsModel response = await _apiHttpClient.GetAsync<PathExistsModel>($"path/check-path-exists?path={Uri.EscapeDataString(path)}", cancellationToken: cancellationToken);
|
||||
PathExistsModel response = await _apiHttpClient.GetAsync<PathExistsModel>($"path/check-path-exists?path={Uri.EscapeDataString(path)}&includeHiddenElements={includeHiddenElements}", cancellationToken: cancellationToken);
|
||||
return Json(new { success = true, data = new { exists = response.Exists } });
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -238,7 +238,7 @@ async function checkPathAsync(path) {
|
||||
if (addressBarInput.value !== null && !addressBarInput.value.endsWith(pathSeparator))
|
||||
addressBarInput.value += pathSeparator;
|
||||
} else {
|
||||
const pathExistsResponse = await callApiGetAsync(`${clientBasePath}path/check-path-exists?path=${encodeURIComponent(path)}`);
|
||||
const pathExistsResponse = await callApiGetAsync(`${clientBasePath}path/check-path-exists?path=${encodeURIComponent(path)}&includeHiddenElements=${showHiddenElements}`);
|
||||
if (pathExistsResponse !== undefined && !pathExistsResponse.exists) {
|
||||
notificationService.show("Specified path does not exist!", NotificationType.ERROR); // TODO: should ask error message from server when translation is implemented
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user