AccountUtils.cs 1.8 KB

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