mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-12-09 21:31:04 +00:00
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:
@@ -8,6 +8,7 @@
|
|||||||
#include <fmt/xchar.h> // for wstring support
|
#include <fmt/xchar.h> // for wstring support
|
||||||
#include <toml.hpp>
|
#include <toml.hpp>
|
||||||
|
|
||||||
|
#include "common/assert.h"
|
||||||
#include "common/config.h"
|
#include "common/config.h"
|
||||||
#include "common/logging/formatter.h"
|
#include "common/logging/formatter.h"
|
||||||
#include "common/path_util.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 {
|
namespace Config {
|
||||||
|
|
||||||
|
ConfigMode config_mode = ConfigMode::Default;
|
||||||
|
|
||||||
|
void setConfigMode(ConfigMode mode) {
|
||||||
|
config_mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class ConfigEntry {
|
class ConfigEntry {
|
||||||
public:
|
public:
|
||||||
|
const T default_value;
|
||||||
T base_value;
|
T base_value;
|
||||||
optional<T> game_specific_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) {
|
ConfigEntry operator=(const T& t) {
|
||||||
base_value = t;
|
base_value = t;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
const T get() const {
|
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) {
|
void setFromToml(const toml::value& v, const std::string& key, bool is_game_specific = false) {
|
||||||
if (is_game_specific) {
|
if (is_game_specific) {
|
||||||
|
|||||||
@@ -9,6 +9,13 @@
|
|||||||
|
|
||||||
namespace Config {
|
namespace Config {
|
||||||
|
|
||||||
|
enum class ConfigMode {
|
||||||
|
Default,
|
||||||
|
Global,
|
||||||
|
Clean,
|
||||||
|
};
|
||||||
|
void setConfigMode(ConfigMode mode);
|
||||||
|
|
||||||
struct GameInstallDir {
|
struct GameInstallDir {
|
||||||
std::filesystem::path path;
|
std::filesystem::path path;
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
|||||||
@@ -62,6 +62,10 @@ int main(int argc, char* argv[]) {
|
|||||||
"parent of game path\n"
|
"parent of game path\n"
|
||||||
" --wait-for-debugger Wait for debugger to attach\n"
|
" --wait-for-debugger Wait for debugger to attach\n"
|
||||||
" --wait-for-pid <pid> Wait for process with specified PID to stop\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";
|
" -h, --help Display this help message\n";
|
||||||
exit(0);
|
exit(0);
|
||||||
}},
|
}},
|
||||||
@@ -151,6 +155,8 @@ int main(int argc, char* argv[]) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}},
|
}},
|
||||||
{"--log-append", [&](int& i) { Common::Log::SetAppend(); }},
|
{"--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",
|
{"--override-root",
|
||||||
[&](int& i) {
|
[&](int& i) {
|
||||||
if (++i >= argc) {
|
if (++i >= argc) {
|
||||||
@@ -249,7 +255,6 @@ int main(int argc, char* argv[]) {
|
|||||||
// Run the emulator with the resolved eboot path
|
// Run the emulator with the resolved eboot path
|
||||||
Core::Emulator* emulator = Common::Singleton<Core::Emulator>::Instance();
|
Core::Emulator* emulator = Common::Singleton<Core::Emulator>::Instance();
|
||||||
emulator->executableName = argv[0];
|
emulator->executableName = argv[0];
|
||||||
emulator->waitForDebuggerBeforeRun = waitForDebugger;
|
|
||||||
emulator->Run(eboot_path, game_args, game_folder);
|
emulator->Run(eboot_path, game_args, game_folder);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -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
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "iostream"
|
#include "iostream"
|
||||||
@@ -68,6 +68,10 @@ int main(int argc, char* argv[]) {
|
|||||||
"parent of game path\n"
|
"parent of game path\n"
|
||||||
" --wait-for-debugger Wait for debugger to attach\n"
|
" --wait-for-debugger Wait for debugger to attach\n"
|
||||||
" --wait-for-pid <pid> Wait for process with specified PID to stop\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";
|
" -h, --help Display this help message\n";
|
||||||
exit(0);
|
exit(0);
|
||||||
}},
|
}},
|
||||||
@@ -142,6 +146,8 @@ int main(int argc, char* argv[]) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
}},
|
}},
|
||||||
{"--log-append", [&](int& i) { Common::Log::SetAppend(); }},
|
{"--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",
|
{"--override-root",
|
||||||
[&](int& i) {
|
[&](int& i) {
|
||||||
if (++i >= argc) {
|
if (++i >= argc) {
|
||||||
|
|||||||
Reference in New Issue
Block a user