Some improvements to handling command-line arguments.

This commit is contained in:
LoRd_MuldeR 2015-01-04 17:04:26 +01:00
parent 6b310b7c05
commit 4d898010c0
6 changed files with 65 additions and 51 deletions

View File

@ -35,7 +35,7 @@
#define VER_LAMEXP_MINOR_LO 1 #define VER_LAMEXP_MINOR_LO 1
#define VER_LAMEXP_TYPE Beta #define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 13 #define VER_LAMEXP_PATCH 13
#define VER_LAMEXP_BUILD 1667 #define VER_LAMEXP_BUILD 1669
#define VER_LAMEXP_CONFG 1558 #define VER_LAMEXP_CONFG 1558
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -1313,18 +1313,13 @@ bool MainWindow::winEvent(MSG *message, long *result)
*/ */
void MainWindow::windowShown(void) 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 //Force resize event
resizeEvent(NULL); resizeEvent(NULL);
//First run? //First run?
bool firstRun = false; const bool firstRun = arguments.contains("first-run");
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;
}
//Check license //Check license
if((m_settings->licenseAccepted() <= 0) || firstRun) if((m_settings->licenseAccepted() <= 0) || firstRun)
@ -1480,33 +1475,36 @@ void MainWindow::windowShown(void)
} }
//Add files from the command-line //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(!value.isEmpty())
if(!arguments[i].compare("--add", Qt::CaseInsensitive))
{ {
QFileInfo currentFile(arguments[++i].trimmed()); QFileInfo currentFile(value);
qDebug("Adding file from CLI: %s", MUTILS_UTF8(currentFile.absoluteFilePath())); qDebug("Adding file from CLI: %s", MUTILS_UTF8(currentFile.absoluteFilePath()));
addedFiles.append(currentFile.absoluteFilePath()); addedFiles.append(currentFile.absoluteFilePath());
} }
if(!addedFiles.isEmpty()) }
{ if(!addedFiles.isEmpty())
addFilesDelayed(addedFiles); {
} addFilesDelayed(addedFiles);
} }
//Add folders from the command-line //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())); qDebug("Adding folder from CLI: %s", MUTILS_UTF8(currentFile.absoluteFilePath()));
addFolder(currentFile.absoluteFilePath(), false, true); 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())); qDebug("Adding folder recursively from CLI: %s", MUTILS_UTF8(currentFile.absoluteFilePath()));
addFolder(currentFile.absoluteFilePath(), true, true); addFolder(currentFile.absoluteFilePath(), true, true);
} }

View File

@ -536,7 +536,7 @@ void ProcessingDialog::initEncoding(void)
unsigned int maximumInstances = qBound(0U, m_settings->maximumInstances(), MAX_INSTANCES); unsigned int maximumInstances = qBound(0U, m_settings->maximumInstances(), MAX_INSTANCES);
if(maximumInstances < 1) 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)); maximumInstances = cores2instances(qBound(1U, cpuFeatures.count, 64U));
} }

View File

@ -175,18 +175,29 @@ static int lamexp_main(int &argc, char **argv)
lamexp_print_logo(); lamexp_print_logo();
//Get CLI arguments //Get CLI arguments
const QStringList &arguments = MUtils::OS::arguments(); const MUtils::OS::ArgumentMap &arguments = MUtils::OS::arguments();
//Enumerate CLI arguments //Enumerate CLI arguments
qDebug("Command-Line Arguments:"); if(!arguments.isEmpty())
for(int i = 0; i < arguments.count(); i++)
{ {
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 //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 vendor id : %s (Intel=%s)", cpuFeatures.vendor, MUTILS_BOOL2STR(cpuFeatures.intel));
qDebug("CPU brand string : %s", cpuFeatures.brand); qDebug("CPU brand string : %s", cpuFeatures.brand);
qDebug(" CPU signature : Family=%d Model=%d Stepping=%d", cpuFeatures.family, cpuFeatures.model, cpuFeatures.stepping); 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? //Kill application?
for(int i = 0; i < argc; i++) 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; return EXIT_SUCCESS;
} }

View File

@ -86,7 +86,7 @@ void ShellIntegration::install(bool async)
const QString lamexpFileType(g_lamexpFileType); const QString lamexpFileType(g_lamexpFileType);
const QString lamexpFileInfo(tr("Audio File supported by LameXP")); 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 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); const QString lamexpShellAction(g_lamexpShellAction);
//Register the LameXP file type //Register the LameXP file type

View File

@ -58,33 +58,32 @@ void MessageProducerThread::run()
{ {
setTerminationEnabled(true); setTerminationEnabled(true);
bool bSentFiles = false; 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!");
{
qWarning("Failed to send IPC message!");
}
return;
} }
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!");
{
qWarning("Failed to send IPC message!");
}
return;
} }
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(file.exists() && file.isFile())
{ {
if(!m_ipcChannel->send(IPC_CMD_ADD_FILE, IPC_FLAG_NONE, MUTILS_UTF8(file.canonicalFilePath()))) if(!m_ipcChannel->send(IPC_CMD_ADD_FILE, IPC_FLAG_NONE, MUTILS_UTF8(file.canonicalFilePath())))
@ -94,9 +93,12 @@ void MessageProducerThread::run()
} }
bSentFiles = true; 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(dir.exists())
{ {
if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_NONE, MUTILS_UTF8(dir.canonicalPath()))) if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_NONE, MUTILS_UTF8(dir.canonicalPath())))
@ -106,9 +108,12 @@ void MessageProducerThread::run()
} }
bSentFiles = true; 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(dir.exists())
{ {
if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_ADD_RECURSIVE, MUTILS_UTF8(dir.canonicalPath()))) if(!m_ipcChannel->send(IPC_CMD_ADD_FOLDER, IPC_FLAG_ADD_RECURSIVE, MUTILS_UTF8(dir.canonicalPath())))