diff --git a/.gitmodules b/.gitmodules index 25b5d307b..716d3fb95 100644 --- a/.gitmodules +++ b/.gitmodules @@ -106,3 +106,6 @@ [submodule "externals/libusb"] path = externals/libusb url = https://github.com/libusb/libusb-cmake.git +[submodule "externals/json"] + path = externals/json + url = https://github.com/nlohmann/json.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c6d03015..b2a380471 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1104,7 +1104,7 @@ endif() create_target_directory_groups(shadps4) target_link_libraries(shadps4 PRIVATE magic_enum::magic_enum fmt::fmt toml11::toml11 tsl::robin_map xbyak::xbyak Tracy::TracyClient RenderDoc::API FFmpeg::ffmpeg Dear_ImGui gcn half::half ZLIB::ZLIB PNG::PNG) -target_link_libraries(shadps4 PRIVATE Boost::headers GPUOpen::VulkanMemoryAllocator LibAtrac9 sirit Vulkan::Headers xxHash::xxhash Zydis::Zydis glslang::glslang SDL3::SDL3 pugixml::pugixml stb::headers libusb::usb) +target_link_libraries(shadps4 PRIVATE Boost::headers GPUOpen::VulkanMemoryAllocator LibAtrac9 sirit Vulkan::Headers xxHash::xxhash Zydis::Zydis glslang::glslang SDL3::SDL3 pugixml::pugixml stb::headers libusb::usb nlohmann_json::nlohmann_json) target_compile_definitions(shadps4 PRIVATE IMGUI_USER_CONFIG="imgui/imgui_config.h") target_compile_definitions(Dear_ImGui PRIVATE IMGUI_USER_CONFIG="${PROJECT_SOURCE_DIR}/src/imgui/imgui_config.h") diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 89b0fbfdd..a283769b5 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -230,3 +230,7 @@ if (APPLE) add_subdirectory(MoltenVK) endif() endif() + +#nlohmann json +set(JSON_BuildTests OFF CACHE INTERNAL "") +add_subdirectory(json) \ No newline at end of file diff --git a/externals/json b/externals/json new file mode 160000 index 000000000..568b708fd --- /dev/null +++ b/externals/json @@ -0,0 +1 @@ +Subproject commit 568b708fd46deeb23a959381393a7564f1586588 diff --git a/src/core/user_account.cpp b/src/core/user_account.cpp index ee4f4711c..83bd9bf4c 100644 --- a/src/core/user_account.cpp +++ b/src/core/user_account.cpp @@ -2,12 +2,36 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include +#include +#include +#include "common/config.h" #include "user_account.h" +using json = nlohmann::json; + user_account::user_account(const std::string& user_id) { // Setting userId. m_user_id = user_id; - // TODO + + m_user_dir = Common::FS::GetUserPathString(Common::FS::PathType::HomeDir) + "/" + + Config::getDefaultUserId() + "/"; + + Common::FS::IOFile userfile(m_user_dir + "localuser.json", Common::FS::FileAccessMode::Read); + if (userfile.IsOpen()) { + nlohmann::json jsonfile; + try { + jsonfile = nlohmann::json::parse(userfile.ReadString(userfile.GetSize())); + } catch (const nlohmann::json::parse_error& e) { + // TODO error code + } + userfile.Close(); + m_username = jsonfile.value("username", "shadps4"); + if (m_username.length() > 16) // max of 16 chars allowed + { + m_username = m_username.substr(0, 16); // substring 16 only characters to display + } + } } std::map user_account::GetUserAccounts(const std::string& base_dir) {