From ab38cf0e059c15af82da7e48045823a5cbbb5d52 Mon Sep 17 00:00:00 2001 From: Jonathan Feenstra <26406078+JonathanFeenstra@users.noreply.github.com> Date: Sun, 17 May 2026 09:28:30 +0200 Subject: Improve code for reading text files line-by-line --- src/loot.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/loot.cpp') diff --git a/src/loot.cpp b/src/loot.cpp index a888b577..6159521b 100644 --- a/src/loot.cpp +++ b/src/loot.cpp @@ -732,6 +732,7 @@ void Loot::processReport(Report& r) const QJsonParseError e; const QJsonDocument doc = QJsonDocument::fromJson(reportFile.readAll(), &e); + reportFile.close(); if (doc.isNull()) { emit log(MOBase::log::Error, QString("invalid json, %1 (error %2)").arg(e.errorString()).arg(e.error)); @@ -776,22 +777,27 @@ const QString Loot::getSortedPluginListMarkdown() const log::debug("parsing sorted plugin list at '{}'", SortedPluginListPath); QFile pluginListFile(SortedPluginListPath); - if (!pluginListFile.open(QIODevice::ReadOnly)) { + if (!pluginListFile.open(QIODevice::ReadOnly | QIODevice::Text)) { emit log(MOBase::log::Error, QString("failed to open file, %1 (error %2)") .arg(pluginListFile.errorString()) .arg(pluginListFile.error())); return {}; } - // skip "# This file was automatically generated by Mod Organizer" - pluginListFile.readLine(); - QString markdown = "### " + tr("Sorted plugins") + "\n
" + tr("Show") + "\n\n"; - const auto pluginList = m_core.pluginList(); - while (!pluginListFile.atEnd()) { - const QString pluginName = QString::fromUtf8(pluginListFile.readLine().trimmed()); + const auto pluginList = m_core.pluginList(); + const QByteArray contents = pluginListFile.readAll(); + pluginListFile.close(); + + for (const QString& line : + QString::fromUtf8(contents).split('\n', Qt::SkipEmptyParts)) { + if (line.at(0) == '#') { + continue; + } + + const QString pluginName = line.trimmed(); const bool active = pluginList->isEnabled(pluginName); const QString prefix = active ? " - [x] " : " - [ ] "; markdown += prefix + pluginName + "\n"; @@ -799,7 +805,6 @@ const QString Loot::getSortedPluginListMarkdown() const markdown += "
\n"; - pluginListFile.close(); return markdown; } -- cgit v1.3.1