[PATCH] remove kcmdwrapper hack

Oswald Buddenhagen ossi at kde.org
Sat Oct 9 13:26:18 CEST 2010


with the introduction of QProcess::setNativeArguments() in Qt 4.7, this
somewhat arcane indirection meant for bypassing QProcess' argument
quoting became obsolete. advantages are a slight performance gain, sane
KProcess::kill() behavior, and less bizarreness in general.
---
 CMakeLists.txt     |   10 -----
 io/kcmdwrapper.cpp |  114 ----------------------------------------------------
 io/kprocess.cpp    |   28 ++++++++-----
 3 files changed, 18 insertions(+), 134 deletions(-)
 delete mode 100644 io/kcmdwrapper.cpp

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6cc0242..5060cb5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -473,16 +473,6 @@ install(TARGETS kde4-config ${INSTALL_TARGETS_DEFAULT_ARGS} )
 
 ########### next target ###############
 
-if (WIN32 AND NOT WINCE)
-    kde4_add_executable(kcmdwrapper NOGUI io/kcmdwrapper.cpp )
-
-    target_link_libraries(kcmdwrapper kernel32 shell32 )
-
-    install(TARGETS kcmdwrapper DESTINATION ${LIBEXEC_INSTALL_DIR} )
-endif (WIN32 AND NOT WINCE)
-
-########### next target ###############
-
 if(NOT WINCE)
     # kjs hash stuff for transcript plugin
     set( CREATE_HASH_TABLE ${CMAKE_SOURCE_DIR}/kjs/create_hash_table )
diff --git a/io/kcmdwrapper.cpp b/io/kcmdwrapper.cpp
deleted file mode 100644
index 4819bb2..0000000
--- a/io/kcmdwrapper.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
-    This file is part of the KDE libraries
-
-    Copyright (c) 2007 Bernhard Loos <nhuh.put at web.de>
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Library General Public
-    License as published by the Free Software Foundation; either
-    version 2 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Library General Public License for more details.
-
-    You should have received a copy of the GNU Library General Public License
-    along with this library; see the file COPYING.LIB.  If not, write to
-    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-    Boston, MA 02110-1301, USA.
-*/
-
-#include <windows.h>
-#include <shellapi.h>
-#include <wchar.h>
-#include <stdio.h>
-
-void errorExit(LPWSTR lpszFunction)
-{
-    WCHAR szBuf[100];
-    LPVOID lpMsgBuf;
-    DWORD dw = GetLastError();
-
-    FormatMessageW(
-        FORMAT_MESSAGE_ALLOCATE_BUFFER |
-        FORMAT_MESSAGE_FROM_SYSTEM,
-        NULL,
-        dw,
-        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-        (LPWSTR) &lpMsgBuf,
-        0, NULL);
-
-    _snwprintf(szBuf, 100,
-        L"kcmdwrapper: %s failed with error %d: %s",
-        lpszFunction, dw, lpMsgBuf);
-
-    OutputDebugStringW(szBuf);
-    LocalFree(lpMsgBuf);
-    ExitProcess(~0U);
-}
-
-void printUsage(void)
-{
-    wprintf(L"A Wrapper for cmd.exe\n\n");
-    wprintf(L"calls shell /S /C argument with proper quoting\n");
-    wprintf(L"Usage: kcmdwrapper shell argument");
-    ExitProcess(~0U);
-}
-
-void printError(const char * p) {}
-#define COMMAND_BUFFER_SIZE 34000
-
-int main(int argc, char **argv)
-{
-    LPWSTR *argList;
-    int nArgs;
-    WCHAR command[COMMAND_BUFFER_SIZE];
-    OSVERSIONINFO vi;
-    STARTUPINFOW si;
-    PROCESS_INFORMATION pi;
-    DWORD exitCode;
-
-    argList = CommandLineToArgvW(GetCommandLineW(), &nArgs);
-
-    if (NULL == argList)
-        errorExit(L"CommandLineToArgvW");
-
-    if (nArgs != 3)
-        printUsage();
-
-    // Instead of checking the OS version we might check the for presence of
-    // the reg keys that enable delayed variable expansion by default - that
-    // would also cover the pathological case of running cmd from win2k under
-    // winNT. OTOH, who cares?
-    GetVersionEx(&vi);
-    _snwprintf(command, COMMAND_BUFFER_SIZE,
-        (vi.dwMajorVersion >= 5 /* Win2k */) ?
-            L"/V:OFF /S /C \"%s\"" : L"/S /C \"%s\"",
-        argList[2]);
-
-
-    ZeroMemory( &si, sizeof(si) );
-    si.cb = sizeof(si);
-    ZeroMemory( &pi, sizeof(pi) );
-
-
-    if (CreateProcessW(argList[1], command, NULL, NULL, true, 0, NULL, NULL, &si, &pi) == 0)
-        errorExit(L"CreateProcessW");
-
-    CloseHandle(GetStdHandle(STD_INPUT_HANDLE));
-    CloseHandle(GetStdHandle(STD_ERROR_HANDLE));
-    CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE));
-
-    if (WaitForSingleObject(pi.hProcess, INFINITE) == WAIT_FAILED)
-        errorExit(L"WaitForSingleObject");
-
-    if (!GetExitCodeProcess(pi.hProcess, &exitCode))
-        errorExit(L"WaitForSingleObject");
-
-    if (exitCode == STILL_ACTIVE )
-        OutputDebugStringW(L"cmdwrapper: STILL_ACTIVE returned");
-
-    return exitCode;
-}
-
diff --git a/io/kprocess.cpp b/io/kprocess.cpp
index 42873a9..ca73dac 100644
--- a/io/kprocess.cpp
+++ b/io/kprocess.cpp
@@ -212,6 +212,9 @@ void KProcess::setProgram(const QString &exe, const QStringList &args)
 
     d->prog = exe;
     d->args = args;
+#ifdef Q_OS_WIN
+    setNativeArguments(QString());
+#endif
 }
 
 void KProcess::setProgram(const QStringList &argv)
@@ -221,6 +224,9 @@ void KProcess::setProgram(const QStringList &argv)
     Q_ASSERT( !argv.isEmpty() );
     d->args = argv;
     d->prog = d->args.takeFirst();
+#ifdef Q_OS_WIN
+    setNativeArguments(QString());
+#endif
 }
 
 KProcess &KProcess::operator<<(const QString &arg)
@@ -251,6 +257,9 @@ void KProcess::clearProgram()
 
     d->prog.clear();
     d->args.clear();
+#ifdef Q_OS_WIN
+    setNativeArguments(QString());
+#endif
 }
 
 void KProcess::setShellCommand(const QString &cmd)
@@ -264,6 +273,9 @@ void KProcess::setShellCommand(const QString &cmd)
         d->prog = KStandardDirs::findExe(d->args[0]);
         if (!d->prog.isEmpty()) {
             d->args.removeFirst();
+#ifdef Q_OS_WIN
+            setNativeArguments(QString());
+#endif
             return;
         }
     }
@@ -303,19 +315,15 @@ void KProcess::setShellCommand(const QString &cmd)
     // KShell::joinArgs() may generate these for security reasons.
     setEnv(PERCENT_VARIABLE, "%");
 
-    //see also TrollTechTaskTracker entry 88373.
-    d->prog = KStandardDirs::findExe("kcmdwrapper");
-
 #ifndef _WIN32_WCE
-    UINT size;
     WCHAR sysdir[MAX_PATH + 1];
-    size = GetSystemDirectoryW(sysdir, MAX_PATH + 1);
-    QString cmdexe = QString::fromUtf16((const ushort *) sysdir, size);
-    cmdexe.append("\\cmd.exe");
-
-    d->args << cmdexe << cmd;
+    UINT size = GetSystemDirectoryW(sysdir, MAX_PATH + 1);
+    d->prog = QString::fromUtf16((const ushort *) sysdir, size);
+    d->prog += "\\cmd.exe";
+    setNativeArguments("/V:OFF /S /C \"" + cmd + '"');
 #else
-    d->args << "\\windows\\cmd.exe" << cmd;
+    d->prog = "\\windows\\cmd.exe";
+    setNativeArguments("/S /C \"" + cmd + '"');
 #endif
 #endif
 }
-- 
1.7.3.2.g9027fa


--pWyiEgJYm5f9v55/--


More information about the Kde-windows mailing list