mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-12 20:55:56 +00:00
use json to read local file
This commit is contained in:
parent
4bccf7a2db
commit
7b0d6c4bf8
5 changed files with 34 additions and 2 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
4
externals/CMakeLists.txt
vendored
4
externals/CMakeLists.txt
vendored
|
@ -230,3 +230,7 @@ if (APPLE)
|
|||
add_subdirectory(MoltenVK)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#nlohmann json
|
||||
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
||||
add_subdirectory(json)
|
1
externals/json
vendored
Submodule
1
externals/json
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 568b708fd46deeb23a959381393a7564f1586588
|
|
@ -2,12 +2,36 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <filesystem>
|
||||
#include <common/io_file.h>
|
||||
#include <common/path_util.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#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<u32, user_account> user_account::GetUserAccounts(const std::string& base_dir) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue