2020-12-15 22:05:11 +00:00
|
|
|
#include <options.h>
|
2020-12-22 13:50:26 +00:00
|
|
|
#include <spdlog/spdlog.h>
|
2020-12-22 22:04:46 +00:00
|
|
|
#include <stdlib.h>
|
2020-12-15 22:05:11 +00:00
|
|
|
|
|
|
|
namespace options {
|
2020-12-22 13:50:26 +00:00
|
|
|
CMDLineOptions opts;
|
|
|
|
|
|
|
|
void loadDefaults() {
|
2021-11-16 02:33:09 +00:00
|
|
|
#if defined(_WIN32)
|
2020-12-22 13:50:26 +00:00
|
|
|
opts.root = ".";
|
2021-02-06 20:28:27 +00:00
|
|
|
opts.showConsole = false;
|
2021-11-17 21:37:21 +00:00
|
|
|
#elif defined(IS_MACOS_BUNDLE)
|
2021-11-16 02:33:09 +00:00
|
|
|
std::string homedir = getenv("HOME");
|
|
|
|
opts.root = homedir + "/Library/Application Support/sdrpp";
|
2020-12-22 13:50:26 +00:00
|
|
|
#else
|
2020-12-22 22:04:46 +00:00
|
|
|
std::string homedir = getenv("HOME");
|
|
|
|
opts.root = homedir + "/.config/sdrpp";
|
2020-12-22 13:50:26 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool parse(int argc, char *argv[]) {
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
char* arg = argv[i];
|
|
|
|
if (!strcmp(arg, "-r") || !strcmp(arg, "--root")) {
|
|
|
|
if (i == argc - 1) { return false; }
|
|
|
|
opts.root = argv[++i];
|
|
|
|
}
|
2021-02-06 20:28:27 +00:00
|
|
|
else if (!strcmp(arg, "-s") || !strcmp(arg, "--show-console")) {
|
|
|
|
opts.showConsole = true;
|
|
|
|
}
|
2021-07-23 04:29:16 +00:00
|
|
|
else if (!strcmp(arg, "--server")) {
|
|
|
|
opts.serverMode = true;
|
|
|
|
}
|
2020-12-22 13:50:26 +00:00
|
|
|
else {
|
|
|
|
spdlog::error("Invalid command line option: {0}", arg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2020-12-15 22:05:11 +00:00
|
|
|
}
|
|
|
|
}
|