NOISSUE remove dependency of legacy mod list on the Mod class
This commit is contained in:
parent
f5f3149dcf
commit
40c9af1a8b
@ -47,11 +47,6 @@ public:
|
|||||||
{
|
{
|
||||||
return m_type;
|
return m_type;
|
||||||
}
|
}
|
||||||
QString mcversion() const
|
|
||||||
{
|
|
||||||
return m_mcversion;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
bool valid()
|
bool valid()
|
||||||
{
|
{
|
||||||
return m_type != MOD_UNKNOWN;
|
return m_type != MOD_UNKNOWN;
|
||||||
@ -118,13 +113,6 @@ private:
|
|||||||
void ReadLiteModInfo(QByteArray contents);
|
void ReadLiteModInfo(QByteArray contents);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// FIXME: what do do with those? HMM...
|
|
||||||
/*
|
|
||||||
void ReadModInfoData(QString info);
|
|
||||||
void ReadForgeInfoData(QString infoFileData);
|
|
||||||
*/
|
|
||||||
|
|
||||||
QFileInfo m_file;
|
QFileInfo m_file;
|
||||||
QDateTime m_changedDateTime;
|
QDateTime m_changedDateTime;
|
||||||
QString m_mmc_id;
|
QString m_mmc_id;
|
||||||
|
@ -25,8 +25,7 @@
|
|||||||
SimpleModList::SimpleModList(const QString &dir) : QAbstractListModel(), m_dir(dir)
|
SimpleModList::SimpleModList(const QString &dir) : QAbstractListModel(), m_dir(dir)
|
||||||
{
|
{
|
||||||
FS::ensureFolderPathExists(m_dir.absolutePath());
|
FS::ensureFolderPathExists(m_dir.absolutePath());
|
||||||
m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs |
|
m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs | QDir::NoSymLinks);
|
||||||
QDir::NoSymLinks);
|
|
||||||
m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware);
|
m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware);
|
||||||
m_watcher = new QFileSystemWatcher(this);
|
m_watcher = new QFileSystemWatcher(this);
|
||||||
connect(m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString)));
|
connect(m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString)));
|
||||||
|
@ -107,11 +107,6 @@ std::shared_ptr<LegacyModList> LegacyInstance::jarModList() const
|
|||||||
return jar_mod_list;
|
return jar_mod_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Mod> LegacyInstance::getJarMods() const
|
|
||||||
{
|
|
||||||
return jarModList()->allMods();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString LegacyInstance::gameRoot() const
|
QString LegacyInstance::gameRoot() const
|
||||||
{
|
{
|
||||||
QFileInfo mcDir(FS::PathCombine(instanceRoot(), "minecraft"));
|
QFileInfo mcDir(FS::PathCombine(instanceRoot(), "minecraft"));
|
||||||
|
@ -78,7 +78,6 @@ public:
|
|||||||
QString customBaseJar() const;
|
QString customBaseJar() const;
|
||||||
|
|
||||||
std::shared_ptr<LegacyModList> jarModList() const;
|
std::shared_ptr<LegacyModList> jarModList() const;
|
||||||
QList<Mod> getJarMods() const;
|
|
||||||
std::shared_ptr<WorldList> worldList() const;
|
std::shared_ptr<WorldList> worldList() const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -22,8 +22,7 @@ LegacyModList::LegacyModList(const QString &dir, const QString &list_file)
|
|||||||
: m_dir(dir), m_list_file(list_file)
|
: m_dir(dir), m_list_file(list_file)
|
||||||
{
|
{
|
||||||
FS::ensureFolderPathExists(m_dir.absolutePath());
|
FS::ensureFolderPathExists(m_dir.absolutePath());
|
||||||
m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs |
|
m_dir.setFilter(QDir::Readable | QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs | QDir::NoSymLinks);
|
||||||
QDir::NoSymLinks);
|
|
||||||
m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware);
|
m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,15 +33,11 @@ LegacyModList::LegacyModList(const QString &dir, const QString &list_file)
|
|||||||
};
|
};
|
||||||
typedef QList<OrderItem> OrderList;
|
typedef QList<OrderItem> OrderList;
|
||||||
|
|
||||||
static void internalSort(QList<Mod> &what)
|
static void internalSort(QList<LegacyModList::Mod> &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.fileName().localeAwareCompare(right.fileName()) < 0;
|
||||||
{
|
|
||||||
return left.mmc_id().localeAwareCompare(right.mmc_id()) < 0;
|
|
||||||
}
|
|
||||||
return left.name().localeAwareCompare(right.name()) < 0;
|
|
||||||
};
|
};
|
||||||
std::sort(what.begin(), what.end(), predicate);
|
std::sort(what.begin(), what.end(), predicate);
|
||||||
}
|
}
|
||||||
@ -90,7 +85,6 @@ bool LegacyModList::update()
|
|||||||
QList<Mod> newMods;
|
QList<Mod> newMods;
|
||||||
m_dir.refresh();
|
m_dir.refresh();
|
||||||
auto folderContents = m_dir.entryInfoList();
|
auto folderContents = m_dir.entryInfoList();
|
||||||
bool orderOrStateChanged = false;
|
|
||||||
|
|
||||||
// first, process the ordered items (if any)
|
// first, process the ordered items (if any)
|
||||||
OrderList listOrder = readListFile(m_list_file);
|
OrderList listOrder = readListFile(m_list_file);
|
||||||
@ -124,48 +118,19 @@ bool LegacyModList::update()
|
|||||||
// remove from the actual folder contents list
|
// remove from the actual folder contents list
|
||||||
folderContents.takeAt(idx);
|
folderContents.takeAt(idx);
|
||||||
// append the new mod
|
// append the new mod
|
||||||
orderedMods.append(Mod(info));
|
orderedMods.append(info);
|
||||||
if (isEnabled != item.enabled)
|
|
||||||
orderOrStateChanged = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
orderOrStateChanged = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if there are any untracked files...
|
// if there are any untracked files... append them sorted at the end
|
||||||
if (folderContents.size())
|
if (folderContents.size())
|
||||||
{
|
{
|
||||||
// the order surely changed!
|
|
||||||
for (auto entry : folderContents)
|
for (auto entry : folderContents)
|
||||||
{
|
{
|
||||||
newMods.append(Mod(entry));
|
newMods.append(entry);
|
||||||
}
|
}
|
||||||
internalSort(newMods);
|
internalSort(newMods);
|
||||||
orderedMods.append(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);
|
mods.swap(orderedMods);
|
||||||
if (orderOrStateChanged && !m_list_file.isEmpty())
|
|
||||||
{
|
|
||||||
qDebug() << "Mod list " << m_list_file << " changed!";
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,8 @@ class MULTIMC_LOGIC_EXPORT LegacyModList
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
using Mod = QFileInfo;
|
||||||
|
|
||||||
LegacyModList(const QString &dir, const QString &list_file = QString());
|
LegacyModList(const QString &dir, const QString &list_file = QString());
|
||||||
|
|
||||||
/// Reloads the mod list and returns true if the list changed.
|
/// Reloads the mod list and returns true if the list changed.
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "LegacyInstance.h"
|
#include "LegacyInstance.h"
|
||||||
#include "minecraft/MinecraftInstance.h"
|
#include "minecraft/MinecraftInstance.h"
|
||||||
#include "minecraft/ComponentList.h"
|
#include "minecraft/ComponentList.h"
|
||||||
|
#include "LegacyModList.h"
|
||||||
#include "classparser.h"
|
#include "classparser.h"
|
||||||
|
|
||||||
LegacyUpgradeTask::LegacyUpgradeTask(InstancePtr origInstance)
|
LegacyUpgradeTask::LegacyUpgradeTask(InstancePtr origInstance)
|
||||||
@ -96,10 +97,10 @@ void LegacyUpgradeTask::copyFinished()
|
|||||||
components->installCustomJar(jarPath);
|
components->installCustomJar(jarPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto jarMods = legacyInst->getJarMods();
|
auto jarMods = legacyInst->jarModList()->allMods();
|
||||||
for(auto & jarMod: jarMods)
|
for(auto & jarMod: jarMods)
|
||||||
{
|
{
|
||||||
QString modPath = jarMod.filename().absoluteFilePath();
|
QString modPath = jarMod.absoluteFilePath();
|
||||||
qDebug() << "jarMod: " << modPath;
|
qDebug() << "jarMod: " << modPath;
|
||||||
components->installJarMods({modPath});
|
components->installJarMods({modPath});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user