2024-09-29 19:25:14 +02:00
|
|
|
#include "core/plugin.h"
|
2025-12-24 20:12:05 +01:00
|
|
|
#include "init.h"
|
2024-09-29 19:25:14 +02:00
|
|
|
#include "logger.h"
|
|
|
|
|
|
2025-03-14 11:12:18 +01:00
|
|
|
#include "core/config.h"
|
2025-05-31 20:26:47 +02:00
|
|
|
|
2025-05-19 22:26:32 +02:00
|
|
|
#include "loader/archive_loader.h"
|
2024-09-29 19:25:14 +02:00
|
|
|
|
2025-06-22 17:18:53 +02:00
|
|
|
#include "explorer/explorer.h"
|
2025-05-31 20:26:47 +02:00
|
|
|
#include "imgui/imgui_stdlib.h"
|
2025-03-25 21:33:06 +01:00
|
|
|
|
2024-09-29 19:25:14 +02:00
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
bool _loader_open = false;
|
2024-10-01 11:52:26 -04:00
|
|
|
std::unique_ptr<satdump::ArchiveLoader> _loader = nullptr;
|
2025-05-19 22:26:32 +02:00
|
|
|
} // namespace
|
2024-09-29 19:25:14 +02:00
|
|
|
|
2025-07-24 21:55:57 +02:00
|
|
|
void provideExplorerFileLoader(const satdump::explorer::ExplorerRequestFileLoad &evt);
|
|
|
|
|
|
2025-08-12 13:42:31 +02:00
|
|
|
class FirstPartyLoaderSupport : public satdump::Plugin
|
2024-09-29 19:25:14 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2025-08-12 13:42:31 +02:00
|
|
|
std::string getID() { return "first_party_loader_support"; }
|
2024-09-29 19:25:14 +02:00
|
|
|
|
|
|
|
|
void init()
|
|
|
|
|
{
|
|
|
|
|
satdump::eventBus->register_handler<satdump::config::RegisterPluginConfigHandlersEvent>(registerConfigHandler);
|
2025-07-24 21:55:57 +02:00
|
|
|
satdump::eventBus->register_handler<satdump::explorer::RenderLoadMenuElementsEvent>(renderExplorerLoaderButton);
|
|
|
|
|
satdump::eventBus->register_handler<satdump::explorer::ExplorerRequestFileLoad>(provideExplorerFileLoader);
|
2024-09-29 19:25:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void registerConfigHandler(const satdump::config::RegisterPluginConfigHandlersEvent &evt)
|
|
|
|
|
{
|
2025-08-12 13:42:31 +02:00
|
|
|
evt.plugin_config_handlers.push_back({"First-Party Support", FirstPartyLoaderSupport::renderConfig, FirstPartyLoaderSupport::saveConfig});
|
2024-09-29 19:25:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static void initLoader()
|
|
|
|
|
{
|
|
|
|
|
if (!_loader)
|
|
|
|
|
{
|
|
|
|
|
_loader = std::make_unique<satdump::ArchiveLoader>();
|
|
|
|
|
|
2025-12-25 13:49:03 +01:00
|
|
|
std::string eumetsat_user_consumer_credential = satdump::db->get_user("firstparty_products/eumetsat_credentials_key", "");
|
|
|
|
|
std::string eumetsat_user_consumer_secret = satdump::db->get_user("firstparty_products/eumetsat_credentials_secret", "");
|
2025-12-24 20:12:05 +01:00
|
|
|
|
|
|
|
|
if (eumetsat_user_consumer_credential.size())
|
|
|
|
|
_loader->eumetsat_user_consumer_credential = eumetsat_user_consumer_credential;
|
|
|
|
|
if (eumetsat_user_consumer_secret.size())
|
|
|
|
|
_loader->eumetsat_user_consumer_secret = eumetsat_user_consumer_secret;
|
2024-09-29 19:25:14 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void renderConfig()
|
|
|
|
|
{
|
|
|
|
|
initLoader();
|
|
|
|
|
|
2025-07-14 11:23:51 +02:00
|
|
|
ImGui::Text("EUMETSAT User «Consumer Key»");
|
2024-09-29 19:25:14 +02:00
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::InputText("##eumetsattokenloader_key", &_loader->eumetsat_user_consumer_credential);
|
|
|
|
|
|
2025-07-14 11:23:51 +02:00
|
|
|
ImGui::Text("EUMETSAT User «Consumer Secret»");
|
2024-09-29 19:25:14 +02:00
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::InputText("##eumetsattokenloader_secret", &_loader->eumetsat_user_consumer_secret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void saveConfig()
|
|
|
|
|
{
|
2025-03-14 11:12:18 +01:00
|
|
|
if (_loader == nullptr)
|
2024-10-01 11:52:26 -04:00
|
|
|
return;
|
2025-12-24 20:12:05 +01:00
|
|
|
|
2025-12-25 13:49:03 +01:00
|
|
|
satdump::db->set_user("firstparty_products/eumetsat_credentials_key", _loader->eumetsat_user_consumer_credential);
|
|
|
|
|
satdump::db->set_user("firstparty_products/eumetsat_credentials_secret", _loader->eumetsat_user_consumer_secret);
|
2024-09-29 19:25:14 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-24 21:55:57 +02:00
|
|
|
static void renderExplorerLoaderButton(const satdump::explorer::RenderLoadMenuElementsEvent &evt)
|
2025-03-25 21:33:06 +01:00
|
|
|
{
|
|
|
|
|
if (ImGui::BeginMenu("File"))
|
|
|
|
|
{
|
2025-08-12 13:42:31 +02:00
|
|
|
if (ImGui::MenuItem("Load First-Party"))
|
2025-03-25 21:33:06 +01:00
|
|
|
_loader_open = true;
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
2024-09-29 19:25:14 +02:00
|
|
|
|
2025-03-25 21:33:06 +01:00
|
|
|
if (_loader_open)
|
|
|
|
|
{
|
|
|
|
|
initLoader();
|
|
|
|
|
_loader->drawUI(&_loader_open);
|
|
|
|
|
}
|
2025-05-24 20:17:10 +02:00
|
|
|
}
|
2024-09-29 19:25:14 +02:00
|
|
|
};
|
|
|
|
|
|
2025-08-12 13:42:31 +02:00
|
|
|
PLUGIN_LOADER(FirstPartyLoaderSupport)
|