2018-10-07 09:13:46 -04:00
|
|
|
using Ryujinx.HLE.Utilities;
|
2018-04-29 19:18:46 -04:00
|
|
|
using System;
|
2018-08-14 18:02:42 -04:00
|
|
|
using System.Collections.Concurrent;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2018-04-29 19:18:46 -04:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
namespace Ryujinx.HLE.HOS.SystemState
|
2018-04-24 16:14:26 -04:00
|
|
|
{
|
2018-04-29 19:18:46 -04:00
|
|
|
public class SystemStateMgr
|
2018-04-24 16:14:26 -04:00
|
|
|
{
|
2018-04-29 19:18:46 -04: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 16:14:26 -04:00
|
|
|
internal static string[] AudioOutputs = new string[]
|
|
|
|
{
|
|
|
|
"AudioTvOutput",
|
|
|
|
"AudioStereoJackOutput",
|
|
|
|
"AudioBuiltInSpeakerOutput"
|
|
|
|
};
|
|
|
|
|
2018-04-29 19:18:46 -04:00
|
|
|
internal long DesiredLanguageCode { get; private set; }
|
|
|
|
|
2018-09-19 08:09:49 -04:00
|
|
|
public TitleLanguage DesiredTitleLanguage { get; private set; }
|
|
|
|
|
2018-04-29 19:18:46 -04:00
|
|
|
internal string ActiveAudioOutput { get; private set; }
|
2018-08-14 18:02:42 -04:00
|
|
|
|
|
|
|
public bool DockedMode { get; set; }
|
|
|
|
|
|
|
|
public ColorSet ThemeColor { get; set; }
|
|
|
|
|
2018-11-18 14:37:41 -05:00
|
|
|
public bool InstallContents { get; set; }
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
private ConcurrentDictionary<string, UserProfile> _profiles;
|
2018-08-14 18:02:42 -04:00
|
|
|
|
|
|
|
internal UserProfile LastOpenUser { get; private set; }
|
2018-04-24 16:14:26 -04:00
|
|
|
|
|
|
|
public SystemStateMgr()
|
|
|
|
{
|
|
|
|
SetAudioOutputAsBuiltInSpeaker();
|
2018-08-14 18:02:42 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
_profiles = new ConcurrentDictionary<string, UserProfile>();
|
2018-08-14 18:02:42 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
UInt128 defaultUuid = new UInt128("00000000000000000000000000000001");
|
2018-08-14 18:02:42 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
AddUser(defaultUuid, "Player");
|
2018-10-07 09:13:46 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
OpenUser(defaultUuid);
|
2018-04-24 16:14:26 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
public void SetLanguage(SystemLanguage language)
|
2018-04-29 19:18:46 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
DesiredLanguageCode = GetLanguageCode((int)language);
|
2018-09-19 08:09:49 -04:00
|
|
|
|
2018-12-27 10:08:34 -05:00
|
|
|
switch (language)
|
|
|
|
{
|
|
|
|
case SystemLanguage.Taiwanese:
|
|
|
|
case SystemLanguage.TraditionalChinese:
|
|
|
|
DesiredTitleLanguage = TitleLanguage.Taiwanese;
|
|
|
|
break;
|
|
|
|
case SystemLanguage.Chinese:
|
|
|
|
case SystemLanguage.SimplifiedChinese:
|
|
|
|
DesiredTitleLanguage = TitleLanguage.Chinese;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DesiredTitleLanguage = Enum.Parse<TitleLanguage>(Enum.GetName(typeof(SystemLanguage), language));
|
|
|
|
break;
|
|
|
|
}
|
2018-04-29 19:18:46 -04:00
|
|
|
}
|
|
|
|
|
2018-04-24 16:14:26 -04:00
|
|
|
public void SetAudioOutputAsTv()
|
|
|
|
{
|
|
|
|
ActiveAudioOutput = AudioOutputs[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetAudioOutputAsStereoJack()
|
|
|
|
{
|
|
|
|
ActiveAudioOutput = AudioOutputs[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetAudioOutputAsBuiltInSpeaker()
|
|
|
|
{
|
|
|
|
ActiveAudioOutput = AudioOutputs[2];
|
|
|
|
}
|
2018-04-29 19:18:46 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
public void AddUser(UInt128 uuid, string name)
|
2018-08-14 18:02:42 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
UserProfile profile = new UserProfile(uuid, name);
|
2018-08-14 18:02:42 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
_profiles.AddOrUpdate(uuid.ToString(), profile, (key, old) => profile);
|
2018-08-14 18:02:42 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
public void OpenUser(UInt128 uuid)
|
2018-08-14 18:02:42 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
if (_profiles.TryGetValue(uuid.ToString(), out UserProfile profile))
|
2018-08-14 18:02:42 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
(LastOpenUser = profile).AccountState = OpenCloseState.Open;
|
2018-08-14 18:02:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
public void CloseUser(UInt128 uuid)
|
2018-08-14 18:02:42 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
if (_profiles.TryGetValue(uuid.ToString(), out UserProfile profile))
|
2018-08-14 18:02:42 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
profile.AccountState = OpenCloseState.Closed;
|
2018-08-14 18:02:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int GetUserCount()
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
return _profiles.Count;
|
2018-08-14 18:02:42 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
internal bool TryGetUser(UInt128 uuid, out UserProfile profile)
|
2018-08-14 18:02:42 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
return _profiles.TryGetValue(uuid.ToString(), out profile);
|
2018-08-14 18:02:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
internal IEnumerable<UserProfile> GetAllUsers()
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
return _profiles.Values;
|
2018-08-14 18:02:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
internal IEnumerable<UserProfile> GetOpenUsers()
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
return _profiles.Values.Where(x => x.AccountState == OpenCloseState.Open);
|
2018-08-14 18:02:42 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
internal static long GetLanguageCode(int index)
|
2018-04-29 19:18:46 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
if ((uint)index >= LanguageCodes.Length)
|
2018-04-29 19:18:46 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(index));
|
2018-04-29 19:18:46 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
long code = 0;
|
|
|
|
int shift = 0;
|
2018-04-29 19:18:46 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
foreach (char chr in LanguageCodes[index])
|
2018-04-29 19:18:46 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
code |= (long)(byte)chr << shift++ * 8;
|
2018-04-29 19:18:46 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
return code;
|
2018-04-29 19:18:46 -04:00
|
|
|
}
|
2018-04-24 16:14:26 -04:00
|
|
|
}
|
2018-08-11 08:12:28 -04:00
|
|
|
}
|