2019-11-21 14:26:08 +00:00
|
|
|
|
using System.IO;
|
2019-11-20 00:15:46 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Common
|
|
|
|
|
{
|
|
|
|
|
public class StatusFileStream : Stream
|
|
|
|
|
{
|
|
|
|
|
private string _message;
|
2019-11-22 05:19:42 +00:00
|
|
|
|
private Stream _inner;
|
2020-01-18 22:09:32 +00:00
|
|
|
|
private WorkQueue _queue;
|
2019-11-20 00:15:46 +00:00
|
|
|
|
|
2020-01-18 22:09:32 +00:00
|
|
|
|
public StatusFileStream(Stream fs, string message, WorkQueue queue = null)
|
2019-11-20 00:15:46 +00:00
|
|
|
|
{
|
2020-01-18 22:09:32 +00:00
|
|
|
|
_queue = queue;
|
2019-11-20 00:15:46 +00:00
|
|
|
|
_inner = fs;
|
|
|
|
|
_message = message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Flush()
|
|
|
|
|
{
|
|
|
|
|
_inner.Flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override long Seek(long offset, SeekOrigin origin)
|
|
|
|
|
{
|
|
|
|
|
return _inner.Seek(offset, origin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetLength(long value)
|
|
|
|
|
{
|
|
|
|
|
_inner.SetLength(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Read(byte[] buffer, int offset, int count)
|
|
|
|
|
{
|
|
|
|
|
UpdateStatus();
|
|
|
|
|
return _inner.Read(buffer, offset, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateStatus()
|
|
|
|
|
{
|
2020-01-18 22:09:32 +00:00
|
|
|
|
if (_inner.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_queue != null)
|
2020-02-08 04:35:08 +00:00
|
|
|
|
_queue.Report(_message, Percent.FactoryPutInRange(_inner.Position, _inner.Length));
|
2020-01-18 22:09:32 +00:00
|
|
|
|
else
|
2020-02-08 04:35:08 +00:00
|
|
|
|
Utils.Status(_message, Percent.FactoryPutInRange(_inner.Position, _inner.Length));
|
2019-11-20 00:15:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Write(byte[] buffer, int offset, int count)
|
|
|
|
|
{
|
|
|
|
|
UpdateStatus();
|
|
|
|
|
_inner.Write(buffer, offset, count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool CanRead => _inner.CanRead;
|
|
|
|
|
public override bool CanSeek => _inner.CanSeek;
|
|
|
|
|
public override bool CanWrite => _inner.CanWrite;
|
|
|
|
|
public override long Length => _inner.Length;
|
|
|
|
|
|
|
|
|
|
public override long Position
|
|
|
|
|
{
|
|
|
|
|
get => _inner.Position;
|
|
|
|
|
set => _inner.Position = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|