SystemStateMgr.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace Ryujinx.HLE.HOS.SystemState
  6. {
  7. public class SystemStateMgr
  8. {
  9. internal static string[] LanguageCodes = new string[]
  10. {
  11. "ja",
  12. "en-US",
  13. "fr",
  14. "de",
  15. "it",
  16. "es",
  17. "zh-CN",
  18. "ko",
  19. "nl",
  20. "pt",
  21. "ru",
  22. "zh-TW",
  23. "en-GB",
  24. "fr-CA",
  25. "es-419",
  26. "zh-Hans",
  27. "zh-Hant"
  28. };
  29. internal static string[] AudioOutputs = new string[]
  30. {
  31. "AudioTvOutput",
  32. "AudioStereoJackOutput",
  33. "AudioBuiltInSpeakerOutput"
  34. };
  35. internal long DesiredLanguageCode { get; private set; }
  36. internal string ActiveAudioOutput { get; private set; }
  37. public bool DockedMode { get; set; }
  38. public ColorSet ThemeColor { get; set; }
  39. private ConcurrentDictionary<string, UserProfile> Profiles;
  40. internal UserProfile LastOpenUser { get; private set; }
  41. public SystemStateMgr()
  42. {
  43. SetLanguage(SystemLanguage.AmericanEnglish);
  44. SetAudioOutputAsBuiltInSpeaker();
  45. Profiles = new ConcurrentDictionary<string, UserProfile>();
  46. UserId DefaultUuid = new UserId("00000000000000000000000000000001");
  47. AddUser(DefaultUuid, "Player");
  48. OpenUser(DefaultUuid);
  49. }
  50. public void SetLanguage(SystemLanguage Language)
  51. {
  52. DesiredLanguageCode = GetLanguageCode((int)Language);
  53. }
  54. public void SetAudioOutputAsTv()
  55. {
  56. ActiveAudioOutput = AudioOutputs[0];
  57. }
  58. public void SetAudioOutputAsStereoJack()
  59. {
  60. ActiveAudioOutput = AudioOutputs[1];
  61. }
  62. public void SetAudioOutputAsBuiltInSpeaker()
  63. {
  64. ActiveAudioOutput = AudioOutputs[2];
  65. }
  66. public void AddUser(UserId Uuid, string Name)
  67. {
  68. UserProfile Profile = new UserProfile(Uuid, Name);
  69. Profiles.AddOrUpdate(Uuid.UserIdHex, Profile, (Key, Old) => Profile);
  70. }
  71. public void OpenUser(UserId Uuid)
  72. {
  73. if (Profiles.TryGetValue(Uuid.UserIdHex, out UserProfile Profile))
  74. {
  75. (LastOpenUser = Profile).AccountState = OpenCloseState.Open;
  76. }
  77. }
  78. public void CloseUser(UserId Uuid)
  79. {
  80. if (Profiles.TryGetValue(Uuid.UserIdHex, out UserProfile Profile))
  81. {
  82. Profile.AccountState = OpenCloseState.Closed;
  83. }
  84. }
  85. public int GetUserCount()
  86. {
  87. return Profiles.Count;
  88. }
  89. internal bool TryGetUser(UserId Uuid, out UserProfile Profile)
  90. {
  91. return Profiles.TryGetValue(Uuid.UserIdHex, out Profile);
  92. }
  93. internal IEnumerable<UserProfile> GetAllUsers()
  94. {
  95. return Profiles.Values;
  96. }
  97. internal IEnumerable<UserProfile> GetOpenUsers()
  98. {
  99. return Profiles.Values.Where(x => x.AccountState == OpenCloseState.Open);
  100. }
  101. internal static long GetLanguageCode(int Index)
  102. {
  103. if ((uint)Index >= LanguageCodes.Length)
  104. {
  105. throw new ArgumentOutOfRangeException(nameof(Index));
  106. }
  107. long Code = 0;
  108. int Shift = 0;
  109. foreach (char Chr in LanguageCodes[Index])
  110. {
  111. Code |= (long)(byte)Chr << Shift++ * 8;
  112. }
  113. return Code;
  114. }
  115. }
  116. }