Changeset 561 for trunk/tools/configure/environment.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/tools/configure/environment.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the tools applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 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 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 147 147 148 148 HKEY handle = 0; 149 LONG res; 150 QT_WA( { 151 res = RegOpenKeyExW(parentHandle, (WCHAR*)rSubkeyPath.utf16(), 152 0, KEY_READ, &handle); 153 } , { 154 res = RegOpenKeyExA(parentHandle, rSubkeyPath.toLocal8Bit(), 155 0, KEY_READ, &handle); 156 } ); 157 149 LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle); 158 150 if (res != ERROR_SUCCESS) 159 151 return QString(); … … 162 154 DWORD dataType; 163 155 DWORD dataSize; 164 QT_WA( { 165 res = RegQueryValueExW(handle, (WCHAR*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize); 166 }, { 167 res = RegQueryValueExA(handle, rSubkeyName.toLocal8Bit(), 0, &dataType, 0, &dataSize); 168 } ); 156 res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize); 169 157 if (res != ERROR_SUCCESS) { 170 158 RegCloseKey(handle); … … 174 162 // get the value 175 163 QByteArray data(dataSize, 0); 176 QT_WA( { 177 res = RegQueryValueExW(handle, (WCHAR*)rSubkeyName.utf16(), 0, 0, 178 reinterpret_cast<unsigned char*>(data.data()), &dataSize); 179 }, { 180 res = RegQueryValueExA(handle, rSubkeyName.toLocal8Bit(), 0, 0, 181 reinterpret_cast<unsigned char*>(data.data()), &dataSize); 182 } ); 164 res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0, 165 reinterpret_cast<unsigned char*>(data.data()), &dataSize); 183 166 if (res != ERROR_SUCCESS) { 184 167 RegCloseKey(handle); … … 190 173 case REG_EXPAND_SZ: 191 174 case REG_SZ: { 192 QT_WA( { 193 result = QString::fromUtf16(((const ushort*)data.constData())); 194 }, { 195 result = QString::fromLatin1(data.constData()); 196 } ); 175 result = QString::fromWCharArray(((const wchar_t *)data.constData())); 197 176 break; 198 177 } … … 202 181 int i = 0; 203 182 for (;;) { 204 QString s; 205 QT_WA( { 206 s = QString::fromUtf16((const ushort*)data.constData() + i); 207 }, { 208 s = QString::fromLatin1(data.constData() + i); 209 } ); 183 QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); 210 184 i += s.length() + 1; 211 185 … … 214 188 l.append(s); 215 189 } 216 190 result = l.join(", "); 217 191 break; 218 192 } … … 220 194 case REG_NONE: 221 195 case REG_BINARY: { 222 QT_WA( { 223 result = QString::fromUtf16((const ushort*)data.constData(), data.size()/2); 224 }, { 225 result = QString::fromLatin1(data.constData(), data.size()); 226 } ); 196 result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); 227 197 break; 228 198 } … … 233 203 int i; 234 204 memcpy((char*)&i, data.constData(), sizeof(int)); 235 205 result = QString::number(i); 236 206 break; 237 207 } … … 351 321 memset(&procInfo, 0, sizeof(procInfo)); 352 322 353 bool couldExecute; 354 QT_WA({ 355 // Unicode version 356 STARTUPINFOW startInfo; 357 memset(&startInfo, 0, sizeof(startInfo)); 358 startInfo.cb = sizeof(startInfo); 359 360 couldExecute = CreateProcessW(0, (WCHAR*)executable.utf16(), 323 STARTUPINFO startInfo; 324 memset(&startInfo, 0, sizeof(startInfo)); 325 startInfo.cb = sizeof(startInfo); 326 327 bool couldExecute = CreateProcess(0, (wchar_t*)executable.utf16(), 361 328 0, 0, false, 362 329 CREATE_NO_WINDOW | CREATE_SUSPENDED, 363 330 0, 0, &startInfo, &procInfo); 364 365 }, {366 // Ansi version367 STARTUPINFOA startInfo;368 memset(&startInfo, 0, sizeof(startInfo));369 startInfo.cb = sizeof(startInfo);370 371 couldExecute = CreateProcessA(0, executable.toLocal8Bit().data(),372 0, 0, false,373 CREATE_NO_WINDOW | CREATE_SUSPENDED,374 0, 0, &startInfo, &procInfo);375 })376 331 377 332 if (couldExecute) { … … 422 377 423 378 /*! 424 Creates a QByteArray of the \a environment in either UNICODE or 425 ansi representation. 379 Creates a QByteArray of the \a environment. 426 380 */ 427 381 static QByteArray qt_create_environment(const QStringList &environment) 428 382 { 429 383 QByteArray envlist; 430 if (!environment.isEmpty()) { 431 int pos = 0; 432 // add PATH if necessary (for DLL loading) 433 QByteArray path = qgetenv("PATH"); 434 QT_WA({ 435 if (environment.filter(QRegExp("^PATH=",Qt::CaseInsensitive)).isEmpty() 436 && !path.isNull()) { 437 QString tmp = QString(QLatin1String("PATH=%1")).arg(QString::fromLocal8Bit(path)); 438 uint tmpSize = sizeof(TCHAR) * (tmp.length()+1); 439 envlist.resize(envlist.size() + tmpSize ); 440 memcpy(envlist.data()+pos, tmp.utf16(), tmpSize); 441 pos += tmpSize; 442 } 443 // add the user environment 444 for (QStringList::ConstIterator it = environment.begin(); it != environment.end(); it++ ) { 445 QString tmp = *it; 446 uint tmpSize = sizeof(TCHAR) * (tmp.length()+1); 447 envlist.resize(envlist.size() + tmpSize); 448 memcpy(envlist.data()+pos, tmp.utf16(), tmpSize); 449 pos += tmpSize; 450 } 451 // add the 2 terminating 0 (actually 4, just to be on the safe side) 452 envlist.resize( envlist.size()+4 ); 453 envlist[pos++] = 0; 454 envlist[pos++] = 0; 455 envlist[pos++] = 0; 456 envlist[pos++] = 0; 457 }, { 458 if (environment.filter(QRegExp("^PATH=",Qt::CaseInsensitive)).isEmpty() && !path.isNull()) { 459 QByteArray tmp = QString("PATH=%1").arg(QString::fromLocal8Bit(path)).toLocal8Bit(); 460 uint tmpSize = tmp.length() + 1; 461 envlist.resize(envlist.size() + tmpSize); 462 memcpy(envlist.data()+pos, tmp.data(), tmpSize); 463 pos += tmpSize; 464 } 465 // add the user environment 466 for (QStringList::ConstIterator it = environment.begin(); it != environment.end(); it++) { 467 QByteArray tmp = (*it).toLocal8Bit(); 468 uint tmpSize = tmp.length() + 1; 469 envlist.resize(envlist.size() + tmpSize); 470 memcpy(envlist.data()+pos, tmp.data(), tmpSize); 471 pos += tmpSize; 472 } 473 // add the terminating 0 (actually 2, just to be on the safe side) 474 envlist.resize(envlist.size()+2); 475 envlist[pos++] = 0; 476 envlist[pos++] = 0; 477 }) 478 } 384 if (environment.isEmpty()) 385 return envlist; 386 387 int pos = 0; 388 // add PATH if necessary (for DLL loading) 389 QByteArray path = qgetenv("PATH"); 390 if (environment.filter(QRegExp("^PATH=",Qt::CaseInsensitive)).isEmpty() && !path.isNull()) { 391 QString tmp = QString(QLatin1String("PATH=%1")).arg(QString::fromLocal8Bit(path)); 392 uint tmpSize = sizeof(wchar_t) * (tmp.length() + 1); 393 envlist.resize(envlist.size() + tmpSize); 394 memcpy(envlist.data() + pos, tmp.utf16(), tmpSize); 395 pos += tmpSize; 396 } 397 // add the user environment 398 for (QStringList::ConstIterator it = environment.begin(); it != environment.end(); it++ ) { 399 QString tmp = *it; 400 uint tmpSize = sizeof(wchar_t) * (tmp.length() + 1); 401 envlist.resize(envlist.size() + tmpSize); 402 memcpy(envlist.data() + pos, tmp.utf16(), tmpSize); 403 pos += tmpSize; 404 } 405 // add the 2 terminating 0 (actually 4, just to be on the safe side) 406 envlist.resize(envlist.size() + 4); 407 envlist[pos++] = 0; 408 envlist[pos++] = 0; 409 envlist[pos++] = 0; 410 envlist[pos++] = 0; 479 411 480 412 return envlist; … … 502 434 qDebug() << " " << removeEnv; 503 435 #endif 504 // GetEnvironmentStrings is defined to GetEnvironmentStringsW when505 // UNICODE is defined. We cannot use that, since we need to506 // destinguish between unicode and ansi versions of the functions.507 #if defined(UNICODE) && defined(GetEnvironmentStrings)508 #undef GetEnvironmentStrings509 #endif510 511 436 // Create the full environment from the current environment and 512 437 // the additionalEnv strings, then remove all variables defined 513 438 // in removeEnv 514 439 QMap<QString, QString> fullEnvMap; 515 QT_WA({ 516 LPWSTR envStrings = GetEnvironmentStringsW(); 517 if (envStrings) { 518 int strLen = 0; 519 for (LPWSTR envString = envStrings; *(envString); envString += strLen + 1) { 520 strLen = wcslen(envString); 521 QString str = QString((const QChar*)envString, strLen); 522 if (!str.startsWith("=")) { // These are added by the system 523 int sepIndex = str.indexOf('='); 524 fullEnvMap.insert(str.left(sepIndex).toUpper(), str.mid(sepIndex +1)); 525 } 440 LPWSTR envStrings = GetEnvironmentStrings(); 441 if (envStrings) { 442 int strLen = 0; 443 for (LPWSTR envString = envStrings; *(envString); envString += strLen + 1) { 444 strLen = wcslen(envString); 445 QString str = QString((const QChar*)envString, strLen); 446 if (!str.startsWith("=")) { // These are added by the system 447 int sepIndex = str.indexOf('='); 448 fullEnvMap.insert(str.left(sepIndex).toUpper(), str.mid(sepIndex +1)); 526 449 } 527 450 } 528 FreeEnvironmentStringsW(envStrings); 529 }, { 530 LPSTR envStrings = GetEnvironmentStrings(); 531 if (envStrings) { 532 int strLen = 0; 533 for (LPSTR envString = envStrings; *(envString); envString += strLen + 1) { 534 strLen = strlen(envString); 535 QString str = QLatin1String(envString); 536 if (!str.startsWith("=")) { // These are added by the system 537 int sepIndex = str.indexOf('='); 538 fullEnvMap.insert(str.left(sepIndex).toUpper(), str.mid(sepIndex +1)); 539 } 540 } 541 } 542 FreeEnvironmentStringsA(envStrings); 543 }) 451 } 452 FreeEnvironmentStrings(envStrings); 453 544 454 // Add additionalEnv variables 545 455 for (int i = 0; i < additionalEnv.count(); ++i) { … … 570 480 memset(&procInfo, 0, sizeof(procInfo)); 571 481 572 bool couldExecute; 573 QT_WA({ 574 // Unicode version 575 STARTUPINFOW startInfo; 576 memset(&startInfo, 0, sizeof(startInfo)); 577 startInfo.cb = sizeof(startInfo); 578 579 couldExecute = CreateProcessW(0, (WCHAR*)args.utf16(), 482 STARTUPINFO startInfo; 483 memset(&startInfo, 0, sizeof(startInfo)); 484 startInfo.cb = sizeof(startInfo); 485 486 bool couldExecute = CreateProcess(0, (wchar_t*)args.utf16(), 580 487 0, 0, true, CREATE_UNICODE_ENVIRONMENT, 581 488 envlist.isEmpty() ? 0 : envlist.data(), 582 489 0, &startInfo, &procInfo); 583 }, {584 // Ansi version585 STARTUPINFOA startInfo;586 memset(&startInfo, 0, sizeof(startInfo));587 startInfo.cb = sizeof(startInfo);588 589 couldExecute = CreateProcessA(0, args.toLocal8Bit().data(),590 0, 0, true, 0,591 envlist.isEmpty() ? 0 : envlist.data(),592 0, &startInfo, &procInfo);593 })594 490 595 491 if (couldExecute) { … … 655 551 QFile::remove(destFile); 656 552 intermediate = QFile::copy(entry.absoluteFilePath(), destFile); 657 SetFileAttributes A(destFile.toLocal8Bit(), FILE_ATTRIBUTE_NORMAL);553 SetFileAttributes((wchar_t*)destFile.utf16(), FILE_ATTRIBUTE_NORMAL); 658 554 } 659 555 if(!intermediate) {
Note:
See TracChangeset
for help on using the changeset viewer.