summaryrefslogtreecommitdiff
path: root/src/loot.cpp
diff options
context:
space:
mode:
authorJonathan Feenstra <26406078+JonathanFeenstra@users.noreply.github.com>2026-05-17 09:28:30 +0200
committerGitHub <noreply@github.com>2026-05-17 02:28:30 -0500
commitab38cf0e059c15af82da7e48045823a5cbbb5d52 (patch)
tree314a78b4e8bfe3ceee91474403b153c55cbf5bd6 /src/loot.cpp
parent0c95bf22e6be661fbed83cbc7ac0a43596bc80f4 (diff)
Improve code for reading text files line-by-line
Diffstat (limited to 'src/loot.cpp')
-rw-r--r--src/loot.cpp21
1 files changed, 13 insertions, 8 deletions
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<details><summary>" +
tr("Show") + "</summary>\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 += "</details>\n";
- pluginListFile.close();
return markdown;
}