Code organization

This commit is contained in:
yell0wsuit 2024-04-17 20:19:19 +07:00
parent 44d6e8aa9c
commit c0c873243f
No known key found for this signature in database
GPG key ID: 5B4F198A9800F6F4
15 changed files with 7 additions and 25 deletions

View file

@ -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);
}
});
}

View file

@ -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);
});
}
}
}

View file

@ -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.

View file

@ -55,7 +55,7 @@ namespace Ryujinx.Modules
}
else
{
DoUpdateWithSingleThread(taskDialog, downloadUrl, updateFile);
await DoUpdateWithSingleThread(taskDialog, downloadUrl, updateFile);
}
};

View file

@ -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;