Commit c07cd44 1 parent ccc91e2 commit c07cd44 Copy full SHA for c07cd44
File tree 1 file changed +25
-2
lines changed
1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change 31
31
32
32
#include < algorithm>
33
33
34
+ #ifdef Q_OS_WIN
35
+ #include < memory>
36
+ #endif
37
+
34
38
#include < QAtomicInt>
35
39
#include < QDebug>
36
40
#include < QFileInfo>
77
81
#include < iostream>
78
82
#endif // DISABLE_GUI
79
83
84
+ #ifdef Q_OS_WIN
85
+ #include < Shellapi.h>
86
+ #endif
87
+
80
88
#ifndef DISABLE_WEBUI
81
89
#include " webui/webui.h"
82
90
#endif
@@ -275,7 +283,7 @@ void Application::processMessage(const QString &message)
275
283
276
284
void Application::runExternalProgram (const BitTorrent::TorrentHandle *torrent) const
277
285
{
278
- QString program = Preferences::instance ()->getAutoRunProgram ();
286
+ QString program = Preferences::instance ()->getAutoRunProgram (). trimmed () ;
279
287
program.replace (" %N" , torrent->name ());
280
288
program.replace (" %L" , torrent->category ());
281
289
@@ -297,7 +305,22 @@ void Application::runExternalProgram(const BitTorrent::TorrentHandle *torrent) c
297
305
#if defined(Q_OS_UNIX)
298
306
QProcess::startDetached (QLatin1String (" /bin/sh" ), {QLatin1String (" -c" ), program});
299
307
#else
300
- QProcess::startDetached (program);
308
+ std::unique_ptr<wchar_t []> programWchar (new wchar_t [program.length () + 1 ] {});
309
+ program.toWCharArray (programWchar.get ());
310
+
311
+ // Need to split arguments manually because QProcess::startDetached(QString)
312
+ // will strip off empty parameters.
313
+ // E.g. `python.exe "1" "" "3"` will become `python.exe "1" "3"`
314
+ int argCount = 0 ;
315
+ LPWSTR *args = ::CommandLineToArgvW (programWchar.get (), &argCount);
316
+
317
+ QStringList argList;
318
+ for (int i = 1 ; i < argCount; ++i)
319
+ argList += QString::fromWCharArray (args[i]);
320
+
321
+ QProcess::startDetached (QString::fromWCharArray (args[0 ]), argList);
322
+
323
+ ::LocalFree (args);
301
324
#endif
302
325
}
303
326
You can’t perform that action at this time.
0 commit comments