mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-14 16:57:55 +00:00
Detect uknown command line parameters.
This commit is contained in:
parent
8bfd333c60
commit
ca2dc325f5
50
src/main.cpp
50
src/main.cpp
@ -114,6 +114,7 @@ struct QBtCommandLineParameters
|
|||||||
#endif
|
#endif
|
||||||
int webUiPort;
|
int webUiPort;
|
||||||
QStringList torrents;
|
QStringList torrents;
|
||||||
|
QString uknownParameter;
|
||||||
|
|
||||||
QBtCommandLineParameters()
|
QBtCommandLineParameters()
|
||||||
: showHelp(false)
|
: showHelp(false)
|
||||||
@ -154,6 +155,12 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
const QBtCommandLineParameters params = parseCommandLine();
|
const QBtCommandLineParameters params = parseCommandLine();
|
||||||
|
|
||||||
|
if (!params.uknownParameter.isEmpty()) {
|
||||||
|
displayBadArgMessage(QObject::tr("%1 is an uknown command line parameter.", "--random-parameter is an uknown command line parameter.")
|
||||||
|
.arg(params.uknownParameter));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef Q_OS_WIN
|
#ifndef Q_OS_WIN
|
||||||
if (params.showVersion) {
|
if (params.showVersion) {
|
||||||
if (isOneArg) {
|
if (isOneArg) {
|
||||||
@ -292,28 +299,37 @@ QBtCommandLineParameters parseCommandLine()
|
|||||||
for (int i = 1; i < appArguments.size(); ++i) {
|
for (int i = 1; i < appArguments.size(); ++i) {
|
||||||
const QString& arg = appArguments[i];
|
const QString& arg = appArguments[i];
|
||||||
|
|
||||||
if ((arg == QLatin1String("-h")) || (arg == QLatin1String("--help"))) {
|
if ((arg.startsWith("--") && !arg.endsWith(".torrent")) ||
|
||||||
result.showHelp = true;
|
(arg.startsWith("-") && arg.size() == 2)) {
|
||||||
}
|
//Parse known parameters
|
||||||
|
if ((arg == QLatin1String("-h")) || (arg == QLatin1String("--help"))) {
|
||||||
|
result.showHelp = true;
|
||||||
|
}
|
||||||
#ifndef Q_OS_WIN
|
#ifndef Q_OS_WIN
|
||||||
else if ((arg == QLatin1String("-v")) || (arg == QLatin1String("--version"))) {
|
else if ((arg == QLatin1String("-v")) || (arg == QLatin1String("--version"))) {
|
||||||
result.showVersion = true;
|
result.showVersion = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (arg.startsWith(QLatin1String("--webui-port="))) {
|
else if (arg.startsWith(QLatin1String("--webui-port="))) {
|
||||||
QStringList parts = arg.split(QLatin1Char('='));
|
QStringList parts = arg.split(QLatin1Char('='));
|
||||||
if (parts.size() == 2)
|
if (parts.size() == 2)
|
||||||
result.webUiPort = parts.last().toInt();
|
result.webUiPort = parts.last().toInt();
|
||||||
}
|
}
|
||||||
#ifndef DISABLE_GUI
|
#ifndef DISABLE_GUI
|
||||||
else if (arg == QLatin1String("--no-splash")) {
|
else if (arg == QLatin1String("--no-splash")) {
|
||||||
result.noSplash = true;
|
result.noSplash = true;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
else if ((arg == QLatin1String("-d")) || (arg == QLatin1String("--daemon"))) {
|
else if ((arg == QLatin1String("-d")) || (arg == QLatin1String("--daemon"))) {
|
||||||
result.shouldDaemonize = true;
|
result.shouldDaemonize = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
else {
|
||||||
|
//Uknown argument
|
||||||
|
result.uknownParameter = arg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
QFileInfo torrentPath;
|
QFileInfo torrentPath;
|
||||||
torrentPath.setFile(arg);
|
torrentPath.setFile(arg);
|
||||||
|
Loading…
Reference in New Issue
Block a user