Improved custom parameter checking some more + properly split custom parameters that contain whitespaces.

This commit is contained in:
LoRd_MuldeR 2012-02-06 22:40:07 +01:00
parent 048f0f6945
commit 394379d74f
6 changed files with 121 additions and 47 deletions

View File

@ -788,6 +788,35 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QLabel" name="iconNotification">
<property name="toolTip">
<string>Your custom parameters will be ignored entirely, if you don't fix them!</string>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../res/resources.qrc">:/buttons/error.png</pixmap>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>6</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item> <item>
<widget class="QLabel" name="labelNotification"> <widget class="QLabel" name="labelNotification">
<property name="palette"> <property name="palette">
@ -913,6 +942,11 @@
</item> </item>
<item> <item>
<widget class="QLineEdit" name="editCustomParams"> <widget class="QLineEdit" name="editCustomParams">
<property name="font">
<font>
<family>Lucida Console</family>
</font>
</property>
<property name="toolTip"> <property name="toolTip">
<string>All command-line parameters you enter here will be passed to x264 unmodified and unchecked. Some parameters are forbidden, as they are reserved for the GUI.</string> <string>All command-line parameters you enter here will be passed to x264 unmodified and unchecked. Some parameters are forbidden, as they are reserved for the GUI.</string>
</property> </property>

View File

@ -516,8 +516,14 @@ x264_cpu_t x264_detect_cpu_features(int argc, char **argv)
for(int i = 0; i < argc; i++) for(int i = 0; i < argc; i++)
{ {
if(!_stricmp("--force-cpu-no-64bit", argv[i])) { flag = true; features.x64 = false; } if(!_stricmp("--force-cpu-no-64bit", argv[i])) { flag = true; features.x64 = false; }
if(!_stricmp("--force-cpu-no-mmx", argv[i])) { flag = true; features.mmx = false; }
if(!_stricmp("--force-cpu-no-sse", argv[i])) { flag = true; features.sse = features.sse2 = features.sse3 = features.ssse3 = false; } if(!_stricmp("--force-cpu-no-sse", argv[i])) { flag = true; features.sse = features.sse2 = features.sse3 = features.ssse3 = false; }
if(!_stricmp("--force-cpu-no-intel", argv[i])) { flag = true; features.intel = false; } if(!_stricmp("--force-cpu-no-intel", argv[i])) { flag = true; features.intel = false; }
if(!_stricmp("--force-cpu-have-64bit", argv[i])) { flag = true; features.x64 = true; }
if(!_stricmp("--force-cpu-have-mmx", argv[i])) { flag = true; features.mmx = true; }
if(!_stricmp("--force-cpu-have-sse", argv[i])) { flag = true; features.sse = features.sse2 = features.sse3 = features.ssse3 = true; }
if(!_stricmp("--force-cpu-have-intel", argv[i])) { flag = true; features.intel = true; }
} }
if(flag) qWarning("CPU flags overwritten by user-defined parameters. Take care!\n"); if(flag) qWarning("CPU flags overwritten by user-defined parameters. Take care!\n");
} }

View File

