Some improvements to handling command-line arguments.
This commit is contained in:
parent
6b310b7c05
commit
4d898010c0
@ -35,7 +35,7 @@
|
||||
#define VER_LAMEXP_MINOR_LO 1
|
||||
#define VER_LAMEXP_TYPE Beta
|
||||
#define VER_LAMEXP_PATCH 13
|
||||
#define VER_LAMEXP_BUILD 1667
|
||||
#define VER_LAMEXP_BUILD 1669
|
||||
#define VER_LAMEXP_CONFG 1558
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1313,18 +1313,13 @@ bool MainWindow::winEvent(MSG *message, long *result)
|
||||
*/
|
||||
void MainWindow::windowShown(void)
|
||||
{
|
||||
const QStringList &arguments = MUtils::OS::arguments(); //QApplication::arguments();
|
||||
const MUtils::OS::ArgumentMap &arguments = MUtils::OS::arguments(); //QApplication::arguments();
|
||||
|
||||
//Force resize event
|
||||
resizeEvent(NULL);
|
||||
|
||||
//First run?
|
||||
bool firstRun = false;
|
||||
for(int i = 0; i < arguments.count(); i++)
|
||||
{
|
||||
/*QMessageBox::information(this, QString::number(i), arguments[i]);*/
|
||||
if(!arguments[i].compare("--first-run", Qt::CaseInsensitive)) firstRun = true;
|
||||
}
|
||||
const bool firstRun = arguments.contains("first-run");
|
||||
|
||||
//Check license
|
||||
if((m_settings->licenseAccepted() <= 0) || firstRun)
|
||||
@ -1480,33 +1475,36 @@ void MainWindow::windowShown(void)
|
||||
}
|
||||
|
||||
//Add files from the command-line
|
||||
for(int i = 0; i < arguments.count() - 1; i++)
|
||||
QStringList addedFiles;
|
||||
foreach(const QString &value, arguments.values("add"))
|
||||
{
|
||||
QStringList addedFiles;
|
||||
if(!arguments[i].compare("--add", Qt::CaseInsensitive))
|
||||
if(!value.isEmpty())
|
||||
{
|
||||
QFileInfo currentFile(arguments[++i].trimmed());
|
||||
QFileInfo currentFile(value);
|
||||
qDebug("Adding file from CLI: %s", MUTILS_UTF8(currentFile.absoluteFilePath()));
|
||||
addedFiles.append(currentFile.absoluteFilePath());
|
||||
}
|
||||
if(!addedFiles.isEmpty())
|
||||
{
|
||||
addFilesDelayed(addedFiles);
|
||||
}
|
||||
}
|
||||
if(!addedFiles.isEmpty())
|
||||
{
|
||||
addFilesDelayed(addedFiles);
|
||||
}
|
||||
|
||||
//Add folders from the command-line
|
||||
for(int i = 0; i < arguments.count() - 1; i++)
|
||||
foreach(const QString &value, arguments.values("add-folder"))
|
||||
{
|
||||
if(!arguments[i].compare("--add-folder", Qt::CaseInsensitive))
|
||||
if(!value.isEmpty())
|
||||
{
|
||||
QFileInfo currentFile(arguments[++i].trimmed());
|
||||
const QFileInfo currentFile(value);
|
||||
qDebug("Adding folder from CLI: %s", MUTILS_UTF8(currentFile.absoluteFilePath()));
|
||||
addFolder(currentFile.absoluteFilePath(), false, true);
|
||||
}
|
||||
if(!arguments[i].compare("--add-recursive", Qt::CaseInsensitive))
|
||||
}
|
||||
foreach(const QString &value, arguments.values("add-recursive"))
|
||||
{
|
||||
if(!value.isEmpty())
|
||||
{
|
||||
QFileInfo currentFile(arguments[++i].trimmed());
|
||||
const QFileInfo currentFile(value);
|
||||
qDebug("Adding folder recursively from CLI: %s", MUTILS_UTF8(currentFile.absoluteFilePath()));
|
||||
addFolder(currentFile.absoluteFilePath(), true, true);
|
||||
}
|
||||
|
@ -536,7 +536,7 @@ void ProcessingDialog::initEncoding(void)
|
||||
unsigned int maximumInstances = qBound(0U, m_settings->maximumInstances(), MAX_INSTANCES);
|
||||
if(maximumInstances < 1)
|
||||
{
|
||||
const MUtils::CPUFetaures::cpu_info_t cpuFeatures = MUtils::CPUFetaures::detect(MUtils::OS::arguments());
|
||||
const MUtils::CPUFetaures::cpu_info_t cpuFeatures = MUtils::CPUFetaures::detect();
|
||||
maximumInstances = cores2instances(qBound(1U, cpuFeatures.count, 64U));
|
||||
}
|
||||
|
||||
|
25
src/Main.cpp
25
src/Main.cpp
@ -175,18 +175,29 @@ static int lamexp_main(int &argc, char **argv)
|
||||
lamexp_print_logo();
|
||||
|
||||
//Get CLI arguments
|
||||
const QStringList &arguments = MUtils::OS::arguments();
|
||||
const MUtils::OS::ArgumentMap &arguments = MUtils::OS::arguments();
|
||||
|
||||
//Enumerate CLI arguments
|
||||
qDebug("Command-Line Arguments:");
|
||||
for(int i = 0; i < arguments.count(); i++)
|
||||
if(!arguments.isEmpty())
|
||||
{
|
||||
qDebug("argv[%d]=%s", i, MUTILS_UTF8(arguments.at(i)));
|
||||
qDebug("Command-Line Arguments:");
|
||||
foreach(const QString &key, arguments.uniqueKeys())
|
||||
{
|
||||
foreach(const QString &val, arguments.values(key))
|
||||
{
|
||||
if(!val.isEmpty())
|
||||
{
|
||||
qDebug("--> %s = \"%s\"", MUTILS_UTF8(key), MUTILS_UTF8(val));
|
||||
continue;
|
||||
}
|
||||
qDebug("--> %s", MUTILS_UTF8(key));
|
||||
}
|
||||
}
|
||||
qDebug(" ");
|
||||
}
|
||||
qDebug(" ");
|
||||
|
||||
//Detect CPU capabilities
|
||||
const MUtils::CPUFetaures::cpu_info_t cpuFeatures = MUtils::CPUFetaures::detect(MUtils::OS::arguments());
|
||||
const MUtils::CPUFetaures::cpu_info_t cpuFeatures = MUtils::CPUFetaures::detect();
|
||||
qDebug(" CPU vendor id : %s (Intel=%s)", cpuFeatures.vendor, MUTILS_BOOL2STR(cpuFeatures.intel));
|
||||
qDebug("CPU brand string : %s", cpuFeatures.brand);
|
||||
qDebug(" CPU signature : Family=%d Model=%d Stepping=%d", cpuFeatures.family, cpuFeatures.model, cpuFeatures.stepping);
|
||||
@ -225,7 +236,7 @@ static int lamexp_main(int &argc, char **argv)
|
||||
//Kill application?
|
||||
for(int i = 0; i < argc; i++)
|
||||
{
|
||||
if(!arguments[i].compare("--kill", Qt::CaseInsensitive) || !arguments[i].compare("--force-kill", Qt::CaseInsensitive))
|
||||
if(arguments.contains("kill") || arguments.contains("force-kill"))
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ void ShellIntegration::install(bool async)
|
||||
const QString lamexpFileType(g_lamexpFileType);
|
||||
const QString lamexpFileInfo(tr("Audio File supported by LameXP"));
|
||||
const QString lamexpShellText(tr("Convert this file with LameXP v%1").arg(QString().sprintf("%d.%02d", lamexp_version_major(), lamexp_version_minor())));
|
||||
const QString lamexpShellCommand = QString("\"%1\" --add \"%2\"").arg(QDir::toNativeSeparators(QFileInfo(QApplication::applicationFilePath()).canonicalFilePath()), "%1");
|
||||
const QString lamexpShellCommand = QString("\"%1\" \"--add=%2\"").arg(QDir::toNativeSeparators(QFileInfo(QApplication::applicationFilePath()).canonicalFilePath()), "%1");
|
||||
const QString lamexpShellAction(g_lamexpShellAction);
|
||||
|
||||
//Register the LameXP file type
|
||||
|
@ -58,33 +58,32 @@ void MessageProducerThread::run()
|
||||
{
|
||||
setTerminationEnabled(true);
|
||||
bool bSentFiles = false;
|
||||
const QStringList &arguments = MUtils::OS::arguments();
|
||||
const MUtils::OS::ArgumentMap &arguments = MUtils::OS::arguments();
|
||||
|
||||
for(int i = 0; i < arguments.count(); i++)
|
||||
//Kill application?
|
||||
if(arguments.contains("kill"))
|
||||
{
|
||||
if(!arguments[i].compare("--kill", Qt::CaseInsensitive))
|
||||
if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_NONE, NULL))
|
||||
{
|
||||
if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_NONE, NULL))
|
||||
{
|
||||
qWarning("Failed to send IPC message!");
|
||||
}
|
||||
return;
|
||||
qWarning("Failed to send IPC message!");
|
||||
}
|
||||
if(!arguments[i].compare("--force-kill", Qt::CaseInsensitive))
|
||||
return;
|
||||
}
|
||||
if(arguments.contains("force-kill"))
|
||||
{
|
||||
if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_FORCE, NULL))
|
||||
{
|
||||
if(!m_ipcChannel->send(IPC_CMD_TERMINATE, IPC_FLAG_FORCE, NULL))
|
||||
{
|
||||
qWarning("Failed to send IPC message!");
|
||||
}
|
||||
return;
|
||||
qWarning("Failed to send IPC message!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i = 0; i < arguments.count() - 1; i++)
|
||||
//Send file to "matser" instance
|
||||
foreach(const QString &value, arguments.values("add"))
|
||||
{
|
||||
if(!arguments[i].compare("--add", Qt::CaseInsensitive))
|
||||
if(!value.isEmpty())
|
||||
{
|
||||
QFileInfo file = QFileInfo(arguments[++i]);
|
||||
const QFileInfo file = QFileInfo(value);
|
||||
if(file.exists() && file.isFile())
|
||||
{
|
||||
if(!m_ipcChannel->send(IPC_CMD_ADD_FILE, IPC_FLAG_NONE, MUTILS_UTF8(file.canonicalFilePath())))
|
||||
@ -94,9 +93,12 @@ void MessageProducerThread::run()
|
||||
}
|
||||
bSentFiles = true;
|
||||
}
|
||||
if(!arguments[i].compare("--add-folder", Qt::CaseInsensitive))
|
||||
}
|
||||
foreach(const QString &value, arguments.values("add-folder"))
|
||||
{
|
||||
if(!value.isEmpty())
|
||||
{
|
||||
QDir dir = QDir(arguments[++i]);
|
||||
const QDir dir = QDir(value);
|
||||
if(dir.exists())
|
||||
{
|
||||
if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_NONE, MUTILS_UTF8(dir.canonicalPath())))
|
||||
@ -106,9 +108,12 @@ void MessageProducerThread::run()
|
||||
}
|
||||
bSentFiles = true;
|
||||
}
|
||||
if(!arguments[i].compare("--add-recursive", Qt::CaseInsensitive))
|
||||
}
|
||||
foreach(const QString &value, arguments.values("add-recursive"))
|
||||
{
|
||||
if(!value.isEmpty())
|
||||
{
|
||||
QDir dir = QDir(arguments[++i]);
|
||||
const QDir dir = QDir(value);
|
||||
if(dir.exists())
|
||||
{
|
||||
if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_ADD_RECURSIVE, MUTILS_UTF8(dir.canonicalPath())))
|
||||
|
Loading…
x
Reference in New Issue
Block a user