Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bootstrap): fix euroscope crash in development mode #318

Merged
merged 1 commit into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/plugin/bootstrap/DllInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pch/pch.h"
#include "bootstrap/InitialisePlugin.h"
#include "update/PluginVersion.h"
#include "helper/HelperFunctions.h"
#include "update/CheckDevelopmentVersion.h"

#ifndef UKCP_CORE_API
#define UKCP_CORE_API extern "C" __declspec(dllexport)
Expand All @@ -10,6 +10,7 @@


using UKControllerPlugin::Plugin::PluginVersion;
using UKControllerPluginUtils::Update::IsDevelopmentVersion;

// The one true app to rule them all...
UKControllerPlugin::InitialisePlugin thePluginApp;
Expand Down Expand Up @@ -94,8 +95,7 @@ UKCP_CORE_API const char* GetPluginVersion()
*/
UKCP_CORE_DIRECT_API void EuroScopePlugInInit(EuroScopePlugIn::CPlugIn** ppPlugInInstance)
{
std::string version(PluginVersion::version);
if (version != "#VERSION_STRING#" && version != "non-release-build") {
if (!IsDevelopmentVersion(PluginVersion::version)) {
MessageBox(
GetActiveWindow(),
L"Core binary cannot be loaded directly in release versions.",
Expand All @@ -113,7 +113,7 @@ UKCP_CORE_DIRECT_API void EuroScopePlugInInit(EuroScopePlugIn::CPlugIn** ppPlugI
*/
UKCP_CORE_DIRECT_API void EuroScopePlugInExit(void)
{
if (PluginVersion::version != "#VERSION_STRING#" && PluginVersion::version != "non-release-build") {
if (!IsDevelopmentVersion(PluginVersion::version)) {
return;
}

Expand Down
17 changes: 0 additions & 17 deletions src/plugin/bootstrap/InitialisePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,11 @@ using UKControllerPlugin::Euroscope::GeneralSettingsConfigurationBootstrap;
using UKControllerPlugin::Dependency::DependencyLoader;

namespace UKControllerPlugin {
/*
Creates a dummy plugin to fill the spot.
*/
void InitialisePlugin::CreateDummy(void)
{
this->fallbackPlugin = std::unique_ptr<EuroScopePlugIn::CPlugIn>(
new EuroScopePlugIn::CPlugIn(
EuroScopePlugIn::COMPATIBILITY_CODE,
"UK Controller Plugin (Disabled)",
"XXX",
"VATSIM UK",
"VATSIM United Kingdom Division"
)
);
}

/*
Clean up after ourself as we get closed down.
*/
void InitialisePlugin::EuroScopeCleanup(void)
{
// Shut down the container, task runner and logs.
this->container->taskRunner.reset();
this->container.reset();
this->duplicatePlugin.reset();
Expand Down
3 changes: 0 additions & 3 deletions src/plugin/bootstrap/InitialisePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ namespace UKControllerPlugin {

private:

void CreateDummy(void);


// In the event of an invalid version, this is the "dummy" fallback plugin.
std::unique_ptr<EuroScopePlugIn::CPlugIn> fallbackPlugin;

Expand Down
1 change: 1 addition & 0 deletions src/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ set(srd
source_group("srd" FILES ${srd})

set(update
"update/CheckDevelopmentVersion.cpp"
"update/LoadChangelog.cpp"
"update/LoadChangelog.h"
"update/PluginVersion.cpp"
Expand Down
17 changes: 17 additions & 0 deletions src/utils/update/CheckDevelopmentVersion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "pch/pch.h"
#include "update/CheckDevelopmentVersion.h"

const std::string NO_VERSION_SPECIFIED = "#VERSION_STRING#";
const std::string NON_RELEASE_BUILD = "non-release-build";

namespace UKControllerPluginUtils::Update {
bool IsDevelopmentVersion(std::string version)
{
return version == NO_VERSION_SPECIFIED || version == NON_RELEASE_BUILD;
}

bool IsDevelopmentVersion(const char* version)
{
return IsDevelopmentVersion(std::string(version));
}
} // namespace UKControllerPluginUtils::Update
6 changes: 6 additions & 0 deletions src/utils/update/CheckDevelopmentVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

namespace UKControllerPluginUtils::Update {
bool IsDevelopmentVersion(const char* version);
bool IsDevelopmentVersion(std::string version);
} // namespace UKControllerPluginUtils::Update
1 change: 1 addition & 0 deletions test/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ source_group("test\\squawk" FILES ${test__squawk})

set(test__update
"update/UpdateBinariesTest.cpp"
"update/CheckDevelopmentVersionTest.cpp"
)
source_group("test\\update" FILES ${test__update})

Expand Down
35 changes: 35 additions & 0 deletions test/utils/update/CheckDevelopmentVersionTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "pch/pch.h"
#include "update/CheckDevelopmentVersion.h"

using testing::Test;
using UKControllerPluginUtils::Update::IsDevelopmentVersion;

namespace UKControllerPluginUtilsTest::Update {
class CheckDevelopmentVersionTest: public Test
{};

TEST_F(CheckDevelopmentVersionTest, IsDevelopmentIfVersionUnspecified)
{
EXPECT_TRUE(IsDevelopmentVersion("#VERSION_STRING#"));
}

TEST_F(CheckDevelopmentVersionTest, IsDevelopmentIfVersionNonRelease)
{
EXPECT_TRUE(IsDevelopmentVersion("non-release-build"));
}

TEST_F(CheckDevelopmentVersionTest, IsNotDevelopmentOnRelease)
{
EXPECT_FALSE(IsDevelopmentVersion("1.5.0-"));
}

TEST_F(CheckDevelopmentVersionTest, IsNotDevelopmentOnBetaRelease)
{
EXPECT_FALSE(IsDevelopmentVersion("1.6.0-beta1"));
}

TEST_F(CheckDevelopmentVersionTest, DevelopmentVersionsAreCheckedForStrings)
{
EXPECT_TRUE(IsDevelopmentVersion(std::string("#VERSION_STRING#")));
}
} // namespace UKControllerPluginUtilsTest::Update