added set-addon-folder in main

This commit is contained in:
georgemoralis 2025-06-12 11:20:59 +03:00
parent 847a56288d
commit e33e5e522a

View File

@ -32,91 +32,107 @@ int main(int argc, char* argv[]) {
std::vector<std::string> game_args{}; std::vector<std::string> game_args{};
// Map of argument strings to lambda functions // Map of argument strings to lambda functions
std::unordered_map<std::string, std::function<void(int&)>> arg_map = { std::unordered_map<std::string, std::function<void(int&)>> arg_map =
{"-h", { {"-h",
[&](int&) { [&](int&) {
std::cout std::cout << "Usage: shadps4 [options] <elf or eboot.bin path>\n"
<< "Usage: shadps4 [options] <elf or eboot.bin path>\n" "Options:\n"
"Options:\n" " -g, --game <path|ID> Specify game path to launch\n"
" -g, --game <path|ID> Specify game path to launch\n" " -- ... Parameters passed to the game ELF. "
" -- ... Parameters passed to the game ELF. " "Needs to be at the end of the line, and everything after \"--\" is a "
"Needs to be at the end of the line, and everything after \"--\" is a " "game argument.\n"
"game argument.\n" " -p, --patch <patch_file> Apply specified patch file\n"
" -p, --patch <patch_file> Apply specified patch file\n" " -i, --ignore-game-patch Disable automatic loading of game patch\n"
" -i, --ignore-game-patch Disable automatic loading of game patch\n" " -f, --fullscreen <true|false> Specify window initial fullscreen "
" -f, --fullscreen <true|false> Specify window initial fullscreen " "state. Does not overwrite the config file.\n"
"state. Does not overwrite the config file.\n" " --add-game-folder <folder> Adds a new game folder to the config.\n"
" --add-game-folder <folder> Adds a new game folder to the config.\n" " --set-addon-folder <folder> Sets the addon folder to the config.\n"
" -h, --help Display this help message\n"; " -h, --help Display this help message\n";
exit(0); exit(0);
}}, }},
{"--help", [&](int& i) { arg_map["-h"](i); }}, {"--help", [&](int& i) { arg_map["-h"](i); }},
{"-g", {"-g",
[&](int& i) { [&](int& i) {
if (i + 1 < argc) { if (i + 1 < argc) {
game_path = argv[++i]; game_path = argv[++i];
has_game_argument = true; has_game_argument = true;
} else { } else {
std::cerr << "Error: Missing argument for -g/--game\n"; std::cerr << "Error: Missing argument for -g/--game\n";
exit(1); exit(1);
} }
}}, }},
{"--game", [&](int& i) { arg_map["-g"](i); }}, {"--game", [&](int& i) { arg_map["-g"](i); }},
{"-p", {"-p",
[&](int& i) { [&](int& i) {
if (i + 1 < argc) { if (i + 1 < argc) {
MemoryPatcher::patchFile = argv[++i]; MemoryPatcher::patchFile = argv[++i];
} else { } else {
std::cerr << "Error: Missing argument for -p/--patch\n"; std::cerr << "Error: Missing argument for -p/--patch\n";
exit(1); exit(1);
} }
}}, }},
{"--patch", [&](int& i) { arg_map["-p"](i); }}, {"--patch", [&](int& i) { arg_map["-p"](i); }},
{"-i", [&](int&) { Core::FileSys::MntPoints::ignore_game_patches = true; }}, {"-i", [&](int&) { Core::FileSys::MntPoints::ignore_game_patches = true; }},
{"--ignore-game-patch", [&](int& i) { arg_map["-i"](i); }}, {"--ignore-game-patch", [&](int& i) { arg_map["-i"](i); }},
{"-f", {"-f",
[&](int& i) { [&](int& i) {
if (++i >= argc) { if (++i >= argc) {
std::cerr << "Error: Missing argument for -f/--fullscreen\n"; std::cerr << "Error: Missing argument for -f/--fullscreen\n";
exit(1); exit(1);
} }
std::string f_param(argv[i]); std::string f_param(argv[i]);
bool is_fullscreen; bool is_fullscreen;
if (f_param == "true") { if (f_param == "true") {
is_fullscreen = true; is_fullscreen = true;
} else if (f_param == "false") { } else if (f_param == "false") {
is_fullscreen = false; is_fullscreen = false;
} else { } else {
std::cerr std::cerr << "Error: Invalid argument for -f/--fullscreen. Use 'true' or 'false'.\n";
<< "Error: Invalid argument for -f/--fullscreen. Use 'true' or 'false'.\n"; exit(1);
exit(1); }
} // Set fullscreen mode without saving it to config file
// Set fullscreen mode without saving it to config file Config::setIsFullscreen(is_fullscreen);
Config::setIsFullscreen(is_fullscreen); }},
}}, {"--fullscreen", [&](int& i) { arg_map["-f"](i); }},
{"--fullscreen", [&](int& i) { arg_map["-f"](i); }}, {"--add-game-folder",
{"--add-game-folder", [&](int& i) {
[&](int& i) { if (++i >= argc) {
if (++i >= argc) { std::cerr << "Error: Missing argument for --add-game-folder\n";
std::cerr << "Error: Missing argument for --add-game-folder\n"; exit(1);
exit(1); }
} std::string config_dir(argv[i]);
std::string config_dir(argv[i]); std::filesystem::path config_path = std::filesystem::path(config_dir);
std::filesystem::path config_path = std::filesystem::path(config_dir); std::error_code discard;
std::error_code discard; if (!std::filesystem::exists(config_path, discard)) {
if (!std::filesystem::exists(config_path, discard)) { std::cerr << "Error: File does not exist: " << config_path << "\n";
std::cerr << "Error: File does not exist: " << config_path << "\n"; exit(1);
exit(1); }
}
Config::addGameInstallDir(config_path); Config::addGameInstallDir(config_path);
Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml"); Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml");
std::cout << "Game folder successfully saved.\n"; std::cout << "Game folder successfully saved.\n";
exit(0); exit(0);
}}, },
}; {"--set-addon-folder", [&](int& i) {
if (++i >= argc) {
std::cerr << "Error: Missing argument for --add-addon-folder\n";
exit(1);
}
std::string config_dir(argv[i]);
std::filesystem::path config_path = std::filesystem::path(config_dir);
std::error_code discard;
if (!std::filesystem::exists(config_path, discard)) {
std::cerr << "Error: File does not exist: " << config_path << "\n";
exit(1);
}
Config::setAddonInstallDir(config_path);
Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml");
std::cout << "Addon folder successfully saved.\n";
exit(0);
}}};
if (argc == 1) { if (argc == 1) {
int dummy = 0; // one does not simply pass 0 directly int dummy = 0; // one does not simply pass 0 directly