@ -62,6 +62,12 @@ static int x264_main(int argc, char* argv[])
qDebug("CPU capabilities : MMX: %s, SSE: %s, SSE2: %s, SSE3: %s, SSSE3: %s, x64: %s", X264_BOOL(cpuFeatures.mmx), X264_BOOL(cpuFeatures.sse), X264_BOOL(cpuFeatures.sse2), X264_BOOL(cpuFeatures.sse3), X264_BOOL(cpuFeatures.ssse3), X264_BOOL(cpuFeatures.x64)); qDebug("CPU capabilities : MMX: %s, SSE: %s, SSE2: %s, SSE3: %s, SSSE3: %s, x64: %s", X264_BOOL(cpuFeatures.mmx), X264_BOOL(cpuFeatures.sse), X264_BOOL(cpuFeatures.sse2), X264_BOOL(cpuFeatures.sse3), X264_BOOL(cpuFeatures.ssse3), X264_BOOL(cpuFeatures.x64));
qDebug(" Number of CPU's : %d\n", cpuFeatures.count); qDebug(" Number of CPU's : %d\n", cpuFeatures.count);
//Make sure this CPU can run x264
if(!(cpuFeatures.mmx && cpuFeatures.sse))
{
qFatal("Sorry, but this machine is not physically capable of running x264. Please get a CPU that supports at least the MMX and ISSE instruction sets!");
}
//Initialize Qt //Initialize Qt
if(!x264_init_qt(argc, argv)) if(!x264_init_qt(argc, argv))
{ {

View File

@ -59,6 +59,15 @@ QMutex EncodeThread::m_mutex_startProcess;
} \ } \
} }
#define APPEND_AND_CLEAR(LIST, STR) \
{ \
if(!((STR).isEmpty())) \
{ \
(LIST) << (STR); \
(STR).clear(); \
} \
}
/* /*
* Static vars * Static vars
*/ */
@ -509,8 +518,7 @@ QStringList EncodeThread::buildCommandLine(bool usePipe, unsigned int frames, co
if(!m_options->custom().isEmpty()) if(!m_options->custom().isEmpty())
{ {
//FIXME: Handle custom parameters that contain withspaces within quotes! cmdLine.append(splitParams(m_options->custom()));
cmdLine.append(m_options->custom().split(" "));
} }
cmdLine << "--output" << pathToLocal(QDir::toNativeSeparators(m_outputFileName), true); cmdLine << "--output" << pathToLocal(QDir::toNativeSeparators(m_outputFileName), true);
@ -1026,3 +1034,32 @@ QString EncodeThread::commandline2string(const QString &program, const QStringLi
return commandline; return commandline;
} }
QStringList EncodeThread::splitParams(const QString &params)
{
QStringList list;
bool isQuoted = false;
QString temp;
for(int i = 0; i < params.length(); i++)
{
const QChar c = params.at(i);
if(c == QChar::fromLatin1('"'))
{
APPEND_AND_CLEAR(list, temp);
isQuoted = (!isQuoted);
continue;
}
else if((!isQuoted) && (c == QChar::fromLatin1(' ')))
{
APPEND_AND_CLEAR(list, temp);
continue;
}
temp.append(c);
}
APPEND_AND_CLEAR(list, temp);
return list;
}

View File

@ -126,6 +126,7 @@ protected:
//Static functions //Static functions
static QString commandline2string(const QString &program, const QStringList &arguments); static QString commandline2string(const QString &program, const QStringList &arguments);
static QStringList splitParams(const QString &params);
signals: signals:
void statusChanged(const QUuid &jobId, EncodeThread::JobStatus newStatus); void statusChanged(const QUuid &jobId, EncodeThread::JobStatus newStatus);

View File

