diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/service/acc/acc.cpp | 54 | ||||
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.cpp | 147 | ||||
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.h | 21 | ||||
| -rw-r--r-- | src/core/hle/service/am/am.cpp | 33 | ||||
| -rw-r--r-- | src/core/settings.h | 2 | ||||
| -rw-r--r-- | src/yuzu/configuration/config.cpp | 9 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_system.cpp | 260 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_system.h | 33 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_system.ui | 252 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 40 | ||||
| -rw-r--r-- | src/yuzu_cmd/config.cpp | 9 |
11 files changed, 742 insertions, 118 deletions
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index e61748ca3..cf065c2e0 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -2,9 +2,13 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include <array> | 6 | #include <array> |
| 7 | #include "common/common_paths.h" | ||
| 6 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | #include "common/file_util.h" | ||
| 7 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 11 | #include "common/string_util.h" | ||
| 8 | #include "common/swap.h" | 12 | #include "common/swap.h" |
| 9 | #include "core/core_timing.h" | 13 | #include "core/core_timing.h" |
| 10 | #include "core/hle/ipc_helpers.h" | 14 | #include "core/hle/ipc_helpers.h" |
| @@ -16,6 +20,9 @@ | |||
| 16 | #include "core/hle/service/acc/profile_manager.h" | 20 | #include "core/hle/service/acc/profile_manager.h" |
| 17 | 21 | ||
| 18 | namespace Service::Account { | 22 | namespace Service::Account { |
| 23 | |||
| 24 | constexpr u32 MAX_JPEG_IMAGE_SIZE = 0x20000; | ||
| 25 | |||
| 19 | // TODO: RE this structure | 26 | // TODO: RE this structure |
| 20 | struct UserData { | 27 | struct UserData { |
| 21 | INSERT_PADDING_WORDS(1); | 28 | INSERT_PADDING_WORDS(1); |
| @@ -27,6 +34,11 @@ struct UserData { | |||
| 27 | }; | 34 | }; |
| 28 | static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); | 35 | static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); |
| 29 | 36 | ||
| 37 | static std::string GetImagePath(UUID uuid) { | ||
| 38 | return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + | ||
| 39 | "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; | ||
| 40 | } | ||
| 41 | |||
| 30 | class IProfile final : public ServiceFramework<IProfile> { | 42 | class IProfile final : public ServiceFramework<IProfile> { |
| 31 | public: | 43 | public: |
| 32 | explicit IProfile(UUID user_id, ProfileManager& profile_manager) | 44 | explicit IProfile(UUID user_id, ProfileManager& profile_manager) |
| @@ -73,11 +85,11 @@ private: | |||
| 73 | } | 85 | } |
| 74 | 86 | ||
| 75 | void LoadImage(Kernel::HLERequestContext& ctx) { | 87 | void LoadImage(Kernel::HLERequestContext& ctx) { |
| 76 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 88 | LOG_DEBUG(Service_ACC, "called"); |
| 77 | // smallest jpeg https://github.com/mathiasbynens/small/blob/master/jpeg.jpg | 89 | // smallest jpeg https://github.com/mathiasbynens/small/blob/master/jpeg.jpg |
| 78 | // TODO(mailwl): load actual profile image from disk, width 256px, max size 0x20000 | 90 | // used as a backup should the one on disk not exist |
| 79 | constexpr u32 jpeg_size = 107; | 91 | constexpr u32 backup_jpeg_size = 107; |
| 80 | static constexpr std::array<u8, jpeg_size> jpeg{ | 92 | static constexpr std::array<u8, backup_jpeg_size> backup_jpeg{ |
| 81 | 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, | 93 | 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, |
| 82 | 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, | 94 | 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, |
| 83 | 0x08, 0x06, 0x06, 0x05, 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, | 95 | 0x08, 0x06, 0x06, 0x05, 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, |
| @@ -87,18 +99,42 @@ private: | |||
| 87 | 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, 0x01, 0x01, | 99 | 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, 0x01, 0x01, |
| 88 | 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, | 100 | 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, |
| 89 | }; | 101 | }; |
| 90 | ctx.WriteBuffer(jpeg); | 102 | |
| 91 | IPC::ResponseBuilder rb{ctx, 3}; | 103 | IPC::ResponseBuilder rb{ctx, 3}; |
| 92 | rb.Push(RESULT_SUCCESS); | 104 | rb.Push(RESULT_SUCCESS); |
| 93 | rb.Push<u32>(jpeg_size); | 105 | |
| 106 | const FileUtil::IOFile image(GetImagePath(user_id), "rb"); | ||
| 107 | |||
| 108 | if (!image.IsOpen()) { | ||
| 109 | LOG_WARNING(Service_ACC, | ||
| 110 | "Failed to load user provided image! Falling back to built-in backup..."); | ||
| 111 | ctx.WriteBuffer(backup_jpeg); | ||
| 112 | rb.Push<u32>(backup_jpeg_size); | ||
| 113 | } else { | ||
| 114 | const auto size = std::min<u32>(image.GetSize(), MAX_JPEG_IMAGE_SIZE); | ||
| 115 | std::vector<u8> buffer(size); | ||
| 116 | image.ReadBytes(buffer.data(), buffer.size()); | ||
| 117 | |||
| 118 | ctx.WriteBuffer(buffer.data(), buffer.size()); | ||
| 119 | rb.Push<u32>(buffer.size()); | ||
| 120 | } | ||
| 94 | } | 121 | } |
| 95 | 122 | ||
| 96 | void GetImageSize(Kernel::HLERequestContext& ctx) { | 123 | void GetImageSize(Kernel::HLERequestContext& ctx) { |
| 97 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 124 | LOG_DEBUG(Service_ACC, "called"); |
| 98 | constexpr u32 jpeg_size = 107; | 125 | constexpr u32 backup_jpeg_size = 107; |
| 99 | IPC::ResponseBuilder rb{ctx, 3}; | 126 | IPC::ResponseBuilder rb{ctx, 3}; |
| 100 | rb.Push(RESULT_SUCCESS); | 127 | rb.Push(RESULT_SUCCESS); |
| 101 | rb.Push<u32>(jpeg_size); | 128 | |
| 129 | const FileUtil::IOFile image(GetImagePath(user_id), "rb"); | ||
| 130 | |||
| 131 | if (!image.IsOpen()) { | ||
| 132 | LOG_WARNING(Service_ACC, | ||
| 133 | "Failed to load user provided image! Falling back to built-in backup..."); | ||
| 134 | rb.Push<u32>(backup_jpeg_size); | ||
| 135 | } else { | ||
| 136 | rb.Push<u32>(std::min<u32>(image.GetSize(), MAX_JPEG_IMAGE_SIZE)); | ||
| 137 | } | ||
| 102 | } | 138 | } |
| 103 | 139 | ||
| 104 | const ProfileManager& profile_manager; | 140 | const ProfileManager& profile_manager; |
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index bcb3475db..06f7d1b15 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp | |||
| @@ -4,32 +4,57 @@ | |||
| 4 | 4 | ||
| 5 | #include <random> | 5 | #include <random> |
| 6 | #include <boost/optional.hpp> | 6 | #include <boost/optional.hpp> |
| 7 | #include "common/file_util.h" | ||
| 7 | #include "core/hle/service/acc/profile_manager.h" | 8 | #include "core/hle/service/acc/profile_manager.h" |
| 8 | #include "core/settings.h" | 9 | #include "core/settings.h" |
| 9 | 10 | ||
| 10 | namespace Service::Account { | 11 | namespace Service::Account { |
| 12 | |||
| 13 | struct UserRaw { | ||
| 14 | UUID uuid; | ||
| 15 | UUID uuid2; | ||
| 16 | u64 timestamp; | ||
| 17 | ProfileUsername username; | ||
| 18 | INSERT_PADDING_BYTES(0x80); | ||
| 19 | }; | ||
| 20 | static_assert(sizeof(UserRaw) == 0xC8, "UserRaw has incorrect size."); | ||
| 21 | |||
| 22 | struct ProfileDataRaw { | ||
| 23 | INSERT_PADDING_BYTES(0x10); | ||
| 24 | std::array<UserRaw, MAX_USERS> users; | ||
| 25 | }; | ||
| 26 | static_assert(sizeof(ProfileDataRaw) == 0x650, "ProfileDataRaw has incorrect size."); | ||
| 27 | |||
| 11 | // TODO(ogniK): Get actual error codes | 28 | // TODO(ogniK): Get actual error codes |
| 12 | constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, -1); | 29 | constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, -1); |
| 13 | constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2); | 30 | constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2); |
| 14 | constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); | 31 | constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); |
| 15 | 32 | ||
| 16 | const UUID& UUID::Generate() { | 33 | constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/avators/"; |
| 34 | |||
| 35 | UUID UUID::Generate() { | ||
| 17 | std::random_device device; | 36 | std::random_device device; |
| 18 | std::mt19937 gen(device()); | 37 | std::mt19937 gen(device()); |
| 19 | std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max()); | 38 | std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max()); |
| 20 | uuid[0] = distribution(gen); | 39 | return UUID{distribution(gen), distribution(gen)}; |
| 21 | uuid[1] = distribution(gen); | ||
| 22 | return *this; | ||
| 23 | } | 40 | } |
| 24 | 41 | ||
| 25 | ProfileManager::ProfileManager() { | 42 | ProfileManager::ProfileManager() { |
| 26 | // TODO(ogniK): Create the default user we have for now until loading/saving users is added | 43 | ParseUserSaveFile(); |
| 27 | auto user_uuid = UUID{1, 0}; | 44 | |
| 28 | ASSERT(CreateNewUser(user_uuid, Settings::values.username).IsSuccess()); | 45 | if (user_count == 0) |
| 29 | OpenUser(user_uuid); | 46 | CreateNewUser(UUID::Generate(), "yuzu"); |
| 47 | |||
| 48 | auto current = std::clamp<int>(Settings::values.current_user, 0, MAX_USERS - 1); | ||
| 49 | if (UserExistsIndex(current)) | ||
| 50 | current = 0; | ||
| 51 | |||
| 52 | OpenUser(*GetUser(current)); | ||
| 30 | } | 53 | } |
| 31 | 54 | ||
| 32 | ProfileManager::~ProfileManager() = default; | 55 | ProfileManager::~ProfileManager() { |
| 56 | WriteUserSaveFile(); | ||
| 57 | } | ||
| 33 | 58 | ||
| 34 | /// After a users creation it needs to be "registered" to the system. AddToProfiles handles the | 59 | /// After a users creation it needs to be "registered" to the system. AddToProfiles handles the |
| 35 | /// internal management of the users profiles | 60 | /// internal management of the users profiles |
| @@ -101,6 +126,12 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) | |||
| 101 | return CreateNewUser(uuid, username_output); | 126 | return CreateNewUser(uuid, username_output); |
| 102 | } | 127 | } |
| 103 | 128 | ||
| 129 | boost::optional<UUID> ProfileManager::GetUser(std::size_t index) const { | ||
| 130 | if (index >= MAX_USERS) | ||
| 131 | return boost::none; | ||
| 132 | return profiles[index].user_uuid; | ||
| 133 | } | ||
| 134 | |||
| 104 | /// Returns a users profile index based on their user id. | 135 | /// Returns a users profile index based on their user id. |
| 105 | boost::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { | 136 | boost::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { |
| 106 | if (!uuid) { | 137 | if (!uuid) { |
| @@ -164,6 +195,12 @@ bool ProfileManager::UserExists(UUID uuid) const { | |||
| 164 | return (GetUserIndex(uuid) != boost::none); | 195 | return (GetUserIndex(uuid) != boost::none); |
| 165 | } | 196 | } |
| 166 | 197 | ||
| 198 | bool ProfileManager::UserExistsIndex(std::size_t index) const { | ||
| 199 | if (index >= MAX_USERS) | ||
| 200 | return false; | ||
| 201 | return profiles[index].user_uuid.uuid != INVALID_UUID; | ||
| 202 | } | ||
| 203 | |||
| 167 | /// Opens a specific user | 204 | /// Opens a specific user |
| 168 | void ProfileManager::OpenUser(UUID uuid) { | 205 | void ProfileManager::OpenUser(UUID uuid) { |
| 169 | auto idx = GetUserIndex(uuid); | 206 | auto idx = GetUserIndex(uuid); |
| @@ -239,4 +276,96 @@ bool ProfileManager::CanSystemRegisterUser() const { | |||
| 239 | // emulate qlaunch. Update this to dynamically change. | 276 | // emulate qlaunch. Update this to dynamically change. |
| 240 | } | 277 | } |
| 241 | 278 | ||
| 279 | bool ProfileManager::RemoveUser(UUID uuid) { | ||
| 280 | auto index = GetUserIndex(uuid); | ||
| 281 | if (index == boost::none) { | ||
| 282 | return false; | ||
| 283 | } | ||
| 284 | |||
| 285 | profiles[*index] = ProfileInfo{}; | ||
| 286 | std::stable_partition(profiles.begin(), profiles.end(), | ||
| 287 | [](const ProfileInfo& profile) { return profile.user_uuid; }); | ||
| 288 | return true; | ||
| 289 | } | ||
| 290 | |||
| 291 | bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) { | ||
| 292 | auto index = GetUserIndex(uuid); | ||
| 293 | if (profile_new.user_uuid == UUID(INVALID_UUID) || index == boost::none) { | ||
| 294 | return false; | ||
| 295 | } | ||
| 296 | |||
| 297 | auto& profile = profiles[*index]; | ||
| 298 | profile.user_uuid = profile_new.user_uuid; | ||
| 299 | profile.username = profile_new.username; | ||
| 300 | profile.creation_time = profile_new.timestamp; | ||
| 301 | |||
| 302 | return true; | ||
| 303 | } | ||
| 304 | |||
| 305 | void ProfileManager::ParseUserSaveFile() { | ||
| 306 | FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + | ||
| 307 | ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat", | ||
| 308 | "rb"); | ||
| 309 | |||
| 310 | if (!save.IsOpen()) { | ||
| 311 | LOG_WARNING(Service_ACC, "Failed to load profile data from save data... Generating new " | ||
| 312 | "user 'yuzu' with random UUID."); | ||
| 313 | return; | ||
| 314 | } | ||
| 315 | |||
| 316 | ProfileDataRaw data; | ||
| 317 | if (save.ReadBytes(&data, sizeof(ProfileDataRaw)) != sizeof(ProfileDataRaw)) { | ||
| 318 | LOG_WARNING(Service_ACC, "profiles.dat is smaller than expected... Generating new user " | ||
| 319 | "'yuzu' with random UUID."); | ||
| 320 | return; | ||
| 321 | } | ||
| 322 | |||
| 323 | for (std::size_t i = 0; i < MAX_USERS; ++i) { | ||
| 324 | const auto& user = data.users[i]; | ||
| 325 | |||
| 326 | if (user.uuid != UUID(INVALID_UUID)) | ||
| 327 | AddUser({user.uuid, user.username, user.timestamp, {}, false}); | ||
| 328 | } | ||
| 329 | |||
| 330 | std::stable_partition(profiles.begin(), profiles.end(), | ||
| 331 | [](const ProfileInfo& profile) { return profile.user_uuid; }); | ||
| 332 | } | ||
| 333 | |||
| 334 | void ProfileManager::WriteUserSaveFile() { | ||
| 335 | ProfileDataRaw raw{}; | ||
| 336 | |||
| 337 | for (std::size_t i = 0; i < MAX_USERS; ++i) { | ||
| 338 | raw.users[i].username = profiles[i].username; | ||
| 339 | raw.users[i].uuid2 = profiles[i].user_uuid; | ||
| 340 | raw.users[i].uuid = profiles[i].user_uuid; | ||
| 341 | raw.users[i].timestamp = profiles[i].creation_time; | ||
| 342 | } | ||
| 343 | |||
| 344 | const auto raw_path = | ||
| 345 | FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010"; | ||
| 346 | if (FileUtil::Exists(raw_path) && !FileUtil::IsDirectory(raw_path)) | ||
| 347 | FileUtil::Delete(raw_path); | ||
| 348 | |||
| 349 | const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + | ||
| 350 | ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat"; | ||
| 351 | |||
| 352 | if (!FileUtil::CreateFullPath(path)) { | ||
| 353 | LOG_WARNING(Service_ACC, "Failed to create full path of profiles.dat. Create the directory " | ||
| 354 | "nand/system/save/8000000000000010/su/avators to mitigate this " | ||
| 355 | "issue."); | ||
| 356 | return; | ||
| 357 | } | ||
| 358 | |||
| 359 | FileUtil::IOFile save(path, "wb"); | ||
| 360 | |||
| 361 | if (!save.IsOpen()) { | ||
| 362 | LOG_WARNING(Service_ACC, "Failed to write save data to file... No changes to user data " | ||
| 363 | "made in current session will be saved."); | ||
| 364 | return; | ||
| 365 | } | ||
| 366 | |||
| 367 | save.Resize(sizeof(ProfileDataRaw)); | ||
| 368 | save.WriteBytes(&raw, sizeof(ProfileDataRaw)); | ||
| 369 | } | ||
| 370 | |||
| 242 | }; // namespace Service::Account | 371 | }; // namespace Service::Account |
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h index bffd4cf4d..235208d56 100644 --- a/src/core/hle/service/acc/profile_manager.h +++ b/src/core/hle/service/acc/profile_manager.h | |||
| @@ -36,7 +36,7 @@ struct UUID { | |||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | // TODO(ogniK): Properly generate uuids based on RFC-4122 | 38 | // TODO(ogniK): Properly generate uuids based on RFC-4122 |
| 39 | const UUID& Generate(); | 39 | static UUID Generate(); |
| 40 | 40 | ||
| 41 | // Set the UUID to {0,0} to be considered an invalid user | 41 | // Set the UUID to {0,0} to be considered an invalid user |
| 42 | void Invalidate() { | 42 | void Invalidate() { |
| @@ -45,6 +45,15 @@ struct UUID { | |||
| 45 | std::string Format() const { | 45 | std::string Format() const { |
| 46 | return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]); | 46 | return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]); |
| 47 | } | 47 | } |
| 48 | |||
| 49 | std::string FormatSwitch() const { | ||
| 50 | std::array<u8, 16> s{}; | ||
| 51 | std::memcpy(s.data(), uuid.data(), sizeof(u128)); | ||
| 52 | return fmt::format("{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{" | ||
| 53 | ":02x}{:02x}{:02x}{:02x}{:02x}", | ||
| 54 | s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], | ||
| 55 | s[12], s[13], s[14], s[15]); | ||
| 56 | } | ||
| 48 | }; | 57 | }; |
| 49 | static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); | 58 | static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); |
| 50 | 59 | ||
| @@ -81,12 +90,13 @@ static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase is an invalid size"); | |||
| 81 | /// objects | 90 | /// objects |
| 82 | class ProfileManager { | 91 | class ProfileManager { |
| 83 | public: | 92 | public: |
| 84 | ProfileManager(); // TODO(ogniK): Load from system save | 93 | ProfileManager(); |
| 85 | ~ProfileManager(); | 94 | ~ProfileManager(); |
| 86 | 95 | ||
| 87 | ResultCode AddUser(const ProfileInfo& user); | 96 | ResultCode AddUser(const ProfileInfo& user); |
| 88 | ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username); | 97 | ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username); |
| 89 | ResultCode CreateNewUser(UUID uuid, const std::string& username); | 98 | ResultCode CreateNewUser(UUID uuid, const std::string& username); |
| 99 | boost::optional<UUID> GetUser(std::size_t index) const; | ||
| 90 | boost::optional<std::size_t> GetUserIndex(const UUID& uuid) const; | 100 | boost::optional<std::size_t> GetUserIndex(const UUID& uuid) const; |
| 91 | boost::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const; | 101 | boost::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const; |
| 92 | bool GetProfileBase(boost::optional<std::size_t> index, ProfileBase& profile) const; | 102 | bool GetProfileBase(boost::optional<std::size_t> index, ProfileBase& profile) const; |
| @@ -100,6 +110,7 @@ public: | |||
| 100 | std::size_t GetUserCount() const; | 110 | std::size_t GetUserCount() const; |
| 101 | std::size_t GetOpenUserCount() const; | 111 | std::size_t GetOpenUserCount() const; |
| 102 | bool UserExists(UUID uuid) const; | 112 | bool UserExists(UUID uuid) const; |
| 113 | bool UserExistsIndex(std::size_t index) const; | ||
| 103 | void OpenUser(UUID uuid); | 114 | void OpenUser(UUID uuid); |
| 104 | void CloseUser(UUID uuid); | 115 | void CloseUser(UUID uuid); |
| 105 | UserIDArray GetOpenUsers() const; | 116 | UserIDArray GetOpenUsers() const; |
| @@ -108,7 +119,13 @@ public: | |||
| 108 | 119 | ||
| 109 | bool CanSystemRegisterUser() const; | 120 | bool CanSystemRegisterUser() const; |
| 110 | 121 | ||
| 122 | bool RemoveUser(UUID uuid); | ||
| 123 | bool SetProfileBase(UUID uuid, const ProfileBase& profile); | ||
| 124 | |||
| 111 | private: | 125 | private: |
| 126 | void ParseUserSaveFile(); | ||
| 127 | void WriteUserSaveFile(); | ||
| 128 | |||
| 112 | std::array<ProfileInfo, MAX_USERS> profiles{}; | 129 | std::array<ProfileInfo, MAX_USERS> profiles{}; |
| 113 | std::size_t user_count = 0; | 130 | std::size_t user_count = 0; |
| 114 | boost::optional<std::size_t> AddToProfiles(const ProfileInfo& profile); | 131 | boost::optional<std::size_t> AddToProfiles(const ProfileInfo& profile); |
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index ecf72ae24..4ed66d817 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp | |||
| @@ -4,11 +4,13 @@ | |||
| 4 | 4 | ||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include <cinttypes> | 6 | #include <cinttypes> |
| 7 | #include <cstring> | ||
| 7 | #include <stack> | 8 | #include <stack> |
| 8 | #include "core/core.h" | 9 | #include "core/core.h" |
| 9 | #include "core/hle/ipc_helpers.h" | 10 | #include "core/hle/ipc_helpers.h" |
| 10 | #include "core/hle/kernel/event.h" | 11 | #include "core/hle/kernel/event.h" |
| 11 | #include "core/hle/kernel/process.h" | 12 | #include "core/hle/kernel/process.h" |
| 13 | #include "core/hle/service/acc/profile_manager.h" | ||
| 12 | #include "core/hle/service/am/am.h" | 14 | #include "core/hle/service/am/am.h" |
| 13 | #include "core/hle/service/am/applet_ae.h" | 15 | #include "core/hle/service/am/applet_ae.h" |
| 14 | #include "core/hle/service/am/applet_oe.h" | 16 | #include "core/hle/service/am/applet_oe.h" |
| @@ -26,6 +28,16 @@ | |||
| 26 | 28 | ||
| 27 | namespace Service::AM { | 29 | namespace Service::AM { |
| 28 | 30 | ||
| 31 | constexpr u32 POP_LAUNCH_PARAMETER_MAGIC = 0xC79497CA; | ||
| 32 | |||
| 33 | struct LaunchParameters { | ||
| 34 | u32_le magic; | ||
| 35 | u32_le is_account_selected; | ||
| 36 | u128 current_user; | ||
| 37 | INSERT_PADDING_BYTES(0x70); | ||
| 38 | }; | ||
| 39 | static_assert(sizeof(LaunchParameters) == 0x88); | ||
| 40 | |||
| 29 | IWindowController::IWindowController() : ServiceFramework("IWindowController") { | 41 | IWindowController::IWindowController() : ServiceFramework("IWindowController") { |
| 30 | // clang-format off | 42 | // clang-format off |
| 31 | static const FunctionInfo functions[] = { | 43 | static const FunctionInfo functions[] = { |
| @@ -724,20 +736,23 @@ void IApplicationFunctions::EndBlockingHomeButton(Kernel::HLERequestContext& ctx | |||
| 724 | } | 736 | } |
| 725 | 737 | ||
| 726 | void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) { | 738 | void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) { |
| 727 | constexpr std::array<u8, 0x88> data{{ | 739 | LaunchParameters params{}; |
| 728 | 0xca, 0x97, 0x94, 0xc7, // Magic | ||
| 729 | 1, 0, 0, 0, // IsAccountSelected (bool) | ||
| 730 | 1, 0, 0, 0, // User Id (word 0) | ||
| 731 | 0, 0, 0, 0, // User Id (word 1) | ||
| 732 | 0, 0, 0, 0, // User Id (word 2) | ||
| 733 | 0, 0, 0, 0 // User Id (word 3) | ||
| 734 | }}; | ||
| 735 | 740 | ||
| 736 | std::vector<u8> buffer(data.begin(), data.end()); | 741 | params.magic = POP_LAUNCH_PARAMETER_MAGIC; |
| 742 | params.is_account_selected = 1; | ||
| 743 | |||
| 744 | Account::ProfileManager profile_manager{}; | ||
| 745 | const auto uuid = profile_manager.GetUser(Settings::values.current_user); | ||
| 746 | ASSERT(uuid != boost::none); | ||
| 747 | params.current_user = uuid->uuid; | ||
| 737 | 748 | ||
| 738 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 749 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 739 | 750 | ||
| 740 | rb.Push(RESULT_SUCCESS); | 751 | rb.Push(RESULT_SUCCESS); |
| 752 | |||
| 753 | std::vector<u8> buffer(sizeof(LaunchParameters)); | ||
| 754 | std::memcpy(buffer.data(), ¶ms, buffer.size()); | ||
| 755 | |||
| 741 | rb.PushIpcInterface<AM::IStorage>(buffer); | 756 | rb.PushIpcInterface<AM::IStorage>(buffer); |
| 742 | 757 | ||
| 743 | LOG_DEBUG(Service_AM, "called"); | 758 | LOG_DEBUG(Service_AM, "called"); |
diff --git a/src/core/settings.h b/src/core/settings.h index ca80718e2..b5aeff29b 100644 --- a/src/core/settings.h +++ b/src/core/settings.h | |||
| @@ -114,7 +114,7 @@ struct Values { | |||
| 114 | // System | 114 | // System |
| 115 | bool use_docked_mode; | 115 | bool use_docked_mode; |
| 116 | bool enable_nfc; | 116 | bool enable_nfc; |
| 117 | std::string username; | 117 | int current_user; |
| 118 | int language_index; | 118 | int language_index; |
| 119 | 119 | ||
| 120 | // Controls | 120 | // Controls |
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index d029590ff..1fe9a7edd 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include <QSettings> | 5 | #include <QSettings> |
| 6 | #include "common/file_util.h" | 6 | #include "common/file_util.h" |
| 7 | #include "core/hle/service/acc/profile_manager.h" | ||
| 7 | #include "input_common/main.h" | 8 | #include "input_common/main.h" |
| 8 | #include "yuzu/configuration/config.h" | 9 | #include "yuzu/configuration/config.h" |
| 9 | #include "yuzu/ui_settings.h" | 10 | #include "yuzu/ui_settings.h" |
| @@ -123,7 +124,10 @@ void Config::ReadValues() { | |||
| 123 | qt_config->beginGroup("System"); | 124 | qt_config->beginGroup("System"); |
| 124 | Settings::values.use_docked_mode = qt_config->value("use_docked_mode", false).toBool(); | 125 | Settings::values.use_docked_mode = qt_config->value("use_docked_mode", false).toBool(); |
| 125 | Settings::values.enable_nfc = qt_config->value("enable_nfc", true).toBool(); | 126 | Settings::values.enable_nfc = qt_config->value("enable_nfc", true).toBool(); |
| 126 | Settings::values.username = qt_config->value("username", "yuzu").toString().toStdString(); | 127 | |
| 128 | Settings::values.current_user = std::clamp<int>(qt_config->value("current_user", 0).toInt(), 0, | ||
| 129 | Service::Account::MAX_USERS - 1); | ||
| 130 | |||
| 127 | Settings::values.language_index = qt_config->value("language_index", 1).toInt(); | 131 | Settings::values.language_index = qt_config->value("language_index", 1).toInt(); |
| 128 | qt_config->endGroup(); | 132 | qt_config->endGroup(); |
| 129 | 133 | ||
| @@ -260,7 +264,8 @@ void Config::SaveValues() { | |||
| 260 | qt_config->beginGroup("System"); | 264 | qt_config->beginGroup("System"); |
| 261 | qt_config->setValue("use_docked_mode", Settings::values.use_docked_mode); | 265 | qt_config->setValue("use_docked_mode", Settings::values.use_docked_mode); |
| 262 | qt_config->setValue("enable_nfc", Settings::values.enable_nfc); | 266 | qt_config->setValue("enable_nfc", Settings::values.enable_nfc); |
| 263 | qt_config->setValue("username", QString::fromStdString(Settings::values.username)); | 267 | qt_config->setValue("current_user", Settings::values.current_user); |
| 268 | |||
| 264 | qt_config->setValue("language_index", Settings::values.language_index); | 269 | qt_config->setValue("language_index", Settings::values.language_index); |
| 265 | qt_config->endGroup(); | 270 | qt_config->endGroup(); |
| 266 | 271 | ||
diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index e9ed9c38f..83cc49dfc 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp | |||
| @@ -2,13 +2,30 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 6 | #include <QFileDialog> | ||
| 7 | #include <QGraphicsItem> | ||
| 8 | #include <QGraphicsScene> | ||
| 9 | #include <QInputDialog> | ||
| 5 | #include <QMessageBox> | 10 | #include <QMessageBox> |
| 11 | #include <QStandardItemModel> | ||
| 12 | #include <QTreeView> | ||
| 13 | #include <QVBoxLayout> | ||
| 14 | #include "common/common_paths.h" | ||
| 15 | #include "common/logging/backend.h" | ||
| 16 | #include "common/string_util.h" | ||
| 6 | #include "core/core.h" | 17 | #include "core/core.h" |
| 18 | #include "core/hle/service/acc/profile_manager.h" | ||
| 7 | #include "core/settings.h" | 19 | #include "core/settings.h" |
| 8 | #include "ui_configure_system.h" | 20 | #include "ui_configure_system.h" |
| 9 | #include "yuzu/configuration/configure_system.h" | 21 | #include "yuzu/configuration/configure_system.h" |
| 10 | #include "yuzu/main.h" | 22 | #include "yuzu/main.h" |
| 11 | 23 | ||
| 24 | static std::string GetImagePath(Service::Account::UUID uuid) { | ||
| 25 | return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + | ||
| 26 | "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; | ||
| 27 | } | ||
| 28 | |||
| 12 | static const std::array<int, 12> days_in_month = {{ | 29 | static const std::array<int, 12> days_in_month = {{ |
| 13 | 31, | 30 | 31, |
| 14 | 29, | 31 | 29, |
| @@ -24,7 +41,20 @@ static const std::array<int, 12> days_in_month = {{ | |||
| 24 | 31, | 41 | 31, |
| 25 | }}; | 42 | }}; |
| 26 | 43 | ||
| 27 | ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) { | 44 | // Same backup JPEG used by acc IProfile::GetImage if no jpeg found |
| 45 | static constexpr std::array<u8, 107> backup_jpeg{ | ||
| 46 | 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, | ||
| 47 | 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05, | ||
| 48 | 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e, | ||
| 49 | 0x0b, 0x09, 0x09, 0x0d, 0x11, 0x0d, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x10, 0x0a, 0x0c, 0x12, 0x13, | ||
| 50 | 0x12, 0x10, 0x13, 0x0f, 0x10, 0x10, 0x10, 0xff, 0xc9, 0x00, 0x0b, 0x08, 0x00, 0x01, 0x00, 0x01, | ||
| 51 | 0x01, 0x01, 0x11, 0x00, 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, | ||
| 52 | 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, | ||
| 53 | }; | ||
| 54 | |||
| 55 | ConfigureSystem::ConfigureSystem(QWidget* parent) | ||
| 56 | : QWidget(parent), ui(new Ui::ConfigureSystem), | ||
| 57 | profile_manager(std::make_unique<Service::Account::ProfileManager>()) { | ||
| 28 | ui->setupUi(this); | 58 | ui->setupUi(this); |
| 29 | connect(ui->combo_birthmonth, | 59 | connect(ui->combo_birthmonth, |
| 30 | static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, | 60 | static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, |
| @@ -32,6 +62,45 @@ ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui:: | |||
| 32 | connect(ui->button_regenerate_console_id, &QPushButton::clicked, this, | 62 | connect(ui->button_regenerate_console_id, &QPushButton::clicked, this, |
| 33 | &ConfigureSystem::refreshConsoleID); | 63 | &ConfigureSystem::refreshConsoleID); |
| 34 | 64 | ||
| 65 | layout = new QVBoxLayout; | ||
| 66 | tree_view = new QTreeView; | ||
| 67 | item_model = new QStandardItemModel(tree_view); | ||
| 68 | tree_view->setModel(item_model); | ||
| 69 | |||
| 70 | tree_view->setAlternatingRowColors(true); | ||
| 71 | tree_view->setSelectionMode(QHeaderView::SingleSelection); | ||
| 72 | tree_view->setSelectionBehavior(QHeaderView::SelectRows); | ||
| 73 | tree_view->setVerticalScrollMode(QHeaderView::ScrollPerPixel); | ||
| 74 | tree_view->setHorizontalScrollMode(QHeaderView::ScrollPerPixel); | ||
| 75 | tree_view->setSortingEnabled(true); | ||
| 76 | tree_view->setEditTriggers(QHeaderView::NoEditTriggers); | ||
| 77 | tree_view->setUniformRowHeights(true); | ||
| 78 | tree_view->setIconSize({64, 64}); | ||
| 79 | tree_view->setContextMenuPolicy(Qt::NoContextMenu); | ||
| 80 | |||
| 81 | item_model->insertColumns(0, 1); | ||
| 82 | item_model->setHeaderData(0, Qt::Horizontal, "Users"); | ||
| 83 | |||
| 84 | // We must register all custom types with the Qt Automoc system so that we are able to use it | ||
| 85 | // with signals/slots. In this case, QList falls under the umbrells of custom types. | ||
| 86 | qRegisterMetaType<QList<QStandardItem*>>("QList<QStandardItem*>"); | ||
| 87 | |||
| 88 | layout->setContentsMargins(0, 0, 0, 0); | ||
| 89 | layout->setSpacing(0); | ||
| 90 | layout->addWidget(tree_view); | ||
| 91 | |||
| 92 | ui->scrollArea->setLayout(layout); | ||
| 93 | |||
| 94 | connect(tree_view, &QTreeView::clicked, this, &ConfigureSystem::SelectUser); | ||
| 95 | |||
| 96 | connect(ui->pm_add, &QPushButton::pressed, this, &ConfigureSystem::AddUser); | ||
| 97 | connect(ui->pm_rename, &QPushButton::pressed, this, &ConfigureSystem::RenameUser); | ||
| 98 | connect(ui->pm_remove, &QPushButton::pressed, this, &ConfigureSystem::DeleteUser); | ||
| 99 | connect(ui->pm_set_image, &QPushButton::pressed, this, &ConfigureSystem::SetUserImage); | ||
| 100 | |||
| 101 | scene = new QGraphicsScene; | ||
| 102 | ui->current_user_icon->setScene(scene); | ||
| 103 | |||
| 35 | this->setConfiguration(); | 104 | this->setConfiguration(); |
| 36 | } | 105 | } |
| 37 | 106 | ||
| @@ -39,16 +108,74 @@ ConfigureSystem::~ConfigureSystem() = default; | |||
| 39 | 108 | ||
| 40 | void ConfigureSystem::setConfiguration() { | 109 | void ConfigureSystem::setConfiguration() { |
| 41 | enabled = !Core::System::GetInstance().IsPoweredOn(); | 110 | enabled = !Core::System::GetInstance().IsPoweredOn(); |
| 42 | ui->edit_username->setText(QString::fromStdString(Settings::values.username)); | 111 | |
| 43 | ui->combo_language->setCurrentIndex(Settings::values.language_index); | 112 | ui->combo_language->setCurrentIndex(Settings::values.language_index); |
| 113 | |||
| 114 | item_model->removeRows(0, item_model->rowCount()); | ||
| 115 | list_items.clear(); | ||
| 116 | |||
| 117 | PopulateUserList(); | ||
| 118 | UpdateCurrentUser(); | ||
| 119 | } | ||
| 120 | |||
| 121 | static QPixmap GetIcon(Service::Account::UUID uuid) { | ||
| 122 | const auto icon_url = QString::fromStdString(GetImagePath(uuid)); | ||
| 123 | QPixmap icon{icon_url}; | ||
| 124 | |||
| 125 | if (!icon) { | ||
| 126 | icon.fill(Qt::black); | ||
| 127 | icon.loadFromData(backup_jpeg.data(), backup_jpeg.size()); | ||
| 128 | } | ||
| 129 | |||
| 130 | return icon; | ||
| 131 | } | ||
| 132 | |||
| 133 | void ConfigureSystem::PopulateUserList() { | ||
| 134 | const auto& profiles = profile_manager->GetAllUsers(); | ||
| 135 | for (const auto& user : profiles) { | ||
| 136 | Service::Account::ProfileBase profile; | ||
| 137 | if (!profile_manager->GetProfileBase(user, profile)) | ||
| 138 | continue; | ||
| 139 | |||
| 140 | const auto username = Common::StringFromFixedZeroTerminatedBuffer( | ||
| 141 | reinterpret_cast<const char*>(profile.username.data()), profile.username.size()); | ||
| 142 | |||
| 143 | list_items.push_back(QList<QStandardItem*>{new QStandardItem{ | ||
| 144 | GetIcon(user).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), | ||
| 145 | QString::fromStdString(username + '\n' + user.FormatSwitch())}}); | ||
| 146 | } | ||
| 147 | |||
| 148 | for (const auto& item : list_items) | ||
| 149 | item_model->appendRow(item); | ||
| 150 | } | ||
| 151 | |||
| 152 | void ConfigureSystem::UpdateCurrentUser() { | ||
| 153 | ui->pm_add->setEnabled(profile_manager->GetUserCount() < Service::Account::MAX_USERS); | ||
| 154 | |||
| 155 | const auto& current_user = profile_manager->GetUser(Settings::values.current_user); | ||
| 156 | ASSERT(current_user != boost::none); | ||
| 157 | const auto username = GetAccountUsername(*current_user); | ||
| 158 | |||
| 159 | scene->clear(); | ||
| 160 | scene->addPixmap( | ||
| 161 | GetIcon(*current_user).scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); | ||
| 162 | ui->current_user_username->setText(QString::fromStdString(username)); | ||
| 44 | } | 163 | } |
| 45 | 164 | ||
| 46 | void ConfigureSystem::ReadSystemSettings() {} | 165 | void ConfigureSystem::ReadSystemSettings() {} |
| 47 | 166 | ||
| 167 | std::string ConfigureSystem::GetAccountUsername(Service::Account::UUID uuid) const { | ||
| 168 | Service::Account::ProfileBase profile; | ||
| 169 | if (!profile_manager->GetProfileBase(uuid, profile)) | ||
| 170 | return ""; | ||
| 171 | return Common::StringFromFixedZeroTerminatedBuffer( | ||
| 172 | reinterpret_cast<const char*>(profile.username.data()), profile.username.size()); | ||
| 173 | } | ||
| 174 | |||
| 48 | void ConfigureSystem::applyConfiguration() { | 175 | void ConfigureSystem::applyConfiguration() { |
| 49 | if (!enabled) | 176 | if (!enabled) |
| 50 | return; | 177 | return; |
| 51 | Settings::values.username = ui->edit_username->text().toStdString(); | 178 | |
| 52 | Settings::values.language_index = ui->combo_language->currentIndex(); | 179 | Settings::values.language_index = ui->combo_language->currentIndex(); |
| 53 | Settings::Apply(); | 180 | Settings::Apply(); |
| 54 | } | 181 | } |
| @@ -92,3 +219,130 @@ void ConfigureSystem::refreshConsoleID() { | |||
| 92 | ui->label_console_id->setText( | 219 | ui->label_console_id->setText( |
| 93 | tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper())); | 220 | tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper())); |
| 94 | } | 221 | } |
| 222 | |||
| 223 | void ConfigureSystem::SelectUser(const QModelIndex& index) { | ||
| 224 | Settings::values.current_user = | ||
| 225 | std::clamp<std::size_t>(index.row(), 0, profile_manager->GetUserCount() - 1); | ||
| 226 | |||
| 227 | UpdateCurrentUser(); | ||
| 228 | |||
| 229 | ui->pm_remove->setEnabled(profile_manager->GetUserCount() >= 2); | ||
| 230 | ui->pm_rename->setEnabled(true); | ||
| 231 | ui->pm_set_image->setEnabled(true); | ||
| 232 | } | ||
| 233 | |||
| 234 | void ConfigureSystem::AddUser() { | ||
| 235 | Service::Account::UUID uuid; | ||
| 236 | uuid.Generate(); | ||
| 237 | |||
| 238 | bool ok = false; | ||
| 239 | const auto username = | ||
| 240 | QInputDialog::getText(this, tr("Enter Username"), tr("Enter a username for the new user:"), | ||
| 241 | QLineEdit::Normal, QString(), &ok); | ||
| 242 | if (!ok) | ||
| 243 | return; | ||
| 244 | |||
| 245 | profile_manager->CreateNewUser(uuid, username.toStdString()); | ||
| 246 | |||
| 247 | item_model->appendRow(new QStandardItem{ | ||
| 248 | GetIcon(uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), | ||
| 249 | QString::fromStdString(username.toStdString() + '\n' + uuid.FormatSwitch())}); | ||
| 250 | } | ||
| 251 | |||
| 252 | void ConfigureSystem::RenameUser() { | ||
| 253 | const auto user = tree_view->currentIndex().row(); | ||
| 254 | const auto uuid = profile_manager->GetUser(user); | ||
| 255 | ASSERT(uuid != boost::none); | ||
| 256 | const auto username = GetAccountUsername(*uuid); | ||
| 257 | |||
| 258 | Service::Account::ProfileBase profile; | ||
| 259 | if (!profile_manager->GetProfileBase(*uuid, profile)) | ||
| 260 | return; | ||
| 261 | |||
| 262 | bool ok = false; | ||
| 263 | const auto new_username = | ||
| 264 | QInputDialog::getText(this, tr("Enter Username"), tr("Enter a new username:"), | ||
| 265 | QLineEdit::Normal, QString::fromStdString(username), &ok); | ||
| 266 | |||
| 267 | if (!ok) | ||
| 268 | return; | ||
| 269 | |||
| 270 | std::fill(profile.username.begin(), profile.username.end(), '\0'); | ||
| 271 | const auto username_std = new_username.toStdString(); | ||
| 272 | if (username_std.size() > profile.username.size()) { | ||
| 273 | std::copy_n(username_std.begin(), std::min(profile.username.size(), username_std.size()), | ||
| 274 | profile.username.begin()); | ||
| 275 | } else { | ||
| 276 | std::copy(username_std.begin(), username_std.end(), profile.username.begin()); | ||
| 277 | } | ||
| 278 | |||
| 279 | profile_manager->SetProfileBase(*uuid, profile); | ||
| 280 | |||
| 281 | item_model->setItem( | ||
| 282 | user, 0, | ||
| 283 | new QStandardItem{ | ||
| 284 | GetIcon(*uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), | ||
| 285 | tr("%1\n%2", "%1 is the profile username, %2 is the formatted UUID (e.g. " | ||
| 286 | "00112233-4455-6677-8899-AABBCCDDEEFF))") | ||
| 287 | .arg(QString::fromStdString(username_std), | ||
| 288 | QString::fromStdString(uuid->FormatSwitch()))}); | ||
| 289 | UpdateCurrentUser(); | ||
| 290 | } | ||
| 291 | |||
| 292 | void ConfigureSystem::DeleteUser() { | ||
| 293 | const auto index = tree_view->currentIndex().row(); | ||
| 294 | const auto uuid = profile_manager->GetUser(index); | ||
| 295 | ASSERT(uuid != boost::none); | ||
| 296 | const auto username = GetAccountUsername(*uuid); | ||
| 297 | |||
| 298 | const auto confirm = | ||
| 299 | QMessageBox::question(this, tr("Confirm Delete"), | ||
| 300 | tr("You are about to delete user with name %1. Are you sure?") | ||
| 301 | .arg(QString::fromStdString(username))); | ||
| 302 | |||
| 303 | if (confirm == QMessageBox::No) | ||
| 304 | return; | ||
| 305 | |||
| 306 | if (Settings::values.current_user == tree_view->currentIndex().row()) | ||
| 307 | Settings::values.current_user = 0; | ||
| 308 | UpdateCurrentUser(); | ||
| 309 | |||
| 310 | if (!profile_manager->RemoveUser(*uuid)) | ||
| 311 | return; | ||
| 312 | |||
| 313 | item_model->removeRows(tree_view->currentIndex().row(), 1); | ||
| 314 | tree_view->clearSelection(); | ||
| 315 | |||
| 316 | ui->pm_remove->setEnabled(false); | ||
| 317 | ui->pm_rename->setEnabled(false); | ||
| 318 | } | ||
| 319 | |||
| 320 | void ConfigureSystem::SetUserImage() { | ||
| 321 | const auto index = tree_view->currentIndex().row(); | ||
| 322 | const auto uuid = profile_manager->GetUser(index); | ||
| 323 | ASSERT(uuid != boost::none); | ||
| 324 | const auto username = GetAccountUsername(*uuid); | ||
| 325 | |||
| 326 | const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), | ||
| 327 | "JPEG Images (*.jpg *.jpeg)"); | ||
| 328 | |||
| 329 | if (file.isEmpty()) | ||
| 330 | return; | ||
| 331 | |||
| 332 | FileUtil::Delete(GetImagePath(*uuid)); | ||
| 333 | |||
| 334 | const auto raw_path = | ||
| 335 | FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010"; | ||
| 336 | if (FileUtil::Exists(raw_path) && !FileUtil::IsDirectory(raw_path)) | ||
| 337 | FileUtil::Delete(raw_path); | ||
| 338 | |||
| 339 | FileUtil::CreateFullPath(GetImagePath(*uuid)); | ||
| 340 | FileUtil::Copy(file.toStdString(), GetImagePath(*uuid)); | ||
| 341 | |||
| 342 | item_model->setItem( | ||
| 343 | index, 0, | ||
| 344 | new QStandardItem{ | ||
| 345 | GetIcon(*uuid).scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation), | ||
| 346 | QString::fromStdString(username + '\n' + uuid->FormatSwitch())}); | ||
| 347 | UpdateCurrentUser(); | ||
| 348 | } | ||
diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index f13de17d4..b73e0719c 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h | |||
| @@ -5,8 +5,21 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | |||
| 9 | #include <QList> | ||
| 8 | #include <QWidget> | 10 | #include <QWidget> |
| 9 | 11 | ||
| 12 | namespace Service::Account { | ||
| 13 | class ProfileManager; | ||
| 14 | struct UUID; | ||
| 15 | } // namespace Service::Account | ||
| 16 | |||
| 17 | class QGraphicsScene; | ||
| 18 | class QStandardItem; | ||
| 19 | class QStandardItemModel; | ||
| 20 | class QTreeView; | ||
| 21 | class QVBoxLayout; | ||
| 22 | |||
| 10 | namespace Ui { | 23 | namespace Ui { |
| 11 | class ConfigureSystem; | 24 | class ConfigureSystem; |
| 12 | } | 25 | } |
| @@ -21,18 +34,36 @@ public: | |||
| 21 | void applyConfiguration(); | 34 | void applyConfiguration(); |
| 22 | void setConfiguration(); | 35 | void setConfiguration(); |
| 23 | 36 | ||
| 37 | void PopulateUserList(); | ||
| 38 | void UpdateCurrentUser(); | ||
| 39 | |||
| 24 | public slots: | 40 | public slots: |
| 25 | void updateBirthdayComboBox(int birthmonth_index); | 41 | void updateBirthdayComboBox(int birthmonth_index); |
| 26 | void refreshConsoleID(); | 42 | void refreshConsoleID(); |
| 27 | 43 | ||
| 44 | void SelectUser(const QModelIndex& index); | ||
| 45 | void AddUser(); | ||
| 46 | void RenameUser(); | ||
| 47 | void DeleteUser(); | ||
| 48 | void SetUserImage(); | ||
| 49 | |||
| 28 | private: | 50 | private: |
| 29 | void ReadSystemSettings(); | 51 | void ReadSystemSettings(); |
| 52 | std::string GetAccountUsername(Service::Account::UUID uuid) const; | ||
| 53 | |||
| 54 | QVBoxLayout* layout; | ||
| 55 | QTreeView* tree_view; | ||
| 56 | QStandardItemModel* item_model; | ||
| 57 | QGraphicsScene* scene; | ||
| 58 | |||
| 59 | std::vector<QList<QStandardItem*>> list_items; | ||
| 30 | 60 | ||
| 31 | std::unique_ptr<Ui::ConfigureSystem> ui; | 61 | std::unique_ptr<Ui::ConfigureSystem> ui; |
| 32 | bool enabled; | 62 | bool enabled; |
| 33 | 63 | ||
| 34 | std::u16string username; | ||
| 35 | int birthmonth, birthday; | 64 | int birthmonth, birthday; |
| 36 | int language_index; | 65 | int language_index; |
| 37 | int sound_index; | 66 | int sound_index; |
| 67 | |||
| 68 | std::unique_ptr<Service::Account::ProfileManager> profile_manager; | ||
| 38 | }; | 69 | }; |
diff --git a/src/yuzu/configuration/configure_system.ui b/src/yuzu/configuration/configure_system.ui index f3f8db038..020b32a37 100644 --- a/src/yuzu/configuration/configure_system.ui +++ b/src/yuzu/configuration/configure_system.ui | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | <x>0</x> | 7 | <x>0</x> |
| 8 | <y>0</y> | 8 | <y>0</y> |
| 9 | <width>360</width> | 9 | <width>360</width> |
| 10 | <height>377</height> | 10 | <height>483</height> |
| 11 | </rect> | 11 | </rect> |
| 12 | </property> | 12 | </property> |
| 13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
| @@ -22,34 +22,28 @@ | |||
| 22 | <string>System Settings</string> | 22 | <string>System Settings</string> |
| 23 | </property> | 23 | </property> |
| 24 | <layout class="QGridLayout" name="gridLayout"> | 24 | <layout class="QGridLayout" name="gridLayout"> |
| 25 | <item row="0" column="0"> | 25 | <item row="1" column="0"> |
| 26 | <widget class="QLabel" name="label_username"> | 26 | <widget class="QLabel" name="label_language"> |
| 27 | <property name="text"> | 27 | <property name="text"> |
| 28 | <string>Username</string> | 28 | <string>Language</string> |
| 29 | </property> | 29 | </property> |
| 30 | </widget> | 30 | </widget> |
| 31 | </item> | 31 | </item> |
| 32 | <item row="0" column="1"> | 32 | <item row="0" column="0"> |
| 33 | <widget class="QLineEdit" name="edit_username"> | 33 | <widget class="QLabel" name="label_birthday"> |
| 34 | <property name="sizePolicy"> | 34 | <property name="text"> |
| 35 | <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> | 35 | <string>Birthday</string> |
| 36 | <horstretch>0</horstretch> | ||
| 37 | <verstretch>0</verstretch> | ||
| 38 | </sizepolicy> | ||
| 39 | </property> | ||
| 40 | <property name="maxLength"> | ||
| 41 | <number>32</number> | ||
| 42 | </property> | 36 | </property> |
| 43 | </widget> | 37 | </widget> |
| 44 | </item> | 38 | </item> |
| 45 | <item row="1" column="0"> | 39 | <item row="3" column="0"> |
| 46 | <widget class="QLabel" name="label_birthday"> | 40 | <widget class="QLabel" name="label_console_id"> |
| 47 | <property name="text"> | 41 | <property name="text"> |
| 48 | <string>Birthday</string> | 42 | <string>Console ID:</string> |
| 49 | </property> | 43 | </property> |
| 50 | </widget> | 44 | </widget> |
| 51 | </item> | 45 | </item> |
| 52 | <item row="1" column="1"> | 46 | <item row="0" column="1"> |
| 53 | <layout class="QHBoxLayout" name="horizontalLayout_birthday2"> | 47 | <layout class="QHBoxLayout" name="horizontalLayout_birthday2"> |
| 54 | <item> | 48 | <item> |
| 55 | <widget class="QComboBox" name="combo_birthmonth"> | 49 | <widget class="QComboBox" name="combo_birthmonth"> |
| @@ -120,14 +114,7 @@ | |||
| 120 | </item> | 114 | </item> |
| 121 | </layout> | 115 | </layout> |
| 122 | </item> | 116 | </item> |
| 123 | <item row="2" column="0"> | 117 | <item row="1" column="1"> |
| 124 | <widget class="QLabel" name="label_language"> | ||
| 125 | <property name="text"> | ||
| 126 | <string>Language</string> | ||
| 127 | </property> | ||
| 128 | </widget> | ||
| 129 | </item> | ||
| 130 | <item row="2" column="1"> | ||
| 131 | <widget class="QComboBox" name="combo_language"> | 118 | <widget class="QComboBox" name="combo_language"> |
| 132 | <property name="toolTip"> | 119 | <property name="toolTip"> |
| 133 | <string>Note: this can be overridden when region setting is auto-select</string> | 120 | <string>Note: this can be overridden when region setting is auto-select</string> |
| @@ -187,31 +174,31 @@ | |||
| 187 | <string>Russian (Русский)</string> | 174 | <string>Russian (Русский)</string> |
| 188 | </property> | 175 | </property> |
| 189 | </item> | 176 | </item> |
| 190 | <item> | 177 | <item> |
| 191 | <property name="text"> | 178 | <property name="text"> |
| 192 | <string>Taiwanese</string> | 179 | <string>Taiwanese</string> |
| 193 | </property> | 180 | </property> |
| 194 | </item> | 181 | </item> |
| 195 | <item> | 182 | <item> |
| 196 | <property name="text"> | 183 | <property name="text"> |
| 197 | <string>British English</string> | 184 | <string>British English</string> |
| 198 | </property> | 185 | </property> |
| 199 | </item> | 186 | </item> |
| 200 | <item> | 187 | <item> |
| 201 | <property name="text"> | 188 | <property name="text"> |
| 202 | <string>Canadian French</string> | 189 | <string>Canadian French</string> |
| 203 | </property> | 190 | </property> |
| 204 | </item> | 191 | </item> |
| 205 | <item> | 192 | <item> |
| 206 | <property name="text"> | 193 | <property name="text"> |
| 207 | <string>Latin American Spanish</string> | 194 | <string>Latin American Spanish</string> |
| 208 | </property> | 195 | </property> |
| 209 | </item> | 196 | </item> |
| 210 | <item> | 197 | <item> |
| 211 | <property name="text"> | 198 | <property name="text"> |
| 212 | <string>Simplified Chinese</string> | 199 | <string>Simplified Chinese</string> |
| 213 | </property> | 200 | </property> |
| 214 | </item> | 201 | </item> |
| 215 | <item> | 202 | <item> |
| 216 | <property name="text"> | 203 | <property name="text"> |
| 217 | <string>Traditional Chinese (正體中文)</string> | 204 | <string>Traditional Chinese (正體中文)</string> |
| @@ -219,14 +206,14 @@ | |||
| 219 | </item> | 206 | </item> |
| 220 | </widget> | 207 | </widget> |
| 221 | </item> | 208 | </item> |
| 222 | <item row="3" column="0"> | 209 | <item row="2" column="0"> |
| 223 | <widget class="QLabel" name="label_sound"> | 210 | <widget class="QLabel" name="label_sound"> |
| 224 | <property name="text"> | 211 | <property name="text"> |
| 225 | <string>Sound output mode</string> | 212 | <string>Sound output mode</string> |
| 226 | </property> | 213 | </property> |
| 227 | </widget> | 214 | </widget> |
| 228 | </item> | 215 | </item> |
| 229 | <item row="3" column="1"> | 216 | <item row="2" column="1"> |
| 230 | <widget class="QComboBox" name="combo_sound"> | 217 | <widget class="QComboBox" name="combo_sound"> |
| 231 | <item> | 218 | <item> |
| 232 | <property name="text"> | 219 | <property name="text"> |
| @@ -245,14 +232,7 @@ | |||
| 245 | </item> | 232 | </item> |
| 246 | </widget> | 233 | </widget> |
| 247 | </item> | 234 | </item> |
| 248 | <item row="4" column="0"> | 235 | <item row="3" column="1"> |
| 249 | <widget class="QLabel" name="label_console_id"> | ||
| 250 | <property name="text"> | ||
| 251 | <string>Console ID:</string> | ||
| 252 | </property> | ||
| 253 | </widget> | ||
| 254 | </item> | ||
| 255 | <item row="4" column="1"> | ||
| 256 | <widget class="QPushButton" name="button_regenerate_console_id"> | 236 | <widget class="QPushButton" name="button_regenerate_console_id"> |
| 257 | <property name="sizePolicy"> | 237 | <property name="sizePolicy"> |
| 258 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | 238 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> |
| @@ -272,6 +252,143 @@ | |||
| 272 | </widget> | 252 | </widget> |
| 273 | </item> | 253 | </item> |
| 274 | <item> | 254 | <item> |
| 255 | <widget class="QGroupBox" name="gridGroupBox"> | ||
| 256 | <property name="title"> | ||
| 257 | <string>Profile Manager</string> | ||
| 258 | </property> | ||
| 259 | <layout class="QGridLayout" name="gridLayout_2"> | ||
| 260 | <property name="sizeConstraint"> | ||
| 261 | <enum>QLayout::SetNoConstraint</enum> | ||
| 262 | </property> | ||
| 263 | <item row="0" column="0"> | ||
| 264 | <layout class="QHBoxLayout" name="horizontalLayout_2"> | ||
| 265 | <item> | ||
| 266 | <widget class="QLabel" name="label"> | ||
| 267 | <property name="sizePolicy"> | ||
| 268 | <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> | ||
| 269 | <horstretch>0</horstretch> | ||
| 270 | <verstretch>0</verstretch> | ||
| 271 | </sizepolicy> | ||
| 272 | </property> | ||
| 273 | <property name="text"> | ||
| 274 | <string>Current User</string> | ||
| 275 | </property> | ||
| 276 | </widget> | ||
| 277 | </item> | ||
| 278 | <item> | ||
| 279 | <widget class="QGraphicsView" name="current_user_icon"> | ||
| 280 | <property name="minimumSize"> | ||
| 281 | <size> | ||
| 282 | <width>48</width> | ||
| 283 | <height>48</height> | ||
| 284 | </size> | ||
| 285 | </property> | ||
| 286 | <property name="maximumSize"> | ||
| 287 | <size> | ||
| 288 | <width>48</width> | ||
| 289 | <height>48</height> | ||
| 290 | </size> | ||
| 291 | </property> | ||
| 292 | <property name="verticalScrollBarPolicy"> | ||
| 293 | <enum>Qt::ScrollBarAlwaysOff</enum> | ||
| 294 | </property> | ||
| 295 | <property name="horizontalScrollBarPolicy"> | ||
| 296 | <enum>Qt::ScrollBarAlwaysOff</enum> | ||
| 297 | </property> | ||
| 298 | <property name="interactive"> | ||
| 299 | <bool>false</bool> | ||
| 300 | </property> | ||
| 301 | </widget> | ||
| 302 | </item> | ||
| 303 | <item> | ||
| 304 | <widget class="QLabel" name="current_user_username"> | ||
| 305 | <property name="sizePolicy"> | ||
| 306 | <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> | ||
| 307 | <horstretch>0</horstretch> | ||
| 308 | <verstretch>0</verstretch> | ||
| 309 | </sizepolicy> | ||
| 310 | </property> | ||
| 311 | <property name="text"> | ||
| 312 | <string>Username</string> | ||
| 313 | </property> | ||
| 314 | </widget> | ||
| 315 | </item> | ||
| 316 | </layout> | ||
| 317 | </item> | ||
| 318 | <item row="1" column="0"> | ||
| 319 | <widget class="QScrollArea" name="scrollArea"> | ||
| 320 | <property name="sizePolicy"> | ||
| 321 | <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> | ||
| 322 | <horstretch>0</horstretch> | ||
| 323 | <verstretch>0</verstretch> | ||
| 324 | </sizepolicy> | ||
| 325 | </property> | ||
| 326 | <property name="frameShape"> | ||
| 327 | <enum>QFrame::StyledPanel</enum> | ||
| 328 | </property> | ||
| 329 | <property name="widgetResizable"> | ||
| 330 | <bool>false</bool> | ||
| 331 | </property> | ||
| 332 | </widget> | ||
| 333 | </item> | ||
| 334 | <item row="2" column="0"> | ||
| 335 | <layout class="QHBoxLayout" name="horizontalLayout_3"> | ||
| 336 | <item> | ||
| 337 | <widget class="QPushButton" name="pm_set_image"> | ||
| 338 | <property name="enabled"> | ||
| 339 | <bool>false</bool> | ||
| 340 | </property> | ||
| 341 | <property name="text"> | ||
| 342 | <string>Set Image</string> | ||
| 343 | </property> | ||
| 344 | </widget> | ||
| 345 | </item> | ||
| 346 | <item> | ||
| 347 | <spacer name="horizontalSpacer"> | ||
| 348 | <property name="orientation"> | ||
| 349 | <enum>Qt::Horizontal</enum> | ||
| 350 | </property> | ||
| 351 | <property name="sizeHint" stdset="0"> | ||
| 352 | <size> | ||
| 353 | <width>40</width> | ||
| 354 | <height>20</height> | ||
| 355 | </size> | ||
| 356 | </property> | ||
| 357 | </spacer> | ||
| 358 | </item> | ||
| 359 | <item> | ||
| 360 | <widget class="QPushButton" name="pm_add"> | ||
| 361 | <property name="text"> | ||
| 362 | <string>Add</string> | ||
| 363 | </property> | ||
| 364 | </widget> | ||
| 365 | </item> | ||
| 366 | <item> | ||
| 367 | <widget class="QPushButton" name="pm_rename"> | ||
| 368 | <property name="enabled"> | ||
| 369 | <bool>false</bool> | ||
| 370 | </property> | ||
| 371 | <property name="text"> | ||
| 372 | <string>Rename</string> | ||
| 373 | </property> | ||
| 374 | </widget> | ||
| 375 | </item> | ||
| 376 | <item> | ||
| 377 | <widget class="QPushButton" name="pm_remove"> | ||
| 378 | <property name="enabled"> | ||
| 379 | <bool>false</bool> | ||
| 380 | </property> | ||
| 381 | <property name="text"> | ||
| 382 | <string>Remove</string> | ||
| 383 | </property> | ||
| 384 | </widget> | ||
| 385 | </item> | ||
| 386 | </layout> | ||
| 387 | </item> | ||
| 388 | </layout> | ||
| 389 | </widget> | ||
| 390 | </item> | ||
| 391 | <item> | ||
| 275 | <widget class="QLabel" name="label_disable_info"> | 392 | <widget class="QLabel" name="label_disable_info"> |
| 276 | <property name="text"> | 393 | <property name="text"> |
| 277 | <string>System settings are available only when game is not running.</string> | 394 | <string>System settings are available only when game is not running.</string> |
| @@ -281,19 +398,6 @@ | |||
| 281 | </property> | 398 | </property> |
| 282 | </widget> | 399 | </widget> |
| 283 | </item> | 400 | </item> |
| 284 | <item> | ||
| 285 | <spacer name="verticalSpacer"> | ||
| 286 | <property name="orientation"> | ||
| 287 | <enum>Qt::Vertical</enum> | ||
| 288 | </property> | ||
| 289 | <property name="sizeHint" stdset="0"> | ||
| 290 | <size> | ||
| 291 | <width>20</width> | ||
| 292 | <height>40</height> | ||
| 293 | </size> | ||
| 294 | </property> | ||
| 295 | </spacer> | ||
| 296 | </item> | ||
| 297 | </layout> | 401 | </layout> |
| 298 | </item> | 402 | </item> |
| 299 | </layout> | 403 | </layout> |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index be9896614..47f494841 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | // VFS includes must be before glad as they will conflict with Windows file api, which uses defines. | 10 | // VFS includes must be before glad as they will conflict with Windows file api, which uses defines. |
| 11 | #include "core/file_sys/vfs.h" | 11 | #include "core/file_sys/vfs.h" |
| 12 | #include "core/file_sys/vfs_real.h" | 12 | #include "core/file_sys/vfs_real.h" |
| 13 | #include "core/hle/service/acc/profile_manager.h" | ||
| 13 | 14 | ||
| 14 | // These are wrappers to avoid the calls to CreateDirectory and CreateFile becuase of the Windows | 15 | // These are wrappers to avoid the calls to CreateDirectory and CreateFile becuase of the Windows |
| 15 | // defines. | 16 | // defines. |
| @@ -757,12 +758,43 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target | |||
| 757 | open_target = "Save Data"; | 758 | open_target = "Save Data"; |
| 758 | const std::string nand_dir = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); | 759 | const std::string nand_dir = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); |
| 759 | ASSERT(program_id != 0); | 760 | ASSERT(program_id != 0); |
| 760 | // TODO(tech4me): Update this to work with arbitrary user profile | 761 | |
| 761 | // Refer to core/hle/service/acc/profile_manager.cpp ProfileManager constructor | 762 | Service::Account::ProfileManager manager{}; |
| 762 | constexpr u128 user_id = {1, 0}; | 763 | const auto user_ids = manager.GetAllUsers(); |
| 764 | QStringList list; | ||
| 765 | for (const auto& user_id : user_ids) { | ||
| 766 | if (user_id == Service::Account::UUID{}) | ||
| 767 | continue; | ||
| 768 | Service::Account::ProfileBase base; | ||
| 769 | if (!manager.GetProfileBase(user_id, base)) | ||
| 770 | continue; | ||
| 771 | |||
| 772 | list.push_back(QString::fromStdString(Common::StringFromFixedZeroTerminatedBuffer( | ||
| 773 | reinterpret_cast<const char*>(base.username.data()), base.username.size()))); | ||
| 774 | } | ||
| 775 | |||
| 776 | bool ok = false; | ||
| 777 | const auto index_string = | ||
| 778 | QInputDialog::getItem(this, tr("Select User"), | ||
| 779 | tr("Please select the user's save data you would like to open."), | ||
| 780 | list, Settings::values.current_user, false, &ok); | ||
| 781 | if (!ok) | ||
| 782 | return; | ||
| 783 | |||
| 784 | const auto index = list.indexOf(index_string); | ||
| 785 | ASSERT(index != -1 && index < 8); | ||
| 786 | |||
| 787 | const auto user_id = manager.GetUser(index); | ||
| 788 | ASSERT(user_id != boost::none); | ||
| 763 | path = nand_dir + FileSys::SaveDataFactory::GetFullPath(FileSys::SaveDataSpaceId::NandUser, | 789 | path = nand_dir + FileSys::SaveDataFactory::GetFullPath(FileSys::SaveDataSpaceId::NandUser, |
| 764 | FileSys::SaveDataType::SaveData, | 790 | FileSys::SaveDataType::SaveData, |
| 765 | program_id, user_id, 0); | 791 | program_id, user_id->uuid, 0); |
| 792 | |||
| 793 | if (!FileUtil::Exists(path)) { | ||
| 794 | FileUtil::CreateFullPath(path); | ||
| 795 | FileUtil::CreateDir(path); | ||
| 796 | } | ||
| 797 | |||
| 766 | break; | 798 | break; |
| 767 | } | 799 | } |
| 768 | case GameListOpenTarget::ModData: { | 800 | case GameListOpenTarget::ModData: { |
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 654a15a5c..b456266a6 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "common/file_util.h" | 8 | #include "common/file_util.h" |
| 9 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 10 | #include "common/param_package.h" | 10 | #include "common/param_package.h" |
| 11 | #include "core/hle/service/acc/profile_manager.h" | ||
| 11 | #include "core/settings.h" | 12 | #include "core/settings.h" |
| 12 | #include "input_common/main.h" | 13 | #include "input_common/main.h" |
| 13 | #include "yuzu_cmd/config.h" | 14 | #include "yuzu_cmd/config.h" |
| @@ -126,10 +127,10 @@ void Config::ReadValues() { | |||
| 126 | // System | 127 | // System |
| 127 | Settings::values.use_docked_mode = sdl2_config->GetBoolean("System", "use_docked_mode", false); | 128 | Settings::values.use_docked_mode = sdl2_config->GetBoolean("System", "use_docked_mode", false); |
| 128 | Settings::values.enable_nfc = sdl2_config->GetBoolean("System", "enable_nfc", true); | 129 | Settings::values.enable_nfc = sdl2_config->GetBoolean("System", "enable_nfc", true); |
| 129 | Settings::values.username = sdl2_config->Get("System", "username", "yuzu"); | 130 | const auto size = sdl2_config->GetInteger("System", "users_size", 0); |
| 130 | if (Settings::values.username.empty()) { | 131 | |
| 131 | Settings::values.username = "yuzu"; | 132 | Settings::values.current_user = std::clamp<int>( |
| 132 | } | 133 | sdl2_config->GetInteger("System", "current_user", 0), 0, Service::Account::MAX_USERS - 1); |
| 133 | 134 | ||
| 134 | // Miscellaneous | 135 | // Miscellaneous |
| 135 | Settings::values.log_filter = sdl2_config->Get("Miscellaneous", "log_filter", "*:Trace"); | 136 | Settings::values.log_filter = sdl2_config->Get("Miscellaneous", "log_filter", "*:Trace"); |