From 04a405067d80d716600c3bd51a25b6d7ad3161f8 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sat, 6 Dec 2025 14:37:39 +0500 Subject: [PATCH 1/8] fix(LaunchController): correctly communicate if asking for offline name was successful Signed-off-by: Octol1ttle --- launcher/LaunchController.cpp | 19 +++++++++++++------ launcher/LaunchController.h | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp index 2273318ee..ea9694056 100644 --- a/launcher/LaunchController.cpp +++ b/launcher/LaunchController.cpp @@ -148,8 +148,12 @@ bool LaunchController::askPlayDemo() return box.clickedButton() == demoButton; } -QString LaunchController::askOfflineName(QString playerName, bool demo, bool& ok) +QString LaunchController::askOfflineName(QString playerName, bool demo, bool* ok) { + if (ok) { + *ok = false; + } + // we ask the user for a player name QString message = tr("Choose your offline mode player name."); if (demo) { @@ -166,9 +170,12 @@ QString LaunchController::askOfflineName(QString playerName, bool demo, bool& ok return {}; } - if (const QString name = dialog.getUsername(); !name.isEmpty()) { - usedname = name; - APPLICATION->settings()->set("LastOfflinePlayerName", usedname); + const QString name = dialog.getUsername(); + usedname = name; + APPLICATION->settings()->set("LastOfflinePlayerName", usedname); + + if (ok) { + *ok = true; } return usedname; } @@ -185,7 +192,7 @@ void LaunchController::login() if (m_demo) { // we ask the user for a player name bool ok = false; - auto name = askOfflineName("Player", m_demo, ok); + auto name = askOfflineName("Player", m_demo, &ok); if (ok) { m_session = std::make_shared(); static const QRegularExpression s_removeChars("[{}-]"); @@ -264,7 +271,7 @@ void LaunchController::login() bool ok = false; QString name; if (m_offlineName.isEmpty()) { - name = askOfflineName(m_session->player_name, m_session->demo, ok); + name = askOfflineName(m_session->player_name, m_session->demo, &ok); if (!ok) { tryagain = false; break; diff --git a/launcher/LaunchController.h b/launcher/LaunchController.h index af57994f5..50b72eb18 100644 --- a/launcher/LaunchController.h +++ b/launcher/LaunchController.h @@ -77,7 +77,7 @@ class LaunchController : public Task { void launchInstance(); void decideAccount(); bool askPlayDemo(); - QString askOfflineName(QString playerName, bool demo, bool& ok); + QString askOfflineName(QString playerName, bool demo, bool* ok = nullptr); bool reauthenticateAccount(MinecraftAccountPtr account); private slots: From 86fd58e6cbe6683e0482646041c7695eb651d9fb Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sat, 6 Dec 2025 16:34:59 +0500 Subject: [PATCH 2/8] Apply suggestions from code review Co-authored-by: TheKodeToad Signed-off-by: Octol1ttle --- launcher/LaunchController.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp index ea9694056..cbea045fc 100644 --- a/launcher/LaunchController.cpp +++ b/launcher/LaunchController.cpp @@ -150,7 +150,7 @@ bool LaunchController::askPlayDemo() QString LaunchController::askOfflineName(QString playerName, bool demo, bool* ok) { - if (ok) { + if (ok != nullptr) { *ok = false; } @@ -174,7 +174,7 @@ QString LaunchController::askOfflineName(QString playerName, bool demo, bool* ok usedname = name; APPLICATION->settings()->set("LastOfflinePlayerName", usedname); - if (ok) { + if (ok != nullptr) { *ok = true; } return usedname; From 61f94f50c833f7ced47ece4b357a53576447c52a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 7 Dec 2025 00:31:09 +0000 Subject: [PATCH 3/8] chore(nix): update lockfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/2fad6eac6077f03fe109c4d4eb171cf96791faa4?narHash=sha256-sKoIWfnijJ0%2B9e4wRvIgm/HgE27bzwQxcEmo2J/gNpI%3D' (2025-11-27) → 'github:NixOS/nixpkgs/f61125a668a320878494449750330ca58b78c557?narHash=sha256-BmPWzogsG2GsXZtlT%2BMTcAWeDK5hkbGRZTeZNW42fwA%3D' (2025-12-05) --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 5f4817048..86b1d61e9 100644 --- a/flake.lock +++ b/flake.lock @@ -18,11 +18,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1764242076, - "narHash": "sha256-sKoIWfnijJ0+9e4wRvIgm/HgE27bzwQxcEmo2J/gNpI=", + "lastModified": 1764950072, + "narHash": "sha256-BmPWzogsG2GsXZtlT+MTcAWeDK5hkbGRZTeZNW42fwA=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "2fad6eac6077f03fe109c4d4eb171cf96791faa4", + "rev": "f61125a668a320878494449750330ca58b78c557", "type": "github" }, "original": { From 904e8ef1ed6a16065f47ac0fee753b7d65d18026 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sun, 7 Dec 2025 12:30:49 +0500 Subject: [PATCH 4/8] clang-format: specify access modifier offset used in codebase Signed-off-by: Octol1ttle --- .clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-format b/.clang-format index 114bcba50..a0b93351f 100644 --- a/.clang-format +++ b/.clang-format @@ -5,6 +5,7 @@ AllowShortIfStatementsOnASingleLine: false ColumnLimit: 140 --- Language: Cpp +AccessModifierOffset: -1 AlignConsecutiveMacros: None AlignConsecutiveAssignments: None BraceWrapping: From 1344dcb27e12005212aeb9fbd36b6cb30ad6faec Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sun, 7 Dec 2025 12:45:35 +0500 Subject: [PATCH 5/8] EditorConfig: set continuation indent size in CMakeLists for IntelliJ Signed-off-by: Octol1ttle --- .editorconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index 56166b207..52510c515 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,3 +6,6 @@ root = true # C++ Code Style settings [*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}] cpp_generate_documentation_comments = doxygen_slash_star + +[CMakeLists.txt] +ij_continuation_indent_size = 4 \ No newline at end of file From c9d3f050a16d9b8cf8314c332d05c7be6fd88978 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sun, 7 Dec 2025 12:09:41 +0000 Subject: [PATCH 6/8] EditorConfig essentials Signed-off-by: TheKodeToad --- .editorconfig | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/.editorconfig b/.editorconfig index 52510c515..03b99379b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,11 +1,22 @@ -# EditorConfig specs and documentation: https://EditorConfig.org - -# top-most EditorConfig file -root = true - -# C++ Code Style settings -[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}] -cpp_generate_documentation_comments = doxygen_slash_star - -[CMakeLists.txt] -ij_continuation_indent_size = 4 \ No newline at end of file +# EditorConfig specs and documentation: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{yml,nix}] +indent_size = 2 + +# C++ Code Style settings +[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}] +cpp_generate_documentation_comments = doxygen_slash_star + +[CMakeLists.txt] +ij_continuation_indent_size = 4 From fd3ae85d45a34616fbe75cf53abc514b82da781b Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sun, 7 Dec 2025 12:56:30 +0000 Subject: [PATCH 7/8] Simplify MessageLevel::Enum -> MessageLevel Signed-off-by: TheKodeToad --- launcher/Application.cpp | 2 +- launcher/LoggedProcess.h | 2 +- launcher/MessageLevel.cpp | 12 ++++---- launcher/MessageLevel.h | 12 ++++---- launcher/launch/LaunchStep.h | 4 +-- launcher/launch/LaunchTask.cpp | 8 +++--- launcher/launch/LaunchTask.h | 6 ++-- launcher/launch/LogModel.cpp | 6 ++-- launcher/launch/LogModel.h | 6 ++-- launcher/launch/steps/TextPrint.cpp | 4 +-- launcher/launch/steps/TextPrint.h | 6 ++-- launcher/logs/LogParser.cpp | 6 ++-- launcher/logs/LogParser.h | 4 +-- .../minecraft/launch/LauncherPartLaunch.cpp | 2 +- launcher/ui/pages/instance/LogPage.cpp | 4 +-- launcher/ui/pages/instance/OtherLogsPage.cpp | 6 ++-- launcher/ui/themes/CustomTheme.cpp | 2 +- launcher/ui/themes/ITheme.h | 4 +-- launcher/ui/widgets/AppearanceWidget.cpp | 2 +- tests/XmlLogs_test.cpp | 28 +++++++++---------- 20 files changed, 62 insertions(+), 64 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 0ed1cc71d..ac6d7a114 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -241,7 +241,7 @@ void appDebugOutput(QtMsgType type, const QMessageLogContext& context, const QSt QString out = qFormatLogMessage(type, context, msg); if (APPLICATION->logModel) { - APPLICATION->logModel->append(MessageLevel::getLevel(type), out); + APPLICATION->logModel->append(messageLevelFromQtMsgType(type), out); } out += QChar::LineFeed; diff --git a/launcher/LoggedProcess.h b/launcher/LoggedProcess.h index c01d464d1..ce35b27e8 100644 --- a/launcher/LoggedProcess.h +++ b/launcher/LoggedProcess.h @@ -58,7 +58,7 @@ class LoggedProcess : public QProcess { void setDetachable(bool detachable); signals: - void log(QStringList lines, MessageLevel::Enum level); + void log(QStringList lines, MessageLevel level); void stateChanged(LoggedProcess::State state); public slots: diff --git a/launcher/MessageLevel.cpp b/launcher/MessageLevel.cpp index c1c190c72..913902517 100644 --- a/launcher/MessageLevel.cpp +++ b/launcher/MessageLevel.cpp @@ -1,6 +1,6 @@ #include "MessageLevel.h" -MessageLevel::Enum MessageLevel::getLevel(const QString& levelName) +MessageLevel messageLevelFromName(const QString& levelName) { QString name = levelName.toUpper(); if (name == "LAUNCHER") @@ -25,7 +25,7 @@ MessageLevel::Enum MessageLevel::getLevel(const QString& levelName) return MessageLevel::Unknown; } -MessageLevel::Enum MessageLevel::getLevel(QtMsgType type) +MessageLevel messageLevelFromQtMsgType(QtMsgType type) { switch (type) { case QtDebugMsg: @@ -43,19 +43,19 @@ MessageLevel::Enum MessageLevel::getLevel(QtMsgType type) } } -MessageLevel::Enum MessageLevel::fromLine(QString& line) +MessageLevel messageLevelFromLine(QString& line) { // Level prefix int endmark = line.indexOf("]!"); if (line.startsWith("!![") && endmark != -1) { - auto level = MessageLevel::getLevel(line.left(endmark).mid(3)); + auto level = messageLevelFromName(line.left(endmark).mid(3)); line = line.mid(endmark + 2); return level; } return MessageLevel::Unknown; } -MessageLevel::Enum MessageLevel::fromLauncherLine(QString& line) +MessageLevel messageLevelFromLauncherLine(QString& line) { // Level prefix int startMark = 0; @@ -63,7 +63,7 @@ MessageLevel::Enum MessageLevel::fromLauncherLine(QString& line) ++startMark; int endmark = line.indexOf(":"); if (startMark < line.size() && endmark != -1) { - auto level = MessageLevel::getLevel(line.left(endmark).mid(startMark)); + auto level = messageLevelFromName(line.left(endmark).mid(startMark)); line = line.mid(endmark + 2); return level; } diff --git a/launcher/MessageLevel.h b/launcher/MessageLevel.h index 4c840dfc1..a79c36d02 100644 --- a/launcher/MessageLevel.h +++ b/launcher/MessageLevel.h @@ -7,8 +7,7 @@ * @brief the MessageLevel Enum * defines what level a log message is */ -namespace MessageLevel { -enum Enum { +enum class MessageLevel { Unknown, /**< No idea what this is or where it came from */ StdOut, /**< Undetermined stderr messages */ StdErr, /**< Undetermined stdout messages */ @@ -21,12 +20,11 @@ enum Enum { Error, /**< Errors */ Fatal, /**< Fatal Errors */ }; -MessageLevel::Enum getLevel(const QString& levelName); -MessageLevel::Enum getLevel(QtMsgType type); +MessageLevel messageLevelFromName(const QString& levelName); +MessageLevel messageLevelFromQtMsgType(QtMsgType type); /* Get message level from a line. Line is modified if it was successful. */ -MessageLevel::Enum fromLine(QString& line); +MessageLevel messageLevelFromLine(QString& line); /* Get message level from a line from the launcher log. Line is modified if it was successful. */ -MessageLevel::Enum fromLauncherLine(QString& line); -} // namespace MessageLevel +MessageLevel messageLevelFromLauncherLine(QString& line); diff --git a/launcher/launch/LaunchStep.h b/launcher/launch/LaunchStep.h index d49d7545b..80dcd31e9 100644 --- a/launcher/launch/LaunchStep.h +++ b/launcher/launch/LaunchStep.h @@ -28,8 +28,8 @@ class LaunchStep : public Task { virtual ~LaunchStep() = default; signals: - void logLines(QStringList lines, MessageLevel::Enum level); - void logLine(QString line, MessageLevel::Enum level); + void logLines(QStringList lines, MessageLevel level); + void logLine(QString line, MessageLevel level); void readyForLaunch(); void progressReportingRequest(); diff --git a/launcher/launch/LaunchTask.cpp b/launcher/launch/LaunchTask.cpp index 4468a2a77..68e706c11 100644 --- a/launcher/launch/LaunchTask.cpp +++ b/launcher/launch/LaunchTask.cpp @@ -214,7 +214,7 @@ shared_qobject_ptr LaunchTask::getLogModel() return m_logModel; } -bool LaunchTask::parseXmlLogs(QString const& line, MessageLevel::Enum level) +bool LaunchTask::parseXmlLogs(QString const& line, MessageLevel level) { LogParser* parser; switch (level) { @@ -254,7 +254,7 @@ bool LaunchTask::parseXmlLogs(QString const& line, MessageLevel::Enum level) } else if (std::holds_alternative(item)) { auto msg = std::get(item).message; - MessageLevel::Enum newLevel = MessageLevel::fromLine(msg); + MessageLevel newLevel = messageLevelFromLine(msg); if (newLevel == MessageLevel::Unknown) newLevel = LogParser::guessLevel(line); @@ -271,14 +271,14 @@ bool LaunchTask::parseXmlLogs(QString const& line, MessageLevel::Enum level) return true; } -void LaunchTask::onLogLines(const QStringList& lines, MessageLevel::Enum defaultLevel) +void LaunchTask::onLogLines(const QStringList& lines, MessageLevel defaultLevel) { for (auto& line : lines) { onLogLine(line, defaultLevel); } } -void LaunchTask::onLogLine(QString line, MessageLevel::Enum level) +void LaunchTask::onLogLine(QString line, MessageLevel level) { if (parseXmlLogs(line, level)) { return; diff --git a/launcher/launch/LaunchTask.h b/launcher/launch/LaunchTask.h index 5effab980..db7e453e4 100644 --- a/launcher/launch/LaunchTask.h +++ b/launcher/launch/LaunchTask.h @@ -106,8 +106,8 @@ class LaunchTask : public Task { void requestLogging(); public slots: - void onLogLines(const QStringList& lines, MessageLevel::Enum defaultLevel = MessageLevel::Launcher); - void onLogLine(QString line, MessageLevel::Enum defaultLevel = MessageLevel::Launcher); + void onLogLines(const QStringList& lines, MessageLevel defaultLevel = MessageLevel::Launcher); + void onLogLine(QString line, MessageLevel defaultLevel = MessageLevel::Launcher); void onReadyForLaunch(); void onStepFinished(); void onProgressReportingRequested(); @@ -116,7 +116,7 @@ class LaunchTask : public Task { void finalizeSteps(bool successful, const QString& error); protected: - bool parseXmlLogs(QString const& line, MessageLevel::Enum level); + bool parseXmlLogs(QString const& line, MessageLevel level); protected: /* data */ MinecraftInstancePtr m_instance; diff --git a/launcher/launch/LogModel.cpp b/launcher/launch/LogModel.cpp index f13e2c27f..117867c1d 100644 --- a/launcher/launch/LogModel.cpp +++ b/launcher/launch/LogModel.cpp @@ -24,13 +24,13 @@ QVariant LogModel::data(const QModelIndex& index, int role) const return m_content[realRow].line; } if (role == LevelRole) { - return m_content[realRow].level; + return static_cast(m_content[realRow].level); } return QVariant(); } -void LogModel::append(MessageLevel::Enum level, QString line) +void LogModel::append(MessageLevel level, QString line) { if (m_suspended) { return; @@ -167,7 +167,7 @@ bool LogModel::isOverFlow() return m_numLines >= m_maxLines && m_stopOnOverflow; } -MessageLevel::Enum LogModel::previousLevel() +MessageLevel LogModel::previousLevel() { if (m_numLines > 0) { return m_content[m_numLines - 1].level; diff --git a/launcher/launch/LogModel.h b/launcher/launch/LogModel.h index 4521bac17..847a41f5f 100644 --- a/launcher/launch/LogModel.h +++ b/launcher/launch/LogModel.h @@ -12,7 +12,7 @@ class LogModel : public QAbstractListModel { int rowCount(const QModelIndex& parent = QModelIndex()) const; QVariant data(const QModelIndex& index, int role) const; - void append(MessageLevel::Enum, QString line); + void append(MessageLevel, QString line); void clear(); void suspend(bool suspend); @@ -31,13 +31,13 @@ class LogModel : public QAbstractListModel { void setColorLines(bool state); bool colorLines() const; - MessageLevel::Enum previousLevel(); + MessageLevel previousLevel(); enum Roles { LevelRole = Qt::UserRole }; private /* types */: struct entry { - MessageLevel::Enum level = MessageLevel::Enum::Unknown; + MessageLevel level = MessageLevel::Unknown; QString line; }; diff --git a/launcher/launch/steps/TextPrint.cpp b/launcher/launch/steps/TextPrint.cpp index 0dec35b79..53aff807e 100644 --- a/launcher/launch/steps/TextPrint.cpp +++ b/launcher/launch/steps/TextPrint.cpp @@ -1,11 +1,11 @@ #include "TextPrint.h" -TextPrint::TextPrint(LaunchTask* parent, const QStringList& lines, MessageLevel::Enum level) : LaunchStep(parent) +TextPrint::TextPrint(LaunchTask* parent, const QStringList& lines, MessageLevel level) : LaunchStep(parent) { m_lines = lines; m_level = level; } -TextPrint::TextPrint(LaunchTask* parent, const QString& line, MessageLevel::Enum level) : LaunchStep(parent) +TextPrint::TextPrint(LaunchTask* parent, const QString& line, MessageLevel level) : LaunchStep(parent) { m_lines.append(line); m_level = level; diff --git a/launcher/launch/steps/TextPrint.h b/launcher/launch/steps/TextPrint.h index a96c2f887..4479a260a 100644 --- a/launcher/launch/steps/TextPrint.h +++ b/launcher/launch/steps/TextPrint.h @@ -26,8 +26,8 @@ class TextPrint : public LaunchStep { Q_OBJECT public: - explicit TextPrint(LaunchTask* parent, const QStringList& lines, MessageLevel::Enum level); - explicit TextPrint(LaunchTask* parent, const QString& line, MessageLevel::Enum level); + explicit TextPrint(LaunchTask* parent, const QStringList& lines, MessageLevel level); + explicit TextPrint(LaunchTask* parent, const QString& line, MessageLevel level); virtual ~TextPrint() {}; virtual void executeTask(); @@ -36,5 +36,5 @@ class TextPrint : public LaunchStep { private: QStringList m_lines; - MessageLevel::Enum m_level; + MessageLevel m_level; }; diff --git a/launcher/logs/LogParser.cpp b/launcher/logs/LogParser.cpp index 962e5184f..b33f9546f 100644 --- a/launcher/logs/LogParser.cpp +++ b/launcher/logs/LogParser.cpp @@ -60,7 +60,7 @@ std::optional LogParser::parseAttributes() entry.timestamp = QDateTime::fromSecsSinceEpoch(value.trimmed().toLongLong()); } else if (name == "level"_L1) { entry.levelText = value.trimmed().toString(); - entry.level = MessageLevel::getLevel(entry.levelText); + entry.level = messageLevelFromName(entry.levelText); } else if (name == "thread"_L1) { entry.thread = value.trimmed().toString(); } @@ -320,7 +320,7 @@ std::optional LogParser::parseLog4J() throw std::runtime_error("unreachable: already verified this was a complete log4j:Event"); } -MessageLevel::Enum LogParser::guessLevel(const QString& line) +MessageLevel LogParser::guessLevel(const QString& line) { static const QRegularExpression LINE_WITH_LEVEL("^\\[(?[0-9:]+)\\] \\[[^/]+/(?[^\\]]+)\\]"); auto match = LINE_WITH_LEVEL.match(line); @@ -329,7 +329,7 @@ MessageLevel::Enum LogParser::guessLevel(const QString& line) QString timestamp = match.captured("timestamp"); QString levelStr = match.captured("level"); - return MessageLevel::getLevel(levelStr); + return messageLevelFromName(levelStr); } else { // Old style forge logs if (line.contains("[INFO]") || line.contains("[CONFIG]") || line.contains("[FINE]") || line.contains("[FINER]") || diff --git a/launcher/logs/LogParser.h b/launcher/logs/LogParser.h index 609913d3b..9741a9809 100644 --- a/launcher/logs/LogParser.h +++ b/launcher/logs/LogParser.h @@ -31,7 +31,7 @@ class LogParser { public: struct LogEntry { QString logger; - MessageLevel::Enum level; + MessageLevel level; QString levelText; QDateTime timestamp; QString thread; @@ -59,7 +59,7 @@ class LogParser { std::optional getError(); /// guess log level from a line of game log - static MessageLevel::Enum guessLevel(const QString& line); + static MessageLevel guessLevel(const QString& line); protected: std::optional parseAttributes(); diff --git a/launcher/minecraft/launch/LauncherPartLaunch.cpp b/launcher/minecraft/launch/LauncherPartLaunch.cpp index d824c904b..ee754dc85 100644 --- a/launcher/minecraft/launch/LauncherPartLaunch.cpp +++ b/launcher/minecraft/launch/LauncherPartLaunch.cpp @@ -56,7 +56,7 @@ LauncherPartLaunch::LauncherPartLaunch(LaunchTask* parent) static const QRegularExpression s_settingUser(".*Setting user.+", QRegularExpression::CaseInsensitiveOption); std::shared_ptr connection{ new QMetaObject::Connection }; *connection = connect(&m_process, &LoggedProcess::log, this, - [connection](const QStringList& lines, [[maybe_unused]] MessageLevel::Enum level) { + [connection](const QStringList& lines, [[maybe_unused]] MessageLevel level) { qDebug() << lines; if (lines.filter(s_settingUser).length() != 0) { APPLICATION->closeAllWindows(); diff --git a/launcher/ui/pages/instance/LogPage.cpp b/launcher/ui/pages/instance/LogPage.cpp index 928368236..02be853c0 100644 --- a/launcher/ui/pages/instance/LogPage.cpp +++ b/launcher/ui/pages/instance/LogPage.cpp @@ -60,7 +60,7 @@ QVariant LogFormatProxyModel::data(const QModelIndex& index, int role) const case Qt::FontRole: return m_font; case Qt::ForegroundRole: { - auto level = static_cast(QIdentityProxyModel::data(index, LogModel::LevelRole).toInt()); + auto level = static_cast(QIdentityProxyModel::data(index, LogModel::LevelRole).toInt()); QColor result = colors.foreground.value(level); if (result.isValid()) @@ -69,7 +69,7 @@ QVariant LogFormatProxyModel::data(const QModelIndex& index, int role) const break; } case Qt::BackgroundRole: { - auto level = static_cast(QIdentityProxyModel::data(index, LogModel::LevelRole).toInt()); + auto level = static_cast(QIdentityProxyModel::data(index, LogModel::LevelRole).toInt()); QColor result = colors.background.value(level); if (result.isValid()) diff --git a/launcher/ui/pages/instance/OtherLogsPage.cpp b/launcher/ui/pages/instance/OtherLogsPage.cpp index 2449ecb2b..c8d0c3346 100644 --- a/launcher/ui/pages/instance/OtherLogsPage.cpp +++ b/launcher/ui/pages/instance/OtherLogsPage.cpp @@ -274,18 +274,18 @@ void OtherLogsPage::reload() showTooBig(); return; } - MessageLevel::Enum last = MessageLevel::Unknown; + MessageLevel last = MessageLevel::Unknown; auto handleLine = [this, &last](QString line) { if (line.isEmpty()) return false; if (line.back() == '\n') line = line.remove(line.size() - 1, 1); - MessageLevel::Enum level = MessageLevel::Unknown; + MessageLevel level = MessageLevel::Unknown; QString lineTemp = line; // don't edit out the time and level for clarity if (!m_instance) { - level = MessageLevel::fromLauncherLine(lineTemp); + level = messageLevelFromLauncherLine(lineTemp); } else { level = LogParser::guessLevel(line); diff --git a/launcher/ui/themes/CustomTheme.cpp b/launcher/ui/themes/CustomTheme.cpp index 560d0ece8..e32e53381 100644 --- a/launcher/ui/themes/CustomTheme.cpp +++ b/launcher/ui/themes/CustomTheme.cpp @@ -229,7 +229,7 @@ bool CustomTheme::read(const QString& path, bool& hasCustomLogColors) hasCustomLogColors = true; auto logColorsRoot = Json::requireObject(root, "logColors"); - auto readAndSetLogColor = [this, readColor, logColorsRoot](MessageLevel::Enum level, bool fg, const QString& colorName) { + auto readAndSetLogColor = [this, readColor, logColorsRoot](MessageLevel level, bool fg, const QString& colorName) { auto color = readColor(logColorsRoot, colorName); if (color.isValid()) { if (fg) diff --git a/launcher/ui/themes/ITheme.h b/launcher/ui/themes/ITheme.h index a3dd14d09..6e0e613f9 100644 --- a/launcher/ui/themes/ITheme.h +++ b/launcher/ui/themes/ITheme.h @@ -42,8 +42,8 @@ class QStyle; struct LogColors { - QMap background; - QMap foreground; + QMap background; + QMap foreground; }; // TODO: rename to Theme; this is not an interface as it contains method implementations diff --git a/launcher/ui/widgets/AppearanceWidget.cpp b/launcher/ui/widgets/AppearanceWidget.cpp index cfe3b8c0d..5ab622ef9 100644 --- a/launcher/ui/widgets/AppearanceWidget.cpp +++ b/launcher/ui/widgets/AppearanceWidget.cpp @@ -232,7 +232,7 @@ void AppearanceWidget::updateConsolePreview() m_ui->consolePreview->clear(); m_defaultFormat.setFont(QFont(fontFamily, fontSize)); - auto print = [this, colors](const QString& message, MessageLevel::Enum level) { + auto print = [this, colors](const QString& message, MessageLevel level) { QTextCharFormat format(m_defaultFormat); QColor bg = colors.background.value(level); diff --git a/tests/XmlLogs_test.cpp b/tests/XmlLogs_test.cpp index 9e7aed974..75a2dd90c 100644 --- a/tests/XmlLogs_test.cpp +++ b/tests/XmlLogs_test.cpp @@ -47,10 +47,10 @@ class XmlLogParseTest : public QObject { QStringList shortTextLevels_s = QString::fromUtf8(FS::read(FS::PathCombine(source, "vanilla-1.21.5-levels.txt"))) .split(QRegularExpression("\n|\r\n|\r"), Qt::SkipEmptyParts); - QList shortTextLevels; + QList shortTextLevels; shortTextLevels.reserve(24); std::transform(shortTextLevels_s.cbegin(), shortTextLevels_s.cend(), std::back_inserter(shortTextLevels), - [](const QString& line) { return MessageLevel::getLevel(line.trimmed()); }); + [](const QString& line) { return messageLevelFromName(line.trimmed()); }); QString longXml = QString::fromUtf8(FS::read(FS::PathCombine(source, "TerraFirmaGreg-Modern-forge.xml.log"))); QString longText = QString::fromUtf8(FS::read(FS::PathCombine(source, "TerraFirmaGreg-Modern-forge.text.log"))); @@ -59,18 +59,18 @@ class XmlLogParseTest : public QObject { QStringList longTextLevelsXml_s = QString::fromUtf8(FS::read(FS::PathCombine(source, "TerraFirmaGreg-Modern-xml-levels.txt"))) .split(QRegularExpression("\n|\r\n|\r"), Qt::SkipEmptyParts); - QList longTextLevelsPlain; + QList longTextLevelsPlain; longTextLevelsPlain.reserve(974); std::transform(longTextLevels_s.cbegin(), longTextLevels_s.cend(), std::back_inserter(longTextLevelsPlain), - [](const QString& line) { return MessageLevel::getLevel(line.trimmed()); }); - QList longTextLevelsXml; + [](const QString& line) { return messageLevelFromName(line.trimmed()); }); + QList longTextLevelsXml; longTextLevelsXml.reserve(896); std::transform(longTextLevelsXml_s.cbegin(), longTextLevelsXml_s.cend(), std::back_inserter(longTextLevelsXml), - [](const QString& line) { return MessageLevel::getLevel(line.trimmed()); }); + [](const QString& line) { return messageLevelFromName(line.trimmed()); }); QTest::addColumn("log"); QTest::addColumn("num_entries"); - QTest::addColumn>("entry_levels"); + QTest::addColumn>("entry_levels"); QTest::newRow("short-vanilla-plain") << shortText << 25 << shortTextLevels; QTest::newRow("short-vanilla-xml") << shortXml << 25 << shortTextLevels; @@ -82,9 +82,9 @@ class XmlLogParseTest : public QObject { { QFETCH(QString, log); QFETCH(int, num_entries); - QFETCH(QList, entry_levels); + QFETCH(QList, entry_levels); - QList> entries = {}; + QList> entries = {}; QBENCHMARK { @@ -93,10 +93,10 @@ class XmlLogParseTest : public QObject { QCOMPARE(entries.length(), num_entries); - QList levels = {}; + QList levels = {}; std::transform(entries.cbegin(), entries.cend(), std::back_inserter(levels), - [](std::pair entry) { return entry.first; }); + [](std::pair entry) { return entry.first; }); QCOMPARE(levels, entry_levels); } @@ -104,10 +104,10 @@ class XmlLogParseTest : public QObject { private: LogParser m_parser; - QList> parseLines(const QStringList& lines) + QList> parseLines(const QStringList& lines) { - QList> out; - MessageLevel::Enum last = MessageLevel::Unknown; + QList> out; + MessageLevel last = MessageLevel::Unknown; for (const auto& line : lines) { m_parser.appendLine(line); From de5c7bac723d674dde779069cb6b0cac8986d557 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sun, 7 Dec 2025 14:32:58 +0000 Subject: [PATCH 8/8] Simplify IndexedVersionType::VersionType -> IndexedVersionType Signed-off-by: TheKodeToad --- launcher/minecraft/mod/Mod.cpp | 4 +-- launcher/modplatform/ModIndex.cpp | 34 ++++--------------- launcher/modplatform/ModIndex.h | 32 +++-------------- launcher/modplatform/flame/FlameModIndex.cpp | 13 +++---- .../modrinth/ModrinthPackIndex.cpp | 2 +- launcher/modplatform/packwiz/Packwiz.cpp | 4 +-- .../ui/dialogs/ResourceDownloadDialog.cpp | 3 +- launcher/ui/dialogs/ResourceUpdateDialog.cpp | 4 +-- .../ui/pages/modplatform/ResourcePage.cpp | 4 +-- launcher/ui/widgets/ModFilterWidget.cpp | 8 ++--- 10 files changed, 33 insertions(+), 75 deletions(-) diff --git a/launcher/minecraft/mod/Mod.cpp b/launcher/minecraft/mod/Mod.cpp index e9ca2e682..7aadb04a8 100644 --- a/launcher/minecraft/mod/Mod.cpp +++ b/launcher/minecraft/mod/Mod.cpp @@ -195,9 +195,9 @@ auto Mod::mcVersions() const -> QString auto Mod::releaseType() const -> QString { if (metadata()) - return metadata()->releaseType.toString(); + return ModPlatform::indexedVersionTypeToString(metadata()->releaseType); - return ModPlatform::IndexedVersionType().toString(); + return ModPlatform::indexedVersionTypeToString(ModPlatform::IndexedVersionType::Unknown); } auto Mod::description() const -> QString diff --git a/launcher/modplatform/ModIndex.cpp b/launcher/modplatform/ModIndex.cpp index 5e8759f97..5750b631c 100644 --- a/launcher/modplatform/ModIndex.cpp +++ b/launcher/modplatform/ModIndex.cpp @@ -25,10 +25,10 @@ namespace ModPlatform { -static const QMap s_indexed_version_type_names = { - { "release", IndexedVersionType::VersionType::Release }, - { "beta", IndexedVersionType::VersionType::Beta }, - { "alpha", IndexedVersionType::VersionType::Alpha } +static const QMap s_indexed_version_type_names = { + { "release", IndexedVersionType::Release }, + { "beta", IndexedVersionType::Beta }, + { "alpha", IndexedVersionType::Alpha } }; static const QList loaderList = { NeoForge, Forge, Cauldron, LiteLoader, Quilt, Fabric, @@ -45,32 +45,12 @@ QList modLoaderTypesToList(ModLoaderTypes flags) return flagList; } -IndexedVersionType::IndexedVersionType(const QString& type) : IndexedVersionType(enumFromString(type)) {} - -IndexedVersionType::IndexedVersionType(const IndexedVersionType::VersionType& type) -{ - m_type = type; -} - -IndexedVersionType::IndexedVersionType(const IndexedVersionType& other) -{ - m_type = other.m_type; -} - -IndexedVersionType& IndexedVersionType::operator=(const IndexedVersionType& other) -{ - m_type = other.m_type; - return *this; -} - -const QString IndexedVersionType::toString(const IndexedVersionType::VersionType& type) -{ +QString indexedVersionTypeToString(IndexedVersionType type) { return s_indexed_version_type_names.key(type, "unknown"); } -IndexedVersionType::VersionType IndexedVersionType::enumFromString(const QString& type) -{ - return s_indexed_version_type_names.value(type, IndexedVersionType::VersionType::Unknown); +IndexedVersionType indexedVersionTypeFromString(const QString& type) { + return s_indexed_version_type_names.value(type, IndexedVersionType::Unknown); } const char* ProviderCapabilities::name(ResourceProvider p) diff --git a/launcher/modplatform/ModIndex.h b/launcher/modplatform/ModIndex.h index 6cff8c622..d6283a074 100644 --- a/launcher/modplatform/ModIndex.h +++ b/launcher/modplatform/ModIndex.h @@ -74,33 +74,9 @@ struct DonationData { QString url; }; -struct IndexedVersionType { - enum class VersionType { Release = 1, Beta, Alpha, Unknown }; - IndexedVersionType(const QString& type); - IndexedVersionType(const IndexedVersionType::VersionType& type); - IndexedVersionType(const IndexedVersionType& type); - IndexedVersionType() : IndexedVersionType(IndexedVersionType::VersionType::Unknown) {} - static const QString toString(const IndexedVersionType::VersionType& type); - static IndexedVersionType::VersionType enumFromString(const QString& type); - bool isValid() const { return m_type != IndexedVersionType::VersionType::Unknown; } - IndexedVersionType& operator=(const IndexedVersionType& other); - bool operator==(const IndexedVersionType& other) const { return m_type == other.m_type; } - bool operator==(const IndexedVersionType::VersionType& type) const { return m_type == type; } - bool operator!=(const IndexedVersionType& other) const { return m_type != other.m_type; } - bool operator!=(const IndexedVersionType::VersionType& type) const { return m_type != type; } - bool operator<(const IndexedVersionType& other) const { return m_type < other.m_type; } - bool operator<(const IndexedVersionType::VersionType& type) const { return m_type < type; } - bool operator<=(const IndexedVersionType& other) const { return m_type <= other.m_type; } - bool operator<=(const IndexedVersionType::VersionType& type) const { return m_type <= type; } - bool operator>(const IndexedVersionType& other) const { return m_type > other.m_type; } - bool operator>(const IndexedVersionType::VersionType& type) const { return m_type > type; } - bool operator>=(const IndexedVersionType& other) const { return m_type >= other.m_type; } - bool operator>=(const IndexedVersionType::VersionType& type) const { return m_type >= type; } - - QString toString() const { return toString(m_type); } - - IndexedVersionType::VersionType m_type; -}; +enum class IndexedVersionType { Unknown, Release = 1, Beta, Alpha }; +IndexedVersionType indexedVersionTypeFromString(const QString& type); +QString indexedVersionTypeToString(IndexedVersionType type); struct Dependency { QVariant addonId; @@ -131,7 +107,7 @@ struct IndexedVersion { QString getVersionDisplayString() const { - auto release_type = version_type.isValid() ? QString(" [%1]").arg(version_type.toString()) : ""; + auto release_type = version_type != IndexedVersionType::Unknown ? QString(" [%1]").arg(indexedVersionTypeToString(version_type)) : ""; auto versionStr = !version.contains(version_number) ? version_number : ""; QString gameVersion = ""; for (auto v : mcVersion) { diff --git a/launcher/modplatform/flame/FlameModIndex.cpp b/launcher/modplatform/flame/FlameModIndex.cpp index a01de847b..122f23bd0 100644 --- a/launcher/modplatform/flame/FlameModIndex.cpp +++ b/launcher/modplatform/flame/FlameModIndex.cpp @@ -143,21 +143,22 @@ auto FlameMod::loadIndexedPackVersion(QJsonObject& obj, bool load_changelog) -> file.fileName = Json::requireString(obj, "fileName"); file.fileName = FS::RemoveInvalidPathChars(file.fileName); - ModPlatform::IndexedVersionType::VersionType ver_type; + ModPlatform::IndexedVersionType ver_type; switch (Json::requireInteger(obj, "releaseType")) { case 1: - ver_type = ModPlatform::IndexedVersionType::VersionType::Release; + ver_type = ModPlatform::IndexedVersionType::Release; break; case 2: - ver_type = ModPlatform::IndexedVersionType::VersionType::Beta; + ver_type = ModPlatform::IndexedVersionType::Beta; break; case 3: - ver_type = ModPlatform::IndexedVersionType::VersionType::Alpha; + ver_type = ModPlatform::IndexedVersionType::Alpha; break; default: - ver_type = ModPlatform::IndexedVersionType::VersionType::Unknown; + ver_type = ModPlatform::IndexedVersionType::Unknown; + break; } - file.version_type = ModPlatform::IndexedVersionType(ver_type); + file.version_type = ver_type; auto hash_list = obj["hashes"].toArray(); for (auto h : hash_list) { diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp index 2c8ce76b9..dd8be5cae 100644 --- a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp +++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp @@ -145,7 +145,7 @@ ModPlatform::IndexedVersion Modrinth::loadIndexedPackVersion(QJsonObject& obj, Q } file.version = Json::requireString(obj, "name"); file.version_number = Json::requireString(obj, "version_number"); - file.version_type = ModPlatform::IndexedVersionType(Json::requireString(obj, "version_type")); + file.version_type = ModPlatform::indexedVersionTypeFromString(Json::requireString(obj, "version_type")); file.changelog = Json::requireString(obj, "changelog"); diff --git a/launcher/modplatform/packwiz/Packwiz.cpp b/launcher/modplatform/packwiz/Packwiz.cpp index 072450c9a..d1cf25cc1 100644 --- a/launcher/modplatform/packwiz/Packwiz.cpp +++ b/launcher/modplatform/packwiz/Packwiz.cpp @@ -198,7 +198,7 @@ void V1::updateModIndex(const QDir& index_dir, Mod& mod) { "side", ModPlatform::SideUtils::toString(mod.side).toStdString() }, { "x-prismlauncher-loaders", loaders }, { "x-prismlauncher-mc-versions", mcVersions }, - { "x-prismlauncher-release-type", mod.releaseType.toString().toStdString() }, + { "x-prismlauncher-release-type", ModPlatform::indexedVersionTypeToString(mod.releaseType).toStdString() }, { "x-prismlauncher-version-number", mod.version_number.toStdString() }, { "download", toml::table{ @@ -272,7 +272,7 @@ auto V1::getIndexForMod(const QDir& index_dir, QString slug) -> Mod mod.name = stringEntry(table, "name"); mod.filename = stringEntry(table, "filename"); mod.side = ModPlatform::SideUtils::fromString(stringEntry(table, "side")); - mod.releaseType = ModPlatform::IndexedVersionType(table["x-prismlauncher-release-type"].value_or("")); + mod.releaseType = ModPlatform::indexedVersionTypeFromString(table["x-prismlauncher-release-type"].value_or("")); if (auto loaders = table["x-prismlauncher-loaders"]; loaders && loaders.is_array()) { for (auto&& loader : *loaders.as_array()) { if (loader.is_string()) { diff --git a/launcher/ui/dialogs/ResourceDownloadDialog.cpp b/launcher/ui/dialogs/ResourceDownloadDialog.cpp index 3015ae6e7..fae9fa03e 100644 --- a/launcher/ui/dialogs/ResourceDownloadDialog.cpp +++ b/launcher/ui/dialogs/ResourceDownloadDialog.cpp @@ -187,7 +187,8 @@ void ResourceDownloadDialog::confirm() auto extraInfo = dependencyExtraInfo.value(task->getPack()->addonId.toString()); confirm_dialog->appendResource({ task->getName(), task->getFilename(), task->getCustomPath(), ModPlatform::ProviderCapabilities::name(task->getProvider()), extraInfo.required_by, - task->getVersion().version_type.toString(), !extraInfo.maybe_installed }); + ModPlatform::indexedVersionTypeToString(task->getVersion().version_type), + !extraInfo.maybe_installed }); } if (confirm_dialog->exec()) { diff --git a/launcher/ui/dialogs/ResourceUpdateDialog.cpp b/launcher/ui/dialogs/ResourceUpdateDialog.cpp index a460e9d35..ec275cc91 100644 --- a/launcher/ui/dialogs/ResourceUpdateDialog.cpp +++ b/launcher/ui/dialogs/ResourceUpdateDialog.cpp @@ -453,8 +453,8 @@ void ResourceUpdateDialog::appendResource(CheckUpdateTask::Update const& info, Q if (info.new_version_type.has_value()) { auto new_version_type_item = new QTreeWidgetItem(item_top); - new_version_type_item->setText(0, tr("New Version Type: %1").arg(info.new_version_type.value().toString())); - new_version_type_item->setData(0, Qt::UserRole, info.new_version_type.value().toString()); + new_version_type_item->setText(0, tr("New Version Type: %1").arg(indexedVersionTypeToString(info.new_version_type.value()))); + new_version_type_item->setData(0, Qt::UserRole, indexedVersionTypeToString(info.new_version_type.value())); } if (!requiredBy.isEmpty()) { diff --git a/launcher/ui/pages/modplatform/ResourcePage.cpp b/launcher/ui/pages/modplatform/ResourcePage.cpp index 061e96491..964e3b662 100644 --- a/launcher/ui/pages/modplatform/ResourcePage.cpp +++ b/launcher/ui/pages/modplatform/ResourcePage.cpp @@ -297,8 +297,8 @@ void ResourcePage::versionListUpdated(const QModelIndex& index) continue; auto versionText = version.version; - if (version.version_type.isValid()) { - versionText += QString(" [%1]").arg(version.version_type.toString()); + if (version.version_type != ModPlatform::IndexedVersionType::Unknown) { + versionText += QString(" [%1]").arg(ModPlatform::indexedVersionTypeToString(version.version_type)); } if (version.fileId == installedVersion) { versionText += tr(" [installed]", "Mod version select"); diff --git a/launcher/ui/widgets/ModFilterWidget.cpp b/launcher/ui/widgets/ModFilterWidget.cpp index 4fb0aef22..60b298901 100644 --- a/launcher/ui/widgets/ModFilterWidget.cpp +++ b/launcher/ui/widgets/ModFilterWidget.cpp @@ -387,13 +387,13 @@ void ModFilterWidget::onReleaseFilterChanged() { std::list releases; if (ui->releaseCb->isChecked()) - releases.push_back(ModPlatform::IndexedVersionType(ModPlatform::IndexedVersionType::VersionType::Release)); + releases.push_back(ModPlatform::IndexedVersionType::Release); if (ui->betaCb->isChecked()) - releases.push_back(ModPlatform::IndexedVersionType(ModPlatform::IndexedVersionType::VersionType::Beta)); + releases.push_back(ModPlatform::IndexedVersionType::Beta); if (ui->alphaCb->isChecked()) - releases.push_back(ModPlatform::IndexedVersionType(ModPlatform::IndexedVersionType::VersionType::Alpha)); + releases.push_back(ModPlatform::IndexedVersionType::Alpha); if (ui->unknownCb->isChecked()) - releases.push_back(ModPlatform::IndexedVersionType(ModPlatform::IndexedVersionType::VersionType::Unknown)); + releases.push_back(ModPlatform::IndexedVersionType::Unknown); m_filter_changed = releases != m_filter->releases; m_filter->releases = releases; if (m_filter_changed)