diff options
| author | 2018-10-09 22:35:02 -0400 | |
|---|---|---|
| committer | 2018-10-23 19:31:28 -0400 | |
| commit | 19c5cf9c637d7fb685ca6977fb7cbf06e075cedf (patch) | |
| tree | ae471ed509e014a869fb81277cd45837ff7c80eb | |
| parent | qt: Allow user to select emu user on open save data (diff) | |
| download | yuzu-19c5cf9c637d7fb685ca6977fb7cbf06e075cedf.tar.gz yuzu-19c5cf9c637d7fb685ca6977fb7cbf06e075cedf.tar.xz yuzu-19c5cf9c637d7fb685ca6977fb7cbf06e075cedf.zip | |
acc: Load user images from config dir
| -rw-r--r-- | src/core/hle/service/acc/acc.cpp | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index e61748ca3..0149ea8b3 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -3,8 +3,11 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include "common/common_paths.h" | ||
| 6 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/file_util.h" | ||
| 7 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 10 | #include "common/string_util.h" | ||
| 8 | #include "common/swap.h" | 11 | #include "common/swap.h" |
| 9 | #include "core/core_timing.h" | 12 | #include "core/core_timing.h" |
| 10 | #include "core/hle/ipc_helpers.h" | 13 | #include "core/hle/ipc_helpers.h" |
| @@ -16,6 +19,9 @@ | |||
| 16 | #include "core/hle/service/acc/profile_manager.h" | 19 | #include "core/hle/service/acc/profile_manager.h" |
| 17 | 20 | ||
| 18 | namespace Service::Account { | 21 | namespace Service::Account { |
| 22 | |||
| 23 | constexpr u32 MAX_JPEG_IMAGE_SIZE = 0x20000; | ||
| 24 | |||
| 19 | // TODO: RE this structure | 25 | // TODO: RE this structure |
| 20 | struct UserData { | 26 | struct UserData { |
| 21 | INSERT_PADDING_WORDS(1); | 27 | INSERT_PADDING_WORDS(1); |
| @@ -27,6 +33,11 @@ struct UserData { | |||
| 27 | }; | 33 | }; |
| 28 | static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); | 34 | static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); |
| 29 | 35 | ||
| 36 | static std::string GetImagePath(const std::string& username) { | ||
| 37 | return FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "users" + DIR_SEP + username + | ||
| 38 | ".jpg"; | ||
| 39 | } | ||
| 40 | |||
| 30 | class IProfile final : public ServiceFramework<IProfile> { | 41 | class IProfile final : public ServiceFramework<IProfile> { |
| 31 | public: | 42 | public: |
| 32 | explicit IProfile(UUID user_id, ProfileManager& profile_manager) | 43 | explicit IProfile(UUID user_id, ProfileManager& profile_manager) |
| @@ -38,6 +49,15 @@ public: | |||
| 38 | {11, &IProfile::LoadImage, "LoadImage"}, | 49 | {11, &IProfile::LoadImage, "LoadImage"}, |
| 39 | }; | 50 | }; |
| 40 | RegisterHandlers(functions); | 51 | RegisterHandlers(functions); |
| 52 | |||
| 53 | ProfileBase profile_base{}; | ||
| 54 | if (profile_manager.GetProfileBase(user_id, profile_base)) { | ||
| 55 | image = std::make_unique<FileUtil::IOFile>( | ||
| 56 | GetImagePath(Common::StringFromFixedZeroTerminatedBuffer( | ||
| 57 | reinterpret_cast<const char*>(profile_base.username.data()), | ||
| 58 | profile_base.username.size())), | ||
| 59 | "rb"); | ||
| 60 | } | ||
| 41 | } | 61 | } |
| 42 | 62 | ||
| 43 | private: | 63 | private: |
| @@ -73,11 +93,11 @@ private: | |||
| 73 | } | 93 | } |
| 74 | 94 | ||
| 75 | void LoadImage(Kernel::HLERequestContext& ctx) { | 95 | void LoadImage(Kernel::HLERequestContext& ctx) { |
| 76 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 96 | LOG_DEBUG(Service_ACC, "called"); |
| 77 | // smallest jpeg https://github.com/mathiasbynens/small/blob/master/jpeg.jpg | 97 | // 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 | 98 | // used as a backup should the one on disk not exist |
| 79 | constexpr u32 jpeg_size = 107; | 99 | constexpr u32 backup_jpeg_size = 107; |
| 80 | static constexpr std::array<u8, jpeg_size> jpeg{ | 100 | 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, | 101 | 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, | 102 | 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, | 103 | 0x08, 0x06, 0x06, 0x05, 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, |
| @@ -87,22 +107,38 @@ private: | |||
| 87 | 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, 0x01, 0x01, | 107 | 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, 0x01, 0x01, |
| 88 | 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, | 108 | 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, |
| 89 | }; | 109 | }; |
| 90 | ctx.WriteBuffer(jpeg); | 110 | |
| 91 | IPC::ResponseBuilder rb{ctx, 3}; | 111 | IPC::ResponseBuilder rb{ctx, 3}; |
| 92 | rb.Push(RESULT_SUCCESS); | 112 | rb.Push(RESULT_SUCCESS); |
| 93 | rb.Push<u32>(jpeg_size); | 113 | |
| 114 | if (image == nullptr) { | ||
| 115 | ctx.WriteBuffer(backup_jpeg); | ||
| 116 | rb.Push<u32>(backup_jpeg_size); | ||
| 117 | } else { | ||
| 118 | const auto size = std::min<u32>(image->GetSize(), MAX_JPEG_IMAGE_SIZE); | ||
| 119 | std::vector<u8> buffer(size); | ||
| 120 | image->ReadBytes(buffer.data(), buffer.size()); | ||
| 121 | |||
| 122 | ctx.WriteBuffer(buffer.data(), buffer.size()); | ||
| 123 | rb.Push<u32>(buffer.size()); | ||
| 124 | } | ||
| 94 | } | 125 | } |
| 95 | 126 | ||
| 96 | void GetImageSize(Kernel::HLERequestContext& ctx) { | 127 | void GetImageSize(Kernel::HLERequestContext& ctx) { |
| 97 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 128 | LOG_DEBUG(Service_ACC, "called"); |
| 98 | constexpr u32 jpeg_size = 107; | 129 | constexpr u32 backup_jpeg_size = 107; |
| 99 | IPC::ResponseBuilder rb{ctx, 3}; | 130 | IPC::ResponseBuilder rb{ctx, 3}; |
| 100 | rb.Push(RESULT_SUCCESS); | 131 | rb.Push(RESULT_SUCCESS); |
| 101 | rb.Push<u32>(jpeg_size); | 132 | |
| 133 | if (image == nullptr) | ||
| 134 | rb.Push<u32>(backup_jpeg_size); | ||
| 135 | else | ||
| 136 | rb.Push<u32>(std::min<u32>(image->GetSize(), MAX_JPEG_IMAGE_SIZE)); | ||
| 102 | } | 137 | } |
| 103 | 138 | ||
| 104 | const ProfileManager& profile_manager; | 139 | const ProfileManager& profile_manager; |
| 105 | UUID user_id; ///< The user id this profile refers to. | 140 | UUID user_id; ///< The user id this profile refers to. |
| 141 | std::unique_ptr<FileUtil::IOFile> image = nullptr; | ||
| 106 | }; | 142 | }; |
| 107 | 143 | ||
| 108 | class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { | 144 | class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { |