1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 15:27:54 +00:00

Merge pull request #8915 from Chocobo1/runext4

Improve "Run External Program" behavior
This commit is contained in:
Mike Tzou 2018-05-19 14:58:45 +08:00 committed by GitHub
commit 07c15127ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -290,9 +290,21 @@ void Application::runExternalProgram(const BitTorrent::TorrentHandle *torrent) c
std::sort(tags.begin(), tags.end(), Utils::String::naturalLessThan<Qt::CaseInsensitive>); std::sort(tags.begin(), tags.end(), Utils::String::naturalLessThan<Qt::CaseInsensitive>);
program.replace("%G", tags.join(',')); program.replace("%G", tags.join(','));
#if defined(Q_OS_WIN)
const auto chopPathSep = [](const QString &str) -> QString
{
if (str.endsWith('\\'))
return str.mid(0, (str.length() -1));
return str;
};
program.replace("%F", chopPathSep(Utils::Fs::toNativePath(torrent->contentPath())));
program.replace("%R", chopPathSep(Utils::Fs::toNativePath(torrent->rootPath())));
program.replace("%D", chopPathSep(Utils::Fs::toNativePath(torrent->savePath())));
#else
program.replace("%F", Utils::Fs::toNativePath(torrent->contentPath())); program.replace("%F", Utils::Fs::toNativePath(torrent->contentPath()));
program.replace("%R", Utils::Fs::toNativePath(torrent->rootPath())); program.replace("%R", Utils::Fs::toNativePath(torrent->rootPath()));
program.replace("%D", Utils::Fs::toNativePath(torrent->savePath())); program.replace("%D", Utils::Fs::toNativePath(torrent->savePath()));
#endif
program.replace("%C", QString::number(torrent->filesCount())); program.replace("%C", QString::number(torrent->filesCount()));
program.replace("%Z", QString::number(torrent->totalSize())); program.replace("%Z", QString::number(torrent->totalSize()));
program.replace("%T", torrent->currentTracker()); program.replace("%T", torrent->currentTracker());
@ -301,9 +313,7 @@ void Application::runExternalProgram(const BitTorrent::TorrentHandle *torrent) c
Logger *logger = Logger::instance(); Logger *logger = Logger::instance();
logger->addMessage(tr("Torrent: %1, running external program, command: %2").arg(torrent->name(), program)); logger->addMessage(tr("Torrent: %1, running external program, command: %2").arg(torrent->name(), program));
#if defined(Q_OS_UNIX) #if defined(Q_OS_WIN)
QProcess::startDetached(QLatin1String("/bin/sh"), {QLatin1String("-c"), program});
#else
std::unique_ptr<wchar_t[]> programWchar(new wchar_t[program.length() + 1] {}); std::unique_ptr<wchar_t[]> programWchar(new wchar_t[program.length() + 1] {});
program.toWCharArray(programWchar.get()); program.toWCharArray(programWchar.get());
@ -320,6 +330,8 @@ void Application::runExternalProgram(const BitTorrent::TorrentHandle *torrent) c
QProcess::startDetached(QString::fromWCharArray(args[0]), argList); QProcess::startDetached(QString::fromWCharArray(args[0]), argList);
::LocalFree(args); ::LocalFree(args);
#else
QProcess::startDetached(QLatin1String("/bin/sh"), {QLatin1String("-c"), program});
#endif #endif
} }