Finish users.json migration

This commit is contained in:
kalaposfos13 2026-03-03 14:30:51 +01:00
parent fefa647e1e
commit d20df93f31
9 changed files with 30 additions and 30 deletions

View File

@ -249,7 +249,6 @@ bool EmulatorSettingsImpl::Save(const std::string& serial) {
j["Audio"] = m_audio;
j["GPU"] = m_gpu;
j["Vulkan"] = m_vulkan;
j["Users"] = m_userManager.GetUsers();
std::ofstream out(path);
if (!out) {
LOG_ERROR(EmuSettings, "Failed to open config for writing: {}", path.string());
@ -293,8 +292,6 @@ bool EmulatorSettingsImpl::Load(const std::string& serial) {
mergeGroup(m_gpu, "GPU");
mergeGroup(m_vulkan, "Vulkan");
if (gj.contains("Users"))
m_userManager.GetUsers() = gj.at("Users").get<Users>();
LOG_DEBUG(EmuSettings, "Global config loaded successfully");
} else {
if (std::filesystem::exists(Common::FS::GetUserPath(Common::FS::PathType::UserDir) /
@ -324,8 +321,6 @@ bool EmulatorSettingsImpl::Load(const std::string& serial) {
}
LOG_DEBUG(EmuSettings, "Global config not found - using defaults");
SetDefaultValues();
if (m_userManager.GetUsers().user.empty())
m_userManager.GetUsers().user = m_userManager.CreateDefaultUser();
Save();
}
if (GetConfigVersion() != Common::g_scm_rev) {
@ -334,7 +329,7 @@ bool EmulatorSettingsImpl::Load(const std::string& serial) {
return true;
} else {
// ── Per-game override file ─────────────────────────────────
// Never reloads global settings. Only applies
// Never reloads global settings. Only applies
// game_specific_value overrides on top of the already-loaded
// base configuration.
const auto gamePath =

View File

@ -389,11 +389,6 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(VulkanSettings, gpu_id, renderdoc_enabled, vk
vkvalidation_gpu_enabled, vkcrash_diagnostic_enabled,
vkhost_markers, vkguest_markers, pipeline_cache_enabled,
pipeline_cache_archived)
// -------------------------------
// User settings
// -------------------------------
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(User, user_id, user_color, user_name, controller_port)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Users, default_user_id, user)
// -------------------------------
// Main manager
@ -444,11 +439,6 @@ public:
std::filesystem::path GetFontsDir();
void SetFontsDir(const std::filesystem::path& dir);
// user helpers
UserManager& GetUserManager() {
return m_userManager;
}
private:
GeneralSettings m_general{};
DebugSettings m_debug{};
@ -456,7 +446,6 @@ private:
AudioSettings m_audio{};
GPUSettings m_gpu{};
VulkanSettings m_vulkan{};
UserManager m_userManager;
ConfigMode m_configMode{ConfigMode::Default};
static std::shared_ptr<EmulatorSettingsImpl> s_instance;

View File

@ -12,6 +12,7 @@
#include "core/libraries/np/np_error.h"
#include "core/libraries/np/np_manager.h"
#include "core/tls.h"
#include <core/user_settings.h>
namespace Libraries::Np::NpManager {

View File

@ -12,6 +12,7 @@
#include "core/libraries/system/userservice_error.h"
#include "core/tls.h"
#include "input/controller.h"
#include <core/user_settings.h>
namespace Libraries::UserService {

View File

@ -6,6 +6,7 @@
#include <common/path_util.h>
#include "emulator_settings.h"
#include "user_manager.h"
#include "user_settings.h"
bool UserManager::AddUser(const User& user) {
for (const auto& u : m_users.user) {
@ -129,4 +130,8 @@ std::vector<User> UserManager::GetValidUsers() const {
}
return result;
}
bool UserManager::Save() const {
return UserSettings.Save();
}

View File

@ -7,8 +7,6 @@
#include <vector>
#include "common/types.h"
#define UserManagement EmulatorSettings.GetUserManager()
struct User {
s32 user_id;
u32 user_color;
@ -43,6 +41,8 @@ public:
return m_users;
}
bool Save() const;
private:
Users m_users;
};

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025-2026 shadPS4 Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm>
@ -23,11 +23,18 @@ UserSettingsImpl::~UserSettingsImpl() {
Save();
}
std::shared_ptr<UserSettingsImpl> UserSettingsImpl::GetInstance() {
std::lock_guard lock(s_mutex);
if (!s_instance)
s_instance = std::make_shared<UserSettingsImpl>();
return s_instance;
}
bool UserSettingsImpl::Save() const {
const auto path = Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "users.json";
try {
json j;
j["Users"] = m_userManager.GetUsers();
j = m_userManager.GetUsers();
std::ofstream out(path);
if (!out) {
@ -63,11 +70,9 @@ bool UserSettingsImpl::Load() {
json j;
in >> j;
if (j.contains("Users")) {
m_userManager.GetUsers() = j.at("Users").get<Users>();
LOG_DEBUG(EmuSettings, "User settings loaded successfully");
return true;
}
m_userManager.GetUsers() = j.get<Users>();
LOG_DEBUG(EmuSettings, "User settings loaded successfully");
return true;
return false;
} catch (const std::exception& e) {

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2025-2026 shadPS4 Emulator Project
// SPDX-FileCopyrightText: Copyright 2026 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
@ -17,6 +17,8 @@
#define UserSettings (*UserSettingsImpl::GetInstance())
#define UserManagement UserSettings.GetUserManager()
// -------------------------------
// User settings
// -------------------------------
@ -34,6 +36,8 @@ public:
bool Save() const;
bool Load();
static std::shared_ptr<UserSettingsImpl> GetInstance();
private:
UserManager m_userManager;

View File

@ -24,6 +24,7 @@
#endif
#include <common/key_manager.h>
#include <core/emulator_settings.h>
#include "core/user_settings.h"
int main(int argc, char* argv[]) {
#ifdef _WIN32
@ -35,9 +36,8 @@ int main(int argc, char* argv[]) {
std::shared_ptr<EmulatorState> m_emu_state = std::make_shared<EmulatorState>();
EmulatorState::SetInstance(m_emu_state);
// Load configurations
std::shared_ptr<EmulatorSettingsImpl> emu_settings = std::make_shared<EmulatorSettingsImpl>();
EmulatorSettingsImpl::SetInstance(emu_settings);
emu_settings->Load();
EmulatorSettings.Load();
UserSettings.Load();
// TODO add back trophy key migration without the need of entire previous config framework