mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2024-12-27 11:03:04 +00:00
Code organization
This commit is contained in:
parent
44d6e8aa9c
commit
c0c873243f
15 changed files with 7 additions and 25 deletions
|
@ -71,7 +71,7 @@ namespace Ryujinx.Modules
|
|||
{
|
||||
Logger.Warning?.Print(LogClass.Application, e.Message);
|
||||
Logger.Warning?.Print(LogClass.Application, "Multi-Threaded update failed, falling back to single-threaded updater.");
|
||||
DoUpdateWithSingleThread(taskDialog, downloadUrl, updateFile);
|
||||
await DoUpdateWithSingleThread(taskDialog, downloadUrl, updateFile);
|
||||
}
|
||||
});
|
||||
}
|
|
@ -18,7 +18,7 @@ namespace Ryujinx.Modules
|
|||
{
|
||||
internal static partial class Updater
|
||||
{
|
||||
private static async Task DoUpdateWithSingleThreadWorker(TaskDialog taskDialog, string downloadUrl, string updateFile)
|
||||
private static async Task DoUpdateWithSingleThread(TaskDialog taskDialog, string downloadUrl, string updateFile)
|
||||
{
|
||||
// We do not want to timeout while downloading
|
||||
_httpClient.Timeout = TimeSpan.FromDays(1);
|
||||
|
@ -42,40 +42,22 @@ namespace Ryujinx.Modules
|
|||
|
||||
while ((readSize = await remoteFileStream.ReadAsync(buffer, CancellationToken.None)) > 0)
|
||||
{
|
||||
#pragma warning disable IDE0057 // Disable the warning for unnecessary slicing
|
||||
updateFileStream.Write(buffer.Slice(0, readSize).ToArray(), 0, readSize);
|
||||
#pragma warning restore IDE0057
|
||||
updateFileStream.Write(buffer.Span.Slice(0, readSize));
|
||||
byteWritten += readSize;
|
||||
|
||||
int progress = GetPercentage(byteWritten, totalBytes);
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
taskDialog.SetProgressBarState(progress, TaskDialogProgressState.Normal);
|
||||
taskDialog.SetProgressBarState(GetPercentage(byteWritten, totalBytes), TaskDialogProgressState.Normal);
|
||||
});
|
||||
}
|
||||
|
||||
await InstallUpdate(taskDialog, updateFile);
|
||||
}
|
||||
|
||||
private static int GetPercentage(long value, long total)
|
||||
{
|
||||
if (total == 0)
|
||||
return 0;
|
||||
return (int)((value * 100) / total);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static double GetPercentage(double value, double max)
|
||||
{
|
||||
return max == 0 ? 0 : value / max * 100;
|
||||
}
|
||||
|
||||
private static void DoUpdateWithSingleThread(TaskDialog taskDialog, string downloadUrl, string updateFile)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await DoUpdateWithSingleThreadWorker(taskDialog, downloadUrl, updateFile);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,8 +8,6 @@ namespace Ryujinx.Modules
|
|||
{
|
||||
internal static partial class Updater
|
||||
{
|
||||
private static readonly string _homeDir = AppDomain.CurrentDomain.BaseDirectory;
|
||||
private static readonly string _updatePublishDir = Path.Combine(_updateDir, "publish");
|
||||
private static readonly string[] _windowsDependencyDirs = Array.Empty<string>();
|
||||
|
||||
// NOTE: This method should always reflect the latest build layout.
|
|
@ -55,7 +55,7 @@ namespace Ryujinx.Modules
|
|||
}
|
||||
else
|
||||
{
|
||||
DoUpdateWithSingleThread(taskDialog, downloadUrl, updateFile);
|
||||
await DoUpdateWithSingleThread(taskDialog, downloadUrl, updateFile);
|
||||
}
|
||||
};
|
||||
|
|
@ -21,7 +21,9 @@ namespace Ryujinx.Modules
|
|||
}
|
||||
};
|
||||
|
||||
private static readonly string _homeDir = AppDomain.CurrentDomain.BaseDirectory;
|
||||
private static readonly string _updateDir = Path.Combine(Path.GetTempPath(), "Ryujinx", "update");
|
||||
private static readonly string _updatePublishDir = Path.Combine(_updateDir, "publish");
|
||||
|
||||
private static bool _running;
|
||||
|
||||
|
|
Loading…
Reference in a new issue