| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the tools applications of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at qt-info@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 | if (dictionary[ "BUILDNOKIA" ] == "yes") {
|
|---|
| 62 | dictionary["EDITION"] = "NokiaInternalBuild";
|
|---|
| 63 | dictionary["LICENSE_FILE"] = ""; // No License for nokia developers
|
|---|
| 64 | dictionary["QT_EDITION"] = "QT_EDITION_OPENSOURCE";
|
|---|
| 65 | return; // No license key checking in internal builds
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | QString tpLicense = dictionary["QT_SOURCE_TREE"] + "/LICENSE.PREVIEW.OPENSOURCE";
|
|---|
| 69 | if (QFile::exists(tpLicense)) {
|
|---|
| 70 | dictionary["EDITION"] = "Preview";
|
|---|
| 71 | dictionary["LICENSE FILE"] = tpLicense;
|
|---|
| 72 | dictionary["QT_EDITION"] = "QT_EDITION_OPENSOURCE";
|
|---|
| 73 | return; // No license key checking in Tech Preview
|
|---|
| 74 | }
|
|---|
| 75 | tpLicense = dictionary["QT_SOURCE_TREE"] + "/LICENSE.PREVIEW.COMMERCIAL";
|
|---|
| 76 | if (QFile::exists(tpLicense)) {
|
|---|
| 77 | dictionary["EDITION"] = "Preview";
|
|---|
| 78 | dictionary["LICENSE FILE"] = tpLicense;
|
|---|
| 79 | dictionary["QT_EDITION"] = "QT_EDITION_DESKTOP";
|
|---|
| 80 | return; // No license key checking in Tech Preview
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | // Read in the license file
|
|---|
| 84 | QFile licenseFile(path);
|
|---|
| 85 | if( !path.isEmpty() && licenseFile.open( QFile::ReadOnly ) ) {
|
|---|
| 86 | cout << "Reading license file in....." << qPrintable(path) << endl;
|
|---|
| 87 |
|
|---|
| 88 | QString buffer = licenseFile.readLine(1024);
|
|---|
| 89 | while (!buffer.isEmpty()) {
|
|---|
| 90 | if( buffer[ 0 ] != '#' ) {
|
|---|
| 91 | QStringList components = buffer.split( '=' );
|
|---|
| 92 | if ( components.size() >= 2 ) {
|
|---|
| 93 | QStringList::Iterator it = components.begin();
|
|---|
| 94 | QString key = (*it++).trimmed().replace( "\"", QString() ).toUpper();
|
|---|
| 95 | QString value = (*it++).trimmed().replace( "\"", QString() );
|
|---|
| 96 | licenseInfo[ key ] = value;
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 | // read next line
|
|---|
| 100 | buffer = licenseFile.readLine(1024);
|
|---|
| 101 | }
|
|---|
| 102 | licenseFile.close();
|
|---|
| 103 | } else {
|
|---|
| 104 | cout << "License file not found in " << QDir::homePath() << endl;
|
|---|
| 105 | cout << "Please put the Qt license file, '.qt-license' in your home "
|
|---|
| 106 | << "directory and run configure again.";
|
|---|
| 107 | dictionary["DONE"] = "error";
|
|---|
| 108 | return;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | // Verify license info...
|
|---|
| 112 | QString licenseKey = licenseInfo["LICENSEKEYEXT"];
|
|---|
| 113 | QByteArray clicenseKey = licenseKey.toLatin1();
|
|---|
| 114 | //We check the licence
|
|---|
| 115 | static const char * const SEP = "-";
|
|---|
| 116 | char *licenseParts[NUMBER_OF_PARTS];
|
|---|
| 117 | int partNumber = 0;
|
|---|
| 118 | for (char *part = strtok(clicenseKey.data(), SEP); part != 0; part = strtok(0, SEP))
|
|---|
| 119 | licenseParts[partNumber++] = part;
|
|---|
| 120 | if (partNumber < (NUMBER_OF_PARTS-1)) {
|
|---|
| 121 | dictionary["DONE"] = "error";
|
|---|
| 122 | cout << "License file does not contain proper license key." <<partNumber<< endl;
|
|---|
| 123 | return;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | char products = licenseParts[0][0];
|
|---|
| 127 | char* platforms = licenseParts[1];
|
|---|
| 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 | } else if (strcmp(licenseSchema,"Z4M") == 0 || strcmp(licenseSchema,"R4M") == 0 || strcmp(licenseSchema,"Q4M") == 0) {
|
|---|
| 146 | if (products == 'B') {
|
|---|
| 147 | dictionary["EDITION"] = "Evaluation";
|
|---|
| 148 | dictionary["QT_EDITION"] = "QT_EDITION_EVALUATION";
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | if (platforms[2] == 'L') {
|
|---|
| 153 | static const char src[] = "8NPQRTZ";
|
|---|
| 154 | static const char dst[] = "UCWX9M7";
|
|---|
| 155 | const char *p = strchr(src, platforms[1]);
|
|---|
| 156 | platforms[1] = dst[p - src];
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | #define PL(a,b) (int(a)+int(b)*256)
|
|---|
| 160 | int platformCode = PL(platforms[0],platforms[1]);
|
|---|
| 161 | switch (platformCode) {
|
|---|
| 162 | case PL('X','9'):
|
|---|
| 163 | case PL('X','C'):
|
|---|
| 164 | case PL('X','U'):
|
|---|
| 165 | case PL('X','W'):
|
|---|
| 166 | case PL('X','M'): // old license key
|
|---|
| 167 | dictionary["LICENSE_EXTENSION"] = "-ALLOS";
|
|---|
| 168 | break;
|
|---|
| 169 |
|
|---|
| 170 | case PL('6', 'M'):
|
|---|
| 171 | case PL('8', 'M'):
|
|---|
| 172 | case PL('K', 'M'): // old license key
|
|---|
| 173 | case PL('N', '7'):
|
|---|
| 174 | case PL('N', '9'):
|
|---|
| 175 | case PL('N', 'X'):
|
|---|
| 176 | case PL('S', '9'):
|
|---|
| 177 | case PL('S', 'C'):
|
|---|
| 178 | case PL('S', 'U'):
|
|---|
| 179 | case PL('S', 'W'):
|
|---|
| 180 | dictionary["LICENSE_EXTENSION"] = "-EMBEDDED";
|
|---|
| 181 | if (dictionary["PLATFORM NAME"].contains("Windows CE")
|
|---|
| 182 | && platformCode != PL('6', 'M') && platformCode != PL('S', '9')
|
|---|
| 183 | && platformCode != PL('S', 'C') && platformCode != PL('S', 'U')
|
|---|
| 184 | && platformCode != PL('S', 'W') && platformCode != PL('K', 'M')) {
|
|---|
| 185 | dictionary["DONE"] = "error";
|
|---|
| 186 | } else if (dictionary["PLATFORM NAME"].contains("Symbian")
|
|---|
| 187 | && platformCode != PL('N', '9') && platformCode != PL('S', '9')
|
|---|
| 188 | && platformCode != PL('S', 'C') && platformCode != PL('S', 'U')
|
|---|
| 189 | && platformCode != PL('S', 'W')) {
|
|---|
| 190 | dictionary["DONE"] = "error";
|
|---|
| 191 | }
|
|---|
| 192 | break;
|
|---|
| 193 | case PL('R', 'M'):
|
|---|
| 194 | case PL('F', 'M'):
|
|---|
| 195 | dictionary["LICENSE_EXTENSION"] = "-DESKTOP";
|
|---|
| 196 | if (!dictionary["PLATFORM NAME"].endsWith("Windows")) {
|
|---|
| 197 | dictionary["DONE"] = "error";
|
|---|
| 198 | }
|
|---|
| 199 | break;
|
|---|
| 200 | default:
|
|---|
| 201 | dictionary["DONE"] = "error";
|
|---|
| 202 | break;
|
|---|
| 203 | }
|
|---|
| 204 | #undef PL
|
|---|
| 205 |
|
|---|
| 206 | if (dictionary.value("DONE") == "error") {
|
|---|
| 207 | cout << "You are not licensed for the " << dictionary["PLATFORM NAME"] << " platform." << endl << endl;
|
|---|
| 208 | cout << "Please contact qt-info@nokia.com to upgrade your license" << endl;
|
|---|
| 209 | cout << "to include the " << dictionary["PLATFORM NAME"] << " platform, or install the" << endl;
|
|---|
| 210 | cout << "Qt Open Source Edition if you intend to develop free software." << endl;
|
|---|
| 211 | return;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | // Override for evaluation licenses
|
|---|
| 215 | if (dictionary["Edition"] == "Evaluation")
|
|---|
| 216 | dictionary["LICENSE_EXTENSION"] = "-EVALUATION";
|
|---|
| 217 |
|
|---|
| 218 | if (QFile::exists(dictionary["QT_SOURCE_TREE"] + "/.LICENSE")) {
|
|---|
| 219 | // Generic, no-suffix license
|
|---|
| 220 | dictionary["LICENSE_EXTENSION"] = QString();
|
|---|
| 221 | } else if (dictionary["LICENSE_EXTENSION"].isEmpty()) {
|
|---|
| 222 | cout << "License file does not contain proper license key." << endl;
|
|---|
| 223 | dictionary["DONE"] = "error";
|
|---|
| 224 | }
|
|---|
| 225 | if (licenseType.isEmpty()
|
|---|
| 226 | || dictionary["EDITION"].isEmpty()
|
|---|
| 227 | || dictionary["QT_EDITION"].isEmpty()) {
|
|---|
| 228 | cout << "License file does not contain proper license key." << endl;
|
|---|
| 229 | dictionary["DONE"] = "error";
|
|---|
| 230 | return;
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | // copy one of .LICENSE-*(-US) to LICENSE
|
|---|
| 234 | QString toLicenseFile = dictionary["QT_SOURCE_TREE"] + "/LICENSE";
|
|---|
| 235 | QString fromLicenseFile = dictionary["QT_SOURCE_TREE"] + "/.LICENSE" + dictionary["LICENSE_EXTENSION"];
|
|---|
| 236 | if (licenseFeatures == 'B' || licenseFeatures == 'G'
|
|---|
| 237 | || licenseFeatures == 'L' || licenseFeatures == 'Y')
|
|---|
| 238 | fromLicenseFile += "-US";
|
|---|
| 239 |
|
|---|
| 240 | if (!CopyFile((wchar_t*)QDir::toNativeSeparators(fromLicenseFile).utf16(),
|
|---|
| 241 | (wchar_t*)QDir::toNativeSeparators(toLicenseFile).utf16(), FALSE)) {
|
|---|
| 242 | cout << "Failed to copy license file (" << fromLicenseFile << ")";
|
|---|
| 243 | dictionary["DONE"] = "error";
|
|---|
| 244 | return;
|
|---|
| 245 | }
|
|---|
| 246 | dictionary["LICENSE FILE"] = toLicenseFile;
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|