more settings porting

This commit is contained in:
georgemoralis
2025-11-27 17:08:55 +02:00
parent f54367734d
commit f952d375a4
10 changed files with 54 additions and 132 deletions

View File

@@ -133,10 +133,8 @@ static ConfigEntry<int> volumeSlider(100);
static ConfigEntry<string> logFilter("");
static ConfigEntry<string> logType("sync");
static ConfigEntry<string> userName("shadPS4");
static ConfigEntry<bool> isShowSplash(false);
static ConfigEntry<bool> isConnectedToNetwork(false);
static bool enableDiscordRPC = false;
static std::filesystem::path sys_modules_path = {};
// Input
static ConfigEntry<int> cursorState(HideCursorState::Idle);
@@ -194,7 +192,6 @@ static ConfigEntry<bool> logEnabled(true);
// GUI
static std::vector<GameInstallDir> settings_install_dirs = {};
std::vector<bool> install_dirs_enabled = {};
std::filesystem::path settings_addon_install_dir = {};
std::filesystem::path save_data_path = {};
// Settings
@@ -223,17 +220,6 @@ void setGameRunning(bool running) {
isGameRunning = running;
}
std::filesystem::path getSysModulesPath() {
if (sys_modules_path.empty()) {
return Common::FS::GetUserPath(Common::FS::PathType::SysModuleDir);
}
return sys_modules_path;
}
void setSysModulesPath(const std::filesystem::path& path) {
sys_modules_path = path;
}
int getVolumeSlider() {
return volumeSlider.get();
}
@@ -378,10 +364,6 @@ bool collectShadersForDebug() {
return isShaderDebug.get();
}
bool showSplash() {
return isShowSplash.get();
}
bool nullGpu() {
return isNullGpu.get();
}
@@ -509,10 +491,6 @@ void setCollectShaderForDebug(bool enable, bool is_game_specific) {
isShaderDebug.set(enable, is_game_specific);
}
void setShowSplash(bool enable, bool is_game_specific) {
isShowSplash.set(enable, is_game_specific);
}
void setNullGpu(bool enable, bool is_game_specific) {
isNullGpu.set(enable, is_game_specific);
}
@@ -577,7 +555,6 @@ void setPresentMode(std::string mode, bool is_game_specific) {
presentMode.set(mode, is_game_specific);
}
void setEnableDiscordRPC(bool enable) {
enableDiscordRPC = enable;
}
@@ -630,79 +607,10 @@ void setIsMotionControlsEnabled(bool use, bool is_game_specific) {
isMotionControlsEnabled.set(use, is_game_specific);
}
bool addGameInstallDir(const std::filesystem::path& dir, bool enabled) {
for (const auto& install_dir : settings_install_dirs) {
if (install_dir.path == dir) {
return false;
}
}
settings_install_dirs.push_back({dir, enabled});
return true;
}
void removeGameInstallDir(const std::filesystem::path& dir) {
auto iterator =
std::find_if(settings_install_dirs.begin(), settings_install_dirs.end(),
[&dir](const GameInstallDir& install_dir) { return install_dir.path == dir; });
if (iterator != settings_install_dirs.end()) {
settings_install_dirs.erase(iterator);
}
}
void setGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled) {
auto iterator =
std::find_if(settings_install_dirs.begin(), settings_install_dirs.end(),
[&dir](const GameInstallDir& install_dir) { return install_dir.path == dir; });
if (iterator != settings_install_dirs.end()) {
iterator->enabled = enabled;
}
}
void setAddonInstallDir(const std::filesystem::path& dir) {
settings_addon_install_dir = dir;
}
void setGameInstallDirs(const std::vector<std::filesystem::path>& dirs_config) {
settings_install_dirs.clear();
for (const auto& dir : dirs_config) {
settings_install_dirs.push_back({dir, true});
}
}
void setAllGameInstallDirs(const std::vector<GameInstallDir>& dirs_config) {
settings_install_dirs = dirs_config;
}
void setSaveDataPath(const std::filesystem::path& path) {
save_data_path = path;
}
const std::vector<std::filesystem::path> getGameInstallDirs() {
std::vector<std::filesystem::path> enabled_dirs;
for (const auto& dir : settings_install_dirs) {
if (dir.enabled) {
enabled_dirs.push_back(dir.path);
}
}
return enabled_dirs;
}
const std::vector<bool> getGameInstallDirsEnabled() {
std::vector<bool> enabled_dirs;
for (const auto& dir : settings_install_dirs) {
enabled_dirs.push_back(dir.enabled);
}
return enabled_dirs;
}
std::filesystem::path getAddonInstallDir() {
if (settings_addon_install_dir.empty()) {
// Default for users without a config file or a config file from before this option existed
return Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "addcont";
}
return settings_addon_install_dir;
}
u32 GetLanguage() {
return m_language.get();
}
@@ -792,12 +700,8 @@ void load(const std::filesystem::path& path, bool is_game_specific) {
logFilter.setFromToml(general, "logFilter", is_game_specific);
logType.setFromToml(general, "logType", is_game_specific);
userName.setFromToml(general, "userName", is_game_specific);
isShowSplash.setFromToml(general, "showSplash", is_game_specific);
isConnectedToNetwork.setFromToml(general, "isConnectedToNetwork", is_game_specific);
defaultControllerID.setFromToml(general, "defaultControllerID", is_game_specific);
sys_modules_path = toml::find_fs_path_or(general, "sysModulesPath", sys_modules_path);
}
if (data.contains("Input")) {
@@ -894,9 +798,6 @@ void load(const std::filesystem::path& path, bool is_game_specific) {
}
save_data_path = toml::find_fs_path_or(gui, "saveDataPath", save_data_path);
settings_addon_install_dir =
toml::find_fs_path_or(gui, "addonInstallDir", settings_addon_install_dir);
}
if (data.contains("Settings")) {
@@ -972,7 +873,6 @@ void save(const std::filesystem::path& path, bool is_game_specific) {
logFilter.setTomlValue(data, "General", "logFilter", is_game_specific);
logType.setTomlValue(data, "General", "logType", is_game_specific);
userName.setTomlValue(data, "General", "userName", is_game_specific);
isShowSplash.setTomlValue(data, "General", "showSplash", is_game_specific);
isConnectedToNetwork.setTomlValue(data, "General", "isConnectedToNetwork", is_game_specific);
cursorState.setTomlValue(data, "Input", "cursorState", is_game_specific);
@@ -1052,12 +952,9 @@ void save(const std::filesystem::path& path, bool is_game_specific) {
// Non game-specific entries
data["General"]["enableDiscordRPC"] = enableDiscordRPC;
data["General"]["sysModulesPath"] = string{fmt::UTF(sys_modules_path.u8string()).data};
data["GUI"]["installDirs"] = install_dirs;
data["GUI"]["installDirsEnabled"] = install_dirs_enabled;
data["GUI"]["saveDataPath"] = string{fmt::UTF(save_data_path.u8string()).data};
data["GUI"]["addonInstallDir"] =
string{fmt::UTF(settings_addon_install_dir.u8string()).data};
data["Debug"]["ConfigVersion"] = config_version;
data["Keys"]["TrophyKey"] = trophyKey;
@@ -1097,8 +994,6 @@ void setDefaultValues(bool is_game_specific) {
logFilter.set("", is_game_specific);
logType.set("sync", is_game_specific);
userName.set("shadPS4", is_game_specific);
isShowSplash.set(false, is_game_specific);
// GS - Input
cursorState.set(HideCursorState::Idle, is_game_specific);

View File

@@ -55,8 +55,6 @@ 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);
bool nullGpu();
void setNullGpu(bool enable, bool is_game_specific = false);
bool copyGPUCmdBuffers();
@@ -128,8 +126,6 @@ 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);
bool getLoadAutoPatches();
void setLoadAutoPatches(bool enable);
@@ -146,18 +142,7 @@ 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);

View File

@@ -506,7 +506,7 @@ enum PosixPageProtection {
struct AddressSpace::Impl {
Impl() {
BackingSize += Config::getExtraDmemInMbytes() * 1_MB;
BackingSize += EmulatorSettings::GetInstance()->GetExtraDmemInMBytes() * 1_MB;
// Allocate virtual address placeholder for our address space.
system_managed_size = SystemManagedSize;
system_reserved_size = SystemReservedSize;

View File

@@ -11,6 +11,7 @@
#include "common/config.h"
#include "common/elf_info.h"
#include "common/path_util.h"
#include "core/emulator_settings.h"
namespace Core::Devtools::Widget {
@@ -23,7 +24,7 @@ public:
bool open = false;
static bool IsSystemModule(const std::filesystem::path& path) {
const auto sys_modules_path = Config::getSysModulesPath();
const auto sys_modules_path = EmulatorSettings::GetInstance()->GetSysModulesDir();
const auto abs_path = std::filesystem::absolute(path).lexically_normal();
const auto abs_sys_path = std::filesystem::absolute(sys_modules_path).lexically_normal();

View File

@@ -82,6 +82,39 @@ void EmulatorSettings::SetAllGameInstallDirs(const std::vector<GameInstallDir>&
m_general.install_dirs.value = dirs;
}
void EmulatorSettings::RemoveGameInstallDir(const std::filesystem::path& dir) {
auto iterator =
std::find_if(m_general.install_dirs.value.begin(), m_general.install_dirs.value.end(),
[&dir](const GameInstallDir& install_dir) { return install_dir.path == dir; });
if (iterator != m_general.install_dirs.value.end()) {
m_general.install_dirs.value.erase(iterator);
}
}
void EmulatorSettings::SetGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled) {
auto iterator =
std::find_if(m_general.install_dirs.value.begin(), m_general.install_dirs.value.end(),
[&dir](const GameInstallDir& install_dir) { return install_dir.path == dir; });
if (iterator != m_general.install_dirs.value.end()) {
iterator->enabled = enabled;
}
}
void EmulatorSettings::SetGameInstallDirs(const std::vector<std::filesystem::path>& dirs_config) {
m_general.install_dirs.value.clear();
for (const auto& dir : dirs_config) {
m_general.install_dirs.value.push_back({dir, true});
}
}
const std::vector<bool> EmulatorSettings::GetGameInstallDirsEnabled() {
std::vector<bool> enabled_dirs;
for (const auto& dir : m_general.install_dirs.value) {
enabled_dirs.push_back(dir.enabled);
}
return enabled_dirs;
}
std::filesystem::path EmulatorSettings::GetHomeDir() {
if (m_general.home_dir.value.empty()) {
return Common::FS::GetUserPath(Common::FS::PathType::HomeDir);

View File

@@ -264,6 +264,11 @@ public:
bool AddGameInstallDir(const std::filesystem::path& dir, bool enabled = true);
std::vector<std::filesystem::path> GetGameInstallDirs() const;
void SetAllGameInstallDirs(const std::vector<GameInstallDir>& dirs);
void RemoveGameInstallDir(const std::filesystem::path& dir);
void SetGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled);
void SetGameInstallDirs(const std::vector<std::filesystem::path>& dirs_config);
const std::vector<bool> GetGameInstallDirsEnabled();
std::filesystem::path GetHomeDir();
void SetHomeDir(const std::filesystem::path& dir);
std::filesystem::path GetSysModulesDir();
@@ -325,7 +330,8 @@ public:
SETTING_FORWARD_BOOL(m_general, PSNSignedIn, psn_signed_in)
SETTING_FORWARD_BOOL(m_general, TrophyPopupDisabled, trophy_popup_disabled)
SETTING_FORWARD(m_general, TrophyNotificationDuration, trophy_notification_duration)
SETTING_FORWARD(m_general, GetTrophyNotificationSide, trophy_notification_side)
SETTING_FORWARD(m_general, TrophyNotificationSide, trophy_notification_side)
SETTING_FORWARD_BOOL(m_general, ShowSplash, show_splash)
SETTING_FORWARD(m_general, AddonInstallDir, addon_install_dir)
// Debug settings

View File

@@ -13,6 +13,7 @@
#include "core/libraries/app_content/app_content_error.h"
#include "core/libraries/libs.h"
#include "core/libraries/system/systemservice.h"
#include "core/emulator_settings.h"
namespace Libraries::AppContent {
@@ -57,7 +58,7 @@ int PS4_SYSV_ABI sceAppContentAddcontMount(u32 service_label,
OrbisAppContentMountPoint* mount_point) {
LOG_INFO(Lib_AppContent, "called");
const auto& addon_path = Config::getAddonInstallDir() / title_id;
const auto& addon_path = EmulatorSettings::GetInstance()->GetAddonInstallDir() / title_id;
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
// Determine which loaded additional content this entitlement label is for.
@@ -282,7 +283,7 @@ int PS4_SYSV_ABI sceAppContentInitialize(const OrbisAppContentInitParam* initPar
LOG_ERROR(Lib_AppContent, "(DUMMY) called");
auto* param_sfo = Common::Singleton<PSF>::Instance();
const auto addons_dir = Config::getAddonInstallDir();
const auto addons_dir = EmulatorSettings::GetInstance()->GetAddonInstallDir();
if (const auto value = param_sfo->GetString("TITLE_ID"); value.has_value()) {
title_id = *value;
} else {

View File

@@ -4,6 +4,7 @@
#include "common/config.h"
#include "common/logging/log.h"
#include "common/singleton.h"
#include "core/emulator_settings.h"
#include "core/file_sys/fs.h"
#include "core/libraries/libs.h"
#include "core/libraries/system/systemservice.h"
@@ -17,7 +18,7 @@ std::queue<OrbisSystemServiceEvent> g_event_queue;
std::mutex g_event_queue_mutex;
bool IsSplashVisible() {
return Config::showSplash() && g_splash_status;
return EmulatorSettings::GetInstance()->IsShowSplash() && g_splash_status;
}
int PS4_SYSV_ABI sceAppMessagingClearEventFlag() {

View File

@@ -508,7 +508,7 @@ void Emulator::LoadSystemModules(const std::string& game_serial) {
{"libSceFreeTypeOt.sprx", nullptr}});
std::vector<std::filesystem::path> found_modules;
const auto& sys_module_path = Config::getSysModulesPath();
const auto& sys_module_path = EmulatorSettings::GetInstance()->GetSysModulesDir();
for (const auto& entry : std::filesystem::directory_iterator(sys_module_path)) {
found_modules.push_back(entry.path());
}

View File

@@ -134,7 +134,7 @@ int main(int argc, char* argv[]) {
exit(1);
}
Config::addGameInstallDir(config_path);
EmulatorSettings::GetInstance()->AddGameInstallDir(config_path);
Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml");
std::cout << "Game folder successfully saved.\n";
exit(0);
@@ -153,8 +153,8 @@ int main(int argc, char* argv[]) {
exit(1);
}
Config::setAddonInstallDir(config_path);
Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml");
EmulatorSettings::GetInstance()->SetAddonInstallDir(config_path);
EmulatorSettings::GetInstance()->Save();
std::cout << "Addon folder successfully saved.\n";
exit(0);
}},
@@ -220,7 +220,7 @@ int main(int argc, char* argv[]) {
}
// If no game directory is set and no command line argument, prompt for it
if (Config::getGameInstallDirs().empty()) {
if (EmulatorSettings::GetInstance()->GetGameInstallDirs().empty()) {
std::cerr << "Warning: No game folder set, please set it by calling shadps4"
" with the --add-game-folder <folder_name> argument\n";
}
@@ -238,7 +238,7 @@ int main(int argc, char* argv[]) {
// If not a file, treat it as a game ID and search in install directories recursively
bool game_found = false;
const int max_depth = 5;
for (const auto& install_dir : Config::getGameInstallDirs()) {
for (const auto& install_dir : EmulatorSettings::GetInstance()->GetGameInstallDirs()) {
if (auto found_path = Common::FS::FindGameByID(install_dir, game_path, max_depth)) {
eboot_path = *found_path;
game_found = true;