2021-09-27 12:42:46 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2022-10-24 04:56:57 +00:00
|
|
|
|
using Wabbajack.Common;
|
2021-09-27 12:42:46 +00:00
|
|
|
|
using Wabbajack.DTOs.Streams;
|
2022-10-24 04:56:57 +00:00
|
|
|
|
using Wabbajack.Hashing.xxHash64;
|
2021-09-27 12:42:46 +00:00
|
|
|
|
using Wabbajack.Paths;
|
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
|
namespace Wabbajack.FileExtractor.ExtractedFiles;
|
|
|
|
|
|
|
|
|
|
public interface IExtractedFile : IStreamFactory
|
2021-09-27 12:42:46 +00:00
|
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
|
public bool CanMove { get; set; }
|
2021-09-27 12:42:46 +00:00
|
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
|
/// <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, CancellationToken token);
|
2022-10-24 04:56:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class IExtractedFileExtensions
|
|
|
|
|
{
|
|
|
|
|
public static async Task<Hash> MoveHashedAsync(this IExtractedFile file, AbsolutePath destPath, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (file.CanMove)
|
|
|
|
|
{
|
|
|
|
|
await file.Move(destPath, token);
|
|
|
|
|
return await destPath.Hash(token);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await using var s = await file.GetStream();
|
|
|
|
|
return await destPath.WriteAllHashedAsync(s, token, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
}
|