AccountUtils.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using Ryujinx.HLE.HOS.SystemState;
  2. using Ryujinx.HLE.Utilities;
  3. using System.Collections.Concurrent;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. namespace Ryujinx.HLE.HOS.Services.Acc
  7. {
  8. public class AccountUtils
  9. {
  10. private ConcurrentDictionary<string, UserProfile> _profiles;
  11. internal UserProfile LastOpenedUser { get; private set; }
  12. public AccountUtils()
  13. {
  14. _profiles = new ConcurrentDictionary<string, UserProfile>();
  15. }
  16. public void AddUser(UInt128 userId, string name)
  17. {
  18. UserProfile profile = new UserProfile(userId, name);
  19. _profiles.AddOrUpdate(userId.ToString(), profile, (key, old) => profile);
  20. }
  21. public void OpenUser(UInt128 userId)
  22. {
  23. if (_profiles.TryGetValue(userId.ToString(), out UserProfile profile))
  24. {
  25. (LastOpenedUser = profile).AccountState = AccountState.Open;
  26. }
  27. }
  28. public void CloseUser(UInt128 userId)
  29. {
  30. if (_profiles.TryGetValue(userId.ToString(), out UserProfile profile))
  31. {
  32. profile.AccountState = AccountState.Closed;
  33. }
  34. }
  35. public int GetUserCount()
  36. {
  37. return _profiles.Count;
  38. }
  39. internal bool TryGetUser(UInt128 userId, out UserProfile profile)
  40. {
  41. return _profiles.TryGetValue(userId.ToString(), out profile);
  42. }
  43. internal IEnumerable<UserProfile> GetAllUsers()
  44. {
  45. return _profiles.Values;
  46. }
  47. internal IEnumerable<UserProfile> GetOpenedUsers()
  48. {
  49. return _profiles.Values.Where(x => x.AccountState == AccountState.Open);
  50. }
  51. internal UserProfile GetFirst()
  52. {
  53. return _profiles.First().Value;
  54. }
  55. }
  56. }