From 40c9af1a8b2f42f4c90c8d358eac43370c04a227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 3 Aug 2019 03:12:48 +0200 Subject: [PATCH] NOISSUE remove dependency of legacy mod list on the Mod class --- api/logic/minecraft/Mod.h | 12 ----- api/logic/minecraft/SimpleModList.cpp | 3 +- api/logic/minecraft/legacy/LegacyInstance.cpp | 5 -- api/logic/minecraft/legacy/LegacyInstance.h | 1 - api/logic/minecraft/legacy/LegacyModList.cpp | 49 +++---------------- api/logic/minecraft/legacy/LegacyModList.h | 2 + .../minecraft/legacy/LegacyUpgradeTask.cpp | 5 +- 7 files changed, 13 insertions(+), 64 deletions(-) diff --git a/api/logic/minecraft/Mod.h b/api/logic/minecraft/Mod.h index 63bf5ab4..6d36d525 100644 --- a/api/logic/minecraft/Mod.h +++ b/api/logic/minecraft/Mod.h @@ -47,11 +47,6 @@ public: { return m_type; } - QString mcversion() const - { - return m_mcversion; - } - ; bool valid() { return m_type != MOD_UNKNOWN; @@ -118,13 +113,6 @@ private: void ReadLiteModInfo(QByteArray contents); protected: - - // FIXME: what do do with those? HMM... - /* - void ReadModInfoData(QString info); - void ReadForgeInfoData(QString infoFileData); - */ - QFileInfo m_file; QDateTime m_changedDateTime; QString m_mmc_id; diff --git a/api/logic/minecraft/SimpleModList.cpp b/api/logic/minecraft/SimpleModList.cpp index 39f5565d..5edd6856 100644 --- a/api/logic/minecraft/SimpleModList.cpp +++ b/api/logic/minecraft/SimpleModList.cpp @@ -25,8 +25,7 @@ SimpleModList::SimpleModList(const QString &dir) : QAbstractListModel(), m_dir(dir) { FS::ensureFolderPathExists(m_dir.absolutePath()); - m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs | - QDir::NoSymLinks); + m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs | QDir::NoSymLinks); m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware); m_watcher = new QFileSystemWatcher(this); connect(m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString))); diff --git a/api/logic/minecraft/legacy/LegacyInstance.cpp b/api/logic/minecraft/legacy/LegacyInstance.cpp index ea81f9fb..f00eb23f 100644 --- a/api/logic/minecraft/legacy/LegacyInstance.cpp +++ b/api/logic/minecraft/legacy/LegacyInstance.cpp @@ -107,11 +107,6 @@ std::shared_ptr LegacyInstance::jarModList() const return jar_mod_list; } -QList LegacyInstance::getJarMods() const -{ - return jarModList()->allMods(); -} - QString LegacyInstance::gameRoot() const { QFileInfo mcDir(FS::PathCombine(instanceRoot(), "minecraft")); diff --git a/api/logic/minecraft/legacy/LegacyInstance.h b/api/logic/minecraft/legacy/LegacyInstance.h index 8bbc2d88..46fca3e4 100644 --- a/api/logic/minecraft/legacy/LegacyInstance.h +++ b/api/logic/minecraft/legacy/LegacyInstance.h @@ -78,7 +78,6 @@ public: QString customBaseJar() const; std::shared_ptr jarModList() const; - QList getJarMods() const; std::shared_ptr worldList() const; /*! diff --git a/api/logic/minecraft/legacy/LegacyModList.cpp b/api/logic/minecraft/legacy/LegacyModList.cpp index 22511380..23b837c1 100644 --- a/api/logic/minecraft/legacy/LegacyModList.cpp +++ b/api/logic/minecraft/legacy/LegacyModList.cpp @@ -22,8 +22,7 @@ LegacyModList::LegacyModList(const QString &dir, const QString &list_file) : m_dir(dir), m_list_file(list_file) { FS::ensureFolderPathExists(m_dir.absolutePath()); - m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs | - QDir::NoSymLinks); + m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs | QDir::NoSymLinks); m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware); } @@ -34,15 +33,11 @@ LegacyModList::LegacyModList(const QString &dir, const QString &list_file) }; typedef QList OrderList; -static void internalSort(QList &what) +static void internalSort(QList &what) { - auto predicate = [](const Mod &left, const Mod &right) + auto predicate = [](const LegacyModList::Mod &left, const LegacyModList::Mod &right) { - if (left.name() == right.name()) - { - return left.mmc_id().localeAwareCompare(right.mmc_id()) < 0; - } - return left.name().localeAwareCompare(right.name()) < 0; + return left.fileName().localeAwareCompare(right.fileName()) < 0; }; std::sort(what.begin(), what.end(), predicate); } @@ -90,7 +85,6 @@ bool LegacyModList::update() QList newMods; m_dir.refresh(); auto folderContents = m_dir.entryInfoList(); - bool orderOrStateChanged = false; // first, process the ordered items (if any) OrderList listOrder = readListFile(m_list_file); @@ -124,48 +118,19 @@ bool LegacyModList::update() // remove from the actual folder contents list folderContents.takeAt(idx); // append the new mod - orderedMods.append(Mod(info)); - if (isEnabled != item.enabled) - orderOrStateChanged = true; - } - else - { - orderOrStateChanged = true; + orderedMods.append(info); } } - // if there are any untracked files... + // if there are any untracked files... append them sorted at the end if (folderContents.size()) { - // the order surely changed! for (auto entry : folderContents) { - newMods.append(Mod(entry)); + newMods.append(entry); } internalSort(newMods); orderedMods.append(newMods); - orderOrStateChanged = true; - } - // otherwise, if we were already tracking some mods - else if (mods.size()) - { - // if the number doesn't match, order changed. - if (mods.size() != orderedMods.size()) - orderOrStateChanged = true; - // if it does match, compare the mods themselves - else - for (int i = 0; i < mods.size(); i++) - { - if (!mods[i].strongCompare(orderedMods[i])) - { - orderOrStateChanged = true; - break; - } - } } mods.swap(orderedMods); - if (orderOrStateChanged && !m_list_file.isEmpty()) - { - qDebug() << "Mod list " << m_list_file << " changed!"; - } return true; } diff --git a/api/logic/minecraft/legacy/LegacyModList.h b/api/logic/minecraft/legacy/LegacyModList.h index 1b5b24c4..4e91958d 100644 --- a/api/logic/minecraft/legacy/LegacyModList.h +++ b/api/logic/minecraft/legacy/LegacyModList.h @@ -34,6 +34,8 @@ class MULTIMC_LOGIC_EXPORT LegacyModList { public: + using Mod = QFileInfo; + LegacyModList(const QString &dir, const QString &list_file = QString()); /// Reloads the mod list and returns true if the list changed. diff --git a/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp b/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp index 9a832a24..9d86a7b5 100644 --- a/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp +++ b/api/logic/minecraft/legacy/LegacyUpgradeTask.cpp @@ -7,6 +7,7 @@ #include "LegacyInstance.h" #include "minecraft/MinecraftInstance.h" #include "minecraft/ComponentList.h" +#include "LegacyModList.h" #include "classparser.h" LegacyUpgradeTask::LegacyUpgradeTask(InstancePtr origInstance) @@ -96,10 +97,10 @@ void LegacyUpgradeTask::copyFinished() components->installCustomJar(jarPath); } - auto jarMods = legacyInst->getJarMods(); + auto jarMods = legacyInst->jarModList()->allMods(); for(auto & jarMod: jarMods) { - QString modPath = jarMod.filename().absoluteFilePath(); + QString modPath = jarMod.absoluteFilePath(); qDebug() << "jarMod: " << modPath; components->installJarMods({modPath}); }