From 7cb5dc0f4fdfe88a196505eaa710d25e7777d5f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quang=20Ng=C3=B4?= Date: Sun, 29 Dec 2024 12:02:39 +0700 Subject: [PATCH] config: Don't load config in the Emulator class Allows overriding of configs in frontends. Fix set fullscreen not working when specified in the CLI. Also add minor check to Qt to treat last CLI argument as game path (like what SDL version does currently). --- src/emulator.cpp | 4 ---- src/main.cpp | 5 +++++ src/qt_gui/main.cpp | 14 +++++++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/emulator.cpp b/src/emulator.cpp index 10d17a2db4a..dbe21a141fb 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -45,10 +45,6 @@ Frontend::WindowSDL* g_window = nullptr; namespace Core { Emulator::Emulator() { - // Read configuration file. - const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir); - Config::load(config_dir / "config.toml"); - // Initialize NT API functions and set high priority #ifdef _WIN32 Common::NtApi::Initialize(); diff --git a/src/main.cpp b/src/main.cpp index 17b5c11fe97..eee97a54294 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include #include "common/config.h" #include "common/memory_patcher.h" +#include "common/path_util.h" #include "emulator.h" #ifdef _WIN32 @@ -20,6 +21,10 @@ int main(int argc, char* argv[]) { SetConsoleOutputCP(CP_UTF8); #endif + // Load configurations and initialize Qt application + const auto user_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir); + Config::load(user_dir / "config.toml"); + bool has_game_argument = false; std::string game_path; diff --git a/src/qt_gui/main.cpp b/src/qt_gui/main.cpp index 318245053d1..a1a4ea7c143 100644 --- a/src/qt_gui/main.cpp +++ b/src/qt_gui/main.cpp @@ -31,7 +31,7 @@ int main(int argc, char* argv[]) { bool has_command_line_argument = argc > 1; bool show_gui = false, has_game_argument = false; - std::string gamePath; + std::string game_path; // Map of argument strings to lambda functions std::unordered_map> arg_map = { @@ -57,7 +57,7 @@ int main(int argc, char* argv[]) { {"-g", [&](int& i) { if (i + 1 < argc) { - gamePath = argv[++i]; + game_path = argv[++i]; has_game_argument = true; } else { std::cerr << "Error: Missing argument for -g/--game\n"; @@ -106,6 +106,10 @@ int main(int argc, char* argv[]) { auto it = arg_map.find(cur_arg); if (it != arg_map.end()) { it->second(i); // Call the associated lambda function + } else if (i == argc - 1 && !has_game_argument) { + // Assume the last argument is the game file if not specified via -g/--game + game_path = argv[i]; + has_game_argument = true; } else { std::cerr << "Unknown argument: " << cur_arg << ", see --help for info.\n"; return 1; @@ -134,14 +138,14 @@ int main(int argc, char* argv[]) { // Process game path or ID if provided if (has_game_argument) { - std::filesystem::path game_file_path(gamePath); + std::filesystem::path game_file_path(game_path); // Check if the provided path is a valid file if (!std::filesystem::exists(game_file_path)) { // If not a file, treat it as a game ID and search in install directories bool game_found = false; for (const auto& install_dir : Config::getGameInstallDirs()) { - auto potential_game_path = install_dir / gamePath / "eboot.bin"; + auto potential_game_path = install_dir / game_path / "eboot.bin"; if (std::filesystem::exists(potential_game_path)) { game_file_path = potential_game_path; game_found = true; @@ -149,7 +153,7 @@ int main(int argc, char* argv[]) { } } if (!game_found) { - std::cerr << "Error: Game ID or file path not found: " << gamePath << std::endl; + std::cerr << "Error: Game ID or file path not found: " << game_path << std::endl; return 1; } }