Base project

This commit is contained in:
2022-03-31 15:35:33 +00:00
parent 389c392899
commit ad5bedf339
35 changed files with 637 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
using FileTime.Providers.Local;
using Microsoft.Extensions.DependencyInjection;
namespace FileTime.App.DependencyInjection
{
public static class DependencyInjection
{
public static IServiceCollection RegisterDefaultServices(IServiceCollection? serviceCollection = null)
{
serviceCollection ??= new ServiceCollection();
return serviceCollection
.AddLocalServices();
}
}
}

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Providers\FileTime.Providers.Local\FileTime.Providers.Local.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,7 @@
namespace FileTime.Core.Behaviors
{
public interface IOnContainerEnter
{
Task OnEnter();
}
}

View File

@@ -0,0 +1,9 @@
namespace FileTime.Core.Enums
{
public enum AbsolutePathType
{
Unknown,
Container,
Element
}
}

View File

@@ -0,0 +1,9 @@
namespace FileTime.Core.Enums
{
public enum SupportsDelete
{
False,
True,
HardDeleteOnly,
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Reactive" Version="5.0.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,4 @@
namespace FileTime.Core.Models
{
public record FullName(string Path);
}

View File

@@ -0,0 +1,13 @@
using FileTime.Core.Enums;
using FileTime.Core.Services;
namespace FileTime.Core.Models
{
public interface IAbsolutePath
{
IContentProvider ContentProvider { get; }
IContentProvider? VirtualContentProvider { get; }
FullName Path { get; }
AbsolutePathType Type { get; }
}
}

View File

@@ -0,0 +1,7 @@
namespace FileTime.Core.Models
{
public interface IContainer : IItem
{
IReadOnlyList<IAbsolutePath> Items { get; }
}
}

View File

@@ -0,0 +1,7 @@
namespace FileTime.Core.Models
{
public interface IElement : IItem
{
}
}

View File

@@ -0,0 +1,7 @@
namespace FileTime.Core.Models
{
public interface IFileElement : IElement
{
}
}

View File

@@ -0,0 +1,18 @@
using FileTime.Core.Enums;
using FileTime.Core.Services;
namespace FileTime.Core.Models
{
public interface IItem
{
string Name { get; }
string DisplayName { get; }
FullName? FullName { get; }
NativePath? NativePath { get; }
bool IsHidden { get; }
bool IsExists { get; }
SupportsDelete CanDelete { get; }
bool CanRename { get; }
IContentProvider Provider { get; }
}
}

View File

@@ -0,0 +1,4 @@
namespace FileTime.Core.Models
{
public record NativePath(string Path);
}

View File

@@ -0,0 +1,12 @@
using FileTime.Core.Behaviors;
using FileTime.Core.Models;
namespace FileTime.Core.Services
{
public interface IContentProvider : IContainer, IOnContainerEnter
{
Task<IItem> GetItemByFullNameAsync(FullName fullName);
Task<IItem> GetItemByNativePathAsync(NativePath nativePath);
Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName);
}
}

View File

@@ -0,0 +1,7 @@
namespace FileTime.Core.Services
{
public interface ITab
{
}
}

View File

@@ -0,0 +1,22 @@
using FileTime.Core.Enums;
using FileTime.Core.Services;
namespace FileTime.Core.Models
{
public class AbsolutePath : IAbsolutePath
{
public IContentProvider ContentProvider { get; }
public IContentProvider? VirtualContentProvider { get; }
public FullName Path { get; }
public AbsolutePathType Type { get; }
public AbsolutePath(IContentProvider contentProvider, FullName path, AbsolutePathType type, IContentProvider? virtualContentProvider = null)
{
ContentProvider = contentProvider;
Path = path;
VirtualContentProvider = virtualContentProvider;
Type = type;
}
}
}

View File

@@ -0,0 +1,8 @@
namespace FileTime.Core.Models
{
public static class Constants
{
public const char SeparatorChar = '/';
public const string ContentProviderProtocol = "ctp://";
}
}

View File

@@ -0,0 +1,17 @@
using FileTime.Core.Enums;
using FileTime.Core.Services;
namespace FileTime.Core.Models
{
public record Container
(string Name,
string DisplayName,
FullName FullName,
NativePath NativePath,
bool IsHidden,
bool IsExists,
SupportsDelete CanDelete,
bool CanRename,
IContentProvider Provider,
IReadOnlyList<IAbsolutePath> Items) : IContainer;
}

View File

@@ -0,0 +1,16 @@
using FileTime.Core.Enums;
using FileTime.Core.Services;
namespace FileTime.Core.Models
{
public record Element
(string Name,
string DisplayName,
FullName FullName,
NativePath NativePath,
bool IsHidden,
bool IsExists,
SupportsDelete CanDelete,
bool CanRename,
IContentProvider Provider) : IElement;
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,41 @@
using FileTime.Core.Enums;
using FileTime.Core.Models;
namespace FileTime.Core.Services
{
public abstract class ContentProviderBase : IContentProvider
{
protected List<IAbsolutePath> Items { get; set; } = new List<IAbsolutePath>();
IReadOnlyList<IAbsolutePath> IContainer.Items => Items;
public string Name { get; }
public string DisplayName { get; }
public FullName? FullName => null;
public NativePath? NativePath => null;
public bool IsHidden => false;
public bool IsExists => true;
public SupportsDelete CanDelete => SupportsDelete.False;
public bool CanRename => false;
public IContentProvider Provider => this;
protected ContentProviderBase(string name)
{
DisplayName = Name = name;
}
public virtual Task OnEnter() => Task.CompletedTask;
public virtual async Task<IItem> GetItemByFullNameAsync(FullName fullName) => await GetItemByNativePathAsync(GetNativePath(fullName));
public abstract Task<IItem> GetItemByNativePathAsync(NativePath nativePath);
public abstract Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName);
public abstract NativePath GetNativePath(FullName fullName);
}
}

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Reactive" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" />
<ProjectReference Include="..\FileTime.Core.Models\FileTime.Core.Models.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,7 @@
namespace FileTime.Core.Services
{
public class Tab : ITab
{
}
}

76
src/FileTime.sln Normal file
View File

@@ -0,0 +1,76 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32203.90
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{3324D046-1E05-46B5-B1BA-82910D56B332}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileTime.Core.Abstraction", "Core\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj", "{99562652-F633-4496-9932-AF8E614906C4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileTime.Core.Models", "Core\FileTime.Core.Models\FileTime.Core.Models.csproj", "{E4681ADE-BAF7-4903-BD2F-59C144AE5637}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileTime.Core.Services", "Core\FileTime.Core.Services\FileTime.Core.Services.csproj", "{5DEA3A08-62FF-4508-B755-3DABA96FC2B2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GuiApp", "GuiApp", "{8ADCA794-440F-4E8F-B9F2-2A30E54119A7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ConsoleApp", "ConsoleApp", "{CAEEAD3C-41EB-405C-ACA9-BA1E4C352549}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AppCommon", "AppCommon", "{A5291117-3001-498B-AC8B-E14F71F72570}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Avalonia", "Avalonia", "{01F231DE-4A65-435F-B4BB-77EE5221890C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileTime.GuiApp", "GuiApp\Avalonia\FileTime.GuiApp\FileTime.GuiApp.csproj", "{C389087E-EB78-4DCD-96AF-F1E2A4DEE0B0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Providers", "Providers", "{2FC40FE1-4446-44AB-BF77-00F94D995FA3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileTime.Providers.Local", "Providers\FileTime.Providers.Local\FileTime.Providers.Local.csproj", "{EA3C5B46-3950-4CD6-8FA9-45E17C63DAFA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileTime.App.DependencyInjection", "AppCommon\FileTime.App.DependencyInjection\FileTime.App.DependencyInjection.csproj", "{A55F4A86-03ED-4D25-807A-04619A1D9507}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{99562652-F633-4496-9932-AF8E614906C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99562652-F633-4496-9932-AF8E614906C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99562652-F633-4496-9932-AF8E614906C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99562652-F633-4496-9932-AF8E614906C4}.Release|Any CPU.Build.0 = Release|Any CPU
{E4681ADE-BAF7-4903-BD2F-59C144AE5637}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4681ADE-BAF7-4903-BD2F-59C144AE5637}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4681ADE-BAF7-4903-BD2F-59C144AE5637}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4681ADE-BAF7-4903-BD2F-59C144AE5637}.Release|Any CPU.Build.0 = Release|Any CPU
{5DEA3A08-62FF-4508-B755-3DABA96FC2B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5DEA3A08-62FF-4508-B755-3DABA96FC2B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5DEA3A08-62FF-4508-B755-3DABA96FC2B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5DEA3A08-62FF-4508-B755-3DABA96FC2B2}.Release|Any CPU.Build.0 = Release|Any CPU
{C389087E-EB78-4DCD-96AF-F1E2A4DEE0B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C389087E-EB78-4DCD-96AF-F1E2A4DEE0B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C389087E-EB78-4DCD-96AF-F1E2A4DEE0B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C389087E-EB78-4DCD-96AF-F1E2A4DEE0B0}.Release|Any CPU.Build.0 = Release|Any CPU
{EA3C5B46-3950-4CD6-8FA9-45E17C63DAFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA3C5B46-3950-4CD6-8FA9-45E17C63DAFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA3C5B46-3950-4CD6-8FA9-45E17C63DAFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA3C5B46-3950-4CD6-8FA9-45E17C63DAFA}.Release|Any CPU.Build.0 = Release|Any CPU
{A55F4A86-03ED-4D25-807A-04619A1D9507}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A55F4A86-03ED-4D25-807A-04619A1D9507}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A55F4A86-03ED-4D25-807A-04619A1D9507}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A55F4A86-03ED-4D25-807A-04619A1D9507}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{99562652-F633-4496-9932-AF8E614906C4} = {3324D046-1E05-46B5-B1BA-82910D56B332}
{E4681ADE-BAF7-4903-BD2F-59C144AE5637} = {3324D046-1E05-46B5-B1BA-82910D56B332}
{5DEA3A08-62FF-4508-B755-3DABA96FC2B2} = {3324D046-1E05-46B5-B1BA-82910D56B332}
{01F231DE-4A65-435F-B4BB-77EE5221890C} = {8ADCA794-440F-4E8F-B9F2-2A30E54119A7}
{C389087E-EB78-4DCD-96AF-F1E2A4DEE0B0} = {01F231DE-4A65-435F-B4BB-77EE5221890C}
{EA3C5B46-3950-4CD6-8FA9-45E17C63DAFA} = {2FC40FE1-4446-44AB-BF77-00F94D995FA3}
{A55F4A86-03ED-4D25-807A-04619A1D9507} = {A5291117-3001-498B-AC8B-E14F71F72570}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {859FB3DF-C60A-46B1-82E5-90274905D1EF}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,11 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FileTime.GuiApp"
x:Class="FileTime.GuiApp.App">
<Application.DataTemplates>
</Application.DataTemplates>
<Application.Styles>
<FluentTheme Mode="Light"/>
</Application.Styles>
</Application>

View File

@@ -0,0 +1,29 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using FileTime.GuiApp.ViewModels;
using FileTime.GuiApp.Views;
namespace FileTime.GuiApp
{
public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
};
}
base.OnFrameworkInitializationCompleted();
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<!--Avalonia doesen't support TrimMode=link currently,but we are working on that https://github.com/AvaloniaUI/Avalonia/issues/6892 -->
<TrimMode>copyused</TrimMode>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationIcon>Assets\filetime.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**" />
<None Remove=".gitignore" />
</ItemGroup>
<ItemGroup>
<Content Include="Assets\filetime.ico" />
</ItemGroup>
<ItemGroup>
<!--This helps with theme dll-s trimming.
If you will publish your application in self-contained mode with p:PublishTrimmed=true and it will use Fluent theme Default theme will be trimmed from the output and vice versa.
https://github.com/AvaloniaUI/Avalonia/issues/5593 -->
<TrimmableAssembly Include="Avalonia.Themes.Fluent" />
<TrimmableAssembly Include="Avalonia.Themes.Default" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.13" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.13" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.13" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.13" />
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\AppCommon\FileTime.App.DependencyInjection\FileTime.App.DependencyInjection.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,23 @@
using System;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.ReactiveUI;
namespace FileTime.GuiApp
{
class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
}
}

