2021-09-27 12:42:46 +00:00
|
|
|
using System;
|
2020-09-05 14:01:32 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Threading.Tasks;
|
2021-09-27 12:42:46 +00:00
|
|
|
using Wabbajack.DTOs.Streams;
|
|
|
|
using Wabbajack.Paths;
|
|
|
|
using Wabbajack.Paths.IO;
|
2020-09-05 14:01:32 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
namespace Wabbajack.Common;
|
|
|
|
|
|
|
|
public class NativeFileStreamFactory : IStreamFactory
|
2020-09-05 14:01:32 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
protected AbsolutePath _file;
|
2020-09-05 14:01:32 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
private DateTime? _lastModifiedCache;
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public NativeFileStreamFactory(AbsolutePath file, IPath path)
|
|
|
|
{
|
|
|
|
_file = file;
|
|
|
|
Name = path;
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public NativeFileStreamFactory(AbsolutePath file)
|
|
|
|
{
|
|
|
|
_file = file;
|
|
|
|
Name = file;
|
|
|
|
}
|
2021-09-27 12:42:46 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public ValueTask<Stream> GetStream()
|
|
|
|
{
|
|
|
|
return new ValueTask<Stream>(_file.Open(FileMode.Open, FileAccess.Read, FileShare.Read));
|
|
|
|
}
|
2020-09-05 14:01:32 +00:00
|
|
|
|
2021-10-23 16:51:17 +00:00
|
|
|
public DateTime LastModifiedUtc
|
|
|
|
{
|
|
|
|
get
|
2021-07-06 05:26:08 +00:00
|
|
|
{
|
2021-10-23 16:51:17 +00:00
|
|
|
_lastModifiedCache ??= _file.LastModifiedUtc();
|
|
|
|
return _lastModifiedCache.Value;
|
2021-07-06 05:26:08 +00:00
|
|
|
}
|
2020-09-05 14:01:32 +00:00
|
|
|
}
|
2021-10-23 16:51:17 +00:00
|
|
|
|
|
|
|
public IPath Name { get; }
|
2022-07-11 20:55:54 +00:00
|
|
|
|
|
|
|
public AbsolutePath FullPath => (AbsolutePath) Name;
|
2021-09-27 12:42:46 +00:00
|
|
|
}
|