From 5813b2e354e072d43eb30c51083e737cf6bc1ee2 Mon Sep 17 00:00:00 2001 From: Kurochi51 Date: Mon, 5 Jun 2023 15:19:17 +0300 Subject: [PATCH] Updater: Ignore files introduced by the user in base directory (#5092) * Updater: Ignore files introduced by the user in base directory * Replicate logic in Avalonia version. * Address requested changes * Updater: Ignore files introduced by the user in base directory * Replicate logic in Avalonia version. * Address requested changes * Address requested changes * Address requested changes * Comment cleanup * Address feedback * Forgot comment, tehe --- src/Ryujinx.Ava/Modules/Updater/Updater.cs | 12 ++++++++++++ src/Ryujinx/Modules/Updater/Updater.cs | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Ryujinx.Ava/Modules/Updater/Updater.cs b/src/Ryujinx.Ava/Modules/Updater/Updater.cs index 77d77d7945..839526c4e2 100644 --- a/src/Ryujinx.Ava/Modules/Updater/Updater.cs +++ b/src/Ryujinx.Ava/Modules/Updater/Updater.cs @@ -740,6 +740,18 @@ namespace Ryujinx.Modules { var files = Directory.EnumerateFiles(HomeDir); // All files directly in base dir. + // Determine and exclude user files only when the updater is running, not when cleaning old files + if (_running) + { + // Compare the loose files in base directory against the loose files from the incoming update, and store foreign ones in a user list. + var oldFiles = Directory.EnumerateFiles(HomeDir, "*", SearchOption.TopDirectoryOnly).Select(Path.GetFileName); + var newFiles = Directory.EnumerateFiles(UpdatePublishDir, "*", SearchOption.TopDirectoryOnly).Select(Path.GetFileName); + var userFiles = oldFiles.Except(newFiles).Select(filename => Path.Combine(HomeDir, filename)); + + // Remove user files from the paths in files. + files = files.Except(userFiles); + } + if (OperatingSystem.IsWindows()) { foreach (string dir in WindowsDependencyDirs) diff --git a/src/Ryujinx/Modules/Updater/Updater.cs b/src/Ryujinx/Modules/Updater/Updater.cs index 3e0dc99b4f..344edf9e52 100644 --- a/src/Ryujinx/Modules/Updater/Updater.cs +++ b/src/Ryujinx/Modules/Updater/Updater.cs @@ -565,6 +565,18 @@ namespace Ryujinx.Modules { var files = Directory.EnumerateFiles(HomeDir); // All files directly in base dir. + // Determine and exclude user files only when the updater is running, not when cleaning old files + if (Running) + { + // Compare the loose files in base directory against the loose files from the incoming update, and store foreign ones in a user list. + var oldFiles = Directory.EnumerateFiles(HomeDir, "*", SearchOption.TopDirectoryOnly).Select(Path.GetFileName); + var newFiles = Directory.EnumerateFiles(UpdatePublishDir, "*", SearchOption.TopDirectoryOnly).Select(Path.GetFileName); + var userFiles = oldFiles.Except(newFiles).Select(filename => Path.Combine(HomeDir, filename)); + + // Remove user files from the paths in files. + files = files.Except(userFiles); + } + if (OperatingSystem.IsWindows()) { foreach (string dir in WindowsDependencyDirs)