mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-29 22:20:53 +03:00
Option to show console when external program is run
Windows only. Closes #9592
This commit is contained in:
parent
4ae8e176dc
commit
8fa6e372a2
5 changed files with 59 additions and 1 deletions
|
@ -345,8 +345,34 @@ void Application::runExternalProgram(const BitTorrent::TorrentHandle *torrent) c
|
|||
for (int i = 1; i < argCount; ++i)
|
||||
argList += QString::fromWCharArray(args[i]);
|
||||
|
||||
QProcess::startDetached(QString::fromWCharArray(args[0]), argList);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
QProcess proc;
|
||||
proc.setProgram(QString::fromWCharArray(args[0]));
|
||||
proc.setArguments(argList);
|
||||
proc.setCreateProcessArgumentsModifier([](QProcess::CreateProcessArguments *args)
|
||||
{
|
||||
if (Preferences::instance()->isAutoRunConsoleEnabled()) {
|
||||
args->flags |= CREATE_NEW_CONSOLE;
|
||||
args->flags &= ~(CREATE_NO_WINDOW | DETACHED_PROCESS);
|
||||
}
|
||||
else {
|
||||
args->flags |= CREATE_NO_WINDOW;
|
||||
args->flags &= ~(CREATE_NEW_CONSOLE | DETACHED_PROCESS);
|
||||
}
|
||||
args->inheritHandles = false;
|
||||
args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES;
|
||||
::CloseHandle(args->startupInfo->hStdInput);
|
||||
::CloseHandle(args->startupInfo->hStdOutput);
|
||||
::CloseHandle(args->startupInfo->hStdError);
|
||||
args->startupInfo->hStdInput = nullptr;
|
||||
args->startupInfo->hStdOutput = nullptr;
|
||||
args->startupInfo->hStdError = nullptr;
|
||||
});
|
||||
proc.startDetached();
|
||||
#else
|
||||
QProcess::startDetached(QString::fromWCharArray(args[0]), argList);
|
||||
#endif // QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
||||
#else // Q_OS_WIN
|
||||
// Cannot give users shell environment by default, as doing so could
|
||||
// enable command injection via torrent name and other arguments
|
||||
// (especially when some automated download mechanism has been setup).
|
||||
|
|
|
@ -804,6 +804,18 @@ void Preferences::setAutoRunProgram(const QString &program)
|
|||
setValue("AutoRun/program", program);
|
||||
}
|
||||
|
||||
#if defined(Q_OS_WIN) && (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
bool Preferences::isAutoRunConsoleEnabled() const
|
||||
{
|
||||
return value("AutoRun/ConsoleEnabled", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setAutoRunConsoleEnabled(const bool enabled)
|
||||
{
|
||||
setValue("AutoRun/ConsoleEnabled", enabled);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Preferences::shutdownWhenDownloadsComplete() const
|
||||
{
|
||||
return value("Preferences/Downloads/AutoShutDownOnCompletion", false).toBool();
|
||||
|
|
|
@ -238,6 +238,10 @@ public:
|
|||
void setAutoRunEnabled(bool enabled);
|
||||
QString getAutoRunProgram() const;
|
||||
void setAutoRunProgram(const QString &program);
|
||||
#if defined(Q_OS_WIN) && (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
bool isAutoRunConsoleEnabled() const;
|
||||
void setAutoRunConsoleEnabled(bool enabled);
|
||||
#endif
|
||||
bool shutdownWhenDownloadsComplete() const;
|
||||
void setShutdownWhenDownloadsComplete(bool shutdown);
|
||||
bool suspendWhenDownloadsComplete() const;
|
||||
|
|
|
@ -295,6 +295,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
|
|||
connect(m_ui->mailNotifPassword, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
|
||||
connect(m_ui->autoRunBox, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
|
||||
connect(m_ui->lineEditAutoRun, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
|
||||
connect(m_ui->autoRunConsole, &QCheckBox::toggled, this, &ThisType::enableApplyButton);
|
||||
|
||||
const QString autoRunStr = QString("%1\n %2\n %3\n %4\n %5\n %6\n %7\n %8\n %9\n %10\n %11\n%12")
|
||||
.arg(tr("Supported parameters (case sensitive):")
|
||||
|
@ -696,6 +697,9 @@ void OptionsDialog::saveOptions()
|
|||
pref->setMailNotificationSMTPPassword(m_ui->mailNotifPassword->text());
|
||||
pref->setAutoRunEnabled(m_ui->autoRunBox->isChecked());
|
||||
pref->setAutoRunProgram(m_ui->lineEditAutoRun->text().trimmed());
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) && defined(Q_OS_WIN)
|
||||
pref->setAutoRunConsoleEnabled(m_ui->autoRunConsole->isChecked());
|
||||
#endif
|
||||
pref->setActionOnDblClOnTorrentDl(getActionOnDblClOnTorrentDl());
|
||||
pref->setActionOnDblClOnTorrentFn(getActionOnDblClOnTorrentFn());
|
||||
TorrentFileGuard::setAutoDeleteMode(!m_ui->deleteTorrentBox->isChecked() ? TorrentFileGuard::Never
|
||||
|
@ -970,6 +974,11 @@ void OptionsDialog::loadOptions()
|
|||
|
||||
m_ui->autoRunBox->setChecked(pref->isAutoRunEnabled());
|
||||
m_ui->lineEditAutoRun->setText(pref->getAutoRunProgram());
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) && defined(Q_OS_WIN)
|
||||
m_ui->autoRunConsole->setChecked(pref->isAutoRunConsoleEnabled());
|
||||
#else
|
||||
m_ui->autoRunConsole->hide();
|
||||
#endif
|
||||
intValue = pref->getActionOnDblClOnTorrentDl();
|
||||
if (intValue >= m_ui->actionTorrentDlOnDblClBox->count())
|
||||
intValue = 0;
|
||||
|
|
|
@ -1264,6 +1264,13 @@
|
|||
<item>
|
||||
<widget class="QLineEdit" name="lineEditAutoRun"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="autoRunConsole">
|
||||
<property name="text">
|
||||
<string>Show console window</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelAutoRunParam">
|
||||
<property name="wordWrap">
|
||||
|
|
Loading…
Reference in a new issue