26 #include <QtCore/QBool>
27 #include <QtCore/QTextCodec>
34 #include <QtCore/QDir>
35 #include <QtCore/QString>
36 #include <QtCore/QLibrary>
48 #ifndef _USE_OLD_IOSTREAMS
52 #if defined(__MINGW32__)
53 # define WIN32_CAST_CHAR (const WCHAR*)
55 # define WIN32_CAST_CHAR (LPCWSTR)
63 #ifdef KDELIBS_STATIC_LIBS
64 static bool kde4prefixInitialized =
false;
90 Q_ASSERT(pos < MAX_PATH + 1);
100 if (kde4prefixInitialized)
103 QDir kde4prefixDir(QString::fromUtf16((ushort*) STATIC_INSTALL_PATH));
104 if (kde4prefixDir.exists()){
107 kde4prefixInitialized =
true;
115 retval = QDir::fromNativeSeparators(retval);
118 kde4prefixInitialized =
true;
128 #ifndef KDELIBS_STATIC_LIBS
135 BOOL WINAPI
DllMain ( HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpReserved)
137 BOOL WINAPI
DllMain ( HANDLE hinstDLL,DWORD fdwReason,LPVOID lpReserved)
140 switch ( fdwReason ) {
141 case DLL_PROCESS_ATTACH:
146 case DLL_PROCESS_DETACH:
158 if( lpReserved == NULL )
187 if ( subKey.isEmpty() )
194 if ( ERROR_SUCCESS!=RegOpenKeyExW ( key,
WIN32_CAST_CHAR subKey.utf16(), 0, KEY_READ, &hKey ) )
197 if ( ERROR_SUCCESS!=RegQueryValueExW ( hKey,
WIN32_CAST_CHAR item.utf16(), NULL, NULL, NULL, &dwSize ) )
200 lszValue =
new TCHAR[dwSize];
202 if ( ERROR_SUCCESS!=RegQueryValueExW ( hKey,
WIN32_CAST_CHAR item.utf16(), NULL, &dwType, ( LPBYTE ) lszValue, &dwSize ) ) {
206 RegCloseKey ( hKey );
208 QString res = QString::fromUtf16 ( (
const ushort* ) lszValue );
220 QString path_ = QDir::convertSeparators ( QFileInfo ( fileName ).absoluteFilePath() );
223 SHELLEXECUTEINFOW execInfo;
225 SHELLEXECUTEINFO execInfo;
227 memset ( &execInfo,0,
sizeof ( execInfo ) );
228 execInfo.cbSize =
sizeof ( execInfo );
230 execInfo.fMask = SEE_MASK_INVOKEIDLIST | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
232 execInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
234 const QString verb ( QLatin1String (
"properties" ) );
238 return ShellExecuteExW ( &execInfo );
240 return ShellExecuteEx ( &execInfo );
252 QLatin1String(
"Control Panel\\International"),
253 QLatin1String(
"Locale"), &ok );
257 QLatin1String(
"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layout\\DosKeybCodes"),
261 return localeName.toLatin1();
270 QLatin1String(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"),
280 char *buf =
new char[BUFSIZE];
283 strlcpy(buf,
"Debug:",BUFSIZE);
284 strlcat(buf,msg,BUFSIZE);
287 strlcpy(buf,
"Warning:",BUFSIZE);
288 strlcat(buf,msg,BUFSIZE);
291 strlcpy(buf,
"Critical:",BUFSIZE);
292 strlcat(buf,msg,BUFSIZE);
295 strlcpy(buf,
"Fatal:",BUFSIZE);
296 strlcat(buf,msg,BUFSIZE);
300 strlcat(buf,
"\n",BUFSIZE);
301 OutputDebugStringW( (WCHAR*)QString::fromLatin1(buf).utf16());
312 fprintf(stderr,
"Debug: %s\n", msg);
315 fprintf(stderr,
"Warning: %s\n", msg);
318 fprintf(stderr,
"Critical: %s\n", msg);
321 fprintf(stderr,
"Fatal: %s\n", msg);
354 hCrt = _open_osfhandle((intptr_t) GetStdHandle(STD_INPUT_HANDLE),_O_TEXT);
356 hf = _fdopen( hCrt,
"r" );
358 i = setvbuf( stdin, NULL, _IONBF, 0 );
361 hCrt = _open_osfhandle((intptr_t) GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT);
363 hf = _fdopen( hCrt,
"w" );
365 i = setvbuf( stdout, NULL, _IONBF, 0 );
368 hCrt = _open_osfhandle((intptr_t) GetStdHandle(STD_ERROR_HANDLE),_O_TEXT);
370 hf = _fdopen( hCrt,
"w" );
372 i = setvbuf( stderr, NULL, _IONBF, 0 );
376 ios::sync_with_stdio();
385 class debug_streambuf:
public std::streambuf
388 debug_streambuf(
const char *
prefix)
391 index = rindex = strlen(buf);
395 virtual int overflow(
int c = EOF)
399 char cc = traits_type::to_char_type(c);
405 OutputDebugStringW((WCHAR*)QString::fromLatin1(buf).utf16());
409 return traits_type::not_eof(c);
424 return IMAGE_SUBSYSTEM_WINDOWS_CE_GUI;
431 PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)GetModuleHandle(NULL);
432 PIMAGE_NT_HEADERS ntHeader = (PIMAGE_NT_HEADERS) ((
char *)dosHeader + dosHeader->e_lfanew);
433 if (ntHeader->Signature != 0x00004550)
435 subSystem = IMAGE_SUBSYSTEM_UNKNOWN;
438 subSystem = ntHeader->OptionalHeader.Subsystem;
471 static class kMessageOutputInstaller {
473 kMessageOutputInstaller() : stdoutBuffer(
"stdout:"), stderrBuffer(
"stderr:"), oldStdoutBuffer(0), oldStderrBuffer(0)
475 if (
subSystem() == IMAGE_SUBSYSTEM_WINDOWS_CUI) {
486 oldStdoutBuffer = std::cout.rdbuf(&stdoutBuffer);
487 oldStderrBuffer = std::cerr.rdbuf(&stderrBuffer);
490 else if (
subSystem() == IMAGE_SUBSYSTEM_WINDOWS_GUI) {
499 oldStdoutBuffer = std::cout.rdbuf(&stdoutBuffer);
500 oldStderrBuffer = std::cerr.rdbuf(&stderrBuffer);
503 }
else if (
subSystem() == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI) {
506 oldStdoutBuffer = std::cout.rdbuf(&stdoutBuffer);
507 oldStderrBuffer = std::cerr.rdbuf(&stderrBuffer);
510 qWarning(
"unknown subsystem %d detected, could not setup qt message handler",
subSystem());
512 ~kMessageOutputInstaller()
515 std::cout.rdbuf(oldStdoutBuffer);
517 std::cerr.rdbuf(oldStderrBuffer);
521 debug_streambuf stdoutBuffer;
522 debug_streambuf stderrBuffer;
523 std::streambuf* oldStdoutBuffer;
524 std::streambuf* oldStderrBuffer;
531 return ( file.endsWith( QLatin1String(
".exe" ) ) ||
532 file.endsWith( QLatin1String(
".com" ) ) ||
533 file.endsWith( QLatin1String(
".bat" ) ) ||
534 file.endsWith( QLatin1String(
".sln" ) ) ||
535 file.endsWith( QLatin1String(
".lnk" ) ) );