View File

@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FileTime.GuiApp.ViewModels
{
public class MainWindowViewModel
{
}
}

View File

@@ -0,0 +1,17 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:FileTime.GuiApp.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="FileTime.GuiApp.Views.MainWindow"
Icon="/Assets/filetime.ico"
Title="FileTime.GuiApp">
<Design.DataContext>
<vm:MainWindowViewModel/>
</Design.DataContext>
<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Window>

View File

@@ -0,0 +1,12 @@
using Avalonia.Controls;
namespace FileTime.GuiApp.Views
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" />
<ProjectReference Include="..\..\Core\FileTime.Core.Models\FileTime.Core.Models.csproj" />
<ProjectReference Include="..\..\Core\FileTime.Core.Services\FileTime.Core.Services.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,99 @@
using System.Runtime.InteropServices;
using FileTime.Core.Enums;
using FileTime.Core.Models;
using FileTime.Core.Services;
namespace FileTime.Providers.Local
{
public class LocalContentProvider : ContentProviderBase
{
protected bool IsCaseInsensitive { get; init; }
public LocalContentProvider() : base("local")
{
IsCaseInsensitive = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
RefreshRootDirectories();
}
public override Task OnEnter()
{
RefreshRootDirectories();
return Task.CompletedTask;
}
private void RefreshRootDirectories()
{
var rootDirectories = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? new DirectoryInfo("/").GetDirectories()
: Environment.GetLogicalDrives().Select(d => new DirectoryInfo(d));
Items.Clear();
Items.AddRange(rootDirectories.Select(DirectoryToAbsolutePath));
}
public override Task<IItem> GetItemByNativePathAsync(NativePath nativePath)
{
var path = nativePath.Path;
if (Directory.Exists(path))
{
return Task.FromResult((IItem)DirectoryToContainer(new DirectoryInfo(path)));
}
else if (File.Exists(path))
{
return Task.FromResult((IItem)FileToElement(new FileInfo(path)));
}
throw new FileNotFoundException();
}
public override Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName) => Task.FromResult(GetItemsByContainer(fullName));
public List<IAbsolutePath> GetItemsByContainer(FullName fullName) => GetItemsByContainer(new DirectoryInfo(GetNativePath(fullName).Path));
public List<IAbsolutePath> GetItemsByContainer(DirectoryInfo directoryInfo) => directoryInfo.GetDirectories().Select(DirectoryToAbsolutePath).Concat(directoryInfo.GetFiles().Select(FileToAbsolutePath)).ToList();
private IAbsolutePath DirectoryToAbsolutePath(DirectoryInfo directoryInfo)
{
var fullName = GetFullName(directoryInfo);
return new AbsolutePath(this, fullName, AbsolutePathType.Container);
}
private IAbsolutePath FileToAbsolutePath(FileInfo file)
{
var fullName = GetFullName(file);
return new AbsolutePath(this, fullName, AbsolutePathType.Element);
}
private Container DirectoryToContainer(DirectoryInfo directoryInfo) =>
new(
directoryInfo.Name,
directoryInfo.Name,
GetFullName(directoryInfo.FullName),
new(directoryInfo.FullName),
(directoryInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden,
directoryInfo.Exists,
SupportsDelete.True,
true,
this,
GetItemsByContainer(directoryInfo)
);
private Element FileToElement(FileInfo fileInfo) =>
new(
fileInfo.Name,
fileInfo.Name,
GetFullName(fileInfo),
new(fileInfo.FullName),
(fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden,
fileInfo.Exists,
SupportsDelete.True,
true,
this
);
private FullName GetFullName(DirectoryInfo directoryInfo) => GetFullName(directoryInfo.FullName);
private FullName GetFullName(FileInfo fileInfo) => GetFullName(fileInfo.FullName);
private FullName GetFullName(NativePath nativePath) => GetFullName(nativePath.Path);
private FullName GetFullName(string nativePath) => new(Name + Constants.SeparatorChar + string.Join(Constants.SeparatorChar, nativePath.Split(Path.DirectorySeparatorChar)));
public override NativePath GetNativePath(FullName fullName) => new(string.Join(Path.DirectorySeparatorChar, fullName.Path.Split(Constants.SeparatorChar).Skip(1)));
}
}

View File

@@ -0,0 +1,15 @@
using FileTime.Core.Services;
using Microsoft.Extensions.DependencyInjection;
namespace FileTime.Providers.Local
{
public static class Startup
{
public static IServiceCollection AddLocalServices(this IServiceCollection serviceCollection)
{
return serviceCollection
.AddSingleton<LocalContentProvider>()
.AddSingleton<IContentProvider, LocalContentProvider>(sp => sp.GetService<LocalContentProvider>() ?? throw new Exception($"No {nameof(LocalContentProvider)} instance found"));
}
}
}