mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2024-12-27 11:03:04 +00:00
Fixed CA1835
This commit is contained in:
parent
18cdae513d
commit
22e00bf42a
2 changed files with 9 additions and 6 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue