license: Implemented new license format
* Implemented new format splitting user, version, and usage period into separate lines * Refactored all classes: License, LicenseGenerator, LicenseChecker * Removed redundant license check hash from ApplicationSettings, don't generate, store and check it anymore * Moved license checking and encoding logic to LicenseChecker * Moved default for license generation to main.cpp * Refactored license checking logic in whole app, removed involved message types * Added LicenseCheckerTestSuite for checking all legacy and current license types * Generate new license type lifelong
This commit is contained in:
@@ -98,12 +98,12 @@ void QtMainView::saveLayout()
|
||||
m_window->saveLayout();
|
||||
}
|
||||
|
||||
void QtMainView::loadWindow(bool showStartWindow)
|
||||
void QtMainView::loadWindow(bool showStartWindow, bool showEULA, bool enterLicense, std::string licenseError)
|
||||
{
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
m_window->loadWindow(showStartWindow);
|
||||
m_window->loadWindow(showStartWindow, showEULA, enterLicense, licenseError);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -163,6 +163,16 @@ void QtMainView::activateWindow()
|
||||
);
|
||||
}
|
||||
|
||||
void QtMainView::forceEnterLicense(std::string licenseError)
|
||||
{
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
m_window->forceEnterLicense(licenseError);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtMainView::updateRecentProjectMenu()
|
||||
{
|
||||
m_onQtThread(
|
||||
@@ -208,18 +218,6 @@ void QtMainView::clearBookmarksMenu()
|
||||
updateBookmarksMenu({});
|
||||
}
|
||||
|
||||
void QtMainView::handleMessage(MessageForceEnterLicense* message)
|
||||
{
|
||||
LicenseChecker::LicenseState state = message->state;
|
||||
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
m_window->forceEnterLicense(state);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtMainView::handleMessage(MessageProjectEdit* message)
|
||||
{
|
||||
m_onQtThread(
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "QtThreadedFunctor.h"
|
||||
|
||||
#include "MessageListener.h"
|
||||
#include "MessageForceEnterLicense.h"
|
||||
#include "MessageProjectEdit.h"
|
||||
#include "MessageProjectNew.h"
|
||||
|
||||
@@ -19,7 +18,6 @@ class View;
|
||||
|
||||
class QtMainView
|
||||
: public MainView
|
||||
, public MessageListener<MessageForceEnterLicense>
|
||||
, public MessageListener<MessageProjectEdit>
|
||||
, public MessageListener<MessageProjectNew>
|
||||
{
|
||||
@@ -50,13 +48,14 @@ public:
|
||||
void loadLayout() override;
|
||||
void saveLayout() override;
|
||||
|
||||
void loadWindow(bool showStartWindow) override;
|
||||
void loadWindow(bool showStartWindow, bool showEULA, bool enterLicense, std::string licenseError) override;
|
||||
|
||||
void refreshView() override;
|
||||
|
||||
void hideStartScreen() override;
|
||||
void setTitle(const std::wstring& title) override;
|
||||
void activateWindow() override;
|
||||
void forceEnterLicense(std::string licenseError) override;
|
||||
|
||||
void updateRecentProjectMenu() override;
|
||||
|
||||
@@ -67,7 +66,6 @@ public:
|
||||
void clearBookmarksMenu() override;
|
||||
|
||||
private:
|
||||
void handleMessage(MessageForceEnterLicense* message) override;
|
||||
void handleMessage(MessageProjectEdit* message) override;
|
||||
void handleMessage(MessageProjectNew* message) override;
|
||||
|
||||
|
||||
@@ -7,9 +7,8 @@ class QtEulaWindow
|
||||
: public QtWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static const int EULA_VERSION = 5;
|
||||
|
||||
public:
|
||||
QtEulaWindow(QWidget* parent, bool forceAccept);
|
||||
QSize sizeHint() const override;
|
||||
|
||||
|
||||
@@ -85,9 +85,11 @@ void QtLicenseWindow::populateWindow(QWidget* widget)
|
||||
m_licenseText->setPlaceholderText(
|
||||
"-----BEGIN LICENSE-----\n"
|
||||
"Product: Sourcetrail\n"
|
||||
"Licensed to:\n"
|
||||
"License holder:\n"
|
||||
"License type:\n"
|
||||
"Valid up to version:\n"
|
||||
"Licensed number of users:\n"
|
||||
"Licensed product version:\n"
|
||||
"Licensed usage period:\n"
|
||||
"-\n"
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
|
||||
@@ -152,45 +154,22 @@ void QtLicenseWindow::handleNext()
|
||||
if (m_commercialUse->isChecked())
|
||||
{
|
||||
std::string licenseString = m_licenseText->toPlainText().toStdString();
|
||||
|
||||
LicenseChecker::LicenseState state = LicenseChecker::checkLicenseString(licenseString);
|
||||
|
||||
std::string errorString;
|
||||
std::string errorString = LicenseChecker::getLicenseErrorForState(state);
|
||||
|
||||
switch (state)
|
||||
if (state == LicenseChecker::LicenseState::VALID)
|
||||
{
|
||||
case LicenseChecker::LICENSE_EMPTY:
|
||||
errorString = "No license key was entered.";
|
||||
break;
|
||||
case LicenseChecker::LICENSE_MOVED:
|
||||
case LicenseChecker::LICENSE_MALFORMED:
|
||||
errorString = "The entered license key is malformed.";
|
||||
break;
|
||||
case LicenseChecker::LICENSE_INVALID:
|
||||
errorString = "The entered license key is invalid.";
|
||||
break;
|
||||
case LicenseChecker::LICENSE_EXPIRED:
|
||||
errorString = "The entered license key is expired.";
|
||||
break;
|
||||
case LicenseChecker::LICENSE_VALID:
|
||||
{
|
||||
if (LicenseChecker::getLicenseType(licenseString) == MessageEnteredLicense::LICENSE_NON_COMMERCIAL)
|
||||
{
|
||||
errorString =
|
||||
"The entered license key does not permit commercial use. You no longer need a license "
|
||||
"key for non-commercial use. Please choose the non-commercial option below.";
|
||||
break;
|
||||
}
|
||||
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
|
||||
|
||||
LicenseChecker::saveCurrentLicenseString(licenseString);
|
||||
m_errorLabel->setText(" ");
|
||||
LicenseChecker::setCurrentLicenseString(licenseString);
|
||||
|
||||
ApplicationSettings::getInstance()->setNonCommercialUse(false);
|
||||
ApplicationSettings::getInstance()->save();
|
||||
appSettings->setLicenseString(LicenseChecker::getCurrentLicenseStringEncoded());
|
||||
appSettings->setNonCommercialUse(false);
|
||||
appSettings->save();
|
||||
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
|
||||
m_errorLabel->setText(errorString.c_str());
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "QtStartScreen.h"
|
||||
#include "ApplicationSettings.h"
|
||||
#include "FileSystem.h"
|
||||
#include "LicenseChecker.h"
|
||||
#include "logging.h"
|
||||
#include "MessageErrorsHelpMessage.h"
|
||||
#include "MessageHistoryRedo.h"
|
||||
@@ -39,7 +40,6 @@
|
||||
#include "MessageBookmarkBrowse.h"
|
||||
#include "MessageBookmarkCreate.h"
|
||||
#include "MessageCodeReference.h"
|
||||
#include "MessageEnteredLicense.h"
|
||||
#include "MessageFind.h"
|
||||
#include "MessageIndexingShowDialog.h"
|
||||
#include "MessageLoadProject.h"
|
||||
@@ -116,8 +116,7 @@ bool MouseReleaseFilter::eventFilter(QObject* obj, QEvent* event)
|
||||
|
||||
|
||||
QtMainWindow::QtMainWindow()
|
||||
: m_loaded(false)
|
||||
, m_historyMenu(nullptr)
|
||||
: m_historyMenu(nullptr)
|
||||
, m_bookmarksMenu(nullptr)
|
||||
, m_showDockWidgetTitleBars(true)
|
||||
, m_windowStack(this)
|
||||
@@ -324,46 +323,20 @@ void QtMainWindow::loadDockWidgetLayout()
|
||||
}
|
||||
}
|
||||
|
||||
void QtMainWindow::loadWindow(bool showStartWindow)
|
||||
void QtMainWindow::loadWindow(bool showStartWindow, bool showEULA, bool enterLicense, const std::string& licenseError)
|
||||
{
|
||||
if (m_loaded)
|
||||
{
|
||||
if (!showStartWindow)
|
||||
{
|
||||
hideStartScreen();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
m_loaded = true;
|
||||
|
||||
LicenseChecker::LicenseState state = LicenseChecker::checkCurrentLicense();
|
||||
bool licenseValid = (state == LicenseChecker::LICENSE_VALID);
|
||||
|
||||
if (licenseValid)
|
||||
{
|
||||
MessageEnteredLicense(LicenseChecker::getCurrentLicenseType()).dispatch();
|
||||
}
|
||||
|
||||
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
|
||||
|
||||
if (state == LicenseChecker::LICENSE_MOVED)
|
||||
{
|
||||
appSettings->setLicenseString("");
|
||||
}
|
||||
|
||||
if (showStartWindow)
|
||||
{
|
||||
showStartScreen();
|
||||
}
|
||||
|
||||
if (state != LicenseChecker::LICENSE_VALID && !appSettings->getNonCommercialUse())
|
||||
if (enterLicense)
|
||||
{
|
||||
forceEnterLicense(state);
|
||||
forceEnterLicense(licenseError);
|
||||
}
|
||||
|
||||
#ifndef Q_OS_WIN
|
||||
if (appSettings->getAcceptedEulaVersion() < QtEulaWindow::EULA_VERSION)
|
||||
if (showEULA)
|
||||
{
|
||||
showEula(true);
|
||||
}
|
||||
@@ -387,7 +360,7 @@ void QtMainWindow::saveLayout()
|
||||
settings.setValue("DOCK_LOCATIONS", this->saveState());
|
||||
}
|
||||
|
||||
void QtMainWindow::forceEnterLicense(LicenseChecker::LicenseState state)
|
||||
void QtMainWindow::forceEnterLicense(const std::string& licenseError)
|
||||
{
|
||||
QtLicenseWindow* window = dynamic_cast<QtLicenseWindow*>(m_windowStack.getTopWindow());
|
||||
if (window)
|
||||
@@ -404,14 +377,9 @@ void QtMainWindow::forceEnterLicense(LicenseChecker::LicenseState state)
|
||||
return;
|
||||
}
|
||||
|
||||
if (state == LicenseChecker::LICENSE_EXPIRED)
|
||||
if (licenseError.size())
|
||||
{
|
||||
window->setErrorMessage("The license key is expired.");
|
||||
}
|
||||
else if (state != LicenseChecker::LICENSE_VALID && state != LicenseChecker::LICENSE_EMPTY)
|
||||
{
|
||||
window->clear();
|
||||
window->setErrorMessage("Please re-enter your license key.");
|
||||
window->setErrorMessage(QString::fromStdString(licenseError));
|
||||
}
|
||||
|
||||
window->updateCloseButton("Quit");
|
||||
@@ -620,7 +588,7 @@ void QtMainWindow::showEula(bool forceAccept)
|
||||
|
||||
void QtMainWindow::acceptedEula()
|
||||
{
|
||||
ApplicationSettings::getInstance()->setAcceptedEulaVersion(QtEulaWindow::EULA_VERSION);
|
||||
ApplicationSettings::getInstance()->setAcceptedEulaVersion(Application::EULA_VERSION);
|
||||
ApplicationSettings::getInstance()->save();
|
||||
|
||||
setEnabled(true);
|
||||
@@ -654,7 +622,7 @@ void QtMainWindow::enteredLicense()
|
||||
|
||||
m_windowStack.clearWindows();
|
||||
|
||||
MessageEnteredLicense(LicenseChecker::getCurrentLicenseType()).dispatch();
|
||||
MessageRefreshUI().dispatch();
|
||||
|
||||
setEnabled(true);
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "SearchMatch.h"
|
||||
#include "LicenseChecker.h"
|
||||
#include "QtWindowsTaskbarButton.h"
|
||||
#include "QtWindowStack.h"
|
||||
|
||||
class Bookmark;
|
||||
class MessageBase;
|
||||
class QDockWidget;
|
||||
class View;
|
||||
|
||||
@@ -73,9 +73,9 @@ public:
|
||||
void saveLayout();
|
||||
|
||||
void loadDockWidgetLayout();
|
||||
void loadWindow(bool showStartWindow);
|
||||
void loadWindow(bool showStartWindow, bool showEULA, bool enterLicense, const std::string& licenseError);
|
||||
|
||||
void forceEnterLicense(LicenseChecker::LicenseState state);
|
||||
void forceEnterLicense(const std::string& licenseError);
|
||||
|
||||
void updateHistoryMenu(std::shared_ptr<MessageBase> message);
|
||||
void clearHistoryMenu();
|
||||
@@ -190,8 +190,6 @@ private:
|
||||
|
||||
std::vector<DockWidget> m_dockWidgets;
|
||||
|
||||
bool m_loaded;
|
||||
|
||||
QMenu* m_viewMenu;
|
||||
QAction* m_viewSeparator;
|
||||
|
||||
|
||||
@@ -8,11 +8,9 @@
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "ApplicationSettings.h"
|
||||
#include "AppPath.h"
|
||||
#include "License.h"
|
||||
#include "LicenseChecker.h"
|
||||
#include "MessageLoadProject.h"
|
||||
#include "ProjectSettings.h"
|
||||
#include "PublicKey.h"
|
||||
#include "QtUpdateCheckerWidget.h"
|
||||
#include "QtNewsWidget.h"
|
||||
#include "ResourcePaths.h"
|
||||
@@ -146,9 +144,6 @@ void QtStartScreen::updateButtons()
|
||||
|
||||
void QtStartScreen::setupStartScreen()
|
||||
{
|
||||
License license;
|
||||
license.loadFromEncodedString(ApplicationSettings::getInstance()->getLicenseString(), AppPath::getAppPath().str());
|
||||
|
||||
setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath().concatenate(L"startscreen/startscreen.css")).c_str());
|
||||
addLogo();
|
||||
|
||||
@@ -170,15 +165,15 @@ void QtStartScreen::setupStartScreen()
|
||||
|
||||
col->addSpacing(15);
|
||||
|
||||
if (license.isValid())
|
||||
if (LicenseChecker::checkCurrentLicense() == LicenseChecker::LicenseState::VALID)
|
||||
{
|
||||
std::string licenseString = license.getLicenseInfo();
|
||||
std::string licenseInfo = LicenseChecker::getCurrentLicense()->getLicenseInfo();
|
||||
|
||||
QLabel* licenseHeader = new QLabel("Licensed to:");
|
||||
licenseHeader->setObjectName("boldLabel");
|
||||
col->addWidget(licenseHeader);
|
||||
col->addSpacing(2);
|
||||
QLabel* licenseLabel = new QLabel(licenseString.c_str());
|
||||
QLabel* licenseLabel = new QLabel(licenseInfo.c_str());
|
||||
licenseLabel->setObjectName("textLabel");
|
||||
col->addWidget(licenseLabel);
|
||||
}
|
||||
|
||||
@@ -224,32 +224,3 @@ std::string utility::getOsTypeString()
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
bool utility::saveLicense(const License* license)
|
||||
{
|
||||
if (license == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (license->isValid())
|
||||
{
|
||||
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
|
||||
if (appSettings == nullptr)
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "Unable to retrieve app settings");
|
||||
return false;
|
||||
}
|
||||
|
||||
const FilePath appLocation = AppPath::getAppPath();
|
||||
appSettings->setLicenseString(license->getLicenseEncodedString(appLocation.str()));
|
||||
appSettings->setLicenseCheck(license->hashLocation(appLocation.getAbsolute().str()));
|
||||
appSettings->save();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR( "The entered license key is invalid.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,6 @@ namespace utility
|
||||
|
||||
OsType getOsType();
|
||||
std::string getOsTypeString();
|
||||
|
||||
bool saveLicense(const License* license);
|
||||
}
|
||||
|
||||
#endif // UTILITY_APP_H
|
||||
|
||||
Reference in New Issue
Block a user