diff --git a/src/Ryujinx/Modules/Updater/Utils/DoUpdateWithMultipleThreads.cs b/src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithMultipleThreads.cs similarity index 98% rename from src/Ryujinx/Modules/Updater/Utils/DoUpdateWithMultipleThreads.cs rename to src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithMultipleThreads.cs index 9df2f54d1..f75139aa0 100644 --- a/src/Ryujinx/Modules/Updater/Utils/DoUpdateWithMultipleThreads.cs +++ b/src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithMultipleThreads.cs @@ -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); } }); } diff --git a/src/Ryujinx/Modules/Updater/Utils/DoUpdateWithSingleThread.cs b/src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithSingleThread.cs similarity index 67% rename from src/Ryujinx/Modules/Updater/Utils/DoUpdateWithSingleThread.cs rename to src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithSingleThread.cs index 2deff25f9..5da83fff3 100644 --- a/src/Ryujinx/Modules/Updater/Utils/DoUpdateWithSingleThread.cs +++ b/src/Ryujinx/Modules/Updater/DownloadHelpers/DoUpdateWithSingleThread.cs @@ -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); - }); - } } } diff --git a/src/Ryujinx/Modules/Updater/Utils/CleanupUpdate.cs b/src/Ryujinx/Modules/Updater/FileOperations/CleanupUpdate.cs similarity index 100% rename from src/Ryujinx/Modules/Updater/Utils/CleanupUpdate.cs rename to src/Ryujinx/Modules/Updater/FileOperations/CleanupUpdate.cs diff --git a/src/Ryujinx/Modules/Updater/Utils/EnumerateFilesToDelete.cs b/src/Ryujinx/Modules/Updater/FileOperations/EnumerateFilesToDelete.cs similarity index 91% rename from src/Ryujinx/Modules/Updater/Utils/EnumerateFilesToDelete.cs rename to src/Ryujinx/Modules/Updater/FileOperations/EnumerateFilesToDelete.cs index 128b34b8a..c94245cca 100644 --- a/src/Ryujinx/Modules/Updater/Utils/EnumerateFilesToDelete.cs +++ b/src/Ryujinx/Modules/Updater/FileOperations/EnumerateFilesToDelete.cs @@ -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(); // NOTE: This method should always reflect the latest build layout. diff --git a/src/Ryujinx/Modules/Updater/Utils/ExtractTarGzipFile.cs b/src/Ryujinx/Modules/Updater/FileOperations/ExtractTarGzipFile.cs similarity index 100% rename from src/Ryujinx/Modules/Updater/Utils/ExtractTarGzipFile.cs rename to src/Ryujinx/Modules/Updater/FileOperations/ExtractTarGzipFile.cs diff --git a/src/Ryujinx/Modules/Updater/Utils/ExtractZipFile.cs b/src/Ryujinx/Modules/Updater/FileOperations/ExtractZipFile.cs similarity index 100% rename from src/Ryujinx/Modules/Updater/Utils/ExtractZipFile.cs rename to src/Ryujinx/Modules/Updater/FileOperations/ExtractZipFile.cs diff --git a/src/Ryujinx/Modules/Updater/Utils/MoveAllFilesOver.cs b/src/Ryujinx/Modules/Updater/FileOperations/MoveAllFilesOver.cs similarity index 100% rename from src/Ryujinx/Modules/Updater/Utils/MoveAllFilesOver.cs rename to src/Ryujinx/Modules/Updater/FileOperations/MoveAllFilesOver.cs diff --git a/src/Ryujinx/Modules/Updater/Utils/CanUpdate.cs b/src/Ryujinx/Modules/Updater/UpdateHelpers/CanUpdate.cs similarity index 100% rename from src/Ryujinx/Modules/Updater/Utils/CanUpdate.cs rename to src/Ryujinx/Modules/Updater/UpdateHelpers/CanUpdate.cs diff --git a/src/Ryujinx/Modules/Updater/Utils/FetchBuildSizeInfo.cs b/src/Ryujinx/Modules/Updater/UpdateHelpers/FetchBuildSizeInfo.cs similarity index 100% rename from src/Ryujinx/Modules/Updater/Utils/FetchBuildSizeInfo.cs rename to src/Ryujinx/Modules/Updater/UpdateHelpers/FetchBuildSizeInfo.cs diff --git a/src/Ryujinx/Modules/Updater/Utils/GetCurrentVersion.cs b/src/Ryujinx/Modules/Updater/UpdateHelpers/GetCurrentVersion.cs similarity index 100% rename from src/Ryujinx/Modules/Updater/Utils/GetCurrentVersion.cs rename to src/Ryujinx/Modules/Updater/UpdateHelpers/GetCurrentVersion.cs diff --git a/src/Ryujinx/Modules/Updater/Utils/HandleVersionComparison.cs b/src/Ryujinx/Modules/Updater/UpdateHelpers/HandleVersionComparison.cs similarity index 100% rename from src/Ryujinx/Modules/Updater/Utils/HandleVersionComparison.cs rename to src/Ryujinx/Modules/Updater/UpdateHelpers/HandleVersionComparison.cs diff --git a/src/Ryujinx/Modules/Updater/Utils/ShowUpdateDialogAndExecute.cs b/src/Ryujinx/Modules/Updater/UpdateHelpers/ShowUpdateDialogAndExecute.cs similarity index 100% rename from src/Ryujinx/Modules/Updater/Utils/ShowUpdateDialogAndExecute.cs rename to src/Ryujinx/Modules/Updater/UpdateHelpers/ShowUpdateDialogAndExecute.cs diff --git a/src/Ryujinx/Modules/Updater/Utils/TryUpdateVersionInfo.cs b/src/Ryujinx/Modules/Updater/UpdateHelpers/TryUpdateVersionInfo.cs similarity index 100% rename from src/Ryujinx/Modules/Updater/Utils/TryUpdateVersionInfo.cs rename to src/Ryujinx/Modules/Updater/UpdateHelpers/TryUpdateVersionInfo.cs diff --git a/src/Ryujinx/Modules/Updater/Utils/UpdateRyujinx.cs b/src/Ryujinx/Modules/Updater/UpdateHelpers/UpdateRyujinx.cs similarity index 96% rename from src/Ryujinx/Modules/Updater/Utils/UpdateRyujinx.cs rename to src/Ryujinx/Modules/Updater/UpdateHelpers/UpdateRyujinx.cs index d112ea461..b69e3aa9c 100644 --- a/src/Ryujinx/Modules/Updater/Utils/UpdateRyujinx.cs +++ b/src/Ryujinx/Modules/Updater/UpdateHelpers/UpdateRyujinx.cs @@ -55,7 +55,7 @@ namespace Ryujinx.Modules } else { - DoUpdateWithSingleThread(taskDialog, downloadUrl, updateFile); + await DoUpdateWithSingleThread(taskDialog, downloadUrl, updateFile); } }; diff --git a/src/Ryujinx/Modules/Updater/Updater.cs b/src/Ryujinx/Modules/Updater/Updater.cs index b33511e4e..cbe6e0aba 100644 --- a/src/Ryujinx/Modules/Updater/Updater.cs +++ b/src/Ryujinx/Modules/Updater/Updater.cs @@ -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;