Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor & modularize code in Updater.cs #6670

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

yell0wsuit
Copy link
Contributor

@yell0wsuit yell0wsuit commented Apr 17, 2024

  • Change WebClient to HttpClient
  • Use async and await instead of Result
  • Refactor & modularize code to make it more manageable

Please test by updating the app when prompted to make sure there's no regression. I only tested on Windows, but you can test again to make sure.

Also please check if I do something wrong or miss something 🙏🙏.

Cache httpClient and remove ConstructHttpClient()
Replace `WebClient` with `HttpClient`, plus updating DoUpdateWithSingleThreadWorker and DoUpdateWithMultipleThreads
This is just for testing the update functionality!
@github-actions github-actions bot added the gui Related to Ryujinx.Ui label Apr 17, 2024
Since Memory<byte> is initialized with a fixed size, `.Slice(0, readSize)` and `.Slice(0, bytesRead)` are necessary to ensure that only the part of the buffer that contains data is written to the file stream. So IDE0057 is not appropriate in this context.
@yell0wsuit yell0wsuit marked this pull request as ready for review April 18, 2024 06:23
@ryujinx-mako ryujinx-mako bot requested review from AcK77, emmauss, TSRBerry and a team April 18, 2024 06:24
Copy link
Member

@AcK77 AcK77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick review on code side. I think you should reduce the amount of sub-files because a lot of them only contains one method, you should store everything in classes instead.

Comment on lines +24 to +25
private static long _buildSize;
private const int ConnectionCount = 4;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static long _buildSize;
private const int ConnectionCount = 4;
private const int ConnectionCount = 4;
private static long _buildSize;

int completedRequests = 0;
int[] progressPercentage = new int[ConnectionCount];
List<byte[]> chunkDataList = new List<byte[]>(new byte[ConnectionCount][]);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Buffer.BlockCopy(chunk, 0, data, (int)position, chunk.Length);
position += chunk.Length;
}
return data;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return data;
return data;

{
internal static partial class Updater
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

await ContentDialogHelper.CreateWarningDialog(
LocaleManager.Instance[LocaleKeys.DialogUpdaterConvertFailedMessage],
LocaleManager.Instance[LocaleKeys.DialogUpdaterCancelUpdateMessage]);
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return null;
return null;

LocaleManager.Instance[LocaleKeys.DialogUpdaterConvertFailedGithubMessage],
LocaleManager.Instance[LocaleKeys.DialogUpdaterCancelUpdateMessage]);
_running = false;
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return false;
return false;

if (asset.Name.StartsWith("ryujinx") && asset.Name.EndsWith(_platformExt) && asset.State == "uploaded")
{
_buildUrl = asset.BrowserDownloadUrl;
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return true;
return true;

}

_running = false;
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return false;
return false;

await ContentDialogHelper.CreateErrorDialog(
LocaleManager.Instance[LocaleKeys.DialogUpdaterFailedToGetVersionMessage]);
_running = false;
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return false;
return false;

{
request.Headers.Range = range;
}
return await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
return await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gui Related to Ryujinx.Ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants