Commit 5ae330b6546dabada53c394b53ce9513f552a8a5

src/corelib: Remove QT_WA and non-Unicode code paths, dropping Win9x and NT support

Also: QString::fromUtf16() -> QString::fromWCharArray()
      WCHAR & TCHAR -> wchar_t
      LPTSTR/LPCTSTR -> LPWSTR/LPCWSTR
      Documentation update

Merge-request: 604
Reviewed-by: Marius Storm-Olsen <marius@trolltech.com>
  
233233 return QString();
234234
235235 const int wclen_auto = 4096;
236 WCHAR wc_auto[wclen_auto];
236 wchar_t wc_auto[wclen_auto];
237237 int wclen = wclen_auto;
238 WCHAR *wc = wc_auto;
238 wchar_t *wc = wc_auto;
239239 int len;
240240 QString sp;
241241 bool prepend = false;
275275 } else {
276276 wclen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
277277 mb, mblen, 0, 0);
278 wc = new WCHAR[wclen];
278 wc = new wchar_t[wclen];
279279 // and try again...
280280 }
281281 } else if (r == ERROR_NO_UNICODE_TRANSLATION) {
341341 const char *next = 0;
342342 QString s;
343343 while((next = CharNextExA(CP_ACP, mb, 0)) != mb) {
344 WCHAR wc[2] ={0};
344 wchar_t wc[2] ={0};
345345 int charlength = next - mb;
346346 int len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS, mb, charlength, wc, 2);
347347 if (len>0) {
10421042 This might be needed for some applications that want to use their
10431043 own mechanism for setting the locale.
10441044
1045 Setting this codec is not supported on DOS based Windows.
1046
10471045 \sa codecForLocale()
10481046*/
10491047void QTextCodec::setCodecForLocale(QTextCodec *c)
10501048{
1051#ifdef Q_WS_WIN
1052 if (QSysInfo::WindowsVersion& QSysInfo::WV_DOS_based)
1053 return;
1054#endif
10551049 localeMapper = c;
10561050 if (!localeMapper)
10571051 setupLocaleMapper();
  
915915 \fn bool qt_winUnicode()
916916 \relates <QtGlobal>
917917
918 Use QSysInfo::WindowsVersion and QSysInfo::WV_DOS_based instead.
918 This function always returns true.
919919
920920 \sa QSysInfo
921921*/
16201620 if (winver)
16211621 return winver;
16221622 winver = QSysInfo::WV_NT;
1623#ifndef Q_OS_WINCE
1624 OSVERSIONINFOA osver;
1625 osver.dwOSVersionInfoSize = sizeof(osver);
1626 GetVersionExA(&osver);
1627#else
1628 DWORD qt_cever = 0;
16291623 OSVERSIONINFOW osver;
16301624 osver.dwOSVersionInfoSize = sizeof(osver);
16311625 GetVersionEx(&osver);
1626#ifdef Q_OS_WINCE
1627 DWORD qt_cever = 0;
16321628 qt_cever = osver.dwMajorVersion * 100;
16331629 qt_cever += osver.dwMinorVersion * 10;
16341630#endif
19001900 break;
19011901 default: {
19021902#ifdef Q_OS_WIN
1903 QT_WA({
1904 unsigned short *string = 0;
1905 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
1906 NULL,
1907 errorCode,
1908 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1909 (LPTSTR)&string,
1910 0,
1911 NULL);
1912 ret = QString::fromUtf16(string);
1913 LocalFree((HLOCAL)string);
1914 }, {
1915 char *string = 0;
1916 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
1917 NULL,
1918 errorCode,
1919 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1920 (LPSTR)&string,
1921 0,
1922 NULL);
1923 ret = QString::fromLocal8Bit(string);
1924 LocalFree((HLOCAL)string);
1925 });
1903 wchar_t *string = 0;
1904 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
1905 NULL,
1906 errorCode,
1907 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1908 string,
1909 0,
1910 NULL);
1911 ret = QString::fromWCharArray(string);
1912 LocalFree((HLOCAL)string);
19261913
19271914 if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND)
19281915 ret = QString::fromLatin1("The specified module could not be found.");
  
147147 MSDOS - MS-DOS and Windows
148148 OS2 - OS/2
149149 OS2EMX - XFree86 on OS/2 (not PM)
150 WIN32 - Win32 (Windows 95/98/ME and Windows NT/2000/XP)
150 WIN32 - Win32 (Windows 2000/XP/Vista/7 and Windows Server 2003/2008)
151151 WINCE - WinCE (Windows CE 5.0)
152152 CYGWIN - Cygwin
153153 SOLARIS - Sun Solaris
14161416
14171417#if defined(Q_WS_WIN) || defined(Q_OS_CYGWIN)
14181418#if defined(QT3_SUPPORT)
1419inline QT3_SUPPORT bool qt_winUnicode() { return !(QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based); }
1419inline QT3_SUPPORT bool qt_winUnicode() { return true; }
14201420inline QT3_SUPPORT int qWinVersion() { return QSysInfo::WindowsVersion; }
14211421#endif
14221422
  
117117 if (access == ExecuteAccess)
118118 return getFileFlags(QAbstractFileEngine::ExeUserPerm);
119119
120 QT_WA( {
121 return ::_waccess((TCHAR *)QFSFileEnginePrivate::longFileName(data->fileName).utf16(), mode) == 0;
122 } , {
123 return QT_ACCESS(QFSFileEnginePrivate::win95Name(data->fileName), mode) == 0;
124 } );
120 return ::_waccess((wchar_t*)QFSFileEnginePrivate::longFileName(data->fileName).utf16(), mode) == 0;
125121#endif
126122 return false;
127123}
  
