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
+6 -9
View File
@@ -3,7 +3,9 @@
#include "utility/logging/logging.h"
#include "utility/messaging/MessageQueue.h"
#include "utility/messaging/type/MessageActivateNodes.h"
#include "utility/messaging/type/MessageDispatchWhenLicenseValid.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/messaging/type/MessageShowStartScreen.h"
#include "utility/scheduling/TaskScheduler.h"
#include "utility/UserPaths.h"
#include "utility/Version.h"
@@ -31,18 +33,13 @@ std::shared_ptr<Application> Application::create(
ptr->m_mainView = viewFactory->createMainView();
ptr->m_mainView->setTitle("Coati");
MessageDispatchWhenLicenseValid(std::make_shared<MessageShowStartScreen>()).dispatch();
ptr->m_componentManager->setup(ptr->m_mainView.get());
ptr->m_mainView->loadLayout();
ptr->m_project = Project::create(ptr->m_storageCache.get());
std::string startupProjectFilePath = ApplicationSettings::getInstance()->getStartupProjectFilePath();
if (startupProjectFilePath.size())
{
MessageLoadProject(startupProjectFilePath, false).dispatch();
ptr->m_mainView->hideStartScreen();
}
ptr->m_ideCommunicationController = networkFactory->createIDECommunicationController(ptr->m_storageCache.get());
ptr->startMessagingAndScheduling();
@@ -138,11 +135,11 @@ void Application::saveProject(const FilePath& projectSettingsFilePath)
}
}
void Application::showLicenseScreen()
void Application::forceEnterLicense()
{
if (m_hasGUI)
{
m_mainView->showLicenseScreen();
m_mainView->forceLicenseScreen();
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ public:
void loadProject(const FilePath& projectSettingsFilePath);
void refreshProject();
void saveProject(const FilePath& projectSettingsFilePath);
void showLicenseScreen();
void forceEnterLicense();
bool hasGUI();
private:
+4
View File
@@ -228,6 +228,7 @@ add_files(
utility/messaging/type/MessageChangeFileView.h
utility/messaging/type/MessageClearErrorCount.h
utility/messaging/type/MessageDeactivateEdge.h
utility/messaging/type/MessageDispatchWhenLicenseValid.h
utility/messaging/type/MessageEnteredLicense.h
utility/messaging/type/MessageFind.h
utility/messaging/type/MessageFinishedParsing.h
@@ -250,6 +251,7 @@ add_files(
utility/messaging/type/MessageSearchAutocomplete.h
utility/messaging/type/MessageShowErrors.h
utility/messaging/type/MessageShowScope.h
utility/messaging/type/MessageShowStartScreen.h
utility/messaging/type/MessageStatus.h
utility/messaging/type/MessageSwitchColorScheme.h
utility/messaging/type/MessageUndo.h
@@ -319,6 +321,8 @@ add_files(
Application.cpp
Application.h
isTrial.h
LicenseChecker.cpp
LicenseChecker.h
Project.cpp
Project.h
)
+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;
+38
View File
@@ -0,0 +1,38 @@
#ifndef LICENSE_CHECKER_H
#define LICENSE_CHECKER_H
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageEnteredLicense.h"
#include "utility/messaging/type/MessageDispatchWhenLicenseValid.h"
class Application;
class LicenseChecker
: public MessageListener<MessageDispatchWhenLicenseValid>
, public MessageListener<MessageEnteredLicense>
{
public:
static void createInstance();
static std::shared_ptr<LicenseChecker> getInstance();
~LicenseChecker();
void setApp(Application* app);
private:
LicenseChecker();
LicenseChecker(const LicenseChecker&) = delete;
void operator=(const LicenseChecker&) = delete;
void handleMessage(MessageDispatchWhenLicenseValid* message);
void handleMessage(MessageEnteredLicense* message);
bool checkLicenseString();
static std::shared_ptr<LicenseChecker> s_instance;
Application* m_app;
std::shared_ptr<MessageBase> m_pendingMessage;
bool m_forcedLicenseEntering;
};
#endif // LICENSE_CHECKER_H
@@ -6,6 +6,7 @@
#include "utility/messaging/type/MessageActivateTokenLocations.h"
#include "utility/messaging/type/MessageActivateWindow.h"
#include "utility/messaging/type/MessageDispatchWhenLicenseValid.h"
#include "utility/messaging/type/MessageLoadProject.h"
#include "utility/messaging/type/MessageProjectNew.h"
#include "utility/messaging/type/MessageStatus.h"
@@ -83,14 +84,14 @@ void IDECommunicationController::handleSetActiveTokenMessage(const NetworkProtoc
if (selectedLocationIds.size() > 0)
{
MessageStatus("Activating a source location from external succeeded.").dispatch();
MessageActivateTokenLocations(selectedLocationIds).dispatch();
MessageDispatchWhenLicenseValid(std::make_shared<MessageActivateTokenLocations>(selectedLocationIds)).dispatch();
MessageActivateWindow().dispatch();
}
else
{
MessageStatus(
"Activating a source location from external failed. No symbol(s) have been found at the selected location."
).dispatch();
).dispatch();
}
}
}
@@ -101,10 +102,10 @@ void IDECommunicationController::handleCreateProjectMessage(const NetworkProtoco
{
if (message.ideId == "vs")
{
MessageProjectNew msg;
msg.setSolutionPath(message.solutionFileLocation);
msg.ideId = message.ideId;
msg.dispatch();
std::shared_ptr<MessageProjectNew> msg = std::make_shared<MessageProjectNew>();
msg->setSolutionPath(message.solutionFileLocation);
msg->ideId = message.ideId;
MessageDispatchWhenLicenseValid(msg).dispatch();
}
else
{
@@ -125,4 +126,4 @@ void IDECommunicationController::handleMessage(MessageMoveIDECursor* message)
).dispatch();
sendMessage(networkMessage);
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ public:
virtual void setTitle(const std::string& title) = 0;
virtual void activateWindow() = 0;
virtual void updateRecentProjectMenu() = 0;
virtual void showLicenseScreen() = 0;
virtual void forceLicenseScreen() = 0;
};
#endif // MAIN_VIEW_H
-5
View File
@@ -18,11 +18,6 @@ ApplicationSettings::~ApplicationSettings()
{
}
std::string ApplicationSettings::getStartupProjectFilePath() const
{
return getValue<std::string>("startup_project", "");
}
int ApplicationSettings::getMaxRecentProjectsCount() const
{
return 7;
-2
View File
@@ -12,8 +12,6 @@ public:
static std::shared_ptr<ApplicationSettings> getInstance();
~ApplicationSettings();
std::string getStartupProjectFilePath() const;
int getMaxRecentProjectsCount() const;
// source
+2 -2
View File
@@ -31,8 +31,8 @@ public:
protected:
ColorScheme();
ColorScheme(const ColorScheme&);
void operator=(const ColorScheme&);
ColorScheme(const ColorScheme&) = delete;
void operator=(const ColorScheme&) = delete;
static std::shared_ptr<ColorScheme> s_instance;
+5 -1
View File
@@ -15,10 +15,14 @@ std::shared_ptr<MessageQueue> MessageQueue::getInstance()
{
s_instance = std::shared_ptr<MessageQueue>(new MessageQueue());
}
return s_instance;
}
MessageQueue::~MessageQueue()
{
// TODO: remove remaining listeners. And tell them that they shouldn't unregister anymore.
}
void MessageQueue::registerListener(MessageListenerBase* listener)
{
std::lock_guard<std::mutex> lock(m_listenersMutex);
+4 -2
View File
@@ -15,6 +15,8 @@ class MessageQueue
public:
static std::shared_ptr<MessageQueue> getInstance();
~MessageQueue();
void registerListener(MessageListenerBase* listener);
void unregisterListener(MessageListenerBase* listener);
@@ -38,8 +40,8 @@ private:
static std::shared_ptr<MessageQueue> s_instance;
MessageQueue();
MessageQueue(const MessageQueue&);
void operator=(const MessageQueue&);
MessageQueue(const MessageQueue&) = delete;
void operator=(const MessageQueue&) = delete;
void processMessages();
void sendMessage(std::shared_ptr<MessageBase> message);
@@ -0,0 +1,23 @@
#ifndef MESSAGE_DISPATCH_WHEN_LICENSE_VALID_H
#define MESSAGE_DISPATCH_WHEN_LICENSE_VALID_H
#include "utility/messaging/Message.h"
class MessageDispatchWhenLicenseValid
: public Message<MessageDispatchWhenLicenseValid>
{
public:
MessageDispatchWhenLicenseValid(std::shared_ptr<MessageBase> content)
: content(content)
{
}
static const std::string getStaticType()
{
return "MessageDispatchWhenLicenseValid";
}
std::shared_ptr<MessageBase> content;
};
#endif // MESSAGE_DISPATCH_WHEN_LICENSE_VALID_H
@@ -0,0 +1,20 @@
#ifndef MESSAGE_SHOW_START_SCREEN_H
#define MESSAGE_SHOW_START_SCREEN_H
#include "utility/messaging/Message.h"
class MessageShowStartScreen
: public Message<MessageShowStartScreen>
{
public:
MessageShowStartScreen()
{
}
static const std::string getStaticType()
{
return "MessageShowStartScreen";
}
};
#endif // MESSAGE_SHOW_START_SCREEN_H