TimeTravel
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
using FileTime.Core.Command;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.StateManagement;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.Providers.Local.CommandHandlers
|
||||
{
|
||||
public class CopyCommandHandler : ICommandHandler
|
||||
{
|
||||
private readonly List<Thread> _copyOperations = new();
|
||||
private readonly ElementCreationStates _elementCreationStates;
|
||||
|
||||
public CopyCommandHandler(ElementCreationStates elementCreationStates)
|
||||
@@ -25,17 +25,14 @@ namespace FileTime.Providers.Local.CommandHandlers
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Execute(object command)
|
||||
public async Task ExecuteAsync(object command, TimeRunner timeRunner)
|
||||
{
|
||||
if (command is not CopyCommand copyCommand) throw new ArgumentException($"Can not execute command of type '{command.GetType()}'.");
|
||||
|
||||
var thread = new Thread(() => copyCommand.Execute(CopyElement));
|
||||
thread.Start();
|
||||
|
||||
_copyOperations.Add(thread);
|
||||
await copyCommand.Execute(CopyElement, timeRunner);
|
||||
}
|
||||
|
||||
public void CopyElement(IAbsolutePath sourcePath, IAbsolutePath targetPath)
|
||||
public static void CopyElement(AbsolutePath sourcePath, AbsolutePath targetPath)
|
||||
{
|
||||
using var sourceStream = File.OpenRead(sourcePath.Path);
|
||||
using var sourceReader = new BinaryReader(sourceStream);
|
||||
@@ -43,7 +40,7 @@ namespace FileTime.Providers.Local.CommandHandlers
|
||||
using var targetStream = File.OpenWrite(targetPath.Path);
|
||||
using var targetWriter = new BinaryWriter(targetStream);
|
||||
|
||||
var bufferSize = 1024 * 1024;
|
||||
const int bufferSize = 1024 * 1024;
|
||||
byte[] dataRead;
|
||||
|
||||
do
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using AsyncEvent;
|
||||
using FileTime.Core.Models;
|
||||
@@ -19,12 +20,15 @@ namespace FileTime.Providers.Local
|
||||
|
||||
public string? FullName { get; }
|
||||
public bool IsHidden => false;
|
||||
public bool IsLoaded => true;
|
||||
|
||||
public IContentProvider Provider => this;
|
||||
|
||||
public AsyncEventHandler Refreshed { get; } = new();
|
||||
|
||||
public bool IsCaseInsensitive { get; }
|
||||
public bool CanDelete => false;
|
||||
public bool CanRename => false;
|
||||
|
||||
public LocalContentProvider(ILogger<LocalContentProvider> logger)
|
||||
{
|
||||
@@ -81,5 +85,7 @@ namespace FileTime.Providers.Local
|
||||
public Task<IReadOnlyList<IItem>?> GetItems(CancellationToken token = default) => Task.FromResult(_items);
|
||||
public Task<IReadOnlyList<IContainer>?> GetContainers(CancellationToken token = default) => Task.FromResult((IReadOnlyList<IContainer>?)_rootContainers);
|
||||
public Task<IReadOnlyList<IElement>?> GetElements(CancellationToken token = default) => Task.FromResult(_elements);
|
||||
|
||||
public Task Rename(string newName) => throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,18 @@ namespace FileTime.Providers.Local
|
||||
public string Attributes => GetAttributes();
|
||||
|
||||
public DateTime CreatedAt => File.CreationTime;
|
||||
public bool CanDelete => true;
|
||||
public bool CanRename => true;
|
||||
|
||||
public LocalFile(FileInfo file, IContentProvider contentProvider)
|
||||
private readonly LocalFolder _parent;
|
||||
|
||||
public LocalFile(FileInfo file, LocalFolder parent, IContentProvider contentProvider)
|
||||
{
|
||||
_parent = parent;
|
||||
File = file;
|
||||
|
||||
Name = file.Name;
|
||||
FullName = file.FullName;
|
||||
FullName = parent.FullName + Constants.SeparatorChar + file.Name;
|
||||
Provider = contentProvider;
|
||||
}
|
||||
|
||||
@@ -41,6 +46,14 @@ namespace FileTime.Providers.Local
|
||||
File.Delete();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
public async Task Rename(string newName)
|
||||
{
|
||||
if (_parent is LocalFolder parentFolder)
|
||||
{
|
||||
System.IO.File.Move(File.FullName, Path.Combine(parentFolder.Directory.FullName, newName));
|
||||
await _parent.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public string GetAttributes()
|
||||
{
|
||||
@@ -57,5 +70,7 @@ namespace FileTime.Providers.Local
|
||||
+ ((File.Attributes & FileAttributes.System) == FileAttributes.System ? "s" : "-");
|
||||
}
|
||||
}
|
||||
|
||||
public IContainer? GetParent() => _parent;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,12 @@ namespace FileTime.Providers.Local
|
||||
|
||||
public string FullName { get; }
|
||||
|
||||
public bool IsLoaded => _items != null;
|
||||
public bool CanDelete => true;
|
||||
public bool CanRename => true;
|
||||
|
||||
public AsyncEventHandler Refreshed { get; } = new();
|
||||
|
||||
public string Attributes => GetAttributes();
|
||||
|
||||
public DateTime CreatedAt => Directory.CreationTime;
|
||||
@@ -48,7 +53,7 @@ namespace FileTime.Providers.Local
|
||||
try
|
||||
{
|
||||
_containers = Directory.GetDirectories().Select(d => new LocalFolder(d, Provider, this)).OrderBy(d => d.Name).ToList().AsReadOnly();
|
||||
_elements = Directory.GetFiles().Select(f => new LocalFile(f, Provider)).OrderBy(f => f.Name).ToList().AsReadOnly();
|
||||
_elements = Directory.GetFiles().Select(f => new LocalFile(f, this, Provider)).OrderBy(f => f.Name).ToList().AsReadOnly();
|
||||
}
|
||||
catch { }
|
||||
|
||||
@@ -115,6 +120,14 @@ namespace FileTime.Providers.Local
|
||||
Directory.Delete(true);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
public async Task Rename(string newName)
|
||||
{
|
||||
if (_parent is LocalFolder parentFolder)
|
||||
{
|
||||
System.IO.Directory.Move(Directory.FullName, Path.Combine(parentFolder.Directory.FullName, newName));
|
||||
await _parent.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public string GetAttributes()
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using AsyncEvent;
|
||||
using FileTime.Core.Interactions;
|
||||
using FileTime.Core.Models;
|
||||
@@ -11,7 +12,7 @@ namespace FileTime.Providers.Smb
|
||||
private readonly IInputInterface _inputInterface;
|
||||
private readonly List<IContainer> _rootContainers;
|
||||
private readonly IReadOnlyList<IContainer> _rootContainersReadOnly;
|
||||
private readonly IReadOnlyList<IItem>? _items;
|
||||
private IReadOnlyList<IItem>? _items;
|
||||
private readonly IReadOnlyList<IElement>? _elements = new List<IElement>().AsReadOnly();
|
||||
|
||||
public string Name { get; } = "smb";
|
||||
@@ -19,14 +20,18 @@ namespace FileTime.Providers.Smb
|
||||
public string? FullName { get; }
|
||||
|
||||
public bool IsHidden => false;
|
||||
public bool IsLoaded => true;
|
||||
|
||||
public IContentProvider Provider => this;
|
||||
public bool CanDelete => false;
|
||||
public bool CanRename => false;
|
||||
|
||||
public AsyncEventHandler Refreshed { get; } = new();
|
||||
|
||||
public SmbContentProvider(IInputInterface inputInterface)
|
||||
{
|
||||
_rootContainers = new List<IContainer>();
|
||||
_items = new List<IItem>();
|
||||
_rootContainersReadOnly = _rootContainers.AsReadOnly();
|
||||
_inputInterface = inputInterface;
|
||||
}
|
||||
@@ -40,6 +45,7 @@ namespace FileTime.Providers.Smb
|
||||
{
|
||||
container = new SmbServer(fullName, this, _inputInterface);
|
||||
_rootContainers.Add(container);
|
||||
_items = _rootContainers.OrderBy(c => c.Name).ToList().AsReadOnly();
|
||||
}
|
||||
|
||||
await Refresh();
|
||||
@@ -78,5 +84,7 @@ namespace FileTime.Providers.Smb
|
||||
public Task<IReadOnlyList<IItem>?> GetItems(CancellationToken token = default) => Task.FromResult(_items);
|
||||
public Task<IReadOnlyList<IContainer>?> GetContainers(CancellationToken token = default) => Task.FromResult((IReadOnlyList<IContainer>?)_rootContainersReadOnly);
|
||||
public Task<IReadOnlyList<IElement>?> GetElements(CancellationToken token = default) => Task.FromResult(_elements);
|
||||
|
||||
public Task Rename(string newName) => throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,11 @@ namespace FileTime.Providers.Smb
|
||||
public string? FullName { get; }
|
||||
|
||||
public bool IsHidden => false;
|
||||
public bool CanDelete => true;
|
||||
public bool CanRename => true;
|
||||
|
||||
public IContentProvider Provider { get; }
|
||||
private IContainer _parent;
|
||||
|
||||
public SmbFile(string name, SmbContentProvider provider, IContainer parent)
|
||||
{
|
||||
@@ -22,16 +25,23 @@ namespace FileTime.Providers.Smb
|
||||
FullName = parent.FullName + Constants.SeparatorChar + Name;
|
||||
|
||||
Provider = provider;
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
public Task Delete()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public Task Rename(string newName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetPrimaryAttributeText()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public IContainer? GetParent() => _parent;
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,12 @@ namespace FileTime.Providers.Smb
|
||||
public string? FullName { get; }
|
||||
|
||||
public bool IsHidden => false;
|
||||
public bool IsLoaded => _items != null;
|
||||
|
||||
public SmbContentProvider Provider { get; }
|
||||
IContentProvider IItem.Provider => Provider;
|
||||
public bool CanDelete => true;
|
||||
public bool CanRename => true;
|
||||
|
||||
public AsyncEventHandler Refreshed { get; } = new();
|
||||
|
||||
@@ -77,6 +80,10 @@ namespace FileTime.Providers.Smb
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public Task Rename(string newName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task Refresh()
|
||||
{
|
||||
|
||||
@@ -24,10 +24,13 @@ namespace FileTime.Providers.Smb
|
||||
public string? FullName { get; }
|
||||
|
||||
public bool IsHidden => false;
|
||||
public bool IsLoaded => _items != null;
|
||||
|
||||
public SmbContentProvider Provider { get; }
|
||||
|
||||
IContentProvider IItem.Provider => Provider;
|
||||
public bool CanDelete => false;
|
||||
public bool CanRename => false;
|
||||
|
||||
public AsyncEventHandler Refreshed { get; } = new();
|
||||
|
||||
@@ -128,5 +131,7 @@ namespace FileTime.Providers.Smb
|
||||
}
|
||||
return _client;
|
||||
}
|
||||
|
||||
public Task Rename(string newName) => throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using AsyncEvent;
|
||||
using FileTime.Core.Interactions;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Providers;
|
||||
using SMBLibrary;
|
||||
@@ -20,9 +19,12 @@ namespace FileTime.Providers.Smb
|
||||
public string? FullName { get; }
|
||||
|
||||
public bool IsHidden => false;
|
||||
public bool IsLoaded => _items != null;
|
||||
|
||||
public SmbContentProvider Provider { get; }
|
||||
IContentProvider IItem.Provider => Provider;
|
||||
public bool CanDelete => false;
|
||||
public bool CanRename => false;
|
||||
|
||||
public AsyncEventHandler Refreshed { get; } = new();
|
||||
|
||||
@@ -150,5 +152,7 @@ namespace FileTime.Providers.Smb
|
||||
|
||||
return (containers, elements);
|
||||
}
|
||||
|
||||
public Task Rename(string newName) => throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user