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,11 +32,10 @@ int main(int argc, char* argv[]) {
std::vector<std::string> game_args{};
// Map of argument strings to lambda functions
std::unordered_map<std::string, std::function<void(int&)>> arg_map = {
{"-h",
std::unordered_map<std::string, std::function<void(int&)>> arg_map =
{ {"-h",
[&](int&) {
std::cout
<< "Usage: shadps4 [options] <elf or eboot.bin path>\n"
std::cout << "Usage: shadps4 [options] <elf or eboot.bin path>\n"
"Options:\n"
" -g, --game <path|ID> Specify game path to launch\n"
" -- ... Parameters passed to the game ELF. "
@ -47,6 +46,7 @@ int main(int argc, char* argv[]) {
" -f, --fullscreen <true|false> Specify window initial fullscreen "
"state. Does not overwrite the config file.\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";
exit(0);
}},
@ -89,8 +89,7 @@ int main(int argc, char* argv[]) {
} else if (f_param == "false") {
is_fullscreen = false;
} else {
std::cerr
<< "Error: Invalid argument for -f/--fullscreen. Use 'true' or 'false'.\n";
std::cerr << "Error: Invalid argument for -f/--fullscreen. Use 'true' or 'false'.\n";
exit(1);
}
// Set fullscreen mode without saving it to config file
@ -115,8 +114,25 @@ int main(int argc, char* argv[]) {
Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml");
std::cout << "Game folder successfully saved.\n";
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) {
int dummy = 0; // one does not simply pass 0 directly