diff --git a/Ryujinx/Modules/Updater/Updater.cs b/Ryujinx/Modules/Updater/Updater.cs index 9e18d6b3..b4fe3351 100644 --- a/Ryujinx/Modules/Updater/Updater.cs +++ b/Ryujinx/Modules/Updater/Updater.cs @@ -9,6 +9,7 @@ using Ryujinx.Ui.Widgets; using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Runtime.InteropServices; @@ -35,6 +36,9 @@ namespace Ryujinx.Modules private const string AppveyorApiUrl = "https://ci.appveyor.com/api"; + // On Windows, GtkSharp.Dependencies adds these extra dirs that must be cleaned during updates. + private static readonly string[] WindowsDependencyDirs = new string[] { "bin", "etc", "lib", "share" }; + public static async Task BeginParse(MainWindow mainWindow, bool showVersionUpToDate) { if (Running) return; @@ -402,32 +406,29 @@ namespace Ryujinx.Modules // Delete downloaded zip File.Delete(updateFile); - string[] allFiles = Directory.GetFiles(HomeDir, "*", SearchOption.AllDirectories); + List allFiles = EnumerateFilesToDelete().ToList(); updateDialog.MainText.Text = "Renaming Old Files..."; updateDialog.ProgressBar.Value = 0; - updateDialog.ProgressBar.MaxValue = allFiles.Length; + updateDialog.ProgressBar.MaxValue = allFiles.Count; // Replace old files await Task.Run(() => { foreach (string file in allFiles) { - if (!Path.GetExtension(file).Equals(".log")) + try { - try - { - File.Move(file, file + ".ryuold"); + File.Move(file, file + ".ryuold"); - Application.Invoke(delegate - { - updateDialog.ProgressBar.Value++; - }); - } - catch + Application.Invoke(delegate { - Logger.Warning?.Print(LogClass.Application, "Updater wasn't able to rename file: " + file); - } + updateDialog.ProgressBar.Value++; + }); + } + catch + { + Logger.Warning?.Print(LogClass.Application, "Updater wasn't able to rename file: " + file); } } @@ -487,6 +488,26 @@ namespace Ryujinx.Modules return true; } + // NOTE: This method should always reflect the latest build layout. + private static IEnumerable EnumerateFilesToDelete() + { + var files = Directory.EnumerateFiles(HomeDir); // All files directly in base dir. + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + foreach (string dir in WindowsDependencyDirs) + { + string dirPath = Path.Combine(HomeDir, dir); + if (Directory.Exists(dirPath)) + { + files = files.Concat(Directory.EnumerateFiles(dirPath, "*", SearchOption.AllDirectories)); + } + } + } + + return files; + } + private static void MoveAllFilesOver(string root, string dest, UpdateDialog dialog) { foreach (string directory in Directory.GetDirectories(root)) @@ -514,7 +535,7 @@ namespace Ryujinx.Modules public static void CleanupUpdate() { - foreach (string file in Directory.GetFiles(HomeDir, "*", SearchOption.AllDirectories)) + foreach (string file in EnumerateFilesToDelete()) { if (Path.GetExtension(file).EndsWith(".ryuold")) { diff --git a/Ryujinx/Program.cs b/Ryujinx/Program.cs index 5d50e9d2..24642b61 100644 --- a/Ryujinx/Program.cs +++ b/Ryujinx/Program.cs @@ -156,7 +156,10 @@ namespace Ryujinx if (ConfigurationState.Instance.CheckUpdatesOnStart.Value && Updater.CanUpdate(false)) { - _ = Updater.BeginParse(mainWindow, false); + Updater.BeginParse(mainWindow, false).ContinueWith(task => + { + Logger.Error?.Print(LogClass.Application, $"Updater Error: {task.Exception}"); + }, TaskContinuationOptions.OnlyOnFaulted); } Application.Run(); diff --git a/Ryujinx/Ui/MainWindow.cs b/Ryujinx/Ui/MainWindow.cs index 2118076a..828fe853 100644 --- a/Ryujinx/Ui/MainWindow.cs +++ b/Ryujinx/Ui/MainWindow.cs @@ -1131,7 +1131,10 @@ namespace Ryujinx.Ui { if (Updater.CanUpdate(true)) { - _ = Updater.BeginParse(this, true); + Updater.BeginParse(this, true).ContinueWith(task => + { + Logger.Error?.Print(LogClass.Application, $"Updater Error: {task.Exception}"); + }, TaskContinuationOptions.OnlyOnFaulted); } }