From cec5f7332eceb23b8236b7916e964558e8f82ad7 Mon Sep 17 00:00:00 2001 From: janrupf Date: Wed, 19 Jun 2019 17:54:39 +0200 Subject: [PATCH] NOISSUE Prepare mod install for possible move --- api/logic/minecraft/SimpleModList.cpp | 10 ++++------ api/logic/minecraft/SimpleModList.h | 2 +- application/pages/instance/ModFolderPage.cpp | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/api/logic/minecraft/SimpleModList.cpp b/api/logic/minecraft/SimpleModList.cpp index 6f4011a9..298328e4 100644 --- a/api/logic/minecraft/SimpleModList.cpp +++ b/api/logic/minecraft/SimpleModList.cpp @@ -97,7 +97,7 @@ bool SimpleModList::isValid() } // FIXME: this does not take disabled mod (with extra .disable extension) into account... -bool SimpleModList::installMod(const QString &filename) +bool SimpleModList::installMod(const QString &filename, bool move) { // NOTE: fix for GH-1178: remove trailing slash to avoid issues with using the empty result of QFileInfo::fileName auto originalPath = FS::NormalizePath(filename); @@ -143,7 +143,7 @@ bool SimpleModList::installMod(const QString &filename) } qDebug() << newpath << "has been deleted."; } - if (!QFile::copy(fileinfo.filePath(), newpath)) + if (move ? !QFile::rename(fileinfo.filePath(), newpath) : !QFile::copy(fileinfo.filePath(), newpath)) { qWarning() << "Copy from" << originalPath << "to" << newpath << "has failed."; // FIXME: report error in a user-visible way @@ -163,7 +163,7 @@ bool SimpleModList::installMod(const QString &filename) return false; } - if (!FS::copy(from, newpath)()) + if (move ? !QDir().rename(from, newpath) : !FS::copy(from, newpath)()) { qWarning() << "Copy of folder from" << originalPath << "to" << newpath << "has (potentially partially) failed."; return false; @@ -307,7 +307,6 @@ QVariant SimpleModList::headerData(int section, Qt::Orientation orientation, int default: return QVariant(); } - return QVariant(); } Qt::ItemFlags SimpleModList::flags(const QModelIndex &index) const @@ -357,9 +356,8 @@ bool SimpleModList::dropMimeData(const QMimeData* data, Qt::DropAction action, i { continue; } - // TODO: implement not only copy, but also move // FIXME: handle errors here - installMod(url.toLocalFile()); + installMod(url.toLocalFile(), action == Qt::DropAction::MoveAction); } return true; } diff --git a/api/logic/minecraft/SimpleModList.h b/api/logic/minecraft/SimpleModList.h index 3ed2edfe..72973b6d 100644 --- a/api/logic/minecraft/SimpleModList.h +++ b/api/logic/minecraft/SimpleModList.h @@ -83,7 +83,7 @@ public: /** * Adds the given mod to the list at the given index - if the list supports custom ordering */ - bool installMod(const QString& filename); + bool installMod(const QString& filename, bool move); /// Deletes all the selected mods virtual bool deleteMods(const QModelIndexList &indexes); diff --git a/application/pages/instance/ModFolderPage.cpp b/application/pages/instance/ModFolderPage.cpp index 15dd55a2..d20ba19d 100644 --- a/application/pages/instance/ModFolderPage.cpp +++ b/application/pages/instance/ModFolderPage.cpp @@ -163,7 +163,7 @@ void ModFolderPage::on_addModBtn_clicked() { for (auto filename : list) { - m_mods->installMod(filename); + m_mods->installMod(filename, false); } } }