wabbajack/Wabbajack.VirtualFileSystem/ExtractedDiskFile.cs

54 lines
1.5 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Wabbajack.Common;
namespace Wabbajack.VirtualFileSystem
{
public class ExtractedDiskFile : IExtractedFile
{
2020-07-10 22:59:39 +00:00
protected AbsolutePath _path;
public ExtractedDiskFile(AbsolutePath path)
{
if (path == default)
throw new InvalidDataException("Path cannot be empty");
_path = path;
}
2020-07-10 22:59:39 +00:00
public virtual async Task<Hash> HashAsync()
{
return await _path.FileHashAsync();
}
public DateTime LastModifiedUtc => _path.LastModifiedUtc;
public long Size => _path.Size;
public async ValueTask<Stream> OpenRead()
{
return await _path.OpenRead();
}
public async Task<bool> CanExtract()
{
return await FileExtractor.CanExtract(_path);
}
2020-07-28 03:30:25 +00:00
public Task<ExtractedFiles> ExtractAll(WorkQueue queue, IEnumerable<RelativePath> onlyFiles, bool throwOnError)
{
2020-07-28 03:30:25 +00:00
return FileExtractor.ExtractAll(queue, _path, onlyFiles, throwOnError);
}
public async Task MoveTo(AbsolutePath path)
{
2020-04-27 04:49:54 +00:00
if (FileExtractor.MightBeArchive(_path.Extension))
{
path.Parent.CreateDirectory();
await _path.CopyToAsync(path);
return;
}
await _path.MoveToAsync(path, true);
_path = path;
}
}
}