SystemStateMgr.cs 3.9 KB

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