TimeTravel

This commit is contained in:
2022-01-31 23:13:39 +01:00
parent 80570d8895
commit c2dcb49016
78 changed files with 2294 additions and 363 deletions

View File

@@ -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

View File

@@ -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();
}
}

View File

@@ -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;
}
}

View File

@@ -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()
{