From f448587271035e636480ae41619718acd213c3ae Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 23 Jul 2016 13:19:26 +0800 Subject: [PATCH 1/2] Add function `windowsSystemPath()` --- src/app/application.cpp | 7 +------ src/base/utils/misc.cpp | 12 ++++++++++++ src/base/utils/misc.h | 6 +++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 2e1a378e2..a2010dffa 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -261,13 +261,8 @@ void Application::runExternalProgram(BitTorrent::TorrentHandle *const torrent) c #if defined(Q_OS_UNIX) QProcess::startDetached(QLatin1String("/bin/sh"), {QLatin1String("-c"), program}); #elif defined(Q_OS_WIN) // test cmd: `echo "%F" > "c:\ab ba.txt"` - static const QString cmdPath = []() -> QString { - WCHAR systemPath[64] = {0}; - GetSystemDirectoryW(systemPath, sizeof(systemPath) / sizeof(WCHAR)); - return QString::fromWCharArray(systemPath) + QLatin1String("\\cmd.exe /C "); - }(); program.prepend(QLatin1String("\"")).append(QLatin1String("\"")); - program.prepend(cmdPath); + program.prepend(Utils::Misc::windowsSystemPath() + QLatin1String("\\cmd.exe /C ")); const uint cmdMaxLength = 32768; // max length (incl. terminate char) for `lpCommandLine` in `CreateProcessW()` if ((program.size() + 1) > cmdMaxLength) { logger->addMessage(tr("Torrent: %1, run external program command too long (length > %2), execution failed.").arg(torrent->name()).arg(cmdMaxLength), Log::CRITICAL); diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index eb37aed40..8b27e02b0 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -696,3 +696,15 @@ QString Utils::Misc::libtorrentVersionString() static const QString ver = LIBTORRENT_VERSION; return ver; } + +#ifdef Q_OS_WIN +QString Utils::Misc::windowsSystemPath() +{ + static const QString path = []() -> QString { + WCHAR systemPath[64] = {0}; + GetSystemDirectoryW(systemPath, sizeof(systemPath) / sizeof(WCHAR)); + return QString::fromWCharArray(systemPath); + }(); + return path; +} +#endif diff --git a/src/base/utils/misc.h b/src/base/utils/misc.h index 947c944f7..d0a1c39bb 100644 --- a/src/base/utils/misc.h +++ b/src/base/utils/misc.h @@ -102,12 +102,16 @@ namespace Utils QList intListfromStringList(const QStringList &l); QList boolListfromStringList(const QStringList &l); + void msleep(unsigned long msecs); + #ifndef DISABLE_GUI void openPath(const QString& absolutePath); void openFolderSelect(const QString& absolutePath); #endif - void msleep(unsigned long msecs); +#ifdef Q_OS_WIN + QString windowsSystemPath(); +#endif } } From a64538b9643cd9f6eb783153b3b4651c6553b6e7 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 23 Jul 2016 13:36:19 +0800 Subject: [PATCH 2/2] Call system msiexec.exe directly --- src/gui/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 23bef83b4..a2e8fc169 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1772,7 +1772,7 @@ void MainWindow::pythonDownloadSuccess(const QString &url, const QString &filePa QProcess installer; qDebug("Launching Python installer in passive mode..."); - installer.start("msiexec.exe /passive /i " + Utils::Fs::toNativePath(filePath) + ".msi"); + installer.start(Utils::Misc::windowsSystemPath() + "\\msiexec.exe /passive /i " + Utils::Fs::toNativePath(filePath) + ".msi"); // Wait for setup to complete installer.waitForFinished();