From ac716fb3b8be66c165444e54225a2c3335c77395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Arrouye?= <5017270+tarrouye@users.noreply.github.com> Date: Sun, 4 Jun 2023 17:32:11 -0700 Subject: [PATCH] Adjust migration logic Handles clean-up for an edge-case scenario that for some reason the user launches the old version of Ryujinx again and it creates the default legacy files. --- src/Ryujinx.Ui.Common/App/ApplicationLibrary.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Ryujinx.Ui.Common/App/ApplicationLibrary.cs b/src/Ryujinx.Ui.Common/App/ApplicationLibrary.cs index 27369dd08..2f473eac5 100644 --- a/src/Ryujinx.Ui.Common/App/ApplicationLibrary.cs +++ b/src/Ryujinx.Ui.Common/App/ApplicationLibrary.cs @@ -521,12 +521,20 @@ namespace Ryujinx.Ui.App.Common // Handle migration from old default to current user string legacyFile = Path.Combine(guiFolder, "metadata.json"); - if (File.Exists(legacyFile) && !File.Exists(metadataFile)) + if (File.Exists(legacyFile)) { - File.Move(legacyFile, metadataFile); - File.Delete(legacyFile); + if (!File.Exists(metadataFile)) + { + File.Move(legacyFile, metadataFile); + } + + if (File.Exists(metadataFile)) + { + File.Delete(legacyFile); + } } + // Create metadata file if it doesn't exist yet ApplicationMetadata appMetadata; if (!File.Exists(metadataFile)) @@ -536,6 +544,7 @@ namespace Ryujinx.Ui.App.Common JsonHelper.SerializeToFile(metadataFile, appMetadata, SerializerContext.ApplicationMetadata); } + // Read from the metadata file try { appMetadata = JsonHelper.DeserializeFromFile(metadataFile, SerializerContext.ApplicationMetadata); @@ -547,6 +556,7 @@ namespace Ryujinx.Ui.App.Common appMetadata = new ApplicationMetadata(); } + // Modify the metadata and save it back to the file if (modifyFunction != null) { modifyFunction(appMetadata);