| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the tools applications of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "tools.h"
|
|---|
| 43 |
|
|---|
| 44 | #include <QDir>
|
|---|
| 45 | #include <QFile>
|
|---|
| 46 | #include <QByteArray>
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | // std stuff ------------------------------------
|
|---|
| 50 | #include <iostream>
|
|---|
| 51 | #include <windows.h>
|
|---|
| 52 | #include <conio.h>
|
|---|
| 53 | #define NUMBER_OF_PARTS 7
|
|---|
| 54 |
|
|---|
| 55 | std::ostream &operator<<(std::ostream &s, const QString &val); // defined in configureapp.cpp
|
|---|
| 56 | using namespace std;
|
|---|
| 57 |
|
|---|
| 58 | void Tools::checkLicense(QMap<QString,QString> &dictionary, QMap<QString,QString> &licenseInfo,
|
|---|
| 59 | const QString &path)
|
|---|
| 60 | {
|
|---|
| 61 | QString tpLicense = dictionary["QT_SOURCE_TREE"] + "/LICENSE.PREVIEW.OPENSOURCE";
|
|---|
| 62 | if (QFile::exists(tpLicense)) {
|
|---|
| 63 | dictionary["EDITION"] = "Preview";
|
|---|
| 64 | dictionary["LICENSE FILE"] = tpLicense;
|
|---|
| 65 | dictionary["QT_EDITION"] = "QT_EDITION_OPENSOURCE";
|
|---|
| 66 | return; // No license key checking in Tech Preview
|
|---|
| 67 | }
|
|---|
| 68 | tpLicense = dictionary["QT_SOURCE_TREE"] + "/LICENSE.PREVIEW.COMMERCIAL";
|
|---|
| 69 | if (QFile::exists(tpLicense)) {
|
|---|
| 70 | dictionary["EDITION"] = "Preview";
|
|---|
| 71 | dictionary["LICENSE FILE"] = tpLicense;
|
|---|
| 72 | dictionary["QT_EDITION"] = "QT_EDITION_DESKTOP";
|
|---|
| 73 | return; // No license key checking in Tech Preview
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | // Read in the license file
|
|---|
| 77 | QFile licenseFile(path);
|
|---|
| 78 | if( !path.isEmpty() && licenseFile.open( QFile::ReadOnly ) ) {
|
|---|
| 79 | cout << "Reading license file in....." << qPrintable(path) << endl;
|
|---|
| 80 |
|
|---|
| 81 | QString buffer = licenseFile.readLine(1024);
|
|---|
| 82 | while (!buffer.isEmpty()) {
|
|---|
| 83 | if( buffer[ 0 ] != '#' ) {
|
|---|
| 84 | QStringList components = buffer.split( '=' );
|
|---|
| 85 | if ( components.size() >= 2 ) {
|
|---|
| 86 | QStringList::Iterator it = components.begin();
|
|---|
| 87 | QString key = (*it++).trimmed().replace( "\"", QString() ).toUpper();
|
|---|
| 88 | QString value = (*it++).trimmed().replace( "\"", QString() );
|
|---|
| 89 | licenseInfo[ key ] = value;
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 | // read next line
|
|---|
| 93 | buffer = licenseFile.readLine(1024);
|
|---|
| 94 | }
|
|---|
| 95 | licenseFile.close();
|
|---|
| 96 | } else {
|
|---|
| 97 | cout << "License file not found in " << QDir::homePath() << endl;
|
|---|
| 98 | cout << "Please put the Qt license file, '.qt-license' in your home "
|
|---|
| 99 | << "directory and run configure again.";
|
|---|
| 100 | dictionary["DONE"] = "error";
|
|---|
| 101 | return;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | // Verify license info...
|
|---|
| 105 | QString licenseKey = licenseInfo["LICENSEKEYEXT"];
|
|---|
| 106 | const char * clicenseKey = licenseKey.toLatin1();
|
|---|
| 107 | //We check the licence
|
|---|
| 108 | #ifndef _WIN32_WCE
|
|---|
| 109 | char *buffer = strdup(clicenseKey);
|
|---|
| 110 | #else
|
|---|
| 111 | char *buffer = (char*) malloc(strlen(clicenseKey) + 1);
|
|---|
| 112 | strcpy(buffer, clicenseKey);
|
|---|
| 113 | #endif
|
|---|
| 114 | static const char * const SEP = "-";
|
|---|
| 115 | char *licenseParts[NUMBER_OF_PARTS];
|
|---|
| 116 | int partNumber = 0;
|
|---|
| 117 | for (char *part = strtok(buffer, SEP); part != 0; part = strtok(0, SEP))
|
|---|
| 118 | licenseParts[partNumber++] = part;
|
|---|
| 119 | if (partNumber < (NUMBER_OF_PARTS-1)) {
|
|---|
| 120 | dictionary["DONE"] = "error";
|
|---|
| 121 | cout << "License file does not contain proper license key." <<partNumber<< endl;
|
|---|
| 122 | free(buffer);
|
|---|
| 123 | return;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | char products = licenseParts[0][0];
|
|---|
| 127 | char platforms = licenseParts[1][0];
|
|---|
| 128 | char* licenseSchema = licenseParts[2];
|
|---|
| 129 | char licenseFeatures = licenseParts[3][0];
|
|---|
| 130 |
|
|---|
| 131 | // Determine edition ---------------------------------------------------------------------------
|
|---|
| 132 | QString licenseType;
|
|---|
| 133 | if (strcmp(licenseSchema,"F4M") == 0) {
|
|---|
| 134 | licenseType = "Commercial";
|
|---|
| 135 | if (products == 'F') {
|
|---|
| 136 | dictionary["EDITION"] = "Universal";
|
|---|
| 137 | dictionary["QT_EDITION"] = "QT_EDITION_UNIVERSAL";
|
|---|
| 138 | } else if (products == 'B') {
|
|---|
| 139 | dictionary["EDITION"] = "FullFramework";
|
|---|
| 140 | dictionary["QT_EDITION"] = "QT_EDITION_DESKTOP";
|
|---|
| 141 | } else {
|
|---|
| 142 | dictionary["EDITION"] = "GUIFramework";
|
|---|
| 143 | dictionary["QT_EDITION"] = "QT_EDITION_DESKTOPLIGHT";
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | if (platforms == 'X') {
|
|---|
| 147 | dictionary["LICENSE_EXTENSION"] = "-ALLOS";
|
|---|
| 148 | } else if (strchr("3679ACDEHJKMSUWX", platforms)) {
|
|---|
| 149 | dictionary["LICENSE_EXTENSION"] = "-EMBEDDED";
|
|---|
| 150 | } else if (strchr("4BFPQRTY", platforms)) {
|
|---|
| 151 | dictionary["LICENSE_EXTENSION"] = "-DESKTOP";
|
|---|
| 152 | }
|
|---|
| 153 | } else if (strcmp(licenseSchema,"Z4M") == 0 || strcmp(licenseSchema,"R4M") == 0 || strcmp(licenseSchema,"Q4M") == 0) {
|
|---|
| 154 | if (products == 'B') {
|
|---|
| 155 | dictionary["EDITION"] = "Evaluation";
|
|---|
| 156 | dictionary["QT_EDITION"] = "QT_EDITION_EVALUATION";
|
|---|
| 157 | dictionary["LICENSE_EXTENSION"] = "-EVALUATION";
|
|---|
| 158 | }
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | if (QFile::exists(dictionary["QT_SOURCE_TREE"] + "/.LICENSE")) {
|
|---|
| 162 | // Generic, no-suffix license
|
|---|
| 163 | dictionary["LICENSE_EXTENSION"] = QString();
|
|---|
| 164 | } else if (dictionary["LICENSE_EXTENSION"].isEmpty()) {
|
|---|
| 165 | cout << "License file does not contain proper license key." << endl;
|
|---|
| 166 | dictionary["DONE"] = "error";
|
|---|
| 167 | }
|
|---|
| 168 | if (licenseType.isEmpty()
|
|---|
| 169 | || dictionary["EDITION"].isEmpty()
|
|---|
| 170 | || dictionary["QT_EDITION"].isEmpty()) {
|
|---|
| 171 | cout << "License file does not contain proper license key." << endl;
|
|---|
| 172 | dictionary["DONE"] = "error";
|
|---|
| 173 | return;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | if (dictionary["PLATFORM NAME"].contains("Windows CE")) {
|
|---|
| 177 | // verify that we are licensed to use Qt for Windows CE
|
|---|
| 178 | if (dictionary["LICENSE_EXTENSION"] != "-EMBEDDED" && dictionary["LICENSE_EXTENSION"] != "-ALLOS") {
|
|---|
| 179 | cout << "You are not licensed for the " << dictionary["PLATFORM NAME"] << " platform." << endl << endl;
|
|---|
| 180 | cout << "Please contact sales@trolltech.com to upgrade your license" << endl;
|
|---|
| 181 | cout << "to include the " << dictionary["PLATFORM NAME"] << " platform, or install the" << endl;
|
|---|
| 182 | cout << "Qt Open Source Edition if you intend to develop free software." << endl;
|
|---|
| 183 | dictionary["DONE"] = "error";
|
|---|
| 184 | return;
|
|---|
| 185 | }
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | // copy one of .LICENSE-*(-US) to LICENSE
|
|---|
| 189 | QString toLicenseFile = dictionary["QT_SOURCE_TREE"] + "/LICENSE";
|
|---|
| 190 | QString fromLicenseFile = dictionary["QT_SOURCE_TREE"] + "/.LICENSE" + dictionary["LICENSE_EXTENSION"];
|
|---|
| 191 | if (licenseFeatures == 'G') //US
|
|---|
| 192 | fromLicenseFile += "-US";
|
|---|
| 193 |
|
|---|
| 194 | if (licenseFeatures == '5') //Floating
|
|---|
| 195 | dictionary["METERED LICENSE"] = "true";
|
|---|
| 196 |
|
|---|
| 197 | if (!CopyFileA(QDir::toNativeSeparators(fromLicenseFile).toLocal8Bit(),
|
|---|
| 198 | QDir::toNativeSeparators(toLicenseFile).toLocal8Bit(), FALSE)) {
|
|---|
| 199 | cout << "Failed to copy license file (" << fromLicenseFile << ")";
|
|---|
| 200 | dictionary["DONE"] = "error";
|
|---|
| 201 | return;
|
|---|
| 202 | }
|
|---|
| 203 | dictionary["LICENSE FILE"] = toLicenseFile;
|
|---|
| 204 | free(buffer);
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|