From a23384e42a3c69540c0adeaa3ad5b3c1d19b3597 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Sun, 14 May 2023 20:49:29 +0100 Subject: [PATCH] fix: register eventbus in loader and updater --- src/loader/dllmain.cpp | 8 ++++++++ src/loader/pch/pch.h | 1 + src/plugin/bootstrap/InitialisePlugin.cpp | 2 +- src/updater/dllmain.cpp | 10 ++++++++++ src/updater/pch/pch.h | 1 + 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/loader/dllmain.cpp b/src/loader/dllmain.cpp index 161d09ee4..1ecaa5503 100644 --- a/src/loader/dllmain.cpp +++ b/src/loader/dllmain.cpp @@ -8,6 +8,8 @@ #include "setting/SettingRepositoryFactory.h" #include "curl/CurlApi.h" #include "data/PluginDataLocations.h" +#include "eventhandler/MutableEventBus.h" +#include "eventhandler/StandardEventBusFactory.h" #include "update/PluginVersion.h" #ifndef UKCP_LOADER_API @@ -35,6 +37,10 @@ UKCP_LOADER_API void EuroScopePlugInInit(EuroScopePlugIn::CPlugIn** ppPlugInInst CreatePluginDataRoot(*windows); UKControllerPlugin::Log::LoggerBootstrap::Bootstrap(*windows, L"loader"); + // Create the event bus + UKControllerPluginUtils::EventHandler::MutableEventBus::SetFactory( + std::make_shared()); + // Bootstrap the API, download the updater if we don't have it already and run it UKControllerPlugin::Curl::CurlApi curl; std::unique_ptr settings = @@ -80,7 +86,9 @@ UKCP_LOADER_API void EuroScopePlugInInit(EuroScopePlugIn::CPlugIn** ppPlugInInst throw std::exception("UKCP broke"); } *ppPlugInInstance = pluginInstance; + UKControllerPluginUtils::EventHandler::MutableEventBus::Reset(); } catch (std::exception e) { + UKControllerPluginUtils::EventHandler::MutableEventBus::Reset(); ShutdownLogger(); throw; } diff --git a/src/loader/pch/pch.h b/src/loader/pch/pch.h index 1a24f692e..f5259b337 100644 --- a/src/loader/pch/pch.h +++ b/src/loader/pch/pch.h @@ -11,6 +11,7 @@ #pragma warning(pop) #include +#include #include #include #include diff --git a/src/plugin/bootstrap/InitialisePlugin.cpp b/src/plugin/bootstrap/InitialisePlugin.cpp index a1a6c4dac..407409204 100644 --- a/src/plugin/bootstrap/InitialisePlugin.cpp +++ b/src/plugin/bootstrap/InitialisePlugin.cpp @@ -144,7 +144,7 @@ namespace UKControllerPlugin { this->duplicatePlugin = std::make_unique(); this->container = std::make_unique(); - // Create the event bus. + // Create the event bus UKControllerPluginUtils::EventHandler::MutableEventBus::SetFactory( std::make_shared()); diff --git a/src/updater/dllmain.cpp b/src/updater/dllmain.cpp index dc9699706..44ec89077 100644 --- a/src/updater/dllmain.cpp +++ b/src/updater/dllmain.cpp @@ -5,6 +5,8 @@ #include "api/ApiFactory.h" #include "setting/SettingRepositoryFactory.h" #include "curl/CurlApi.h" +#include "eventhandler/MutableEventBus.h" +#include "eventhandler/StandardEventBusFactory.h" #include "log/LoggerBootstrap.h" #include "update/BootstrapReleaseChannelSettings.h" #include "update/PluginVersion.h" @@ -33,6 +35,10 @@ UKCP_UPDATER_API bool PerformUpdates() windows = UKControllerPlugin::Windows::Bootstrap(dllInstance); UKControllerPlugin::Log::LoggerBootstrap::Bootstrap(*windows, L"updater"); + // Create the event bus + UKControllerPluginUtils::EventHandler::MutableEventBus::SetFactory( + std::make_shared()); + // Bootstrap the API, download the updater if we don't have it already and run it UKControllerPlugin::Curl::CurlApi curl; std::unique_ptr settings = @@ -46,6 +52,10 @@ UKCP_UPDATER_API bool PerformUpdates() UKControllerPlugin::Duplicate::DuplicatePlugin duplicatePlugin; const bool updatePeformed = CheckForUpdates( *api, *windows, curl, duplicatePlugin.Duplicate(), settings->GetSetting("release_channel", "stable")); + + // Shutdown event bus and logger + UKControllerPluginUtils::EventHandler::MutableEventBus::Reset(); ShutdownLogger(); + return updatePeformed; } diff --git a/src/updater/pch/pch.h b/src/updater/pch/pch.h index ee93e1385..085be1dce 100644 --- a/src/updater/pch/pch.h +++ b/src/updater/pch/pch.h @@ -12,6 +12,7 @@ // add headers that you want to pre-compile here #include +#include #include #include #include