aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService
diff options
context:
space:
mode:
authorAc_K <Acoustik666@gmail.com>2021-04-13 03:16:43 +0200
committerGitHub <noreply@github.com>2021-04-13 03:16:43 +0200
commit7344dee47598a26fe72de859c311354f834ca2ed (patch)
treeedf8cf10ffda04e49b2aac4cfc69b3f5fd98d5f3 /Ryujinx.HLE/HOS/Services/Account/Acc/AccountService
parent001005b3d56d4984399b4baf8e4b7348ecdb5062 (diff)
account: Adds AccountManager (#2184)
* account: Adds Account Manager In a way to have Custom User Profiles merged in master faster, this PR adds a `AccountManager` class (based on `AccountUtils` class) and the following changes have been made: - Adds a "default profile values" which were the old hardcoded ones. - The image profile is moved to the Account service folder. - The hardcoded UserId for the savedata is now using the `AccountManager` last opened one. - The DeviceId in Mii service is changed to the right value (checked by REd sys:set call). * Fix csproj * Addresses gdkchan's comments * Fix UserProfile fields * Fix mii GetDeviceId() * Update Ryujinx.HLE.csproj
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Account/Acc/AccountService')
-rw-r--r--Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/AccountUtils.cs66
-rw-r--r--Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs29
2 files changed, 13 insertions, 82 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/AccountUtils.cs b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/AccountUtils.cs
deleted file mode 100644
index 8b7f1e54..00000000
--- a/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/AccountUtils.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Ryujinx.HLE.HOS.Services.Account.Acc
-{
- public class AccountUtils
- {
- private ConcurrentDictionary<string, UserProfile> _profiles;
-
- internal UserProfile LastOpenedUser { get; private set; }
-
- public AccountUtils()
- {
- _profiles = new ConcurrentDictionary<string, UserProfile>();
- }
-
- public void AddUser(UserId userId, string name)
- {
- UserProfile profile = new UserProfile(userId, name);
-
- _profiles.AddOrUpdate(userId.ToString(), profile, (key, old) => profile);
- }
-
- public void OpenUser(UserId userId)
- {
- if (_profiles.TryGetValue(userId.ToString(), out UserProfile profile))
- {
- (LastOpenedUser = profile).AccountState = AccountState.Open;
- }
- }
-
- public void CloseUser(UserId userId)
- {
- if (_profiles.TryGetValue(userId.ToString(), out UserProfile profile))
- {
- profile.AccountState = AccountState.Closed;
- }
- }
-
- public int GetUserCount()
- {
- return _profiles.Count;
- }
-
- internal bool TryGetUser(UserId userId, out UserProfile profile)
- {
- return _profiles.TryGetValue(userId.ToString(), out profile);
- }
-
- internal IEnumerable<UserProfile> GetAllUsers()
- {
- return _profiles.Values;
- }
-
- internal IEnumerable<UserProfile> GetOpenedUsers()
- {
- return _profiles.Values.Where(x => x.AccountState == AccountState.Open);
- }
-
- internal UserProfile GetFirst()
- {
- return _profiles.First().Value;
- }
- }
-} \ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs
index c6e0508f..18534393 100644
--- a/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs
+++ b/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs
@@ -1,8 +1,6 @@
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.Utilities;
-using System.IO;
-using System.Reflection;
using System.Text;
namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
@@ -10,12 +8,10 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
class ProfileServer
{
private UserProfile _profile;
- private Stream _profilePictureStream;
public ProfileServer(UserProfile profile)
{
- _profile = profile;
- _profilePictureStream = Assembly.GetCallingAssembly().GetManifestResourceStream("Ryujinx.HLE.RyujinxProfileImage.jpg");
+ _profile = profile;
}
public ResultCode Get(ServiceCtx context)
@@ -54,7 +50,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
public ResultCode GetImageSize(ServiceCtx context)
{
- context.ResponseData.Write(_profilePictureStream.Length);
+ context.ResponseData.Write(_profile.Image.Length);
return ResultCode.Success;
}
@@ -64,13 +60,14 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
long bufferPosition = context.Request.ReceiveBuff[0].Position;
long bufferLen = context.Request.ReceiveBuff[0].Size;
- byte[] profilePictureData = new byte[bufferLen];
+ if (_profile.Image.Length > bufferLen)
+ {
+ return ResultCode.InvalidBufferSize;
+ }
- _profilePictureStream.Read(profilePictureData, 0, profilePictureData.Length);
+ context.Memory.Write((ulong)bufferPosition, _profile.Image);
- context.Memory.Write((ulong)bufferPosition, profilePictureData);
-
- context.ResponseData.Write(_profilePictureStream.Length);
+ context.ResponseData.Write(_profile.Image.Length);
return ResultCode.Success;
}
@@ -100,16 +97,16 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
context.Memory.Read((ulong)userDataPosition, userData);
- long profilePicturePosition = context.Request.SendBuff[0].Position;
- long profilePictureSize = context.Request.SendBuff[0].Size;
+ long profileImagePosition = context.Request.SendBuff[0].Position;
+ long profileImageSize = context.Request.SendBuff[0].Size;
- byte[] profilePictureData = new byte[profilePictureSize];
+ byte[] profileImageData = new byte[profileImageSize];
- context.Memory.Read((ulong)profilePicturePosition, profilePictureData);
+ context.Memory.Read((ulong)profileImagePosition, profileImageData);
// TODO: Read the nn::account::profile::ProfileBase and store everything in the savedata.
- Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { userDataSize, profilePictureSize });
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { userDataSize, profileImageSize });
return ResultCode.Success;
}