Improved custom parameter checking some more + properly split custom parameters that contain whitespaces.
This commit is contained in:
parent
048f0f6945
commit
394379d74f
@ -788,6 +788,35 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</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>
|
||||
<widget class="QLabel" name="labelNotification">
|
||||
<property name="palette">
|
||||
@ -913,6 +942,11 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editCustomParams">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Lucida Console</family>
|
||||
</font>
|
||||
</property>
|
||||
<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>
|
||||
</property>
|
||||
|
@ -516,8 +516,14 @@ x264_cpu_t x264_detect_cpu_features(int argc, char **argv)
|
||||
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-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-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");
|
||||
}
|
||||
|
@ -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(" 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
|
||||
if(!x264_init_qt(argc, argv))
|
||||
{
|
||||
|
@ -59,6 +59,15 @@ QMutex EncodeThread::m_mutex_startProcess;
|
||||
} \
|
||||
}
|
||||
|
||||
#define APPEND_AND_CLEAR(LIST, STR) \
|
||||
{ \
|
||||
if(!((STR).isEmpty())) \
|
||||
{ \
|
||||
(LIST) << (STR); \
|
||||
(STR).clear(); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
* Static vars
|
||||
*/
|
||||
@ -509,8 +518,7 @@ QStringList EncodeThread::buildCommandLine(bool usePipe, unsigned int frames, co
|
||||
|
||||
if(!m_options->custom().isEmpty())
|
||||
{
|
||||
//FIXME: Handle custom parameters that contain withspaces within quotes!
|
||||
cmdLine.append(m_options->custom().split(" "));
|
||||
cmdLine.append(splitParams(m_options->custom()));
|
||||
}
|
||||
|
||||
cmdLine << "--output" << pathToLocal(QDir::toNativeSeparators(m_outputFileName), true);
|
||||
@ -1026,3 +1034,32 @@ QString EncodeThread::commandline2string(const QString &program, const QStringLi
|
||||
|
||||
return commandline;
|
||||
}
|
||||
|
||||
QStringList EncodeThread::splitParams(const QString ¶ms)
|
||||
{
|
||||
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;
|
||||
}
|
@ -126,6 +126,7 @@ protected:
|
||||
|
||||
//Static functions
|
||||
static QString commandline2string(const QString &program, const QStringList &arguments);
|
||||
static QStringList splitParams(const QString ¶ms);
|
||||
|
||||
signals:
|
||||
void statusChanged(const QUuid &jobId, EncodeThread::JobStatus newStatus);
|
||||
|
@ -60,37 +60,25 @@
|
||||
class StringValidator : public QValidator
|
||||
{
|
||||
public:
|
||||
StringValidator(QLabel *notifier)
|
||||
StringValidator(QLabel *notifier, QLabel *icon)
|
||||
:
|
||||
m_notifier(notifier)
|
||||
m_notifier(notifier), m_icon(icon)
|
||||
{
|
||||
m_notifier->hide();
|
||||
m_icon->hide();
|
||||
}
|
||||
|
||||
virtual State validate(QString &input, int &pos) const
|
||||
{
|
||||
static const char* p[] = {"B", "o", "h", "p", "q", "fps", "frames", "preset", "tune", "profile",
|
||||
"stdin", "crf", "bitrate", "qp", "pass", "stats", "output", "help","quiet", NULL};
|
||||
|
||||
bool invalid = false;
|
||||
|
||||
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");
|
||||
invalid = invalid || checkParam(input, "frames");
|
||||
invalid = invalid || checkParam(input, "preset");
|
||||
invalid = invalid || checkParam(input, "tune");
|
||||
invalid = invalid || checkParam(input, "profile");
|
||||
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");
|
||||
for(size_t i = 0; p[i] && (!invalid); i++)
|
||||
{
|
||||
invalid = invalid || checkParam(input, QString::fromLatin1(p[i]));
|
||||
}
|
||||
|
||||
return invalid ? QValidator::Intermediate : QValidator::Acceptable;
|
||||
}
|
||||
@ -101,44 +89,45 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
QLabel *const m_notifier;
|
||||
QLabel *const m_notifier, *const m_icon;
|
||||
|
||||
bool checkParam(const QString &input, const QString ¶m) const
|
||||
{
|
||||
static const char c[20] = {' ', '*', '?', '<', '>', '/', '\\', '"', '\'', '!', '+', '#', '&', '%', '=', ',', ';', '.', '´', '`'};
|
||||
|
||||
bool flag = false;
|
||||
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);
|
||||
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
|
||||
{
|
||||
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));
|
||||
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)
|
||||
{
|
||||
MessageBeep(MB_ICONWARNING);
|
||||
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();
|
||||
if(m_notifier)
|
||||
{
|
||||
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
|
||||
{
|
||||
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;
|
||||
}
|
||||
@ -180,7 +169,7 @@ AddJobDialog::AddJobDialog(QWidget *parent, OptionsModel *options, bool x64suppo
|
||||
|
||||
//Setup validator
|
||||
editCustomParams->installEventFilter(this);
|
||||
editCustomParams->setValidator(new StringValidator(labelNotification));
|
||||
editCustomParams->setValidator(new StringValidator(labelNotification, iconNotification));
|
||||
editCustomParams->clear();
|
||||
|
||||
//Install event filter
|
||||
@ -242,6 +231,7 @@ void AddJobDialog::showEvent(QShowEvent *event)
|
||||
}
|
||||
|
||||
labelNotification->hide();
|
||||
iconNotification->hide();
|
||||
}
|
||||
|
||||
bool AddJobDialog::eventFilter(QObject *o, QEvent *e)
|
||||
|
Loading…
Reference in New Issue
Block a user