diff options
| author | Mikaƫl Capelle <capelle.mikael@gmail.com> | 2020-10-01 18:52:24 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-01 18:52:24 +0200 |
| commit | cd3f496a5b9f6cc090c66a226d4f7f7557c9a8e1 (patch) | |
| tree | e70588af4d80cd15906e4c817721740a55ce1297 /src | |
| parent | fac9d4caf6bc78f62f2f590acb4a05e654be659b (diff) | |
| parent | 92585af197136df91842c8bd8496653d6df56832 (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')
| -rw-r--r-- | src/mainwindow.cpp | 30 | ||||
| -rw-r--r-- | src/transfersavesdialog.cpp | 51 | ||||
| -rw-r--r-- | src/transfersavesdialog.h | 5 |
3 files changed, 60 insertions, 26 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); } } diff --git a/src/transfersavesdialog.cpp b/src/transfersavesdialog.cpp index 6b8f7bd0..f8ebbb9d 100644 --- a/src/transfersavesdialog.cpp +++ b/src/transfersavesdialog.cpp @@ -182,7 +182,9 @@ void TransferSavesDialog::on_moveToLocalBtn_clicked() {
QString character = ui->globalCharacterList->currentItem()->text();
if (transferCharacters(
- character, MOVE_SAVES TO_PROFILE, m_GlobalSaves[character],
+ character, MOVE_SAVES TO_PROFILE,
+ m_GamePlugin->savesDirectory(),
+ m_GlobalSaves[character],
m_Profile.savePath(),
[this](const QString &source, const QString &destination) -> bool {
return shellMove(source, destination, this);
@@ -199,7 +201,9 @@ void TransferSavesDialog::on_copyToLocalBtn_clicked() {
QString character = ui->globalCharacterList->currentItem()->text();
if (transferCharacters(
- character, COPY_SAVES TO_PROFILE, m_GlobalSaves[character],
+ character, COPY_SAVES TO_PROFILE,
+ m_GamePlugin->savesDirectory(),
+ m_GlobalSaves[character],
m_Profile.savePath(),
[this](const QString &source, const QString &destination) -> bool {
return shellCopy(source, destination, this);
@@ -214,7 +218,9 @@ void TransferSavesDialog::on_moveToGlobalBtn_clicked() {
QString character = ui->localCharacterList->currentItem()->text();
if (transferCharacters(
- character, MOVE_SAVES TO_GLOBAL, m_LocalSaves[character],
+ character, MOVE_SAVES TO_GLOBAL,
+ m_Profile.savePath(),
+ m_LocalSaves[character],
m_GamePlugin->savesDirectory().absolutePath(),
[this](const QString &source, const QString &destination) -> bool {
return shellMove(source, destination, this);
@@ -231,7 +237,9 @@ void TransferSavesDialog::on_copyToGlobalBtn_clicked() {
QString character = ui->localCharacterList->currentItem()->text();
if (transferCharacters(
- character, COPY_SAVES TO_GLOBAL, m_LocalSaves[character],
+ character, COPY_SAVES TO_GLOBAL,
+ m_Profile.savePath(),
+ m_LocalSaves[character],
m_GamePlugin->savesDirectory().absolutePath(),
[this](const QString &source, const QString &destination) -> bool {
return shellCopy(source, destination, this);
@@ -276,8 +284,6 @@ void TransferSavesDialog::on_localCharacterList_currentTextChanged(const QString void TransferSavesDialog::refreshSaves(SaveCollection &saveCollection, QString const &savedir)
{
saveCollection.clear();
- QDir savesDir(savedir);
- savesDir.setNameFilters(QStringList() << QString("*.%1").arg(m_GamePlugin->savegameExtension()));
SaveGameInfo const *info = m_GamePlugin->feature<SaveGameInfo>();
if (info == nullptr) {
@@ -285,10 +291,26 @@ void TransferSavesDialog::refreshSaves(SaveCollection &saveCollection, QString c info = &dummyInfo;
}
- QStringList files = savesDir.entryList(QDir::Files, QDir::Time);
- for (const QString &filename : files) {
- QString file = savesDir.absoluteFilePath(filename);
- MOBase::ISaveGame const *save = info->getSaveGameInfo(file);
+ QStringList filters;
+ filters << QString("*.") + m_GamePlugin->savegameExtension();
+
+ QDir savesDir(savedir);
+ savesDir.setNameFilters(QStringList() << QString("*.") + m_GamePlugin->savegameExtension());
+ savesDir.setFilter(QDir::Files);
+ QDirIterator it(savesDir, QDirIterator::Subdirectories);
+ log::debug("reading save games from {}", savesDir.absolutePath());
+
+ 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) {
+ MOBase::ISaveGame const *save = info->getSaveGameInfo(file.absoluteFilePath());
saveCollection[save->getSaveGroupIdentifier()].push_back(
std::unique_ptr<MOBase::ISaveGame const>(save));
}
@@ -312,8 +334,10 @@ void TransferSavesDialog::refreshCharacters(const SaveCollection &saveCollection }
bool TransferSavesDialog::transferCharacters(
- QString const &character, char const *message, SaveList &saves,
- QString const &dest,
+ QString const &character, char const *message,
+ QDir const& sourceDirectory,
+ SaveList &saves,
+ QDir const& destination,
const std::function<bool(const QString &, const QString &)> &method,
char const *errmsg)
{
@@ -325,11 +349,10 @@ bool TransferSavesDialog::transferCharacters( OverwriteMode overwriteMode = OVERWRITE_ASK;
- QDir destination(dest);
for (SaveListItem const &save : saves) {
for (QString source : save->allFiles()) {
QFileInfo sourceFile(source);
- QString destinationFile(destination.absoluteFilePath(sourceFile.fileName()));
+ QString destinationFile(destination.absoluteFilePath(sourceDirectory.relativeFilePath(source)));
//If the file is already there, let them skip (or not).
if (QFile::exists(destinationFile)) {
diff --git a/src/transfersavesdialog.h b/src/transfersavesdialog.h index dee41c72..b983ad9e 100644 --- a/src/transfersavesdialog.h +++ b/src/transfersavesdialog.h @@ -92,8 +92,9 @@ private: QPushButton *move);
bool transferCharacters(
- QString const &character, char const *message, SaveList &saves,
- QString const &dest,
+ QString const &character, char const *message,
+ QDir const& sourceDirectory, SaveList &saves,
+ QDir const& dest,
const std::function<bool(const QString &, const QString &)> &method,
char const *errmsg);
};
|
