SystemStateMgr.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using Ryujinx.HLE.Utilities;
  2. using System;
  3. using System.Collections.Concurrent;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. namespace Ryujinx.HLE.HOS.SystemState
  7. {
  8. public class SystemStateMgr
  9. {
  10. internal static string[] LanguageCodes = new string[]
  11. {
  12. "ja",
  13. "en-US",
  14. "fr",
  15. "de",
  16. "it",
  17. "es",
  18. "zh-CN",
  19. "ko",
  20. "nl",
  21. "pt",
  22. "ru",
  23. "zh-TW",
  24. "en-GB",
  25. "fr-CA",
  26. "es-419",
  27. "zh-Hans",
  28. "zh-Hant"
  29. };
  30. internal static string[] AudioOutputs = new string[]
  31. {
  32. "AudioTvOutput",
  33. "AudioStereoJackOutput",
  34. "AudioBuiltInSpeakerOutput"
  35. };
  36. internal long DesiredLanguageCode { get; private set; }
  37. public TitleLanguage DesiredTitleLanguage { get; private set; }
  38. internal string ActiveAudioOutput { get; private set; }
  39. public bool DockedMode { get; set; }
  40. public ColorSet ThemeColor { get; set; }
  41. public bool InstallContents { get; set; }
  42. private ConcurrentDictionary<string, UserProfile> _profiles;
  43. internal UserProfile LastOpenUser { get; private set; }
  44. public SystemStateMgr()
  45. {
  46. SetAudioOutputAsBuiltInSpeaker();
  47. _profiles = new ConcurrentDictionary<string, UserProfile>();
  48. UInt128 defaultUuid = new UInt128("00000000000000000000000000000001");
  49. AddUser(defaultUuid, "Player");
  50. OpenUser(defaultUuid);
  51. }
  52. public void SetLanguage(SystemLanguage language)
  53. {
  54. DesiredLanguageCode = GetLanguageCode((int)language);
  55. switch (language)
  56. {
  57. case SystemLanguage.Taiwanese:
  58. case SystemLanguage.TraditionalChinese:
  59. DesiredTitleLanguage = TitleLanguage.Taiwanese;
  60. break;
  61. case SystemLanguage.Chinese:
  62. case SystemLanguage.SimplifiedChinese:
  63. DesiredTitleLanguage = TitleLanguage.Chinese;
  64. break;
  65. default:
  66. DesiredTitleLanguage = Enum.Parse<TitleLanguage>(Enum.GetName(typeof(SystemLanguage), language));
  67. break;
  68. }
  69. }
  70. public void SetAudioOutputAsTv()
  71. {
  72. ActiveAudioOutput = AudioOutputs[0];
  73. }
  74. public void SetAudioOutputAsStereoJack()
  75. {
  76. ActiveAudioOutput = AudioOutputs[1];
  77. }
  78. public void SetAudioOutputAsBuiltInSpeaker()
  79. {
  80. ActiveAudioOutput = AudioOutputs[2];
  81. }
  82. public void AddUser(UInt128 uuid, string name)
  83. {
  84. UserProfile profile = new UserProfile(uuid, name);
  85. _profiles.AddOrUpdate(uuid.ToString(), profile, (key, old) => profile);
  86. }
  87. public void OpenUser(UInt128 uuid)
  88. {
  89. if (_profiles.TryGetValue(uuid.ToString(), out UserProfile profile))
  90. {
  91. (LastOpenUser = profile).AccountState = OpenCloseState.Open;
  92. }
  93. }
  94. public void CloseUser(UInt128 uuid)
  95. {
  96. if (_profiles.TryGetValue(uuid.ToString(), out UserProfile profile))
  97. {
  98. profile.AccountState = OpenCloseState.Closed;
  99. }
  100. }
  101. public int GetUserCount()
  102. {
  103. return _profiles.Count;
  104. }
  105. internal bool TryGetUser(UInt128 uuid, out UserProfile profile)
  106. {
  107. return _profiles.TryGetValue(uuid.ToString(), out profile);
  108. }
  109. internal IEnumerable<UserProfile> GetAllUsers()
  110. {
  111. return _profiles.Values;
  112. }
  113. internal IEnumerable<UserProfile> GetOpenUsers()
  114. {
  115. return _profiles.Values.Where(x => x.AccountState == OpenCloseState.Open);
  116. }
  117. internal static long GetLanguageCode(int index)
  118. {
  119. if ((uint)index >= LanguageCodes.Length)
  120. {
  121. throw new ArgumentOutOfRangeException(nameof(index));
  122. }
  123. long code = 0;
  124. int shift = 0;
  125. foreach (char chr in LanguageCodes[index])
  126. {
  127. code |= (long)(byte)chr << shift++ * 8;
  128. }
  129. return code;
  130. }
  131. }
  132. }