diff options
Diffstat (limited to 'Ryujinx.Ava/Ui/ViewModels')
-rw-r--r-- | Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs | 11 | ||||
-rw-r--r-- | Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs | 77 |
2 files changed, 82 insertions, 6 deletions
diff --git a/Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs b/Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs index cd437017..c7053eb1 100644 --- a/Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs +++ b/Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs @@ -76,6 +76,7 @@ namespace Ryujinx.Ava.Ui.ViewModels private bool _showAll; private string _lastScannedAmiiboId; private ReadOnlyObservableCollection<ApplicationData> _appsObservableList; + public ApplicationLibrary ApplicationLibrary => _owner.ApplicationLibrary; public string TitleName { get; internal set; } @@ -103,8 +104,8 @@ namespace Ryujinx.Ava.Ui.ViewModels public void Initialize() { - _owner.ApplicationLibrary.ApplicationCountUpdated += ApplicationLibrary_ApplicationCountUpdated; - _owner.ApplicationLibrary.ApplicationAdded += ApplicationLibrary_ApplicationAdded; + ApplicationLibrary.ApplicationCountUpdated += ApplicationLibrary_ApplicationCountUpdated; + ApplicationLibrary.ApplicationAdded += ApplicationLibrary_ApplicationAdded; Ptc.PtcStateChanged -= ProgressHandler; Ptc.PtcStateChanged += ProgressHandler; @@ -817,7 +818,7 @@ namespace Ryujinx.Ava.Ui.ViewModels Thread thread = new(() => { - _owner.ApplicationLibrary.LoadApplications(ConfigurationState.Instance.Ui.GameDirs.Value, ConfigurationState.Instance.System.Language); + ApplicationLibrary.LoadApplications(ConfigurationState.Instance.Ui.GameDirs.Value, ConfigurationState.Instance.System.Language); _isLoading = false; }) @@ -1005,7 +1006,7 @@ namespace Ryujinx.Ava.Ui.ViewModels public async void ManageProfiles() { - await NavigationDialogHost.Show(_owner.AccountManager, _owner.ContentManager, _owner.VirtualFileSystem); + await NavigationDialogHost.Show(_owner.AccountManager, _owner.ContentManager, _owner.VirtualFileSystem, _owner.LibHacHorizonManager.RyujinxClient); } public async void OpenAboutWindow() @@ -1098,7 +1099,7 @@ namespace Ryujinx.Ava.Ui.ViewModels { selection.Favorite = !selection.Favorite; - _owner.ApplicationLibrary.LoadAndSaveMetaData(selection.TitleId, appMetadata => + ApplicationLibrary.LoadAndSaveMetaData(selection.TitleId, appMetadata => { appMetadata.Favorite = selection.Favorite; }); diff --git a/Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs b/Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs index a48b06e6..eb9f69d6 100644 --- a/Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs +++ b/Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs @@ -1,8 +1,14 @@ +using Avalonia; using Avalonia.Threading; +using FluentAvalonia.UI.Controls; +using LibHac.Common; +using LibHac.Fs; +using LibHac.Fs.Shim; using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Ui.Controls; using Ryujinx.HLE.HOS.Services.Account.Acc; using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using UserProfile = Ryujinx.Ava.Ui.Models.UserProfile; @@ -19,6 +25,7 @@ namespace Ryujinx.Ava.Ui.ViewModels public UserProfileViewModel() { Profiles = new ObservableCollection<UserProfile>(); + LostProfiles = new ObservableCollection<UserProfile>(); } public UserProfileViewModel(NavigationDialogHost owner) : this() @@ -30,6 +37,8 @@ namespace Ryujinx.Ava.Ui.ViewModels public ObservableCollection<UserProfile> Profiles { get; set; } + public ObservableCollection<UserProfile> LostProfiles { get; set; } + public UserProfile SelectedProfile { get => _selectedProfile; @@ -65,12 +74,13 @@ namespace Ryujinx.Ava.Ui.ViewModels public void LoadProfiles() { Profiles.Clear(); + LostProfiles.Clear(); var profiles = _owner.AccountManager.GetAllUsers().OrderByDescending(x => x.AccountState == AccountState.Open); foreach (var profile in profiles) { - Profiles.Add(new UserProfile(profile)); + Profiles.Add(new UserProfile(profile, _owner)); } SelectedProfile = Profiles.FirstOrDefault(x => x.UserId == _owner.AccountManager.LastOpenedUser.UserId); @@ -84,6 +94,42 @@ namespace Ryujinx.Ava.Ui.ViewModels _owner.AccountManager.OpenUser(_selectedProfile.UserId); } } + + var saveDataFilter = SaveDataFilter.Make(programId: default, saveType: SaveDataType.Account, + default, saveDataId: default, index: default); + + using var saveDataIterator = new UniqueRef<SaveDataIterator>(); + + _owner.HorizonClient.Fs.OpenSaveDataIterator(ref saveDataIterator.Ref(), SaveDataSpaceId.User, in saveDataFilter).ThrowIfFailure(); + + Span<SaveDataInfo> saveDataInfo = stackalloc SaveDataInfo[10]; + + HashSet<HLE.HOS.Services.Account.Acc.UserId> lostAccounts = new HashSet<HLE.HOS.Services.Account.Acc.UserId>(); + + while (true) + { + saveDataIterator.Get.ReadSaveDataInfo(out long readCount, saveDataInfo).ThrowIfFailure(); + + if (readCount == 0) + { + break; + } + + for (int i = 0; i < readCount; i++) + { + var save = saveDataInfo[i]; + var id = new HLE.HOS.Services.Account.Acc.UserId((long)save.UserId.Id.Low, (long)save.UserId.Id.High); + if (Profiles.FirstOrDefault( x=> x.UserId == id) == null) + { + lostAccounts.Add(id); + } + } + } + + foreach(var account in lostAccounts) + { + LostProfiles.Add(new UserProfile(new HLE.HOS.Services.Account.Acc.UserProfile(account, "", null), _owner)); + } } public void AddUser() @@ -93,6 +139,25 @@ namespace Ryujinx.Ava.Ui.ViewModels _owner.Navigate(typeof(UserEditor), (this._owner, userProfile, true)); } + public async void ManageSaves() + { + UserProfile userProfile = _highlightedProfile ?? SelectedProfile; + + SaveManager manager = new SaveManager(userProfile, _owner.HorizonClient, _owner.VirtualFileSystem); + + ContentDialog contentDialog = new ContentDialog + { + Title = string.Format(LocaleManager.Instance["SaveManagerHeading"], userProfile.Name), + PrimaryButtonText = "", + SecondaryButtonText = "", + CloseButtonText = LocaleManager.Instance["UserProfilesClose"], + Content = manager, + Padding = new Thickness(0) + }; + + await contentDialog.ShowAsync(); + } + public void EditUser() { _owner.Navigate(typeof(UserEditor), (this._owner, _highlightedProfile ?? SelectedProfile, false)); @@ -134,5 +199,15 @@ namespace Ryujinx.Ava.Ui.ViewModels LoadProfiles(); } + + public void GoBack() + { + _owner.GoBack(); + } + + public void RecoverLostAccounts() + { + _owner.Navigate(typeof(UserRecoverer), (this._owner, this)); + } } }
\ No newline at end of file |