0
|
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 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
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 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
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 |
const char * clicenseKey = licenseKey.toLatin1();
|
|
114 |
//We check the licence
|
|
115 |
#ifndef _WIN32_WCE
|
|
116 |
char *buffer = strdup(clicenseKey);
|
|
117 |
#else
|
|
118 |
char *buffer = (char*) malloc(strlen(clicenseKey) + 1);
|
|
119 |
strcpy(buffer, clicenseKey);
|
|
120 |
#endif
|
|
121 |
static const char * const SEP = "-";
|
|
122 |
char *licenseParts[NUMBER_OF_PARTS];
|
|
123 |
int partNumber = 0;
|
|
124 |
for (char *part = strtok(buffer, SEP); part != 0; part = strtok(0, SEP))
|
|
125 |
licenseParts[partNumber++] = part;
|
|
126 |
if (partNumber < (NUMBER_OF_PARTS-1)) {
|
|
127 |
dictionary["DONE"] = "error";
|
|
128 |
cout << "License file does not contain proper license key." <<partNumber<< endl;
|
|
129 |
free(buffer);
|
|
130 |
return;
|
|
131 |
}
|
|
132 |
|
|
133 |
char products = licenseParts[0][0];
|
|
134 |
char platforms = licenseParts[1][0];
|
|
135 |
char* licenseSchema = licenseParts[2];
|
|
136 |
char licenseFeatures = licenseParts[3][0];
|
|
137 |
|
|
138 |
// Determine edition ---------------------------------------------------------------------------
|
|
139 |
QString licenseType;
|
|
140 |
if (strcmp(licenseSchema,"F4M") == 0) {
|
|
141 |
licenseType = "Commercial";
|
|
142 |
if (products == 'F') {
|
|
143 |
dictionary["EDITION"] = "Universal";
|
|
144 |
dictionary["QT_EDITION"] = "QT_EDITION_UNIVERSAL";
|
|
145 |
} else if (products == 'B') {
|
|
146 |
dictionary["EDITION"] = "FullFramework";
|
|
147 |
dictionary["QT_EDITION"] = "QT_EDITION_DESKTOP";
|
|
148 |
} else {
|
|
149 |
dictionary["EDITION"] = "GUIFramework";
|
|
150 |
dictionary["QT_EDITION"] = "QT_EDITION_DESKTOPLIGHT";
|
|
151 |
}
|
|
152 |
|
|
153 |
if (platforms == 'X') {
|
|
154 |
dictionary["LICENSE_EXTENSION"] = "-ALLOS";
|
|
155 |
} else if (strchr("2346789ABCDEGHJKMPQSTUVWX", platforms)) {
|
|
156 |
dictionary["LICENSE_EXTENSION"] = "-EMBEDDED";
|
|
157 |
} else if (strchr("4BFPQRTY", platforms)) {
|
|
158 |
dictionary["LICENSE_EXTENSION"] = "-DESKTOP";
|
|
159 |
}
|
|
160 |
} else if (strcmp(licenseSchema,"Z4M") == 0 || strcmp(licenseSchema,"R4M") == 0 || strcmp(licenseSchema,"Q4M") == 0) {
|
|
161 |
if (products == 'B') {
|
|
162 |
dictionary["EDITION"] = "Evaluation";
|
|
163 |
dictionary["QT_EDITION"] = "QT_EDITION_EVALUATION";
|
|
164 |
dictionary["LICENSE_EXTENSION"] = "-EVALUATION";
|
|
165 |
}
|
|
166 |
}
|
|
167 |
|
|
168 |
if (QFile::exists(dictionary["QT_SOURCE_TREE"] + "/.LICENSE")) {
|
|
169 |
// Generic, no-suffix license
|
|
170 |
dictionary["LICENSE_EXTENSION"] = QString();
|
|
171 |
} else if (dictionary["LICENSE_EXTENSION"].isEmpty()) {
|
|
172 |
cout << "License file does not contain proper license key." << endl;
|
|
173 |
dictionary["DONE"] = "error";
|
|
174 |
}
|
|
175 |
if (licenseType.isEmpty()
|
|
176 |
|| dictionary["EDITION"].isEmpty()
|
|
177 |
|| dictionary["QT_EDITION"].isEmpty()) {
|
|
178 |
cout << "License file does not contain proper license key." << endl;
|
|
179 |
dictionary["DONE"] = "error";
|
|
180 |
return;
|
|
181 |
}
|
|
182 |
|
|
183 |
if (dictionary["PLATFORM NAME"].contains("Windows CE")) {
|
|
184 |
// verify that we are licensed to use Qt for Windows CE
|
|
185 |
if (dictionary["LICENSE_EXTENSION"] != "-EMBEDDED" && dictionary["LICENSE_EXTENSION"] != "-ALLOS") {
|
|
186 |
cout << "You are not licensed for the " << dictionary["PLATFORM NAME"] << " platform." << endl << endl;
|
|
187 |
cout << "Please contact qt-info@nokia.com to upgrade your license" << endl;
|
|
188 |
cout << "to include the " << dictionary["PLATFORM NAME"] << " platform, or install the" << endl;
|
|
189 |
cout << "Qt Open Source Edition if you intend to develop free software." << endl;
|
|
190 |
dictionary["DONE"] = "error";
|
|
191 |
return;
|
|
192 |
}
|
|
193 |
}
|
|
194 |
|
|
195 |
// copy one of .LICENSE-*(-US) to LICENSE
|
|
196 |
QString toLicenseFile = dictionary["QT_SOURCE_TREE"] + "/LICENSE";
|
|
197 |
QString fromLicenseFile = dictionary["QT_SOURCE_TREE"] + "/.LICENSE" + dictionary["LICENSE_EXTENSION"];
|
|
198 |
if (licenseFeatures == 'G') //US
|
|
199 |
fromLicenseFile += "-US";
|
|
200 |
|
|
201 |
if (licenseFeatures == '5') //Floating
|
|
202 |
dictionary["METERED LICENSE"] = "true";
|
|
203 |
|
|
204 |
if (!CopyFile((wchar_t*)QDir::toNativeSeparators(fromLicenseFile).utf16(),
|
|
205 |
(wchar_t*)QDir::toNativeSeparators(toLicenseFile).utf16(), FALSE)) {
|
|
206 |
cout << "Failed to copy license file (" << fromLicenseFile << ")";
|
|
207 |
dictionary["DONE"] = "error";
|
|
208 |
return;
|
|
209 |
}
|
|
210 |
dictionary["LICENSE FILE"] = toLicenseFile;
|
|
211 |
free(buffer);
|
|
212 |
}
|
|
213 |
|