Ryujinx/Ryujinx.HLE/HOS/SystemState/SystemStateMgr.cs

154 lines
3.9 KiB
C#
Raw Normal View History

using Ryujinx.HLE.Utilities;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
namespace Ryujinx.HLE.HOS.SystemState
{
public class SystemStateMgr
{
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"
};
internal static string[] AudioOutputs = new string[]
{
"AudioTvOutput",
"AudioStereoJackOutput",
"AudioBuiltInSpeakerOutput"
};
internal long DesiredLanguageCode { get; private set; }
public TitleLanguage DesiredTitleLanguage { get; private set; }
internal string ActiveAudioOutput { get; private set; }
public bool DockedMode { get; set; }
public ColorSet ThemeColor { get; set; }
public bool InstallContents { get; set; }
2018-12-01 21:01:59 +01:00
private ConcurrentDictionary<string, UserProfile> _profiles;
internal UserProfile LastOpenUser { get; private set; }
public SystemStateMgr()
{
SetLanguage(SystemLanguage.AmericanEnglish);
SetAudioOutputAsBuiltInSpeaker();
2018-12-01 21:01:59 +01:00
_profiles = new ConcurrentDictionary<string, UserProfile>();
2018-12-01 21:01:59 +01:00
UInt128 defaultUuid = new UInt128("00000000000000000000000000000001");
2018-12-01 21:01:59 +01:00
AddUser(defaultUuid, "Player");
2018-12-01 21:01:59 +01:00
OpenUser(defaultUuid);
}
2018-12-01 21:01:59 +01:00
public void SetLanguage(SystemLanguage language)
{
2018-12-01 21:01:59 +01:00
DesiredLanguageCode = GetLanguageCode((int)language);
2018-12-01 21:01:59 +01:00
DesiredTitleLanguage = Enum.Parse<TitleLanguage>(Enum.GetName(typeof(SystemLanguage), language));
}
public void SetAudioOutputAsTv()
{
ActiveAudioOutput = AudioOutputs[0];
}
public void SetAudioOutputAsStereoJack()
{
ActiveAudioOutput = AudioOutputs[1];
}
public void SetAudioOutputAsBuiltInSpeaker()
{
ActiveAudioOutput = AudioOutputs[2];
}
2018-12-01 21:01:59 +01:00
public void AddUser(UInt128 uuid, string name)
{
2018-12-01 21:01:59 +01:00
UserProfile profile = new UserProfile(uuid, name);
2018-12-01 21:01:59 +01:00
_profiles.AddOrUpdate(uuid.ToString(), profile, (key, old) => profile);
}
2018-12-01 21:01:59 +01:00
public void OpenUser(UInt128 uuid)
{
2018-12-01 21:01:59 +01:00
if (_profiles.TryGetValue(uuid.ToString(), out UserProfile profile))
{
2018-12-01 21:01:59 +01:00
(LastOpenUser = profile).AccountState = OpenCloseState.Open;
}
}
2018-12-01 21:01:59 +01:00
public void CloseUser(UInt128 uuid)
{
2018-12-01 21:01:59 +01:00
if (_profiles.TryGetValue(uuid.ToString(), out UserProfile profile))
{
2018-12-01 21:01:59 +01:00
profile.AccountState = OpenCloseState.Closed;
}
}
public int GetUserCount()
{
2018-12-01 21:01:59 +01:00
return _profiles.Count;
}
2018-12-01 21:01:59 +01:00
internal bool TryGetUser(UInt128 uuid, out UserProfile profile)
{
2018-12-01 21:01:59 +01:00
return _profiles.TryGetValue(uuid.ToString(), out profile);
}
internal IEnumerable<UserProfile> GetAllUsers()
{
2018-12-01 21:01:59 +01:00
return _profiles.Values;
}
internal IEnumerable<UserProfile> GetOpenUsers()
{
2018-12-01 21:01:59 +01:00
return _profiles.Values.Where(x => x.AccountState == OpenCloseState.Open);
}
2018-12-01 21:01:59 +01:00
internal static long GetLanguageCode(int index)
{
2018-12-01 21:01:59 +01:00
if ((uint)index >= LanguageCodes.Length)
{
2018-12-01 21:01:59 +01:00
throw new ArgumentOutOfRangeException(nameof(index));
}
2018-12-01 21:01:59 +01:00
long code = 0;
int shift = 0;
2018-12-01 21:01:59 +01:00
foreach (char chr in LanguageCodes[index])
{
2018-12-01 21:01:59 +01:00
code |= (long)(byte)chr << shift++ * 8;
}
2018-12-01 21:01:59 +01:00
return code;
}
}
}