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.
This commit is contained in:
Théo Arrouye 2023-06-04 17:32:11 -07:00
parent 8eb68aa2aa
commit ac716fb3b8

View file

@ -521,12 +521,20 @@ namespace Ryujinx.Ui.App.Common
// Handle migration from old default to current user // Handle migration from old default to current user
string legacyFile = Path.Combine(guiFolder, "metadata.json"); string legacyFile = Path.Combine(guiFolder, "metadata.json");
if (File.Exists(legacyFile) && !File.Exists(metadataFile)) if (File.Exists(legacyFile))
{ {
File.Move(legacyFile, metadataFile); if (!File.Exists(metadataFile))
File.Delete(legacyFile); {
File.Move(legacyFile, metadataFile);
}
if (File.Exists(metadataFile))
{
File.Delete(legacyFile);
}
} }
// Create metadata file if it doesn't exist yet
ApplicationMetadata appMetadata; ApplicationMetadata appMetadata;
if (!File.Exists(metadataFile)) if (!File.Exists(metadataFile))
@ -536,6 +544,7 @@ namespace Ryujinx.Ui.App.Common
JsonHelper.SerializeToFile(metadataFile, appMetadata, SerializerContext.ApplicationMetadata); JsonHelper.SerializeToFile(metadataFile, appMetadata, SerializerContext.ApplicationMetadata);
} }
// Read from the metadata file
try try
{ {
appMetadata = JsonHelper.DeserializeFromFile(metadataFile, SerializerContext.ApplicationMetadata); appMetadata = JsonHelper.DeserializeFromFile(metadataFile, SerializerContext.ApplicationMetadata);
@ -547,6 +556,7 @@ namespace Ryujinx.Ui.App.Common
appMetadata = new ApplicationMetadata(); appMetadata = new ApplicationMetadata();
} }
// Modify the metadata and save it back to the file
if (modifyFunction != null) if (modifyFunction != null)
{ {
modifyFunction(appMetadata); modifyFunction(appMetadata);