mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-06-02 04:38:28 -06:00
Core: Remove old config code (#4499)
* Remove old config backend Trophy key migration now uses the toml library directly, like our config transfer code. * Don't retrieve user_dir in main No longer needed.
This commit is contained in:
parent
2736ce8c2e
commit
48283da2a6
@ -732,8 +732,6 @@ set(COMMON src/common/logging/classes.h
|
||||
src/common/bit_field.h
|
||||
src/common/bounded_threadsafe_queue.h
|
||||
src/common/concepts.h
|
||||
src/common/config.cpp
|
||||
src/common/config.h
|
||||
src/common/cstring.h
|
||||
src/common/debug.h
|
||||
src/common/decoder.cpp
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,213 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025-2026 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <vector>
|
||||
#include "types.h"
|
||||
|
||||
namespace Config {
|
||||
|
||||
enum class ConfigMode {
|
||||
Default,
|
||||
Global,
|
||||
Clean,
|
||||
};
|
||||
void setConfigMode(ConfigMode mode);
|
||||
|
||||
struct GameInstallDir {
|
||||
std::filesystem::path path;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
enum HideCursorState : int { Never, Idle, Always };
|
||||
|
||||
enum GpuReadbacksMode : int {
|
||||
Disabled,
|
||||
Relaxed,
|
||||
Precise,
|
||||
};
|
||||
|
||||
void load(const std::filesystem::path& path, bool is_game_specific = false);
|
||||
void save(const std::filesystem::path& path, bool is_game_specific = false);
|
||||
void resetGameSpecificValue(std::string entry);
|
||||
|
||||
bool getGameRunning();
|
||||
void setGameRunning(bool running);
|
||||
int getVolumeSlider();
|
||||
void setVolumeSlider(int volumeValue, bool is_game_specific = false);
|
||||
std::string getTrophyKey();
|
||||
void setTrophyKey(std::string key);
|
||||
bool getIsFullscreen();
|
||||
void setIsFullscreen(bool enable, bool is_game_specific = false);
|
||||
std::string getFullscreenMode();
|
||||
void setFullscreenMode(std::string mode, bool is_game_specific = false);
|
||||
std::string getPresentMode();
|
||||
void setPresentMode(std::string mode, bool is_game_specific = false);
|
||||
u32 getWindowWidth();
|
||||
u32 getWindowHeight();
|
||||
void setWindowWidth(u32 width, bool is_game_specific = false);
|
||||
void setWindowHeight(u32 height, bool is_game_specific = false);
|
||||
u32 getInternalScreenWidth();
|
||||
u32 getInternalScreenHeight();
|
||||
void setInternalScreenWidth(u32 width);
|
||||
void setInternalScreenHeight(u32 height);
|
||||
bool debugDump();
|
||||
void setDebugDump(bool enable, bool is_game_specific = false);
|
||||
s32 getGpuId();
|
||||
void setGpuId(s32 selectedGpuId, bool is_game_specific = false);
|
||||
bool allowHDR();
|
||||
void setAllowHDR(bool enable, bool is_game_specific = false);
|
||||
bool collectShadersForDebug();
|
||||
void setCollectShaderForDebug(bool enable, bool is_game_specific = false);
|
||||
bool showSplash();
|
||||
void setShowSplash(bool enable, bool is_game_specific = false);
|
||||
std::string sideTrophy();
|
||||
void setSideTrophy(std::string side, bool is_game_specific = false);
|
||||
bool nullGpu();
|
||||
void setNullGpu(bool enable, bool is_game_specific = false);
|
||||
bool copyGPUCmdBuffers();
|
||||
void setCopyGPUCmdBuffers(bool enable, bool is_game_specific = false);
|
||||
int getReadbacksMode();
|
||||
void setReadbacksMode(int mode, bool is_game_specific = false);
|
||||
bool readbackLinearImages();
|
||||
void setReadbackLinearImages(bool enable, bool is_game_specific = false);
|
||||
bool directMemoryAccess();
|
||||
void setDirectMemoryAccess(bool enable, bool is_game_specific = false);
|
||||
bool dumpShaders();
|
||||
void setDumpShaders(bool enable, bool is_game_specific = false);
|
||||
u32 vblankFreq();
|
||||
void setVblankFreq(u32 value, bool is_game_specific = false);
|
||||
bool getisTrophyPopupDisabled();
|
||||
void setisTrophyPopupDisabled(bool disable, bool is_game_specific = false);
|
||||
s16 getCursorState();
|
||||
void setCursorState(s16 cursorState, bool is_game_specific = false);
|
||||
bool vkValidationEnabled();
|
||||
void setVkValidation(bool enable, bool is_game_specific = false);
|
||||
bool vkValidationSyncEnabled();
|
||||
void setVkSyncValidation(bool enable, bool is_game_specific = false);
|
||||
bool vkValidationGpuEnabled();
|
||||
void setVkGpuValidation(bool enable, bool is_game_specific = false);
|
||||
bool vkValidationCoreEnabled();
|
||||
void setVkCoreValidation(bool enable, bool is_game_specific = false);
|
||||
bool getVkCrashDiagnosticEnabled();
|
||||
void setVkCrashDiagnosticEnabled(bool enable, bool is_game_specific = false);
|
||||
bool getVkHostMarkersEnabled();
|
||||
void setVkHostMarkersEnabled(bool enable, bool is_game_specific = false);
|
||||
bool getVkGuestMarkersEnabled();
|
||||
void setVkGuestMarkersEnabled(bool enable, bool is_game_specific = false);
|
||||
bool getEnableDiscordRPC();
|
||||
void setEnableDiscordRPC(bool enable);
|
||||
bool isRdocEnabled();
|
||||
bool isPipelineCacheEnabled();
|
||||
bool isPipelineCacheArchived();
|
||||
void setRdocEnabled(bool enable, bool is_game_specific = false);
|
||||
void setPipelineCacheEnabled(bool enable, bool is_game_specific = false);
|
||||
void setPipelineCacheArchived(bool enable, bool is_game_specific = false);
|
||||
|
||||
// Log
|
||||
bool isLogAppend();
|
||||
void setLogAppend(bool enable, bool is_game_specific = false);
|
||||
bool getLogEnable();
|
||||
void setLogEnable(bool enable, bool is_game_specific = false);
|
||||
std::string getLogFilter();
|
||||
void setLogFilter(const std::string& type, bool is_game_specific = false);
|
||||
u32 getLogMaxSkipDuration();
|
||||
void setLogMaxSkipDuration(u32 duration, bool is_game_specific = false);
|
||||
bool getLogSeparateLogFilesEnabled();
|
||||
void setLogSeparateLogFilesEnabled(bool enabled, bool is_game_specific = false);
|
||||
unsigned long long getLogSizeLimit();
|
||||
void setLogSizeLimit(unsigned long long size, bool is_game_specific = false);
|
||||
bool getLogSkipDuplicate();
|
||||
void setLogSkipDuplicate(bool enable, bool is_game_specific = false);
|
||||
bool isLogSync();
|
||||
void setLogSync(bool sync, bool is_game_specific = false);
|
||||
#ifdef _WIN32
|
||||
std::string getLogType();
|
||||
void setLogType(const std::string& type, bool is_game_specific = false);
|
||||
#endif
|
||||
|
||||
double getTrophyNotificationDuration();
|
||||
void setTrophyNotificationDuration(double newTrophyNotificationDuration,
|
||||
bool is_game_specific = false);
|
||||
int getCursorHideTimeout();
|
||||
std::string getMainOutputDevice();
|
||||
void setMainOutputDevice(std::string device, bool is_game_specific = false);
|
||||
std::string getPadSpkOutputDevice();
|
||||
void setPadSpkOutputDevice(std::string device, bool is_game_specific = false);
|
||||
std::string getMicDevice();
|
||||
void setCursorHideTimeout(int newcursorHideTimeout, bool is_game_specific = false);
|
||||
void setMicDevice(std::string device, bool is_game_specific = false);
|
||||
u32 GetLanguage();
|
||||
void setLanguage(u32 language, bool is_game_specific = false);
|
||||
void setUseSpecialPad(bool use);
|
||||
bool getUseSpecialPad();
|
||||
void setSpecialPadClass(int type);
|
||||
int getSpecialPadClass();
|
||||
bool getPSNSignedIn();
|
||||
void setPSNSignedIn(bool sign, bool is_game_specific = false);
|
||||
bool patchShaders(); // no set
|
||||
bool getShowFpsCounter();
|
||||
void setShowFpsCounter(bool enable, bool is_game_specific = false);
|
||||
bool isNeoModeConsole();
|
||||
void setNeoMode(bool enable, bool is_game_specific = false);
|
||||
bool isDevKitConsole();
|
||||
void setDevKitConsole(bool enable, bool is_game_specific = false);
|
||||
|
||||
int getExtraDmemInMbytes();
|
||||
void setExtraDmemInMbytes(int value, bool is_game_specific = false);
|
||||
bool getIsMotionControlsEnabled();
|
||||
void setIsMotionControlsEnabled(bool use, bool is_game_specific = false);
|
||||
std::string getDefaultControllerID();
|
||||
void setDefaultControllerID(std::string id);
|
||||
bool getBackgroundControllerInput();
|
||||
void setBackgroundControllerInput(bool enable, bool is_game_specific = false);
|
||||
bool getLoggingEnabled();
|
||||
void setLoggingEnabled(bool enable, bool is_game_specific = false);
|
||||
bool getFsrEnabled();
|
||||
void setFsrEnabled(bool enable, bool is_game_specific = false);
|
||||
bool getRcasEnabled();
|
||||
void setRcasEnabled(bool enable, bool is_game_specific = false);
|
||||
int getRcasAttenuation();
|
||||
void setRcasAttenuation(int value, bool is_game_specific = false);
|
||||
bool getIsConnectedToNetwork();
|
||||
void setConnectedToNetwork(bool enable, bool is_game_specific = false);
|
||||
void setUserName(const std::string& name, bool is_game_specific = false);
|
||||
std::filesystem::path getSysModulesPath();
|
||||
void setSysModulesPath(const std::filesystem::path& path);
|
||||
std::filesystem::path getFontsPath();
|
||||
void setFontsPath(const std::filesystem::path& path);
|
||||
|
||||
enum UsbBackendType : int { Real, SkylandersPortal, InfinityBase, DimensionsToypad };
|
||||
int getUsbDeviceBackend();
|
||||
void setUsbDeviceBackend(int value, bool is_game_specific = false);
|
||||
|
||||
// TODO
|
||||
std::filesystem::path GetSaveDataPath();
|
||||
std::string getUserName();
|
||||
bool GetUseUnifiedInputConfig();
|
||||
void SetUseUnifiedInputConfig(bool use);
|
||||
bool GetOverrideControllerColor();
|
||||
void SetOverrideControllerColor(bool enable);
|
||||
int* GetControllerCustomColor();
|
||||
void SetControllerCustomColor(int r, int b, int g);
|
||||
void setGameInstallDirs(const std::vector<std::filesystem::path>& dirs_config);
|
||||
void setAllGameInstallDirs(const std::vector<GameInstallDir>& dirs_config);
|
||||
void setSaveDataPath(const std::filesystem::path& path);
|
||||
// Gui
|
||||
bool addGameInstallDir(const std::filesystem::path& dir, bool enabled = true);
|
||||
void removeGameInstallDir(const std::filesystem::path& dir);
|
||||
void setGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled);
|
||||
void setAddonInstallDir(const std::filesystem::path& dir);
|
||||
|
||||
const std::vector<std::filesystem::path> getGameInstallDirs();
|
||||
const std::vector<bool> getGameInstallDirsEnabled();
|
||||
std::filesystem::path getAddonInstallDir();
|
||||
|
||||
void setDefaultValues(bool is_game_specific = false);
|
||||
|
||||
constexpr std::string_view GetDefaultGlobalConfig();
|
||||
std::filesystem::path GetInputConfigFile(const std::string& game_id = "");
|
||||
|
||||
}; // namespace Config
|
||||
@ -5,6 +5,8 @@
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <toml.hpp>
|
||||
#include "common/logging/formatter.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "key_manager.h"
|
||||
#include "path_util.h"
|
||||
@ -33,6 +35,40 @@ void KeyManager::SetInstance(std::shared_ptr<KeyManager> instance) {
|
||||
}
|
||||
|
||||
// ------------------- Load / Save -------------------
|
||||
bool KeyManager::TransferTrophyKey() {
|
||||
try {
|
||||
auto path = Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml";
|
||||
if (!std::filesystem::exists(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parse the old config
|
||||
std::ifstream ifs;
|
||||
ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
ifs.open(path, std::ios_base::binary);
|
||||
toml::value og_data =
|
||||
toml::parse(ifs, std::string{fmt::UTF(path.filename().u8string()).data});
|
||||
|
||||
// Retrieve old trophy key and store it.
|
||||
if (og_data.contains("Keys")) {
|
||||
const auto& keys = og_data.at("Keys").as_table();
|
||||
auto it = keys.find("TrophyKey");
|
||||
if (it == keys.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string old_key = toml::get<std::string>(it->second);
|
||||
if (!old_key.empty()) {
|
||||
m_keys.TrophyKeySet.ReleaseTrophyKey = KeyManager::HexStringToBytes(old_key);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (std::exception& ex) {
|
||||
fmt::print("Got exception trying to load config file. Exception: {}\n", ex.what());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool KeyManager::LoadFromFile() {
|
||||
try {
|
||||
const auto userDir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||
@ -40,6 +76,7 @@ bool KeyManager::LoadFromFile() {
|
||||
|
||||
if (!std::filesystem::exists(keysPath)) {
|
||||
SetDefaultKeys();
|
||||
TransferTrophyKey();
|
||||
SaveToFile();
|
||||
LOG_DEBUG(KeyManager, "Created default key file: {}", keysPath.string());
|
||||
return true;
|
||||
@ -56,8 +93,17 @@ bool KeyManager::LoadFromFile() {
|
||||
|
||||
SetDefaultKeys(); // start from defaults
|
||||
|
||||
if (j.contains("TrophyKeySet"))
|
||||
if (j.contains("TrophyKeySet")) {
|
||||
j.at("TrophyKeySet").get_to(m_keys.TrophyKeySet);
|
||||
}
|
||||
|
||||
if (m_keys.TrophyKeySet.ReleaseTrophyKey.empty()) {
|
||||
// No key, try to transfer it from the old configs
|
||||
if (TransferTrophyKey()) {
|
||||
// If we did transfer something, make sure to save it.
|
||||
SaveToFile();
|
||||
}
|
||||
}
|
||||
|
||||
LOG_DEBUG(KeyManager, "Successfully loaded keys from: {}", keysPath.string());
|
||||
return true;
|
||||
|
||||
@ -34,6 +34,7 @@ public:
|
||||
static void SetInstance(std::shared_ptr<KeyManager> instance);
|
||||
|
||||
// ------------------- File operations -------------------
|
||||
bool TransferTrophyKey();
|
||||
bool LoadFromFile();
|
||||
bool SaveToFile();
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
#include <fmt/std.h>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/config.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/logging/thread_name_formatter.h"
|
||||
#include "common/types.h"
|
||||
|
||||
16
src/main.cpp
16
src/main.cpp
@ -11,7 +11,6 @@
|
||||
|
||||
#include <core/emulator_settings.h>
|
||||
#include <core/emulator_state.h>
|
||||
#include "common/config.h"
|
||||
#include "common/key_manager.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/memory_patcher.h"
|
||||
@ -113,22 +112,9 @@ int main(int argc, char* argv[]) {
|
||||
EmulatorState::SetInstance(emu_state);
|
||||
UserSettings.Load();
|
||||
|
||||
const auto user_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||
Config::load(user_dir / "config.toml");
|
||||
|
||||
// ---- Trophy key migration ----
|
||||
// Initialize key manager
|
||||
auto key_manager = KeyManager::GetInstance();
|
||||
key_manager->LoadFromFile();
|
||||
if (key_manager->GetAllKeys().TrophyKeySet.ReleaseTrophyKey.empty() &&
|
||||
!Config::getTrophyKey().empty()) {
|
||||
auto keys = key_manager->GetAllKeys();
|
||||
if (keys.TrophyKeySet.ReleaseTrophyKey.empty() && !Config::getTrophyKey().empty()) {
|
||||
keys.TrophyKeySet.ReleaseTrophyKey =
|
||||
KeyManager::HexStringToBytes(Config::getTrophyKey());
|
||||
key_manager->SetAllKeys(keys);
|
||||
key_manager->SaveToFile();
|
||||
}
|
||||
}
|
||||
|
||||
// Load configurations
|
||||
std::shared_ptr<EmulatorSettingsImpl> emu_settings = std::make_shared<EmulatorSettingsImpl>();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user