mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Rework file extraction to combine the old and new methods
This commit is contained in:
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
|
||||
namespace Wabbajack.VirtualFileSystem.ExtractedFiles
|
||||
{
|
||||
public class ExtractedMemoryFile : IExtractedFile
|
||||
{
|
||||
private IStreamFactory _factory;
|
||||
|
||||
public ExtractedMemoryFile(IStreamFactory factory)
|
||||
{
|
||||
_factory = factory;
|
||||
}
|
||||
|
||||
|
||||
public ValueTask<Stream> GetStream()
|
||||
{
|
||||
return _factory.GetStream();
|
||||
}
|
||||
|
||||
public DateTime LastModifiedUtc => _factory.LastModifiedUtc;
|
||||
public IPath Name => _factory.Name;
|
||||
public async ValueTask Move(AbsolutePath newPath)
|
||||
{
|
||||
await using var stream = await _factory.GetStream();
|
||||
await newPath.WriteAllAsync(stream);
|
||||
}
|
||||
|
||||
public bool CanMove { get; set; } = true;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
|
||||
namespace Wabbajack.VirtualFileSystem.ExtractedFiles
|
||||
{
|
||||
public class ExtractedNativeFile : NativeFileStreamFactory, IExtractedFile
|
||||
{
|
||||
public bool CanMove { get; set; } = true;
|
||||
|
||||
public ExtractedNativeFile(AbsolutePath file, IPath path) : base(file, path)
|
||||
{
|
||||
}
|
||||
|
||||
public ExtractedNativeFile(AbsolutePath file) : base(file)
|
||||
{
|
||||
}
|
||||
|
||||
public async ValueTask Move(AbsolutePath newPath)
|
||||
{
|
||||
if (CanMove)
|
||||
await _file.MoveToAsync(newPath, overwrite: true);
|
||||
else
|
||||
await _file.CopyToAsync(newPath);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
|
||||
namespace Wabbajack.VirtualFileSystem.ExtractedFiles
|
||||
{
|
||||
public interface IExtractedFile : IStreamFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Possibly destructive move operation. Should greatly optimize file copies when the file
|
||||
/// exists on the same disk as the newPath. Performs a copy if a move is not possible.
|
||||
/// </summary>
|
||||
/// <param name="newPath">destination to move the entry to</param>
|
||||
/// <returns></returns>
|
||||
public ValueTask Move(AbsolutePath newPath);
|
||||
|
||||
public bool CanMove { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user