Fix a lot of the analyzer warnings too

This commit is contained in:
Loporrit
2025-06-30 17:50:31 +00:00
parent dd42bf0913
commit aa377439ce
46 changed files with 160 additions and 210 deletions

View File

@@ -43,7 +43,7 @@ public class CountedStream : Stream
public async override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
int n = await _stream.ReadAsync(buffer, offset, count, cancellationToken);
int n = await _stream.ReadAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false);
BytesRead += n;
return n;
}
@@ -66,7 +66,7 @@ public class CountedStream : Stream
public async override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
await _stream.WriteAsync(buffer, offset, count, cancellationToken);
await _stream.WriteAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false);
BytesWritten += count;
}
}

View File

@@ -8,7 +8,7 @@ public class HashingStream : Stream
private readonly Stream _stream;
private readonly HashAlgorithm _hashAlgo;
private bool _finished = false;
public bool DisposeUnderlying = true;
public bool DisposeUnderlying { get; set; } = true;
public Stream UnderlyingStream { get => _stream; }
@@ -20,6 +20,7 @@ public class HashingStream : Stream
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!DisposeUnderlying)
return;
if (!_finished)
@@ -63,7 +64,6 @@ public class HashingStream : Stream
{
ObjectDisposedException.ThrowIf(_finished, this);
_stream.Write(buffer, offset, count);
string x = new(System.Text.Encoding.ASCII.GetChars(buffer.AsSpan().Slice(offset, count).ToArray()));
_hashAlgo.TransformBlock(buffer, offset, count, buffer, offset);
}
@@ -72,6 +72,7 @@ public class HashingStream : Stream
if (_finished)
return _hashAlgo.Hash!;
_hashAlgo.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
_finished = true;
if (DisposeUnderlying)
_stream.Dispose();
return _hashAlgo.Hash!;

View File

@@ -4,9 +4,9 @@ namespace MareSynchronos.Utils;
public class LimitedStream : Stream
{
private readonly Stream _stream;
public long _estimatedPosition = 0;
private long _estimatedPosition = 0;
public long MaxPosition { get; private init; }
public bool DisposeUnderlying = true;
public bool DisposeUnderlying { get; set; } = true;
public Stream UnderlyingStream { get => _stream; }
@@ -15,7 +15,7 @@ public class LimitedStream : Stream
_stream = underlyingStream;
try
{
_estimatedPosition = Position;
_estimatedPosition = _stream.Position;
}
catch { }
MaxPosition = _estimatedPosition + byteLimit;
@@ -23,6 +23,7 @@ public class LimitedStream : Stream
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!DisposeUnderlying)
return;
_stream.Dispose();
@@ -60,20 +61,20 @@ public class LimitedStream : Stream
count = remainder;
#pragma warning disable CA1835
int n = await _stream.ReadAsync(buffer, offset, count, cancellationToken);
int n = await _stream.ReadAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false);
#pragma warning restore CA1835
_estimatedPosition += n;
return n;
}
public async override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken)
public async override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
{
int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue);
if (buffer.Length > remainder)
buffer = buffer[..remainder];
int n = await _stream.ReadAsync(buffer, cancellationToken);
int n = await _stream.ReadAsync(buffer, cancellationToken).ConfigureAwait(false);
_estimatedPosition += n;
return n;
}
@@ -109,19 +110,19 @@ public class LimitedStream : Stream
count = remainder;
#pragma warning disable CA1835
await _stream.WriteAsync(buffer, offset, count, cancellationToken);
await _stream.WriteAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false);
#pragma warning restore CA1835
_estimatedPosition += count;
}
public async override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
public async override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
{
int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue);
if (buffer.Length > remainder)
buffer = buffer[..remainder];
await _stream.WriteAsync(buffer, cancellationToken);
await _stream.WriteAsync(buffer, cancellationToken).ConfigureAwait(false);
_estimatedPosition += buffer.Length;
}
}

View File

@@ -4,7 +4,7 @@ namespace MareSynchronos.Utils;
public class RollingList<T> : IEnumerable<T>
{
private readonly object _addLock = new();
private readonly Lock _addLock = new();
private readonly LinkedList<T> _list = new();
public RollingList(int maximumCount)

View File

@@ -97,7 +97,7 @@ public static class VariousExtensions
logger.LogDebug("[BASE-{appBase}] Updating {object}/{kind} (FileReplacements not equal) => {change}", applicationBase, cachedPlayer, objectKind, PlayerChanges.ModFiles);
charaDataToUpdate[objectKind].Add(PlayerChanges.ModFiles);
// XXX: This logic is disabled disabled because it seems to skip redrawing for something as basic as toggling a gear mod
/*
#if false
if (forceApplyMods || objectKind != ObjectKind.Player)
{
charaDataToUpdate[objectKind].Add(PlayerChanges.ForcedRedraw);
@@ -135,7 +135,7 @@ public static class VariousExtensions
charaDataToUpdate[objectKind].Add(PlayerChanges.ForcedRedraw);
}
}
*/
#endif
// XXX: Redraw on mod file changes always
charaDataToUpdate[objectKind].Add(PlayerChanges.ForcedRedraw);
}