Add CLI argument to launch the emulator with global config or with default settings (#3688)

* --config-clean, --config-global

* copyright 2025

* fine you win

* copyright 2024
This commit is contained in:
kalaposfos13
2025-10-01 21:28:34 +02:00
committed by GitHub
parent af147debc6
commit 74c0ea8432
4 changed files with 39 additions and 4 deletions

View File

@@ -8,6 +8,7 @@
#include <fmt/xchar.h> // for wstring support
#include <toml.hpp>
#include "common/assert.h"
#include "common/config.h"
#include "common/logging/formatter.h"
#include "common/path_util.h"
@@ -74,18 +75,34 @@ std::optional<T> get_optional(const toml::value& v, const std::string& key) {
namespace Config {
ConfigMode config_mode = ConfigMode::Default;
void setConfigMode(ConfigMode mode) {
config_mode = mode;
}
template <typename T>
class ConfigEntry {
public:
const T default_value;
T base_value;
optional<T> game_specific_value;
ConfigEntry(const T& t = T()) : base_value(t), game_specific_value(nullopt) {}
ConfigEntry(const T& t = T()) : default_value(t), base_value(t), game_specific_value(nullopt) {}
ConfigEntry operator=(const T& t) {
base_value = t;
return *this;
}
const T get() const {
return game_specific_value.has_value() ? *game_specific_value : base_value;
switch (config_mode) {
case ConfigMode::Default:
return game_specific_value.value_or(base_value);
case ConfigMode::Global:
return base_value;
case ConfigMode::Clean:
return default_value;
default:
UNREACHABLE();
}
}
void setFromToml(const toml::value& v, const std::string& key, bool is_game_specific = false) {
if (is_game_specific) {

View File

@@ -9,6 +9,13 @@
namespace Config {
enum class ConfigMode {
Default,
Global,
Clean,
};
void setConfigMode(ConfigMode mode);
struct GameInstallDir {
std::filesystem::path path;
bool enabled;

View File

@@ -62,6 +62,10 @@ int main(int argc, char* argv[]) {
"parent of game path\n"
" --wait-for-debugger Wait for debugger to attach\n"
" --wait-for-pid <pid> Wait for process with specified PID to stop\n"
" --config-clean Run the emulator with the default config "
"values, ignores the config file(s) entirely.\n"
" --config-global Run the emulator with the base config file "
"only, ignores game specific configs.\n"
" -h, --help Display this help message\n";
exit(0);
}},
@@ -151,6 +155,8 @@ int main(int argc, char* argv[]) {
exit(0);
}},
{"--log-append", [&](int& i) { Common::Log::SetAppend(); }},
{"--config-clean", [&](int& i) { Config::setConfigMode(Config::ConfigMode::Clean); }},
{"--config-global", [&](int& i) { Config::setConfigMode(Config::ConfigMode::Global); }},
{"--override-root",
[&](int& i) {
if (++i >= argc) {
@@ -249,7 +255,6 @@ int main(int argc, char* argv[]) {
// Run the emulator with the resolved eboot path
Core::Emulator* emulator = Common::Singleton<Core::Emulator>::Instance();
emulator->executableName = argv[0];
emulator->waitForDebuggerBeforeRun = waitForDebugger;
emulator->Run(eboot_path, game_args, game_folder);
return 0;

View File

@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "iostream"
@@ -68,6 +68,10 @@ int main(int argc, char* argv[]) {
"parent of game path\n"
" --wait-for-debugger Wait for debugger to attach\n"
" --wait-for-pid <pid> Wait for process with specified PID to stop\n"
" --config-clean Run the emulator with the default config "
"values, ignores the config file(s) entirely.\n"
" --config-global Run the emulator with the base config file "
"only, ignores game specific configs.\n"
" -h, --help Display this help message\n";
exit(0);
}},
@@ -142,6 +146,8 @@ int main(int argc, char* argv[]) {
exit(0);
}},
{"--log-append", [&](int& i) { Common::Log::SetAppend(); }},
{"--config-clean", [&](int& i) { Config::setConfigMode(Config::ConfigMode::Clean); }},
{"--config-global", [&](int& i) { Config::setConfigMode(Config::ConfigMode::Global); }},
{"--override-root",
[&](int& i) {
if (++i >= argc) {