From 4f8c71d62626aa61fb4d13f80bc043d5e6492c3e Mon Sep 17 00:00:00 2001 From: Tannin Date: Fri, 12 Feb 2016 19:08:25 +0100 Subject: merged master into new_vfs_library --- src/mainwindow.cpp | 299 ++++++++++++++++++++++++----------------------------- 1 file changed, 133 insertions(+), 166 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c242bfe6..db7bd682 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -20,7 +20,24 @@ along with Mod Organizer. If not, see . #include "mainwindow.h" #include "ui_mainwindow.h" +#include "directoryentry.h" +#include "directoryrefresher.h" +#include "executableinfo.h" +#include "executableslist.h" +#include "guessedvalue.h" +#include "imodinterface.h" +#include "iplugingame.h" +#include "iplugindiagnose.h" +#include "isavegame.h" +#include "isavegameinfowidget.h" +#include "nexusinterface.h" +#include "organizercore.h" +#include "pluginlistsortproxy.h" +#include "previewgenerator.h" +#include "savegameinfo.h" #include "spawn.h" +#include "versioninfo.h" + #include "report.h" #include "modlist.h" #include "modlistsortproxy.h" @@ -31,7 +48,6 @@ along with Mod Organizer. If not, see . #include "editexecutablesdialog.h" #include "categories.h" #include "categoriesdialog.h" -#include "utility.h" #include "modinfodialog.h" #include "overwriteinfodialog.h" #include "activatemodsdialog.h" @@ -41,16 +57,13 @@ along with Mod Organizer. If not, see . #include "messagedialog.h" #include "installationmanager.h" #include "lockeddialog.h" -#include "syncoverwritedialog.h" #include "logbuffer.h" #include "downloadlistsortproxy.h" #include "motddialog.h" #include "filedialogmemory.h" -#include "questionboxmemory.h" #include "tutorialmanager.h" #include "modflagicondelegate.h" #include "genericicondelegate.h" -#include "credentialsdialog.h" #include "selectiondialog.h" #include "csvbuilder.h" #include "savetextasdialog.h" @@ -59,62 +72,86 @@ along with Mod Organizer. If not, see . #include "browserdialog.h" #include "aboutdialog.h" #include "safewritefile.h" -//? -//#include "isavegame.h" -//#include "savegameinfo.h" -//? #include "nxmaccessmanager.h" -#include -#include +#include "appconfig.h" #include -#include #include #include -#include #include -#include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include #include -#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) #include #else #include #endif -#include -#include #ifndef Q_MOC_RUN #include @@ -123,18 +160,16 @@ along with Mod Organizer. If not, see . #include #endif -#include #include -#include -#include -#include -#include +#include +#include #include #include -#include -#include -#include +#include +#include +#include +#include #ifdef TEST_MODELS #include "modeltest.h" @@ -826,37 +861,24 @@ void MainWindow::setBrowserGeometry(const QByteArray &geometry) m_IntegratedBrowser.restoreGeometry(geometry); } - -SaveGameGamebryo *MainWindow::getSaveGame(const QString &name) -{ - IPluginGame const *game = m_OrganizerCore.managedGame(); - return new SaveGameGamebryo(this, name, game); -} - - -SaveGameGamebryo *MainWindow::getSaveGame(QListWidgetItem *item) -{ - try { - SaveGameGamebryo *saveGame = getSaveGame(item->data(Qt::UserRole).toString()); - saveGame->setParent(item->listWidget()); - return saveGame; - } catch (const std::exception &e) { - reportError(tr("failed to read savegame: %1").arg(e.what())); - return nullptr; - } -} - - -void MainWindow::displaySaveGameInfo(const SaveGameGamebryo *save, QPoint pos) +void MainWindow::displaySaveGameInfo(QListWidgetItem *newItem) { + QString const &save = newItem->data(Qt::UserRole).toString(); if (m_CurrentSaveView == nullptr) { - m_CurrentSaveView = new SaveGameInfoWidgetGamebryo(save, m_OrganizerCore.pluginList(), this); - } else { - m_CurrentSaveView->setSave(save); + IPluginGame const *game = m_OrganizerCore.managedGame(); + SaveGameInfo const *info = game->feature(); + if (info != nullptr) { + m_CurrentSaveView = info->getSaveGameWidget(this); + } + if (m_CurrentSaveView == nullptr) { + return; + } } + m_CurrentSaveView->setSave(save); QRect screenRect = QApplication::desktop()->availableGeometry(m_CurrentSaveView); + QPoint pos = QCursor::pos(); if (pos.x() + m_CurrentSaveView->width() > screenRect.right()) { pos.rx() -= (m_CurrentSaveView->width() + 2); } else { @@ -871,8 +893,9 @@ void MainWindow::displaySaveGameInfo(const SaveGameGamebryo *save, QPoint pos) m_CurrentSaveView->move(pos); m_CurrentSaveView->show(); + m_CurrentSaveView->setProperty("displayItem", qVariantFromValue(static_cast(newItem))); + ui->savegameList->activateWindow(); - connect(m_CurrentSaveView, SIGNAL(closeSaveInfo()), this, SLOT(hideSaveGameInfo())); } @@ -880,21 +903,15 @@ void MainWindow::saveSelectionChanged(QListWidgetItem *newItem) { if (newItem == nullptr) { hideSaveGameInfo(); - } else if ((m_CurrentSaveView == nullptr) || (newItem != m_CurrentSaveView->property("displayItem").value())) { - const SaveGameGamebryo *save = getSaveGame(newItem); - if (save != nullptr) { - displaySaveGameInfo(save, QCursor::pos()); - m_CurrentSaveView->setProperty("displayItem", qVariantFromValue((void*)newItem)); - } + } else if (m_CurrentSaveView == nullptr || newItem != m_CurrentSaveView->property("displayItem").value()) { + displaySaveGameInfo(newItem); } } - void MainWindow::hideSaveGameInfo() { if (m_CurrentSaveView != nullptr) { - disconnect(m_CurrentSaveView, SIGNAL(closeSaveInfo()), this, SLOT(hideSaveGameInfo())); m_CurrentSaveView->deleteLater(); m_CurrentSaveView = nullptr; } @@ -1258,7 +1275,7 @@ QDir MainWindow::currentSavesDir() const { QDir savesDir; if (m_OrganizerCore.currentProfile()->localSavesEnabled()) { - savesDir.setPath(m_OrganizerCore.currentProfile()->absolutePath() + "/saves"); + savesDir.setPath(m_OrganizerCore.currentProfile()->savePath()); } else { wchar_t path[MAX_PATH]; ::GetPrivateProfileStringW( @@ -3002,109 +3019,47 @@ void MainWindow::on_categoriesList_itemSelectionChanged() void MainWindow::deleteSavegame_clicked() { - QModelIndexList selectedIndexes = ui->savegameList->selectionModel()->selectedIndexes(); + SaveGameInfo const *info = m_OrganizerCore.managedGame()->feature(); QString savesMsgLabel; QStringList deleteFiles; int count = 0; - for (const QModelIndex &idx : selectedIndexes) { - QString name = idx.data().toString(); - SaveGame *save = new SaveGame(this, idx.data(Qt::UserRole).toString(), m_OrganizerCore.managedGame()); + for (const QModelIndex &idx : ui->savegameList->selectionModel()->selectedIndexes()) { + QString name = idx.data(Qt::UserRole).toString(); if (count < 10) { savesMsgLabel += "
  • " + QFileInfo(name).completeBaseName() + "
  • "; } ++count; - deleteFiles << save->saveFiles(); + if (info == nullptr) { + deleteFiles.push_back(name); + } else { + ISaveGame const *save = info->getSaveGameInfo(name); + deleteFiles += save->allFiles(); + } } if (count > 10) { savesMsgLabel += "
  • ... " + tr("%1 more").arg(count - 10) + "
  • "; } - if (QMessageBox::question(this, tr("Confirm"), tr("Are you sure you want to remove the following %n save(s)?
      %1

    Removed saves will be sent to the Recycle Bin.", "", selectedIndexes.count()) - .arg(savesMsgLabel), + if (QMessageBox::question(this, tr("Confirm"), + tr("Are you sure you want to remove the following %n save(s)?
    " + "
      %1

    " + "Removed saves will be sent to the Recycle Bin.", "", count) + .arg(savesMsgLabel), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { shellDelete(deleteFiles, true); // recycle bin delete. } } -void MainWindow::fixMods_clicked() +void MainWindow::fixMods_clicked(SaveGameInfo::MissingAssets const &missingAssets) { - QListWidgetItem *selectedItem = ui->savegameList->currentItem(); - - if (selectedItem == nullptr) - return; - - // if required, parse the save game - if (selectedItem->data(Qt::UserRole).isNull()) { - QVariant temp; - SaveGameGamebryo *save = getSaveGame(selectedItem->data(Qt::UserRole).toString()); - save->setParent(selectedItem->listWidget()); - temp.setValue(save); - selectedItem->setData(Qt::UserRole, temp); - } - - const SaveGameGamebryo *save = getSaveGame(selectedItem); - - // collect the list of missing plugins - std::map > missingPlugins; - - for (int i = 0; i < save->numPlugins(); ++i) { - const QString &pluginName = save->plugin(i); - if (!m_OrganizerCore.pluginList()->isEnabled(pluginName)) { - missingPlugins[pluginName] = std::vector(); - } - } - - // figure out, for each esp/esm, which mod, if any, contains it - QStringList espFilter("*.esp"); - espFilter.append("*.esm"); - - // search in data - { - QDir dataDir(m_OrganizerCore.managedGame()->dataDirectory()); - QStringList esps = dataDir.entryList(espFilter); - for (const QString &esp : esps) { - std::map >::iterator iter = missingPlugins.find(esp); - if (iter != missingPlugins.end()) { - iter->second.push_back(""); - } - } - } - - // search in mods - for (unsigned int i = 0; i < m_OrganizerCore.currentProfile()->numRegularMods(); ++i) { - int modIndex = m_OrganizerCore.currentProfile()->modIndexByPriority(i); - ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex); - - QStringList esps = QDir(modInfo->absolutePath()).entryList(espFilter); - for (const QString &esp : esps) { - std::map >::iterator iter = missingPlugins.find(esp); - if (iter != missingPlugins.end()) { - iter->second.push_back(modInfo->name()); - } - } - } - - // search in overwrite - { - QDir overwriteDir(qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::overwritePath())); - QStringList esps = overwriteDir.entryList(espFilter); - for (const QString &esp : esps) { - std::map >::iterator iter = missingPlugins.find(esp); - if (iter != missingPlugins.end()) { - iter->second.push_back(""); - } - } - } - - - ActivateModsDialog dialog(missingPlugins, this); + ActivateModsDialog dialog(missingAssets, this); if (dialog.exec() == QDialog::Accepted) { // activate the required mods, then enable all esps std::set modsToActivate = dialog.getModsToActivate(); @@ -3131,13 +3086,25 @@ void MainWindow::on_savegameList_customContextMenuRequested(const QPoint &pos) { QItemSelectionModel *selection = ui->savegameList->selectionModel(); - if (!selection->hasSelection()) + if (!selection->hasSelection()) { return; + } QMenu menu; - - if (!(selection->selectedIndexes().count() > 1)) - menu.addAction(tr("Fix Mods..."), this, SLOT(fixMods_clicked())); + QAction *action = menu.addAction(tr("Enable Mods...")); + action->setEnabled(false); + + if (selection->selectedIndexes().count() == 1) { + SaveGameInfo const *info = this->m_OrganizerCore.managedGame()->feature(); + if (info != nullptr) { + QString save = ui->savegameList->currentItem()->data(Qt::UserRole).toString(); + SaveGameInfo::MissingAssets missing = info->getMissingAssets(save); + if (missing.size() != 0) { + connect(action, &QAction::triggered, this, [this, missing]{ fixMods_clicked(missing); }); + action->setEnabled(true); + } + } + } QString deleteMenuLabel = tr("Delete %n save(s)", "", selection->selectedIndexes().count()); -- cgit v1.3.1