Changeset 561 for trunk/src/corelib/io/qsettings_win.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/src/corelib/io/qsettings_win.cpp
r229 r561 2 2 ** 3 3 ** 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]) 5 6 ** 6 7 ** This file is part of the QtCore module 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 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 131 131 static QString errorCodeToString(DWORD errorCode) 132 132 { 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'))) 152 141 result.truncate(result.length() - 1); 153 142 … … 159 148 { 160 149 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()), 165 151 0, perms, &resultHandle); 166 } , {167 res = RegOpenKeyExA(parentHandle, rSubKey.toLocal8Bit(),168 0, perms, &resultHandle);169 } );170 152 171 153 if (res == ERROR_SUCCESS) … … 184 166 185 167 // 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, 189 169 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 } );194 170 195 171 if (res == ERROR_SUCCESS) … … 226 202 { 227 203 QStringList result; 228 LONG res;229 204 DWORD numKeys; 230 205 DWORD maxKeySize; … … 233 208 234 209 // 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, 237 211 &numKeys, &maxKeySize, 0, 0, 0); 238 }, {239 res = RegQueryInfoKeyA(parentHandle, 0, 0, 0, &numSubgroups, &maxSubgroupSize, 0,240 &numKeys, &maxKeySize, 0, 0, 0);241 } );242 212 243 213 if (res != ERROR_SUCCESS) { … … 259 229 } 260 230 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. */ 263 232 ++m; 264 233 265 234 // Get the list 266 QByteArray buff(m *sizeof(ushort), 0);235 QByteArray buff(mt), 0); 267 236 for (int i = 0; i < n; ++i) { 268 237 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); 291 246 292 247 if (res != ERROR_SUCCESS) { … … 343 298 344 299 // 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())); 351 301 if (res != ERROR_SUCCESS) { 352 302 qWarning("QSettings: RegDeleteKey failed on subkey \"%s\": %s", … … 520 470 DWORD dataType; 521 471 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); 528 473 if (res != ERROR_SUCCESS) { 529 474 RegCloseKey(handle); … … 533 478 // get the value 534 479 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); 542 482 if (res != ERROR_SUCCESS) { 543 483 RegCloseKey(handle); 544 484 return false; 545 485 } 546 547 // note that when getting and setting the key contents on non-Unicode systems548 // 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 represented551 // in Local8Bit (and vice versa), doing Latin1 -> QString -> Local8Bit ->552 // QString -> Latin1 may distort data (in particular, replace some characters553 // with ?).554 486 555 487 switch (dataType) { … … 558 490 QString s; 559 491 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())); 565 493 } 566 494 if (value != 0) … … 574 502 int i = 0; 575 503 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); 582 505 i += s.length() + 1; 583 506 … … 596 519 QString s; 597 520 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); 603 522 } 604 523 if (value != 0) … … 642 561 if (deleteWriteHandleOnExit && writeHandle() != 0) { 643 562 #if defined(Q_OS_WINCE) 644 remove(regList.at(0).key()); 563 remove(regList.at(0).key()); 645 564 #else 646 DWORD res;647 565 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())); 653 567 if (res != ERROR_SUCCESS) { 654 568 qWarning("QSettings: Failed to delete key \"%s\": %s", … … 675 589 HKEY handle = openKey(writeHandle(), registryPermissions, keyPath(rKey)); 676 590 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())); 682 592 RegCloseKey(handle); 683 593 } … … 694 604 QString group = childKeys.at(i); 695 605 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())); 702 607 if (res != ERROR_SUCCESS) { 703 608 qWarning("QSettings: RegDeleteValue failed on subkey \"%s\": %s", … … 710 615 RegCloseKey(handle); 711 616 #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())); 717 618 718 619 if (res != ERROR_SUCCESS) { … … 751 652 DWORD type; 752 653 QByteArray regValueBuff; 753 754 // note that when getting and setting the key contents on non-Unicode systems755 // 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 represented758 // in Local8Bit (and vice versa), doing Latin1 -> QString -> Local8Bit ->759 // QString -> Latin1 may distort data (in particular, replace some characters760 // with ?).761 654 762 655 // Determine the type … … 778 671 if (type == REG_BINARY) { 779 672 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); 785 674 } else { 786 675 QStringList::const_iterator it = l.constBegin(); 787 676 for (; it != l.constEnd(); ++it) { 788 677 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); 794 679 } 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); 801 682 } 802 683 break; … … 809 690 break; 810 691 } 692 693 694 811 695 812 696 default: { … … 816 700 type = stringContainsNullChar(s) ? REG_BINARY : REG_SZ; 817 701 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); 823 703 } 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); 829 705 } 830 706 break; … … 833 709 834 710 // 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, 838 712 reinterpret_cast<const unsigned char*>(regValueBuff.constData()), 839 713 regValueBuff.size()); 840 }, {841 res = RegSetValueExA(handle, keyName(rKey).toLocal8Bit(), 0, type,842 reinterpret_cast<const unsigned char*>(regValueBuff.constData()),843 regValueBuff.size());844 } );845 714 846 715 if (res == ERROR_SUCCESS) {
Note:
See TracChangeset
for help on using the changeset viewer.