refactor(test): fix loading mod metadata setting

This commit is contained in:
Sefa Eyeoglu 2022-06-04 15:30:34 +02:00
parent e843b8e188
commit 8856c8cd62
No known key found for this signature in database
GPG Key ID: C10411294912A422
14 changed files with 28 additions and 25 deletions

View File

@ -21,12 +21,14 @@
#include "Application.h" #include "Application.h"
#include "minecraft/mod/ModFolderModel.h" #include "minecraft/mod/ModFolderModel.h"
ModDownloadTask::ModDownloadTask(ModPlatform::IndexedPack mod, ModPlatform::IndexedVersion version, const std::shared_ptr<ModFolderModel> mods) ModDownloadTask::ModDownloadTask(ModPlatform::IndexedPack mod, ModPlatform::IndexedVersion version, const std::shared_ptr<ModFolderModel> mods, bool is_indexed)
: m_mod(mod), m_mod_version(version), mods(mods) : m_mod(mod), m_mod_version(version), mods(mods)
{ {
m_update_task.reset(new LocalModUpdateTask(mods->indexDir(), m_mod, m_mod_version)); if (is_indexed) {
m_update_task.reset(new LocalModUpdateTask(mods->indexDir(), m_mod, m_mod_version));
addTask(m_update_task); addTask(m_update_task);
}
m_filesNetJob.reset(new NetJob(tr("Mod download"), APPLICATION->network())); m_filesNetJob.reset(new NetJob(tr("Mod download"), APPLICATION->network()));
m_filesNetJob->setStatus(tr("Downloading mod:\n%1").arg(m_mod_version.downloadUrl)); m_filesNetJob->setStatus(tr("Downloading mod:\n%1").arg(m_mod_version.downloadUrl));

View File

@ -29,7 +29,7 @@ class ModFolderModel;
class ModDownloadTask : public SequentialTask { class ModDownloadTask : public SequentialTask {
Q_OBJECT Q_OBJECT
public: public:
explicit ModDownloadTask(ModPlatform::IndexedPack mod, ModPlatform::IndexedVersion version, const std::shared_ptr<ModFolderModel> mods); explicit ModDownloadTask(ModPlatform::IndexedPack mod, ModPlatform::IndexedVersion version, const std::shared_ptr<ModFolderModel> mods, bool is_indexed);
const QString& getFilename() const { return m_mod_version.fileName; } const QString& getFilename() const { return m_mod_version.fileName; }
private: private:

View File

@ -1015,7 +1015,8 @@ std::shared_ptr<ModFolderModel> MinecraftInstance::loaderModList() const
{ {
if (!m_loader_mod_list) if (!m_loader_mod_list)
{ {
m_loader_mod_list.reset(new ModFolderModel(modsRoot())); bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
m_loader_mod_list.reset(new ModFolderModel(modsRoot(), is_indexed));
m_loader_mod_list->disableInteraction(isRunning()); m_loader_mod_list->disableInteraction(isRunning());
connect(this, &BaseInstance::runningStatusChanged, m_loader_mod_list.get(), &ModFolderModel::disableInteraction); connect(this, &BaseInstance::runningStatusChanged, m_loader_mod_list.get(), &ModFolderModel::disableInteraction);
} }
@ -1026,7 +1027,8 @@ std::shared_ptr<ModFolderModel> MinecraftInstance::coreModList() const
{ {
if (!m_core_mod_list) if (!m_core_mod_list)
{ {
m_core_mod_list.reset(new ModFolderModel(coreModsDir())); bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
m_core_mod_list.reset(new ModFolderModel(coreModsDir(), is_indexed));
m_core_mod_list->disableInteraction(isRunning()); m_core_mod_list->disableInteraction(isRunning());
connect(this, &BaseInstance::runningStatusChanged, m_core_mod_list.get(), &ModFolderModel::disableInteraction); connect(this, &BaseInstance::runningStatusChanged, m_core_mod_list.get(), &ModFolderModel::disableInteraction);
} }

View File

@ -161,7 +161,7 @@ auto Mod::destroy(QDir& index_dir) -> bool
{ {
auto n = name(); auto n = name();
// FIXME: This can fail to remove the metadata if the // FIXME: This can fail to remove the metadata if the
// "DontUseModMetadata" setting is on, since there could // "ModMetadataDisabled" setting is on, since there could
// be a name mismatch! // be a name mismatch!
Metadata::remove(index_dir, n); Metadata::remove(index_dir, n);

View File

@ -28,7 +28,7 @@
#include "minecraft/mod/tasks/LocalModParseTask.h" #include "minecraft/mod/tasks/LocalModParseTask.h"
#include "minecraft/mod/tasks/ModFolderLoadTask.h" #include "minecraft/mod/tasks/ModFolderLoadTask.h"
ModFolderModel::ModFolderModel(const QString &dir) : QAbstractListModel(), m_dir(dir) ModFolderModel::ModFolderModel(const QString &dir, bool is_indexed) : QAbstractListModel(), m_dir(dir), m_is_indexed(is_indexed)
{ {
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);
@ -82,7 +82,7 @@ bool ModFolderModel::update()
} }
auto index_dir = indexDir(); auto index_dir = indexDir();
auto task = new ModFolderLoadTask(dir(), index_dir); auto task = new ModFolderLoadTask(dir(), index_dir, m_is_indexed);
m_update = task->result(); m_update = task->result();

View File

@ -52,7 +52,7 @@ public:
Enable, Enable,
Toggle Toggle
}; };
ModFolderModel(const QString &dir); ModFolderModel(const QString &dir, bool is_indexed);
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
@ -146,6 +146,7 @@ protected:
bool scheduled_update = false; bool scheduled_update = false;
bool interaction_disabled = false; bool interaction_disabled = false;
QDir m_dir; QDir m_dir;
bool m_is_indexed;
QMap<QString, int> modsIndex; QMap<QString, int> modsIndex;
QMap<int, LocalModParseTask::ResultPtr> activeTickets; QMap<int, LocalModParseTask::ResultPtr> activeTickets;
int nextResolutionTicket = 0; int nextResolutionTicket = 0;

View File

@ -32,7 +32,7 @@ slots:
{ {
QString folder = source; QString folder = source;
QTemporaryDir tempDir; QTemporaryDir tempDir;
ModFolderModel m(tempDir.path()); ModFolderModel m(tempDir.path(), true);
m.installMod(folder); m.installMod(folder);
verify(tempDir.path()); verify(tempDir.path());
} }
@ -41,7 +41,7 @@ slots:
{ {
QString folder = source + '/'; QString folder = source + '/';
QTemporaryDir tempDir; QTemporaryDir tempDir;
ModFolderModel m(tempDir.path()); ModFolderModel m(tempDir.path(), true);
m.installMod(folder); m.installMod(folder);
verify(tempDir.path()); verify(tempDir.path());
} }

View File

@ -1,6 +1,6 @@
#include "ResourcePackFolderModel.h" #include "ResourcePackFolderModel.h"
ResourcePackFolderModel::ResourcePackFolderModel(const QString &dir) : ModFolderModel(dir) { ResourcePackFolderModel::ResourcePackFolderModel(const QString &dir) : ModFolderModel(dir, false) {
} }
QVariant ResourcePackFolderModel::headerData(int section, Qt::Orientation orientation, int role) const { QVariant ResourcePackFolderModel::headerData(int section, Qt::Orientation orientation, int role) const {

View File

@ -1,6 +1,6 @@
#include "TexturePackFolderModel.h" #include "TexturePackFolderModel.h"
TexturePackFolderModel::TexturePackFolderModel(const QString &dir) : ModFolderModel(dir) { TexturePackFolderModel::TexturePackFolderModel(const QString &dir) : ModFolderModel(dir, false) {
} }
QVariant TexturePackFolderModel::headerData(int section, Qt::Orientation orientation, int role) const { QVariant TexturePackFolderModel::headerData(int section, Qt::Orientation orientation, int role) const {

View File

@ -35,11 +35,6 @@ void LocalModUpdateTask::executeTask()
{ {
setStatus(tr("Updating index for mod:\n%1").arg(m_mod.name)); setStatus(tr("Updating index for mod:\n%1").arg(m_mod.name));
if(APPLICATION->settings()->get("DontUseModMetadata").toBool()){
emitSucceeded();
return;
}
auto pw_mod = Metadata::create(m_index_dir, m_mod, m_mod_version); auto pw_mod = Metadata::create(m_index_dir, m_mod, m_mod_version);
Metadata::update(m_index_dir, pw_mod); Metadata::update(m_index_dir, pw_mod);

View File

@ -38,13 +38,13 @@
#include "Application.h" #include "Application.h"
#include "minecraft/mod/MetadataHandler.h" #include "minecraft/mod/MetadataHandler.h"
ModFolderLoadTask::ModFolderLoadTask(QDir& mods_dir, QDir& index_dir) ModFolderLoadTask::ModFolderLoadTask(QDir& mods_dir, QDir& index_dir, bool is_indexed)
: m_mods_dir(mods_dir), m_index_dir(index_dir), m_result(new Result()) : m_mods_dir(mods_dir), m_index_dir(index_dir), m_is_indexed(is_indexed), m_result(new Result())
{} {}
void ModFolderLoadTask::run() void ModFolderLoadTask::run()
{ {
if (!APPLICATION->settings()->get("ModMetadataDisabled").toBool()) { if (m_is_indexed) {
// Read metadata first // Read metadata first
getFromMetadata(); getFromMetadata();
} }

View File

@ -55,7 +55,7 @@ public:
} }
public: public:
ModFolderLoadTask(QDir& mods_dir, QDir& index_dir); ModFolderLoadTask(QDir& mods_dir, QDir& index_dir, bool is_indexed);
void run(); void run();
signals: signals:
void succeeded(); void succeeded();
@ -65,5 +65,6 @@ private:
private: private:
QDir& m_mods_dir, m_index_dir; QDir& m_mods_dir, m_index_dir;
bool m_is_indexed;
ResultPtr m_result; ResultPtr m_result;
}; };

View File

@ -450,7 +450,7 @@ void LauncherPage::loadSettings()
} }
// Mods // Mods
ui->metadataDisableBtn->setChecked(s->get("DontUseModMetadata").toBool()); ui->metadataDisableBtn->setChecked(s->get("ModMetadataDisabled").toBool());
ui->metadataWarningLabel->setHidden(!ui->metadataDisableBtn->isChecked()); ui->metadataWarningLabel->setHidden(!ui->metadataDisableBtn->isChecked());
} }

View File

@ -1,4 +1,5 @@
#include "ModPage.h" #include "ModPage.h"
#include "Application.h"
#include "ui_ModPage.h" #include "ui_ModPage.h"
#include <QKeyEvent> #include <QKeyEvent>
@ -150,7 +151,8 @@ void ModPage::onModSelected()
if (dialog->isModSelected(current.name, version.fileName)) { if (dialog->isModSelected(current.name, version.fileName)) {
dialog->removeSelectedMod(current.name); dialog->removeSelectedMod(current.name);
} else { } else {
dialog->addSelectedMod(current.name, new ModDownloadTask(current, version, dialog->mods)); bool is_indexed = !APPLICATION->settings()->get("ModMetadataDisabled").toBool();
dialog->addSelectedMod(current.name, new ModDownloadTask(current, version, dialog->mods, is_indexed));
} }
updateSelectionButton(); updateSelectionButton();