Skip to content

Commit

Permalink
Added --fullscreen <true|false> argument
Browse files Browse the repository at this point in the history
  • Loading branch information
kalaposfos13 committed Nov 10, 2024
1 parent 3ddba20 commit beea900
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
31 changes: 29 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "unordered_map"

#include <fmt/core.h>
#include "common/config.h"
#include "common/memory_patcher.h"
#include "emulator.h"

Expand Down Expand Up @@ -57,6 +58,27 @@ int main(int argc, char* argv[]) {
}
}},
{"--patch", [&](int& i) { arg_map["-p"](i); }},
{"-f",
[&](int& i) {
if (++i >= argc) {
std::cerr << "Error: Missing argument for -f/--fullscreen\n";
exit(1);
}
std::string f_param(argv[i]);
bool is_fullscreen;
if (f_param == "true") {
is_fullscreen = true;
} else if (f_param == "false") {
is_fullscreen = false;
} else {
std::cerr
<< "Error: Invalid argument for -f/--fullscreen. Use 'true' or 'false'.\n";
exit(1);
}
// Set fullscreen mode without saving it to config file
Config::setFullscreenMode(is_fullscreen);
}},
{"--fullscreen", [&](int& i) { arg_map["-f"](i); }},
};

if (argc == 1) {
Expand All @@ -76,13 +98,18 @@ int main(int argc, char* argv[]) {
game_path = argv[i];
has_game_argument = true;
} else {
std::cerr << "Unknown argument: " << cur_arg << "\n";
std::cerr << "Unknown argument: " << cur_arg << ", see --help for info.\n";
return 1;
}
}

if (!has_game_argument) {
std::cerr << "Error: Please provide a game path or ID.\n";
exit(1);
}

// Check if the game path or ID exists
if (!has_game_argument || !std::filesystem::exists(game_path)) {
if (!std::filesystem::exists(game_path)) {
std::cerr << "Error: Game file not found\n";
return -1;
}
Expand Down
28 changes: 27 additions & 1 deletion src/qt_gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ int main(int argc, char* argv[]) {
}
}},
{"--patch", [&](int& i) { arg_map["-p"](i); }},
{"-f",
[&](int& i) {
if (++i >= argc) {
std::cerr << "Error: Missing argument for -f/--fullscreen\n";
exit(1);
}
std::string f_param(argv[i]);
bool is_fullscreen;
if (f_param == "true") {
is_fullscreen = true;
} else if (f_param == "false") {
is_fullscreen = false;
} else {
std::cerr
<< "Error: Invalid argument for -f/--fullscreen. Use 'true' or 'false'.\n";
exit(1);
}
// Set fullscreen mode without saving it to config file
Config::setFullscreenMode(is_fullscreen);
}},
{"--fullscreen", [&](int& i) { arg_map["-f"](i); }},
};

// Parse command-line arguments using the map
Expand All @@ -83,7 +104,7 @@ int main(int argc, char* argv[]) {
if (it != arg_map.end()) {
it->second(i); // Call the associated lambda function
} else {
std::cerr << "Unknown argument: " << cur_arg << "\n";
std::cerr << "Unknown argument: " << cur_arg << ", see --help for info.\n";
return 1;
}
}
Expand All @@ -103,6 +124,11 @@ int main(int argc, char* argv[]) {
m_main_window->Init();
}

if (has_command_line_argument && !has_game_argument) {
std::cerr << "Error: Please provide a game path or ID.\n";
exit(1);
}

// Process game path or ID if provided
if (has_game_argument) {
std::filesystem::path game_file_path(gamePath);
Expand Down

0 comments on commit beea900

Please sign in to comment.