Merge pull request #1044 from flowln/better_orphan_fix

This commit is contained in:
Sefa Eyeoglu 2022-08-20 12:50:43 +02:00 committed by GitHub
commit 311758233b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 10 deletions

View File

@ -63,6 +63,9 @@ void ModFolderModel::startWatching()
if(is_watching) if(is_watching)
return; return;
// Remove orphaned metadata next time
m_first_folder_load = true;
update(); update();
// Watch the mods folder // Watch the mods folder
@ -113,7 +116,8 @@ bool ModFolderModel::update()
} }
auto index_dir = indexDir(); auto index_dir = indexDir();
auto task = new ModFolderLoadTask(dir(), index_dir, m_is_indexed); auto task = new ModFolderLoadTask(dir(), index_dir, m_is_indexed, m_first_folder_load);
m_first_folder_load = false;
m_update = task->result(); m_update = task->result();

View File

@ -172,6 +172,7 @@ protected:
bool interaction_disabled = false; bool interaction_disabled = false;
QDir m_dir; QDir m_dir;
bool m_is_indexed; bool m_is_indexed;
bool m_first_folder_load = true;
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

@ -38,8 +38,8 @@
#include "minecraft/mod/MetadataHandler.h" #include "minecraft/mod/MetadataHandler.h"
ModFolderLoadTask::ModFolderLoadTask(QDir& mods_dir, QDir& index_dir, bool is_indexed) ModFolderLoadTask::ModFolderLoadTask(QDir& mods_dir, QDir& index_dir, bool is_indexed, bool clean_orphan)
: m_mods_dir(mods_dir), m_index_dir(index_dir), m_is_indexed(is_indexed), m_result(new Result()) : m_mods_dir(mods_dir), m_index_dir(index_dir), m_is_indexed(is_indexed), m_clean_orphan(clean_orphan), m_result(new Result())
{} {}
void ModFolderLoadTask::run() void ModFolderLoadTask::run()
@ -85,12 +85,14 @@ void ModFolderLoadTask::run()
// Remove orphan metadata to prevent issues // Remove orphan metadata to prevent issues
// See https://github.com/PolyMC/PolyMC/issues/996 // See https://github.com/PolyMC/PolyMC/issues/996
QMutableMapIterator<QString, Mod::Ptr> iter(m_result->mods); if (m_clean_orphan) {
while (iter.hasNext()) { QMutableMapIterator<QString, Mod::Ptr> iter(m_result->mods);
auto mod = iter.next().value(); while (iter.hasNext()) {
if (mod->status() == ModStatus::NotInstalled) { auto mod = iter.next().value();
mod->destroy(m_index_dir, false); if (mod->status() == ModStatus::NotInstalled) {
iter.remove(); mod->destroy(m_index_dir, false);
iter.remove();
}
} }
} }

View File

@ -56,7 +56,7 @@ public:
} }
public: public:
ModFolderLoadTask(QDir& mods_dir, QDir& index_dir, bool is_indexed); ModFolderLoadTask(QDir& mods_dir, QDir& index_dir, bool is_indexed, bool clean_orphan = false);
void run(); void run();
signals: signals:
void succeeded(); void succeeded();
@ -67,5 +67,6 @@ private:
private: private:
QDir& m_mods_dir, m_index_dir; QDir& m_mods_dir, m_index_dir;
bool m_is_indexed; bool m_is_indexed;
bool m_clean_orphan;
ResultPtr m_result; ResultPtr m_result;
}; };