SystemStateMgr.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 DiscordIntergrationEnabled { get; set; }
  40. public bool DockedMode { get; set; }
  41. public ColorSet ThemeColor { get; set; }
  42. public bool InstallContents { get; set; }
  43. private ConcurrentDictionary<string, UserProfile> _profiles;
  44. internal UserProfile LastOpenUser { get; private set; }
  45. public SystemStateMgr()
  46. {
  47. SetAudioOutputAsBuiltInSpeaker();
  48. _profiles = new ConcurrentDictionary<string, UserProfile>();
  49. UInt128 defaultUuid = new UInt128("00000000000000000000000000000001");
  50. AddUser(defaultUuid, "Player");
  51. OpenUser(defaultUuid);
  52. }
  53. public void SetLanguage(SystemLanguage language)
  54. {
  55. DesiredLanguageCode = GetLanguageCode((int)language);
  56. switch (language)
  57. {
  58. case SystemLanguage.Taiwanese:
  59. case SystemLanguage.TraditionalChinese:
  60. DesiredTitleLanguage = TitleLanguage.Taiwanese;
  61. break;
  62. case SystemLanguage.Chinese:
  63. case SystemLanguage.SimplifiedChinese:
  64. DesiredTitleLanguage = TitleLanguage.Chinese;
  65. break;
  66. default:
  67. DesiredTitleLanguage = Enum.Parse<TitleLanguage>(Enum.GetName(typeof(SystemLanguage), language));
  68. break;
  69. }
  70. }
  71. public void SetAudioOutputAsTv()
  72. {
  73. ActiveAudioOutput = AudioOutputs[0];
  74. }
  75. public void SetAudioOutputAsStereoJack()
  76. {
  77. ActiveAudioOutput = AudioOutputs[1];
  78. }
  79. public void SetAudioOutputAsBuiltInSpeaker()
  80. {
  81. ActiveAudioOutput = AudioOutputs[2];
  82. }
  83. public void AddUser(UInt128 uuid, string name)
  84. {
  85. UserProfile profile = new UserProfile(uuid, name);
  86. _profiles.AddOrUpdate(uuid.ToString(), profile, (key, old) => profile);
  87. }
  88. public void OpenUser(UInt128 uuid)
  89. {
  90. if (_profiles.TryGetValue(uuid.ToString(), out UserProfile profile))
  91. {
  92. (LastOpenUser = profile).AccountState = OpenCloseState.Open;
  93. }
  94. }
  95. public void CloseUser(UInt128 uuid)
  96. {
  97. if (_profiles.TryGetValue(uuid.ToString(), out UserProfile profile))
  98. {
  99. profile.AccountState = OpenCloseState.Closed;
  100. }
  101. }
  102. public int GetUserCount()
  103. {
  104. return _profiles.Count;
  105. }
  106. internal bool TryGetUser(UInt128 uuid, out UserProfile profile)
  107. {
  108. return _profiles.TryGetValue(uuid.ToString(), out profile);
  109. }
  110. internal IEnumerable<UserProfile> GetAllUsers()
  111. {
  112. return _profiles.Values;
  113. }
  114. internal IEnumerable<UserProfile> GetOpenUsers()
  115. {
  116. return _profiles.Values.Where(x => x.AccountState == OpenCloseState.Open);
  117. }
  118. internal static long GetLanguageCode(int index)
  119. {
  120. if ((uint)index >= LanguageCodes.Length)
  121. {
  122. throw new ArgumentOutOfRangeException(nameof(index));
  123. }
  124. long code = 0;
  125. int shift = 0;
  126. foreach (char chr in LanguageCodes[index])
  127. {
  128. code |= (long)(byte)chr << shift++ * 8;
  129. }
  130. return code;
  131. }
  132. }
  133. }