2018-10-07 13:13:46 +00:00
|
|
|
using Ryujinx.HLE.Utilities;
|
2018-04-29 23:18:46 +00:00
|
|
|
using System;
|
2018-08-14 22:02:42 +00:00
|
|
|
using System.Collections.Concurrent;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2018-04-29 23:18:46 +00:00
|
|
|
|
2018-08-16 23:47:36 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.SystemState
|
2018-04-24 20:14:26 +00:00
|
|
|
{
|
2018-04-29 23:18:46 +00:00
|
|
|
public class SystemStateMgr
|
2018-04-24 20:14:26 +00:00
|
|
|
{
|
2018-04-29 23:18:46 +00:00
|
|
|
internal static string[] LanguageCodes = new string[]
|
|
|
|
{
|
|
|
|
"ja",
|
|
|
|
"en-US",
|
|
|
|
"fr",
|
|
|
|
"de",
|
|
|
|
"it",
|
|
|
|
"es",
|
|
|
|
"zh-CN",
|
|
|
|
"ko",
|
|
|
|
"nl",
|
|
|
|
"pt",
|
|
|
|
"ru",
|
|
|
|
"zh-TW",
|
|
|
|
"en-GB",
|
|
|
|
"fr-CA",
|
|
|
|
"es-419",
|
|
|
|
"zh-Hans",
|
|
|
|
"zh-Hant"
|
|
|
|
};
|
|
|
|
|
2018-04-24 20:14:26 +00:00
|
|
|
internal static string[] AudioOutputs = new string[]
|
|
|
|
{
|
|
|
|
"AudioTvOutput",
|
|
|
|
"AudioStereoJackOutput",
|
|
|
|
"AudioBuiltInSpeakerOutput"
|
|
|
|
};
|
|
|
|
|
2018-04-29 23:18:46 +00:00
|
|
|
internal long DesiredLanguageCode { get; private set; }
|
|
|
|
|
2018-09-19 12:09:49 +00:00
|
|
|
public TitleLanguage DesiredTitleLanguage { get; private set; }
|
|
|
|
|
2018-04-29 23:18:46 +00:00
|
|
|
internal string ActiveAudioOutput { get; private set; }
|
2018-08-14 22:02:42 +00:00
|
|
|
|
|
|
|
public bool DockedMode { get; set; }
|
|
|
|
|
|
|
|
public ColorSet ThemeColor { get; set; }
|
|
|
|
|
2018-11-18 19:37:41 +00:00
|
|
|
public bool InstallContents { get; set; }
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
private ConcurrentDictionary<string, UserProfile> Profiles;
|
2018-08-14 22:02:42 +00:00
|
|
|
|
|
|
|
internal UserProfile LastOpenUser { get; private set; }
|
2018-04-24 20:14:26 +00:00
|
|
|
|
|
|
|
public SystemStateMgr()
|
|
|
|
{
|
2018-04-29 23:18:46 +00:00
|
|
|
SetLanguage(SystemLanguage.AmericanEnglish);
|
|
|
|
|
2018-04-24 20:14:26 +00:00
|
|
|
SetAudioOutputAsBuiltInSpeaker();
|
2018-08-14 22:02:42 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
Profiles = new ConcurrentDictionary<string, UserProfile>();
|
2018-08-14 22:02:42 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
UInt128 DefaultUuid = new UInt128("00000000000000000000000000000001");
|
2018-08-14 22:02:42 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
AddUser(DefaultUuid, "Player");
|
2018-10-07 13:13:46 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
OpenUser(DefaultUuid);
|
2018-04-24 20:14:26 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public void SetLanguage(SystemLanguage Language)
|
2018-04-29 23:18:46 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
DesiredLanguageCode = GetLanguageCode((int)Language);
|
2018-09-19 12:09:49 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
DesiredTitleLanguage = Enum.Parse<TitleLanguage>(Enum.GetName(typeof(SystemLanguage), Language));
|
2018-04-29 23:18:46 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 20:14:26 +00:00
|
|
|
public void SetAudioOutputAsTv()
|
|
|
|
{
|
|
|
|
ActiveAudioOutput = AudioOutputs[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetAudioOutputAsStereoJack()
|
|
|
|
{
|
|
|
|
ActiveAudioOutput = AudioOutputs[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetAudioOutputAsBuiltInSpeaker()
|
|
|
|
{
|
|
|
|
ActiveAudioOutput = AudioOutputs[2];
|
|
|
|
}
|
2018-04-29 23:18:46 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public void AddUser(UInt128 Uuid, string Name)
|
2018-08-14 22:02:42 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
UserProfile Profile = new UserProfile(Uuid, Name);
|
2018-08-14 22:02:42 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
Profiles.AddOrUpdate(Uuid.ToString(), Profile, (Key, Old) => Profile);
|
2018-08-14 22:02:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public void OpenUser(UInt128 Uuid)
|
2018-08-14 22:02:42 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
if (Profiles.TryGetValue(Uuid.ToString(), out UserProfile Profile))
|
2018-08-14 22:02:42 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
(LastOpenUser = Profile).AccountState = OpenCloseState.Open;
|
2018-08-14 22:02:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public void CloseUser(UInt128 Uuid)
|
2018-08-14 22:02:42 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
if (Profiles.TryGetValue(Uuid.ToString(), out UserProfile Profile))
|
2018-08-14 22:02:42 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
Profile.AccountState = OpenCloseState.Closed;
|
2018-08-14 22:02:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int GetUserCount()
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
return Profiles.Count;
|
2018-08-14 22:02:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
internal bool TryGetUser(UInt128 Uuid, out UserProfile Profile)
|
2018-08-14 22:02:42 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
return Profiles.TryGetValue(Uuid.ToString(), out Profile);
|
2018-08-14 22:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal IEnumerable<UserProfile> GetAllUsers()
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
return Profiles.Values;
|
2018-08-14 22:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal IEnumerable<UserProfile> GetOpenUsers()
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
return Profiles.Values.Where(x => x.AccountState == OpenCloseState.Open);
|
2018-08-14 22:02:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
internal static long GetLanguageCode(int Index)
|
2018-04-29 23:18:46 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
if ((uint)Index >= LanguageCodes.Length)
|
2018-04-29 23:18:46 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(Index));
|
2018-04-29 23:18:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
long Code = 0;
|
|
|
|
int Shift = 0;
|
2018-04-29 23:18:46 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
foreach (char Chr in LanguageCodes[Index])
|
2018-04-29 23:18:46 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
Code |= (long)(byte)Chr << Shift++ * 8;
|
2018-04-29 23:18:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
return Code;
|
2018-04-29 23:18:46 +00:00
|
|
|
}
|
2018-04-24 20:14:26 +00:00
|
|
|
}
|
2018-08-11 12:12:28 +00:00
|
|
|
}
|