SystemStateMgr.cs 3.9 KB

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