Compression, fixes

This commit is contained in:
2022-02-17 14:40:38 +01:00
parent f110a8442b
commit ef5c3a9caf
22 changed files with 332 additions and 47 deletions

View File

@@ -1,4 +1,5 @@
using AsyncEvent;
using FileTime.Core.Interactions;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
@@ -14,7 +15,7 @@ namespace FileTime.Core.Command
public IList<AbsolutePath> Sources { get; } = new List<AbsolutePath>();
public IContainer? Target { get; set; }
public AbsolutePath? Target { get; set; }
public TransportMode? TransportMode { get; set; } = Command.TransportMode.Merge;
@@ -25,6 +26,9 @@ namespace FileTime.Core.Command
public string DisplayLabel { get; } = "Copy";
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
public bool TargetIsContainer => true;
public List<InputElement> Inputs { get; } = new();
public List<object>? InputResults { get; set; }
private async Task UpdateProgress()
{
@@ -85,7 +89,8 @@ namespace FileTime.Core.Command
return (IContainer)(await newContainerDiff.AbsolutePath.ResolveAsync())!;
};
await TraverseTree(Sources, Target, TransportMode.Value);
var resolvedTarget = (IContainer)(await Target.ResolveAsync())!;
await TraverseTree(Sources, resolvedTarget, TransportMode.Value);
return startPoint.WithDifferences(newDiffs);
}
@@ -122,7 +127,8 @@ namespace FileTime.Core.Command
}
};
await TraverseTree(Sources, Target, TransportMode.Value);
var resolvedTarget = (IContainer)(await Target.ResolveAsync())!;
await TraverseTree(Sources, resolvedTarget, TransportMode.Value);
}
private async Task CalculateProgress()
@@ -150,7 +156,8 @@ namespace FileTime.Core.Command
}
};
await TraverseTree(Sources, Target, TransportMode.Value);
var resolvedTarget = (IContainer)(await Target.ResolveAsync())!;
await TraverseTree(Sources, resolvedTarget, TransportMode.Value);
_operationStatuses = operationStatuses;
}
@@ -198,7 +205,7 @@ namespace FileTime.Core.Command
var targetFolderPath = new AbsolutePath(target);
var targetElementPath = AbsolutePath.FromParentAndChildName(target, targetName, AbsolutePathType.Element);
foreach(var asd in _operationStatuses.Keys)
foreach (var asd in _operationStatuses.Keys)
{
var hash1 = asd.GetHashCode();
var hash2 = targetFolderPath.GetHashCode();

View File

@@ -1,3 +1,4 @@
using FileTime.Core.Interactions;
using FileTime.Core.Models;
namespace FileTime.Core.Command
@@ -5,7 +6,10 @@ namespace FileTime.Core.Command
public interface ITransportationCommand : ICommand
{
IList<AbsolutePath> Sources { get; }
IContainer? Target { get; set;}
AbsolutePath? Target { get; set; }
TransportMode? TransportMode { get; set; }
bool TargetIsContainer { get; }
List<InputElement> Inputs { get; }
List<object>? InputResults { get; set; }
}
}

View File

@@ -1,4 +1,5 @@
using AsyncEvent;
using FileTime.Core.Interactions;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
@@ -8,7 +9,7 @@ namespace FileTime.Core.Command
{
public IList<AbsolutePath> Sources { get; } = new List<AbsolutePath>();
public IContainer? Target { get; set; }
public AbsolutePath? Target { get; set; }
public TransportMode? TransportMode { get; set; } = Command.TransportMode.Merge;
public int Progress => 100;
@@ -16,6 +17,10 @@ namespace FileTime.Core.Command
public AsyncEventHandler ProgressChanged { get; } = new();
public string DisplayLabel { get; } = "MoveCommand";
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
public bool TargetIsContainer => true;
public List<InputElement> Inputs { get; } = new();
public List<object>? InputResults { get; set; }
public Task<CanCommandRun> CanRun(PointInTime startPoint)
{

View File

@@ -1,5 +1,6 @@
using AsyncEvent;
using FileTime.Core.Extensions;
using FileTime.Core.Interactions;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
@@ -28,7 +29,7 @@ namespace FileTime.Core.Command
if (itemToRename != null)
{
await itemToRename.Rename(Target);
if(timeRunner.RefreshContainer != null) await timeRunner.RefreshContainer.InvokeAsync(this, new AbsolutePath(itemToRename.GetParent()!));
if (timeRunner.RefreshContainer != null) await timeRunner.RefreshContainer.InvokeAsync(this, new AbsolutePath(itemToRename.GetParent()!));
}
}

View File

@@ -10,7 +10,7 @@ namespace FileTime.Core.CommandHandlers
{
if (command is not CopyCommand copyCommand) return false;
return (copyCommand.Target?.Provider.SupportsContentStreams ?? false)
return (copyCommand.Target?.ContentProvider.SupportsContentStreams ?? false)
&& copyCommand.Sources.All(p => p.ContentProvider.SupportsContentStreams);
}

View File

@@ -31,9 +31,9 @@ namespace FileTime.Core.Interactions
return new InputElement(label, InputType.Password, defaultValue);
}
public static InputElement ForOptions(string label, List<object> defaultValue)
public static InputElement ForOptions(string label, IEnumerable<object> defaultValue)
{
return new InputElement(label, InputType.Options, defaultValue);
return new InputElement(label, InputType.Options, new List<object>(defaultValue));
}
}
}

