From 2f5e55bea05c600d0ff44678f7a79ea7e276ee6d Mon Sep 17 00:00:00 2001 From: flow Date: Thu, 11 Aug 2022 13:00:09 -0300 Subject: [PATCH] fix: only remove orphaned metadata on first opening This avoids deleting the metadata while one is updating their mods. Signed-off-by: flow --- launcher/minecraft/mod/ModFolderModel.cpp | 6 +++++- launcher/minecraft/mod/ModFolderModel.h | 1 + .../minecraft/mod/tasks/ModFolderLoadTask.cpp | 18 ++++++++++-------- .../minecraft/mod/tasks/ModFolderLoadTask.h | 3 ++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp index 112d219e..d4c5e819 100644 --- a/launcher/minecraft/mod/ModFolderModel.cpp +++ b/launcher/minecraft/mod/ModFolderModel.cpp @@ -63,6 +63,9 @@ void ModFolderModel::startWatching() if(is_watching) return; + // Remove orphaned metadata next time + m_first_folder_load = true; + update(); // Watch the mods folder @@ -113,7 +116,8 @@ bool ModFolderModel::update() } 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(); diff --git a/launcher/minecraft/mod/ModFolderModel.h b/launcher/minecraft/mod/ModFolderModel.h index a7d3ece0..3d6efac3 100644 --- a/launcher/minecraft/mod/ModFolderModel.h +++ b/launcher/minecraft/mod/ModFolderModel.h @@ -172,6 +172,7 @@ protected: bool interaction_disabled = false; QDir m_dir; bool m_is_indexed; + bool m_first_folder_load = true; QMap modsIndex; QMap activeTickets; int nextResolutionTicket = 0; diff --git a/launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp b/launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp index 9b70e7a1..015ead80 100644 --- a/launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp +++ b/launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp @@ -38,8 +38,8 @@ #include "minecraft/mod/MetadataHandler.h" -ModFolderLoadTask::ModFolderLoadTask(QDir& mods_dir, QDir& index_dir, bool is_indexed) - : m_mods_dir(mods_dir), m_index_dir(index_dir), m_is_indexed(is_indexed), m_result(new Result()) +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_clean_orphan(clean_orphan), m_result(new Result()) {} void ModFolderLoadTask::run() @@ -85,12 +85,14 @@ void ModFolderLoadTask::run() // Remove orphan metadata to prevent issues // See https://github.com/PolyMC/PolyMC/issues/996 - QMutableMapIterator iter(m_result->mods); - while (iter.hasNext()) { - auto mod = iter.next().value(); - if (mod->status() == ModStatus::NotInstalled) { - mod->destroy(m_index_dir, false); - iter.remove(); + if (m_clean_orphan) { + QMutableMapIterator iter(m_result->mods); + while (iter.hasNext()) { + auto mod = iter.next().value(); + if (mod->status() == ModStatus::NotInstalled) { + mod->destroy(m_index_dir, false); + iter.remove(); + } } } diff --git a/launcher/minecraft/mod/tasks/ModFolderLoadTask.h b/launcher/minecraft/mod/tasks/ModFolderLoadTask.h index 0b6bb6cc..1f2015d2 100644 --- a/launcher/minecraft/mod/tasks/ModFolderLoadTask.h +++ b/launcher/minecraft/mod/tasks/ModFolderLoadTask.h @@ -56,7 +56,7 @@ 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(); signals: void succeeded(); @@ -67,5 +67,6 @@ private: private: QDir& m_mods_dir, m_index_dir; bool m_is_indexed; + bool m_clean_orphan; ResultPtr m_result; };