satdump/src-core/init.cpp

161 lines
6.4 KiB
C++
Raw Permalink Normal View History

2022-05-12 15:24:25 -07:00
#define SATDUMP_DLL_EXPORT 1
2021-03-22 18:53:09 +01:00
#include "init.h"
#include "logger.h"
#include "core/module.h"
#include "core/pipeline.h"
2021-05-04 12:23:22 +02:00
#include <filesystem>
#include "core/plugin.h"
#include "satdump_vars.h"
#include "core/config.h"
2021-08-02 23:33:10 +02:00
2022-04-21 16:10:00 +02:00
#include "common/tracking/tle.h"
2022-05-20 20:19:14 +02:00
#include "products/products.h"
2024-10-07 22:05:30 -04:00
#include "imgui/pfd/portable-file-dialogs.h"
2022-04-21 16:10:00 +02:00
2022-08-30 12:01:12 +02:00
#include "core/opencl.h"
#include "common/dsp/buffer.h"
2022-03-10 19:56:37 +01:00
namespace satdump
2021-03-22 18:53:09 +01:00
{
2022-05-12 15:24:25 -07:00
SATDUMP_DLL std::string user_path;
2022-09-11 19:15:24 +02:00
SATDUMP_DLL std::string tle_file_override = "";
2023-01-23 14:23:09 +01:00
SATDUMP_DLL bool tle_do_update_on_init = true;
2022-05-07 17:06:56 +02:00
2024-10-07 22:05:30 -04:00
void initSatdump(bool is_gui)
2022-03-10 19:56:37 +01:00
{
logger->info(" _____ __ ____ ");
logger->info(" / ___/____ _/ /_/ __ \\__ ______ ___ ____ ");
logger->info(" \\__ \\/ __ `/ __/ / / / / / / __ `__ \\/ __ \\");
logger->info(" ___/ / /_/ / /_/ /_/ / /_/ / / / / / / /_/ /");
logger->info("/____/\\__,_/\\__/_____/\\__,_/_/ /_/ /_/ .___/ ");
logger->info(" /_/ ");
logger->info("Starting SatDump v" + (std::string)SATDUMP_VERSION);
logger->info("");
2022-03-30 15:41:23 +02:00
#ifdef _WIN32
2023-09-18 07:48:47 -07:00
if (std::filesystem::exists("satdump_cfg.json"))
user_path = "./config";
2023-09-18 07:48:47 -07:00
else
user_path = std::string(getenv("APPDATA")) + "/satdump";
2022-05-13 21:35:51 +02:00
#elif __ANDROID__
user_path = ".";
2022-03-30 15:41:23 +02:00
#else
2022-05-07 17:06:56 +02:00
user_path = std::string(getenv("HOME")) + "/.config/satdump";
2022-03-30 15:41:23 +02:00
#endif
2024-10-07 22:05:30 -04:00
try
{
if (std::filesystem::exists("satdump_cfg.json"))
config::loadConfig("satdump_cfg.json", user_path);
else
config::loadConfig(satdump::RESPATH + "satdump_cfg.json", user_path);
}
catch (std::exception &e)
{
logger->critical("Error loading SatDump config! SatDump will now exit. Error:\n%s", e.what());
if(is_gui)
pfd::message("SatDump", "Error loading SatDump config! SatDump will now exit. Error:\n\n" +
std::string(e.what()), pfd::choice::ok, pfd::icon::error);
exit(1);
}
2022-03-10 19:56:37 +01:00
2022-11-26 17:50:44 +01:00
if (config::main_cfg["satdump_general"].contains("log_to_file"))
{
bool log_file = config::main_cfg["satdump_general"]["log_to_file"]["value"];
if (log_file)
initFileSink();
}
2022-11-26 17:34:22 +01:00
if (config::main_cfg["satdump_general"].contains("log_level"))
{
2022-11-27 21:30:17 +01:00
std::string log_level = config::main_cfg["satdump_general"]["log_level"]["value"];
if (log_level == "trace")
2023-02-26 00:54:58 +00:00
setConsoleLevel(slog::LOG_TRACE);
2022-11-27 21:30:17 +01:00
else if (log_level == "debug")
2023-02-26 00:54:58 +00:00
setConsoleLevel(slog::LOG_DEBUG);
2022-11-27 21:30:17 +01:00
else if (log_level == "info")
2023-02-26 00:54:58 +00:00
setConsoleLevel(slog::LOG_INFO);
2022-11-27 21:30:17 +01:00
else if (log_level == "warn")
2023-02-26 00:54:58 +00:00
setConsoleLevel(slog::LOG_WARN);
2022-11-27 21:30:17 +01:00
else if (log_level == "error")
2023-02-26 00:54:58 +00:00
setConsoleLevel(slog::LOG_ERROR);
2022-11-27 21:30:17 +01:00
else if (log_level == "critical")
2023-02-26 00:54:58 +00:00
setConsoleLevel(slog::LOG_CRIT);
2022-11-26 17:34:22 +01:00
}
2022-03-10 19:56:37 +01:00
loadPlugins();
2023-09-14 10:38:02 +02:00
// Let plugins know we started
eventBus->fire_event<config::RegisterPluginConfigHandlersEvent>({config::plugin_config_handlers});
2022-03-10 19:56:37 +01:00
registerModules();
// Load pipelines
if (std::filesystem::exists("pipelines") && std::filesystem::is_directory("pipelines"))
loadPipelines("pipelines");
else
loadPipelines(satdump::RESPATH + "pipelines");
2022-03-10 19:56:37 +01:00
// List them
logger->debug("Registered pipelines :");
for (Pipeline &pipeline : pipelines)
logger->debug(" - " + pipeline.name);
2022-08-30 12:01:12 +02:00
#ifdef USE_OPENCL
// OpenCL
opencl::initOpenCL();
#endif
2022-03-10 19:56:37 +01:00
// TLEs
2022-09-11 19:15:24 +02:00
if (tle_file_override == "")
2022-09-08 23:03:54 +02:00
{
loadTLEFileIntoRegistry(user_path + "/satdump_tles.txt");
2023-10-25 12:11:17 -04:00
if (tle_do_update_on_init)
autoUpdateTLE(user_path + "/satdump_tles.txt");
2022-09-11 19:15:24 +02:00
}
else
{
if (std::filesystem::exists(tle_file_override))
loadTLEFileIntoRegistry(tle_file_override);
else
logger->error("TLE File doesn't exist : " + tle_file_override);
2022-09-08 23:03:54 +02:00
}
2022-03-10 19:56:37 +01:00
2022-05-20 20:19:14 +02:00
// Products
registerProducts();
// Set DSP buffer sizes if they have been changed
if (config::main_cfg.contains("advanced_settings"))
{
if (config::main_cfg["advanced_settings"].contains("default_buffer_size"))
{
int new_sz = config::main_cfg["advanced_settings"]["default_buffer_size"].get<int>();
dsp::STREAM_BUFFER_SIZE = new_sz;
dsp::RING_BUF_SZ = new_sz;
2023-05-08 23:08:34 +02:00
logger->warn("DSP Buffer size was changed to %d", new_sz);
}
}
2022-03-10 19:56:37 +01:00
// Let plugins know we started
eventBus->fire_event<SatDumpStartedEvent>({});
#ifdef BUILD_IS_DEBUG
// If in debug, warn the user!
logger->error("██████╗ █████╗ ███╗ ██╗ ██████╗ ███████╗██████╗ ");
logger->error("██╔══██╗██╔══██╗████╗ ██║██╔════╝ ██╔════╝██╔══██╗");
logger->error("██║ ██║███████║██╔██╗ ██║██║ ███╗█████╗ ██████╔╝");
logger->error("██║ ██║██╔══██║██║╚██╗██║██║ ██║██╔══╝ ██╔══██╗");
logger->error("██████╔╝██║ ██║██║ ╚████║╚██████╔╝███████╗██║ ██║");
logger->error("╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝");
logger->error("SatDump has NOT been built in Release mode.");
logger->error("If you are not a developer but intending to use the software,");
logger->error("you probably do not want this. If so, make sure to");
logger->error("specify -DCMAKE_BUILD_TYPE=Release in CMake.");
#endif
2024-06-02 23:14:46 -04:00
logger->error("WARNING! SatDump for Windows XP is a technical experiment!");
logger->error("Things may not work, and it has no support. Do not open");
logger->error("issues on GitHub for this build of SatDump.");
2022-03-10 19:56:37 +01:00
}
}