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>
|
2021-12-26 01:09:37 +00:00
|
|
|
#include <filesystem>
|
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";
|
2022-02-13 16:25:23 +00:00
|
|
|
#elif defined(__ANDROID__)
|
|
|
|
opts.root = "/storage/self/primary/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
|
2021-12-26 01:09:37 +00:00
|
|
|
opts.root = std::filesystem::absolute(opts.root).string();
|
2022-01-21 19:22:13 +00:00
|
|
|
opts.serverHost = "0.0.0.0";
|
|
|
|
opts.serverPort = 5259;
|
2020-12-22 13:50:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-19 21:11:44 +00:00
|
|
|
bool parse(int argc, char* argv[]) {
|
2020-12-22 13:50:26 +00:00
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
char* arg = argv[i];
|
|
|
|
if (!strcmp(arg, "-r") || !strcmp(arg, "--root")) {
|
|
|
|
if (i == argc - 1) { return false; }
|
2021-12-26 01:09:37 +00:00
|
|
|
opts.root = std::filesystem::absolute(argv[++i]).string();
|
2020-12-22 13:50:26 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
2022-01-21 19:22:13 +00:00
|
|
|
else if (!strcmp(arg, "-a") || !strcmp(arg, "--addr")) {
|
|
|
|
if (i == argc - 1) { return false; }
|
|
|
|
opts.serverHost = argv[++i];
|
|
|
|
opts.showConsole = true;
|
|
|
|
}
|
|
|
|
else if (!strcmp(arg, "-p") || !strcmp(arg, "--port")) {
|
|
|
|
if (i == argc - 1) { return false; }
|
|
|
|
sscanf(argv[++i], "%d", &opts.serverPort);
|
|
|
|
opts.showConsole = 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
|
|
|
}
|
|
|
|
}
|