Pacify updater (#1899)

* Updater: Remove dirs selectively

* Log exceptions from updater async tasks

* Address riperiperi's comments
This commit is contained in:
mageven 2021-02-23 20:49:02 +05:30 committed by GitHub
parent bcbf240d2e
commit fa55d7133a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 17 deletions

View file

@ -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,18 +406,16 @@ namespace Ryujinx.Modules
// Delete downloaded zip
File.Delete(updateFile);
string[] allFiles = Directory.GetFiles(HomeDir, "*", SearchOption.AllDirectories);
List<string> 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
{
@ -429,7 +431,6 @@ namespace Ryujinx.Modules
Logger.Warning?.Print(LogClass.Application, "Updater wasn't able to rename file: " + file);
}
}
}
Application.Invoke(delegate
{
@ -487,6 +488,26 @@ namespace Ryujinx.Modules
return true;
}
// NOTE: This method should always reflect the latest build layout.
private static IEnumerable<string> 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"))
{

View file

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

View file

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