SystemStateMgr.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. public TitleLanguage DesiredTitleLanguage { get; private set; }
  37. internal string ActiveAudioOutput { get; private set; }
  38. public bool DockedMode { get; set; }
  39. public ColorSet ThemeColor { get; set; }
  40. private ConcurrentDictionary<string, UserProfile> Profiles;
  41. internal UserProfile LastOpenUser { get; private set; }
  42. public SystemStateMgr()
  43. {
  44. SetLanguage(SystemLanguage.AmericanEnglish);
  45. SetAudioOutputAsBuiltInSpeaker();
  46. Profiles = new ConcurrentDictionary<string, UserProfile>();
  47. UserId DefaultUuid = new UserId("00000000000000000000000000000001");
  48. AddUser(DefaultUuid, "Player");
  49. OpenUser(DefaultUuid);
  50. }
  51. public void SetLanguage(SystemLanguage Language)
  52. {
  53. DesiredLanguageCode = GetLanguageCode((int)Language);
  54. DesiredTitleLanguage = Enum.Parse<TitleLanguage>(Enum.GetName(typeof(SystemLanguage), Language));
  55. }
  56. public void SetAudioOutputAsTv()
  57. {
  58. ActiveAudioOutput = AudioOutputs[0];
  59. }
  60. public void SetAudioOutputAsStereoJack()
  61. {
  62. ActiveAudioOutput = AudioOutputs[1];
  63. }
  64. public void SetAudioOutputAsBuiltInSpeaker()
  65. {
  66. ActiveAudioOutput = AudioOutputs[2];
  67. }
  68. public void AddUser(UserId Uuid, string Name)
  69. {
  70. UserProfile Profile = new UserProfile(Uuid, Name);
  71. Profiles.AddOrUpdate(Uuid.UserIdHex, Profile, (Key, Old) => Profile);
  72. }
  73. public void OpenUser(UserId Uuid)
  74. {
  75. if (Profiles.TryGetValue(Uuid.UserIdHex, out UserProfile Profile))
  76. {
  77. (LastOpenUser = Profile).AccountState = OpenCloseState.Open;
  78. }
  79. }
  80. public void CloseUser(UserId Uuid)
  81. {
  82. if (Profiles.TryGetValue(Uuid.UserIdHex, out UserProfile Profile))
  83. {
  84. Profile.AccountState = OpenCloseState.Closed;
  85. }
  86. }
  87. public int GetUserCount()
  88. {
  89. return Profiles.Count;
  90. }
  91. internal bool TryGetUser(UserId Uuid, out UserProfile Profile)
  92. {
  93. return Profiles.TryGetValue(Uuid.UserIdHex, out Profile);
  94. }
  95. internal IEnumerable<UserProfile> GetAllUsers()
  96. {
  97. return Profiles.Values;
  98. }
  99. internal IEnumerable<UserProfile> GetOpenUsers()
  100. {
  101. return Profiles.Values.Where(x => x.AccountState == OpenCloseState.Open);
  102. }
  103. internal static long GetLanguageCode(int Index)
  104. {
  105. if ((uint)Index >= LanguageCodes.Length)
  106. {
  107. throw new ArgumentOutOfRangeException(nameof(Index));
  108. }
  109. long Code = 0;
  110. int Shift = 0;
  111. foreach (char Chr in LanguageCodes[Index])
  112. {
  113. Code |= (long)(byte)Chr << Shift++ * 8;
  114. }
  115. return Code;
  116. }
  117. }
  118. }