Save Common implementation (#434)
* save common implementation * remove zero userid check * Renamed UserId to UInt128 * fix index in hex conversion
This commit is contained in:
committed by
Thomas Guillemard
parent
5b8ccb717f
commit
caa181edf2
@ -1,3 +1,4 @@
|
||||
using Ryujinx.HLE.Utilities;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@ -57,9 +58,10 @@ namespace Ryujinx.HLE.HOS.SystemState
|
||||
|
||||
Profiles = new ConcurrentDictionary<string, UserProfile>();
|
||||
|
||||
UserId DefaultUuid = new UserId("00000000000000000000000000000001");
|
||||
UInt128 DefaultUuid = new UInt128("00000000000000000000000000000001");
|
||||
|
||||
AddUser(DefaultUuid, "Player");
|
||||
|
||||
OpenUser(DefaultUuid);
|
||||
}
|
||||
|
||||
@ -85,24 +87,24 @@ namespace Ryujinx.HLE.HOS.SystemState
|
||||
ActiveAudioOutput = AudioOutputs[2];
|
||||
}
|
||||
|
||||
public void AddUser(UserId Uuid, string Name)
|
||||
public void AddUser(UInt128 Uuid, string Name)
|
||||
{
|
||||
UserProfile Profile = new UserProfile(Uuid, Name);
|
||||
|
||||
Profiles.AddOrUpdate(Uuid.UserIdHex, Profile, (Key, Old) => Profile);
|
||||
Profiles.AddOrUpdate(Uuid.ToString(), Profile, (Key, Old) => Profile);
|
||||
}
|
||||
|
||||
public void OpenUser(UserId Uuid)
|
||||
public void OpenUser(UInt128 Uuid)
|
||||
{
|
||||
if (Profiles.TryGetValue(Uuid.UserIdHex, out UserProfile Profile))
|
||||
if (Profiles.TryGetValue(Uuid.ToString(), out UserProfile Profile))
|
||||
{
|
||||
(LastOpenUser = Profile).AccountState = OpenCloseState.Open;
|
||||
}
|
||||
}
|
||||
|
||||
public void CloseUser(UserId Uuid)
|
||||
public void CloseUser(UInt128 Uuid)
|
||||
{
|
||||
if (Profiles.TryGetValue(Uuid.UserIdHex, out UserProfile Profile))
|
||||
if (Profiles.TryGetValue(Uuid.ToString(), out UserProfile Profile))
|
||||
{
|
||||
Profile.AccountState = OpenCloseState.Closed;
|
||||
}
|
||||
@ -113,9 +115,9 @@ namespace Ryujinx.HLE.HOS.SystemState
|
||||
return Profiles.Count;
|
||||
}
|
||||
|
||||
internal bool TryGetUser(UserId Uuid, out UserProfile Profile)
|
||||
internal bool TryGetUser(UInt128 Uuid, out UserProfile Profile)
|
||||
{
|
||||
return Profiles.TryGetValue(Uuid.UserIdHex, out Profile);
|
||||
return Profiles.TryGetValue(Uuid.ToString(), out Profile);
|
||||
}
|
||||
|
||||
internal IEnumerable<UserProfile> GetAllUsers()
|
||||
|
@ -1,76 +0,0 @@
|
||||
using Ryujinx.HLE.Utilities;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.SystemState
|
||||
{
|
||||
public struct UserId
|
||||
{
|
||||
public string UserIdHex { get; private set; }
|
||||
|
||||
public byte[] Bytes { get; private set; }
|
||||
|
||||
public UserId(long Low, long High)
|
||||
{
|
||||
if ((Low | High) == 0)
|
||||
{
|
||||
throw new ArgumentException("Zero is not a valid user id!");
|
||||
}
|
||||
|
||||
byte[] Bytes = new byte[16];
|
||||
|
||||
int Index = Bytes.Length;
|
||||
|
||||
void WriteBytes(long Value)
|
||||
{
|
||||
for (int Byte = 0; Byte < 8; Byte++)
|
||||
{
|
||||
Bytes[--Index] = (byte)(Value >> Byte * 8);
|
||||
}
|
||||
}
|
||||
|
||||
WriteBytes(Low);
|
||||
WriteBytes(High);
|
||||
|
||||
UserIdHex = string.Empty;
|
||||
|
||||
foreach (byte Byte in Bytes)
|
||||
{
|
||||
UserIdHex += Byte.ToString("X2");
|
||||
}
|
||||
|
||||
this.Bytes = Bytes;
|
||||
}
|
||||
|
||||
public UserId(string UserIdHex)
|
||||
{
|
||||
if (UserIdHex == null || UserIdHex.Length != 32 || !UserIdHex.All("0123456789abcdefABCDEF".Contains))
|
||||
{
|
||||
throw new ArgumentException("Invalid user id!", nameof(UserIdHex));
|
||||
}
|
||||
|
||||
if (UserIdHex == "00000000000000000000000000000000")
|
||||
{
|
||||
throw new ArgumentException("Zero is not a valid user id!", nameof(UserIdHex));
|
||||
}
|
||||
|
||||
this.UserIdHex = UserIdHex.ToUpper();
|
||||
|
||||
Bytes = StringUtils.HexToBytes(UserIdHex);
|
||||
}
|
||||
|
||||
internal void Write(BinaryWriter Writer)
|
||||
{
|
||||
for (int Index = Bytes.Length - 1; Index >= 0; Index--)
|
||||
{
|
||||
Writer.Write(Bytes[Index]);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return UserIdHex;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Ryujinx.HLE.Utilities;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.SystemState
|
||||
{
|
||||
@ -6,7 +7,7 @@ namespace Ryujinx.HLE.HOS.SystemState
|
||||
{
|
||||
private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
public UserId Uuid { get; private set; }
|
||||
public UInt128 Uuid { get; private set; }
|
||||
|
||||
public string Name { get; private set; }
|
||||
|
||||
@ -15,7 +16,7 @@ namespace Ryujinx.HLE.HOS.SystemState
|
||||
public OpenCloseState AccountState { get; set; }
|
||||
public OpenCloseState OnlinePlayState { get; set; }
|
||||
|
||||
public UserProfile(UserId Uuid, string Name)
|
||||
public UserProfile(UInt128 Uuid, string Name)
|
||||
{
|
||||
this.Uuid = Uuid;
|
||||
this.Name = Name;
|
||||
|
Reference in New Issue
Block a user