summaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
authorMikaƫl Capelle <capelle.mikael@gmail.com>2020-10-01 18:52:24 +0200
committerGitHub <noreply@github.com>2020-10-01 18:52:24 +0200
commitcd3f496a5b9f6cc090c66a226d4f7f7557c9a8e1 (patch)
treee70588af4d80cd15906e4c817721740a55ce1297 /src/mainwindow.cpp
parentfac9d4caf6bc78f62f2f590acb4a05e654be659b (diff)
parent92585af197136df91842c8bd8496653d6df56832 (diff)
Merge pull request #1245 from Holt59/save-game-recursive
Allow MO2 to find game saves into subdirectories / Hide 'Enable Mods... ' when SaveGameInfo does not exist.
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index a20dfd06..fa5a790c 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1932,11 +1932,21 @@ void MainWindow::refreshSaveList()
QDir savesDir = currentSavesDir();
savesDir.setNameFilters(filters);
+ savesDir.setFilter(QDir::Files);
+ QDirIterator it(savesDir, QDirIterator::Subdirectories);
log::debug("reading save games from {}", savesDir.absolutePath());
- QFileInfoList files = savesDir.entryInfoList(QDir::Files, QDir::Time);
+ QFileInfoList files;
+ while (it.hasNext()) {
+ it.next();
+ files.append(it.fileInfo());
+ }
+ std::sort(files.begin(), files.end(), [](auto const& lhs, auto const& rhs) {
+ return lhs.fileTime(QFileDevice::FileModificationTime) < rhs.fileTime(QFileDevice::FileModificationTime);
+ });
+
for (const QFileInfo &file : files) {
- QListWidgetItem *item = new QListWidgetItem(file.fileName());
+ QListWidgetItem *item = new QListWidgetItem(savesDir.relativeFilePath(file.absoluteFilePath()));
item->setData(Qt::UserRole, file.absoluteFilePath());
ui->savegameList->addItem(item);
}
@@ -4963,25 +4973,25 @@ void MainWindow::fixMods_clicked(SaveGameInfo::MissingAssets const &missingAsset
}
-void MainWindow::on_savegameList_customContextMenuRequested(const QPoint &pos)
+void MainWindow::on_savegameList_customContextMenuRequested(const QPoint& pos)
{
- QItemSelectionModel *selection = ui->savegameList->selectionModel();
+ QItemSelectionModel* selection = ui->savegameList->selectionModel();
if (!selection->hasSelection()) {
return;
}
QMenu menu;
- QAction *action = menu.addAction(tr("Enable Mods..."));
- action->setEnabled(false);
- if (selection->selectedIndexes().count() == 1) {
- SaveGameInfo const *info = this->m_OrganizerCore.managedGame()->feature<SaveGameInfo>();
- if (info != nullptr) {
+ SaveGameInfo const* info = this->m_OrganizerCore.managedGame()->feature<SaveGameInfo>();
+ if (info != nullptr) {
+ QAction* action = menu.addAction(tr("Enable Mods..."));
+ action->setEnabled(false);
+ if (selection->selectedIndexes().count() == 1) {
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); });
+ connect(action, &QAction::triggered, this, [this, missing] { fixMods_clicked(missing); });
action->setEnabled(true);
}
}