summaryrefslogtreecommitdiffstats
path: root/tools/configure/tools.cpp
diff options
context:
space:
mode:
authorKalle Viironen <kalle.viironen@digia.com>2014-02-26 16:16:34 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-25 12:50:28 +0100
commitebcb5c176fa3552960f3b96c2fcbd7aaa2b29e50 (patch)
treec1c0d59848b93f09d1aae19d4da3d2480cfbcc0b /tools/configure/tools.cpp
parentdd1220651c50b0bacceab618df8fdf3a7f26a0ab (diff)
Externalize license key handling from configure
Enterprise only license key handling removed from configure. This does not affect the functionality of the Open Source version nor the enterprise version. Change-Id: I01736eba3066c56b6e50e022fae8de6aa9bd884b Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Diffstat (limited to 'tools/configure/tools.cpp')
-rw-r--r--tools/configure/tools.cpp189
1 files changed, 27 insertions, 162 deletions
diff --git a/tools/configure/tools.cpp b/tools/configure/tools.cpp
index 07c3c82a0b..e2a6f3cc8a 100644
--- a/tools/configure/tools.cpp
+++ b/tools/configure/tools.cpp
@@ -40,191 +40,56 @@
****************************************************************************/
#include "tools.h"
+#include "environment.h"
#include <qdir.h>
#include <qfile.h>
#include <qbytearray.h>
+#include <qstringlist.h>
-
-// std stuff ------------------------------------
#include <iostream>
-#include <windows.h>
-#include <conio.h>
-#define NUMBER_OF_PARTS 7
-std::ostream &operator<<(std::ostream &s, const QString &val); // defined in configureapp.cpp
+std::ostream &operator<<(std::ostream &s, const QString &val);
using namespace std;
-void Tools::checkLicense(QMap<QString,QString> &dictionary, QMap<QString,QString> &licenseInfo,
- const QString &path, const QString &sourcePath)
+void Tools::checkLicense(QMap<QString,QString> &dictionary,
+ const QString &sourcePath, const QString &buildPath)
{
- QString tpLicense = sourcePath + "/LICENSE.PREVIEW.OPENSOURCE";
- if (QFile::exists(tpLicense)) {
- dictionary["EDITION"] = "Preview";
- dictionary["LICENSE FILE"] = tpLicense;
- return; // No license key checking in Tech Preview
- }
- tpLicense = sourcePath + "/LICENSE.PREVIEW.COMMERCIAL";
+ QString tpLicense = sourcePath + "/LICENSE.PREVIEW.COMMERCIAL";
if (QFile::exists(tpLicense)) {
dictionary["EDITION"] = "Preview";
dictionary["LICENSE FILE"] = tpLicense;
- return; // No license key checking in Tech Preview
- }
-
- // Read in the license file
- QFile licenseFile(path);
- if( !path.isEmpty() && licenseFile.open( QFile::ReadOnly ) ) {
- cout << "Reading license file in....." << qPrintable(path) << endl;
-
- QString buffer = licenseFile.readLine(1024);
- while (!buffer.isEmpty()) {
- if( buffer[ 0 ] != '#' ) {
- QStringList components = buffer.split( '=' );
- if ( components.size() >= 2 ) {
- QStringList::Iterator it = components.begin();
- QString key = (*it++).trimmed().remove('"').toUpper();
- QString value = (*it++).trimmed().remove('"');
- licenseInfo[ key ] = value;
- }
- }
- // read next line
- buffer = licenseFile.readLine(1024);
- }
- licenseFile.close();
- } else {
- cout << "License file not found in " << QDir::homePath() << endl;
- cout << "Please put the Qt license file, '.qt-license' in your home "
- << "directory and run configure again.";
- dictionary["DONE"] = "error";
- return;
- }
-
- // Verify license info...
- QString licenseKey = licenseInfo["LICENSEKEYEXT"];
- QByteArray clicenseKey = licenseKey.toLatin1();
- //We check the license
- static const char * const SEP = "-";
- char *licenseParts[NUMBER_OF_PARTS];
- int partNumber = 0;
- for (char *part = strtok(clicenseKey.data(), SEP); part != 0; part = strtok(0, SEP))
- licenseParts[partNumber++] = part;
- if (partNumber < (NUMBER_OF_PARTS-1)) {
- dictionary["DONE"] = "error";
- cout << "License file does not contain proper license key." <<partNumber<< endl;
return;
}
- char products = licenseParts[0][0];
- char* platforms = licenseParts[1];
- char* licenseSchema = licenseParts[2];
- char licenseFeatures = licenseParts[3][0];
+ const QString licenseChecker =
+ QDir::toNativeSeparators(sourcePath + "/bin/licheck.exe");
- // Determine edition ---------------------------------------------------------------------------
- QString licenseType;
- if (strcmp(licenseSchema,"F4M") == 0) {
- licenseType = "Commercial";
- if (products == 'F') {
- dictionary["EDITION"] = "Universal";
- } else if (products == 'B') {
- dictionary["EDITION"] = "FullFramework";
- } else {
- dictionary["EDITION"] = "GUIFramework";
- }
- } else if (strcmp(licenseSchema,"Z4M") == 0 || strcmp(licenseSchema,"R4M") == 0 || strcmp(licenseSchema,"Q4M") == 0) {
- if (products == 'B') {
- dictionary["EDITION"] = "Evaluation";
- licenseType = "Evaluation";
- }
- }
+ if (QFile::exists(licenseChecker)) {
+ const QString qMakeSpec =
+ QDir::toNativeSeparators(dictionary.value("QMAKESPEC"));
+ const QString xQMakeSpec =
+ QDir::toNativeSeparators(dictionary.value("XQMAKESPEC"));
- if (platforms[2] == 'L') {
- static const char src[] = "8NPQRTZ";
- static const char dst[] = "UCWX9M7";
- const char *p = strchr(src, platforms[1]);
- platforms[1] = dst[p - src];
- }
+ QString command = QString("%1 %2 %3 %4 %5")
+ .arg(licenseChecker,
+ QDir::toNativeSeparators(sourcePath),
+ QDir::toNativeSeparators(buildPath),
+ qMakeSpec, xQMakeSpec);
-#define PL(a,b) (int(a)+int(b)*256)
- int platformCode = PL(platforms[0],platforms[1]);
- switch (platformCode) {
- case PL('X','9'):
- case PL('X','C'):
- case PL('X','U'):
- case PL('X','W'):
- case PL('X','M'): // old license key
- dictionary["LICENSE_EXTENSION"] = "-ALLOS";
- break;
+ int returnValue = 0;
+ QString licheckOutput = Environment::execute(command, &returnValue);
- case PL('6', 'M'):
- case PL('8', 'M'):
- case PL('K', 'M'): // old license key
- case PL('N', '7'):
- case PL('N', '9'):
- case PL('N', 'X'):
- case PL('S', '9'):
- case PL('S', 'C'):
- case PL('S', 'U'):
- case PL('S', 'W'):
- dictionary["LICENSE_EXTENSION"] = "-EMBEDDED";
- if (dictionary["PLATFORM NAME"].contains("Windows CE")
- && platformCode != PL('6', 'M') && platformCode != PL('S', '9')
- && platformCode != PL('S', 'C') && platformCode != PL('S', 'U')
- && platformCode != PL('S', 'W') && platformCode != PL('K', 'M')) {
- dictionary["DONE"] = "error";
- }
- break;
- case PL('R', 'M'):
- case PL('F', 'M'):
- dictionary["LICENSE_EXTENSION"] = "-DESKTOP";
- if (!dictionary["PLATFORM NAME"].endsWith("Windows")) {
+ if (returnValue) {
dictionary["DONE"] = "error";
+ } else {
+ foreach (const QString &var, licheckOutput.split('\n'))
+ dictionary[var.section('=', 0, 0).toUpper()] = var.section('=', 1, 1);
}
- break;
- default:
- dictionary["DONE"] = "error";
- break;
- }
-#undef PL
-
- if (dictionary.value("DONE") == "error") {
- cout << "You are not licensed for the " << dictionary["PLATFORM NAME"] << " platform." << endl << endl;
- cout << "Please use the contact form at http://qt.digia.com/contact-us to upgrade your license" << endl;
- cout << "to include the " << dictionary["PLATFORM NAME"] << " platform, or install the" << endl;
- cout << "Qt Open Source Edition if you intend to develop free software." << endl;
- return;
- }
-
- // Override for evaluation licenses
- if (dictionary["EDITION"] == "Evaluation")
- dictionary["LICENSE_EXTENSION"] = "-EVALUATION";
-
- if (QFile::exists(sourcePath + "/.LICENSE")) {
- // Generic, no-suffix license
- dictionary["LICENSE_EXTENSION"].clear();
- } else if (dictionary["LICENSE_EXTENSION"].isEmpty()) {
- cout << "License file does not contain proper license key." << endl;
- dictionary["DONE"] = "error";
- }
- if (licenseType.isEmpty()
- || dictionary["EDITION"].isEmpty()) {
- cout << "License file does not contain proper license key." << endl;
- dictionary["DONE"] = "error";
- return;
- }
-
- // copy one of .LICENSE-*(-US) to LICENSE
- QString toLicenseFile = sourcePath + "/LICENSE";
- QString fromLicenseFile = sourcePath + "/.LICENSE" + dictionary["LICENSE_EXTENSION"];
- if (licenseFeatures == 'B' || licenseFeatures == 'G'
- || licenseFeatures == 'L' || licenseFeatures == 'Y')
- fromLicenseFile += "-US";
-
- if (!CopyFile((wchar_t*)QDir::toNativeSeparators(fromLicenseFile).utf16(),
- (wchar_t*)QDir::toNativeSeparators(toLicenseFile).utf16(), false)) {
- cout << "Failed to copy license file (" << fromLicenseFile << ")";
+ } else {
+ cout << endl << "Error: Could not find licheck.exe" << endl
+ << "Try re-installing." << endl << endl;
dictionary["DONE"] = "error";
- return;
}
- dictionary["LICENSE FILE"] = toLicenseFile;
}