Index: trunk/tools/configure/environment.cpp
===================================================================
--- trunk/tools/configure/environment.cpp	(revision 5)
+++ trunk/tools/configure/environment.cpp	(revision 561)
@@ -2,5 +2,6 @@
 **
 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
 **
 ** This file is part of the tools applications of the Qt Toolkit.
@@ -21,8 +22,7 @@
 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 **
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 **
 ** GNU General Public License Usage
@@ -34,6 +34,6 @@
 ** met: http://www.gnu.org/copyleft/gpl.html.
 **
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
 ** $QT_END_LICENSE$
 **
@@ -147,13 +147,5 @@
 
     HKEY handle = 0;
-    LONG res;
-    QT_WA( {
-        res = RegOpenKeyExW(parentHandle, (WCHAR*)rSubkeyPath.utf16(),
-                            0, KEY_READ, &handle);
-    } , {
-        res = RegOpenKeyExA(parentHandle, rSubkeyPath.toLocal8Bit(),
-                            0, KEY_READ, &handle);
-    } );
-
+    LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle);
     if (res != ERROR_SUCCESS)
         return QString();
@@ -162,9 +154,5 @@
     DWORD dataType;
     DWORD dataSize;
-    QT_WA( {
-        res = RegQueryValueExW(handle, (WCHAR*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize);
-    }, {
-        res = RegQueryValueExA(handle, rSubkeyName.toLocal8Bit(), 0, &dataType, 0, &dataSize);
-    } );
+    res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize);
     if (res != ERROR_SUCCESS) {
         RegCloseKey(handle);
@@ -174,11 +162,6 @@
     // get the value
     QByteArray data(dataSize, 0);
-    QT_WA( {
-        res = RegQueryValueExW(handle, (WCHAR*)rSubkeyName.utf16(), 0, 0,
-                               reinterpret_cast<unsigned char*>(data.data()), &dataSize);
-    }, {
-        res = RegQueryValueExA(handle, rSubkeyName.toLocal8Bit(), 0, 0,
-                               reinterpret_cast<unsigned char*>(data.data()), &dataSize);
-    } );
+    res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0,
+                           reinterpret_cast<unsigned char*>(data.data()), &dataSize);
     if (res != ERROR_SUCCESS) {
         RegCloseKey(handle);
@@ -190,9 +173,5 @@
         case REG_EXPAND_SZ:
         case REG_SZ: {
-            QT_WA( {
-                result = QString::fromUtf16(((const ushort*)data.constData()));
-            }, {
-                result = QString::fromLatin1(data.constData());
-            } );
+            result = QString::fromWCharArray(((const wchar_t *)data.constData()));
             break;
         }
@@ -202,10 +181,5 @@
             int i = 0;
             for (;;) {
-                QString s;
-                QT_WA( {
-                    s = QString::fromUtf16((const ushort*)data.constData() + i);
-                }, {
-                    s = QString::fromLatin1(data.constData() + i);
-                } );
+                QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i);
                 i += s.length() + 1;
 
@@ -214,5 +188,5 @@
                 l.append(s);
             }
-	    result = l.join(", ");
+            result = l.join(", ");
             break;
         }
@@ -220,9 +194,5 @@
         case REG_NONE:
         case REG_BINARY: {
-            QT_WA( {
-                result = QString::fromUtf16((const ushort*)data.constData(), data.size()/2);
-            }, {
-                result = QString::fromLatin1(data.constData(), data.size());
-            } );
+            result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2);
             break;
         }
@@ -233,5 +203,5 @@
             int i;
             memcpy((char*)&i, data.constData(), sizeof(int));
-	    result = QString::number(i);
+            result = QString::number(i);
             break;
         }
@@ -351,27 +321,12 @@
     memset(&procInfo, 0, sizeof(procInfo));
 
