Skip to content

Commit

Permalink
config: Don't load config in the Emulator class
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
ngoquang2708 committed Dec 29, 2024
1 parent 122fe22 commit 7cb5dc0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 0 additions & 4 deletions src/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <fmt/core.h>
#include "common/config.h"
#include "common/memory_patcher.h"
#include "common/path_util.h"
#include "emulator.h"

#ifdef _WIN32
Expand All @@ -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;

Expand Down
14 changes: 9 additions & 5 deletions src/qt_gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::function<void(int&)>> arg_map = {
Expand All @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -134,22 +138,22 @@ 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;
break;
}
}
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;
}
}
Expand Down

0 comments on commit 7cb5dc0

Please sign in to comment.