mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-04-29 22:24:26 +02:00
chore: make all the regexes static const
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
21c90527d2
commit
c5fd5e6ac1
@ -42,7 +42,6 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QRegularExpression>
|
|
||||||
|
|
||||||
#include "settings/INISettingsObject.h"
|
#include "settings/INISettingsObject.h"
|
||||||
#include "settings/OverrideSetting.h"
|
#include "settings/OverrideSetting.h"
|
||||||
|
@ -378,8 +378,8 @@ void InstanceImportTask::processModrinth()
|
|||||||
} else {
|
} else {
|
||||||
QString pack_id;
|
QString pack_id;
|
||||||
if (!m_sourceUrl.isEmpty()) {
|
if (!m_sourceUrl.isEmpty()) {
|
||||||
QRegularExpression regex(R"(data\/([^\/]*)\/versions)");
|
static const QRegularExpression s_regex(R"(data\/([^\/]*)\/versions)");
|
||||||
pack_id = regex.match(m_sourceUrl.toString()).captured(1);
|
pack_id = s_regex.match(m_sourceUrl.toString()).captured(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Find a way to get the ID in directly imported ZIPs
|
// FIXME: Find a way to get the ID in directly imported ZIPs
|
||||||
|
@ -41,7 +41,9 @@
|
|||||||
|
|
||||||
bool JavaCommon::checkJVMArgs(QString jvmargs, QWidget* parent)
|
bool JavaCommon::checkJVMArgs(QString jvmargs, QWidget* parent)
|
||||||
{
|
{
|
||||||
if (jvmargs.contains("-XX:PermSize=") || jvmargs.contains(QRegularExpression("-Xm[sx]")) || jvmargs.contains("-XX-MaxHeapSize") ||
|
static const QRegularExpression s_memRegex("-Xm[sx]");
|
||||||
|
static const QRegularExpression s_versionRegex("-version:.*");
|
||||||
|
if (jvmargs.contains("-XX:PermSize=") || jvmargs.contains(s_memRegex) || jvmargs.contains("-XX-MaxHeapSize") ||
|
||||||
jvmargs.contains("-XX:InitialHeapSize")) {
|
jvmargs.contains("-XX:InitialHeapSize")) {
|
||||||
auto warnStr = QObject::tr(
|
auto warnStr = QObject::tr(
|
||||||
"You tried to manually set a JVM memory option (using \"-XX:PermSize\", \"-XX-MaxHeapSize\", \"-XX:InitialHeapSize\", \"-Xmx\" "
|
"You tried to manually set a JVM memory option (using \"-XX:PermSize\", \"-XX-MaxHeapSize\", \"-XX:InitialHeapSize\", \"-Xmx\" "
|
||||||
@ -52,7 +54,7 @@ bool JavaCommon::checkJVMArgs(QString jvmargs, QWidget* parent)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// block lunacy with passing required version to the JVM
|
// block lunacy with passing required version to the JVM
|
||||||
if (jvmargs.contains(QRegularExpression("-version:.*"))) {
|
if (jvmargs.contains(s_versionRegex)) {
|
||||||
auto warnStr = QObject::tr(
|
auto warnStr = QObject::tr(
|
||||||
"You tried to pass required Java version argument to the JVM (using \"-version:xxx\"). This is not safe and will not be "
|
"You tried to pass required Java version argument to the JVM (using \"-version:xxx\"). This is not safe and will not be "
|
||||||
"allowed.\n"
|
"allowed.\n"
|
||||||
|
@ -182,7 +182,8 @@ void LaunchController::login()
|
|||||||
auto name = askOfflineName("Player", m_demo, ok);
|
auto name = askOfflineName("Player", m_demo, ok);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
m_session = std::make_shared<AuthSession>();
|
m_session = std::make_shared<AuthSession>();
|
||||||
m_session->MakeDemo(name, MinecraftAccount::uuidFromUsername(name).toString().remove(QRegularExpression("[{}-]")));
|
static const QRegularExpression s_removeChars("[{}-]");
|
||||||
|
m_session->MakeDemo(name, MinecraftAccount::uuidFromUsername(name).toString().remove(s_removeChars));
|
||||||
launchInstance();
|
launchInstance();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "RecursiveFileSystemWatcher.h"
|
#include "RecursiveFileSystemWatcher.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QRegularExpression>
|
|
||||||
|
|
||||||
RecursiveFileSystemWatcher::RecursiveFileSystemWatcher(QObject* parent) : QObject(parent), m_watcher(new QFileSystemWatcher(this))
|
RecursiveFileSystemWatcher::RecursiveFileSystemWatcher(QObject* parent) : QObject(parent), m_watcher(new QFileSystemWatcher(this))
|
||||||
{
|
{
|
||||||
|
@ -213,11 +213,10 @@ QPair<QString, QString> StringUtils::splitFirst(const QString& s, const QRegular
|
|||||||
return qMakePair(left, right);
|
return qMakePair(left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const QRegularExpression ulMatcher("<\\s*/\\s*ul\\s*>");
|
|
||||||
|
|
||||||
QString StringUtils::htmlListPatch(QString htmlStr)
|
QString StringUtils::htmlListPatch(QString htmlStr)
|
||||||
{
|
{
|
||||||
int pos = htmlStr.indexOf(ulMatcher);
|
static const QRegularExpression s_ulMatcher("<\\s*/\\s*ul\\s*>");
|
||||||
|
int pos = htmlStr.indexOf(s_ulMatcher);
|
||||||
int imgPos;
|
int imgPos;
|
||||||
while (pos != -1) {
|
while (pos != -1) {
|
||||||
pos = htmlStr.indexOf(">", pos) + 1; // Get the size of the </ul> tag. Add one for zeroeth index
|
pos = htmlStr.indexOf(">", pos) + 1; // Get the size of the </ul> tag. Add one for zeroeth index
|
||||||
@ -230,7 +229,7 @@ QString StringUtils::htmlListPatch(QString htmlStr)
|
|||||||
if (textBetween.isEmpty())
|
if (textBetween.isEmpty())
|
||||||
htmlStr.insert(pos, "<br>");
|
htmlStr.insert(pos, "<br>");
|
||||||
|
|
||||||
pos = htmlStr.indexOf(ulMatcher, pos);
|
pos = htmlStr.indexOf(s_ulMatcher, pos);
|
||||||
}
|
}
|
||||||
return htmlStr;
|
return htmlStr;
|
||||||
}
|
}
|
@ -1,7 +1,6 @@
|
|||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QRegularExpression>
|
|
||||||
#include <QRegularExpressionMatch>
|
#include <QRegularExpressionMatch>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
@ -19,9 +19,13 @@ JavaVersion& JavaVersion::operator=(const QString& javaVersionString)
|
|||||||
|
|
||||||
QRegularExpression pattern;
|
QRegularExpression pattern;
|
||||||
if (javaVersionString.startsWith("1.")) {
|
if (javaVersionString.startsWith("1.")) {
|
||||||
pattern = QRegularExpression("1[.](?<major>[0-9]+)([.](?<minor>[0-9]+))?(_(?<security>[0-9]+)?)?(-(?<prerelease>[a-zA-Z0-9]+))?");
|
static const QRegularExpression s_withOne(
|
||||||
|
"1[.](?<major>[0-9]+)([.](?<minor>[0-9]+))?(_(?<security>[0-9]+)?)?(-(?<prerelease>[a-zA-Z0-9]+))?");
|
||||||
|
pattern = s_withOne;
|
||||||
} else {
|
} else {
|
||||||
pattern = QRegularExpression("(?<major>[0-9]+)([.](?<minor>[0-9]+))?([.](?<security>[0-9]+))?(-(?<prerelease>[a-zA-Z0-9]+))?");
|
static const QRegularExpression s_withoutOne(
|
||||||
|
"(?<major>[0-9]+)([.](?<minor>[0-9]+))?([.](?<security>[0-9]+))?(-(?<prerelease>[a-zA-Z0-9]+))?");
|
||||||
|
pattern = s_withoutOne;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto match = pattern.match(m_string);
|
auto match = pattern.match(m_string);
|
||||||
|
@ -41,7 +41,6 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QRegularExpression>
|
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include "MessageLevel.h"
|
#include "MessageLevel.h"
|
||||||
|
@ -54,11 +54,11 @@ struct GradleSpecifier {
|
|||||||
4 "jdk15"
|
4 "jdk15"
|
||||||
5 "jar"
|
5 "jar"
|
||||||
*/
|
*/
|
||||||
QRegularExpression matcher(
|
static const QRegularExpression s_matcher(
|
||||||
QRegularExpression::anchoredPattern("([^:@]+):([^:@]+):([^:@]+)"
|
QRegularExpression::anchoredPattern("([^:@]+):([^:@]+):([^:@]+)"
|
||||||
"(?::([^:@]+))?"
|
"(?::([^:@]+))?"
|
||||||
"(?:@([^:@]+))?"));
|
"(?:@([^:@]+))?"));
|
||||||
QRegularExpressionMatch match = matcher.match(value);
|
QRegularExpressionMatch match = s_matcher.match(value);
|
||||||
m_valid = match.hasMatch();
|
m_valid = match.hasMatch();
|
||||||
if (!m_valid) {
|
if (!m_valid) {
|
||||||
m_invalidValue = value;
|
m_invalidValue = value;
|
||||||
|
@ -53,7 +53,6 @@
|
|||||||
#include "MMCTime.h"
|
#include "MMCTime.h"
|
||||||
#include "java/JavaVersion.h"
|
#include "java/JavaVersion.h"
|
||||||
#include "pathmatcher/MultiMatcher.h"
|
#include "pathmatcher/MultiMatcher.h"
|
||||||
#include "pathmatcher/RegexpMatcher.h"
|
|
||||||
|
|
||||||
#include "launch/LaunchTask.h"
|
#include "launch/LaunchTask.h"
|
||||||
#include "launch/TaskStepWrapper.h"
|
#include "launch/TaskStepWrapper.h"
|
||||||
@ -689,9 +688,9 @@ static QString replaceTokensIn(QString text, QMap<QString, QString> with)
|
|||||||
{
|
{
|
||||||
// TODO: does this still work??
|
// TODO: does this still work??
|
||||||
QString result;
|
QString result;
|
||||||
QRegularExpression token_regexp("\\$\\{(.+)\\}", QRegularExpression::InvertedGreedinessOption);
|
static const QRegularExpression s_token_regexp("\\$\\{(.+)\\}", QRegularExpression::InvertedGreedinessOption);
|
||||||
QStringList list;
|
QStringList list;
|
||||||
QRegularExpressionMatchIterator i = token_regexp.globalMatch(text);
|
QRegularExpressionMatchIterator i = s_token_regexp.globalMatch(text);
|
||||||
int lastCapturedEnd = 0;
|
int lastCapturedEnd = 0;
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
QRegularExpressionMatch match = i.next();
|
QRegularExpressionMatch match = i.next();
|
||||||
|
@ -114,9 +114,9 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument& doc
|
|||||||
out->uid = root.value("fileId").toString();
|
out->uid = root.value("fileId").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QRegularExpression valid_uid_regex{ QRegularExpression::anchoredPattern(
|
static const QRegularExpression s_validUidRegex{ QRegularExpression::anchoredPattern(
|
||||||
QStringLiteral(R"([a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]+)*)")) };
|
QStringLiteral(R"([a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]+)*)")) };
|
||||||
if (!valid_uid_regex.match(out->uid).hasMatch()) {
|
if (!s_validUidRegex.match(out->uid).hasMatch()) {
|
||||||
qCritical() << "The component's 'uid' contains illegal characters! UID:" << out->uid;
|
qCritical() << "The component's 'uid' contains illegal characters! UID:" << out->uid;
|
||||||
out->addProblem(ProblemSeverity::Error,
|
out->addProblem(ProblemSeverity::Error,
|
||||||
QObject::tr("The component's 'uid' contains illegal characters! This can cause security issues."));
|
QObject::tr("The component's 'uid' contains illegal characters! This can cause security issues."));
|
||||||
|
@ -41,7 +41,6 @@
|
|||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QRegularExpression>
|
|
||||||
#include <QSaveFile>
|
#include <QSaveFile>
|
||||||
|
|
||||||
namespace ProfileUtils {
|
namespace ProfileUtils {
|
||||||
|
@ -38,7 +38,6 @@
|
|||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QRegularExpression>
|
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -55,7 +55,8 @@
|
|||||||
|
|
||||||
MinecraftAccount::MinecraftAccount(QObject* parent) : QObject(parent)
|
MinecraftAccount::MinecraftAccount(QObject* parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
data.internalId = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
|
static const QRegularExpression s_removeChars("[{}-]");
|
||||||
|
data.internalId = QUuid::createUuid().toString().remove(s_removeChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
MinecraftAccountPtr MinecraftAccount::loadFromJsonV3(const QJsonObject& json)
|
MinecraftAccountPtr MinecraftAccount::loadFromJsonV3(const QJsonObject& json)
|
||||||
@ -76,14 +77,15 @@ MinecraftAccountPtr MinecraftAccount::createBlankMSA()
|
|||||||
|
|
||||||
MinecraftAccountPtr MinecraftAccount::createOffline(const QString& username)
|
MinecraftAccountPtr MinecraftAccount::createOffline(const QString& username)
|
||||||
{
|
{
|
||||||
|
static const QRegularExpression s_removeChars("[{}-]");
|
||||||
auto account = makeShared<MinecraftAccount>();
|
auto account = makeShared<MinecraftAccount>();
|
||||||
account->data.type = AccountType::Offline;
|
account->data.type = AccountType::Offline;
|
||||||
account->data.yggdrasilToken.token = "0";
|
account->data.yggdrasilToken.token = "0";
|
||||||
account->data.yggdrasilToken.validity = Validity::Certain;
|
account->data.yggdrasilToken.validity = Validity::Certain;
|
||||||
account->data.yggdrasilToken.issueInstant = QDateTime::currentDateTimeUtc();
|
account->data.yggdrasilToken.issueInstant = QDateTime::currentDateTimeUtc();
|
||||||
account->data.yggdrasilToken.extra["userName"] = username;
|
account->data.yggdrasilToken.extra["userName"] = username;
|
||||||
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
|
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(s_removeChars);
|
||||||
account->data.minecraftProfile.id = uuidFromUsername(username).toString().remove(QRegularExpression("[{}-]"));
|
account->data.minecraftProfile.id = uuidFromUsername(username).toString().remove(s_removeChars);
|
||||||
account->data.minecraftProfile.name = username;
|
account->data.minecraftProfile.name = username;
|
||||||
account->data.minecraftProfile.validity = Validity::Certain;
|
account->data.minecraftProfile.validity = Validity::Certain;
|
||||||
return account;
|
return account;
|
||||||
@ -231,6 +233,7 @@ bool MinecraftAccount::shouldRefresh() const
|
|||||||
|
|
||||||
void MinecraftAccount::fillSession(AuthSessionPtr session)
|
void MinecraftAccount::fillSession(AuthSessionPtr session)
|
||||||
{
|
{
|
||||||
|
static const QRegularExpression s_removeChars("[{}-]");
|
||||||
if (ownsMinecraft() && !hasProfile()) {
|
if (ownsMinecraft() && !hasProfile()) {
|
||||||
session->status = AuthSession::RequiresProfileSetup;
|
session->status = AuthSession::RequiresProfileSetup;
|
||||||
} else {
|
} else {
|
||||||
@ -248,7 +251,7 @@ void MinecraftAccount::fillSession(AuthSessionPtr session)
|
|||||||
// profile ID
|
// profile ID
|
||||||
session->uuid = data.profileId();
|
session->uuid = data.profileId();
|
||||||
if (session->uuid.isEmpty())
|
if (session->uuid.isEmpty())
|
||||||
session->uuid = uuidFromUsername(session->player_name).toString().remove(QRegularExpression("[{}-]"));
|
session->uuid = uuidFromUsername(session->player_name).toString().remove(s_removeChars);
|
||||||
// 'legacy' or 'mojang', depending on account type
|
// 'legacy' or 'mojang', depending on account type
|
||||||
session->user_type = typeString();
|
session->user_type = typeString();
|
||||||
if (!session->access_token.isEmpty()) {
|
if (!session->access_token.isEmpty()) {
|
||||||
|
@ -53,15 +53,16 @@ LauncherPartLaunch::LauncherPartLaunch(LaunchTask* parent)
|
|||||||
, m_process(parent->instance()->getJavaVersion().defaultsToUtf8() ? QTextCodec::codecForName("UTF-8") : QTextCodec::codecForLocale())
|
, m_process(parent->instance()->getJavaVersion().defaultsToUtf8() ? QTextCodec::codecForName("UTF-8") : QTextCodec::codecForLocale())
|
||||||
{
|
{
|
||||||
if (parent->instance()->settings()->get("CloseAfterLaunch").toBool()) {
|
if (parent->instance()->settings()->get("CloseAfterLaunch").toBool()) {
|
||||||
|
static const QRegularExpression s_settingUser(".*Setting user.+", QRegularExpression::CaseInsensitiveOption);
|
||||||
std::shared_ptr<QMetaObject::Connection> connection{ new QMetaObject::Connection };
|
std::shared_ptr<QMetaObject::Connection> connection{ new QMetaObject::Connection };
|
||||||
*connection = connect(
|
*connection = connect(&m_process, &LoggedProcess::log, this,
|
||||||
&m_process, &LoggedProcess::log, this, [connection](const QStringList& lines, [[maybe_unused]] MessageLevel::Enum level) {
|
[connection](const QStringList& lines, [[maybe_unused]] MessageLevel::Enum level) {
|
||||||
qDebug() << lines;
|
qDebug() << lines;
|
||||||
if (lines.filter(QRegularExpression(".*Setting user.+", QRegularExpression::CaseInsensitiveOption)).length() != 0) {
|
if (lines.filter(s_settingUser).length() != 0) {
|
||||||
APPLICATION->closeAllWindows();
|
APPLICATION->closeAllWindows();
|
||||||
disconnect(*connection);
|
disconnect(*connection);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(&m_process, &LoggedProcess::log, this, &LauncherPartLaunch::logLines);
|
connect(&m_process, &LoggedProcess::log, this, &LauncherPartLaunch::logLines);
|
||||||
|
@ -82,8 +82,8 @@ auto Resource::name() const -> QString
|
|||||||
|
|
||||||
static void removeThePrefix(QString& string)
|
static void removeThePrefix(QString& string)
|
||||||
{
|
{
|
||||||
QRegularExpression regex(QStringLiteral("^(?:the|teh) +"), QRegularExpression::CaseInsensitiveOption);
|
static const QRegularExpression s_regex(QStringLiteral("^(?:the|teh) +"), QRegularExpression::CaseInsensitiveOption);
|
||||||
string.remove(regex);
|
string.remove(s_regex);
|
||||||
string = string.trimmed();
|
string = string.trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QRegularExpression>
|
|
||||||
|
|
||||||
#include "MTPixmapCache.h"
|
#include "MTPixmapCache.h"
|
||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
|
|
||||||
|
@ -22,8 +22,6 @@
|
|||||||
|
|
||||||
#include "ShaderPack.h"
|
#include "ShaderPack.h"
|
||||||
|
|
||||||
#include <QRegularExpression>
|
|
||||||
|
|
||||||
void ShaderPack::setPackFormat(ShaderPackFormat new_format)
|
void ShaderPack::setPackFormat(ShaderPackFormat new_format)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_data_lock);
|
QMutexLocker locker(&m_data_lock);
|
||||||
|
@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QRegularExpression>
|
|
||||||
|
|
||||||
#include "MTPixmapCache.h"
|
#include "MTPixmapCache.h"
|
||||||
|
|
||||||
#include "minecraft/mod/tasks/LocalTexturePackParseTask.h"
|
#include "minecraft/mod/tasks/LocalTexturePackParseTask.h"
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include "minecraft/mod/ModDetails.h"
|
#include "minecraft/mod/ModDetails.h"
|
||||||
#include "settings/INIFile.h"
|
#include "settings/INIFile.h"
|
||||||
|
|
||||||
static QRegularExpression newlineRegex("\r\n|\n|\r");
|
static const QRegularExpression s_newlineRegex("\r\n|\n|\r");
|
||||||
|
|
||||||
namespace ModUtils {
|
namespace ModUtils {
|
||||||
|
|
||||||
@ -494,7 +494,7 @@ bool processZIP(Mod& mod, [[maybe_unused]] ProcessingLevel level)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// quick and dirty line-by-line parser
|
// quick and dirty line-by-line parser
|
||||||
auto manifestLines = QString(file.readAll()).split(newlineRegex);
|
auto manifestLines = QString(file.readAll()).split(s_newlineRegex);
|
||||||
QString manifestVersion = "";
|
QString manifestVersion = "";
|
||||||
for (auto& line : manifestLines) {
|
for (auto& line : manifestLines) {
|
||||||
if (line.startsWith("Implementation-Version: ", Qt::CaseInsensitive)) {
|
if (line.startsWith("Implementation-Version: ", Qt::CaseInsensitive)) {
|
||||||
|
@ -43,5 +43,6 @@ void ATLauncher::loadIndexedPack(ATLauncher::IndexedPack& m, QJsonObject& obj)
|
|||||||
m.system = Json::ensureBoolean(obj, QString("system"), false);
|
m.system = Json::ensureBoolean(obj, QString("system"), false);
|
||||||
m.description = Json::ensureString(obj, "description", "");
|
m.description = Json::ensureString(obj, "description", "");
|
||||||
|
|
||||||
m.safeName = Json::requireString(obj, "name").replace(QRegularExpression("[^A-Za-z0-9]"), "").toLower() + ".png";
|
static const QRegularExpression s_regex("[^A-Za-z0-9]");
|
||||||
|
m.safeName = Json::requireString(obj, "name").replace(s_regex, "").toLower() + ".png";
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,8 @@ PackInstallTask::PackInstallTask(UserInteractionSupport* support, QString packNa
|
|||||||
{
|
{
|
||||||
m_support = support;
|
m_support = support;
|
||||||
m_pack_name = packName;
|
m_pack_name = packName;
|
||||||
m_pack_safe_name = packName.replace(QRegularExpression("[^A-Za-z0-9]"), "");
|
static const QRegularExpression s_regex("[^A-Za-z0-9]");
|
||||||
|
m_pack_safe_name = packName.replace(s_regex, "");
|
||||||
m_version_name = version;
|
m_version_name = version;
|
||||||
m_install_mode = installMode;
|
m_install_mode = installMode;
|
||||||
}
|
}
|
||||||
@ -938,7 +939,8 @@ bool PackInstallTask::extractMods(const QMap<QString, VersionMod>& toExtract,
|
|||||||
QString folderToExtract = "";
|
QString folderToExtract = "";
|
||||||
if (mod.type == ModType::Extract) {
|
if (mod.type == ModType::Extract) {
|
||||||
folderToExtract = mod.extractFolder;
|
folderToExtract = mod.extractFolder;
|
||||||
folderToExtract.remove(QRegularExpression("^/"));
|
static const QRegularExpression s_regex("^/");
|
||||||
|
folderToExtract.remove(s_regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Extracting " + mod.file + " to " + extractToDir;
|
qDebug() << "Extracting " + mod.file + " to " + extractToDir;
|
||||||
|
@ -391,7 +391,8 @@ bool FlameCreationTask::createInstance()
|
|||||||
|
|
||||||
// Hack to correct some 'special sauce'...
|
// Hack to correct some 'special sauce'...
|
||||||
if (mcVersion.endsWith('.')) {
|
if (mcVersion.endsWith('.')) {
|
||||||
mcVersion.remove(QRegularExpression("[.]+$"));
|
static const QRegularExpression s_regex("[.]+$");
|
||||||
|
mcVersion.remove(s_regex);
|
||||||
logWarning(tr("Mysterious trailing dots removed from Minecraft version while importing pack."));
|
logWarning(tr("Mysterious trailing dots removed from Minecraft version while importing pack."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,8 +98,8 @@ Task::State MetaCacheSink::finalizeCache(QNetworkReply& reply)
|
|||||||
auto cache_control_header = reply.rawHeader("Cache-Control");
|
auto cache_control_header = reply.rawHeader("Cache-Control");
|
||||||
qCDebug(taskMetaCacheLogC) << "Parsing 'Cache-Control' header with" << cache_control_header;
|
qCDebug(taskMetaCacheLogC) << "Parsing 'Cache-Control' header with" << cache_control_header;
|
||||||
|
|
||||||
QRegularExpression max_age_expr("max-age=([0-9]+)");
|
static const QRegularExpression s_maxAgeExpr("max-age=([0-9]+)");
|
||||||
qint64 max_age = max_age_expr.match(cache_control_header).captured(1).toLongLong();
|
qint64 max_age = s_maxAgeExpr.match(cache_control_header).captured(1).toLongLong();
|
||||||
m_entry->setMaximumAge(max_age);
|
m_entry->setMaximumAge(max_age);
|
||||||
|
|
||||||
} else if (reply.hasRawHeader("Expires")) {
|
} else if (reply.hasRawHeader("Expires")) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SeparatorPrefixTree.h>
|
#include <SeparatorPrefixTree.h>
|
||||||
#include <QRegularExpression>
|
|
||||||
#include "IPathMatcher.h"
|
#include "IPathMatcher.h"
|
||||||
|
|
||||||
class FSTreeMatcher : public IPathMatcher {
|
class FSTreeMatcher : public IPathMatcher {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SeparatorPrefixTree.h>
|
#include <SeparatorPrefixTree.h>
|
||||||
#include <QRegularExpression>
|
|
||||||
#include "IPathMatcher.h"
|
#include "IPathMatcher.h"
|
||||||
|
|
||||||
class MultiMatcher : public IPathMatcher {
|
class MultiMatcher : public IPathMatcher {
|
||||||
|
@ -12,6 +12,8 @@ class RegexpMatcher : public IPathMatcher {
|
|||||||
m_onlyFilenamePart = !regexp.contains('/');
|
m_onlyFilenamePart = !regexp.contains('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegexpMatcher(const QRegularExpression& regex) : m_regexp(regex) { m_onlyFilenamePart = !regex.pattern().contains('/'); }
|
||||||
|
|
||||||
RegexpMatcher& caseSensitive(bool cs = true)
|
RegexpMatcher& caseSensitive(bool cs = true)
|
||||||
{
|
{
|
||||||
if (cs) {
|
if (cs) {
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
#include <QRegularExpression>
|
|
||||||
#include "IPathMatcher.h"
|
#include "IPathMatcher.h"
|
||||||
|
|
||||||
class SimplePrefixMatcher : public IPathMatcher {
|
class SimplePrefixMatcher : public IPathMatcher {
|
||||||
|
@ -83,7 +83,8 @@ NewComponentDialog::~NewComponentDialog()
|
|||||||
void NewComponentDialog::updateDialogState()
|
void NewComponentDialog::updateDialogState()
|
||||||
{
|
{
|
||||||
auto protoUid = ui->nameTextBox->text().toLower();
|
auto protoUid = ui->nameTextBox->text().toLower();
|
||||||
protoUid.remove(QRegularExpression("[^a-z]"));
|
static const QRegularExpression s_removeChars("[^a-z]");
|
||||||
|
protoUid.remove(s_removeChars);
|
||||||
if (protoUid.isEmpty()) {
|
if (protoUid.isEmpty()) {
|
||||||
ui->uidTextBox->setPlaceholderText(originalPlaceholderText);
|
ui->uidTextBox->setPlaceholderText(originalPlaceholderText);
|
||||||
} else {
|
} else {
|
||||||
|
@ -59,9 +59,9 @@ ProfileSetupDialog::ProfileSetupDialog(MinecraftAccountPtr accountToSetup, QWidg
|
|||||||
yellowIcon = APPLICATION->getThemedIcon("status-yellow");
|
yellowIcon = APPLICATION->getThemedIcon("status-yellow");
|
||||||
badIcon = APPLICATION->getThemedIcon("status-bad");
|
badIcon = APPLICATION->getThemedIcon("status-bad");
|
||||||
|
|
||||||
QRegularExpression permittedNames("[a-zA-Z0-9_]{3,16}");
|
static const QRegularExpression s_permittedNames("[a-zA-Z0-9_]{3,16}");
|
||||||
auto nameEdit = ui->nameEdit;
|
auto nameEdit = ui->nameEdit;
|
||||||
nameEdit->setValidator(new QRegularExpressionValidator(permittedNames));
|
nameEdit->setValidator(new QRegularExpressionValidator(s_permittedNames));
|
||||||
nameEdit->setClearButtonEnabled(true);
|
nameEdit->setClearButtonEnabled(true);
|
||||||
validityAction = nameEdit->addAction(yellowIcon, QLineEdit::LeadingPosition);
|
validityAction = nameEdit->addAction(yellowIcon, QLineEdit::LeadingPosition);
|
||||||
connect(nameEdit, &QLineEdit::textEdited, this, &ProfileSetupDialog::nameEdited);
|
connect(nameEdit, &QLineEdit::textEdited, this, &ProfileSetupDialog::nameEdited);
|
||||||
@ -268,7 +268,6 @@ void ProfileSetupDialog::setupProfileFinished()
|
|||||||
QString errorMessage =
|
QString errorMessage =
|
||||||
tr("Network Error: %1\nHTTP Status: %2").arg(m_profile_task->errorString(), QString::number(m_profile_task->replyStatusCode()));
|
tr("Network Error: %1\nHTTP Status: %2").arg(m_profile_task->errorString(), QString::number(m_profile_task->replyStatusCode()));
|
||||||
|
|
||||||
|
|
||||||
if (parsedError.fullyParsed) {
|
if (parsedError.fullyParsed) {
|
||||||
errorMessage += "Path: " + parsedError.path + "\n";
|
errorMessage += "Path: " + parsedError.path + "\n";
|
||||||
errorMessage += "Error: " + parsedError.error + "\n";
|
errorMessage += "Error: " + parsedError.error + "\n";
|
||||||
|
@ -59,10 +59,10 @@ APIPage::APIPage(QWidget* parent) : QWidget(parent), ui(new Ui::APIPage)
|
|||||||
int comboBoxEntries[] = { PasteUpload::PasteType::Mclogs, PasteUpload::PasteType::NullPointer, PasteUpload::PasteType::PasteGG,
|
int comboBoxEntries[] = { PasteUpload::PasteType::Mclogs, PasteUpload::PasteType::NullPointer, PasteUpload::PasteType::PasteGG,
|
||||||
PasteUpload::PasteType::Hastebin };
|
PasteUpload::PasteType::Hastebin };
|
||||||
|
|
||||||
static QRegularExpression validUrlRegExp("https?://.+");
|
static const QRegularExpression s_validUrlRegExp("https?://.+");
|
||||||
static QRegularExpression validMSAClientID(
|
static const QRegularExpression s_validMSAClientID(
|
||||||
QRegularExpression::anchoredPattern("[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}"));
|
QRegularExpression::anchoredPattern("[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}"));
|
||||||
static QRegularExpression validFlameKey(QRegularExpression::anchoredPattern("\\$2[ayb]\\$.{56}"));
|
static const QRegularExpression s_validFlameKey(QRegularExpression::anchoredPattern("\\$2[ayb]\\$.{56}"));
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@ -75,10 +75,10 @@ APIPage::APIPage(QWidget* parent) : QWidget(parent), ui(new Ui::APIPage)
|
|||||||
// This function needs to be called even when the ComboBox's index is still in its default state.
|
// This function needs to be called even when the ComboBox's index is still in its default state.
|
||||||
updateBaseURLPlaceholder(ui->pasteTypeComboBox->currentIndex());
|
updateBaseURLPlaceholder(ui->pasteTypeComboBox->currentIndex());
|
||||||
// NOTE: this allows http://, but we replace that with https later anyway
|
// NOTE: this allows http://, but we replace that with https later anyway
|
||||||
ui->metaURL->setValidator(new QRegularExpressionValidator(validUrlRegExp, ui->metaURL));
|
ui->metaURL->setValidator(new QRegularExpressionValidator(s_validUrlRegExp, ui->metaURL));
|
||||||
ui->baseURLEntry->setValidator(new QRegularExpressionValidator(validUrlRegExp, ui->baseURLEntry));
|
ui->baseURLEntry->setValidator(new QRegularExpressionValidator(s_validUrlRegExp, ui->baseURLEntry));
|
||||||
ui->msaClientID->setValidator(new QRegularExpressionValidator(validMSAClientID, ui->msaClientID));
|
ui->msaClientID->setValidator(new QRegularExpressionValidator(s_validMSAClientID, ui->msaClientID));
|
||||||
ui->flameKey->setValidator(new QRegularExpressionValidator(validFlameKey, ui->flameKey));
|
ui->flameKey->setValidator(new QRegularExpressionValidator(s_validFlameKey, ui->flameKey));
|
||||||
|
|
||||||
ui->metaURL->setPlaceholderText(BuildConfig.META_URL);
|
ui->metaURL->setPlaceholderText(BuildConfig.META_URL);
|
||||||
ui->userAgentLineEdit->setPlaceholderText(BuildConfig.USER_AGENT);
|
ui->userAgentLineEdit->setPlaceholderText(BuildConfig.USER_AGENT);
|
||||||
|
@ -150,7 +150,8 @@ class FilterModel : public QIdentityProxyModel {
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||||
QVariant result = sourceModel()->data(mapToSource(proxyIndex), role);
|
QVariant result = sourceModel()->data(mapToSource(proxyIndex), role);
|
||||||
return result.toString().remove(QRegularExpression("\\.png$"));
|
static const QRegularExpression s_removeChars("\\.png$");
|
||||||
|
return result.toString().remove(s_removeChars);
|
||||||
}
|
}
|
||||||
if (role == Qt::DecorationRole) {
|
if (role == Qt::DecorationRole) {
|
||||||
QVariant result = sourceModel()->data(mapToSource(proxyIndex), QFileSystemModel::FilePathRole);
|
QVariant result = sourceModel()->data(mapToSource(proxyIndex), QFileSystemModel::FilePathRole);
|
||||||
|
@ -721,8 +721,8 @@ QList<GitHubReleaseAsset> PrismUpdaterApp::validReleaseArtifacts(const GitHubRel
|
|||||||
for_platform = false;
|
for_platform = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto qt_pattern = QRegularExpression("-qt(\\d+)");
|
static const QRegularExpression s_qtPattern("-qt(\\d+)");
|
||||||
auto qt_match = qt_pattern.match(asset_name);
|
auto qt_match = s_qtPattern.match(asset_name);
|
||||||
if (for_platform && qt_match.hasMatch()) {
|
if (for_platform && qt_match.hasMatch()) {
|
||||||
if (platform_qt_ver.isEmpty() || platform_qt_ver.toInt() != qt_match.captured(1).toInt()) {
|
if (platform_qt_ver.isEmpty() || platform_qt_ver.toInt() != qt_match.captured(1).toInt()) {
|
||||||
qDebug() << "Rejecting" << asset.name << "because it is not for the correct qt version" << platform_qt_ver.toInt() << "vs"
|
qDebug() << "Rejecting" << asset.name << "because it is not for the correct qt version" << platform_qt_ver.toInt() << "vs"
|
||||||
@ -1018,12 +1018,11 @@ void PrismUpdaterApp::backupAppDir()
|
|||||||
logUpdate("manifest.txt empty or missing. making best guess at files to back up.");
|
logUpdate("manifest.txt empty or missing. making best guess at files to back up.");
|
||||||
}
|
}
|
||||||
logUpdate(tr("Backing up:\n %1").arg(file_list.join(",\n ")));
|
logUpdate(tr("Backing up:\n %1").arg(file_list.join(",\n ")));
|
||||||
|
static const QRegularExpression s_replaceRegex("[" + QRegularExpression::escape("\\/:*?\"<>|") + "]");
|
||||||
auto app_dir = QDir(m_rootPath);
|
auto app_dir = QDir(m_rootPath);
|
||||||
auto backup_dir = FS::PathCombine(
|
auto backup_dir =
|
||||||
app_dir.absolutePath(),
|
FS::PathCombine(app_dir.absolutePath(),
|
||||||
QStringLiteral("backup_") +
|
QStringLiteral("backup_") + QString(m_prismVersion).replace(s_replaceRegex, QString("_")) + "-" + m_prismGitCommit);
|
||||||
QString(m_prismVersion).replace(QRegularExpression("[" + QRegularExpression::escape("\\/:*?\"<>|") + "]"), QString("_")) + "-" +
|
|
||||||
m_prismGitCommit);
|
|
||||||
FS::ensureFolderPathExists(backup_dir);
|
FS::ensureFolderPathExists(backup_dir);
|
||||||
auto backup_marker_path = FS::PathCombine(m_dataPath, ".prism_launcher_update_backup_path.txt");
|
auto backup_marker_path = FS::PathCombine(m_dataPath, ".prism_launcher_update_backup_path.txt");
|
||||||
FS::write(backup_marker_path, backup_dir.toUtf8());
|
FS::write(backup_marker_path, backup_dir.toUtf8());
|
||||||
|
@ -72,7 +72,8 @@ ApplicationId ApplicationId::fromTraditionalApp()
|
|||||||
protoId = protoId.toLower();
|
protoId = protoId.toLower();
|
||||||
#endif
|
#endif
|
||||||
auto prefix = protoId.section(QLatin1Char('/'), -1);
|
auto prefix = protoId.section(QLatin1Char('/'), -1);
|
||||||
prefix.remove(QRegularExpression("[^a-zA-Z]"));
|
static const QRegularExpression s_removeChars("[^a-zA-Z]");
|
||||||
|
prefix.remove(s_removeChars);
|
||||||
prefix.truncate(6);
|
prefix.truncate(6);
|
||||||
QByteArray idc = protoId.toUtf8();
|
QByteArray idc = protoId.toUtf8();
|
||||||
quint16 idNum = qChecksum(idc);
|
quint16 idNum = qChecksum(idc);
|
||||||
|
@ -8,19 +8,19 @@
|
|||||||
#include <QRegularExpressionMatch>
|
#include <QRegularExpressionMatch>
|
||||||
#include <QRegularExpressionMatchIterator>
|
#include <QRegularExpressionMatchIterator>
|
||||||
|
|
||||||
QRegularExpression ruleset_re = QRegularExpression(R"([#.]?(@?\w+?)\s*\{(.*?)\})", QRegularExpression::DotMatchesEverythingOption);
|
static const QRegularExpression s_rulesetRe(R"([#.]?(@?\w+?)\s*\{(.*?)\})", QRegularExpression::DotMatchesEverythingOption);
|
||||||
QRegularExpression rule_re = QRegularExpression(R"((\S+?)\s*:\s*(?:\"(.*?)(?<!\\)\"|'(.*?)(?<!\\)'|(\S+?))\s*(?:;|$))");
|
static const QRegularExpression s_ruleRe(R"((\S+?)\s*:\s*(?:\"(.*?)(?<!\\)\"|'(.*?)(?<!\\)'|(\S+?))\s*(?:;|$))");
|
||||||
|
|
||||||
QDCSS::QDCSS(QString s)
|
QDCSS::QDCSS(QString s)
|
||||||
{
|
{
|
||||||
// not much error handling over here...
|
// not much error handling over here...
|
||||||
// the original java code used indeces returned by the matcher for them, but QRE does not expose those
|
// the original java code used indeces returned by the matcher for them, but QRE does not expose those
|
||||||
QRegularExpressionMatchIterator ruleset_i = ruleset_re.globalMatch(s);
|
QRegularExpressionMatchIterator ruleset_i = s_rulesetRe.globalMatch(s);
|
||||||
while (ruleset_i.hasNext()) {
|
while (ruleset_i.hasNext()) {
|
||||||
QRegularExpressionMatch ruleset = ruleset_i.next();
|
QRegularExpressionMatch ruleset = ruleset_i.next();
|
||||||
QString selector = ruleset.captured(1);
|
QString selector = ruleset.captured(1);
|
||||||
QString rules = ruleset.captured(2);
|
QString rules = ruleset.captured(2);
|
||||||
QRegularExpressionMatchIterator rule_i = rule_re.globalMatch(rules);
|
QRegularExpressionMatchIterator rule_i = s_ruleRe.globalMatch(rules);
|
||||||
while (rule_i.hasNext()) {
|
while (rule_i.hasNext()) {
|
||||||
QRegularExpressionMatch rule = rule_i.next();
|
QRegularExpressionMatch rule = rule_i.next();
|
||||||
QString property = rule.captured(1);
|
QString property = rule.captured(1);
|
||||||
|
@ -40,6 +40,8 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
static const QRegularExpression s_distoSplitRegex("\\s+");
|
||||||
|
|
||||||
Sys::DistributionInfo Sys::read_os_release()
|
Sys::DistributionInfo Sys::read_os_release()
|
||||||
{
|
{
|
||||||
Sys::DistributionInfo out;
|
Sys::DistributionInfo out;
|
||||||
@ -145,7 +147,7 @@ void Sys::lsb_postprocess(Sys::LsbInfo& lsb, Sys::DistributionInfo& out)
|
|||||||
vers = lsb.codename;
|
vers = lsb.codename;
|
||||||
} else {
|
} else {
|
||||||
// ubuntu, debian, gentoo, scientific, slackware, ... ?
|
// ubuntu, debian, gentoo, scientific, slackware, ... ?
|
||||||
auto parts = dist.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
auto parts = dist.split(s_distoSplitRegex, Qt::SkipEmptyParts);
|
||||||
if (parts.size()) {
|
if (parts.size()) {
|
||||||
dist = parts[0];
|
dist = parts[0];
|
||||||
}
|
}
|
||||||
@ -178,7 +180,7 @@ QString Sys::_extract_distribution(const QString& x)
|
|||||||
if (release.startsWith("suse linux enterprise")) {
|
if (release.startsWith("suse linux enterprise")) {
|
||||||
return "sles";
|
return "sles";
|
||||||
}
|
}
|
||||||
QStringList list = release.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
QStringList list = release.split(s_distoSplitRegex, Qt::SkipEmptyParts);
|
||||||
if (list.size()) {
|
if (list.size()) {
|
||||||
return list[0];
|
return list[0];
|
||||||
}
|
}
|
||||||
@ -187,11 +189,11 @@ QString Sys::_extract_distribution(const QString& x)
|
|||||||
|
|
||||||
QString Sys::_extract_version(const QString& x)
|
QString Sys::_extract_version(const QString& x)
|
||||||
{
|
{
|
||||||
QRegularExpression versionish_string(QRegularExpression::anchoredPattern("\\d+(?:\\.\\d+)*$"));
|
static const QRegularExpression s_versionishString(QRegularExpression::anchoredPattern("\\d+(?:\\.\\d+)*$"));
|
||||||
QStringList list = x.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
QStringList list = x.split(s_distoSplitRegex, Qt::SkipEmptyParts);
|
||||||
for (int i = list.size() - 1; i >= 0; --i) {
|
for (int i = list.size() - 1; i >= 0; --i) {
|
||||||
QString chunk = list[i];
|
QString chunk = list[i];
|
||||||
if (versionish_string.match(chunk).hasMatch()) {
|
if (s_versionishString.match(chunk).hasMatch()) {
|
||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user