@ -60,37 +60,25 @@
class StringValidator : public QValidator class StringValidator : public QValidator
{ {
public: public:
StringValidator(QLabel *notifier) StringValidator(QLabel *notifier, QLabel *icon)
: :
m_notifier(notifier) m_notifier(notifier), m_icon(icon)
{ {
m_notifier->hide(); m_notifier->hide();
m_icon->hide();
} }
virtual State validate(QString &input, int &pos) const virtual State validate(QString &input, int &pos) const
{ {
bool invalid = false; static const char* p[] = {"B", "o", "h", "p", "q", "fps", "frames", "preset", "tune", "profile",
"stdin", "crf", "bitrate", "qp", "pass", "stats", "output", "help","quiet", NULL};
invalid = invalid || checkParam(input, "B");
invalid = invalid || checkParam(input, "o");
invalid = invalid || checkParam(input, "h");
invalid = invalid || checkParam(input, "p");
invalid = invalid || checkParam(input, "q");
invalid = invalid || checkParam(input, "fps"); bool invalid = false;
invalid = invalid || checkParam(input, "frames");
invalid = invalid || checkParam(input, "preset"); for(size_t i = 0; p[i] && (!invalid); i++)
invalid = invalid || checkParam(input, "tune"); {
invalid = invalid || checkParam(input, "profile"); invalid = invalid || checkParam(input, QString::fromLatin1(p[i]));
invalid = invalid || checkParam(input, "stdin"); }
invalid = invalid || checkParam(input, "crf");
invalid = invalid || checkParam(input, "bitrate");
invalid = invalid || checkParam(input, "qp");
invalid = invalid || checkParam(input, "pass");
invalid = invalid || checkParam(input, "stats");
invalid = invalid || checkParam(input, "output");
invalid = invalid || checkParam(input, "help");
invalid = invalid || checkParam(input, "quiet");
return invalid ? QValidator::Intermediate : QValidator::Acceptable; return invalid ? QValidator::Intermediate : QValidator::Acceptable;
} }
@ -101,44 +89,45 @@ public:
} }
protected: protected:
QLabel *const m_notifier; QLabel *const m_notifier, *const m_icon;
bool checkParam(const QString &input, const QString &param) const bool checkParam(const QString &input, const QString &param) const
{ {
static const char c[20] = {' ', '*', '?', '<', '>', '/', '\\', '"', '\'', '!', '+', '#', '&', '%', '=', ',', ';', '.', '´', '`'};
bool flag = false; bool flag = false;
if(param.length() > 1) if(param.length() > 1)
{ {
flag = flag || input.contains(QString("--%1 ").arg(param), Qt::CaseInsensitive);
flag = flag || input.contains(QString("--%1*").arg(param), Qt::CaseInsensitive);
flag = flag || input.contains(QString("--%1?").arg(param), Qt::CaseInsensitive);
flag = flag || input.contains(QString("--%1<").arg(param), Qt::CaseInsensitive);
flag = flag || input.contains(QString("--%1>").arg(param), Qt::CaseInsensitive);
flag = flag || input.contains(QString("--%1/").arg(param), Qt::CaseInsensitive);
flag = flag || input.contains(QString("--%1\"").arg(param), Qt::CaseInsensitive);
flag = flag || input.contains(QString("--%1\\").arg(param), Qt::CaseInsensitive);
flag = flag || input.endsWith(QString("--%1").arg(param), Qt::CaseInsensitive); flag = flag || input.endsWith(QString("--%1").arg(param), Qt::CaseInsensitive);
for(size_t i = 0; i < sizeof(c); i++)
{
flag = flag || input.contains(QString("--%1%2").arg(param, QChar::fromLatin1(c[i])), Qt::CaseInsensitive);
}
} }
else else
{ {
flag = flag || input.contains(QString(" -%1").arg(param));
flag = flag || input.contains(QString("*-%1").arg(param));
flag = flag || input.contains(QString("?-%1").arg(param));
flag = flag || input.contains(QString("<-%1").arg(param));
flag = flag || input.contains(QString(">-%1").arg(param));
flag = flag || input.contains(QString("/-%1").arg(param));
flag = flag || input.contains(QString("\"-%1").arg(param));
flag = flag || input.contains(QString("\\-%1").arg(param));
flag = flag || input.startsWith(QString("-%1").arg(param)); flag = flag || input.startsWith(QString("-%1").arg(param));
for(size_t i = 0; i < sizeof(c); i++)
{
flag = flag || input.contains(QString("%1-%2").arg(QChar::fromLatin1(c[i]), param), Qt::CaseSensitive);
}
} }
if(flag) if(flag)
{ {
MessageBeep(MB_ICONWARNING); if(m_notifier)
m_notifier->setText(tr("Invalid parameter entered: %1").arg((param.length() > 1) ? QString("--%1").arg(param) : QString("-%1").arg(param))); {
if(m_notifier->isHidden()) m_notifier->show(); m_notifier->setText(tr("Invalid parameter: %1").arg((param.length() > 1) ? QString("--%1").arg(param) : QString("-%1").arg(param)));
if(m_notifier->isHidden()) m_notifier->show();
if(m_icon) { if(m_icon->isHidden()) m_icon->show(); }
}
} }
else else
{ {
if(m_notifier->isVisible()) m_notifier->hide(); if(m_notifier)
{
if(m_notifier->isVisible()) m_notifier->hide();
if(m_icon) { if(m_icon->isVisible()) m_icon->hide(); }
}
} }
return flag; return flag;
} }
@ -180,7 +169,7 @@ AddJobDialog::AddJobDialog(QWidget *parent, OptionsModel *options, bool x64suppo
//Setup validator //Setup validator
editCustomParams->installEventFilter(this); editCustomParams->installEventFilter(this);
editCustomParams->setValidator(new StringValidator(labelNotification)); editCustomParams->setValidator(new StringValidator(labelNotification, iconNotification));
editCustomParams->clear(); editCustomParams->clear();
//Install event filter //Install event filter
@ -242,6 +231,7 @@ void AddJobDialog::showEvent(QShowEvent *event)
} }
labelNotification->hide(); labelNotification->hide();
iconNotification->hide();
} }
bool AddJobDialog::eventFilter(QObject *o, QEvent *e) bool AddJobDialog::eventFilter(QObject *o, QEvent *e)