Make Ryujinx metadata user-specific

This commit is contained in:
Théo Arrouye 2023-06-04 16:46:20 -07:00
parent 306f7e93a0
commit d6d2b202d1
8 changed files with 32 additions and 15 deletions

View file

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

View file

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

View file

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

View file

@ -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)
{

View file

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

View file

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

View file

@ -81,7 +81,7 @@ namespace Ryujinx.Ui.App.Common
controlFile.Get.Read(out _, 0, outProperty, ReadOption.None).ThrowIfFailure();
}
public void LoadApplications(List<string> appDirs, Language desiredTitleLanguage)
public void LoadApplications(UserId userId, List<string> 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<ApplicationMetadata> modifyFunction = null)
public ApplicationMetadata LoadAndSaveMetaData(UserId userId, string titleId, Action<ApplicationMetadata> 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);

View file

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