2020-09-05 14:01:32 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Common
|
|
|
|
|
{
|
|
|
|
|
public interface IStreamFactory
|
|
|
|
|
{
|
|
|
|
|
ValueTask<Stream> GetStream();
|
|
|
|
|
|
|
|
|
|
DateTime LastModifiedUtc { get; }
|
|
|
|
|
|
|
|
|
|
IPath Name { get; }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public class NativeFileStreamFactory : IStreamFactory
|
|
|
|
|
{
|
2020-10-10 03:02:58 +00:00
|
|
|
|
protected AbsolutePath _file;
|
2020-09-05 14:01:32 +00:00
|
|
|
|
|
2020-09-08 22:15:33 +00:00
|
|
|
|
public NativeFileStreamFactory(AbsolutePath file, IPath path)
|
|
|
|
|
{
|
|
|
|
|
_file = file;
|
|
|
|
|
Name = path;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-05 14:01:32 +00:00
|
|
|
|
public NativeFileStreamFactory(AbsolutePath file)
|
|
|
|
|
{
|
|
|
|
|
_file = file;
|
2020-09-08 22:15:33 +00:00
|
|
|
|
Name = file;
|
2020-09-05 14:01:32 +00:00
|
|
|
|
}
|
|
|
|
|
public async ValueTask<Stream> GetStream()
|
|
|
|
|
{
|
|
|
|
|
return await _file.OpenRead();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 05:26:08 +00:00
|
|
|
|
private DateTime? _lastModifiedCache = null;
|
|
|
|
|
public DateTime LastModifiedUtc
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
_lastModifiedCache ??= _file.LastModifiedUtc;
|
|
|
|
|
return _lastModifiedCache.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-08 22:15:33 +00:00
|
|
|
|
public IPath Name { get; }
|
2020-09-05 14:01:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|