Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/configure/environment.cpp

    r2 r561  
    22**
    33** 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)
    56**
    67** This file is part of the tools applications of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** 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.
    3838** $QT_END_LICENSE$
    3939**
     
    147147
    148148    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);
    158150    if (res != ERROR_SUCCESS)
    159151        return QString();
     
    162154    DWORD dataType;
    163155    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);
    169157    if (res != ERROR_SUCCESS) {
    170158        RegCloseKey(handle);
     
    174162    // get the value
    175163    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);
    183166    if (res != ERROR_SUCCESS) {
    184167        RegCloseKey(handle);
     
    190173        case REG_EXPAND_SZ:
    191174        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()));
    197176            break;
    198177        }
     
    202181            int i = 0;
    203182            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);
    210184                i += s.length() + 1;
    211185
     
    214188                l.append(s);
    215189            }
    216             result = l.join(", ");
     190            result = l.join(", ");
    217191            break;
    218192        }
     
    220194        case REG_NONE:
    221195        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);
    227197            break;
    228198        }
     
    233203            int i;
    234204            memcpy((char*)&i, data.constData(), sizeof(int));
    235             result = QString::number(i);
     205            result = QString::number(i);
    236206            break;
    237207        }
     
    351321    memset(&procInfo, 0, sizeof(procInfo));
    352322
    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(),
    361328                                      0, 0, false,
    362329                                      CREATE_NO_WINDOW | CREATE_SUSPENDED,
    363330                                      0, 0, &startInfo, &procInfo);
    364 
    365     }, {
    366         // Ansi version
    367         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     })
    376331
    377332    if (couldExecute) {
     
    422377
    423378/*!
    424     Creates a QByteArray of the \a environment in either UNICODE or
    425     ansi representation.
     379    Creates a QByteArray of the \a environment.
    426380*/
    427381static QByteArray qt_create_environment(const QStringList &environment)
    428382{
    429383    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;
    479411
    480412    return envlist;
     
    502434    qDebug() << "   " << removeEnv;
    503435#endif
    504 // GetEnvironmentStrings is defined to GetEnvironmentStringsW when
    505 // UNICODE is defined. We cannot use that, since we need to
    506 // destinguish between unicode and ansi versions of the functions.
    507 #if defined(UNICODE) && defined(GetEnvironmentStrings)
    508 #undef GetEnvironmentStrings
    509 #endif
    510 
    511436    // Create the full environment from the current environment and
    512437    // the additionalEnv strings, then remove all variables defined
    513438    // in removeEnv
    514439    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));
    526449            }
    527450        }
    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
    544454    // Add additionalEnv variables
    545455    for (int i = 0; i < additionalEnv.count(); ++i) {
     
    570480    memset(&procInfo, 0, sizeof(procInfo));
    571481
    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(),
    580487                                      0, 0, true, CREATE_UNICODE_ENVIRONMENT,
    581488                                      envlist.isEmpty() ? 0 : envlist.data(),
    582489                                      0, &startInfo, &procInfo);
    583     }, {
    584         // Ansi version
    585         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     })
    594490
    595491    if (couldExecute) {
     
    655551            QFile::remove(destFile);
    656552            intermediate = QFile::copy(entry.absoluteFilePath(), destFile);
    657             SetFileAttributesA(destFile.toLocal8Bit(), FILE_ATTRIBUTE_NORMAL);
     553            SetFileAttributes((wchar_t*)destFile.utf16(), FILE_ATTRIBUTE_NORMAL);
    658554        }
    659555        if(!intermediate) {
Note: See TracChangeset for help on using the changeset viewer.