Much improved validation of custom parameters.
This commit is contained in:
parent
1123701e6f
commit
498ba2690d
@ -2,6 +2,9 @@
|
||||
Simple x264/x265 Launcher version history
|
||||
-----------------------------------------
|
||||
|
||||
Version 2.60 [unreleased]
|
||||
* Much improved validation of custom parameters
|
||||
|
||||
Version 2.51 [2015-04-26]
|
||||
* Fixed regression: Config files were stored in a wrong directory
|
||||
* Updated x265 to version 1.6+239
|
||||
|
@ -26,7 +26,7 @@
|
||||
#define VER_X264_MAJOR 2
|
||||
#define VER_X264_MINOR 6
|
||||
#define VER_X264_PATCH 0
|
||||
#define VER_X264_BUILD 962
|
||||
#define VER_X264_BUILD 965
|
||||
|
||||
#define VER_X264_PORTABLE_EDITION (0)
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
|
||||
//MUtils
|
||||
#include <MUtils/Global.h>
|
||||
#include <MUtils/OSSupport.h>
|
||||
#include <MUtils/Exception.h>
|
||||
|
||||
//Qt
|
||||
@ -137,44 +138,52 @@ public:
|
||||
protected:
|
||||
QLabel *const m_notifier, *const m_icon;
|
||||
|
||||
bool checkParam(const QString &input, const QString ¶m, const bool doubleMinus) const
|
||||
bool checkParam(const QStringList &input, const char *const params[], const bool &doubleMinus) const
|
||||
{
|
||||
static const char c[20] = {' ', '*', '?', '<', '>', '/', '\\', '"', '\'', '!', '+', '#', '&', '%', '=', ',', ';', '.', '´', '`'};
|
||||
const QString prefix = doubleMinus ? QLatin1String("--") : QLatin1String("-");
|
||||
|
||||
bool flag = false;
|
||||
if(param.length() > 1)
|
||||
for(QStringList::ConstIterator iter = input.constBegin(); iter != input.constEnd(); iter++)
|
||||
{
|
||||
flag = flag || input.endsWith(QString("%1%2").arg(prefix, param), Qt::CaseInsensitive);
|
||||
for(size_t i = 0; i < sizeof(c); i++)
|
||||
for(size_t k = 0; params[k]; k++)
|
||||
{
|
||||
flag = flag || input.contains(QString("%1%2%3").arg(prefix, param, QChar::fromLatin1(c[i])), Qt::CaseInsensitive);
|
||||
const QString param = QLatin1String(params[k]);
|
||||
const QString prefix = ((param.length() > 1) && doubleMinus) ? QLatin1String("--") : QLatin1String("-");
|
||||
if(iter->compare(QString("%1%2").arg(prefix, param), Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
if(m_notifier)
|
||||
{
|
||||
m_notifier->setText(tr("Invalid parameter: %1").arg(*iter));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
if(iter->startsWith("-", Qt::CaseInsensitive) || iter->startsWith("--", Qt::CaseInsensitive))
|
||||
{
|
||||
flag = flag || input.startsWith(QString("-%1").arg(param));
|
||||
for(size_t i = 0; i < sizeof(c); i++)
|
||||
for(int i = 1; i < iter->length(); i++)
|
||||
{
|
||||
flag = flag || input.contains(QString("%1-%2").arg(QChar::fromLatin1(c[i]), param), Qt::CaseSensitive);
|
||||
if((!iter->at(i).isLetter()) && (iter->at(i) != '-'))
|
||||
{
|
||||
if(m_notifier)
|
||||
{
|
||||
m_notifier->setText(tr("Invalid string: %1").arg(*iter));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if((flag) && (m_notifier))
|
||||
{
|
||||
m_notifier->setText(tr("Invalid parameter: %1").arg((param.length() > 1) ? QString("%1%2").arg(prefix, param) : QString("-%1").arg(param)));
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
bool checkPrefix(const QString &input) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool checkPrefix(const QStringList &input, const bool &doubleMinus) const
|
||||
{
|
||||
for(QStringList::ConstIterator iter = input.constBegin(); iter != input.constEnd(); iter++)
|
||||
{
|
||||
static const char *const c[3] = { "--", "-", NULL };
|
||||
for(size_t i = 0; c[i]; i++)
|
||||
{
|
||||
const QString prefix = QString::fromLatin1(c[i]);
|
||||
if(input.startsWith(QString("%1 ").arg(prefix)) || input.contains(QString(" %1 ").arg(prefix)) || input.endsWith(prefix))
|
||||
if(iter->compare(prefix, Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
qDebug("A");
|
||||
if(m_notifier)
|
||||
{
|
||||
m_notifier->setText(tr("Invalid parameter: %1").arg(prefix));
|
||||
@ -182,6 +191,41 @@ protected:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if
|
||||
(
|
||||
((!doubleMinus) && iter->startsWith("--", Qt::CaseInsensitive)) ||
|
||||
(doubleMinus && iter->startsWith("-", Qt::CaseInsensitive) && (!iter->startsWith("--", Qt::CaseInsensitive)) && (iter->length() > 2)) ||
|
||||
(doubleMinus && iter->startsWith("--", Qt::CaseInsensitive) && (iter->length() < 4))
|
||||
)
|
||||
{
|
||||
if(m_notifier)
|
||||
{
|
||||
m_notifier->setText(tr("Invalid syntax: %1").arg(*iter));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool checkCharacters(const QStringList &input) const
|
||||
{
|
||||
static const char c[] = {'*', '?', '<', '>', '|', NULL};
|
||||
|
||||
for(QStringList::ConstIterator iter = input.constBegin(); iter != input.constEnd(); iter++)
|
||||
{
|
||||
for(size_t i = 0; c[i]; i++)
|
||||
{
|
||||
if(iter->indexOf(QLatin1Char(c[i])) >= 0)
|
||||
{
|
||||
if(m_notifier)
|
||||
{
|
||||
m_notifier->setText(tr("Invalid character: '%1'").arg(QLatin1Char(c[i])));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -219,16 +263,13 @@ public:
|
||||
|
||||
virtual State validate(QString &input, int &pos) const
|
||||
{
|
||||
static const char* p[] = {"B", "o", "h", "p", "q", /*"fps", "frames",*/ "preset", "tune", "profile",
|
||||
static const char *const params[] = {"B", "o", "h", "p", "q", /*"fps", "frames",*/ "preset", "tune", "profile",
|
||||
"stdin", "crf", "bitrate", "qp", "pass", "stats", "output", "help", "quiet", NULL};
|
||||
|
||||
bool invalid = checkPrefix(input);
|
||||
|
||||
for(size_t i = 0; p[i] && (!invalid); i++)
|
||||
{
|
||||
invalid = invalid || checkParam(input, QString::fromLatin1(p[i]), true);
|
||||
}
|
||||
const QString commandLine = input.trimmed();
|
||||
const QStringList tokens = commandLine.isEmpty() ? QStringList() : MUtils::OS::crack_command_line(commandLine);
|
||||
|
||||
const bool invalid = checkCharacters(tokens) || checkPrefix(tokens, true) || checkParam(tokens, params, true);
|
||||
return setStatus(invalid, "encoder") ? QValidator::Intermediate : QValidator::Acceptable;
|
||||
}
|
||||
};
|
||||
@ -240,15 +281,12 @@ public:
|
||||
|
||||
virtual State validate(QString &input, int &pos) const
|
||||
{
|
||||
static const char* p[] = {"o", "frames", "seek", "raw", "hfyu", "slave", NULL};
|
||||
static const char *const params[] = {"o", "frames", "seek", "raw", "hfyu", "slave", NULL};
|
||||
|
||||
bool invalid = checkPrefix(input);
|
||||
|
||||
for(size_t i = 0; p[i] && (!invalid); i++)
|
||||
{
|
||||
invalid = invalid || checkParam(input, QString::fromLatin1(p[i]), false);
|
||||
}
|
||||
const QString commandLine = input.trimmed();
|
||||
const QStringList tokens = commandLine.isEmpty() ? QStringList() : MUtils::OS::crack_command_line(commandLine);
|
||||
|
||||
const bool invalid = checkCharacters(tokens) || checkPrefix(tokens, false) || checkParam(tokens, params, false);
|
||||
return setStatus(invalid, "Avs2YUV") ? QValidator::Intermediate : QValidator::Acceptable;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user