diff --git a/core/src/core.cpp b/core/src/core.cpp index fb753b5d..d8ed53a1 100644 --- a/core/src/core.cpp +++ b/core/src/core.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #define STB_IMAGE_RESIZE_IMPLEMENTATION #include @@ -77,6 +78,20 @@ int sdrpp_main(int argc, char *argv[]) { options::loadDefaults(); if (!options::parse(argc, argv)) { return -1; } + // Check root directory + if (!std::filesystem::exists(options::opts.root)) { + spdlog::warn("Root directory {0} does not exist, creating it", options::opts.root); + if (!std::filesystem::create_directory(options::opts.root)) { + spdlog::error("Could not create root directory {0}", options::opts.root); + return -1; + } + } + + if (!std::filesystem::is_directory(options::opts.root)) { + spdlog::error("{0} is not a directory", options::opts.root); + return -1; + } + // ======== DEFAULT CONFIG ======== json defConfig; defConfig["bandColors"]["amateur"] = "#FF0000FF"; @@ -103,12 +118,14 @@ int sdrpp_main(int argc, char *argv[]) { }; defConfig["menuWidth"] = 300; defConfig["min"] = -70.0; + defConfig["moduleInstances"]["Audio Sink"] = "audio_sink"; defConfig["moduleInstances"]["PlutoSDR Source"] = "plutosdr_source"; defConfig["moduleInstances"]["RTL-TCP Source"] = "rtl_tcp_source"; defConfig["moduleInstances"]["Radio"] = "radio"; defConfig["moduleInstances"]["Recorder"] = "recorder"; defConfig["moduleInstances"]["SoapySDR Source"] = "soapy_source"; + defConfig["modules"] = json::array(); defConfig["offset"] = 0.0; defConfig["showWaterfall"] = true; @@ -116,6 +133,12 @@ int sdrpp_main(int argc, char *argv[]) { defConfig["streams"] = json::object(); defConfig["windowSize"]["h"] = 720; defConfig["windowSize"]["w"] = 1280; + + defConfig["bandColors"]["broadcast"] = "#0000FFFF"; + defConfig["bandColors"]["amateur"] = "#FF0000FF"; + defConfig["bandColors"]["aviation"] = "#00FF00FF"; + defConfig["bandColors"]["marine"] = "#00FFFFFF"; + defConfig["bandColors"]["military"] = "#FFFF00FF"; #ifdef _WIN32 defConfig["modulesDirectory"] = "./modules"; @@ -147,6 +170,7 @@ int sdrpp_main(int argc, char *argv[]) { int winHeight = core::configManager.conf["windowSize"]["h"]; maximized = core::configManager.conf["maximized"]; std::string resDir = core::configManager.conf["resourcesDirectory"]; + json bandColors = core::configManager.conf["bandColors"]; core::configManager.release(); // Create window with graphics context @@ -217,11 +241,11 @@ int sdrpp_main(int argc, char *argv[]) { LoadingScreen::show("Loading band plans"); spdlog::info("Loading band plans"); - bandplan::loadFromDir(options::opts.root + "/bandplans"); + bandplan::loadFromDir(resDir + "/bandplans"); LoadingScreen::show("Loading band plan colors"); spdlog::info("Loading band plans color table"); - bandplan::loadColorTable(options::opts.root + "/band_colors.json"); + bandplan::loadColorTable(bandColors); windowInit(); diff --git a/core/src/gui/widgets/bandplan.cpp b/core/src/gui/widgets/bandplan.cpp index 28bb4fcd..9e00fa65 100644 --- a/core/src/gui/widgets/bandplan.cpp +++ b/core/src/gui/widgets/bandplan.cpp @@ -108,20 +108,7 @@ namespace bandplan { } } - void loadColorTable(std::string path) { - if (!std::filesystem::exists(path)) { - spdlog::error("Band Plan Color Table file does not exist"); - return; - } - if (!std::filesystem::is_regular_file(path)) { - spdlog::error("Band Plan Color Table file isn't a file..."); - return; - } - std::ifstream file(path.c_str()); - json data; - file >> data; - file.close(); - - colorTable = data.get>(); + void loadColorTable(json table) { + colorTable = table.get>(); } }; \ No newline at end of file diff --git a/core/src/gui/widgets/bandplan.h b/core/src/gui/widgets/bandplan.h index d9107fab..e3129774 100644 --- a/core/src/gui/widgets/bandplan.h +++ b/core/src/gui/widgets/bandplan.h @@ -38,7 +38,7 @@ namespace bandplan { void loadBandPlan(std::string path); void loadFromDir(std::string path); - void loadColorTable(std::string path); + void loadColorTable(json table); extern std::map bandplans; extern std::vector bandplanNames; diff --git a/recorder/src/main.cpp b/recorder/src/main.cpp index c5096886..9cbd2aad 100644 --- a/recorder/src/main.cpp +++ b/recorder/src/main.cpp @@ -310,6 +310,14 @@ MOD_EXPORT void _INIT_() { config.setPath(options::opts.root + "/recorder_config.json"); config.load(def); config.enableAutoSave(); + + // Create default recording directory + if (!std::filesystem::exists(options::opts.root + "/recordings")) { + spdlog::warn("Recordings directory does not exist, creating it"); + if (!std::filesystem::create_directory(options::opts.root + "/recordings")) { + spdlog::error("Could not create recordings directory"); + } + } } MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) { diff --git a/root/band_colors.json b/root/band_colors.json deleted file mode 100644 index 2e9d8a95..00000000 --- a/root/band_colors.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "broadcast": "#0000FFFF", - "amateur": "#FF0000FF", - "aviation": "#00FF00FF", - "marine": "#00FFFFFF", - "military": "#FFFF00FF" -} \ No newline at end of file diff --git a/root/bandplans/general.json b/root/res/bandplans/general.json similarity index 100% rename from root/bandplans/general.json rename to root/res/bandplans/general.json diff --git a/root/bandplans/germany.json b/root/res/bandplans/germany.json similarity index 100% rename from root/bandplans/germany.json rename to root/res/bandplans/germany.json diff --git a/root/bandplans/russia.json b/root/res/bandplans/russia.json similarity index 100% rename from root/bandplans/russia.json rename to root/res/bandplans/russia.json