From d6d2b202d1bba2d05b38e2b183d367ec2c397407 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 16:46:20 -0700 Subject: [PATCH] Make Ryujinx metadata user-specific --- src/Ryujinx.Ava/AppHost.cs | 2 +- .../Controls/ApplicationContextMenu.axaml.cs | 2 +- src/Ryujinx.Ava/UI/Models/SaveModel.cs | 2 +- .../UI/ViewModels/MainWindowViewModel.cs | 2 +- .../UI/Windows/MainWindow.axaml.cs | 2 +- .../HOS/Services/Account/Acc/Types/UserId.cs | 5 ++++ .../App/ApplicationLibrary.cs | 24 ++++++++++++++----- src/Ryujinx/Ui/MainWindow.cs | 8 +++---- 8 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/Ryujinx.Ava/AppHost.cs b/src/Ryujinx.Ava/AppHost.cs index 2502fa41b..d7e6c3655 100644 --- a/src/Ryujinx.Ava/AppHost.cs +++ b/src/Ryujinx.Ava/AppHost.cs @@ -682,7 +682,7 @@ namespace Ryujinx.Ava DiscordIntegrationModule.SwitchToPlayingState(Device.Processes.ActiveApplication.ProgramIdText, Device.Processes.ActiveApplication.Name); - _viewModel.ApplicationLibrary.LoadAndSaveMetaData(Device.Processes.ActiveApplication.ProgramIdText, appMetadata => + _viewModel.ApplicationLibrary.LoadAndSaveMetaData(_accountManager.LastOpenedUser.UserId.ToLibHacFsUid(), Device.Processes.ActiveApplication.ProgramIdText, appMetadata => { appMetadata.LastPlayed = DateTime.UtcNow; }); diff --git a/src/Ryujinx.Ava/UI/Controls/ApplicationContextMenu.axaml.cs b/src/Ryujinx.Ava/UI/Controls/ApplicationContextMenu.axaml.cs index 73c53e7f6..d75e21a4f 100644 --- a/src/Ryujinx.Ava/UI/Controls/ApplicationContextMenu.axaml.cs +++ b/src/Ryujinx.Ava/UI/Controls/ApplicationContextMenu.axaml.cs @@ -42,7 +42,7 @@ namespace Ryujinx.Ava.UI.Controls { viewModel.SelectedApplication.Favorite = !viewModel.SelectedApplication.Favorite; - viewModel.ApplicationLibrary.LoadAndSaveMetaData(viewModel.SelectedApplication.TitleId, appMetadata => + viewModel.ApplicationLibrary.LoadAndSaveMetaData(viewModel.AccountManager.LastOpenedUser.UserId.ToLibHacFsUid(), viewModel.SelectedApplication.TitleId, appMetadata => { appMetadata.Favorite = viewModel.SelectedApplication.Favorite; }); diff --git a/src/Ryujinx.Ava/UI/Models/SaveModel.cs b/src/Ryujinx.Ava/UI/Models/SaveModel.cs index ab919c88d..a468659b8 100644 --- a/src/Ryujinx.Ava/UI/Models/SaveModel.cs +++ b/src/Ryujinx.Ava/UI/Models/SaveModel.cs @@ -74,7 +74,7 @@ namespace Ryujinx.Ava.UI.Models } else { - var appMetadata = MainWindow.MainWindowViewModel.ApplicationLibrary.LoadAndSaveMetaData(TitleIdString); + var appMetadata = MainWindow.MainWindowViewModel.ApplicationLibrary.LoadAndSaveMetaData(UserId, TitleIdString); Title = appMetadata.Title ?? TitleIdString; } diff --git a/src/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs index 409ccad3c..a665b6f16 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs @@ -1523,7 +1523,7 @@ namespace Ryujinx.Ava.UI.ViewModels public void UpdateGameMetadata(string titleId) { - ApplicationLibrary.LoadAndSaveMetaData(titleId, appMetadata => + ApplicationLibrary.LoadAndSaveMetaData(AccountManager.LastOpenedUser.UserId.ToLibHacFsUid(), titleId, appMetadata => { if (appMetadata.LastPlayed.HasValue) { diff --git a/src/Ryujinx.Ava/UI/Windows/MainWindow.axaml.cs b/src/Ryujinx.Ava/UI/Windows/MainWindow.axaml.cs index 66988c4b3..cbcc06c0e 100644 --- a/src/Ryujinx.Ava/UI/Windows/MainWindow.axaml.cs +++ b/src/Ryujinx.Ava/UI/Windows/MainWindow.axaml.cs @@ -554,7 +554,7 @@ namespace Ryujinx.Ava.UI.Windows _isLoading = true; - ApplicationLibrary.LoadApplications(ConfigurationState.Instance.Ui.GameDirs.Value, ConfigurationState.Instance.System.Language); + ApplicationLibrary.LoadApplications(ViewModel.AccountManager.LastOpenedUser.UserId.ToLibHacFsUid(), ConfigurationState.Instance.Ui.GameDirs.Value, ConfigurationState.Instance.System.Language); _isLoading = false; } diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserId.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserId.cs index e5577a94b..c58ed9d6c 100644 --- a/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserId.cs +++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/Types/UserId.cs @@ -56,6 +56,11 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc return new Uid((ulong)High, (ulong)Low); } + public LibHac.Fs.UserId ToLibHacFsUid() + { + return new LibHac.Fs.UserId((ulong)High, (ulong)Low); + } + public UInt128 ToUInt128() { return new UInt128((ulong)High, (ulong)Low); diff --git a/src/Ryujinx.Ui.Common/App/ApplicationLibrary.cs b/src/Ryujinx.Ui.Common/App/ApplicationLibrary.cs index f52af611e..27369dd08 100644 --- a/src/Ryujinx.Ui.Common/App/ApplicationLibrary.cs +++ b/src/Ryujinx.Ui.Common/App/ApplicationLibrary.cs @@ -81,7 +81,7 @@ namespace Ryujinx.Ui.App.Common controlFile.Get.Read(out _, 0, outProperty, ReadOption.None).ThrowIfFailure(); } - public void LoadApplications(List appDirs, Language desiredTitleLanguage) + public void LoadApplications(UserId userId, List appDirs, Language desiredTitleLanguage) { int numApplicationsFound = 0; int numApplicationsLoaded = 0; @@ -418,7 +418,7 @@ namespace Ryujinx.Ui.App.Common continue; } - ApplicationMetadata appMetadata = LoadAndSaveMetaData(titleId, appMetadata => + ApplicationMetadata appMetadata = LoadAndSaveMetaData(userId, titleId, appMetadata => { appMetadata.Title = titleName; @@ -508,17 +508,29 @@ namespace Ryujinx.Ui.App.Common titleId = controlNca?.Header.TitleId.ToString("x16"); } - public ApplicationMetadata LoadAndSaveMetaData(string titleId, Action modifyFunction = null) + public ApplicationMetadata LoadAndSaveMetaData(UserId userId, string titleId, Action modifyFunction = null) { - string metadataFolder = Path.Combine(AppDataManager.GamesDirPath, titleId, "gui"); + string guiFolder = Path.Combine(AppDataManager.GamesDirPath, titleId, "gui"); + string metadataFolder = Path.Combine(guiFolder, userId.ToString()); string metadataFile = Path.Combine(metadataFolder, "metadata.json"); + if (!Directory.Exists(metadataFolder)) + { + Directory.CreateDirectory(metadataFolder); + } + + // Handle migration from old default to current user + string legacyFile = Path.Combine(guiFolder, "metadata.json"); + if (File.Exists(legacyFile) && !File.Exists(metadataFile)) + { + File.Move(legacyFile, metadataFile); + File.Delete(legacyFile); + } + ApplicationMetadata appMetadata; if (!File.Exists(metadataFile)) { - Directory.CreateDirectory(metadataFolder); - appMetadata = new ApplicationMetadata(); JsonHelper.SerializeToFile(metadataFile, appMetadata, SerializerContext.ApplicationMetadata); diff --git a/src/Ryujinx/Ui/MainWindow.cs b/src/Ryujinx/Ui/MainWindow.cs index 1918594ce..b428ff38c 100644 --- a/src/Ryujinx/Ui/MainWindow.cs +++ b/src/Ryujinx/Ui/MainWindow.cs @@ -657,7 +657,7 @@ namespace Ryujinx.Ui Thread applicationLibraryThread = new Thread(() => { - _applicationLibrary.LoadApplications(ConfigurationState.Instance.Ui.GameDirs, ConfigurationState.Instance.System.Language); + _applicationLibrary.LoadApplications(_accountManager.LastOpenedUser.UserId.ToLibHacFsUid(), ConfigurationState.Instance.Ui.GameDirs, ConfigurationState.Instance.System.Language); _updatingGameTable = false; }); @@ -874,7 +874,7 @@ namespace Ryujinx.Ui DiscordIntegrationModule.SwitchToPlayingState(_emulationContext.Processes.ActiveApplication.ProgramIdText, _emulationContext.Processes.ActiveApplication.ApplicationControlProperties.Title[(int)_emulationContext.System.State.DesiredTitleLanguage].NameString.ToString()); - _applicationLibrary.LoadAndSaveMetaData(_emulationContext.Processes.ActiveApplication.ProgramIdText, appMetadata => + _applicationLibrary.LoadAndSaveMetaData(_accountManager.LastOpenedUser.UserId.ToLibHacFsUid(), _emulationContext.Processes.ActiveApplication.ProgramIdText, appMetadata => { appMetadata.LastPlayed = DateTime.UtcNow; }); @@ -1017,7 +1017,7 @@ namespace Ryujinx.Ui { if (_gameLoaded) { - _applicationLibrary.LoadAndSaveMetaData(titleId, appMetadata => + _applicationLibrary.LoadAndSaveMetaData(_accountManager.LastOpenedUser.UserId.ToLibHacFsUid(), titleId, appMetadata => { if (appMetadata.LastPlayed.HasValue) { @@ -1156,7 +1156,7 @@ namespace Ryujinx.Ui _tableStore.SetValue(treeIter, 0, newToggleValue); - _applicationLibrary.LoadAndSaveMetaData(titleId, appMetadata => + _applicationLibrary.LoadAndSaveMetaData(_accountManager.LastOpenedUser.UserId.ToLibHacFsUid(), titleId, appMetadata => { appMetadata.Favorite = newToggleValue; });