mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12:11:10 +00:00
Implements directory browser dialog, part 6: hidden file system items toggle
This commit is contained in:
1 parent
cd44f11d9e
commit
debad9ef74
74 files changed
+596
-427
No files matched your search
+8
-4
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -80,7 +80,9 @@ public sealed class Directory : FileSystemItem
|
||||
dateCreated,
|
||||
dateModified);
|
||||
ErrorOr<Updated> setStatusResult = newDirectory.SetStatus(status);
|
||||
return setStatusResult.IsError ? (ErrorOr<Directory>)setStatusResult.Errors : (ErrorOr<Directory>)newDirectory;
|
||||
if (setStatusResult.IsError)
|
||||
return setStatusResult.Errors;
|
||||
return newDirectory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -107,7 +109,9 @@ public sealed class Directory : FileSystemItem
|
||||
dateCreated,
|
||||
dateModified);
|
||||
ErrorOr<Updated> setStatusResult = newDirectory.SetStatus(status);
|
||||
return setStatusResult.IsError ? (ErrorOr<Directory>)setStatusResult.Errors : (ErrorOr<Directory>)newDirectory;
|
||||
if (setStatusResult.IsError)
|
||||
return setStatusResult.Errors;
|
||||
return newDirectory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -143,4 +147,4 @@ public sealed class Directory : FileSystemItem
|
||||
return Result.Updated;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+8
-4
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
@@ -81,7 +81,9 @@ public sealed class File : FileSystemItem
|
||||
dateModified,
|
||||
size);
|
||||
ErrorOr<Updated> setStatusResult = newFile.SetStatus(status);
|
||||
return setStatusResult.IsError ? (ErrorOr<File>)setStatusResult.Errors : (ErrorOr<File>)newFile;
|
||||
if (setStatusResult.IsError)
|
||||
return setStatusResult.Errors;
|
||||
return newFile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -112,7 +114,9 @@ public sealed class File : FileSystemItem
|
||||
dateModified,
|
||||
size);
|
||||
ErrorOr<Updated> setStatusResult = newFile.SetStatus(status);
|
||||
return setStatusResult.IsError ? (ErrorOr<File>)setStatusResult.Errors : (ErrorOr<File>)newFile;
|
||||
if (setStatusResult.IsError)
|
||||
return setStatusResult.Errors;
|
||||
return newFile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -150,4 +154,4 @@ public sealed class File : FileSystemItem
|
||||
return Result.Updated;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
@@ -55,7 +55,9 @@ public sealed class UnixRootItem : FileSystemItem
|
||||
createPathResult.Value,
|
||||
PATH);
|
||||
ErrorOr<Updated> setStatusResult = newRoot.SetStatus(status);
|
||||
return setStatusResult.IsError ? (ErrorOr<UnixRootItem>)setStatusResult.Errors : (ErrorOr<UnixRootItem>)newRoot;
|
||||
if (setStatusResult.IsError)
|
||||
return setStatusResult.Errors;
|
||||
return newRoot;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+8
-4
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
@@ -59,7 +59,9 @@ public sealed class WindowsRootItem : FileSystemItem
|
||||
createPathResult.Value,
|
||||
name);
|
||||
ErrorOr<Updated> setStatusResult = newRoot.SetStatus(status);
|
||||
return setStatusResult.IsError ? (ErrorOr<WindowsRootItem>)setStatusResult.Errors : (ErrorOr<WindowsRootItem>)newRoot;
|
||||
if (setStatusResult.IsError)
|
||||
return setStatusResult.Errors;
|
||||
return newRoot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -81,7 +83,9 @@ public sealed class WindowsRootItem : FileSystemItem
|
||||
id,
|
||||
name);
|
||||
ErrorOr<Updated> setStatusResult = newFile.SetStatus(status);
|
||||
return setStatusResult.IsError ? (ErrorOr<WindowsRootItem>)setStatusResult.Errors : (ErrorOr<WindowsRootItem>)newFile;
|
||||
if (setStatusResult.IsError)
|
||||
return setStatusResult.Errors;
|
||||
return newFile;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+34
-13
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
@@ -6,6 +6,7 @@ using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
@@ -40,21 +41,41 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
/// Retrieves a list of subdirectory paths from the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path from which to retrieve the subdirectory paths.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of directory paths or an error.</returns>
|
||||
public ErrorOr<IEnumerable<FileSystemPathId>> GetSubdirectoryPaths(FileSystemPathId path)
|
||||
public ErrorOr<IEnumerable<FileSystemPathId>> GetSubdirectoryPaths(FileSystemPathId path, bool includeHiddenElements)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
return !_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ListDirectory, false)
|
||||
? (ErrorOr<IEnumerable<FileSystemPathId>>)Errors.Permission.UnauthorizedAccess
|
||||
: ErrorOrFactory.From(_fileSystem.Directory.GetDirectories(path.Path)
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ListDirectory, false))
|
||||
return Errors.Permission.UnauthorizedAccess;
|
||||
return ErrorOrFactory.From(_fileSystem.Directory.GetDirectories(path.Path)
|
||||
.Where(path => includeHiddenElements || (GetAttributes(path) & FileAttributes.Hidden) != FileAttributes.Hidden)
|
||||
.OrderBy(path => path)
|
||||
.Select(path => path.EndsWith(_fileSystem.Path.DirectorySeparatorChar) ? path : path + _fileSystem.Path.DirectorySeparatorChar)
|
||||
.Select(FileSystemPathId.Create)
|
||||
.Select(path => FileSystemPathId.Create(path))
|
||||
.Where(errorOrPathId => !errorOrPathId.IsError)
|
||||
.Select(errorOrPathId => errorOrPathId.Value)
|
||||
.AsEnumerable());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the attributes of a file system item identified by <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to retrieve the file system attributes.</param>
|
||||
/// <returns>The retrieved file system attributes.</returns>
|
||||
private FileAttributes GetAttributes(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
// File.GetAttributes is used for both directories and files
|
||||
return _fileSystem.File.GetAttributes(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a directory with the specified path exists.
|
||||
/// </summary>
|
||||
@@ -85,9 +106,9 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
public ErrorOr<Optional<DateTime>> GetLastWriteTime(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
return !_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false)
|
||||
? (ErrorOr<Optional<DateTime>>)Errors.Permission.UnauthorizedAccess
|
||||
: (ErrorOr<Optional<DateTime>>)Optional<DateTime>.FromNullable(_fileSystem.Directory.GetLastWriteTime(path.Path));
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false))
|
||||
return Errors.Permission.UnauthorizedAccess;
|
||||
return Optional<DateTime>.FromNullable(_fileSystem.Directory.GetLastWriteTime(path.Path));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -98,9 +119,9 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
public ErrorOr<Optional<DateTime>> GetCreationTime(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
return !_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false)
|
||||
? (ErrorOr<Optional<DateTime>>)Errors.Permission.UnauthorizedAccess
|
||||
: (ErrorOr<Optional<DateTime>>)Optional<DateTime>.FromNullable(_fileSystem.Directory.GetCreationTime(path.Path));
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false))
|
||||
return Errors.Permission.UnauthorizedAccess;
|
||||
return Optional<DateTime>.FromNullable(_fileSystem.Directory.GetCreationTime(path.Path));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -302,4 +323,4 @@ internal class DirectoryProviderService : IDirectoryProviderService
|
||||
return Result.Deleted;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+35
-21
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
@@ -41,37 +41,41 @@ public class DirectoryService : IDirectoryService
|
||||
/// Retrieves subdirectories for the specified string path.
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
public ErrorOr<IEnumerable<Directory>> GetSubdirectories(string path)
|
||||
public ErrorOr<IEnumerable<Directory>> GetSubdirectories(string path, bool includeHiddenElements)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
return fileSystemPathIdResult.IsError ? (ErrorOr<IEnumerable<Directory>>)fileSystemPathIdResult.Errors : GetSubdirectories(fileSystemPathIdResult.Value);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return GetSubdirectories(fileSystemPathIdResult.Value, includeHiddenElements);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves subdirectories for the given directory.
|
||||
/// </summary>
|
||||
/// <param name="directory">Directory object to retrieve subdirectories for.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
public ErrorOr<IEnumerable<Directory>> GetSubdirectories(Directory directory)
|
||||
public ErrorOr<IEnumerable<Directory>> GetSubdirectories(Directory directory, bool includeHiddenElements)
|
||||
{
|
||||
return GetSubdirectories(directory.Id);
|
||||
return GetSubdirectories(directory.Id, includeHiddenElements);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves subdirectories for the specified file system path.
|
||||
/// </summary>
|
||||
/// <param name="path">Identifier for the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
public ErrorOr<IEnumerable<Directory>> GetSubdirectories(FileSystemPathId path)
|
||||
public ErrorOr<IEnumerable<Directory>> GetSubdirectories(FileSystemPathId path, bool includeHiddenElements)
|
||||
{
|
||||
// retrieve the list of subdirectories
|
||||
ErrorOr<IEnumerable<FileSystemPathId>> subdirectoryPathsResult = _environmentContext.DirectoryProviderService.GetSubdirectoryPaths(path);
|
||||
ErrorOr<IEnumerable<FileSystemPathId>> subdirectoryPathsResult = _environmentContext.DirectoryProviderService.GetSubdirectoryPaths(path, includeHiddenElements);
|
||||
if (subdirectoryPathsResult.IsError)
|
||||
return subdirectoryPathsResult.Errors;
|
||||
List<Directory> result = [];
|
||||
IEnumerable<FileSystemPathId> subdirectoryPaths = subdirectoryPathsResult.Value;
|
||||
foreach (FileSystemPathId subPath in subdirectoryPaths)
|
||||
foreach (FileSystemPathId subPath in subdirectoryPathsResult.Value)
|
||||
{
|
||||
// extract directory details
|
||||
ErrorOr<string> dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(subPath);
|
||||
@@ -111,7 +115,9 @@ public class DirectoryService : IDirectoryService
|
||||
public ErrorOr<Directory> CreateDirectory(string path, string name)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
return fileSystemPathIdResult.IsError ? (ErrorOr<Directory>)fileSystemPathIdResult.Errors : CreateDirectory(fileSystemPathIdResult.Value, name);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return CreateDirectory(fileSystemPathIdResult.Value, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -149,7 +155,9 @@ public class DirectoryService : IDirectoryService
|
||||
if (errorDirResult.IsError)
|
||||
return errorDirResult.Errors;
|
||||
ErrorOr<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
return setStatusResult.IsError ? (ErrorOr<Directory>)setStatusResult.Errors : errorDirResult;
|
||||
if (setStatusResult.IsError)
|
||||
return setStatusResult.Errors;
|
||||
return errorDirResult;
|
||||
}
|
||||
else
|
||||
return Directory.Create(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value);
|
||||
@@ -174,9 +182,9 @@ public class DirectoryService : IDirectoryService
|
||||
if (fileSystemSourcePathIdResult.IsError)
|
||||
return fileSystemSourcePathIdResult.Errors;
|
||||
ErrorOr<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath);
|
||||
return fileSystemDestinationPathIdResult.IsError
|
||||
? (ErrorOr<Directory>)fileSystemDestinationPathIdResult.Errors
|
||||
: CopyDirectory(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
|
||||
if (fileSystemDestinationPathIdResult.IsError)
|
||||
return fileSystemDestinationPathIdResult.Errors;
|
||||
return CopyDirectory(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -220,9 +228,9 @@ public class DirectoryService : IDirectoryService
|
||||
if (fileSystemSourcePathIdResult.IsError)
|
||||
return fileSystemSourcePathIdResult.Errors;
|
||||
ErrorOr<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath);
|
||||
return fileSystemDestinationPathIdResult.IsError
|
||||
? (ErrorOr<Directory>)fileSystemDestinationPathIdResult.Errors
|
||||
: MoveDirectory(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
|
||||
if (fileSystemDestinationPathIdResult.IsError)
|
||||
return fileSystemDestinationPathIdResult.Errors;
|
||||
return MoveDirectory(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -257,7 +265,9 @@ public class DirectoryService : IDirectoryService
|
||||
public ErrorOr<Directory> RenameDirectory(string path, string name)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
return fileSystemPathIdResult.IsError ? (ErrorOr<Directory>)fileSystemPathIdResult.Errors : RenameDirectory(fileSystemPathIdResult.Value, name);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return RenameDirectory(fileSystemPathIdResult.Value, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -295,7 +305,9 @@ public class DirectoryService : IDirectoryService
|
||||
if (errorDirResult.IsError)
|
||||
return errorDirResult.Errors;
|
||||
ErrorOr<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
return setStatusResult.IsError ? (ErrorOr<Directory>)setStatusResult.Errors : errorDirResult;
|
||||
if (setStatusResult.IsError)
|
||||
return setStatusResult.Errors;
|
||||
return errorDirResult;
|
||||
}
|
||||
else
|
||||
return Directory.Create(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value);
|
||||
@@ -310,7 +322,9 @@ public class DirectoryService : IDirectoryService
|
||||
public ErrorOr<Deleted> DeleteDirectory(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
return fileSystemPathIdResult.IsError ? (ErrorOr<Deleted>)fileSystemPathIdResult.Errors : DeleteDirectory(fileSystemPathIdResult.Value);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return DeleteDirectory(fileSystemPathIdResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -323,4 +337,4 @@ public class DirectoryService : IDirectoryService
|
||||
return _environmentContext.DirectoryProviderService.DeleteDirectory(path);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
@@ -42,7 +42,9 @@ public class DriveService : IDriveService
|
||||
if (_platformContext.Platform == PlatformType.Unix)
|
||||
{
|
||||
ErrorOr<UnixRootItem> unixRootResult = UnixRootItem.Create(FileSystemItemStatus.Accessible);
|
||||
return unixRootResult.IsError ? (ErrorOr<IEnumerable<FileSystemItem>>)unixRootResult.Errors : (ErrorOr<IEnumerable<FileSystemItem>>)new List<FileSystemItem>() { unixRootResult.Value };
|
||||
if (unixRootResult.IsError)
|
||||
return unixRootResult.Errors;
|
||||
return new List<FileSystemItem>() { unixRootResult.Value };
|
||||
}
|
||||
else
|
||||
return ErrorOrFactory.From(_fileSystem.DriveInfo.GetDrives()
|
||||
@@ -63,4 +65,4 @@ public class DriveService : IDriveService
|
||||
.AsEnumerable());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+41
-20
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
@@ -6,6 +6,7 @@ using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
@@ -40,20 +41,40 @@ internal class FileProviderService : IFileProviderService
|
||||
/// Retrieves a list of file paths at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to retrieve the list of files.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of file paths or an error.</returns>
|
||||
public ErrorOr<IEnumerable<FileSystemPathId>> GetFilePaths(FileSystemPathId path)
|
||||
public ErrorOr<IEnumerable<FileSystemPathId>> GetFilePaths(FileSystemPathId path, bool includeHiddenElements)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
return !_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ListDirectory)
|
||||
? (ErrorOr<IEnumerable<FileSystemPathId>>)Errors.Permission.UnauthorizedAccess
|
||||
: ErrorOrFactory.From(_fileSystem.Directory.GetFiles(path.Path)
|
||||
.OrderBy(p => p)
|
||||
.Select(FileSystemPathId.Create)
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ListDirectory))
|
||||
return Errors.Permission.UnauthorizedAccess;
|
||||
return ErrorOrFactory.From(_fileSystem.Directory.GetFiles(path.Path)
|
||||
.Where(path => includeHiddenElements || (GetAttributes(path) & FileAttributes.Hidden) != FileAttributes.Hidden)
|
||||
.OrderBy(path => path)
|
||||
.Select(path => FileSystemPathId.Create(path))
|
||||
.Where(errorOrPathId => !errorOrPathId.IsError)
|
||||
.Select(errorOrPathId => errorOrPathId.Value)
|
||||
.AsEnumerable());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the attributes of a file system item identified by <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to retrieve the file system attributes.</param>
|
||||
/// <returns>The retrieved file system attributes.</returns>
|
||||
private FileAttributes GetAttributes(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
// File.GetAttributes is used for both directories and files
|
||||
return _fileSystem.File.GetAttributes(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a file with the specified path exists.
|
||||
/// </summary>
|
||||
@@ -82,9 +103,9 @@ internal class FileProviderService : IFileProviderService
|
||||
public ErrorOr<byte[]> GetFileAsync(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
return !_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadContents)
|
||||
? (ErrorOr<byte[]>)Errors.Permission.UnauthorizedAccess
|
||||
: (ErrorOr<byte[]>)System.IO.File.ReadAllBytes(path.Path);
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadContents))
|
||||
return Errors.Permission.UnauthorizedAccess;
|
||||
return System.IO.File.ReadAllBytes(path.Path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -95,9 +116,9 @@ internal class FileProviderService : IFileProviderService
|
||||
public ErrorOr<Optional<DateTime>> GetLastWriteTime(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
return !_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties)
|
||||
? (ErrorOr<Optional<DateTime>>)Errors.Permission.UnauthorizedAccess
|
||||
: (ErrorOr<Optional<DateTime>>)Optional<DateTime>.FromNullable(_fileSystem.File.GetLastWriteTime(path.Path));
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties))
|
||||
return Errors.Permission.UnauthorizedAccess;
|
||||
return Optional<DateTime>.FromNullable(_fileSystem.File.GetLastWriteTime(path.Path));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -108,9 +129,9 @@ internal class FileProviderService : IFileProviderService
|
||||
public ErrorOr<Optional<DateTime>> GetCreationTime(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
return !_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties)
|
||||
? (ErrorOr<Optional<DateTime>>)Errors.Permission.UnauthorizedAccess
|
||||
: (ErrorOr<Optional<DateTime>>)Optional<DateTime>.FromNullable(_fileSystem.File.GetCreationTime(path.Path));
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties))
|
||||
return Errors.Permission.UnauthorizedAccess;
|
||||
return Optional<DateTime>.FromNullable(_fileSystem.File.GetCreationTime(path.Path));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -121,9 +142,9 @@ internal class FileProviderService : IFileProviderService
|
||||
public ErrorOr<long?> GetSize(FileSystemPathId path)
|
||||
{
|
||||
// check if the user has access permissions to the provided path
|
||||
return !_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties)
|
||||
? (ErrorOr<long?>)Errors.Permission.UnauthorizedAccess
|
||||
: (ErrorOr<long?>)(_fileSystem.FileInfo.New(path.Path)?.Length ?? 0);
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties))
|
||||
return Errors.Permission.UnauthorizedAccess;
|
||||
return _fileSystem.FileInfo.New(path.Path)?.Length ?? 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -265,4 +286,4 @@ internal class FileProviderService : IFileProviderService
|
||||
return Result.Deleted;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+34
-19
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
@@ -41,32 +41,37 @@ public class FileService : IFileService
|
||||
/// Retrieves files for the specified string path.
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
public ErrorOr<IEnumerable<File>> GetFiles(string path)
|
||||
public ErrorOr<IEnumerable<File>> GetFiles(string path, bool includeHiddenElements)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
return fileSystemPathIdResult.IsError ? (ErrorOr<IEnumerable<File>>)fileSystemPathIdResult.Errors : GetFiles(fileSystemPathIdResult.Value);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return GetFiles(fileSystemPathIdResult.Value, includeHiddenElements);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves files associated with a given file.
|
||||
/// </summary>
|
||||
/// <param name="file">The file object.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
public ErrorOr<IEnumerable<File>> GetFiles(File file)
|
||||
public ErrorOr<IEnumerable<File>> GetFiles(File file, bool includeHiddenElements)
|
||||
{
|
||||
return GetFiles(file.Id);
|
||||
return GetFiles(file.Id, includeHiddenElements);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves files for a specified file path Id.
|
||||
/// </summary>
|
||||
/// <param name="path">Identifier for the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
public ErrorOr<IEnumerable<File>> GetFiles(FileSystemPathId path)
|
||||
public ErrorOr<IEnumerable<File>> GetFiles(FileSystemPathId path, bool includeHiddenElements)
|
||||
{
|
||||
// retrieve the list of files
|
||||
ErrorOr<IEnumerable<FileSystemPathId>> filePathsResult = _environmentContext.FileProviderService.GetFilePaths(path);
|
||||
ErrorOr<IEnumerable<FileSystemPathId>> filePathsResult = _environmentContext.FileProviderService.GetFilePaths(path, includeHiddenElements);
|
||||
if (filePathsResult.IsError)
|
||||
return filePathsResult.Errors;
|
||||
List<File> result = [];
|
||||
@@ -119,9 +124,9 @@ public class FileService : IFileService
|
||||
if (fileSystemSourcePathIdResult.IsError)
|
||||
return fileSystemSourcePathIdResult.Errors;
|
||||
ErrorOr<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationDirectoryPath);
|
||||
return fileSystemDestinationPathIdResult.IsError
|
||||
? (ErrorOr<File>)fileSystemDestinationPathIdResult.Errors
|
||||
: CopyFile(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
|
||||
if (fileSystemDestinationPathIdResult.IsError)
|
||||
return fileSystemDestinationPathIdResult.Errors;
|
||||
return CopyFile(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -158,7 +163,9 @@ public class FileService : IFileService
|
||||
if (errorFileResult.IsError)
|
||||
return errorFileResult.Errors;
|
||||
ErrorOr<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
return setStatusResult.IsError ? (ErrorOr<File>)setStatusResult.Errors : errorFileResult;
|
||||
if (setStatusResult.IsError)
|
||||
return setStatusResult.Errors;
|
||||
return errorFileResult;
|
||||
}
|
||||
else
|
||||
return File.Create(copyFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
|
||||
@@ -181,9 +188,9 @@ public class FileService : IFileService
|
||||
if (fileSystemSourcePathIdResult.IsError)
|
||||
return fileSystemSourcePathIdResult.Errors;
|
||||
ErrorOr<FileSystemPathId> fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationDirectoryPath);
|
||||
return fileSystemDestinationPathIdResult.IsError
|
||||
? (ErrorOr<File>)fileSystemDestinationPathIdResult.Errors
|
||||
: MoveFile(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
|
||||
if (fileSystemDestinationPathIdResult.IsError)
|
||||
return fileSystemDestinationPathIdResult.Errors;
|
||||
return MoveFile(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -220,7 +227,9 @@ public class FileService : IFileService
|
||||
if (errorFileResult.IsError)
|
||||
return errorFileResult.Errors;
|
||||
ErrorOr<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
return setStatusResult.IsError ? (ErrorOr<File>)setStatusResult.Errors : errorFileResult;
|
||||
if (setStatusResult.IsError)
|
||||
return setStatusResult.Errors;
|
||||
return errorFileResult;
|
||||
}
|
||||
else
|
||||
return File.Create(moveFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
|
||||
@@ -236,7 +245,9 @@ public class FileService : IFileService
|
||||
public ErrorOr<File> RenameFile(string path, string name)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
return fileSystemPathIdResult.IsError ? (ErrorOr<File>)fileSystemPathIdResult.Errors : RenameFile(fileSystemPathIdResult.Value, name);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return RenameFile(fileSystemPathIdResult.Value, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -276,7 +287,9 @@ public class FileService : IFileService
|
||||
if (errorFileResult.IsError)
|
||||
return errorFileResult.Errors;
|
||||
ErrorOr<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
|
||||
return setStatusResult.IsError ? (ErrorOr<File>)setStatusResult.Errors : errorFileResult;
|
||||
if (setStatusResult.IsError)
|
||||
return setStatusResult.Errors;
|
||||
return errorFileResult;
|
||||
}
|
||||
else
|
||||
return File.Create(newFilePathResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
|
||||
@@ -291,7 +304,9 @@ public class FileService : IFileService
|
||||
public ErrorOr<Deleted> DeleteFile(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
return fileSystemPathIdResult.IsError ? (ErrorOr<Deleted>)fileSystemPathIdResult.Errors : DeleteFile(fileSystemPathIdResult.Value);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return DeleteFile(fileSystemPathIdResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -309,4 +324,4 @@ public class FileService : IFileService
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+8
-5
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Enums.PhotoLibrary;
|
||||
@@ -73,9 +73,12 @@ public class FileTypeService : IFileTypeService
|
||||
return type;
|
||||
// no known image header types were found, check other methods
|
||||
string content = Encoding.UTF8.GetString(buffer.ToArray());
|
||||
return IsSvg(content, path.Path)
|
||||
? (ErrorOr<ImageType>)ImageType.SVG
|
||||
: IsTga(buffer.ToArray()) ? (ErrorOr<ImageType>)ImageType.TGA : (ErrorOr<ImageType>)ImageType.None;
|
||||
if (IsSvg(content, path.Path))
|
||||
return ImageType.SVG;
|
||||
else if (IsTga(buffer.ToArray()))
|
||||
return ImageType.TGA;
|
||||
else
|
||||
return ImageType.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -154,4 +157,4 @@ public class FileTypeService : IFileTypeService
|
||||
return ImageType.None;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -18,8 +18,9 @@ public interface IDirectoryProviderService
|
||||
/// Retrieves a list of subdirectory paths from the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path from which to retrieve the subdirectory paths.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of directory paths or an error.</returns>
|
||||
ErrorOr<IEnumerable<FileSystemPathId>> GetSubdirectoryPaths(FileSystemPathId path);
|
||||
ErrorOr<IEnumerable<FileSystemPathId>> GetSubdirectoryPaths(FileSystemPathId path, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a directory with the specified path exists.
|
||||
@@ -91,4 +92,4 @@ public interface IDirectoryProviderService
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of deleting a directory, or an error.</returns>
|
||||
ErrorOr<Deleted> DeleteDirectory(FileSystemPathId path);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+7
-4
@@ -17,22 +17,25 @@ public interface IDirectoryService
|
||||
/// Retrieves subdirectories for the specified string path.
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
ErrorOr<IEnumerable<Directory>> GetSubdirectories(string path);
|
||||
ErrorOr<IEnumerable<Directory>> GetSubdirectories(string path, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves subdirectories for the given directory.
|
||||
/// </summary>
|
||||
/// <param name="directory">Directory object to retrieve subdirectories for.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
ErrorOr<IEnumerable<Directory>> GetSubdirectories(Directory directory);
|
||||
ErrorOr<IEnumerable<Directory>> GetSubdirectories(Directory directory, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves subdirectories for the specified file system path.
|
||||
/// </summary>
|
||||
/// <param name="path">Identifier for the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden subdirectories or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of subdirectories or an error.</returns>
|
||||
ErrorOr<IEnumerable<Directory>> GetSubdirectories(FileSystemPathId path);
|
||||
ErrorOr<IEnumerable<Directory>> GetSubdirectories(FileSystemPathId path, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a directory with the specified <paramref name="name"/>, at the specified <paramref name="path"/>.
|
||||
@@ -75,4 +78,4 @@ public interface IDirectoryService
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the result of deleting a directory, or an error.</returns>
|
||||
ErrorOr<Deleted> DeleteDirectory(string path);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -18,8 +18,9 @@ public interface IFileProviderService
|
||||
/// Retrieves a list of files at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path for which to retrieve the list of files.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of file paths, or an error.</returns>
|
||||
ErrorOr<IEnumerable<FileSystemPathId>> GetFilePaths(FileSystemPathId path);
|
||||
ErrorOr<IEnumerable<FileSystemPathId>> GetFilePaths(FileSystemPathId path, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the contents of a file at the specified path.
|
||||
|
||||
+6
-3
@@ -17,22 +17,25 @@ public interface IFileService
|
||||
/// Retrieves files for the specified string path.
|
||||
/// </summary>
|
||||
/// <param name="path">String representation of the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
ErrorOr<IEnumerable<File>> GetFiles(string path);
|
||||
ErrorOr<IEnumerable<File>> GetFiles(string path, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves files associated with a given file.
|
||||
/// </summary>
|
||||
/// <param name="file">The file object.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
ErrorOr<IEnumerable<File>> GetFiles(File file);
|
||||
ErrorOr<IEnumerable<File>> GetFiles(File file, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves files for a specified file path ID.
|
||||
/// </summary>
|
||||
/// <param name="path">Identifier for the file path.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden files or not.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of files or an error.</returns>
|
||||
ErrorOr<IEnumerable<File>> GetFiles(FileSystemPathId path);
|
||||
ErrorOr<IEnumerable<File>> GetFiles(FileSystemPathId path, bool includeHiddenElements);
|
||||
|
||||
/// <summary>
|
||||
/// Copies a file located at <paramref name="sourcePath"/> to <paramref name="destinationPath"/>.
|
||||
|
||||
+20
-8
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
@@ -43,7 +43,9 @@ public class PathService : IPathService
|
||||
public bool IsValidPath(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
return !newPathResult.IsError && _platformContext.PathStrategy.IsValidPath(newPathResult.Value);
|
||||
if (newPathResult.IsError)
|
||||
return false;
|
||||
return _platformContext.PathStrategy.IsValidPath(newPathResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,7 +56,9 @@ public class PathService : IPathService
|
||||
public bool Exists(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
return !newPathResult.IsError && _platformContext.PathStrategy.Exists(newPathResult.Value);
|
||||
if (newPathResult.IsError)
|
||||
return false;
|
||||
return _platformContext.PathStrategy.Exists(newPathResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -69,7 +73,9 @@ public class PathService : IPathService
|
||||
if (newPathResult.IsError)
|
||||
return newPathResult.Errors;
|
||||
ErrorOr<FileSystemPathId> combinedPathResult = _platformContext.PathStrategy.CombinePath(newPathResult.Value, name);
|
||||
return combinedPathResult.IsError ? (ErrorOr<string>)combinedPathResult.Errors : (ErrorOr<string>)combinedPathResult.Value.Path;
|
||||
if (combinedPathResult.IsError)
|
||||
return combinedPathResult.Errors;
|
||||
return combinedPathResult.Value.Path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -80,7 +86,9 @@ public class PathService : IPathService
|
||||
public ErrorOr<IEnumerable<PathSegment>> ParsePath(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
return newPathResult.IsError ? (ErrorOr<IEnumerable<PathSegment>>)newPathResult.Errors : _platformContext.PathStrategy.ParsePath(newPathResult.Value);
|
||||
if (newPathResult.IsError)
|
||||
return newPathResult.Errors;
|
||||
return _platformContext.PathStrategy.ParsePath(newPathResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -91,7 +99,9 @@ public class PathService : IPathService
|
||||
public ErrorOr<IEnumerable<PathSegment>> GoUpOneLevel(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
return newPathResult.IsError ? (ErrorOr<IEnumerable<PathSegment>>)newPathResult.Errors : _platformContext.PathStrategy.GoUpOneLevel(newPathResult.Value);
|
||||
if (newPathResult.IsError)
|
||||
return newPathResult.Errors;
|
||||
return _platformContext.PathStrategy.GoUpOneLevel(newPathResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -111,7 +121,9 @@ public class PathService : IPathService
|
||||
public ErrorOr<PathSegment> GetPathRoot(string path)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(path);
|
||||
return newPathResult.IsError ? (ErrorOr<PathSegment>)newPathResult.Errors : _platformContext.PathStrategy.GetPathRoot(newPathResult.Value);
|
||||
if (newPathResult.IsError)
|
||||
return newPathResult.Errors;
|
||||
return _platformContext.PathStrategy.GetPathRoot(newPathResult.Value);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.PhotoLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
@@ -45,9 +45,9 @@ public class ThumbnailService : IThumbnailService
|
||||
public async Task<ErrorOr<Thumbnail>> GetThumbnailAsync(string path, int quality)
|
||||
{
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
return fileSystemPathIdResult.IsError
|
||||
? (ErrorOr<Thumbnail>)fileSystemPathIdResult.Errors
|
||||
: await GetThumbnailAsync(fileSystemPathIdResult.Value, quality);
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
return fileSystemPathIdResult.Errors;
|
||||
return await GetThumbnailAsync(fileSystemPathIdResult.Value, quality);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -187,4 +187,4 @@ public class ThumbnailService : IThumbnailService
|
||||
return ((value - fromSource) * (toTarget - fromTarget) / (toSource - fromSource)) + fromTarget;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -1,4 +1,6 @@
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Environment;
|
||||
|
||||
@@ -38,4 +40,4 @@ internal class EnvironmentContext : IEnvironmentContext
|
||||
DirectoryProviderService = directoryProviderService;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+8
-6
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
@@ -127,7 +127,9 @@ public class UnixPathStrategy : IUnixPathStrategy
|
||||
return Errors.FileManagement.CannotNavigateUp;
|
||||
// return the path up to the last slash, or, if there's only the root slash, return that one instead
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(lastIndex > 0 ? tempPath[..lastIndex] : tempPath[..1]);
|
||||
return newPathResult.IsError ? (ErrorOr<IEnumerable<PathSegment>>)newPathResult.Errors : ParsePath(newPathResult.Value);
|
||||
if (newPathResult.IsError)
|
||||
return newPathResult.Errors;
|
||||
return ParsePath(newPathResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -150,9 +152,9 @@ public class UnixPathStrategy : IUnixPathStrategy
|
||||
return Errors.FileManagement.InvalidPath;
|
||||
|
||||
// On Unix-like systems, the root is always "/"
|
||||
return path.Path.StartsWith(PathSeparator)
|
||||
? (ErrorOr<PathSegment>)new PathSegment(PathSeparator.ToString(), isDirectory: false, isDrive: true)
|
||||
: (ErrorOr<PathSegment>)Errors.FileManagement.InvalidPath;
|
||||
if (path.Path.StartsWith(PathSeparator))
|
||||
return new PathSegment(PathSeparator.ToString(), isDirectory: false, isDrive: true);
|
||||
return Errors.FileManagement.InvalidPath;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+8
-6
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
@@ -89,9 +89,9 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
public ErrorOr<IEnumerable<PathSegment>> ParsePath(FileSystemPathId path)
|
||||
{
|
||||
// Windows paths usually start with a drive letter and colon, e.g., "C:"
|
||||
return !path.Path.Contains(':') || !path.Path.Contains(PathSeparator) || !char.IsLetter(path.Path[0]) || path.Path[1] != ':' || path.Path[2] != PathSeparator
|
||||
? (ErrorOr<IEnumerable<PathSegment>>)Errors.FileManagement.InvalidPath
|
||||
: ErrorOrFactory.From(GetPathSegments());
|
||||
if (!path.Path.Contains(':') || !path.Path.Contains(PathSeparator) || !char.IsLetter(path.Path[0]) || path.Path[1] != ':' || path.Path[2] != PathSeparator)
|
||||
return Errors.FileManagement.InvalidPath;
|
||||
return ErrorOrFactory.From(GetPathSegments());
|
||||
IEnumerable<PathSegment> GetPathSegments()
|
||||
{
|
||||
// the drive segment
|
||||
@@ -135,7 +135,9 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
return Errors.FileManagement.CannotNavigateUp;
|
||||
// if we are at the drive root level after trimming, return drive root, otherwise, return the path up to the last slash
|
||||
ErrorOr<FileSystemPathId> newPathResult = FileSystemPathId.Create(lastIndex == 2 && tempPath[1] == ':' ? tempPath[..3] : tempPath[..lastIndex]);
|
||||
return newPathResult.IsError ? (ErrorOr<IEnumerable<PathSegment>>)newPathResult.Errors : ParsePath(newPathResult.Value);
|
||||
if (newPathResult.IsError)
|
||||
return newPathResult.Errors;
|
||||
return ParsePath(newPathResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -181,4 +183,4 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
return Errors.FileManagement.InvalidPath;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
@@ -48,7 +48,9 @@ public sealed class FileSystemPathId : ValueObject
|
||||
/// </returns>
|
||||
public static ErrorOr<FileSystemPathId> Create(string path)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(path) ? (ErrorOr<FileSystemPathId>)Errors.FileManagement.InvalidPath : (ErrorOr<FileSystemPathId>)new FileSystemPathId(path);
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
return Errors.FileManagement.InvalidPath;
|
||||
return new FileSystemPathId(path);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -115,13 +115,13 @@ public class StreamInfo : ValueObject
|
||||
Optional<int> sampleRate,
|
||||
Optional<int> channels)
|
||||
{
|
||||
return streamId is null
|
||||
? (ErrorOr<StreamInfo>)Errors.FileManagement.StreamIdCannotBeEmpty
|
||||
: codec is null
|
||||
? (ErrorOr<StreamInfo>)Errors.FileManagement.CodecCannotBeEmpty
|
||||
: bitrate <= 0
|
||||
? (ErrorOr<StreamInfo>)Errors.FileManagement.BitrateMustBeAPositiveNumber
|
||||
: (ErrorOr<StreamInfo>)new StreamInfo(streamId, mimeType, bitrate, codec, resolution, frameRate, sampleRate, channels);
|
||||
if (streamId is null)
|
||||
return Errors.FileManagement.StreamIdCannotBeEmpty;
|
||||
if (codec is null)
|
||||
return Errors.FileManagement.CodecCannotBeEmpty;
|
||||
if (bitrate <= 0)
|
||||
return Errors.FileManagement.BitrateMustBeAPositiveNumber;
|
||||
return new StreamInfo(streamId, mimeType, bitrate, codec, resolution, frameRate, sampleRate, channels);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -137,4 +137,4 @@ public class StreamInfo : ValueObject
|
||||
yield return Channels;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -51,9 +51,11 @@ public class BookRating : Rating
|
||||
/// </returns>
|
||||
public static ErrorOr<BookRating> Create(decimal value, decimal maxValue, Optional<BookRatingSource> source, Optional<int> voteCount)
|
||||
{
|
||||
return maxValue < 0 || value < 0
|
||||
? (ErrorOr<BookRating>)Errors.Metadata.RatingValueMustBePositive
|
||||
: value > maxValue ? (ErrorOr<BookRating>)Errors.Metadata.RatingValueCannotBeGreaterThanMaxValue : (ErrorOr<BookRating>)new BookRating(value, maxValue, source, voteCount);
|
||||
if (maxValue < 0 || value < 0)
|
||||
return Errors.Metadata.RatingValueMustBePositive;
|
||||
if (value > maxValue)
|
||||
return Errors.Metadata.RatingValueCannotBeGreaterThanMaxValue;
|
||||
return new BookRating(value, maxValue, source, voteCount);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -79,4 +81,4 @@ public class BookRating : Rating
|
||||
return baseString;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -17,8 +17,8 @@ namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggrega
|
||||
public sealed class Isbn : ValueObject
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private static readonly Regex Isbn10Regex = new(@"^(?:ISBN(?:-10)?:? )?(?=[0-9X]{10}$|(?=(?:[0-9]+[-\ ]){3})[-\ 0-9X]{13}$)[0-9]{1,5}[-\ ]?[0-9]+[-\ ]?[0-9]+[-\ ]?[0-9X]$", RegexOptions.Compiled);
|
||||
private static readonly Regex Isbn13Regex = new(@"^(?:ISBN(?:-13)?:? )?(?=[0-9]{13}$|(?=(?:[0-9]+[-\ ]){4})[-\ 0-9]{17}$)97[89][-\ ]?[0-9]{1,5}[-\ ]?[0-9]+[-\ ]?[0-9]+[-\ ]?[0-9]$", RegexOptions.Compiled);
|
||||
private static readonly Regex _isbn10Regex = new(@"^(?:ISBN(?:-10)?:? )?(?=[0-9X]{10}$|(?=(?:[0-9]+[-\ ]){3})[-\ 0-9X]{13}$)[0-9]{1,5}[-\ ]?[0-9]+[-\ ]?[0-9]+[-\ ]?[0-9X]$", RegexOptions.Compiled);
|
||||
private static readonly Regex _isbn13Regex = new(@"^(?:ISBN(?:-13)?:? )?(?=[0-9]{13}$|(?=(?:[0-9]+[-\ ]){4})[-\ 0-9]{17}$)97[89][-\ ]?[0-9]{1,5}[-\ ]?[0-9]+[-\ ]?[0-9]+[-\ ]?[0-9]$", RegexOptions.Compiled);
|
||||
#endregion
|
||||
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
@@ -83,7 +83,7 @@ public sealed class Isbn : ValueObject
|
||||
/// <returns><see langword="true"/> if the ISBN-10 is valid, <see langword="false"/> otherwise.</returns>
|
||||
public static bool IsValidIsbn10(string isbn)
|
||||
{
|
||||
if (!Isbn10Regex.IsMatch(isbn))
|
||||
if (!_isbn10Regex.IsMatch(isbn))
|
||||
return false;
|
||||
// remove any hyphens or spaces
|
||||
isbn = isbn.Replace("-", "").Replace(" ", "").ToUpper();
|
||||
@@ -105,7 +105,7 @@ public sealed class Isbn : ValueObject
|
||||
/// <returns><see langword="true"/> if the ISBN-13 is valid, <see langword="false"/> otherwise.</returns>
|
||||
public static bool IsValidIsbn13(string isbn)
|
||||
{
|
||||
if (!Isbn13Regex.IsMatch(isbn))
|
||||
if (!_isbn13Regex.IsMatch(isbn))
|
||||
return false;
|
||||
// remove any hyphens or spaces
|
||||
isbn = isbn.Replace("-", "").Replace(" ", "");
|
||||
@@ -123,4 +123,4 @@ public sealed class Isbn : ValueObject
|
||||
yield return Format;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+10
-10
@@ -88,15 +88,15 @@ public class WrittenContentMetadata : BaseMetadata
|
||||
Optional<string> publisher,
|
||||
Optional<int> pageCount)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(title)
|
||||
? (ErrorOr<WrittenContentMetadata>)Errors.Metadata.TitleCannotBeEmpty
|
||||
: releaseInfo is null
|
||||
? (ErrorOr<WrittenContentMetadata>)Errors.Metadata.ReleaseInfoCannotBeNull
|
||||
: genres is null
|
||||
? (ErrorOr<WrittenContentMetadata>)Errors.Metadata.GenresListCannotBeNull
|
||||
: tags is null
|
||||
? (ErrorOr<WrittenContentMetadata>)Errors.Metadata.TagsListCannotBeNull
|
||||
: (ErrorOr<WrittenContentMetadata>)new WrittenContentMetadata(
|
||||
if (string.IsNullOrWhiteSpace(title))
|
||||
return Errors.Metadata.TitleCannotBeEmpty;
|
||||
if (releaseInfo is null)
|
||||
return Errors.Metadata.ReleaseInfoCannotBeNull;
|
||||
if (genres is null)
|
||||
return Errors.Metadata.GenresListCannotBeNull;
|
||||
if (tags is null)
|
||||
return Errors.Metadata.TagsListCannotBeNull;
|
||||
return new WrittenContentMetadata(
|
||||
title,
|
||||
originalTitle,
|
||||
description,
|
||||
@@ -118,4 +118,4 @@ public class WrittenContentMetadata : BaseMetadata
|
||||
yield return PageCount;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user