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/src/corelib/io/qsettings_win.cpp

    r229 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information ([email protected])
     4** All rights reserved.
     5** Contact: Nokia Corporation ([email protected])
    56**
    67** This file is part of the QtCore module 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
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    131131static QString errorCodeToString(DWORD errorCode)
    132132{
    133     QString result;
    134         QT_WA({
    135                 wchar_t *data = 0;
    136                 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
    137                         0, errorCode, 0,
    138                         data, 0, 0);
    139                 result = QString::fromUtf16(reinterpret_cast<const ushort *> (data));
    140                 if (data != 0)
    141                         LocalFree(data);
    142         },      {
    143                 char *data = 0;
    144                 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
    145                         0, errorCode, 0,
    146                         (char *)&data, 0, 0);
    147                 result = QString::fromLocal8Bit(data);
    148                 if (data != 0)
    149                         LocalFree(data);
    150         })
    151     if (result.endsWith(QLatin1String("\n")))
     133    wchar_t *data = 0;
     134    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, errorCode, 0, data, 0, 0);
     135    QString result = QString::fromWCharArray(data);
     136
     137    if (data != 0)
     138        LocalFree(data);
     139
     140    if (result.endsWith(QLatin1Char('\n')))
    152141        result.truncate(result.length() - 1);
    153142
     
    159148{
    160149    HKEY resultHandle = 0;
    161 
    162     LONG res;
    163     QT_WA( {
    164         res = RegOpenKeyExW(parentHandle, reinterpret_cast<const wchar_t *>(rSubKey.utf16()),
     150    LONG res = RegOpenKeyEx(parentHandle, reinterpret_cast<const wchar_t *>(rSubKey.utf16()),
    165151                            0, perms, &resultHandle);
    166     } , {
    167         res = RegOpenKeyExA(parentHandle, rSubKey.toLocal8Bit(),
    168                             0, perms, &resultHandle);
    169     } );
    170152
    171153    if (res == ERROR_SUCCESS)
     
    184166
    185167    // try to create it
    186     LONG res;
    187     QT_WA( {
    188         res = RegCreateKeyExW(parentHandle, reinterpret_cast<const wchar_t *>(rSubKey.utf16()), 0, 0,
     168    LONG res = RegCreateKeyEx(parentHandle, reinterpret_cast<const wchar_t *>(rSubKey.utf16()), 0, 0,
    189169                              REG_OPTION_NON_VOLATILE, perms, 0, &resultHandle, 0);
    190     } , {
    191         res = RegCreateKeyExA(parentHandle, rSubKey.toLocal8Bit(), 0, 0,
    192                               REG_OPTION_NON_VOLATILE, perms, 0, &resultHandle, 0);
    193     } );
    194170
    195171    if (res == ERROR_SUCCESS)
     
    226202{
    227203    QStringList result;
    228     LONG res;
    229204    DWORD numKeys;
    230205    DWORD maxKeySize;
     
    233208
    234209    // Find the number of keys and subgroups, as well as the max of their lengths.
    235     QT_WA( {
    236         res = RegQueryInfoKeyW(parentHandle, 0, 0, 0, &numSubgroups, &maxSubgroupSize, 0,
     210    LONG res = RegQueryInfoKey(parentHandle, 0, 0, 0, &numSubgroups, &maxSubgroupSize, 0,
    237211                               &numKeys, &maxKeySize, 0, 0, 0);
    238     }, {
    239         res = RegQueryInfoKeyA(parentHandle, 0, 0, 0, &numSubgroups, &maxSubgroupSize, 0,
    240                                &numKeys, &maxKeySize, 0, 0, 0);
    241     } );
    242212
    243213    if (res != ERROR_SUCCESS) {
     
    259229    }
    260230
    261     /* Windows NT/2000/XP: The size does not include the terminating null character.
    262        Windows Me/98/95: The size includes the terminating null character. */
     231    /* The size does not include the terminating null character. */
    263232    ++m;
    264233
    265234    // Get the list
    266     QByteArray buff(m*sizeof(ushort), 0);
     235    QByteArray buff(mt), 0);
    267236    for (int i = 0; i < n; ++i) {
    268237        QString item;
    269         QT_WA( {
    270             DWORD l = buff.size() / sizeof(ushort);
    271             if (spec == QSettingsPrivate::ChildKeys) {
    272                 res = RegEnumValueW(parentHandle, i,
    273                                     reinterpret_cast<wchar_t *>(buff.data()),
    274                                     &l, 0, 0, 0, 0);
    275             } else {
    276                 res = RegEnumKeyExW(parentHandle, i,
    277                                     reinterpret_cast<wchar_t *>(buff.data()),
    278                                     &l, 0, 0, 0, 0);
    279             }
    280             if (res == ERROR_SUCCESS)
    281                 item = QString::fromUtf16(reinterpret_cast<ushort*>(buff.data()), l);
    282         }, {
    283             DWORD l = buff.size();
    284             if (spec == QSettingsPrivate::ChildKeys)
    285                 res = RegEnumValueA(parentHandle, i, buff.data(), &l, 0, 0, 0, 0);
    286             else
    287                 res = RegEnumKeyExA(parentHandle, i, buff.data(), &l, 0, 0, 0, 0);
    288             if (res == ERROR_SUCCESS)
    289                 item = QString::fromLocal8Bit(buff.data(), l);
    290         } );
     238        DWORD l = buff.size() / sizeof(wchar_t);
     239        if (spec == QSettingsPrivate::ChildKeys) {
     240            res = RegEnumValue(parentHandle, i, reinterpret_cast<wchar_t *>(buff.data()), &l, 0, 0, 0, 0);
     241        } else {
     242            res = RegEnumKeyEx(parentHandle, i, reinterpret_cast<wchar_t *>(buff.data()), &l, 0, 0, 0, 0);
     243        }
     244        if (res == ERROR_SUCCESS)
     245            item = QString::fromWCharArray((const wchar_t *)buff.constData(), l);
    291246
    292247        if (res != ERROR_SUCCESS) {
     
    343298
    344299        // delete group itself
    345         LONG res;
    346         QT_WA( {
    347             res = RegDeleteKeyW(parentHandle, reinterpret_cast<const wchar_t *>(group.utf16()));
    348         }, {
    349             res = RegDeleteKeyA(parentHandle, group.toLocal8Bit());
    350         } );
     300        LONG res = RegDeleteKey(parentHandle, reinterpret_cast<const wchar_t *>(group.utf16()));
    351301        if (res != ERROR_SUCCESS) {
    352302            qWarning("QSettings: RegDeleteKey failed on subkey \"%s\": %s",
     
    520470    DWORD dataType;
    521471    DWORD dataSize;
    522     LONG res;
    523     QT_WA( {
    524         res = RegQueryValueExW(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, &dataType, 0, &dataSize);
    525     }, {
    526         res = RegQueryValueExA(handle, rSubkeyName.toLocal8Bit(), 0, &dataType, 0, &dataSize);
    527     } );
     472    LONG res = RegQueryValueEx(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, &dataType, 0, &dataSize);
    528473    if (res != ERROR_SUCCESS) {
    529474        RegCloseKey(handle);
     
    533478    // get the value
    534479    QByteArray data(dataSize, 0);
    535     QT_WA( {
    536         res = RegQueryValueExW(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, 0,
    537                                reinterpret_cast<unsigned char*>(data.data()), &dataSize);
    538     }, {
    539         res = RegQueryValueExA(handle, rSubkeyName.toLocal8Bit(), 0, 0,
    540                                reinterpret_cast<unsigned char*>(data.data()), &dataSize);
    541     } );
     480    res = RegQueryValueEx(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, 0,
     481                           reinterpret_cast<unsigned char*>(data.data()), &dataSize);
    542482    if (res != ERROR_SUCCESS) {
    543483        RegCloseKey(handle);
    544484        return false;
    545485    }
    546 
    547     // note that when getting and setting the key contents on non-Unicode systems
    548     // we use the Latin1 encoding instead of Local8Bit because stringToVariant()
    549     // and variantToString() use Latin1 to convert between QString and QByteArray.
    550     // Since it's not guaranteed that all characters from Latin1 may be represented
    551     // in Local8Bit (and vice versa), doing Latin1 -> QString -> Local8Bit ->
    552     // QString -> Latin1 may distort data (in particular, replace some characters
    553     // with ?).
    554486
    555487    switch (dataType) {
     
    558490            QString s;
    559491            if (dataSize) {
    560                 QT_WA( {
    561                     s = QString::fromUtf16(((const ushort*)data.constData()));
    562                 }, {
    563                     s = QString::fromLatin1(data.constData());
    564                 } );
     492                s = QString::fromWCharArray(((const wchar_t *)data.constData()));
    565493            }
    566494            if (value != 0)
     
    574502                int i = 0;
    575503                for (;;) {
    576                     QString s;
    577                     QT_WA( {
    578                         s = QString::fromUtf16((const ushort*)data.constData() + i);
    579                     }, {
    580                         s = QString::fromLocal8Bit(data.constData() + i);
    581                     } );
     504                    QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i);
    582505                    i += s.length() + 1;
    583506
     
    596519            QString s;
    597520            if (dataSize) {
    598                 QT_WA( {
    599                     s = QString::fromUtf16((const ushort*)data.constData(), data.size()/2);
    600                 }, {
    601                     s = QString::fromLatin1(data.constData(), data.size());
    602                 } );
     521                s = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2);
    603522            }
    604523            if (value != 0)
     
    642561    if (deleteWriteHandleOnExit && writeHandle() != 0) {
    643562#if defined(Q_OS_WINCE)
    644         remove(regList.at(0).key());
     563        remove(regList.at(0).key());
    645564#else
    646         DWORD res;
    647565        QString emptyKey;
    648         QT_WA( {
    649             res = RegDeleteKeyW(writeHandle(), reinterpret_cast<const wchar_t *>(emptyKey.utf16()));
    650         }, {
    651             res = RegDeleteKeyA(writeHandle(), emptyKey.toLocal8Bit());
    652         } );
     566        DWORD res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(emptyKey.utf16()));
    653567        if (res != ERROR_SUCCESS) {
    654568            qWarning("QSettings: Failed to delete key \"%s\": %s",
     
    675589    HKEY handle = openKey(writeHandle(), registryPermissions, keyPath(rKey));
    676590    if (handle != 0) {
    677         QT_WA( {
    678             res = RegDeleteValueW(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16()));
    679         }, {
    680             res = RegDeleteValueA(handle, keyName(rKey).toLocal8Bit());
    681         } );
     591        res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16()));
    682592        RegCloseKey(handle);
    683593    }
     
    694604                QString group = childKeys.at(i);
    695605
    696                 LONG res;
    697                 QT_WA( {
    698                     res = RegDeleteValueW(handle, reinterpret_cast<const wchar_t *>(group.utf16()));
    699                 }, {
    700                     res = RegDeleteValueA(handle, group.toLocal8Bit());
    701                 } );
     606                LONG res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(group.utf16()));
    702607                if (res != ERROR_SUCCESS) {
    703608                    qWarning("QSettings: RegDeleteValue failed on subkey \"%s\": %s",
     
    710615            RegCloseKey(handle);
    711616#endif
    712             QT_WA( {
    713                 res = RegDeleteKeyW(writeHandle(), reinterpret_cast<const wchar_t *>(rKey.utf16()));
    714             }, {
    715                 res = RegDeleteKeyA(writeHandle(), rKey.toLocal8Bit());
    716             } );
     617            res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(rKey.utf16()));
    717618
    718619            if (res != ERROR_SUCCESS) {
     
    751652    DWORD type;
    752653    QByteArray regValueBuff;
    753 
    754     // note that when getting and setting the key contents on non-Unicode systems
    755     // we use the Latin1 encoding instead of Local8Bit because stringToVariant()
    756     // and variantToString() use Latin1 to convert between QString and QByteArray.
    757     // Since it's not guaranteed that all characters from Latin1 may be represented
    758     // in Local8Bit (and vice versa), doing Latin1 -> QString -> Local8Bit ->
    759     // QString -> Latin1 may distort data (in particular, replace some characters
    760     // with ?).
    761654
    762655    // Determine the type
     
    778671            if (type == REG_BINARY) {
    779672                QString s = variantToString(value);
    780                 QT_WA( {
    781                     regValueBuff = QByteArray((const char*)s.utf16(), s.length()*2);
    782                 }, {
    783                     regValueBuff = QByteArray((const char*)s.toLatin1(), s.length());
    784                 } );
     673                regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2);
    785674            } else {
    786675                QStringList::const_iterator it = l.constBegin();
    787676                for (; it != l.constEnd(); ++it) {
    788677                    const QString &s = *it;
    789                     QT_WA( {
    790                         regValueBuff += QByteArray((const char*)s.utf16(), (s.length() + 1)*2);
    791                     }, {
    792                         regValueBuff += QByteArray((const char*)s.toLatin1(), s.length() + 1);
    793                     } );
     678                    regValueBuff += QByteArray((const char*)s.utf16(), (s.length() + 1) * 2);
    794679                }
    795                 QT_WA( {
    796                     regValueBuff.append((char)0);
    797                     regValueBuff.append((char)0);
    798                 }, {
    799                     regValueBuff.append((char)0);
    800                 } );
     680                regValueBuff.append((char)0);
     681                regValueBuff.append((char)0);
    801682            }
    802683            break;
     
    809690            break;
    810691        }
     692
     693
     694
    811695
    812696        default: {
     
    816700            type = stringContainsNullChar(s) ? REG_BINARY : REG_SZ;
    817701            if (type == REG_BINARY) {
    818                 QT_WA( {
    819                     regValueBuff = QByteArray((const char*)s.utf16(), s.length()*2);
    820                 }, {
    821                     regValueBuff = QByteArray((const char*)s.toLatin1(), s.length());
    822                 } );
     702                regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2);
    823703            } else {
    824                 QT_WA( {
    825                     regValueBuff = QByteArray((const char*)s.utf16(), (s.length() + 1)*2);
    826                 }, {
    827                     regValueBuff = QByteArray((const char*)s.toLatin1(), s.length() + 1);
    828                 } );
     704                regValueBuff = QByteArray((const char*)s.utf16(), (s.length() + 1) * 2);
    829705            }
    830706            break;
     
    833709
    834710    // set the value
    835     LONG res;
    836     QT_WA( {
    837         res = RegSetValueExW(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16()), 0, type,
     711    LONG res = RegSetValueEx(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16()), 0, type,
    838712                             reinterpret_cast<const unsigned char*>(regValueBuff.constData()),
    839713                             regValueBuff.size());
    840     }, {
    841         res = RegSetValueExA(handle, keyName(rKey).toLocal8Bit(), 0, type,
    842                              reinterpret_cast<const unsigned char*>(regValueBuff.constData()),
    843                              regValueBuff.size());
    844     } );
    845714
    846715    if (res == ERROR_SUCCESS) {
Note: See TracChangeset for help on using the changeset viewer.