source: trunk/tools/configure/tools.cpp@ 932

Last change on this file since 932 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 9.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
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 [email protected].
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
55std::ostream &operator<<(std::ostream &s, const QString &val); // defined in configureapp.cpp
56using namespace std;
57
58void 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().remove('"').toUpper();
95 QString value = (*it++).trimmed().remove('"');
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 license
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 licenseType = "Evaluation";
150 }
151 }
152
153 if (platforms[2] == 'L') {
154 static const char src[] = "8NPQRTZ";
155 static const char dst[] = "UCWX9M7";
156 const char *p = strchr(src, platforms[1]);
157 platforms[1] = dst[p - src];
158 }
159
160#define PL(a,b) (int(a)+int(b)*256)
161 int platformCode = PL(platforms[0],platforms[1]);
162 switch (platformCode) {
163 case PL('X','9'):
164 case PL('X','C'):
165 case PL('X','U'):
166 case PL('X','W'):
167 case PL('X','M'): // old license key
168 dictionary["LICENSE_EXTENSION"] = "-ALLOS";
169 break;
170
171 case PL('6', 'M'):
172 case PL('8', 'M'):
173 case PL('K', 'M'): // old license key
174 case PL('N', '7'):
175 case PL('N', '9'):
176 case PL('N', 'X'):
177 case PL('S', '9'):
178 case PL('S', 'C'):
179 case PL('S', 'U'):
180 case PL('S', 'W'):
181 dictionary["LICENSE_EXTENSION"] = "-EMBEDDED";
182 if (dictionary["PLATFORM NAME"].contains("Windows CE")
183 && platformCode != PL('6', 'M') && platformCode != PL('S', '9')
184 && platformCode != PL('S', 'C') && platformCode != PL('S', 'U')
185 && platformCode != PL('S', 'W') && platformCode != PL('K', 'M')) {
186 dictionary["DONE"] = "error";
187 } else if (dictionary["PLATFORM NAME"].contains("Symbian")
188 && platformCode != PL('N', '9') && platformCode != PL('S', '9')
189 && platformCode != PL('S', 'C') && platformCode != PL('S', 'U')
190 && platformCode != PL('S', 'W')) {
191 dictionary["DONE"] = "error";
192 }
193 break;
194 case PL('R', 'M'):
195 case PL('F', 'M'):
196 dictionary["LICENSE_EXTENSION"] = "-DESKTOP";
197 if (!dictionary["PLATFORM NAME"].endsWith("Windows")) {
198 dictionary["DONE"] = "error";
199 }
200 break;
201 default:
202 dictionary["DONE"] = "error";
203 break;
204 }
205#undef PL
206
207 if (dictionary.value("DONE") == "error") {
208 cout << "You are not licensed for the " << dictionary["PLATFORM NAME"] << " platform." << endl << endl;
209 cout << "Please contact [email protected] to upgrade your license" << endl;
210 cout << "to include the " << dictionary["PLATFORM NAME"] << " platform, or install the" << endl;
211 cout << "Qt Open Source Edition if you intend to develop free software." << endl;
212 return;
213 }
214
215 // Override for evaluation licenses
216 if (dictionary["EDITION"] == "Evaluation")
217 dictionary["LICENSE_EXTENSION"] = "-EVALUATION";
218
219 if (QFile::exists(dictionary["QT_SOURCE_TREE"] + "/.LICENSE")) {
220 // Generic, no-suffix license
221 dictionary["LICENSE_EXTENSION"].clear();
222 } else if (dictionary["LICENSE_EXTENSION"].isEmpty()) {
223 cout << "License file does not contain proper license key." << endl;
224 dictionary["DONE"] = "error";
225 }
226 if (licenseType.isEmpty()
227 || dictionary["EDITION"].isEmpty()
228 || dictionary["QT_EDITION"].isEmpty()) {
229 cout << "License file does not contain proper license key." << endl;
230 dictionary["DONE"] = "error";
231 return;
232 }
233
234 // copy one of .LICENSE-*(-US) to LICENSE
235 QString toLicenseFile = dictionary["QT_SOURCE_TREE"] + "/LICENSE";
236 QString fromLicenseFile = dictionary["QT_SOURCE_TREE"] + "/.LICENSE" + dictionary["LICENSE_EXTENSION"];
237 if (licenseFeatures == 'B' || licenseFeatures == 'G'
238 || licenseFeatures == 'L' || licenseFeatures == 'Y')
239 fromLicenseFile += "-US";
240
241 if (!CopyFile((wchar_t*)QDir::toNativeSeparators(fromLicenseFile).utf16(),
242 (wchar_t*)QDir::toNativeSeparators(toLicenseFile).utf16(), false)) {
243 cout << "Failed to copy license file (" << fromLicenseFile << ")";
244 dictionary["DONE"] = "error";
245 return;
246 }
247 dictionary["LICENSE FILE"] = toLicenseFile;
248}
249
Note: See TracBrowser for help on using the repository browser.