From a349ec24df44eaac8c083b8d07c51cabb8f62995 Mon Sep 17 00:00:00 2001 From: Thex Date: Tue, 22 Jan 2019 05:14:38 +0100 Subject: Added ability to move files from the overwrite folder to an existing mod --- src/mainwindow.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++---- src/mainwindow.h | 8 ++++++++ 2 files changed, 62 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index df78df82..bca6f072 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3485,18 +3485,67 @@ void MainWindow::createModFromOverwrite() return; } - IModInterface *newMod = m_OrganizerCore.createMod(name); + const IModInterface *newMod = m_OrganizerCore.createMod(name); if (newMod == nullptr) { return; } + doMoveOverwriteContentToMod(newMod->absolutePath()); +} + +void MainWindow::moveOverwriteContentToExistingMod() +{ + QStringList mods; + auto indexesByPriority = m_OrganizerCore.currentProfile()->getAllIndexesByPriority(); + for (auto & iter : indexesByPriority) { + if ((iter.second != UINT_MAX)) { + ModInfo::Ptr modInfo = ModInfo::getByIndex(iter.second); + if (!modInfo->hasFlag(ModInfo::FLAG_SEPARATOR) && !modInfo->hasFlag(ModInfo::FLAG_FOREIGN) && !modInfo->hasFlag(ModInfo::FLAG_OVERWRITE)) { + mods << modInfo->name(); + } + } + } + + ListDialog dialog(this); + QSettings &settings = m_OrganizerCore.settings().directInterface(); + QString key = QString("geometry/%1").arg(dialog.objectName()); + + dialog.setWindowTitle("Select a mod..."); + dialog.setChoices(mods); + dialog.restoreGeometry(settings.value(key).toByteArray()); + if (dialog.exec() == QDialog::Accepted) { + QString result = dialog.getChoice(); + if (!result.isEmpty()) { + + QString modAbsolutePath; + + for (const auto& mod : m_OrganizerCore.modsSortedByProfilePriority()) { + if (result.compare(mod) == 0) { + ModInfo::Ptr modInfo = ModInfo::getByIndex(ModInfo::getIndex(mod)); + modAbsolutePath = modInfo->absolutePath(); + break; + } + } + + if (modAbsolutePath.isNull()) { + qWarning("Mod %s has not been found, for some reason", qUtf8Printable(result)); + return; + } + + doMoveOverwriteContentToMod(modAbsolutePath); + } + } +} + +void MainWindow::doMoveOverwriteContentToMod(const QString &modAbsolutePath) +{ unsigned int overwriteIndex = ModInfo::findMod([](ModInfo::Ptr mod) -> bool { std::vector flags = mod->getFlags(); return std::find(flags.begin(), flags.end(), ModInfo::FLAG_OVERWRITE) != flags.end(); }); ModInfo::Ptr overwriteInfo = ModInfo::getByIndex(overwriteIndex); - shellMove(QStringList(QDir::toNativeSeparators(overwriteInfo->absolutePath()) + "\\*"), - QStringList(QDir::toNativeSeparators(newMod->absolutePath())), this); + shellMove((QDir::toNativeSeparators(overwriteInfo->absolutePath()) + "\\*"), + (QDir::toNativeSeparators(modAbsolutePath)), true, this); m_OrganizerCore.refreshModList(); } @@ -4348,6 +4397,7 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos) if (QDir(info->absolutePath()).count() > 2) { menu->addAction(tr("Sync to Mods..."), &m_OrganizerCore, SLOT(syncOverwrite())); menu->addAction(tr("Create Mod..."), this, SLOT(createModFromOverwrite())); + menu->addAction(tr("Move content to Mod..."), this, SLOT(moveOverwriteContentToExistingMod())); menu->addAction(tr("Clear Overwrite..."), this, SLOT(clearOverwrite())); } menu->addAction(tr("Open in Explorer"), this, SLOT(openExplorer_clicked())); @@ -6340,7 +6390,7 @@ void MainWindow::sendSelectedModsToSeparator_clicked() if ((iter->second != UINT_MAX)) { ModInfo::Ptr modInfo = ModInfo::getByIndex(iter->second); if (modInfo->hasFlag(ModInfo::FLAG_SEPARATOR)) { - separators << modInfo->name().chopped(10); + separators << modInfo->name().chopped(10); // Chops the "_separator" away from the name } } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 23c38f19..179ede87 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -469,6 +469,14 @@ private slots: BSA::EErrorCode extractBSA(BSA::Archive &archive, BSA::Folder::Ptr folder, const QString &destination, QProgressDialog &extractProgress); void createModFromOverwrite(); + /** + * @brief sends the content of the overwrite folder to an already existing mod + */ + void moveOverwriteContentToExistingMod(); + /** + * @brief actually sends the content of the overwrite folder to specified mod + */ + void doMoveOverwriteContentToMod(const QString &modAbsolutePath); void clearOverwrite(); void procError(QProcess::ProcessError error); -- cgit v1.3.1