-    bool couldExecute;
-    QT_WA({
-        // Unicode version
-        STARTUPINFOW startInfo;
-        memset(&startInfo, 0, sizeof(startInfo));
-        startInfo.cb = sizeof(startInfo);
-
-        couldExecute = CreateProcessW(0, (WCHAR*)executable.utf16(),
+    STARTUPINFO startInfo;
+    memset(&startInfo, 0, sizeof(startInfo));
+    startInfo.cb = sizeof(startInfo);
+
+    bool couldExecute = CreateProcess(0, (wchar_t*)executable.utf16(),
                                       0, 0, false,
                                       CREATE_NO_WINDOW | CREATE_SUSPENDED,
                                       0, 0, &startInfo, &procInfo);
-
-    }, {
-        // Ansi version
-        STARTUPINFOA startInfo;
-        memset(&startInfo, 0, sizeof(startInfo));
-        startInfo.cb = sizeof(startInfo);
-
-        couldExecute = CreateProcessA(0, executable.toLocal8Bit().data(),
-                                      0, 0, false,
-                                      CREATE_NO_WINDOW | CREATE_SUSPENDED,
-                                      0, 0, &startInfo, &procInfo);
-    })
 
     if (couldExecute) {
@@ -422,59 +377,36 @@
 
 /*!
-    Creates a QByteArray of the \a environment in either UNICODE or
-    ansi representation.
+    Creates a QByteArray of the \a environment.
 */
 static QByteArray qt_create_environment(const QStringList &environment)
 {
     QByteArray envlist;
-    if (!environment.isEmpty()) {
-	int pos = 0;
-	// add PATH if necessary (for DLL loading)
-	QByteArray path = qgetenv("PATH");
-        QT_WA({
-	    if (environment.filter(QRegExp("^PATH=",Qt::CaseInsensitive)).isEmpty()
-                && !path.isNull()) {
-                QString tmp = QString(QLatin1String("PATH=%1")).arg(QString::fromLocal8Bit(path));
-                uint tmpSize = sizeof(TCHAR) * (tmp.length()+1);
-                envlist.resize(envlist.size() + tmpSize );
-                memcpy(envlist.data()+pos, tmp.utf16(), tmpSize);
-                pos += tmpSize;
-	    }
-	    // add the user environment
-	    for (QStringList::ConstIterator it = environment.begin(); it != environment.end(); it++ ) {
-                QString tmp = *it;
-                uint tmpSize = sizeof(TCHAR) * (tmp.length()+1);
-                envlist.resize(envlist.size() + tmpSize);
-                memcpy(envlist.data()+pos, tmp.utf16(), tmpSize);
-                pos += tmpSize;
-	    }
-	    // add the 2 terminating 0 (actually 4, just to be on the safe side)
-	    envlist.resize( envlist.size()+4 );
-	    envlist[pos++] = 0;
-	    envlist[pos++] = 0;
-	    envlist[pos++] = 0;
-	    envlist[pos++] = 0;
-        }, {
-            if (environment.filter(QRegExp("^PATH=",Qt::CaseInsensitive)).isEmpty() && !path.isNull()) {
-                QByteArray tmp = QString("PATH=%1").arg(QString::fromLocal8Bit(path)).toLocal8Bit();
-                uint tmpSize = tmp.length() + 1;
-                envlist.resize(envlist.size() + tmpSize);
-                memcpy(envlist.data()+pos, tmp.data(), tmpSize);
-                pos += tmpSize;
-            }
-            // add the user environment
-            for (QStringList::ConstIterator it = environment.begin(); it != environment.end(); it++) {
-                QByteArray tmp = (*it).toLocal8Bit();
-                uint tmpSize = tmp.length() + 1;
-                envlist.resize(envlist.size() + tmpSize);
-                memcpy(envlist.data()+pos, tmp.data(), tmpSize);
-                pos += tmpSize;
-            }
-            // add the terminating 0 (actually 2, just to be on the safe side)
-            envlist.resize(envlist.size()+2);
-            envlist[pos++] = 0;
-            envlist[pos++] = 0;
-        })
-    }
+    if (environment.isEmpty())
+        return envlist;
+
+    int pos = 0;
+    // add PATH if necessary (for DLL loading)
+    QByteArray path = qgetenv("PATH");
+    if (environment.filter(QRegExp("^PATH=",Qt::CaseInsensitive)).isEmpty() && !path.isNull()) {
+            QString tmp = QString(QLatin1String("PATH=%1")).arg(QString::fromLocal8Bit(path));
+            uint tmpSize = sizeof(wchar_t) * (tmp.length() + 1);
+            envlist.resize(envlist.size() + tmpSize);
+            memcpy(envlist.data() + pos, tmp.utf16(), tmpSize);
+            pos += tmpSize;
+    }
+    // add the user environment
+    for (QStringList::ConstIterator it = environment.begin(); it != environment.end(); it++ ) {
+            QString tmp = *it;
+            uint tmpSize = sizeof(wchar_t) * (tmp.length() + 1);
+            envlist.resize(envlist.size() + tmpSize);
+            memcpy(envlist.data() + pos, tmp.utf16(), tmpSize);
+            pos += tmpSize;
+    }
+    // add the 2 terminating 0 (actually 4, just to be on the safe side)
+    envlist.resize(envlist.size() + 4);
+    envlist[pos++] = 0;
+    envlist[pos++] = 0;
+    envlist[pos++] = 0;
+    envlist[pos++] = 0;
 
     return envlist;
@@ -502,44 +434,22 @@
     qDebug() << "   " << removeEnv;
 #endif
-// GetEnvironmentStrings is defined to GetEnvironmentStringsW when
-// UNICODE is defined. We cannot use that, since we need to
-// destinguish between unicode and ansi versions of the functions.
-#if defined(UNICODE) && defined(GetEnvironmentStrings)
-#undef GetEnvironmentStrings
-#endif
-
     // Create the full environment from the current environment and
     // the additionalEnv strings, then remove all variables defined
     // in removeEnv
     QMap<QString, QString> fullEnvMap;
-    QT_WA({
-        LPWSTR envStrings = GetEnvironmentStringsW();
-        if (envStrings) {
-            int strLen = 0;
-            for (LPWSTR envString = envStrings; *(envString); envString += strLen + 1) {
-                strLen = wcslen(envString);
-                QString str = QString((const QChar*)envString, strLen);
-                if (!str.startsWith("=")) { // These are added by the system
-                    int sepIndex = str.indexOf('=');
-                    fullEnvMap.insert(str.left(sepIndex).toUpper(), str.mid(sepIndex +1));
-                }
+    LPWSTR envStrings = GetEnvironmentStrings();
+    if (envStrings) {
+        int strLen = 0;
+        for (LPWSTR envString = envStrings; *(envString); envString += strLen + 1) {
+            strLen = wcslen(envString);
+            QString str = QString((const QChar*)envString, strLen);
+            if (!str.startsWith("=")) { // These are added by the system
+                int sepIndex = str.indexOf('=');
+                fullEnvMap.insert(str.left(sepIndex).toUpper(), str.mid(sepIndex +1));
             }
         }
-        FreeEnvironmentStringsW(envStrings);
-    }, {
-        LPSTR envStrings = GetEnvironmentStrings();
-        if (envStrings) {
-            int strLen = 0;
-            for (LPSTR envString = envStrings; *(envString); envString += strLen + 1) {
-                strLen = strlen(envString);
-                QString str = QLatin1String(envString);
-                if (!str.startsWith("=")) { // These are added by the system
-                    int sepIndex = str.indexOf('=');
-                    fullEnvMap.insert(str.left(sepIndex).toUpper(), str.mid(sepIndex +1));
-                }
-            }
-        }
-        FreeEnvironmentStringsA(envStrings);
-    })
+    }
+    FreeEnvironmentStrings(envStrings);
+
     // Add additionalEnv variables
     for (int i = 0; i < additionalEnv.count(); ++i) {
@@ -570,26 +480,12 @@
     memset(&procInfo, 0, sizeof(procInfo));
 
-    bool couldExecute;
-    QT_WA({
-        // Unicode version
-        STARTUPINFOW startInfo;
-        memset(&startInfo, 0, sizeof(startInfo));
-        startInfo.cb = sizeof(startInfo);
-
-        couldExecute = CreateProcessW(0, (WCHAR*)args.utf16(),
+    STARTUPINFO startInfo;
+    memset(&startInfo, 0, sizeof(startInfo));
+    startInfo.cb = sizeof(startInfo);
+
+    bool couldExecute = CreateProcess(0, (wchar_t*)args.utf16(),
                                       0, 0, true, CREATE_UNICODE_ENVIRONMENT,
                                       envlist.isEmpty() ? 0 : envlist.data(),
                                       0, &startInfo, &procInfo);
-    }, {
-        // Ansi version
-        STARTUPINFOA startInfo;
-        memset(&startInfo, 0, sizeof(startInfo));
-        startInfo.cb = sizeof(startInfo);
-
-        couldExecute = CreateProcessA(0, args.toLocal8Bit().data(),
-                                      0, 0, true, 0,
-                                      envlist.isEmpty() ? 0 : envlist.data(),
-                                      0, &startInfo, &procInfo);
-    })
 
     if (couldExecute) {
@@ -655,5 +551,5 @@
 	    QFile::remove(destFile);
             intermediate = QFile::copy(entry.absoluteFilePath(), destFile);
-            SetFileAttributesA(destFile.toLocal8Bit(), FILE_ATTRIBUTE_NORMAL);
+            SetFileAttributes((wchar_t*)destFile.utf16(), FILE_ATTRIBUTE_NORMAL);
         }
 	if(!intermediate) {
