aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs')
-rw-r--r--Ryujinx.Ava/Ui/ViewModels/UserProfileViewModel.cs77
1 files changed, 76 insertions, 1 deletions
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