Windows fixes
This commit is contained in:
@@ -8,11 +8,14 @@ using FileTime.Core.Providers;
|
|||||||
using FileTime.Core.StateManagement;
|
using FileTime.Core.StateManagement;
|
||||||
using FileTime.Providers.Local;
|
using FileTime.Providers.Local;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace FileTime.ConsoleUI
|
namespace FileTime.ConsoleUI
|
||||||
{
|
{
|
||||||
public static class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
static ILogger<Program>? _logger;
|
||||||
|
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
/* Console.Clear();
|
/* Console.Clear();
|
||||||
@@ -47,11 +50,14 @@ namespace FileTime.ConsoleUI
|
|||||||
return; */
|
return; */
|
||||||
|
|
||||||
var serviceProvider = CreateServiceProvider();
|
var serviceProvider = CreateServiceProvider();
|
||||||
|
_logger = serviceProvider.GetService<ILogger<Program>>()!;
|
||||||
|
|
||||||
var coloredConsoleRenderer = serviceProvider.GetService<IColoredConsoleRenderer>()!;
|
var coloredConsoleRenderer = serviceProvider.GetService<IColoredConsoleRenderer>()!;
|
||||||
var localContentProvider = serviceProvider.GetService<LocalContentProvider>()!;
|
var localContentProvider = serviceProvider.GetService<LocalContentProvider>()!;
|
||||||
|
|
||||||
var currentPossibleDirectory = localContentProvider.GetByPath(Environment.CurrentDirectory.Replace(Path.DirectorySeparatorChar, Constants.SeparatorChar));
|
var currentPath = Environment.CurrentDirectory.Replace(Path.DirectorySeparatorChar, Constants.SeparatorChar);
|
||||||
|
_logger.LogInformation("Current directory: '{0}'", currentPath);
|
||||||
|
var currentPossibleDirectory = localContentProvider.GetByPath(currentPath);
|
||||||
|
|
||||||
if (currentPossibleDirectory is IContainer container)
|
if (currentPossibleDirectory is IContainer container)
|
||||||
{
|
{
|
||||||
@@ -77,12 +83,14 @@ namespace FileTime.ConsoleUI
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("Current working directory is not a directory???");
|
Console.WriteLine("Current working directory is not a directory???");
|
||||||
|
Thread.Sleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ServiceProvider CreateServiceProvider()
|
private static ServiceProvider CreateServiceProvider()
|
||||||
{
|
{
|
||||||
return new ServiceCollection()
|
return new ServiceCollection()
|
||||||
|
.AddLogging((builder) => builder.AddConsole().AddDebug())
|
||||||
.AddSingleton<Application>()
|
.AddSingleton<Application>()
|
||||||
.AddSingleton<IStyles>(new Styles(true))
|
.AddSingleton<IStyles>(new Styles(true))
|
||||||
.AddSingleton<IColoredConsoleRenderer, ColoredConsoleRenderer>()
|
.AddSingleton<IColoredConsoleRenderer, ColoredConsoleRenderer>()
|
||||||
@@ -96,8 +104,11 @@ namespace FileTime.ConsoleUI
|
|||||||
.RegisterCommandHandlers()
|
.RegisterCommandHandlers()
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static IServiceCollection RegisterCommandHandlers(this IServiceCollection serviceCollection)
|
internal static class ProgramExtensions
|
||||||
|
{
|
||||||
|
internal static IServiceCollection RegisterCommandHandlers(this IServiceCollection serviceCollection)
|
||||||
{
|
{
|
||||||
foreach (var commandHandler in Startup.GetCommandHandlers())
|
foreach (var commandHandler in Startup.GetCommandHandlers())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0"/>
|
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0"/>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
using FileTime.Core.Providers;
|
using FileTime.Core.Providers;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace FileTime.Providers.Local
|
namespace FileTime.Providers.Local
|
||||||
{
|
{
|
||||||
public class LocalContentProvider : IContentProvider
|
public class LocalContentProvider : IContentProvider
|
||||||
{
|
{
|
||||||
|
private readonly ILogger<LocalContentProvider> _logger;
|
||||||
|
|
||||||
public IReadOnlyList<IContainer> RootContainers { get; }
|
public IReadOnlyList<IContainer> RootContainers { get; }
|
||||||
|
|
||||||
public IReadOnlyList<IItem> Items => RootContainers;
|
public IReadOnlyList<IItem> Items => RootContainers;
|
||||||
@@ -23,8 +26,14 @@ namespace FileTime.Providers.Local
|
|||||||
|
|
||||||
public event EventHandler? Refreshed;
|
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)
|
var rootDirectories = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
|
||||||
? new DirectoryInfo("/").GetDirectories()
|
? new DirectoryInfo("/").GetDirectories()
|
||||||
: Environment.GetLogicalDrives().Select(d => new DirectoryInfo(d));
|
: Environment.GetLogicalDrives().Select(d => new DirectoryInfo(d));
|
||||||
@@ -36,10 +45,15 @@ namespace FileTime.Providers.Local
|
|||||||
|
|
||||||
public IItem? GetByPath(string path)
|
public IItem? GetByPath(string path)
|
||||||
{
|
{
|
||||||
var pathParts = path.TrimStart(Constants.SeparatorChar).Split(Constants.SeparatorChar);
|
var pathParts = (IsCaseInsensitive ? path.ToLower() : path).TrimStart(Constants.SeparatorChar).Split(Constants.SeparatorChar);
|
||||||
var rootContainer = RootContainers.FirstOrDefault(c => c.Name == pathParts[0]);
|
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)));
|
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 bool IsExists(string name) => Items.Any(i => i.Name == name);
|
||||||
|
|
||||||
public void Delete() => throw new NotSupportedException();
|
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 bool IsHidden => (Directory.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
|
||||||
public DirectoryInfo Directory { get; }
|
public DirectoryInfo Directory { get; }
|
||||||
public IContentProvider Provider { get; }
|
public LocalContentProvider Provider { get; }
|
||||||
|
IContentProvider IItem.Provider => Provider;
|
||||||
|
|
||||||
public IReadOnlyList<IItem> Items
|
public IReadOnlyList<IItem> Items
|
||||||
{
|
{
|
||||||
@@ -53,12 +54,12 @@ namespace FileTime.Providers.Local
|
|||||||
|
|
||||||
public event EventHandler? Refreshed;
|
public event EventHandler? Refreshed;
|
||||||
|
|
||||||
public LocalFolder(DirectoryInfo directory, IContentProvider contentProvider, IContainer? parent)
|
public LocalFolder(DirectoryInfo directory, LocalContentProvider contentProvider, IContainer? parent)
|
||||||
{
|
{
|
||||||
Directory = directory;
|
Directory = directory;
|
||||||
_parent = parent;
|
_parent = parent;
|
||||||
|
|
||||||
Name = directory.Name;
|
Name = directory.Name.TrimEnd(Path.DirectorySeparatorChar);
|
||||||
FullName = parent?.FullName == null ? Name : parent.FullName + Constants.SeparatorChar + Name;
|
FullName = parent?.FullName == null ? Name : parent.FullName + Constants.SeparatorChar + Name;
|
||||||
Provider = contentProvider;
|
Provider = contentProvider;
|
||||||
}
|
}
|
||||||
@@ -85,7 +86,7 @@ namespace FileTime.Providers.Local
|
|||||||
{
|
{
|
||||||
var paths = path.Split(Constants.SeparatorChar);
|
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)
|
if (paths.Length == 1)
|
||||||
{
|
{
|
||||||
@@ -104,7 +105,7 @@ namespace FileTime.Providers.Local
|
|||||||
Directory.CreateSubdirectory(name);
|
Directory.CreateSubdirectory(name);
|
||||||
Refresh();
|
Refresh();
|
||||||
|
|
||||||
return _containers!.FirstOrDefault(c => c.Name == name)!;
|
return _containers!.FirstOrDefault(c => Provider.NormalizePath(c.Name) == Provider.NormalizePath(name))!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IElement CreateElement(string name)
|
public IElement CreateElement(string name)
|
||||||
@@ -112,14 +113,11 @@ namespace FileTime.Providers.Local
|
|||||||
using (File.Create(Path.Combine(Directory.FullName, name))) { }
|
using (File.Create(Path.Combine(Directory.FullName, name))) { }
|
||||||
Refresh();
|
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()
|
public void Delete() => Directory.Delete(true);
|
||||||
{
|
|
||||||
Directory.Delete(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user