From d633a266c19f839cf8ae9274d0c38841cf2cc1e4 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Mon, 3 Aug 2020 15:17:44 +0200 Subject: [PATCH] Add config override as cli arg: --config And add some more logging --- rpcs3/Emu/System.cpp | 48 ++++++++++++++++++++++++++++++++++---------- rpcs3/Emu/System.h | 3 +++ rpcs3/main.cpp | 40 +++++++++++++++++++++++++++++------- rpcs3/util/yaml.cpp | 2 +- 4 files changed, 74 insertions(+), 19 deletions(-) diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index b93d4b4d5a..362862815c 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -122,21 +122,47 @@ void Emulator::Init() g_cfg.from_default(); g_cfg_defaults = g_cfg.to_string(); - // Reload global configuration - const auto cfg_path = fs::get_config_dir() + "/config.yml"; - - if (const fs::file cfg_file{cfg_path, fs::read + fs::create}) + // Reload override configuration set via command line + if (!m_config_override_path.empty()) { - if (!g_cfg.from_string(cfg_file.to_string())) + if (const fs::file cfg_file{m_config_override_path, fs::read + fs::create}) { - sys_log.fatal("Failed to apply global config: %s", cfg_path); + if (!g_cfg.from_string(cfg_file.to_string())) + { + sys_log.fatal("Failed to apply config override: %s. Proceeding with regular configuration.", m_config_override_path); + m_config_override_path.clear(); + } + else + { + sys_log.success("Applied config override: %s", m_config_override_path); + g_cfg.name = m_config_override_path; + } + } + else + { + sys_log.fatal("Failed to access config override: %s (%s). Proceeding with regular configuration.", m_config_override_path, fs::g_tls_error); + m_config_override_path.clear(); } - - g_cfg.name = cfg_path; } - else + + // Reload global configuration + if (m_config_override_path.empty()) { - sys_log.fatal("Failed to access global config: %s (%s)", cfg_path, fs::g_tls_error); + const auto cfg_path = fs::get_config_dir() + "/config.yml"; + + if (const fs::file cfg_file{cfg_path, fs::read + fs::create}) + { + if (!g_cfg.from_string(cfg_file.to_string())) + { + sys_log.fatal("Failed to apply global config: %s", cfg_path); + } + + g_cfg.name = cfg_path; + } + else + { + sys_log.fatal("Failed to access global config: %s (%s)", cfg_path, fs::g_tls_error); + } } // Create directories (can be disabled if necessary) @@ -868,7 +894,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool sys_log.notice("Category: %s", GetCat()); sys_log.notice("Version: %s / %s", GetAppVersion(), version_disc); - if (!add_only && !force_global_config) + if (!add_only && !force_global_config && m_config_override_path.empty()) { const std::string config_path_new = GetCustomConfigPath(m_title_id); const std::string config_path_old = GetCustomConfigPath(m_title_id, true); diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 122b960e98..78abe687ad 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -60,6 +60,7 @@ class Emulator final atomic_t m_pause_start_time{0}; // set when paused atomic_t m_pause_amend_time{0}; // increased when resumed + std::string m_config_override_path; std::string m_path; std::string m_path_old; std::string m_title_id; @@ -213,6 +214,8 @@ public: bool HasGui() const { return m_has_gui; } void SetHasGui(bool has_gui) { m_has_gui = has_gui; } + void SetConfigOverride(std::string path) { m_config_override_path = std::move(path); } + std::string GetFormattedTitle(double fps) const; u32 GetMaxThreads() const; diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index 1948b5912a..00e379de65 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -171,6 +171,7 @@ const char* arg_rounding = "dpi-rounding"; const char* arg_styles = "styles"; const char* arg_style = "style"; const char* arg_stylesheet = "stylesheet"; +const char* arg_config = "config"; const char* arg_error = "error"; const char* arg_updating = "updating"; @@ -405,8 +406,8 @@ int main(int argc, char** argv) parser.addPositionalArgument("(S)ELF", "Path for directly executing a (S)ELF"); parser.addPositionalArgument("[Args...]", "Optional args for the executable"); - const QCommandLineOption helpOption = parser.addHelpOption(); - const QCommandLineOption versionOption = parser.addVersionOption(); + const QCommandLineOption help_option = parser.addHelpOption(); + const QCommandLineOption version_option = parser.addVersionOption(); parser.addOption(QCommandLineOption(arg_headless, "Run RPCS3 in headless mode.")); parser.addOption(QCommandLineOption(arg_no_gui, "Run RPCS3 without its GUI.")); parser.addOption(QCommandLineOption(arg_high_dpi, "Enables Qt High Dpi Scaling.", "enabled", "1")); @@ -414,11 +415,14 @@ int main(int argc, char** argv) parser.addOption(QCommandLineOption(arg_styles, "Lists the available styles.")); parser.addOption(QCommandLineOption(arg_style, "Loads a custom style.", "style", "")); parser.addOption(QCommandLineOption(arg_stylesheet, "Loads a custom stylesheet.", "path", "")); + const QCommandLineOption config_option(arg_config, "Forces the emulator to use this configuration file.", "path", ""); + parser.addOption(config_option); + parser.addOption(QCommandLineOption(arg_error, "For internal usage.")); parser.addOption(QCommandLineOption(arg_updating, "For internal usage.")); parser.process(app->arguments()); // Don't start up the full rpcs3 gui if we just want the version or help. - if (parser.isSet(versionOption) || parser.isSet(helpOption)) + if (parser.isSet(version_option) || parser.isSet(help_option)) return 0; if (parser.isSet(arg_styles)) @@ -460,10 +464,30 @@ int main(int argc, char** argv) } #endif - QStringList args = parser.positionalArguments(); + std::string config_override_path; - if (args.length() > 0) + if (parser.isSet(arg_config)) { + config_override_path = parser.value(config_option).toStdString(); + + if (!fs::is_file(config_override_path)) + { + report_fatal_error(fmt::format("No config file found: %s", config_override_path)); + return 0; + } + + Emu.SetConfigOverride(config_override_path); + } + + for (const auto& opt : parser.optionNames()) + { + sys_log.notice("Option passed via command line: %s = %s", opt.toStdString(), parser.value(opt).toStdString()); + } + + if (const QStringList args = parser.positionalArguments(); !args.isEmpty()) + { + sys_log.notice("Booting application from command line: %s", args.at(0).toStdString()); + // Propagate command line arguments std::vector argv; @@ -473,12 +497,14 @@ int main(int argc, char** argv) for (int i = 1; i < args.length(); i++) { - argv.emplace_back(args[i].toStdString()); + const std::string arg = args[i].toStdString(); + argv.emplace_back(arg); + sys_log.notice("Optional command line argument %d: %s", i, arg); } } // Ugly workaround - QTimer::singleShot(2, [path = sstr(QFileInfo(args.at(0)).absoluteFilePath()), argv = std::move(argv)]() mutable + QTimer::singleShot(2, [config_override_path, path = sstr(QFileInfo(args.at(0)).absoluteFilePath()), argv = std::move(argv)]() mutable { Emu.argv = std::move(argv); Emu.SetForceBoot(true); diff --git a/rpcs3/util/yaml.cpp b/rpcs3/util/yaml.cpp index 1f0716c02a..40e940f2fa 100644 --- a/rpcs3/util/yaml.cpp +++ b/rpcs3/util/yaml.cpp @@ -38,7 +38,7 @@ std::pair yaml_load(const std::string& from) } catch(const std::exception& e) { - return{YAML::Node(), std::string("YAML exception:\n") + e.what()}; + return{YAML::Node(), std::string("YAML exception: ") + e.what()}; } return{result, ""};