5656QWindowsFileSystemWatcherEngine::QWindowsFileSystemWatcherEngine()
5757 : msg(0)
5858{
59 HANDLE h = QT_WA_INLINE(CreateEventW(0, false, false, 0),
60 CreateEventA(0, false, false, 0));
61 if (h != INVALID_HANDLE_VALUE) {
59 if (HANDLE h = CreateEvent(0, false, false, 0)) {
6260 handles.reserve(MAXIMUM_WAIT_OBJECTS);
6361 handles.append(h);
6462 }
214214 const QString effectiveAbsolutePath =
215215 isDir ? (absolutePath + QLatin1Char('/')) : absolutePath;
216216
217 QT_WA({
218 handle.handle = FindFirstChangeNotificationW((TCHAR *) QDir::toNativeSeparators(effectiveAbsolutePath).utf16(),
219 false, flags);
220 },{
221 handle.handle = FindFirstChangeNotificationA(QDir::toNativeSeparators(effectiveAbsolutePath).toLocal8Bit(),
222 false, flags);
223 })
217 handle.handle = FindFirstChangeNotification((wchar_t*) QDir::toNativeSeparators(effectiveAbsolutePath).utf16(), false, flags);
224218 handle.flags = flags;
225219 if (handle.handle == INVALID_HANDLE_VALUE)
226220 continue;
  
7979 it->currentEntry = uncShares.at(uncShareIndex - 1);
8080 } else {
8181 // Local directory
82 QT_WA({
83 it->currentEntry = QString::fromUtf16((unsigned short *)findData.cFileName);
84 } , {
85 it->currentEntry = QString::fromLocal8Bit((const char *)findData.cFileName);
86 });
82 it->currentEntry = QString::fromWCharArray(findData.cFileName);
8783 }
8884}
8985
9393 if (platform->uncFallback) {
9494 ++platform->uncShareIndex;
9595 } else if (platform->findFileHandle != INVALID_HANDLE_VALUE) {
96 QT_WA({
97 if (!FindNextFile(platform->findFileHandle, &platform->findData)) {
98 platform->done = true;
99 FindClose(platform->findFileHandle);
100 }
101 } , {
102 if (!FindNextFileA(platform->findFileHandle, (WIN32_FIND_DATAA *)&platform->findData)) {
103 platform->done = true;
104 FindClose(platform->findFileHandle);
105 }
106 });
96 if (!FindNextFile(platform->findFileHandle, &platform->findData)) {
97 platform->done = true;
98 FindClose(platform->findFileHandle);
99 }
107100 }
108101}
109102
130130 path.append(QLatin1Char('/'));
131131 path.append(QLatin1String("*.*"));
132132
133 QT_WA({
134 QString fileName = QFSFileEnginePrivate::longFileName(path);
135 platform->findFileHandle = FindFirstFileW((TCHAR *)fileName.utf16(),
136 &platform->findData);
137 }, {
138 // Cast is safe, since char is at end of WIN32_FIND_DATA
139 platform->findFileHandle = FindFirstFileA(QFSFileEnginePrivate::win95Name(path),
140 (WIN32_FIND_DATAA*)&platform->findData);
141 });
133 QString fileName = QFSFileEnginePrivate::longFileName(path);
134 platform->findFileHandle = FindFirstFile((const wchar_t *)fileName.utf16(), &platform->findData);
142135
143136 if (platform->findFileHandle == INVALID_HANDLE_VALUE) {
144137 if (path.startsWith(QLatin1String("//"))) {
  
7272
7373public:
7474#ifdef Q_WS_WIN
75 static QByteArray win95Name(const QString &path);
7675 static QString longFileName(const QString &path);
7776#endif
7877 static QString canonicalized(const QString &path);
150150
151151#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
152152 static void resolveLibs();
153 static bool resolveUNCLibs_NT();
154 static bool resolveUNCLibs_9x();
153 static bool resolveUNCLibs();
155154 static bool uncListSharesOnServer(const QString &server, QStringList *list);
156155#endif
157156
  
152152
153153 triedResolve = true;
154154#if !defined(Q_OS_WINCE)
155 if(QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) {
156 HINSTANCE advapiHnd = LoadLibraryW(L"advapi32");
157 if (advapiHnd) {
158 ptrGetNamedSecurityInfoW = (PtrGetNamedSecurityInfoW)GetProcAddress(advapiHnd, "GetNamedSecurityInfoW");
159 ptrLookupAccountSidW = (PtrLookupAccountSidW)GetProcAddress(advapiHnd, "LookupAccountSidW");
160 ptrAllocateAndInitializeSid = (PtrAllocateAndInitializeSid)GetProcAddress(advapiHnd, "AllocateAndInitializeSid");
161 ptrBuildTrusteeWithSidW = (PtrBuildTrusteeWithSidW)GetProcAddress(advapiHnd, "BuildTrusteeWithSidW");
162 ptrBuildTrusteeWithNameW = (PtrBuildTrusteeWithNameW)GetProcAddress(advapiHnd, "BuildTrusteeWithNameW");
163 ptrGetEffectiveRightsFromAclW = (PtrGetEffectiveRightsFromAclW)GetProcAddress(advapiHnd, "GetEffectiveRightsFromAclW");
164 ptrFreeSid = (PtrFreeSid)GetProcAddress(advapiHnd, "FreeSid");
165 }
166 if (ptrBuildTrusteeWithNameW) {
167 HINSTANCE versionHnd = LoadLibraryW(L"version");
168 if (versionHnd) {
169 typedef DWORD (WINAPI *PtrGetFileVersionInfoSizeW)(LPWSTR lptstrFilename,LPDWORD lpdwHandle);
170 PtrGetFileVersionInfoSizeW ptrGetFileVersionInfoSizeW = (PtrGetFileVersionInfoSizeW)GetProcAddress(versionHnd, "GetFileVersionInfoSizeW");
171 typedef BOOL (WINAPI *PtrGetFileVersionInfoW)(LPWSTR lptstrFilename,DWORD dwHandle,DWORD dwLen,LPVOID lpData);
172 PtrGetFileVersionInfoW ptrGetFileVersionInfoW = (PtrGetFileVersionInfoW)GetProcAddress(versionHnd, "GetFileVersionInfoW");
173 typedef BOOL (WINAPI *PtrVerQueryValueW)(const LPVOID pBlock,LPWSTR lpSubBlock,LPVOID *lplpBuffer,PUINT puLen);
174 PtrVerQueryValueW ptrVerQueryValueW = (PtrVerQueryValueW)GetProcAddress(versionHnd, "VerQueryValueW");
175 if(ptrGetFileVersionInfoSizeW && ptrGetFileVersionInfoW && ptrVerQueryValueW) {
176 DWORD fakeHandle;
177 DWORD versionSize = ptrGetFileVersionInfoSizeW(L"secur32.dll", &fakeHandle);
178 if(versionSize) {
179 LPVOID versionData;
180 versionData = malloc(versionSize);
181 if(ptrGetFileVersionInfoW(L"secur32.dll", 0, versionSize, versionData)) {
182 UINT puLen;
183 VS_FIXEDFILEINFO *pLocalInfo;
184 if(ptrVerQueryValueW(versionData, L"\\", (void**)&pLocalInfo, &puLen)) {
185 WORD wVer1, wVer2, wVer3, wVer4;
186 wVer1 = HIWORD(pLocalInfo->dwFileVersionMS);
187 wVer2 = LOWORD(pLocalInfo->dwFileVersionMS);
188 wVer3 = HIWORD(pLocalInfo->dwFileVersionLS);
189 wVer4 = LOWORD(pLocalInfo->dwFileVersionLS);
190 // It will not work with secur32.dll version 5.0.2195.2862
191 if(!(wVer1 == 5 && wVer2 == 0 && wVer3 == 2195 && (wVer4 == 2862 || wVer4 == 4587))) {
192 HINSTANCE userHnd = LoadLibraryW(L"secur32");
193 if (userHnd) {
194 typedef BOOL (WINAPI *PtrGetUserNameExW)(EXTENDED_NAME_FORMAT nameFormat, ushort* lpBuffer, LPDWORD nSize);
195 PtrGetUserNameExW ptrGetUserNameExW = (PtrGetUserNameExW)GetProcAddress(userHnd, "GetUserNameExW");
196 if(ptrGetUserNameExW) {
197 static TCHAR buffer[258];
198 DWORD bufferSize = 257;
199 ptrGetUserNameExW(NameSamCompatible, (ushort*)buffer, &bufferSize);
200 ptrBuildTrusteeWithNameW(&currentUserTrusteeW, (ushort*)buffer);
201 }
202 FreeLibrary(userHnd);
155 HINSTANCE advapiHnd = LoadLibraryW(L"advapi32");
156 if (advapiHnd) {
157 ptrGetNamedSecurityInfoW = (PtrGetNamedSecurityInfoW)GetProcAddress(advapiHnd, "GetNamedSecurityInfoW");
158 ptrLookupAccountSidW = (PtrLookupAccountSidW)GetProcAddress(advapiHnd, "LookupAccountSidW");
159 ptrAllocateAndInitializeSid = (PtrAllocateAndInitializeSid)GetProcAddress(advapiHnd, "AllocateAndInitializeSid");
160 ptrBuildTrusteeWithSidW = (PtrBuildTrusteeWithSidW)GetProcAddress(advapiHnd, "BuildTrusteeWithSidW");
161 ptrBuildTrusteeWithNameW = (PtrBuildTrusteeWithNameW)GetProcAddress(advapiHnd, "BuildTrusteeWithNameW");
162 ptrGetEffectiveRightsFromAclW = (PtrGetEffectiveRightsFromAclW)GetProcAddress(advapiHnd, "GetEffectiveRightsFromAclW");
163 ptrFreeSid = (PtrFreeSid)GetProcAddress(advapiHnd, "FreeSid");
164 }
165 if (ptrBuildTrusteeWithNameW) {
166 HINSTANCE versionHnd = LoadLibraryW(L"version");
167 if (versionHnd) {
168 typedef DWORD (WINAPI *PtrGetFileVersionInfoSizeW)(LPWSTR lptstrFilename,LPDWORD lpdwHandle);
169 PtrGetFileVersionInfoSizeW ptrGetFileVersionInfoSizeW = (PtrGetFileVersionInfoSizeW)GetProcAddress(versionHnd, "GetFileVersionInfoSizeW");
170 typedef BOOL (WINAPI *PtrGetFileVersionInfoW)(LPWSTR lptstrFilename,DWORD dwHandle,DWORD dwLen,LPVOID lpData);
171 PtrGetFileVersionInfoW ptrGetFileVersionInfoW = (PtrGetFileVersionInfoW)GetProcAddress(versionHnd, "GetFileVersionInfoW");
172 typedef BOOL (WINAPI *PtrVerQueryValueW)(const LPVOID pBlock,LPWSTR lpSubBlock,LPVOID *lplpBuffer,PUINT puLen);
173 PtrVerQueryValueW ptrVerQueryValueW = (PtrVerQueryValueW)GetProcAddress(versionHnd, "VerQueryValueW");
174 if(ptrGetFileVersionInfoSizeW && ptrGetFileVersionInfoW && ptrVerQueryValueW) {
175 DWORD fakeHandle;
176 DWORD versionSize = ptrGetFileVersionInfoSizeW(L"secur32.dll", &fakeHandle);
177 if(versionSize) {
178 LPVOID versionData;
179 versionData = malloc(versionSize);
180 if(ptrGetFileVersionInfoW(L"secur32.dll", 0, versionSize, versionData)) {
181 UINT puLen;
182 VS_FIXEDFILEINFO *pLocalInfo;
183 if(ptrVerQueryValueW(versionData, L"\\", (void**)&pLocalInfo, &puLen)) {
184 WORD wVer1, wVer2, wVer3, wVer4;
185 wVer1 = HIWORD(pLocalInfo->dwFileVersionMS);
186 wVer2 = LOWORD(pLocalInfo->dwFileVersionMS);
187 wVer3 = HIWORD(pLocalInfo->dwFileVersionLS);
188 wVer4 = LOWORD(pLocalInfo->dwFileVersionLS);
189 // It will not work with secur32.dll version 5.0.2195.2862
190 if(!(wVer1 == 5 && wVer2 == 0 && wVer3 == 2195 && (wVer4 == 2862 || wVer4 == 4587))) {
191 HINSTANCE userHnd = LoadLibraryW(L"secur32");
192 if (userHnd) {
193 typedef BOOL (WINAPI *PtrGetUserNameExW)(EXTENDED_NAME_FORMAT nameFormat, ushort* lpBuffer, LPDWORD nSize);
194 PtrGetUserNameExW ptrGetUserNameExW = (PtrGetUserNameExW)GetProcAddress(userHnd, "GetUserNameExW");
195 if(ptrGetUserNameExW) {
196 static wchar_t buffer[258];
197 DWORD bufferSize = 257;
198 ptrGetUserNameExW(NameSamCompatible, (ushort*)buffer, &bufferSize);
199 ptrBuildTrusteeWithNameW(&currentUserTrusteeW, (ushort*)buffer);
203200 }
201 FreeLibrary(userHnd);
204202 }
205203 }
206204 }
207 free(versionData);
208205 }
206 free(versionData);
209207 }
210 FreeLibrary(versionHnd);
211208 }
209 FreeLibrary(versionHnd);
212210 }
213211 ptrOpenProcessToken = (PtrOpenProcessToken)GetProcAddress(advapiHnd, "OpenProcessToken");
214 HINSTANCE userenvHnd = LoadLibraryW(L"userenv");
212 HINSTANCE userenvHnd = LoadLibraryW(L"userenv");
215213 if (userenvHnd) {
216214 ptrGetUserProfileDirectoryW = (PtrGetUserProfileDirectoryW)GetProcAddress(userenvHnd, "GetUserProfileDirectoryW");
217215 }
223223#endif // QT_NO_LIBRARY
224224
225225// UNC functions NT
226typedef DWORD (WINAPI *PtrNetShareEnum_NT)(LPWSTR, DWORD, LPBYTE*, DWORD, LPDWORD, LPDWORD, LPDWORD);
227static PtrNetShareEnum_NT ptrNetShareEnum_NT = 0;
228typedef DWORD (WINAPI *PtrNetApiBufferFree_NT)(LPVOID);
229static PtrNetApiBufferFree_NT ptrNetApiBufferFree_NT = 0;
230typedef struct _SHARE_INFO_1_NT {
226typedef DWORD (WINAPI *PtrNetShareEnum)(LPWSTR, DWORD, LPBYTE*, DWORD, LPDWORD, LPDWORD, LPDWORD);
227static PtrNetShareEnum ptrNetShareEnum = 0;
228typedef DWORD (WINAPI *PtrNetApiBufferFree)(LPVOID);
229static PtrNetApiBufferFree ptrNetApiBufferFree = 0;
230typedef struct _SHARE_INFO_1 {
231231 LPWSTR shi1_netname;
232232 DWORD shi1_type;
233233 LPWSTR shi1_remark;
234} SHARE_INFO_1_NT;
234} SHARE_INFO_1;
235235
236236
237bool QFSFileEnginePrivate::resolveUNCLibs_NT()
237bool QFSFileEnginePrivate::resolveUNCLibs()
238238{
239239 static bool triedResolve = false;
240240 if (!triedResolve) {
241241#ifndef QT_NO_THREAD
242242 QMutexLocker locker(QMutexPool::globalInstanceGet(&triedResolve));
243243 if (triedResolve) {
244 return ptrNetShareEnum_NT && ptrNetApiBufferFree_NT;
244 return ptrNetShareEnum && ptrNetApiBufferFree;
245245 }
246246#endif
247247 triedResolve = true;
248248#if !defined(Q_OS_WINCE)
249249 HINSTANCE hLib = LoadLibraryW(L"Netapi32");
250250 if (hLib) {
251 ptrNetShareEnum_NT = (PtrNetShareEnum_NT)GetProcAddress(hLib, "NetShareEnum");
252 if (ptrNetShareEnum_NT)
253 ptrNetApiBufferFree_NT = (PtrNetApiBufferFree_NT)GetProcAddress(hLib, "NetApiBufferFree");
251 ptrNetShareEnum = (PtrNetShareEnum)GetProcAddress(hLib, "NetShareEnum");
252 if (ptrNetShareEnum)
253 ptrNetApiBufferFree = (PtrNetApiBufferFree)GetProcAddress(hLib, "NetApiBufferFree");
254254 }
255255#endif
256256 }
257 return ptrNetShareEnum_NT && ptrNetApiBufferFree_NT;
257 return ptrNetShareEnum && ptrNetApiBufferFree;
258258}
259259
260// UNC functions 9x
261typedef DWORD (WINAPI *PtrNetShareEnum_9x)(const char FAR *, short, char FAR *, unsigned short, unsigned short FAR *, unsigned short FAR *);
262static PtrNetShareEnum_9x ptrNetShareEnum_9x = 0;
263#ifdef LM20_NNLEN
264# define LM20_NNLEN_9x LM20_NNLEN
265#else
266# define LM20_NNLEN_9x 12
267#endif
268typedef struct _SHARE_INFO_1_9x {
269 char shi1_netname[LM20_NNLEN_9x+1];
270 char shi1_pad1;
271 unsigned short shi1_type;
272 char FAR* shi1_remark;
273} SHARE_INFO_1_9x;
274
275bool QFSFileEnginePrivate::resolveUNCLibs_9x()
276{
277 static bool triedResolve = false;
278 if (!triedResolve) {
279#ifndef QT_NO_THREAD
280 QMutexLocker locker(QMutexPool::globalInstanceGet(&triedResolve));
281 if (triedResolve) {
282 return ptrNetShareEnum_9x;
283 }
284#endif
285 triedResolve = true;
286#if !defined(Q_OS_WINCE)
287 HINSTANCE hLib = LoadLibraryA("Svrapi");
288 if (hLib)
289 ptrNetShareEnum_9x = (PtrNetShareEnum_9x)GetProcAddress(hLib, "NetShareEnum");
290#endif
291 }
292 return ptrNetShareEnum_9x;
293}
294
295260bool QFSFileEnginePrivate::uncListSharesOnServer(const QString &server, QStringList *list)
296261{
297 if (resolveUNCLibs_NT()) {
298 SHARE_INFO_1_NT *BufPtr, *p;
262 if (resolveUNCLibs()) {
263 SHARE_INFO_1 *BufPtr, *p;
299264 DWORD res;
300265 DWORD er=0,tr=0,resume=0, i;
301266 do {
302 res = ptrNetShareEnum_NT((wchar_t*)server.utf16(), 1, (LPBYTE *)&BufPtr, DWORD(-1), &er, &tr, &resume);
267 res = ptrNetShareEnum((wchar_t*)server.utf16(), 1, (LPBYTE *)&BufPtr, DWORD(-1), &er, &tr, &resume);
303268 if (res == ERROR_SUCCESS || res == ERROR_MORE_DATA) {
304269 p=BufPtr;
305270 for (i = 1; i <= er; ++i) {
306271 if (list && p->shi1_type == 0)
307 list->append(QString::fromUtf16((unsigned short *)p->shi1_netname));
272 list->append(QString::fromWCharArray(p->shi1_netname));
308273 p++;
309274 }
310275 }
311 ptrNetApiBufferFree_NT(BufPtr);
276 ptrNetApiBufferFree(BufPtr);
312277 } while (res==ERROR_MORE_DATA);
313278 return res == ERROR_SUCCESS;
314279
315 } else if (resolveUNCLibs_9x()) {
316 SHARE_INFO_1_9x *pBuf = 0;
317 short cbBuffer;
318 unsigned short nEntriesRead = 0;
319 unsigned short nTotalEntries = 0;
320 short numBuffs = 20;
321 DWORD nStatus = 0;
322 do {
323 cbBuffer = numBuffs * sizeof(SHARE_INFO_1_9x);
324 pBuf = (SHARE_INFO_1_9x *)malloc(cbBuffer);
325 if (pBuf) {
326 nStatus = ptrNetShareEnum_9x(server.toLocal8Bit().constData(), 1, (char FAR *)pBuf, cbBuffer, &nEntriesRead, &nTotalEntries);
327 if ((nStatus == ERROR_SUCCESS)) {
328 for (int i = 0; i < nEntriesRead; ++i) {
329 if (list && pBuf[i].shi1_type == 0)
330 list->append(QString::fromLocal8Bit(pBuf[i].shi1_netname));
331 }
332 free(pBuf);
333 break;
334 }
335 free(pBuf);
336 numBuffs *=2;
337 }
338 } while (nStatus == ERROR_MORE_DATA);
339 return nStatus == ERROR_SUCCESS;
340280 }
341281 return false;
342282}
337337 return false;
338338}
339339
340#if !defined(Q_OS_WINCE)
341// If you change this function, remember to also change the UNICODE version
342static QString nativeAbsoluteFilePathA(const QString &path)
340static QString nativeAbsoluteFilePathCore(const QString &path)
343341{
344342 QString ret;
345 QVarLengthArray<char, MAX_PATH> buf(MAX_PATH);
346 char *fileName = 0;
347 QByteArray ba = path.toLocal8Bit();
348 DWORD retLen = GetFullPathNameA(ba.constData(), buf.size(), buf.data(), &fileName);
349 if (retLen > (DWORD)buf.size()) {
350 buf.resize(retLen);
351 retLen = GetFullPathNameA(ba.constData(), buf.size(), buf.data(), &fileName);
352 }
353 if (retLen != 0)
354 ret = QString::fromLocal8Bit(buf.data(), retLen);
355 return ret;
356}
357#endif
358
359// If you change this function, remember to also change the NON-UNICODE version
360static QString nativeAbsoluteFilePathW(const QString &path)
361{
362 QString ret;
363343#if !defined(Q_OS_WINCE)
364344 QVarLengthArray<wchar_t, MAX_PATH> buf(MAX_PATH);
365345 wchar_t *fileName = 0;
366 DWORD retLen = GetFullPathNameW((wchar_t*)path.utf16(), buf.size(), buf.data(), &fileName);
346 DWORD retLen = GetFullPathName((wchar_t*)path.utf16(), buf.size(), buf.data(), &fileName);
367347 if (retLen > (DWORD)buf.size()) {
368348 buf.resize(retLen);
369 retLen = GetFullPathNameW((wchar_t*)path.utf16(), buf.size(), buf.data(), &fileName);
349 retLen = GetFullPathName((wchar_t*)path.utf16(), buf.size(), buf.data(), &fileName);
370350 }
371351 if (retLen != 0)
372 ret = QString::fromUtf16((unsigned short *)buf.data(), retLen);
352 ret = QString::fromWCharArray(buf.data(), retLen);
373353#else
374354 if (path.startsWith(QLatin1Char('/')) || path.startsWith(QLatin1Char('\\')))
375355 ret = QDir::toNativeSeparators(path);
361361
362362static QString nativeAbsoluteFilePath(const QString &path)
363363{
364 QString absPath = QT_WA_INLINE(nativeAbsoluteFilePathW(path), nativeAbsoluteFilePathA(path));
364 QString absPath = nativeAbsoluteFilePathCore(path);
365365 // This is really ugly, but GetFullPathName strips off whitespace at the end.
366366 // If you for instance write ". " in the lineedit of QFileDialog,
367367 // (which is an invalid filename) this function will strip the space off and viola,
379379 return absPath;
380380}
381381
382QByteArray QFSFileEnginePrivate::win95Name(const QString &path)
383{
384 QString ret(path);
385 if(path.length() > 1 && path[0] == QLatin1Char('/') && path[1] == QLatin1Char('/')) {
386 // Win95 cannot handle slash-slash needs slosh-slosh.
387 ret[0] = QLatin1Char('\\');
388 ret[1] = QLatin1Char('\\');
389 int n = ret.indexOf(QLatin1Char('/'));
390 if(n >= 0)
391 ret[n] = QLatin1Char('\\');
392 } else if(path.length() > 3 && path[2] == QLatin1Char('/') && path[3] == QLatin1Char('/')) {
393 ret[2] = QLatin1Char('\\');
394 ret.remove(3, 1);
395 int n = ret.indexOf(QLatin1Char('/'));
396 if(n >= 0)
397 ret[n] = QLatin1Char('\\');
398 }
399 return ret.toLocal8Bit();
400}
401
402382/*!
403383 \internal
404384*/
405405*/
406406void QFSFileEnginePrivate::nativeInitFileName()
407407{
408 QT_WA({
409 QString path = longFileName(QDir::toNativeSeparators(fixIfRelativeUncPath(filePath)));
410 nativeFilePath = QByteArray((const char *)path.utf16(), path.size() * 2 + 1);
411 }, {
412 QString path = fixIfRelativeUncPath(filePath);
413 nativeFilePath = win95Name(path).replace('/', '\\');
414 });
408 QString path = longFileName(QDir::toNativeSeparators(fixIfRelativeUncPath(filePath)));
409 nativeFilePath = QByteArray((const char *)path.utf16(), path.size() * 2 + 1);
415410}
416411
417412/*
432432 ? OPEN_ALWAYS : OPEN_EXISTING;
433433
434434 // Create the file handle.
435 QT_WA({
436 fileHandle = CreateFileW((TCHAR *)nativeFilePath.constData(),
437 accessRights,
438 shareMode,
439 &securityAtts,
440 creationDisp,
441 FILE_ATTRIBUTE_NORMAL,
442 NULL);
443 }, {
444 fileHandle = CreateFileA(nativeFilePath.constData(),
445 accessRights,
446 shareMode,
447 &securityAtts,
448 creationDisp,
449 FILE_ATTRIBUTE_NORMAL,
450 NULL);
451 });
435 fileHandle = CreateFile((const wchar_t*)nativeFilePath.constData(),
436 accessRights,
437 shareMode,
438 &securityAtts,
439 creationDisp,
440 FILE_ATTRIBUTE_NORMAL,
441 NULL);
452442
453443 // Bail out on error.
454444 if (fileHandle == INVALID_HANDLE_VALUE) {
524524 // Not-open mode, where the file name is known: We'll check the
525525 // file system directly.
526526 if (openMode == QIODevice::NotOpen && !nativeFilePath.isEmpty()) {
527 bool ok = false;
528527 WIN32_FILE_ATTRIBUTE_DATA attribData;
529 QT_WA({
530 ok = ::GetFileAttributesExW((TCHAR *)nativeFilePath.constData(),
528 bool ok = ::GetFileAttributesEx((const wchar_t*)nativeFilePath.constData(),
531529 GetFileExInfoStandard, &attribData);
532 } , {
533 ok = ::GetFileAttributesExA(nativeFilePath.constData(),
534 GetFileExInfoStandard, &attribData);
535 });
536530 if (ok) {
537531 qint64 size = attribData.nFileSizeHigh;
538532 size <<= 32;
826826bool QFSFileEngine::remove()
827827{
828828 Q_D(QFSFileEngine);
829 QT_WA({
830 return ::DeleteFileW((TCHAR*)QFSFileEnginePrivate::longFileName(d->filePath).utf16()) != 0;
831 } , {
832 return ::DeleteFileA(QFSFileEnginePrivate::win95Name(d->filePath)) != 0;
833 });
829 return ::DeleteFile((wchar_t*)QFSFileEnginePrivate::longFileName(d->filePath).utf16()) != 0;
834830}
835831
836832bool QFSFileEngine::copy(const QString &copyName)
837833{
838834 Q_D(QFSFileEngine);
839 QT_WA({
840 return ::CopyFileW((TCHAR*)QFSFileEnginePrivate::longFileName(d->filePath).utf16(),
841 (TCHAR*)QFSFileEnginePrivate::longFileName(copyName).utf16(), true) != 0;
842 } , {
843 return ::CopyFileA(QFSFileEnginePrivate::win95Name(d->filePath),
844 QFSFileEnginePrivate::win95Name(copyName), true) != 0;
845 });
835 return ::CopyFile((wchar_t*)QFSFileEnginePrivate::longFileName(d->filePath).utf16(),
836 (wchar_t*)QFSFileEnginePrivate::longFileName(copyName).utf16(), true) != 0;
846837}
847838
848839bool QFSFileEngine::rename(const QString &newName)
849840{
850841 Q_D(QFSFileEngine);
851 QT_WA({
852 return ::MoveFileW((TCHAR*)QFSFileEnginePrivate::longFileName(d->filePath).utf16(),
853 (TCHAR*)QFSFileEnginePrivate::longFileName(newName).utf16()) != 0;
854 } , {
855 return ::MoveFileA(QFSFileEnginePrivate::win95Name(d->filePath),
856 QFSFileEnginePrivate::win95Name(newName)) != 0;
857 });
842 return ::MoveFile((wchar_t*)QFSFileEnginePrivate::longFileName(d->filePath).utf16(),
843 (wchar_t*)QFSFileEnginePrivate::longFileName(newName).utf16()) != 0;
858844}
859845
860846static inline bool mkDir(const QString &path)
864864 if (platformId == 1 && QFSFileEnginePrivate::longFileName(path).size() > 256)
865865 return false;
866866#endif
867 QT_WA({
868 return ::CreateDirectoryW((TCHAR*)QFSFileEnginePrivate::longFileName(path).utf16(), 0);
869 } , {
870 return ::CreateDirectoryA(QFSFileEnginePrivate::win95Name(QFileInfo(path).absoluteFilePath()), 0);
871 });
867 return ::CreateDirectory((wchar_t*)QFSFileEnginePrivate::longFileName(path).utf16(), 0);
872868}
873869
874870static inline bool rmDir(const QString &path)
875871{
876 QT_WA({
877 return ::RemoveDirectoryW((TCHAR*)QFSFileEnginePrivate::longFileName(path).utf16());
878 } , {
879 return ::RemoveDirectoryA(QFSFileEnginePrivate::win95Name(QFileInfo(path).absoluteFilePath()));
880 });
872 return ::RemoveDirectory((wchar_t*)QFSFileEnginePrivate::longFileName(path).utf16());
881873}
882874
883875static inline bool isDirPath(const QString &dirPath, bool *existed)
878878 if (path.length() == 2 &&path.at(1) == QLatin1Char(':'))
879879 path += QLatin1Char('\\');
880880
881 DWORD fileAttrib = INVALID_FILE_ATTRIBUTES;
882 QT_WA({
883 fileAttrib = ::GetFileAttributesW((TCHAR*)QFSFileEnginePrivate::longFileName(path).utf16());
884 } , {
885 fileAttrib = ::GetFileAttributesA(QFSFileEnginePrivate::win95Name(QFileInfo(path).absoluteFilePath()));
886 });
881 DWORD fileAttrib = ::GetFileAttributes((wchar_t*)QFSFileEnginePrivate::longFileName(path).utf16());
887882
888883 if (existed)
889884 *existed = fileAttrib != INVALID_FILE_ATTRIBUTES;
960960 return false;
961961
962962#if !defined(Q_OS_WINCE)
963 int r;
964 QT_WA({
965 r = ::SetCurrentDirectoryW((WCHAR*)path.utf16());
966 } , {
967 r = ::SetCurrentDirectoryA(QFSFileEnginePrivate::win95Name(path));
968 });
969 return r != 0;
963 return ::SetCurrentDirectory((wchar_t*)path.utf16()) != 0;
970964#else
971 qfsPrivateCurrentDir = QFSFileEnginePrivate::longFileName(path);
972 return true;
965 qfsPrivateCurrentDir = QFSFileEnginePrivate::longFileName(path);
966 return true;
973967#endif
974968}
975969
976976 fileName.at(0).isLetter() && fileName.at(1) == QLatin1Char(':')) {
977977 int drv = fileName.toUpper().at(0).toLatin1() - 'A' + 1;
978978 if (_getdrive() != drv) {
979 QT_WA({
980 TCHAR buf[PATH_MAX];
981 ::_wgetdcwd(drv, buf, PATH_MAX);
982 ret.setUtf16((ushort*)buf, uint(::wcslen(buf)));
983 }, {
984 char buf[PATH_MAX];
985 ::_getdcwd(drv, buf, PATH_MAX);
986 ret = QString::fromLatin1(buf);
987 });
979 wchar_t buf[PATH_MAX];
980 ::_wgetdcwd(drv, buf, PATH_MAX);
981 ret = QString::fromWCharArray(buf);
988982 }
989983 }
990984 if (ret.isEmpty()) {
991985 //just the pwd
992 QT_WA({
993 DWORD size = 0;
994 WCHAR currentName[PATH_MAX];
995 size = ::GetCurrentDirectoryW(PATH_MAX, currentName);
996 if (size !=0) {
997 if (size > PATH_MAX) {
998 WCHAR * newCurrentName = new WCHAR[size];
999 if (::GetCurrentDirectoryW(PATH_MAX, newCurrentName) != 0)
1000 ret = QString::fromUtf16((ushort*)newCurrentName);
1001 delete [] newCurrentName;
1002 } else {
1003 ret = QString::fromUtf16((ushort*)currentName);
1004 }
986 DWORD size = 0;
987 wchar_t currentName[PATH_MAX];
988 size = ::GetCurrentDirectory(PATH_MAX, currentName);
989 if (size != 0) {
990 if (size > PATH_MAX) {
991 wchar_t *newCurrentName = new wchar_t[size];
992 if (::GetCurrentDirectory(PATH_MAX, newCurrentName) != 0)
993 ret = QString::fromWCharArray(newCurrentName);
994 delete [] newCurrentName;
995 } else {
996 ret = QString::fromWCharArray(currentName);
1005997 }
1006 } , {
1007 DWORD size = 0;
1008 char currentName[PATH_MAX];
1009 size = ::GetCurrentDirectoryA(PATH_MAX, currentName);
1010 if (size !=0)
1011 ret = QString::fromLocal8Bit(currentName);
1012 });
998 }
1013999 }
10141000 if (ret.length() >= 2 && ret[1] == QLatin1Char(':'))
10151001 ret[0] = ret.at(0).toUpper(); // Force uppercase drive letters.
10161002 return QDir::fromNativeSeparators(ret);
10171003#else
1018 Q_UNUSED(fileName);
1019 if (qfsPrivateCurrentDir.isEmpty())
1020 qfsPrivateCurrentDir = QCoreApplication::applicationDirPath();
1004 Q_UNUSED(fileName);
1005 if (qfsPrivateCurrentDir.isEmpty())
1006 qfsPrivateCurrentDir = QCoreApplication::applicationDirPath();
10211007
10221008 return QDir::fromNativeSeparators(qfsPrivateCurrentDir);
10231009#endif
10131013{
10141014 QString ret;
10151015#if !defined(QT_NO_LIBRARY)
1016 QT_WA (
1017 {
1018 QFSFileEnginePrivate::resolveLibs();
1019 if (ptrOpenProcessToken && ptrGetUserProfileDirectoryW) {
1020 HANDLE hnd = ::GetCurrentProcess();
1021 HANDLE token = 0;
1022 BOOL ok = ::ptrOpenProcessToken(hnd, TOKEN_QUERY, &token);
1023 if (ok) {
1024 DWORD dwBufferSize = 0;
1025 // First call, to determine size of the strings (with '\0').
1026 ok = ::ptrGetUserProfileDirectoryW(token, NULL, &dwBufferSize);
1027 if (!ok && dwBufferSize != 0) { // We got the required buffer size
1028 wchar_t *userDirectory = new wchar_t[dwBufferSize];
1029 // Second call, now we can fill the allocated buffer.
1030 ok = ::ptrGetUserProfileDirectoryW(token, userDirectory, &dwBufferSize);
1031 if (ok)
1032 ret = QString::fromUtf16((ushort*)userDirectory);
1016 QFSFileEnginePrivate::resolveLibs();
1017 if (ptrOpenProcessToken && ptrGetUserProfileDirectoryW) {
1018 HANDLE hnd = ::GetCurrentProcess();
1019 HANDLE token = 0;
1020 BOOL ok = ::ptrOpenProcessToken(hnd, TOKEN_QUERY, &token);
1021 if (ok) {
1022 DWORD dwBufferSize = 0;
1023 // First call, to determine size of the strings (with '\0').
1024 ok = ::ptrGetUserProfileDirectoryW(token, NULL, &dwBufferSize);
1025 if (!ok && dwBufferSize != 0) { // We got the required buffer size
1026 wchar_t *userDirectory = new wchar_t[dwBufferSize];
1027 // Second call, now we can fill the allocated buffer.
1028 ok = ::ptrGetUserProfileDirectoryW(token, userDirectory, &dwBufferSize);
1029 if (ok)
1030 ret = QString::fromWCharArray(userDirectory);
10331031
1034 delete [] userDirectory;
1035 }
1036 ::CloseHandle(token);
1037 }
1038 }
1039 }
1040 ,
1041 {
1042 // GetUserProfileDirectory is only available from NT 4.0,
1043 // so fall through for Win98 and friends version.
1044 })
1032 delete [] userDirectory;
1033 }
1034 ::CloseHandle(token);
1035 }
1036 }
10451037#endif
10461038 if(ret.isEmpty() || !QFile::exists(ret)) {
10471039 ret = QString::fromLocal8Bit(qgetenv("USERPROFILE").constData());
10731073
10741074QString QFSFileEngine::tempPath()
10751075{
1076 QString ret;
1077 int success;
1078 QT_WA({
1079 wchar_t tempPath[MAX_PATH];
1080 success = GetTempPathW(MAX_PATH, tempPath);
1081 ret = QString::fromUtf16((ushort*)tempPath);
1082 } , {
1083 char tempPath[MAX_PATH];
1084 success = GetTempPathA(MAX_PATH, tempPath);
1085 ret = QString::fromLocal8Bit(tempPath);
1086 });
1076 wchar_t tempPath[MAX_PATH];
1077 int success = GetTempPath(MAX_PATH, tempPath);
1078 QString ret = QString::fromWCharArray(tempPath);
1079
10871080 if (ret.isEmpty() || !success) {
10881081#if !defined(Q_OS_WINCE)
10891082 ret = QString::fromLatin1("c:/tmp");
11001100#elif defined(Q_OS_OS2EMX)
11011101 quint32 driveBits, cur;
11021102 if(DosQueryCurrentDisk(&cur,&driveBits) != NO_ERROR)
1103 exit(1);
1103 exit(1);
11041104 driveBits &= 0x3ffffff;
11051105#endif
11061106 char driveName[] = "A:/";
11421142 }
11431143 }
11441144#else
1145 DWORD tmpAttributes = GetFileAttributesW((TCHAR*)QFSFileEnginePrivate::longFileName(fname).utf16());
1145 DWORD tmpAttributes = GetFileAttributes((wchar_t*)QFSFileEnginePrivate::longFileName(fname).utf16());
11461146 if (tmpAttributes != -1) {
11471147 fileAttrib = tmpAttributes;
11481148 could_stat = true;
11491149 }
11501150#endif
11511151 } else {
1152 QT_WA({
1153 fileAttrib = GetFileAttributesW((TCHAR*)QFSFileEnginePrivate::longFileName(fname).utf16());
1154 } , {
1155 fileAttrib = GetFileAttributesA(QFSFileEnginePrivate::win95Name(QFileInfo(fname).absoluteFilePath()));
1156 });
1152 fileAttrib = GetFileAttributes((wchar_t*)QFSFileEnginePrivate::longFileName(fname).utf16());
11571153 could_stat = fileAttrib != INVALID_FILE_ATTRIBUTES;
11581154 if (!could_stat) {
11591155#if !defined(Q_OS_WINCE)
12091209#if !defined(Q_OS_WINCE)
12101210#if !defined(QT_NO_LIBRARY)
12111211 QString ret;
1212 QT_WA({
1213 bool neededCoInit = false;
1214 IShellLink *psl; // pointer to IShellLink i/f
1215 HRESULT hres;
1216 WIN32_FIND_DATA wfd;
1217 TCHAR szGotPath[MAX_PATH];
1218 // Get pointer to the IShellLink interface.
1219 hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
1220 IID_IShellLink, (LPVOID *)&psl);
12211212
1222 if(hres == CO_E_NOTINITIALIZED) { // COM was not initialized
1223 neededCoInit = true;
1224 CoInitialize(NULL);
1225 hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
1226 IID_IShellLink, (LPVOID *)&psl);
1227 }
1228 if(SUCCEEDED(hres)) { // Get pointer to the IPersistFile interface.
1229 IPersistFile *ppf;
1230 hres = psl->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf);
1231 if(SUCCEEDED(hres)) {
1232 hres = ppf->Load((LPOLESTR)link.utf16(), STGM_READ);
1233 //The original path of the link is retrieved. If the file/folder
1234 //was moved, the return value still have the old path.
1235 if(SUCCEEDED(hres)) {
1236 if (psl->GetPath(szGotPath, MAX_PATH, &wfd, SLGP_UNCPRIORITY) == NOERROR)
1237 ret = QString::fromUtf16((ushort*)szGotPath);
1238 }
1239 ppf->Release();
1240 }
1241 psl->Release();
1242 }
1243 if(neededCoInit)
1244 CoUninitialize();
1245 } , {
1246 bool neededCoInit = false;
1247 IShellLinkA *psl; // pointer to IShellLink i/f
1248 HRESULT hres;
1249 WIN32_FIND_DATAA wfd;
1250 char szGotPath[MAX_PATH];
1251 // Get pointer to the IShellLink interface.
1213 bool neededCoInit = false;
1214 IShellLink *psl; // pointer to IShellLink i/f
1215 WIN32_FIND_DATA wfd;
1216 wchar_t szGotPath[MAX_PATH];
12521217
1253 hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
1254 IID_IShellLinkA, (LPVOID *)&psl);
1218 // Get pointer to the IShellLink interface.
1219 HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&psl);
12551220
1256 if(hres == CO_E_NOTINITIALIZED) { // COM was not initialized
1257 neededCoInit = true;
1258 CoInitialize(NULL);
1259 hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
1260 IID_IShellLinkA, (LPVOID *)&psl);
1261 }
1262 if(SUCCEEDED(hres)) { // Get pointer to the IPersistFile interface.
1263 IPersistFile *ppf;
1264 hres = psl->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf);
1265 if(SUCCEEDED(hres)) {
1266 hres = ppf->Load((LPOLESTR)QFileInfo(link).absoluteFilePath().utf16(), STGM_READ);
1267 //The original path of the link is retrieved. If the file/folder
1268 //was moved, the return value still have the old path.
1269 if(SUCCEEDED(hres)) {
1270 if (psl->GetPath((char*)szGotPath, MAX_PATH, &wfd, SLGP_UNCPRIORITY) == NOERROR)
1271 ret = QString::fromLocal8Bit(szGotPath);
1272 }
1273 ppf->Release();
1221 if (hres == CO_E_NOTINITIALIZED) { // COM was not initialized
1222 neededCoInit = true;
1223 CoInitialize(NULL);
1224 hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
1225 IID_IShellLink, (LPVOID *)&psl);
1226 }
1227 if (SUCCEEDED(hres)) { // Get pointer to the IPersistFile interface.
1228 IPersistFile *ppf;
1229 hres = psl->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf);
1230 if(SUCCEEDED(hres)) {
1231 hres = ppf->Load((LPOLESTR)link.utf16(), STGM_READ);
1232 //The original path of the link is retrieved. If the file/folder
1233 //was moved, the return value still have the old path.
1234 if(SUCCEEDED(hres)) {
1235 if (psl->GetPath(szGotPath, MAX_PATH, &wfd, SLGP_UNCPRIORITY) == NOERROR)
1236 ret = QString::fromWCharArray(szGotPath);
12741237 }
1275 psl->Release();
1238 ppf->Release();
12761239 }
1277 if(neededCoInit)
1278 CoUninitialize();
1279 });
1240 psl->Release();
1241 }
1242 if (neededCoInit)
1243 CoUninitialize();
1244
12801245 return ret;
12811246#else
12821247 Q_UNUSED(link);
12511251 wchar_t target[MAX_PATH];
12521252 QString result;
12531253 if (SHGetShortcutTarget((wchar_t*)QFileInfo(link).absoluteFilePath().replace(QLatin1Char('/'),QLatin1Char('\\')).utf16(), target, MAX_PATH)) {
1254 result = QString::fromUtf16(reinterpret_cast<const ushort *> (target));
1254 result = QString::fromWCharArray(target);
12551255 if (result.startsWith(QLatin1Char('"')))
12561256 result.remove(0,1);
12571257 if (result.endsWith(QLatin1Char('"')))
12781278 QString linkName = newName;
12791279 //### assume that they add .lnk
12801280
1281 QT_WA({
1282 HRESULT hres;
1283 IShellLink *psl;
1284 bool neededCoInit = false;
1281 IShellLink *psl;
1282 bool neededCoInit = false;
12851283
1286 hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);
1287 if(hres == CO_E_NOTINITIALIZED) { // COM was not initialized
1288 neededCoInit = true;
1289 CoInitialize(NULL);
1290 hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);
1291 }
1292 if (SUCCEEDED(hres)) {
1293 hres = psl->SetPath((wchar_t *)fileName(AbsoluteName).replace(QLatin1Char('/'), QLatin1Char('\\')).utf16());
1294 if (SUCCEEDED(hres)) {
1295 hres = psl->SetWorkingDirectory((wchar_t *)fileName(AbsolutePathName).replace(QLatin1Char('/'), QLatin1Char('\\')).utf16());
1296 if (SUCCEEDED(hres)) {
1297 IPersistFile *ppf;
1298 hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
1299 if (SUCCEEDED(hres)) {
1300 hres = ppf->Save((TCHAR*)linkName.utf16(), TRUE);
1301 if (SUCCEEDED(hres))
1302 ret = true;
1303 ppf->Release();
1304 }
1305 }
1306 }
1307 psl->Release();
1308 }
1309 if(neededCoInit)
1310 CoUninitialize();
1311 } , {
1312 // the SetPath() call _sometimes_ changes the current path and when it does it sometimes
1313 // does not let us change it back unless we call currentPath() many times.
1314 QString cwd = currentPath();
1315 HRESULT hres;
1316 IShellLinkA *psl;
1317 bool neededCoInit = false;
1284 HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);
13181285
1286 if (hres == CO_E_NOTINITIALIZED) { // COM was not initialized
1287 neededCoInit = true;
1288 CoInitialize(NULL);
13191289 hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);
1320 if(hres == CO_E_NOTINITIALIZED) { // COM was not initialized
1321 neededCoInit = true;
1322 CoInitialize(NULL);
1323 hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&psl);
1324 }
1290 }
1291
1292 if (SUCCEEDED(hres)) {
1293 hres = psl->SetPath((wchar_t *)fileName(AbsoluteName).replace(QLatin1Char('/'), QLatin1Char('\\')).utf16());
13251294 if (SUCCEEDED(hres)) {
1326 currentPath();
1327 hres = psl->SetPath((char *)QString::fromLocal8Bit(QFSFileEnginePrivate::win95Name(fileName(AbsoluteName))).utf16());
1328 currentPath();
1295 hres = psl->SetWorkingDirectory((wchar_t *)fileName(AbsolutePathName).replace(QLatin1Char('/'), QLatin1Char('\\')).utf16());
13291296 if (SUCCEEDED(hres)) {
1330 hres = psl->SetWorkingDirectory((char *)QString::fromLocal8Bit(QFSFileEnginePrivate::win95Name(fileName(AbsolutePathName))).utf16());
1331 currentPath();
1297 IPersistFile *ppf;
1298 hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
13321299 if (SUCCEEDED(hres)) {
1333 IPersistFile *ppf;
1334 hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
1335 if (SUCCEEDED(hres)) {
1336 currentPath();
1337 hres = ppf->Save((LPCOLESTR)linkName.utf16(), TRUE);
1338 currentPath();
1339 if (SUCCEEDED(hres))
1340 ret = true;
1341 ppf->Release();
1342 }
1300 hres = ppf->Save((wchar_t*)linkName.utf16(), TRUE);
1301 if (SUCCEEDED(hres))
1302 ret = true;
1303 ppf->Release();
13431304 }
1344 psl->Release();
13451305 }
13461306 }
1347 if(neededCoInit)
1307 psl->Release();
1308 }
1309 if(neededCoInit)
13481310 CoUninitialize();
1349 setCurrentPath(cwd);
1350 });
1311
13511312 return ret;
13521313#else
13531314 Q_UNUSED(newName);
13351335
13361336#if !defined(QT_NO_LIBRARY)
13371337 if((qt_ntfs_permission_lookup > 0) && ((QSysInfo::WindowsVersion&QSysInfo::WV_NT_based) > QSysInfo::WV_NT)) {
1338 PSID pOwner = 0;
1339 PSID pGroup = 0;
1340 PACL pDacl;
1338 PSID pOwner = 0;
1339 PSID pGroup = 0;
1340 PACL pDacl;
13411341 PSECURITY_DESCRIPTOR pSD;
13421342 ACCESS_MASK access_mask;
13431343
13471347
13481348 QString fname = filePath.endsWith(QLatin1String(".lnk")) ? readLink(filePath) : filePath;
13491349 DWORD res = ptrGetNamedSecurityInfoW((wchar_t*)fname.utf16(), SE_FILE_OBJECT,
1350 OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
1351 &pOwner, &pGroup, &pDacl, 0, &pSD);
1350 OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
1351 &pOwner, &pGroup, &pDacl, 0, &pSD);
13521352
13531353 if(res == ERROR_SUCCESS) {
13541354 TRUSTEE_W trustee;
13551355 { //user
13561356 if(ptrGetEffectiveRightsFromAclW(pDacl, &currentUserTrusteeW, &access_mask) != ERROR_SUCCESS)
13571357 access_mask = (ACCESS_MASK)-1;
1358 if(access_mask & ReadMask)
1359 ret |= QAbstractFileEngine::ReadUserPerm;
1360 if(access_mask & WriteMask)
1361 ret |= QAbstractFileEngine::WriteUserPerm;
1362 if(access_mask & ExecMask)
1363 ret |= QAbstractFileEngine::ExeUserPerm;
1358 if(access_mask & ReadMask)
1359 ret |= QAbstractFileEngine::ReadUserPerm;
1360 if(access_mask & WriteMask)
1361 ret |= QAbstractFileEngine::WriteUserPerm;
1362 if(access_mask & ExecMask)
1363 ret |= QAbstractFileEngine::ExeUserPerm;
13641364 }
13651365 { //owner
13661366 ptrBuildTrusteeWithSidW(&trustee, pOwner);
13671367 if(ptrGetEffectiveRightsFromAclW(pDacl, &trustee, &access_mask) != ERROR_SUCCESS)
13681368 access_mask = (ACCESS_MASK)-1;
1369 if(access_mask & ReadMask)
1370 ret |= QAbstractFileEngine::ReadOwnerPerm;
1371 if(access_mask & WriteMask)
1372 ret |= QAbstractFileEngine::WriteOwnerPerm;
1373 if(access_mask & ExecMask)
1374 ret |= QAbstractFileEngine::ExeOwnerPerm;
1369 if(access_mask & ReadMask)
1370 ret |= QAbstractFileEngine::ReadOwnerPerm;
1371 if(access_mask & WriteMask)
1372 ret |= QAbstractFileEngine::WriteOwnerPerm;
1373 if(access_mask & ExecMask)
1374 ret |= QAbstractFileEngine::ExeOwnerPerm;
13751375 }
13761376 { //group
13771377 ptrBuildTrusteeWithSidW(&trustee, pGroup);
13781378 if(ptrGetEffectiveRightsFromAclW(pDacl, &trustee, &access_mask) != ERROR_SUCCESS)
13791379 access_mask = (ACCESS_MASK)-1;
1380 if(access_mask & ReadMask)
1381 ret |= QAbstractFileEngine::ReadGroupPerm;
1382 if(access_mask & WriteMask)
1383 ret |= QAbstractFileEngine::WriteGroupPerm;
1384 if(access_mask & ExecMask)
1385 ret |= QAbstractFileEngine::ExeGroupPerm;
1380 if(access_mask & ReadMask)
1381 ret |= QAbstractFileEngine::ReadGroupPerm;
1382 if(access_mask & WriteMask)
1383 ret |= QAbstractFileEngine::WriteGroupPerm;
1384 if(access_mask & ExecMask)
1385 ret |= QAbstractFileEngine::ExeGroupPerm;
13861386 }
13871387 { //other (world)
13881388 // Create SID for Everyone (World)
13921392 ptrBuildTrusteeWithSidW(&trustee, pWorld);
13931393 if(ptrGetEffectiveRightsFromAclW(pDacl, &trustee, &access_mask) != ERROR_SUCCESS)
13941394 access_mask = (ACCESS_MASK)-1; // ###
1395 if(access_mask & ReadMask)
1396 ret |= QAbstractFileEngine::ReadOtherPerm;
1397 if(access_mask & WriteMask)
1398 ret |= QAbstractFileEngine::WriteOtherPerm;
1399 if(access_mask & ExecMask)
1400 ret |= QAbstractFileEngine::ExeOtherPerm;
1395 if(access_mask & ReadMask)
1396 ret |= QAbstractFileEngine::ReadOtherPerm;
1397 if(access_mask & WriteMask)
1398 ret |= QAbstractFileEngine::WriteOtherPerm;
1399 if(access_mask & ExecMask)
1400 ret |= QAbstractFileEngine::ExeOtherPerm;
14011401 }
14021402 ptrFreeSid(pWorld);
14031403 }
14071407 } else
14081408#endif
14091409 {
1410 //### what to do with permissions if we don't use ntfs or are not on a NT system
1411 // for now just add all permissions and what about exe missions ??
1412 // also qt_ntfs_permission_lookup is now not set by defualt ... should it ?
1413 ret |= QAbstractFileEngine::ReadOtherPerm | QAbstractFileEngine::ReadGroupPerm
1414 | QAbstractFileEngine::ReadOwnerPerm | QAbstractFileEngine::ReadUserPerm
1415 | QAbstractFileEngine::WriteUserPerm | QAbstractFileEngine::WriteOwnerPerm
1416 | QAbstractFileEngine::WriteGroupPerm | QAbstractFileEngine::WriteOtherPerm;
1410 //### what to do with permissions if we don't use NTFS
1411 // for now just add all permissions and what about exe missions ??
1412 // also qt_ntfs_permission_lookup is now not set by defualt ... should it ?
1413 ret |= QAbstractFileEngine::ReadOtherPerm | QAbstractFileEngine::ReadGroupPerm
1414 | QAbstractFileEngine::ReadOwnerPerm | QAbstractFileEngine::ReadUserPerm
1415 | QAbstractFileEngine::WriteUserPerm | QAbstractFileEngine::WriteOwnerPerm
1416 | QAbstractFileEngine::WriteGroupPerm | QAbstractFileEngine::WriteOtherPerm;
14171417 }
14181418
14191419 if (doStat()) {
16481648 return false;
16491649
16501650#if !defined(Q_OS_WINCE)
1651 QT_WA({
1652 ret = ::_wchmod((TCHAR*)d->filePath.utf16(), mode) == 0;
1653 } , {
1654 ret = ::_chmod(d->filePath.toLocal8Bit(), mode) == 0;
1655 });
1651 ret = ::_wchmod((wchar_t*)d->filePath.utf16(), mode) == 0;
16561652#else
1657 ret = ::_wchmod((TCHAR*)d->longFileName(d->filePath).utf16(), mode);
1653 ret = ::_wchmod((wchar_t*)d->longFileName(d->filePath).utf16(), mode);
16581654#endif
16591655 return ret;
16601656}
16931693static inline QDateTime fileTimeToQDateTime(const FILETIME *time)
16941694{
16951695 QDateTime ret;
1696 if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based || QSysInfo::WindowsVersion & QSysInfo::WV_CE_based) {
1697 // SystemTimeToTzSpecificLocalTime is not available on Win98/ME so we have to pull it off ourselves.
1698 SYSTEMTIME systime;
1699 FILETIME ftime;
1700 systime.wYear = 1970;
1701 systime.wMonth = 1;
1702 systime.wDay = 1;
1703 systime.wHour = 0;
1704 systime.wMinute = 0;
1705 systime.wSecond = 0;
1706 systime.wMilliseconds = 0;
1707 systime.wDayOfWeek = 4;
1708 SystemTimeToFileTime(&systime, &ftime);
1709 unsigned __int64 acttime = (unsigned __int64)time->dwHighDateTime << 32 | time->dwLowDateTime;
1710 FileTimeToSystemTime(time, &systime);
1711 unsigned __int64 time1970 = (unsigned __int64)ftime.dwHighDateTime << 32 | ftime.dwLowDateTime;
1712 unsigned __int64 difftime = acttime - time1970;
1713 difftime /= 10000000;
1714 ret.setTime_t((unsigned int)difftime);
1715 } else {
1716#ifndef Q_OS_WINCE
1717 SYSTEMTIME sTime, lTime;
1718 FileTimeToSystemTime(time, &sTime);
1719 SystemTimeToTzSpecificLocalTime(0, &sTime, &lTime);
1720 ret.setDate(QDate(lTime.wYear, lTime.wMonth, lTime.wDay));
1721 ret.setTime(QTime(lTime.wHour, lTime.wMinute, lTime.wSecond, lTime.wMilliseconds));
1696
1697#if defined(Q_OS_WINCE)
1698 SYSTEMTIME systime;
1699 FILETIME ftime;
1700 systime.wYear = 1970;
1701 systime.wMonth = 1;
1702 systime.wDay = 1;
1703 systime.wHour = 0;
1704 systime.wMinute = 0;
1705 systime.wSecond = 0;
1706 systime.wMilliseconds = 0;
1707 systime.wDayOfWeek = 4;
1708 SystemTimeToFileTime(&systime, &ftime);
1709 unsigned __int64 acttime = (unsigned __int64)time->dwHighDateTime << 32 | time->dwLowDateTime;
1710 FileTimeToSystemTime(time, &systime);
1711 unsigned __int64 time1970 = (unsigned __int64)ftime.dwHighDateTime << 32 | ftime.dwLowDateTime;
1712 unsigned __int64 difftime = acttime - time1970;
1713 difftime /= 10000000;
1714 ret.setTime_t((unsigned int)difftime);
1715#else
1716 SYSTEMTIME sTime, lTime;
1717 FileTimeToSystemTime(time, &sTime);
1718 SystemTimeToTzSpecificLocalTime(0, &sTime, &lTime);
1719 ret.setDate(QDate(lTime.wYear, lTime.wMonth, lTime.wDay));
1720 ret.setTime(QTime(lTime.wHour, lTime.wMinute, lTime.wSecond, lTime.wMilliseconds));
17221721#endif
1723 }
1722
17241723 return ret;
17251724}
17261725
17431743 }
17441744#endif
17451745 } else {
1746 bool ok = false;
17471746 WIN32_FILE_ATTRIBUTE_DATA attribData;
1748 QT_WA({
1749 ok = ::GetFileAttributesExW((TCHAR*)QFSFileEnginePrivate::longFileName(d->filePath).utf16(), GetFileExInfoStandard, &attribData);
1750 } , {
1751 ok = ::GetFileAttributesExA(QFSFileEnginePrivate::win95Name(QFileInfo(d->filePath).absoluteFilePath()), GetFileExInfoStandard, &attribData);
1752 });
1747 bool ok = ::GetFileAttributesEx((wchar_t*)QFSFileEnginePrivate::longFileName(d->filePath).utf16(), GetFileExInfoStandard, &attribData);
17531748 if (ok) {
17541749 if(time == CreationTime)
17551750 ret = fileTimeToQDateTime(&attribData.ftCreationTime);
17641764 Q_UNUSED(flags);
17651765 if (openMode == QFile::NotOpen) {
17661766 q->setError(QFile::PermissionsError, qt_error_string());
1767 return 0;
1767 return 0;
17681768 }
17691769 if (offset == 0 && size == 0) {
17701770 q->setError(QFile::UnspecifiedError, qt_error_string());
1771 return 0;
1771 return 0;
17721772 }
17731773
17741774
17811781 #ifdef Q_USE_DEPRECATED_MAP_API
17821782 nativeClose();
17831783 if (fileMapHandle == INVALID_HANDLE_VALUE) {
1784 fileMapHandle = CreateFileForMappingW((TCHAR *)nativeFilePath.constData(),
1784 fileMapHandle = CreateFileForMapping((const wchar_t*)nativeFilePath.constData(),
17851785 GENERIC_READ | (openMode & QIODevice::WriteOnly ? GENERIC_WRITE : 0),
17861786 0,
17871787 NULL,
17961796#endif
17971797
17981798 // first create the file mapping handle
1799 HANDLE mapHandle = 0;
18001799 DWORD protection = (openMode & QIODevice::WriteOnly) ? PAGE_READWRITE : PAGE_READONLY;
1801 QT_WA({
1802 mapHandle = ::CreateFileMappingW(handle, 0, protection,
1803 0, 0, 0);
1804 },{
1805 mapHandle = ::CreateFileMappingA(handle, 0, protection,
1806 0, 0, 0);
1807 });
1800 HANDLE mapHandle = ::CreateFileMapping(handle, 0, protection, 0, 0, 0);
18081801 if (mapHandle == NULL) {
18091802 q->setError(QFile::PermissionsError, qt_error_string());
18101803#ifdef Q_USE_DEPRECATED_MAP_API
18111804 mapHandleClose();
18121805#endif
1813 return 0;
1806 return 0;
18141807 }
18151808
18161809 // setup args to map
18321832 switch(GetLastError()) {
18331833 case ERROR_ACCESS_DENIED:
18341834 q->setError(QFile::PermissionsError, qt_error_string());
1835 break;
1835 break;
18361836 case ERROR_INVALID_PARAMETER:
18371837 // size are out of bounds
18381838 default:
  
5454#include <private/qthread_p.h>
5555#include <qdebug.h>
5656
57#include "private/qfsfileengine_p.h" // for longFileName and win95FileName
57#include "private/qfsfileengine_p.h" // for longFileName
5858
5959
6060#ifndef QT_NO_PROCESS
122122 if (&channel == &stdinChannel) {
123123 // try to open in read-only mode
124124 channel.pipe[1] = INVALID_Q_PIPE;
125 QT_WA({
126 channel.pipe[0] =
127 CreateFileW((TCHAR*)QFSFileEnginePrivate::longFileName(channel.file).utf16(),
128 GENERIC_READ,
129 FILE_SHARE_READ | FILE_SHARE_WRITE,
130 &secAtt,
131 OPEN_EXISTING,
132 FILE_ATTRIBUTE_NORMAL,
133 NULL);
134 }, {
135 channel.pipe[0] =
136 CreateFileA(QFSFileEnginePrivate::win95Name(channel.file),
137 GENERIC_READ,
138 FILE_SHARE_READ | FILE_SHARE_WRITE,
139 &secAtt,
140 OPEN_EXISTING,
141 FILE_ATTRIBUTE_NORMAL,
142 NULL);
143 });
125 channel.pipe[0] =
126 CreateFile((const wchar_t*)QFSFileEnginePrivate::longFileName(channel.file).utf16(),
127 GENERIC_READ,
128 FILE_SHARE_READ | FILE_SHARE_WRITE,
129 &secAtt,
130 OPEN_EXISTING,
131 FILE_ATTRIBUTE_NORMAL,
132 NULL);
133
144134 if (channel.pipe[0] != INVALID_Q_PIPE)
145135 return true;
146136
138138 } else {
139139 // open in write mode
140140 channel.pipe[0] = INVALID_Q_PIPE;
141 DWORD creation;
142 if (channel.append)
143 creation = OPEN_ALWAYS;
144 else
145 creation = CREATE_ALWAYS;
141 channel.pipe[1] =
142 CreateFile((const wchar_t *)QFSFileEnginePrivate::longFileName(channel.file).utf16(),
143 GENERIC_WRITE,
144 FILE_SHARE_READ | FILE_SHARE_WRITE,
145 &secAtt,
146 channel.append ? OPEN_ALWAYS : CREATE_ALWAYS,
147 FILE_ATTRIBUTE_NORMAL,
148 NULL);
146149
147 QT_WA({
148 channel.pipe[1] =
149 CreateFileW((TCHAR*)QFSFileEnginePrivate::longFileName(channel.file).utf16(),
150 GENERIC_WRITE,
151 FILE_SHARE_READ | FILE_SHARE_WRITE,
152 &secAtt,
153 creation,
154 FILE_ATTRIBUTE_NORMAL,
155 NULL);
156 }, {
157 channel.pipe[1] =
158 CreateFileA(QFSFileEnginePrivate::win95Name(channel.file),
159 GENERIC_WRITE,
160 FILE_SHARE_READ | FILE_SHARE_WRITE,
161 &secAtt,
162 creation,
163 FILE_ATTRIBUTE_NORMAL,
164 NULL);
165 });
166150 if (channel.pipe[1] != INVALID_Q_PIPE) {
167151 if (channel.append) {
168152 SetFilePointer(channel.pipe[1], 0, NULL, FILE_END);
301301 int pos = 0;
302302 QHash<QString, QString>::ConstIterator it = copy.constBegin(),
303303 end = copy.constEnd();
304#ifdef UNICODE
305 if (!(QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based)) {
306 static const TCHAR equal = L'=';
307 static const TCHAR nul = L'\0';
308304
309 for ( ; it != end; ++it) {
310 uint tmpSize = sizeof(TCHAR) * (it.key().length() + it.value().length() + 2);
311 // ignore empty strings
312 if (tmpSize == sizeof(TCHAR)*2)
313 continue;
314 envlist.resize(envlist.size() + tmpSize);
305 static const wchar_t equal = L'=';
306 static const wchar_t nul = L'\0';
315307
316 tmpSize = it.key().length() * sizeof(TCHAR);
317 memcpy(envlist.data()+pos, it.key().utf16(), tmpSize);
318 pos += tmpSize;
308 for ( ; it != end; ++it) {
309 uint tmpSize = sizeof(wchar_t) * (it.key().length() + it.value().length() + 2);
310 // ignore empty strings
311 if (tmpSize == sizeof(wchar_t) * 2)
312 continue;
313 envlist.resize(envlist.size() + tmpSize);
319314
320 memcpy(envlist.data()+pos, &equal, sizeof(TCHAR));
321 pos += sizeof(TCHAR);
315 tmpSize = it.key().length() * sizeof(wchar_t);
316 memcpy(envlist.data()+pos, it.key().utf16(), tmpSize);
317 pos += tmpSize;
322318
323 tmpSize = it.value().length() * sizeof(TCHAR);
324 memcpy(envlist.data()+pos, it.value().utf16(), tmpSize);
325 pos += tmpSize;
319 memcpy(envlist.data()+pos, &equal, sizeof(wchar_t));
320 pos += sizeof(wchar_t);
326321
327 memcpy(envlist.data()+pos, &nul, sizeof(TCHAR));
328 pos += sizeof(TCHAR);
329 }
330 // add the 2 terminating 0 (actually 4, just to be on the safe side)
331 envlist.resize( envlist.size()+4 );
332 envlist[pos++] = 0;
333 envlist[pos++] = 0;
334 envlist[pos++] = 0;
335 envlist[pos++] = 0;
336 } else
337#endif // UNICODE
338 {
339 for ( ; it != end; it++) {
340 QByteArray tmp = it.key().toLocal8Bit();
341 tmp.append('=');
342 tmp.append(it.value().toLocal8Bit());
322 tmpSize = it.value().length() * sizeof(wchar_t);
323 memcpy(envlist.data()+pos, it.value().utf16(), tmpSize);
324 pos += tmpSize;
343325
344 uint tmpSize = tmp.length() + 1;
345 envlist.resize(envlist.size() + tmpSize);
346 memcpy(envlist.data()+pos, tmp.data(), tmpSize);
347 pos += tmpSize;
348 }
349 // add the terminating 0 (actually 2, just to be on the safe side)
350 envlist.resize(envlist.size()+2);
351 envlist[pos++] = 0;
352 envlist[pos++] = 0;
326 memcpy(envlist.data()+pos, &nul, sizeof(wchar_t));
327 pos += sizeof(wchar_t);
353328 }
329 // add the 2 terminating 0 (actually 4, just to be on the safe side)
330 envlist.resize( envlist.size()+4 );
331 envlist[pos++] = 0;
332 envlist[pos++] = 0;
333 envlist[pos++] = 0;
334 envlist[pos++] = 0;
354335 }
355336 return envlist;
356337}
372372 qDebug(" pass environment : %s", environment.isEmpty() ? "no" : "yes");
373373#endif
374374
375 DWORD dwCreationFlags = 0;
376 if (!(QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based))
377 dwCreationFlags |= CREATE_NO_WINDOW;
375 DWORD dwCreationFlags = CREATE_NO_WINDOW;
378376
379#ifdef UNICODE
380 if (!(QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based)) {
381377#if defined(Q_OS_WINCE)
382378 QString fullPathProgram = program;
383379 if (!QDir::isAbsolutePath(fullPathProgram))
384380 fullPathProgram = QFileInfo(fullPathProgram).absoluteFilePath();
385381 fullPathProgram.replace(QLatin1Char('/'), QLatin1Char('\\'));
386 success = CreateProcessW((WCHAR*)fullPathProgram.utf16(),
387 (WCHAR*)args.utf16(),
388 0, 0, false, 0, 0, 0, 0, pid);
382 success = CreateProcess((wchar_t*)fullPathProgram.utf16(),
383 (wchar_t*)args.utf16(),
384 0, 0, false, 0, 0, 0, 0, pid);
389385#else
390386 dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;
391387 STARTUPINFOW startupInfo = { sizeof( STARTUPINFO ), 0, 0, 0,
392388 (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
393 (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
394 0, 0, 0,
395 STARTF_USESTDHANDLES,
396 0, 0, 0,
397 stdinChannel.pipe[0], stdoutChannel.pipe[1], stderrChannel.pipe[1]
389 (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
390 0, 0, 0,
391 STARTF_USESTDHANDLES,
392 0, 0, 0,
393 stdinChannel.pipe[0], stdoutChannel.pipe[1], stderrChannel.pipe[1]
398394 };
399 success = CreateProcessW(0, (WCHAR*)args.utf16(),
400 0, 0, TRUE, dwCreationFlags,
401 environment ? envlist.data() : 0,
402 workingDirectory.isEmpty() ? 0
403 : (WCHAR*)QDir::toNativeSeparators(workingDirectory).utf16(),
404 &startupInfo, pid);
405#endif
406 } else
407#endif // UNICODE
408 {
409#ifndef Q_OS_WINCE
410 STARTUPINFOA startupInfo = { sizeof( STARTUPINFOA ), 0, 0, 0,
411 (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
412 (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
413 0, 0, 0,
414 STARTF_USESTDHANDLES,
415 0, 0, 0,
416 stdinChannel.pipe[0], stdoutChannel.pipe[1], stderrChannel.pipe[1]
417 };
395 success = CreateProcess(0, (wchar_t*)args.utf16(),
396 0, 0, TRUE, dwCreationFlags,
397 environment ? envlist.data() : 0,
398 workingDirectory.isEmpty() ? 0
399 : (wchar_t*)QDir::toNativeSeparators(workingDirectory).utf16(),
400 &startupInfo, pid);
418401
419 success = CreateProcessA(0, args.toLocal8Bit().data(),
420 0, 0, TRUE, dwCreationFlags, environment ? envlist.data() : 0,
421 workingDirectory.isEmpty() ? 0
422 : QDir::toNativeSeparators(workingDirectory).toLocal8Bit().data(),
423 &startupInfo, pid);
424#endif // Q_OS_WINCE
425 }
426#ifndef Q_OS_WINCE
427402 if (stdinChannel.pipe[0] != INVALID_Q_PIPE) {
428403 CloseHandle(stdinChannel.pipe[0]);
429404 stdinChannel.pipe[0] = INVALID_Q_PIPE;
438438 }
439439
440440 // give the process a chance to start ...
441 Sleep(SLEEPMIN*2);
441 Sleep(SLEEPMIN * 2);
442442 _q_startupNotification();
443443}
444444
812812
813813 PROCESS_INFORMATION pinfo;
814814
815#ifdef UNICODE
816 if (!(QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based)) {
817815#if defined(Q_OS_WINCE)
818816 QString fullPathProgram = program;
819817 if (!QDir::isAbsolutePath(fullPathProgram))
820818 fullPathProgram.prepend(QDir::currentPath().append(QLatin1Char('/')));
821819 fullPathProgram.replace(QLatin1Char('/'), QLatin1Char('\\'));
822 success = CreateProcessW((WCHAR*)fullPathProgram.utf16(),
823 (WCHAR*)args.utf16(),
824 0, 0, false, CREATE_NEW_CONSOLE, 0, 0, 0, &pinfo);
820 success = CreateProcess((wchar_t*)fullPathProgram.utf16(),
821 (wchar_t*)args.utf16(),
822 0, 0, false, CREATE_NEW_CONSOLE, 0, 0, 0, &pinfo);
825823#else
826824 STARTUPINFOW startupInfo = { sizeof( STARTUPINFO ), 0, 0, 0,
827825 (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
828826 (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
829827 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
830828 };
831 success = CreateProcessW(0, (WCHAR*)args.utf16(),
832 0, 0, FALSE, CREATE_UNICODE_ENVIRONMENT | CREATE_NEW_CONSOLE, 0,
833 workingDir.isEmpty() ? (const WCHAR *)0 : (const WCHAR *)workingDir.utf16(),
834 &startupInfo, &pinfo);
835#endif
836 } else
837#endif // UNICODE
838 {
839#ifndef Q_OS_WINCE
840 STARTUPINFOA startupInfo = { sizeof( STARTUPINFOA ), 0, 0, 0,
841 (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
842 (ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
843 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
844 };
845 success = CreateProcessA(0, args.toLocal8Bit().data(),
846 0, 0, FALSE, CREATE_NEW_CONSOLE, 0,
847 workingDir.isEmpty() ? (LPCSTR)0 : workingDir.toLocal8Bit().constData(),
829 success = CreateProcess(0, (wchar_t*)args.utf16(),
830 0, 0, FALSE, CREATE_UNICODE_ENVIRONMENT | CREATE_NEW_CONSOLE, 0,
831 workingDir.isEmpty() ? 0 : (wchar_t*)workingDir.utf16(),
848832 &startupInfo, &pinfo);
849833#endif // Q_OS_WINCE
850 }
851834
852835 if (success) {
853836 CloseHandle(pinfo.hThread);
  
10371037 // This only happens when bootstrapping qmake.
10381038#ifndef Q_OS_WINCE
10391039 QLibrary library(QLatin1String("shell32"));
1040 QT_WA( {
1041 typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPTSTR, int, BOOL);
1042 GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW");
1043 if (SHGetSpecialFolderPath) {
1044 TCHAR path[MAX_PATH];
1045 SHGetSpecialFolderPath(0, path, type, FALSE);
1046 result = QString::fromUtf16((ushort*)path);
1047 }
1048 } , {
1049 typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, char*, int, BOOL);
1050 GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathA");
1051 if (SHGetSpecialFolderPath) {
1052 char path[MAX_PATH];
1053 SHGetSpecialFolderPath(0, path, type, FALSE);
1054 result = QString::fromLocal8Bit(path);
1055 }
1056 } );
10571040#else
10581041 QLibrary library(QLatin1String("coredll"));
1059 typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPTSTR, int, BOOL);
1060 GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPath");
1042#endif // Q_OS_WINCE
1043 typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL);
1044 GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW");
10611045 if (SHGetSpecialFolderPath) {
10621046 wchar_t path[MAX_PATH];
10631047 SHGetSpecialFolderPath(0, path, type, FALSE);
1064 result = QString::fromUtf16((ushort*)path);
1048 result = QString::fromWCharArray(path);
10651049 }
1066#endif // Q_OS_WINCE
10671050
10681051#endif // QT_NO_QOBJECT
10691052
14421442 QString writeSemName = QLatin1String("QSettingsWriteSem ");
14431443 writeSemName.append(file.fileName());
14441444
1445 QT_WA( {
1446 writeSemaphore = CreateSemaphoreW(0, 1, 1, reinterpret_cast<const wchar_t *>(writeSemName.utf16()));
1447 } , {
1448 writeSemaphore = CreateSemaphoreA(0, 1, 1, writeSemName.toLocal8Bit());
1449 } );
1445 writeSemaphore = CreateSemaphore(0, 1, 1, reinterpret_cast<const wchar_t *>(writeSemName.utf16()));
14501446
14511447 if (writeSemaphore) {
14521448 WaitForSingleObject(writeSemaphore, INFINITE);
14581458 QString readSemName(QLatin1String("QSettingsReadSem "));
14591459 readSemName.append(file.fileName());
14601460
1461 QT_WA( {
1462 readSemaphore = CreateSemaphoreW(0, FileLockSemMax, FileLockSemMax, reinterpret_cast<const wchar_t *>(readSemName.utf16()));
1463 } , {
1464 readSemaphore = CreateSemaphoreA(0, FileLockSemMax, FileLockSemMax, readSemName.toLocal8Bit());
1465 } );
1461 readSemaphore = CreateSemaphore(0, FileLockSemMax, FileLockSemMax, reinterpret_cast<const wchar_t *>(readSemName.utf16()));
14661462
14671463 if (readSemaphore) {
14681464 for (int i = 0; i < numReadLocks; ++i)
  
130130
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 })
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
151140 if (result.endsWith(QLatin1Char('\n')))
152141 result.truncate(result.length() - 1);
153142
147147static HKEY openKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey)
148148{
149149 HKEY resultHandle = 0;
150
151 LONG res;
152 QT_WA( {
153 res = RegOpenKeyExW(parentHandle, reinterpret_cast<const wchar_t *>(rSubKey.utf16()),
150 LONG res = RegOpenKeyEx(parentHandle, reinterpret_cast<const wchar_t *>(rSubKey.utf16()),
154151 0, perms, &resultHandle);
155 } , {
156 res = RegOpenKeyExA(parentHandle, rSubKey.toLocal8Bit(),
157 0, perms, &resultHandle);
158 } );
159152
160153 if (res == ERROR_SUCCESS)
161154 return resultHandle;
165165 return resultHandle;
166166
167167 // try to create it
168 LONG res;
169 QT_WA( {
170 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,
171169 REG_OPTION_NON_VOLATILE, perms, 0, &resultHandle, 0);
172 } , {
173 res = RegCreateKeyExA(parentHandle, rSubKey.toLocal8Bit(), 0, 0,
174 REG_OPTION_NON_VOLATILE, perms, 0, &resultHandle, 0);
175 } );
176170
177171 if (res == ERROR_SUCCESS)
178172 return resultHandle;
201201static QStringList childKeysOrGroups(HKEY parentHandle, QSettingsPrivate::ChildSpec spec)
202202{
203203 QStringList result;
204 LONG res;
205204 DWORD numKeys;
206205 DWORD maxKeySize;
207206 DWORD numSubgroups;
208207 DWORD maxSubgroupSize;
209208
210209 // Find the number of keys and subgroups, as well as the max of their lengths.
211 QT_WA( {
212 res = RegQueryInfoKeyW(parentHandle, 0, 0, 0, &numSubgroups, &maxSubgroupSize, 0,
210 LONG res = RegQueryInfoKey(parentHandle, 0, 0, 0, &numSubgroups, &maxSubgroupSize, 0,
213211 &numKeys, &maxKeySize, 0, 0, 0);
214 }, {
215 res = RegQueryInfoKeyA(parentHandle, 0, 0, 0, &numSubgroups, &maxSubgroupSize, 0,
216 &numKeys, &maxKeySize, 0, 0, 0);
217 } );
218212
219213 if (res != ERROR_SUCCESS) {
220214 qWarning("QSettings: RegQueryInfoKey() failed: %s", errorCodeToString(res).toLatin1().data());
228228 m = maxSubgroupSize;
229229 }
230230
231 /* Windows NT/2000/XP: The size does not include the terminating null character.
232 Windows Me/98/95: The size includes the terminating null character. */
231 /* The size does not include the terminating null character. */
233232 ++m;
234233
235234 // Get the list
236 QByteArray buff(m*sizeof(ushort), 0);
235 QByteArray buff(m * sizeof(wchar_t), 0);
237236 for (int i = 0; i < n; ++i) {
238237 QString item;
239 QT_WA( {
240 DWORD l = buff.size() / sizeof(ushort);
241 if (spec == QSettingsPrivate::ChildKeys) {
242 res = RegEnumValueW(parentHandle, i,
243 reinterpret_cast<wchar_t *>(buff.data()),
244 &l, 0, 0, 0, 0);
245 } else {
246 res = RegEnumKeyExW(parentHandle, i,
247 reinterpret_cast<wchar_t *>(buff.data()),
248 &l, 0, 0, 0, 0);
249 }
250 if (res == ERROR_SUCCESS)
251 item = QString::fromUtf16(reinterpret_cast<ushort*>(buff.data()), l);
252 }, {
253 DWORD l = buff.size();
254 if (spec == QSettingsPrivate::ChildKeys)
255 res = RegEnumValueA(parentHandle, i, buff.data(), &l, 0, 0, 0, 0);
256 else
257 res = RegEnumKeyExA(parentHandle, i, buff.data(), &l, 0, 0, 0, 0);
258 if (res == ERROR_SUCCESS)
259 item = QString::fromLocal8Bit(buff.data(), l);
260 } );
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);
261246
262247 if (res != ERROR_SUCCESS) {
263248 qWarning("QSettings: RegEnumValue failed: %s", errorCodeToString(res).toLatin1().data());
297297 RegCloseKey(childGroupHandle);
298298
299299 // delete group itself
300 LONG res;
301 QT_WA( {
302 res = RegDeleteKeyW(parentHandle, reinterpret_cast<const wchar_t *>(group.utf16()));
303 }, {
304 res = RegDeleteKeyA(parentHandle, group.toLocal8Bit());
305 } );
300 LONG res = RegDeleteKey(parentHandle, reinterpret_cast<const wchar_t *>(group.utf16()));
306301 if (res != ERROR_SUCCESS) {
307302 qWarning("QSettings: RegDeleteKey failed on subkey \"%s\": %s",
308303 group.toLatin1().data(), errorCodeToString(res).toLatin1().data());
469469 // get the size and type of the value
470470 DWORD dataType;
471471 DWORD dataSize;
472 LONG res;
473 QT_WA( {
474 res = RegQueryValueExW(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, &dataType, 0, &dataSize);
475 }, {
476 res = RegQueryValueExA(handle, rSubkeyName.toLocal8Bit(), 0, &dataType, 0, &dataSize);
477 } );
472 LONG res = RegQueryValueEx(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, &dataType, 0, &dataSize);
478473 if (res != ERROR_SUCCESS) {
479474 RegCloseKey(handle);
480475 return false;
477477
478478 // get the value
479479 QByteArray data(dataSize, 0);
480 QT_WA( {
481 res = RegQueryValueExW(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, 0,
482 reinterpret_cast<unsigned char*>(data.data()), &dataSize);
483 }, {
484 res = RegQueryValueExA(handle, rSubkeyName.toLocal8Bit(), 0, 0,
485 reinterpret_cast<unsigned char*>(data.data()), &dataSize);
486 } );
480 res = RegQueryValueEx(handle, reinterpret_cast<const wchar_t *>(rSubkeyName.utf16()), 0, 0,
481 reinterpret_cast<unsigned char*>(data.data()), &dataSize);
487482 if (res != ERROR_SUCCESS) {
488483 RegCloseKey(handle);
489484 return false;
489489 case REG_SZ: {
490490 QString s;
491491 if (dataSize) {
492 QT_WA( {
493 s = QString::fromUtf16(((const ushort*)data.constData()));
494 }, {
495 s = QString::fromLocal8Bit(data.constData());
496 } );
492 s = QString::fromWCharArray(((const wchar_t *)data.constData()));
497493 }
498494 if (value != 0)
499495 *value = stringToVariant(s);
501501 if (dataSize) {
502502 int i = 0;
503503 for (;;) {
504 QString s;
505 QT_WA( {
506 s = QString::fromUtf16((const ushort*)data.constData() + i);
507 }, {
508 s = QString::fromLocal8Bit(data.constData() + i);
509 } );
504 QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i);
510505 i += s.length() + 1;
511506
512507 if (s.isEmpty())
518518 case REG_BINARY: {
519519 QString s;
520520 if (dataSize) {
521 QT_WA( {
522 s = QString::fromUtf16((const ushort*)data.constData(), data.size()/2);
523 }, {
524 s = QString::fromLocal8Bit(data.constData(), data.size());
525 } );
521 s = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2);
526522 }
527523 if (value != 0)
528524 *value = stringToVariant(s);
562562#if defined(Q_OS_WINCE)
563563 remove(regList.at(0).key());
564564#else
565 DWORD res;
566565 QString emptyKey;
567 QT_WA( {
568 res = RegDeleteKeyW(writeHandle(), reinterpret_cast<const wchar_t *>(emptyKey.utf16()));
569 }, {
570 res = RegDeleteKeyA(writeHandle(), emptyKey.toLocal8Bit());
571 } );
566 DWORD res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(emptyKey.utf16()));
572567 if (res != ERROR_SUCCESS) {
573568 qWarning("QSettings: Failed to delete key \"%s\": %s",
574569 regList.at(0).key().toLatin1().data(), errorCodeToString(res).toLatin1().data());
588588 LONG res;
589589 HKEY handle = openKey(writeHandle(), registryPermissions, keyPath(rKey));
590590 if (handle != 0) {
591 QT_WA( {
592 res = RegDeleteValueW(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16()));
593 }, {
594 res = RegDeleteValueA(handle, keyName(rKey).toLocal8Bit());
595 } );
591 res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16()));
596592 RegCloseKey(handle);
597593 }
598594
603603 for (int i = 0; i < childKeys.size(); ++i) {
604604 QString group = childKeys.at(i);
605605
606 LONG res;
607 QT_WA( {
608 res = RegDeleteValueW(handle, reinterpret_cast<const wchar_t *>(group.utf16()));
609 }, {
610 res = RegDeleteValueA(handle, group.toLocal8Bit());
611 } );
606 LONG res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(group.utf16()));
612607 if (res != ERROR_SUCCESS) {
613608 qWarning("QSettings: RegDeleteValue failed on subkey \"%s\": %s",
614609 group.toLatin1().data(), errorCodeToString(res).toLatin1().data());
614614 // For WinCE always Close the handle first.
615615 RegCloseKey(handle);
616616#endif
617 QT_WA( {
618 res = RegDeleteKeyW(writeHandle(), reinterpret_cast<const wchar_t *>(rKey.utf16()));
619 }, {
620 res = RegDeleteKeyA(writeHandle(), rKey.toLocal8Bit());
621 } );
617 res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(rKey.utf16()));
622618
623619 if (res != ERROR_SUCCESS) {
624620 qWarning("QSettings: RegDeleteKey failed on key \"%s\": %s",
670670
671671 if (type == REG_BINARY) {
672672 QString s = variantToString(value);
673 QT_WA( {
674 regValueBuff = QByteArray((const char*)s.utf16(), s.length()*2);
675 }, {
676 regValueBuff = QByteArray((const char*)s.toLocal8Bit(), s.length());
677 } );
673 regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2);
678674 } else {
679675 QStringList::const_iterator it = l.constBegin();
680676 for (; it != l.constEnd(); ++it) {
681677 const QString &s = *it;
682 QT_WA( {
683 regValueBuff += QByteArray((const char*)s.utf16(), (s.length() + 1)*2);
684 }, {
685 regValueBuff += QByteArray((const char*)s.toLocal8Bit(), s.length() + 1);
686 } );
678 regValueBuff += QByteArray((const char*)s.utf16(), (s.length() + 1) * 2);
687679 }
688 QT_WA( {
689 regValueBuff.append((char)0);
690 regValueBuff.append((char)0);
691 }, {
692 regValueBuff.append((char)0);
693 } );
680 regValueBuff.append((char)0);
681 regValueBuff.append((char)0);
694682 }
695683 break;
696684 }
691691 }
692692
693693 case QVariant::ByteArray:
694 // On Win95/98/Me QString::toLocal8Bit() fails to handle chars > 0x7F. So we don't go through variantToString() at all.
695 if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) {
696 QByteArray ba = value.toByteArray();
697 regValueBuff = "@ByteArray(";
698 regValueBuff += ba;
699 regValueBuff += ')';
700 if (ba.contains('\0')) {
701 type = REG_BINARY;
702 } else {
703 type = REG_SZ;
704 regValueBuff += '\0';
705 }
706
707 break;
708 }
709694 // fallthrough intended
710695
711696 default: {
699699 QString s = variantToString(value);
700700 type = stringContainsNullChar(s) ? REG_BINARY : REG_SZ;
701701 if (type == REG_BINARY) {
702 QT_WA( {
703 regValueBuff = QByteArray((const char*)s.utf16(), s.length()*2);
704 }, {
705 regValueBuff = QByteArray((const char*)s.toLocal8Bit(), s.length());
706 } );
702 regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2);
707703 } else {
708 QT_WA( {
709 regValueBuff = QByteArray((const char*)s.utf16(), (s.length() + 1)*2);
710 }, {
711 regValueBuff = QByteArray((const char*)s.toLocal8Bit(), s.length() + 1);
712 } );
704 regValueBuff = QByteArray((const char*)s.utf16(), (s.length() + 1) * 2);
713705 }
714706 break;
715707 }
716708 }
717709
718710 // set the value
719 LONG res;
720 QT_WA( {
721 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,
722712 reinterpret_cast<const unsigned char*>(regValueBuff.constData()),
723713 regValueBuff.size());
724 }, {
725 res = RegSetValueExA(handle, keyName(rKey).toLocal8Bit(), 0, type,
726 reinterpret_cast<const unsigned char*>(regValueBuff.constData()),
727 regValueBuff.size());
728 } );
729714
730715 if (res == ERROR_SUCCESS) {
731716 deleteWriteHandleOnExit = false;
  
17421742 return d->cachedApplicationFilePath;
17431743
17441744#if defined( Q_WS_WIN )
1745 QFileInfo filePath;
1746 QT_WA({
1747 wchar_t module_name[MAX_PATH+1];
1748 GetModuleFileNameW(0, module_name, MAX_PATH);
1749 module_name[MAX_PATH] = 0;
1750 filePath = QString::fromUtf16((ushort *)module_name);
1751 }, {
1752 char module_name[MAX_PATH+1];
1753 GetModuleFileNameA(0, module_name, MAX_PATH);
1754 module_name[MAX_PATH] = 0;
1755 filePath = QString::fromLocal8Bit(module_name);
1756 });
1745 wchar_t module_name[MAX_PATH];
1746 GetModuleFileName(0, module_name, MAX_PATH);
1747 module_name[MAX_PATH] = 0;
1748 QFileInfo filePath = QString::fromWCharArray(module_name);
17571749
17581750 d->cachedApplicationFilePath = filePath.filePath();
17591751 return d->cachedApplicationFilePath;
18941894 return list;
18951895 }
18961896#ifdef Q_OS_WIN
1897 QString cmdline = QT_WA_INLINE(QString::fromUtf16((unsigned short *)GetCommandLineW()), QString::fromLocal8Bit(GetCommandLineA()));
1897 QString cmdline = QString::fromWCharArray(GetCommandLine());
18981898
18991899#if defined(Q_OS_WINCE)
19001900 wchar_t tempFilename[MAX_PATH+1];
1901 if (GetModuleFileNameW(0, tempFilename, MAX_PATH)) {
1901 if (GetModuleFileName(0, tempFilename, MAX_PATH)) {
19021902 tempFilename[MAX_PATH] = 0;
1903 cmdline.prepend(QLatin1Char('\"') + QString::fromUtf16((unsigned short *)tempFilename) + QLatin1String("\" "));
1903 cmdline.prepend(QLatin1Char('\"') + QString::fromWCharArray(tempFilename) + QLatin1String("\" "));
19041904 }
19051905#endif // Q_OS_WINCE
19061906
  
4545#include "qt_windows.h"
4646#include "qvector.h"
4747#include "qmutex.h"
48#include "qfileinfo.h"
4849#include "qcorecmdlineargs_p.h"
4950#include <private/qthread_p.h>
5051#include <ctype.h>
5152
5253QT_BEGIN_NAMESPACE
5354
54char appFileName[MAX_PATH+1]; // application file name
55char theAppName[MAX_PATH+1]; // application name
55char appFileName[MAX_PATH]; // application file name
56char theAppName[MAX_PATH]; // application name
5657HINSTANCE appInst = 0; // handle to app instance
5758HINSTANCE appPrevInst = 0; // handle to prev app instance
5859int appCmdShow = 0;
7474 return appCmdShow;
7575}
7676
77Q_CORE_EXPORT QString qAppFileName() // get application file name
78{
79 wchar_t buffer[MAX_PATH];
80 GetModuleFileName(0, buffer, MAX_PATH);
81 return QString::fromWCharArray(buffer);
82}
7783
7884void set_winapp_name()
7985{
8086 static bool already_set = false;
8187 if (!already_set) {
8288 already_set = true;
83#ifndef Q_OS_WINCE
84 GetModuleFileNameA(0, appFileName, sizeof(appFileName));
85 appFileName[sizeof(appFileName)-1] = 0;
86#else
87 QString afm;
88 afm.resize(sizeof(appFileName));
89 afm.resize(GetModuleFileName(0, (wchar_t *) (afm.unicode()), sizeof(appFileName)));
90 memcpy(appFileName, afm.toLatin1(), sizeof(appFileName));
91#endif
92 const char *p = strrchr(appFileName, '\\'); // skip path
93 if (p)
94 memcpy(theAppName, p+1, qstrlen(p));
95 int l = qstrlen(theAppName);
96 if ((l > 4) && !qstricmp(theAppName + l - 4, ".exe"))
97 theAppName[l-4] = '\0'; // drop .exe extension
9889
99 if (appInst == 0) {
100 QT_WA({
101 appInst = GetModuleHandle(0);
102 }, {
103 appInst = GetModuleHandleA(0);
104 });
105 }
90 QString moduleName = qAppFileName();
91
92 QByteArray filePath = moduleName.toLocal8Bit();
93 QByteArray fileName = QFileInfo(moduleName).baseName().toLocal8Bit();
94
95 memcpy(appFileName, filePath.constData(), filePath.length());
96 memcpy(theAppName, fileName.constData(), fileName.length());
97
98 if (appInst == 0)
99 appInst = GetModuleHandle(0);
106100 }
107101}
108102
109Q_CORE_EXPORT QString qAppFileName() // get application file name
110{
111 return QString::fromLatin1(appFileName);
112}
113
114103QString QCoreApplicationPrivate::appName() const
115104{
116 if (!theAppName[0])
117 set_winapp_name();
118 return QString::fromLatin1(theAppName);
105 return QFileInfo(qAppFileName()).baseName();
119106}
120107
121108class QWinMsgHandlerCriticalSection
133133 str = "(null)";
134134
135135 staticCriticalSection.lock();
136 QT_WA({
137 QString s(QString::fromLocal8Bit(str));
138 s += QLatin1Char('\n');
139 OutputDebugStringW((TCHAR*)s.utf16());
140 }, {
141 QByteArray s(str);
142 s += '\n';
143 OutputDebugStringA(s.data());
144 })
136
137 QString s(QString::fromLocal8Bit(str));
138 s += QLatin1Char('\n');
139 OutputDebugString((wchar_t*)s.utf16());
140
145141 staticCriticalSection.unlock();
146142}
147143
  
135135 QStringList args;
136136
137137 int argc = 0;
138 QVector<ushort*> argv = qWinCmdLine<ushort>((ushort*)cmdLine.utf16(), cmdLine.length(), argc);
138 QVector<wchar_t*> argv = qWinCmdLine<wchar_t>((wchar_t *)cmdLine.utf16(), cmdLine.length(), argc);
139139 for (int a = 0; a < argc; ++a) {
140 args << QString::fromUtf16(argv[a]);
140 args << QString::fromWCharArray(argv[a]);
141141 }
142142
143143 return args;
147147{
148148 Q_UNUSED(argc)
149149 Q_UNUSED(argv)
150 QString cmdLine = QT_WA_INLINE(
151 QString::fromUtf16((unsigned short*)GetCommandLineW()),
152 QString::fromLocal8Bit(GetCommandLineA())
153 );
150 QString cmdLine = QString::fromWCharArray(GetCommandLine());
154151 return qWinCmdArgs(cmdLine);
155152}
156153
  
355355{
356356 resolveTimerAPI();
357357
358 wakeUpNotifier.setHandle(QT_WA_INLINE(CreateEventW(0, FALSE, FALSE, 0),
359 CreateEventA(0, FALSE, FALSE, 0)));
358 wakeUpNotifier.setHandle(CreateEvent(0, FALSE, FALSE, 0));
360359 if (!wakeUpNotifier.handle())
361360 qWarning("QEventDispatcher: Creating QEventDispatcherWin32Private wakeup event failed");
362361}
366366 CloseHandle(wakeUpNotifier.handle());
367367 if (internalHwnd)
368368 DestroyWindow(internalHwnd);
369 QByteArray className = "QEventDispatcherWin32_Internal_Widget" + QByteArray::number(quintptr(qt_internal_proc));
370#if !defined(Q_OS_WINCE)
371 UnregisterClassA(className.constData(), qWinAppInst());
372#else
373 UnregisterClassW(reinterpret_cast<const wchar_t *> (QString::fromLatin1(className.constData()).utf16())
374 , qWinAppInst());
375#endif
369 QString className = QLatin1String("QEventDispatcherWin32_Internal_Widget") + QString::number(quintptr(qt_internal_proc));
370 UnregisterClass((wchar_t*)className.utf16(), qWinAppInst());
376371}
377372
378373void QEventDispatcherWin32Private::activateEventNotifier(QWinEventNotifier * wen)
376376 QCoreApplication::sendEvent(wen, &event);
377377}
378378
379
379// ### Qt 5: remove
380380Q_CORE_EXPORT bool winPeekMessage(MSG* msg, HWND hWnd, UINT wMsgFilterMin,
381381 UINT wMsgFilterMax, UINT wRemoveMsg)
382382{
383 QT_WA({ return PeekMessage(msg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg); } ,
384 { return PeekMessageA(msg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg); });
383 return PeekMessage(msg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
385384}
386385
386// ### Qt 5: remove
387387Q_CORE_EXPORT bool winPostMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
388388{
389 QT_WA({ return PostMessage(hWnd, msg, wParam, lParam); } ,
390 { return PostMessageA(hWnd, msg, wParam, lParam); });
389 return PostMessage(hWnd, msg, wParam, lParam);
391390}
392391
392// ### Qt 5: remove
393Q_CORE_EXPORT bool winGetMessage(MSG* msg, HWND hWnd, UINT wMsgFilterMin,
394 UINT wMsgFilterMax)
395{
396 return GetMessage(msg, hWnd, wMsgFilterMin, wMsgFilterMax);
397}
398
393399// This function is called by a workerthread
394400void WINAPI CALLBACK qt_fast_timer_proc(uint timerId, uint /*reserved*/, DWORD_PTR user, DWORD_PTR /*reserved*/, DWORD_PTR /*reserved*/)
395401{
443443
444444 #ifdef GWLP_USERDATA
445445 QEventDispatcherWin32 *eventDispatcher =
446 (QEventDispatcherWin32 *) GetWindowLongPtrA(hwnd, GWLP_USERDATA);
446 (QEventDispatcherWin32 *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
447447 #else
448448 QEventDispatcherWin32 *eventDispatcher =
449 (QEventDispatcherWin32 *) GetWindowLongA(hwnd, GWL_USERDATA);
449 (QEventDispatcherWin32 *) GetWindowLong(hwnd, GWL_USERDATA);
450450 #endif
451451 if (eventDispatcher) {
452452 QEventDispatcherWin32Private *d = eventDispatcher->d_func();
494494
495495static HWND qt_create_internal_window(const QEventDispatcherWin32 *eventDispatcher)
496496{
497 HINSTANCE hi = qWinAppInst();
498#if defined(Q_OS_WINCE)
497 // make sure that multiple Qt's can coexist in the same process
498 QString className = QLatin1Strign("QEventDispatcherWin32_Internal_Widget") + QString::number(quintptr(qt_internal_proc));
499
499500 WNDCLASS wc;
500#else
501 WNDCLASSA wc;
502#endif
503501 wc.style = 0;
504502 wc.lpfnWndProc = qt_internal_proc;
505503 wc.cbClsExtra = 0;
506504 wc.cbWndExtra = 0;
507 wc.hInstance = hi;
505 wc.hInstance = qWinAppInst();
508506 wc.hIcon = 0;
509507 wc.hCursor = 0;
510508 wc.hbrBackground = 0;
511509 wc.lpszMenuName = NULL;
510 wc.lpszClassName = reinterpret_cast<const wchar_t *> (className.utf16());
512511
513 // make sure that multiple Qt's can coexist in the same process
514 QByteArray className = "QEventDispatcherWin32_Internal_Widget" + QByteArray::number(quintptr(qt_internal_proc));
515#if defined(Q_OS_WINCE)
516 QString tmp = QString::fromLatin1(className.data());
517 wc.lpszClassName = reinterpret_cast<const wchar_t *> (tmp.utf16());
518512 RegisterClass(&wc);
519513 HWND wnd = CreateWindow(wc.lpszClassName, // classname
520 wc.lpszClassName, // window name
521 0, // style
522 0, 0, 0, 0, // geometry
523 0, // parent
524 0, // menu handle
525 hi, // application
526 0); // windows creation data.
527#else
528 wc.lpszClassName = className.constData();
529 RegisterClassA(&wc);
530 HWND wnd = CreateWindowA(wc.lpszClassName, // classname
531 wc.lpszClassName, // window name
532 0, // style
533 0, 0, 0, 0, // geometry
534 0, // parent
535 0, // menu handle
536 hi, // application
537 0); // windows creation data.
538#endif
514 wc.lpszClassName, // window name
515 0, // style
516 0, 0, 0, 0, // geometry
517 0, // parent
518 0, // menu handle
519 qWinAppInst(), // application
520 0); // windows creation data.
539521
540
541522#ifdef GWLP_USERDATA
542 SetWindowLongPtrA(wnd, GWLP_USERDATA, (LONG_PTR)eventDispatcher);
523 SetWindowLongPtr(wnd, GWLP_USERDATA, (LONG_PTR)eventDispatcher);
543524#else
544 SetWindowLongA(wnd, GWL_USERDATA, (LONG)eventDispatcher);
525 SetWindowLong(wnd, GWL_USERDATA, (LONG)eventDispatcher);
545526#endif
546527
547528 if (!wnd) {
671671 haveMessage = true;
672672 msg = d->queuedSocketEvents.takeFirst();
673673 } else {
674 haveMessage = winPeekMessage(&msg, 0, 0, 0, PM_REMOVE);
674 haveMessage = PeekMessage(&msg, 0, 0, 0, PM_REMOVE);
675675 if (haveMessage && (flags & QEventLoop::ExcludeUserInputEvents)
676676 && ((msg.message >= WM_KEYFIRST
677677 && msg.message <= WM_KEYLAST)
719719
720720 if (!filterEvent(&msg)) {
721721 TranslateMessage(&msg);
722 QT_WA({
723 DispatchMessage(&msg);
724 } , {
725 DispatchMessageA(&msg);
726 });
722 DispatchMessage(&msg);
727723 }
728724 } else if (waitRet >= WAIT_OBJECT_0 && waitRet < WAIT_OBJECT_0 + nCount) {
729725 d->activateEventNotifier(d->winEventNotifierList.at(waitRet - WAIT_OBJECT_0));
758758bool QEventDispatcherWin32::hasPendingEvents()
759759{
760760 MSG msg;
761 return qGlobalPostedEventsCount() || winPeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
761 return qGlobalPostedEventsCount() || PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
762762}
763763
764764void QEventDispatcherWin32::registerSocketNotifier(QSocketNotifier *notifier)
  
108108 return 1;
109109}
110110
111int qt_wince__waccess( const WCHAR *path, int pmode )
111int qt_wince__waccess( const wchar_t *path, int pmode )
112112{
113113 DWORD res = GetFileAttributes( path );
114114 if ( 0xFFFFFFFF == res )
118118 return -1;
119119
120120 if ( (pmode & X_OK) && !(res & FILE_ATTRIBUTE_DIRECTORY) ) {
121 QString file = QString::fromUtf16(reinterpret_cast<const ushort *> (path));
121 QString file = QString::fromWCharArray(path);
122122 if ( !(file.endsWith(QString::fromLatin1(".exe")) ||
123123 file.endsWith(QString::fromLatin1(".com"))) )
124124 return -1;
130130int qt_wince_open( const char *filename, int oflag, int pmode )
131131{
132132 QString fn( QString::fromLatin1(filename) );
133 return _wopen( (WCHAR*)fn.utf16(), oflag, pmode );
133 return _wopen( (wchar_t*)fn.utf16(), oflag, pmode );
134134}
135135
136int qt_wince__wopen( const WCHAR *filename, int oflag, int /*pmode*/ )
136int qt_wince__wopen( const wchar_t *filename, int oflag, int /*pmode*/ )
137137{
138 WCHAR *flag;
138 wchar_t *flag;
139139
140140 if ( oflag & _O_APPEND ) {
141141 if ( oflag & _O_WRONLY ) {
290290 return _wchmod( reinterpret_cast<const wchar_t *> (QString::fromLatin1(file).utf16()), mode);
291291}
292292
293bool qt_wince__wchmod(const WCHAR *file, int mode)
293bool qt_wince__wchmod(const wchar_t *file, int mode)
294294{
295295 // ### Does not work properly, what about just adding one property?
296296 if(mode&_S_IWRITE) {
  
175175extern int errno;
176176
177177int qt_wince__getdrive( void );
178int qt_wince__waccess( const WCHAR *path, int pmode );
179int qt_wince__wopen( const WCHAR *filename, int oflag, int pmode );
178int qt_wince__waccess( const wchar_t *path, int pmode );
179int qt_wince__wopen( const wchar_t *filename, int oflag, int pmode );
180180long qt_wince__lseek( int handle, long offset, int origin );
181181int qt_wince__read( int handle, void *buffer, unsigned int count );
182182int qt_wince__write( int handle, const void *buffer, unsigned int count );
204204#endif
205205
206206bool qt_wince__chmod(const char *file, int mode);
207bool qt_wince__wchmod(const WCHAR *file, int mode);
207bool qt_wince__wchmod(const wchar_t *file, int mode);
208208
209209#pragma warning(disable: 4273)
210210HANDLE qt_wince_CreateFileA(LPCSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
  
106106 return false;
107107 }
108108#ifndef Q_OS_WINCE
109 QT_WA({
110 hand = OpenFileMappingW(FILE_MAP_ALL_ACCESS, false, (TCHAR*)safeKey.utf16());
111 }, {
112 hand = OpenFileMappingA(FILE_MAP_ALL_ACCESS, false, safeKey.toLocal8Bit().constData());
113 });
109 hand = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, (wchar_t*)safeKey.utf16());
114110#else
115111 // This works for opening a mapping too, but always opens it with read/write access in
116112 // attach as it seems.
117 hand = CreateFileMappingW(INVALID_HANDLE_VALUE,
118 0, PAGE_READWRITE, 0, 0, (TCHAR*)safeKey.utf16());
113 hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 0, (wchar_t*)safeKey.utf16());
119114#endif
120115 if (!hand) {
121116 setErrorString(function);
143143 }
144144
145145 // Create the file mapping.
146 QT_WA( {
147 hand = CreateFileMappingW(INVALID_HANDLE_VALUE,
148 0, PAGE_READWRITE, 0, size, (TCHAR*)safeKey.utf16());
149 }, {
150 hand = CreateFileMappingA(INVALID_HANDLE_VALUE,
151 0, PAGE_READWRITE, 0, size, safeKey.toLocal8Bit().constData());
152 } );
146 hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, (wchar_t*)safeKey.utf16());
153147 setErrorString(function);
154148
155149 // hand is valid when it already exists unlike unix so explicitly check
  
8787 // Create it if it doesn't already exists.
8888 if (semaphore == 0) {
8989 QString safeName = makeKeyFileName();
90 QT_WA({
91 semaphore = CreateSemaphoreW(0, initialValue, MAXLONG, (TCHAR*)safeName.utf16());
92 }, {
93 semaphore = CreateSemaphoreA(0, initialValue, MAXLONG, safeName.toLocal8Bit().constData());
94 });
90 semaphore = CreateSemaphore(0, initialValue, MAXLONG, (wchar_t*)safeName.utf16());
9591 if (semaphore == NULL)
9692 setErrorString(QLatin1String("QSystemSemaphore::handle"));
9793 }
  
103103
104104 Note that QTimer's accuracy depends on the underlying operating
105105 system and hardware. Most platforms support an accuracy of
106 1 millisecond, but Windows 98 supports only 55. If Qt is
107 unable to deliver the requested number of timer clicks, it will
108 silently discard some.
106 1 millisecond. If Qt is unable to deliver the requested number of
107 timer clicks, it will silently discard some.
109108
110109 An alternative to using QTimer is to call QObject::startTimer()
111110 for your object and reimplement the QObject::timerEvent() event
  
623623#endif
624624 if (!pHnd) {
625625#ifdef Q_OS_WIN
626 QT_WA({
627 hTempModule = ::LoadLibraryExW((wchar_t*)QDir::toNativeSeparators(fileName).utf16(), 0, DONT_RESOLVE_DLL_REFERENCES);
628 } , {
629 temporary_load = load_sys();
630 });
626 hTempModule = ::LoadLibraryEx((wchar_t*)QDir::toNativeSeparators(fileName).utf16(), 0, DONT_RESOLVE_DLL_REFERENCES);
631627#else
632628 temporary_load = load_sys();
633629#endif
637637 QtPluginQueryVerificationDataFunction qtPluginQueryVerificationDataFunction = hTempModule
638638 ? (QtPluginQueryVerificationDataFunction)
639639#ifdef Q_OS_WINCE
640 ::GetProcAddressW(hTempModule, L"qt_plugin_query_verification_data")
640 ::GetProcAddress(hTempModule, L"qt_plugin_query_verification_data")
641641#else
642642 ::GetProcAddress(hTempModule, "qt_plugin_query_verification_data")
643643#endif
  
6767
6868 //avoid 'Bad Image' message box
6969 UINT oldmode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
70 QT_WA({
71 pHnd = LoadLibraryW((TCHAR*)QDir::toNativeSeparators(attempt).utf16());
72 } , {
73 pHnd = LoadLibraryA(QFile::encodeName(QDir::toNativeSeparators(attempt)).data());
74 });
75
70 pHnd = LoadLibrary((wchar_t*)QDir::toNativeSeparators(attempt).utf16());
71
7672 if (pluginState != IsAPlugin) {
7773#if defined(Q_OS_WINCE)
7874 if (!pHnd && ::GetLastError() == ERROR_MOD_NOT_FOUND) {
7975 QString secondAttempt = fileName;
80 QT_WA({
81 pHnd = LoadLibraryW((TCHAR*)QDir::toNativeSeparators(secondAttempt).utf16());
82 } , {
83 pHnd = LoadLibraryA(QFile::encodeName(QDir::toNativeSeparators(secondAttempt)).data());
84 });
76 pHnd = LoadLibrary((wchar_t*)QDir::toNativeSeparators(secondAttempt).utf16());
8577 }
8678#endif
8779 if (!pHnd && ::GetLastError() == ERROR_MOD_NOT_FOUND) {
8880 attempt += QLatin1String(".dll");
89 QT_WA({
90 pHnd = LoadLibraryW((TCHAR*)QDir::toNativeSeparators(attempt).utf16());
91 } , {
92 pHnd = LoadLibraryA(QFile::encodeName(QDir::toNativeSeparators(attempt)).data());
93 });
81 pHnd = LoadLibrary((wchar_t*)QDir::toNativeSeparators(attempt).utf16());
9482 }
9583 }
9684
8888 }
8989 if (pHnd) {
9090 errorString.clear();
91 QT_WA({
92 TCHAR buffer[MAX_PATH + 1];
93 ::GetModuleFileNameW(pHnd, buffer, MAX_PATH);
94 attempt = QString::fromUtf16(reinterpret_cast<const ushort *>(&buffer));
95 }, {
96 char buffer[MAX_PATH + 1];
97 ::GetModuleFileNameA(pHnd, buffer, MAX_PATH);
98 attempt = QString::fromLocal8Bit(buffer);
99 });
91
92 wchar_t buffer[MAX_PATH];
93 ::GetModuleFileName(pHnd, buffer, MAX_PATH);
94 attempt = QString::fromWCharArray(buffer);
95
10096 const QDir dir = QFileInfo(fileName).dir();
10197 const QString realfilename = attempt.mid(attempt.lastIndexOf(QLatin1Char('\\')) + 1);
10298 if (dir.path() == QLatin1String("."))
  
5050QMutexPrivate::QMutexPrivate(QMutex::RecursionMode mode)
5151 : recursive(mode == QMutex::Recursive), contenders(0), lastSpinCount(0), owner(0), count(0)
5252{
53 if (QSysInfo::WindowsVersion == 0) {
54 // mutex was created before initializing WindowsVersion. this
55 // can happen when creating the resource file engine handler,
56 // for example. try again with just the A version
57#ifdef Q_OS_WINCE
58 event = CreateEventW(0, FALSE, FALSE, 0);
59#else
60 event = CreateEventA(0, FALSE, FALSE, 0);
61#endif
62 } else {
63 event = QT_WA_INLINE(CreateEventW(0, FALSE, FALSE, 0),
64 CreateEventA(0, FALSE, FALSE, 0));
65 }
53 event = CreateEvent(0, FALSE, FALSE, 0);
6654 if (!event)
6755 qWarning("QMutexPrivate::QMutexPrivate: Cannot create event");
6856}
  
163163 // Start watcher thread if it is not already running.
164164 if (qt_adopted_thread_watcher_handle == 0) {
165165 if (qt_adopted_thread_wakeup == 0) {
166 qt_adopted_thread_wakeup = QT_WA_INLINE(CreateEventW(0, false, false, 0),
167 CreateEventA(0, false, false, 0));
166 qt_adopted_thread_wakeup = CreateEvent(0, false, false, 0);
168167 qt_adopted_thread_handles.prepend(qt_adopted_thread_wakeup);
169168 }
170169
363363void QThread::yieldCurrentThread()
364364{
365365#ifndef Q_OS_WINCE
366 if (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)
367 SwitchToThread();
368 else
366 SwitchToThread();
367#else
368 ::Sleep(0);
369369#endif
370 ::Sleep(0);
371370}
372371
373372void QThread::sleep(unsigned long secs)
417417 return;
418418 }
419419
420 // Since Win 9x will have problems if the priority is idle or time critical
421 // we have to use the closest one instead
422420 int prio;
423421 d->priority = priority;
424422 switch (d->priority) {
425423 case IdlePriority:
426 if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) {
427 prio = THREAD_PRIORITY_LOWEST;
428 } else {
429 prio = THREAD_PRIORITY_IDLE;
430 }
424 prio = THREAD_PRIORITY_IDLE;
431425 break;
432426
433427 case LowestPriority:
445445 break;
446446
447447 case TimeCriticalPriority:
448 if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) {
449 prio = THREAD_PRIORITY_HIGHEST;
450 } else {
451 prio = THREAD_PRIORITY_TIME_CRITICAL;
452 }
448 prio = THREAD_PRIORITY_TIME_CRITICAL;
453449 break;
454450
455451 case InheritPriority:
551551
552552 // copied from start() with a few modifications:
553553
554 // Since Win 9x will have problems if the priority is idle or time critical
555 // we have to use the closest one instead
556554 int prio;
557555 d->priority = priority;
558556 switch (d->priority) {
559557 case IdlePriority:
560 if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) {
561 prio = THREAD_PRIORITY_LOWEST;
562 } else {
563 prio = THREAD_PRIORITY_IDLE;
564 }
558 prio = THREAD_PRIORITY_IDLE;
565559 break;
566560
567561 case LowestPriority:
579579 break;
580580
581581 case TimeCriticalPriority:
582 if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) {
583 prio = THREAD_PRIORITY_HIGHEST;
584 } else {
585 prio = THREAD_PRIORITY_TIME_CRITICAL;
586 }
582 prio = THREAD_PRIORITY_TIME_CRITICAL;
587583 break;
588584
589585 case InheritPriority:
  
6464public:
6565 inline QWaitConditionEvent() : priority(0), wokenUp(false)
6666 {
67 QT_WA ({
68 event = CreateEvent(NULL, TRUE, FALSE, NULL);
69 }, {
70 event = CreateEventA(NULL, TRUE, FALSE, NULL);
71 });
67 event = CreateEvent(NULL, TRUE, FALSE, NULL);
7268 }
7369 inline ~QWaitConditionEvent() { CloseHandle(event); }
7470 int priority;
  
25032503 buf += QLatin1Char(' ');
25042504 buf += QString::number(d->date.day());
25052505#else
2506 QString winstr;
2507 QT_WA({
2508 TCHAR out[255];
2509 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILDATE, out, 255);
2510 winstr = QString::fromUtf16((ushort*)out);
2511 } , {
2512 char out[255];
2513 GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_ILDATE, (char*)&out, 255);
2514 winstr = QString::fromLocal8Bit(out);
2515 });
2506 wchar_t out[255];
2507 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILDATE, out, 255);
2508 QString winstr = QString::fromWCharArray(out);
25162509 switch (winstr.toInt()) {
25172510 case 1:
25182511 buf = d->date.shortDayName(d->date.dayOfWeek());
  
386386
387387static QString getWinLocaleInfo(LCTYPE type)
388388{
389 int cnt = 0;
390
391389 LCID id = GetUserDefaultLCID();
390 int cnt = GetLocaleInfo(id, type, 0, 0) * 2;
392391
393 QT_WA({
394 cnt = GetLocaleInfoW(id, type, 0, 0)*2;
395 } , {
396 cnt = GetLocaleInfoA(id, type, 0, 0);
397 });
398
399392 if (cnt == 0) {
400393 qWarning("QLocale: empty windows locale info (%d)", (int)type);
401394 return QString();
396396
397397 QByteArray buff(cnt, 0);
398398
399 QT_WA({
400 cnt = GetLocaleInfoW(id, type,
401 reinterpret_cast<wchar_t*>(buff.data()),
402 buff.size()/2);
403 } , {
404 cnt = GetLocaleInfoA(id, type,
405 buff.data(), buff.size());
406 });
399 cnt = GetLocaleInfo(id, type, reinterpret_cast<wchar_t*>(buff.data()), buff.size() / 2);
407400
408401 if (cnt == 0) {
409402 qWarning("QLocale: empty windows locale info (%d)", (int)type);
410403 return QString();
411404 }
412405
413 QString result;
414 QT_WA({
415 result = QString::fromUtf16(reinterpret_cast<ushort*>(buff.data()));
416 } , {
417 result = QString::fromLocal8Bit(buff.data());
418 });
419 return result;
406 return QString::fromWCharArray(reinterpret_cast<const wchar_t *>(buff.data()));
420407}
421408
422409QByteArray getWinLocaleName(LCID id = LOCALE_USER_DEFAULT)
425425 }
426426 }
427427
428 if (QSysInfo::WindowsVersion == QSysInfo::WV_95
429 || (QSysInfo::WindowsVersion & QSysInfo::WV_CE_based)) {
430 result = winLangCodeToIsoName(id != LOCALE_USER_DEFAULT ? id : GetUserDefaultLCID());
431 } else {
432 if (id == LOCALE_USER_DEFAULT)
433 id = GetUserDefaultLCID();
434 QString resultuage = winIso639LangName(id);
435 QString country = winIso3116CtryName(id);
436 result = resultuage.toLatin1();
437 if (!country.isEmpty()) {
438 result += '_';
439 result += country.toLatin1();
440 }
428#if defined(Q_OS_WINCE)
429 result = winLangCodeToIsoName(id != LOCALE_USER_DEFAULT ? id : GetUserDefaultLCID());
430#else
431 if (id == LOCALE_USER_DEFAULT)
432 id = GetUserDefaultLCID();
433 QString resultuage = winIso639LangName(id);
434 QString country = winIso3116CtryName(id);
435 result = resultuage.toLatin1();
436 if (!country.isEmpty()) {
437 result += '_';
438 result += country.toLatin1();
441439 }
440#endif
442441
443442 return result;
444443}
523523
524524 LCID id = GetUserDefaultLCID();
525525
526 QT_WA({
527 TCHAR buf[255];
528 if (GetDateFormatW(id, flags, &st, 0, buf, 255))
529 return QString::fromUtf16((ushort*)buf);
530 } , {
531 char buf[255];
532 if (GetDateFormatA(id, flags, &st, 0, (char*)&buf, 255))
533 return QString::fromLocal8Bit(buf);
534 });
526 wchar_t buf[255];
527 if (GetDateFormat(id, flags, &st, 0, buf, 255))
528 return QString::fromWCharArray(buf);
535529
536530 return QString();
537531}
542542 DWORD flags = 0;
543543 LCID id = GetUserDefaultLCID();
544544
545 QT_WA({
546 TCHAR buf[255];
547 if (GetTimeFormatW(id, flags, &st, 0, buf, 255))
548 return QString::fromUtf16((ushort*)buf);
549 } , {
550 char buf[255];
551 if (GetTimeFormatA(id, flags, &st, 0, (char*)&buf, 255))
552 return QString::fromLocal8Bit(buf);
553 });
545 wchar_t buf[255];
546 if (GetTimeFormat(id, flags, &st, 0, buf, 255))
547 return QString::fromWCharArray(buf);
554548
555549 return QString();
556550}
593593static QLocale::MeasurementSystem winSystemMeasurementSystem()
594594{
595595 LCID id = GetUserDefaultLCID();
596 TCHAR output[2];
596 wchar_t output[2];
597597
598598 if (GetLocaleInfo(id, LOCALE_IMEASURE, output, 2)) {
599 QString iMeasure = QT_WA_INLINE(
600 QString::fromUtf16(reinterpret_cast<ushort*>(output)),
601 QString::fromLocal8Bit(reinterpret_cast<char*>(output)));
599 QString iMeasure = QString::fromWCharArray(output);
602600 if (iMeasure == QLatin1String("1")) {
603601 return QLocale::ImperialSystem;
604602 }
608608static QString winSystemAMText()
609609{
610610 LCID id = GetUserDefaultLCID();
611 TCHAR output[15]; // maximum length including terminating zero character for Win2003+
611 wchar_t output[15]; // maximum length including terminating zero character for Win2003+
612612
613613 if (GetLocaleInfo(id, LOCALE_S1159, output, 15)) {
614 return QT_WA_INLINE(
615 QString::fromUtf16(reinterpret_cast<ushort*>(output)),
616 QString::fromLocal8Bit(reinterpret_cast<char*>(output)));
614 return QString::fromWCharArray(output);
617615 }
618616
619617 return QString();
620620static QString winSystemPMText()
621621{
622622 LCID id = GetUserDefaultLCID();
623 TCHAR output[15]; // maximum length including terminating zero character for Win2003+
623 wchar_t output[15]; // maximum length including terminating zero character for Win2003+
624624
625625 if (GetLocaleInfo(id, LOCALE_S2359, output, 15)) {
626 return QT_WA_INLINE(
627 QString::fromUtf16(reinterpret_cast<ushort*>(output)),
628 QString::fromLocal8Bit(reinterpret_cast<char*>(output)));
626 return QString::fromWCharArray(output);
629627 }
630628
631629 return QString();
727727 return QVariant();
728728}
729729
730/* Win95 doesn't have a function to return the ISO lang/country name of the user's locale.
731 Instead it can return a "Windows code". This maps windows codes to ISO country names. */
732
733730struct WindowsToISOListElt {
734731 ushort windows_code;
735732 char iso_name[6];
882882 // Windows returns the wrong ISO639 for some languages, we need to detect them here using
883883 // the language code
884884 QString lang_code;
885 QT_WA({
886 TCHAR out[256];
887 if (GetLocaleInfoW(id, LOCALE_ILANGUAGE, out, 255))
888 lang_code = QString::fromUtf16((ushort*)out);
889 } , {
890 char out[256];
891 if (GetLocaleInfoA(id, LOCALE_ILANGUAGE, out, 255))
892 lang_code = QString::fromLocal8Bit(out);
893 });
885 wchar_t out[256];
886 if (GetLocaleInfo(id, LOCALE_ILANGUAGE, out, 255))
887 lang_code = QString::fromWCharArray(out);
894888
895889 if (!lang_code.isEmpty()) {
896890 const char *endptr;
906906 return result;
907907
908908 // not one of the problematic languages - do the usual lookup
909 QT_WA({
910 TCHAR out[256];
911 if (GetLocaleInfoW(id, LOCALE_SISO639LANGNAME , out, 255))
912 result = QString::fromUtf16((ushort*)out);
913 } , {
914 char out[256];
915 if (GetLocaleInfoA(id, LOCALE_SISO639LANGNAME, out, 255))
916 result = QString::fromLocal8Bit(out);
917 });
909 if (GetLocaleInfo(id, LOCALE_SISO639LANGNAME , out, 255))
910 result = QString::fromWCharArray(out);
918911
919912 return result;
920913}
916916{
917917 QString result;
918918
919 QT_WA({
920 TCHAR out[256];
921 if (GetLocaleInfoW(id, LOCALE_SISO3166CTRYNAME, out, 255))
922 result = QString::fromUtf16((ushort*)out);
923 } , {
924 char out[256];
925 if (GetLocaleInfoA(id, LOCALE_SISO3166CTRYNAME, out, 255))
926 result = QString::fromLocal8Bit(out);
927 });
919 wchar_t out[256];
920 if (GetLocaleInfo(id, LOCALE_SISO3166CTRYNAME, out, 255))
921 result = QString::fromWCharArray(out);
928922
929923 return result;
930924}
26282628 DWORD res = GetTimeZoneInformation(&info);
26292629 if (res == TIME_ZONE_ID_UNKNOWN)
26302630 return QString();
2631 return QString::fromUtf16(reinterpret_cast<const ushort *> (info.StandardName));
2631 return QString::fromWCharArray(info.StandardName);
26322632#elif defined(Q_OS_WIN)
26332633 _tzset();
26342634# if defined(_MSC_VER) && _MSC_VER >= 1400
  
37143714 BOOL used_def;
37153715 QByteArray mb(4096, 0);
37163716 int len;
3717 while (!(len=WideCharToMultiByte(CP_ACP, 0, (const WCHAR*)ch, uclen,
3717 while (!(len=WideCharToMultiByte(CP_ACP, 0, (const wchar_t*)ch, uclen,
37183718 mb.data(), mb.size()-1, 0, &used_def)))
37193719 {
37203720 int r = GetLastError();
37213721 if (r == ERROR_INSUFFICIENT_BUFFER) {
37223722 mb.resize(1+WideCharToMultiByte(CP_ACP, 0,
3723 (const WCHAR*)ch, uclen,
3723 (const wchar_t*)ch, uclen,
37243724 0, 0, 0, &used_def));
37253725 // and try again...
37263726 } else {
37413741 if (!mb || !mblen)
37423742 return QString();
37433743 const int wclen_auto = 4096;
3744 WCHAR wc_auto[wclen_auto];
3744 wchar_t wc_auto[wclen_auto];
37453745 int wclen = wclen_auto;
3746 WCHAR *wc = wc_auto;
3746 wchar_t *wc = wc_auto;
37473747 int len;
37483748 while (!(len=MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
37493749 mb, mblen, wc, wclen)))
37563756 } else {
37573757 wclen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
37583758 mb, mblen, 0, 0);
3759 wc = new WCHAR[wclen];
3759 wc = new wchar_t[wclen];
37603760 // and try again...
37613761 }
37623762 } else {
37993799 return QString();
38003800 if (size == 0 || (!*str && size < 0))
38013801 return QLatin1String("");
3802#if defined(Q_OS_WIN32)
3803 if(QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) {
3804 return qt_winMB2QString(str, size);
3805 }
3806#endif
38073802#if !defined(QT_NO_TEXTCODEC)
38083803 if (size < 0)
38093804 size = qstrlen(str);
46924692 return ucstrcmp(data1, length1, data2, length2);
46934693
46944694#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
4695 int res;
4696 QT_WA({
4697 const TCHAR* s1 = (TCHAR*)data1;
4698 const TCHAR* s2 = (TCHAR*)data2;
4699 res = CompareStringW(GetUserDefaultLCID(), 0, s1, length1, s2, length2);
4700 } , {
4701 QByteArray s1 = toLocal8Bit_helper(data1, length1);
4702 QByteArray s2 = toLocal8Bit_helper(data2, length2);
4703 res = CompareStringA(GetUserDefaultLCID(), 0, s1.data(), s1.length(), s2.data(), s2.length());
4704 });
4695 int res = CompareString(GetUserDefaultLCID(), 0, (wchar_t*)data1, length1, (wchar_t*)data2, length2);
47054696
47064697 switch (res) {
47074698 case CSTR_LESS_THAN: