summaryrefslogtreecommitdiff
path: root/src/core/hle/service/acc
diff options
context:
space:
mode:
authorGravatar Morph2021-05-25 19:32:56 -0400
committerGravatar GitHub2021-05-25 19:32:56 -0400
commit065867e2c24e9856c360fc2d6b9a86c92aedc43e (patch)
tree7964e85ef4f01a3c2b8f44e850f37b384405b930 /src/core/hle/service/acc
parentMerge pull request #6349 from german77/suppress_config_warning (diff)
downloadyuzu-065867e2c24e9856c360fc2d6b9a86c92aedc43e.tar.gz
yuzu-065867e2c24e9856c360fc2d6b9a86c92aedc43e.tar.xz
yuzu-065867e2c24e9856c360fc2d6b9a86c92aedc43e.zip
common: fs: Rework the Common Filesystem interface to make use of std::filesystem (#6270)
* common: fs: fs_types: Create filesystem types Contains various filesystem types used by the Common::FS library * common: fs: fs_util: Add std::string to std::u8string conversion utility * common: fs: path_util: Add utlity functions for paths Contains various utility functions for getting or manipulating filesystem paths used by the Common::FS library * common: fs: file: Rewrite the IOFile implementation * common: fs: Reimplement Common::FS library using std::filesystem * common: fs: fs_paths: Add fs_paths to replace common_paths * common: fs: path_util: Add the rest of the path functions * common: Remove the previous Common::FS implementation * general: Remove unused fs includes * string_util: Remove unused function and include * nvidia_flags: Migrate to the new Common::FS library * settings: Migrate to the new Common::FS library * logging: backend: Migrate to the new Common::FS library * core: Migrate to the new Common::FS library * perf_stats: Migrate to the new Common::FS library * reporter: Migrate to the new Common::FS library * telemetry_session: Migrate to the new Common::FS library * key_manager: Migrate to the new Common::FS library * bis_factory: Migrate to the new Common::FS library * registered_cache: Migrate to the new Common::FS library * xts_archive: Migrate to the new Common::FS library * service: acc: Migrate to the new Common::FS library * applets/profile: Migrate to the new Common::FS library * applets/web: Migrate to the new Common::FS library * service: filesystem: Migrate to the new Common::FS library * loader: Migrate to the new Common::FS library * gl_shader_disk_cache: Migrate to the new Common::FS library * nsight_aftermath_tracker: Migrate to the new Common::FS library * vulkan_library: Migrate to the new Common::FS library * configure_debug: Migrate to the new Common::FS library * game_list_worker: Migrate to the new Common::FS library * config: Migrate to the new Common::FS library * configure_filesystem: Migrate to the new Common::FS library * configure_per_game_addons: Migrate to the new Common::FS library * configure_profile_manager: Migrate to the new Common::FS library * configure_ui: Migrate to the new Common::FS library * input_profiles: Migrate to the new Common::FS library * yuzu_cmd: config: Migrate to the new Common::FS library * yuzu_cmd: Migrate to the new Common::FS library * vfs_real: Migrate to the new Common::FS library * vfs: Migrate to the new Common::FS library * vfs_libzip: Migrate to the new Common::FS library * service: bcat: Migrate to the new Common::FS library * yuzu: main: Migrate to the new Common::FS library * vfs_real: Delete the contents of an existing file in CreateFile Current usages of CreateFile expect to delete the contents of an existing file, retain this behavior for now. * input_profiles: Don't iterate the input profile dir if it does not exist Silences an error produced in the log if the directory does not exist. * game_list_worker: Skip parsing file if the returned VfsFile is nullptr Prevents crashes in GetLoader when the virtual file is nullptr * common: fs: Validate paths for path length * service: filesystem: Open the mod load directory as read only
Diffstat (limited to 'src/core/hle/service/acc')
-rw-r--r--src/core/hle/service/acc/acc.cpp28
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp33
2 files changed, 33 insertions, 28 deletions
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp
index 49c09a570..39cd1efc1 100644
--- a/src/core/hle/service/acc/acc.cpp
+++ b/src/core/hle/service/acc/acc.cpp
@@ -4,9 +4,9 @@
4 4
5#include <algorithm> 5#include <algorithm>
6#include <array> 6#include <array>
7#include "common/common_paths.h"
8#include "common/common_types.h" 7#include "common/common_types.h"
9#include "common/file_util.h" 8#include "common/fs/file.h"
9#include "common/fs/path_util.h"
10#include "common/logging/log.h" 10#include "common/logging/log.h"
11#include "common/string_util.h" 11#include "common/string_util.h"
12#include "common/swap.h" 12#include "common/swap.h"
@@ -41,9 +41,9 @@ constexpr ResultCode ERR_FAILED_SAVE_DATA{ErrorModule::Account, 100};
41// Thumbnails are hard coded to be at least this size 41// Thumbnails are hard coded to be at least this size
42constexpr std::size_t THUMBNAIL_SIZE = 0x24000; 42constexpr std::size_t THUMBNAIL_SIZE = 0x24000;
43 43
44static std::string GetImagePath(Common::UUID uuid) { 44static std::filesystem::path GetImagePath(Common::UUID uuid) {
45 return Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) + 45 return Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) /
46 "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; 46 fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormatSwitch());
47} 47}
48 48
49static constexpr u32 SanitizeJPEGSize(std::size_t size) { 49static constexpr u32 SanitizeJPEGSize(std::size_t size) {
@@ -328,7 +328,8 @@ protected:
328 IPC::ResponseBuilder rb{ctx, 3}; 328 IPC::ResponseBuilder rb{ctx, 3};
329 rb.Push(RESULT_SUCCESS); 329 rb.Push(RESULT_SUCCESS);
330 330
331 const Common::FS::IOFile image(GetImagePath(user_id), "rb"); 331 const Common::FS::IOFile image(GetImagePath(user_id), Common::FS::FileAccessMode::Read,
332 Common::FS::FileType::BinaryFile);
332 if (!image.IsOpen()) { 333 if (!image.IsOpen()) {
333 LOG_WARNING(Service_ACC, 334 LOG_WARNING(Service_ACC,
334 "Failed to load user provided image! Falling back to built-in backup..."); 335 "Failed to load user provided image! Falling back to built-in backup...");
@@ -339,7 +340,10 @@ protected:
339 340
340 const u32 size = SanitizeJPEGSize(image.GetSize()); 341 const u32 size = SanitizeJPEGSize(image.GetSize());
341 std::vector<u8> buffer(size); 342 std::vector<u8> buffer(size);
342 image.ReadBytes(buffer.data(), buffer.size()); 343
344 if (image.Read(buffer) != buffer.size()) {
345 LOG_ERROR(Service_ACC, "Failed to read all the bytes in the user provided image.");
346 }
343 347
344 ctx.WriteBuffer(buffer); 348 ctx.WriteBuffer(buffer);
345 rb.Push<u32>(size); 349 rb.Push<u32>(size);
@@ -350,7 +354,8 @@ protected:
350 IPC::ResponseBuilder rb{ctx, 3}; 354 IPC::ResponseBuilder rb{ctx, 3};
351 rb.Push(RESULT_SUCCESS); 355 rb.Push(RESULT_SUCCESS);
352 356
353 const Common::FS::IOFile image(GetImagePath(user_id), "rb"); 357 const Common::FS::IOFile image(GetImagePath(user_id), Common::FS::FileAccessMode::Read,
358 Common::FS::FileType::BinaryFile);
354 359
355 if (!image.IsOpen()) { 360 if (!image.IsOpen()) {
356 LOG_WARNING(Service_ACC, 361 LOG_WARNING(Service_ACC,
@@ -415,10 +420,11 @@ protected:
415 ProfileData data; 420 ProfileData data;
416 std::memcpy(&data, user_data.data(), sizeof(ProfileData)); 421 std::memcpy(&data, user_data.data(), sizeof(ProfileData));
417 422
418 Common::FS::IOFile image(GetImagePath(user_id), "wb"); 423 Common::FS::IOFile image(GetImagePath(user_id), Common::FS::FileAccessMode::Write,
424 Common::FS::FileType::BinaryFile);
419 425
420 if (!image.IsOpen() || !image.Resize(image_data.size()) || 426 if (!image.IsOpen() || !image.SetSize(image_data.size()) ||
421 image.WriteBytes(image_data.data(), image_data.size()) != image_data.size() || 427 image.Write(image_data) != image_data.size() ||
422 !profile_manager.SetProfileBaseAndData(user_id, base, data)) { 428 !profile_manager.SetProfileBaseAndData(user_id, base, data)) {
423 LOG_ERROR(Service_ACC, "Failed to update profile data, base, and image!"); 429 LOG_ERROR(Service_ACC, "Failed to update profile data, base, and image!");
424 IPC::ResponseBuilder rb{ctx, 2}; 430 IPC::ResponseBuilder rb{ctx, 2};
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index de83d82a4..77510489c 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -7,7 +7,9 @@
7 7
8#include <fmt/format.h> 8#include <fmt/format.h>
9 9
10#include "common/file_util.h" 10#include "common/fs/file.h"
11#include "common/fs/fs.h"
12#include "common/fs/path_util.h"
11#include "common/settings.h" 13#include "common/settings.h"
12#include "core/hle/service/acc/profile_manager.h" 14#include "core/hle/service/acc/profile_manager.h"
13 15
@@ -36,7 +38,7 @@ constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, u32(-1));
36constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, u32(-2)); 38constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, u32(-2));
37constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); 39constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20);
38 40
39constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/avators/"; 41constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "system/save/8000000000000010/su/avators";
40 42
41ProfileManager::ProfileManager() { 43ProfileManager::ProfileManager() {
42 ParseUserSaveFile(); 44 ParseUserSaveFile();
@@ -325,8 +327,9 @@ bool ProfileManager::SetProfileBaseAndData(Common::UUID uuid, const ProfileBase&
325} 327}
326 328
327void ProfileManager::ParseUserSaveFile() { 329void ProfileManager::ParseUserSaveFile() {
328 const FS::IOFile save( 330 const auto save_path(FS::GetYuzuPath(FS::YuzuPath::NANDDir) / ACC_SAVE_AVATORS_BASE_PATH /
329 FS::GetUserPath(FS::UserPath::NANDDir) + ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat", "rb"); 331 "profiles.dat");
332 const FS::IOFile save(save_path, FS::FileAccessMode::Read, FS::FileType::BinaryFile);
330 333
331 if (!save.IsOpen()) { 334 if (!save.IsOpen()) {
332 LOG_WARNING(Service_ACC, "Failed to load profile data from save data... Generating new " 335 LOG_WARNING(Service_ACC, "Failed to load profile data from save data... Generating new "
@@ -335,7 +338,7 @@ void ProfileManager::ParseUserSaveFile() {
335 } 338 }
336 339
337 ProfileDataRaw data; 340 ProfileDataRaw data;
338 if (save.ReadBytes(&data, sizeof(ProfileDataRaw)) != sizeof(ProfileDataRaw)) { 341 if (!save.ReadObject(data)) {
339 LOG_WARNING(Service_ACC, "profiles.dat is smaller than expected... Generating new user " 342 LOG_WARNING(Service_ACC, "profiles.dat is smaller than expected... Generating new user "
340 "'yuzu' with random UUID."); 343 "'yuzu' with random UUID.");
341 return; 344 return;
@@ -372,31 +375,27 @@ void ProfileManager::WriteUserSaveFile() {
372 }; 375 };
373 } 376 }
374 377
375 const auto raw_path = FS::GetUserPath(FS::UserPath::NANDDir) + "/system/save/8000000000000010"; 378 const auto raw_path(FS::GetYuzuPath(FS::YuzuPath::NANDDir) / "system/save/8000000000000010");
376 if (FS::Exists(raw_path) && !FS::IsDirectory(raw_path)) { 379 if (FS::IsFile(raw_path) && !FS::RemoveFile(raw_path)) {
377 FS::Delete(raw_path); 380 return;
378 } 381 }
379 382
380 const auto path = 383 const auto save_path(FS::GetYuzuPath(FS::YuzuPath::NANDDir) / ACC_SAVE_AVATORS_BASE_PATH /
381 FS::GetUserPath(FS::UserPath::NANDDir) + ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat"; 384 "profiles.dat");
382 385
383 if (!FS::CreateFullPath(path)) { 386 if (!FS::CreateParentDirs(save_path)) {
384 LOG_WARNING(Service_ACC, "Failed to create full path of profiles.dat. Create the directory " 387 LOG_WARNING(Service_ACC, "Failed to create full path of profiles.dat. Create the directory "
385 "nand/system/save/8000000000000010/su/avators to mitigate this " 388 "nand/system/save/8000000000000010/su/avators to mitigate this "
386 "issue."); 389 "issue.");
387 return; 390 return;
388 } 391 }
389 392
390 FS::IOFile save(path, "wb"); 393 FS::IOFile save(save_path, FS::FileAccessMode::Write, FS::FileType::BinaryFile);
391 394
392 if (!save.IsOpen()) { 395 if (!save.IsOpen() || !save.SetSize(sizeof(ProfileDataRaw)) || !save.WriteObject(raw)) {
393 LOG_WARNING(Service_ACC, "Failed to write save data to file... No changes to user data " 396 LOG_WARNING(Service_ACC, "Failed to write save data to file... No changes to user data "
394 "made in current session will be saved."); 397 "made in current session will be saved.");
395 return;
396 } 398 }
397
398 save.Resize(sizeof(ProfileDataRaw));
399 save.WriteBytes(&raw, sizeof(ProfileDataRaw));
400} 399}
401 400
402}; // namespace Service::Account 401}; // namespace Service::Account