Fixed CA1835

This commit is contained in:
yell0wsuit 2024-04-17 16:38:16 +07:00
parent 18cdae513d
commit 22e00bf42a
No known key found for this signature in database
GPG key ID: 5B4F198A9800F6F4
2 changed files with 9 additions and 6 deletions

View file

@ -95,18 +95,20 @@ namespace Ryujinx.Modules
private static async Task<byte[]> DownloadFileChunk(string url, long start, long end, int index, TaskDialog taskDialog, int[] progressPercentage)
{
byte[] buffer = new byte[8192];
Memory<byte> buffer = new byte[8192];
using var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Range = new RangeHeaderValue(start, end);
HttpResponseMessage response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
using var stream = await response.Content.ReadAsStreamAsync();
using var memoryStream = new MemoryStream();
int bytesRead;
long totalRead = 0;
while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
while ((bytesRead = await stream.ReadAsync(buffer, CancellationToken.None)) > 0)
{
memoryStream.Write(buffer, 0, bytesRead);
memoryStream.Write(buffer.Slice(0, bytesRead).ToArray(), 0, bytesRead);
totalRead += bytesRead;
int progress = (int)((totalRead * 100) / (end - start + 1));
progressPercentage[index] = progress;

View file

@ -26,6 +26,7 @@ namespace Ryujinx.Modules
HttpResponseMessage response = await httpClient.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead);
if (!response.IsSuccessStatusCode)
{
Logger.Error?.Print(LogClass.Application, $"Failed to download file: {response.ReasonPhrase}");
throw new HttpRequestException($"Failed to download file: {response.ReasonPhrase}");
}
@ -36,12 +37,12 @@ namespace Ryujinx.Modules
using Stream remoteFileStream = await response.Content.ReadAsStreamAsync();
using Stream updateFileStream = File.Open(updateFile, FileMode.Create);
byte[] buffer = new byte[32 * 1024];
Memory<byte> buffer = new byte[32 * 1024];
int readSize;
while ((readSize = await remoteFileStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
while ((readSize = await remoteFileStream.ReadAsync(buffer, CancellationToken.None)) > 0)
{
updateFileStream.Write(buffer, 0, readSize);
updateFileStream.Write(buffer.Slice(0, readSize).ToArray(), 0, readSize);
byteWritten += readSize;
int progress = GetPercentage(byteWritten, totalBytes);