Windows fixes
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0"/>
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Providers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FileTime.Providers.Local
|
||||
{
|
||||
public class LocalContentProvider : IContentProvider
|
||||
{
|
||||
private readonly ILogger<LocalContentProvider> _logger;
|
||||
|
||||
public IReadOnlyList<IContainer> RootContainers { get; }
|
||||
|
||||
public IReadOnlyList<IItem> Items => RootContainers;
|
||||
@@ -23,8 +26,14 @@ namespace FileTime.Providers.Local
|
||||
|
||||
public event EventHandler? Refreshed;
|
||||
|
||||
public LocalContentProvider()
|
||||
public bool IsCaseInsensitive { get; }
|
||||
|
||||
public LocalContentProvider(ILogger<LocalContentProvider> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
|
||||
IsCaseInsensitive = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
|
||||
var rootDirectories = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
|
||||
? new DirectoryInfo("/").GetDirectories()
|
||||
: Environment.GetLogicalDrives().Select(d => new DirectoryInfo(d));
|
||||
@@ -36,10 +45,15 @@ namespace FileTime.Providers.Local
|
||||
|
||||
public IItem? GetByPath(string path)
|
||||
{
|
||||
var pathParts = path.TrimStart(Constants.SeparatorChar).Split(Constants.SeparatorChar);
|
||||
var rootContainer = RootContainers.FirstOrDefault(c => c.Name == pathParts[0]);
|
||||
var pathParts = (IsCaseInsensitive ? path.ToLower() : path).TrimStart(Constants.SeparatorChar).Split(Constants.SeparatorChar);
|
||||
var rootContainer = RootContainers.FirstOrDefault(c => NormalizePath(c.Name) == NormalizePath(pathParts[0]));
|
||||
|
||||
if (rootContainer == null) return null;
|
||||
_logger.LogError("No root container found with name '{0}'", path[0]);
|
||||
if (rootContainer == null)
|
||||
{
|
||||
_logger.LogWarning("No root container found with name '{0}'", path[0]);
|
||||
return null;
|
||||
}
|
||||
|
||||
return rootContainer.GetByPath(string.Join(Constants.SeparatorChar, pathParts.Skip(1)));
|
||||
}
|
||||
@@ -57,5 +71,7 @@ namespace FileTime.Providers.Local
|
||||
public bool IsExists(string name) => Items.Any(i => i.Name == name);
|
||||
|
||||
public void Delete() => throw new NotSupportedException();
|
||||
|
||||
internal string NormalizePath(string path) => IsCaseInsensitive ? path.ToLower() : path;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,8 @@ namespace FileTime.Providers.Local
|
||||
|
||||
public bool IsHidden => (Directory.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
|
||||
public DirectoryInfo Directory { get; }
|
||||
public IContentProvider Provider { get; }
|
||||
public LocalContentProvider Provider { get; }
|
||||
IContentProvider IItem.Provider => Provider;
|
||||
|
||||
public IReadOnlyList<IItem> Items
|
||||
{
|
||||
@@ -53,12 +54,12 @@ namespace FileTime.Providers.Local
|
||||
|
||||
public event EventHandler? Refreshed;
|
||||
|
||||
public LocalFolder(DirectoryInfo directory, IContentProvider contentProvider, IContainer? parent)
|
||||
public LocalFolder(DirectoryInfo directory, LocalContentProvider contentProvider, IContainer? parent)
|
||||
{
|
||||
Directory = directory;
|
||||
_parent = parent;
|
||||
|
||||
Name = directory.Name;
|
||||
Name = directory.Name.TrimEnd(Path.DirectorySeparatorChar);
|
||||
FullName = parent?.FullName == null ? Name : parent.FullName + Constants.SeparatorChar + Name;
|
||||
Provider = contentProvider;
|
||||
}
|
||||
@@ -85,7 +86,7 @@ namespace FileTime.Providers.Local
|
||||
{
|
||||
var paths = path.Split(Constants.SeparatorChar);
|
||||
|
||||
var item = Items.FirstOrDefault(i => i.Name == paths[0]);
|
||||
var item = Items.FirstOrDefault(i => Provider.NormalizePath(i.Name) == Provider.NormalizePath(paths[0]));
|
||||
|
||||
if (paths.Length == 1)
|
||||
{
|
||||
@@ -104,7 +105,7 @@ namespace FileTime.Providers.Local
|
||||
Directory.CreateSubdirectory(name);
|
||||
Refresh();
|
||||
|
||||
return _containers!.FirstOrDefault(c => c.Name == name)!;
|
||||
return _containers!.FirstOrDefault(c => Provider.NormalizePath(c.Name) == Provider.NormalizePath(name))!;
|
||||
}
|
||||
|
||||
public IElement CreateElement(string name)
|
||||
@@ -112,14 +113,11 @@ namespace FileTime.Providers.Local
|
||||
using (File.Create(Path.Combine(Directory.FullName, name))) { }
|
||||
Refresh();
|
||||
|
||||
return _elements!.FirstOrDefault(e => e.Name == name)!;
|
||||
return _elements!.FirstOrDefault(e => Provider.NormalizePath(e.Name) == Provider.NormalizePath(name))!;
|
||||
}
|
||||
|
||||
public bool IsExists(string name) => Items.Any(i => i.Name == name);
|
||||
public bool IsExists(string name) => Items.Any(i => Provider.NormalizePath(i.Name) == Provider.NormalizePath(name));
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
Directory.Delete(true);
|
||||
}
|
||||
public void Delete() => Directory.Delete(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user