OK nevermind found a way to fix IDE0057

This commit is contained in:
yell0wsuit 2024-04-17 20:34:27 +07:00
parent c0c873243f
commit a29f167593
No known key found for this signature in database
GPG key ID: 5B4F198A9800F6F4
2 changed files with 11 additions and 7 deletions

View file

@ -105,20 +105,24 @@ namespace Ryujinx.Modules
using var memoryStream = new MemoryStream(); using var memoryStream = new MemoryStream();
int bytesRead; int bytesRead;
long totalRead = 0; long totalRead = 0;
int lastReportedProgress = -1;
while ((bytesRead = await stream.ReadAsync(buffer, CancellationToken.None)) > 0) while ((bytesRead = await stream.ReadAsync(buffer, CancellationToken.None)) > 0)
{ {
#pragma warning disable IDE0057 // Disable the warning for unnecessary slicing memoryStream.Write(buffer.Span[..bytesRead]);
memoryStream.Write(buffer.Slice(0, bytesRead).ToArray(), 0, bytesRead);
#pragma warning restore IDE0057
totalRead += bytesRead; totalRead += bytesRead;
int progress = (int)((totalRead * 100) / (end - start + 1)); int progress = (int)((totalRead * 100) / (end - start + 1));
progressPercentage[index] = progress; progressPercentage[index] = progress;
Dispatcher.UIThread.Post(() => // Throttle UI updates to only fire when there is a change in progress percentage
if (progress != lastReportedProgress)
{ {
taskDialog.SetProgressBarState(progressPercentage.Sum() / ConnectionCount, TaskDialogProgressState.Normal); lastReportedProgress = progress;
}); Dispatcher.UIThread.Post(() =>
{
taskDialog.SetProgressBarState(progressPercentage.Sum() / ConnectionCount, TaskDialogProgressState.Normal);
});
}
} }
return memoryStream.ToArray(); return memoryStream.ToArray();

View file

@ -42,7 +42,7 @@ namespace Ryujinx.Modules
while ((readSize = await remoteFileStream.ReadAsync(buffer, CancellationToken.None)) > 0) while ((readSize = await remoteFileStream.ReadAsync(buffer, CancellationToken.None)) > 0)
{ {
updateFileStream.Write(buffer.Span.Slice(0, readSize)); updateFileStream.Write(buffer.Span[..readSize]);
byteWritten += readSize; byteWritten += readSize;
Dispatcher.UIThread.Post(() => Dispatcher.UIThread.Post(() =>