logic: iterated on license checking

- moved LicenseChecker from App to Lib project
- added MessageDispatchWhenLicenseValid. This message takes another message as an argument which is dispatched once the LicenseChecher confirms the current license key or (if the key is invalid) once the user entered a valid key. This message is used when messages are sent that should not be working when no license key has been entered (LoadProject or ActivateTokenLocation via the IDE communication).
- added MessageShowStartScreen which makes the MainView display this screen. This message is also sent via the MessageDispatchWhenLicenseValid.
- removed startup project from appsettings.
This commit is contained in:
malte_langkabel
2016-04-14 15:25:40 +02:00
parent a2cba0b94f
commit 73ee3a27d9
29 changed files with 406 additions and 333 deletions
+117
View File
@@ -0,0 +1,117 @@
#include "LicenseChecker.h"
#include "utility/messaging/type/MessageStatus.h"
#include "License.h"
#include "Application.h"
#include "PublicKey.h"
#include "settings/ApplicationSettings.h"
#include "utility/AppPath.h"
void LicenseChecker::createInstance()
{
if (!s_instance)
{
s_instance = std::shared_ptr<LicenseChecker>(new LicenseChecker());
}
}
std::shared_ptr<LicenseChecker> LicenseChecker::getInstance()
{
createInstance();
return s_instance;
}
LicenseChecker::~LicenseChecker()
{
}
void LicenseChecker::setApp(Application* app)
{
m_app = app;
}
LicenseChecker::LicenseChecker()
: m_app(nullptr)
, m_forcedLicenseEntering(false)
{
}
void LicenseChecker::handleMessage(MessageDispatchWhenLicenseValid* message)
{
if (m_app != nullptr && !checkLicenseString())
{
m_pendingMessage = message->content;
if (!m_forcedLicenseEntering)
{
m_app->forceEnterLicense();
m_forcedLicenseEntering = true;
}
}
else
{
message->content->dispatch();
}
}
void LicenseChecker::handleMessage(MessageEnteredLicense* message)
{
m_forcedLicenseEntering = false;
if (m_pendingMessage)
{
m_pendingMessage->dispatch();
m_pendingMessage.reset();
}
}
bool LicenseChecker::checkLicenseString()
{
MessageStatus("preparing...", false, true).dispatch();
bool valid = false;
do
{
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
std::string licenseCheck = appSettings->getLicenseCheck();
std::string appPath = AppPath::getAppPath(); // for easier debugging...
FilePath p(appPath);
if (!License::checkLocation(p.absolute().str(), licenseCheck))
{
break;
}
std::string licenseString = appSettings->getLicenseString();
if (licenseString.size() == 0)
{
break;
}
License license;
bool isLoaded = license.loadFromEncodedString(licenseString,AppPath::getAppPath());
if (!isLoaded)
{
break;
}
license.loadPublicKeyFromString(PublicKey);
valid = license.isValid();
if (license.isExpired())
{
valid = false;
}
}
while (false);
MessageStatus("ready").dispatch();
return valid;
}
std::shared_ptr<LicenseChecker> LicenseChecker::s_instance;