From c2950552794a1cb93eee9cb7e2bdb4f8d81b301b Mon Sep 17 00:00:00 2001 From: Ice Yeti <101294194+IceYetiWins@users.noreply.github.com> Date: Wed, 27 May 2026 16:48:14 -0400 Subject: [PATCH] clean up watchers --- launcher/minecraft/MultiWorldList.cpp | 56 +++++++++++++++++---------- launcher/ui/MultiWorldListPage.cpp | 10 ++--- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/launcher/minecraft/MultiWorldList.cpp b/launcher/minecraft/MultiWorldList.cpp index 4851f63b7..c32f8cabc 100644 --- a/launcher/minecraft/MultiWorldList.cpp +++ b/launcher/minecraft/MultiWorldList.cpp @@ -48,7 +48,7 @@ MultiWorldList::MultiWorldList(const QList& dirs, QList instances) : QAbstractListModel(), m_instances(instances) { - for (int i = 0; i < dirs.length(); i++) { // better way to do this? iy + for (int i = 0; i < dirs.length(); i++) { m_dirs[i] = dirs[i]; } @@ -63,30 +63,40 @@ MultiWorldList::MultiWorldList(const QList& dirs, QList connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &MultiWorldList::directoryChanged); } -void MultiWorldList::startWatching() //figure out what watchers do / if necessary and do all paths iy +void MultiWorldList::startWatching() { if (m_isWatching) { return; } update(); - m_isWatching = m_watcher->addPath(m_dirs[0].absolutePath()); - if (m_isWatching) { - qDebug() << "Started watching" << m_dirs[0].absolutePath(); - } else { - qDebug() << "Failed to start watching" << m_dirs[0].absolutePath(); + + m_isWatching = true; + + for (QDir dir : m_dirs) { + if (m_watcher->addPath(dir.absolutePath())) { + qDebug() << "Started watching" << dir.absolutePath(); + } else { + m_isWatching = false; + qDebug() << "Failed to start watching" << dir.absolutePath(); + } } } -void MultiWorldList::stopWatching() //same as above function iy +void MultiWorldList::stopWatching() { if (!m_isWatching) { return; } - m_isWatching = !m_watcher->removePath(m_dirs[0].absolutePath()); - if (!m_isWatching) { - qDebug() << "Stopped watching" << m_dirs[0].absolutePath(); - } else { - qDebug() << "Failed to stop watching" << m_dirs[0].absolutePath(); + + m_isWatching = false; + + for (QDir dir : m_dirs) { + if (m_watcher->removePath(dir.absolutePath())) { + qDebug() << "Stopped watching" << dir.absolutePath(); + } else { + m_isWatching = true; + qDebug() << "Failed to stop watching" << dir.absolutePath(); + } } } @@ -216,8 +226,10 @@ QVariant MultiWorldList::data(const QModelIndex& index, int role) const return locale.formattedDataSize(world.bytes()); case InfoColumn: - if (world.isSymLinkUnder(instDirPaths()[0])) { //FIX THIS--NO INDEX 0 iy - return tr("This world is symbolically linked from elsewhere."); + for (QString path : instDirPaths()) { //use canonical paths instead of for loops? iy + if (world.isSymLinkUnder(path)) { + return tr("This world is symbolically linked from elsewhere."); + } } if (world.isMoreThanOneHardLink()) { return tr("\nThis world is hard linked elsewhere."); @@ -234,10 +246,12 @@ QVariant MultiWorldList::data(const QModelIndex& index, int role) const case Qt::ToolTipRole: { if (column == InfoColumn) { - if (world.isSymLinkUnder(instDirPaths()[0])) { //SAME HERE iy - return tr("Warning: This world is symbolically linked from elsewhere. Editing it will also change the original." + for (QString path : instDirPaths()) { //use canonical paths instead of for loops? iy + if (world.isSymLinkUnder(path)) { + return tr("Warning: This world is symbolically linked from elsewhere. Editing it will also change the original." "\nCanonical Path: %1") - .arg(world.canonicalFilePath()); + .arg(world.canonicalFilePath()); + } } if (world.isMoreThanOneHardLink()) { return tr("Warning: This world is hard linked elsewhere. Editing it will also change the original."); @@ -249,7 +263,7 @@ QVariant MultiWorldList::data(const QModelIndex& index, int role) const return QVariant::fromValue((void*)&world); } case FolderRole: { - return QDir::toNativeSeparators(dirs()[0].absoluteFilePath(world.folderName())); //SAME HERE iy + return QDir::toNativeSeparators(QDir(world.canonicalFilePath()).absoluteFilePath(world.folderName())); //test if canonical file path works iy } case SeedRole: { return QVariant::fromValue(world.seed()); @@ -374,7 +388,7 @@ void MultiWorldList::installWorld(QFileInfo filename) if (!w.isValid()) { return; } - w.install(m_dirs[0].absolutePath()); //more directory stuff iy + w.install(m_dirs[0].absolutePath()); //add option for which instance to install to iy } bool MultiWorldList::dropMimeData(const QMimeData* data, @@ -402,7 +416,7 @@ bool MultiWorldList::dropMimeData(const QMimeData* data, QFileInfo worldInfo(filename); - if (!m_dirs[0].entryInfoList().contains(worldInfo)) { //more stuff to fix iy + if (!m_dirs[0].entryInfoList().contains(worldInfo)) { //same as above, add option for which instance to install to iy installWorld(worldInfo); } } diff --git a/launcher/ui/MultiWorldListPage.cpp b/launcher/ui/MultiWorldListPage.cpp index 768ab4a08..da527cc4f 100644 --- a/launcher/ui/MultiWorldListPage.cpp +++ b/launcher/ui/MultiWorldListPage.cpp @@ -38,7 +38,7 @@ #include "MultiWorldListPage.h" #include "minecraft/MultiWorldList.h" #include "ui/dialogs/CustomMessageBox.h" -#include "ui_MultiWorldListPage.h" //fix this iy +#include "ui_MultiWorldListPage.h" #include #include @@ -87,7 +87,7 @@ class MultiWorldListProxyModel : public QSortFilterProxyModel { }; MultiWorldListPage::MultiWorldListPage(MinecraftInstance* inst, MultiWorldList* worlds, QWidget* parent) - : QMainWindow(parent), m_inst(inst), ui(new Ui::MultiWorldListPage), m_worlds(worlds) //use MultiWorldListPage.ui to have separate ui from normal world list page iy + : QMainWindow(parent), m_inst(inst), ui(new Ui::MultiWorldListPage), m_worlds(worlds) { ui->setupUi(this); @@ -209,7 +209,7 @@ void MultiWorldListPage::on_actionRemove_triggered() void MultiWorldListPage::on_actionView_Folder_triggered() { - DesktopServices::openPath(m_worlds->dirs()[0].absolutePath(), true); //change this iy + DesktopServices::openPath(m_worlds->dirs()[0].absolutePath(), true); //remove view folder option for all worlds (make it world specific) iy } void MultiWorldListPage::on_actionData_Packs_triggered() @@ -433,7 +433,7 @@ void MultiWorldListPage::on_actionCopy_triggered() QInputDialog::getText(this, tr("World name"), tr("Enter a new name for the copy."), QLineEdit::Normal, world->name(), &ok); if (ok && name.length() > 0) { - world->install(m_worlds->dirs()[0].absolutePath(), name); //you know what to do iy + world->install(m_worlds->dirs()[0].absolutePath(), name); //ask which instance iy } } @@ -474,4 +474,4 @@ void MultiWorldListPage::on_actionJoin_triggered() APPLICATION->launch(m_inst, LaunchMode::Normal, std::make_shared(MinecraftTarget::parse(world->folderName(), true))); } -#include "MultiWorldListPage.moc" //change this iy +#include "MultiWorldListPage.moc"