mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
61 lines
1.5 KiB
C#
61 lines
1.5 KiB
C#
using System.IO;
|
|
|
|
namespace Wabbajack.Common
|
|
{
|
|
public class StatusFileStream : Stream
|
|
{
|
|
private string _message;
|
|
private FileStream _inner;
|
|
|
|
public StatusFileStream(FileStream fs, string message)
|
|
{
|
|
_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()
|
|
{
|
|
if (_inner.Length != 0)
|
|
Utils.Status(_message, (int) (_inner.Position * 100 / _inner.Length));
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|