View File

@@ -1,16 +1,14 @@
using System.Threading.Tasks;
namespace FileTime.Core.Providers
{
public class ContentProviderStream : Stream
{
private readonly IContentReader? _contentReader;
private readonly IContentWriter? _contentWriter;
public override bool CanRead => _contentReader == null;
public override bool CanRead => _contentReader != null;
public override bool CanSeek => false;
public override bool CanSeek => _contentReader != null;
public override bool CanWrite => _contentWriter == null;
public override bool CanWrite => _contentWriter != null;
public override long Length => throw new NotImplementedException();
@@ -28,7 +26,8 @@ namespace FileTime.Core.Providers
public override void Flush()
{
throw new NotImplementedException();
if (_contentWriter == null) throw new NotSupportedException();
Task.Run(async () => await _contentWriter.FlushAsync()).Wait();
}
public override int Read(byte[] buffer, int offset, int count)
@@ -45,7 +44,16 @@ namespace FileTime.Core.Providers
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotImplementedException();
if (_contentReader == null) throw new NotSupportedException();
var newPosition = origin switch
{
SeekOrigin.Begin => offset,
SeekOrigin.Current => _contentReader.Position ?? 0 + offset,
_ => throw new NotSupportedException()
};
_contentReader.SetPosition(newPosition);
return newPosition;
}
public override void SetLength(long value)
@@ -55,7 +63,14 @@ namespace FileTime.Core.Providers
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
if (_contentWriter == null) throw new NotSupportedException();
var data = buffer;
if (buffer.Length != count)
{
data = new byte[count];
Array.Copy(buffer, data, count);
}
Task.Run(async () => await _contentWriter.WriteBytesAsync(data, offset)).Wait();
}
}
}

View File

@@ -3,7 +3,9 @@ namespace FileTime.Core.Providers
public interface IContentReader : IDisposable
{
int PreferredBufferSize { get; }
long? Position { get; }
Task<byte[]> ReadBytesAsync(int bufferSize, int? offset = null);
void SetPosition(long position);
}
}

View File

@@ -4,7 +4,7 @@ namespace FileTime.Core.Providers
{
int PreferredBufferSize { get; }
Task WriteBytesAsync(byte[] data);
Task WriteBytesAsync(byte[] data, int? index = null);
Task FlushAsync();
}
}

View File

@@ -151,11 +151,11 @@ namespace FileTime.Core.Timeline
}
finally
{
Task.Run(async () => await DisposeCommandThread(Thread.CurrentThread, commandToRun)).Wait();
Task.Run(async () => await DisposeCommandThread(commandToRun)).Wait();
}
}
private async Task DisposeCommandThread(Thread thread, CommandTimeState? command)
private async Task DisposeCommandThread(CommandTimeState? command)
{
await RunWithLockAsync(async () =>
{
@@ -170,7 +170,7 @@ namespace FileTime.Core.Timeline
}
}
var currentCommandRunner = _commandRunners.Find(r => r.Thread == thread);
var currentCommandRunner = _commandRunners.Find(r => r.Command == command);
if (currentCommandRunner != null) _commandRunners.Remove(currentCommandRunner);
await UpdateReadOnlyCommands();
StartCommandRunner();