From 34ce22bfd3ff80ed63a5d24869d9875a01bd478c Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Mon, 28 Sep 2020 20:22:07 +0200 Subject: Allow MO2 to find game saves into subdirectories. --- src/transfersavesdialog.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/transfersavesdialog.cpp') diff --git a/src/transfersavesdialog.cpp b/src/transfersavesdialog.cpp index 6b8f7bd0..ea1861d5 100644 --- a/src/transfersavesdialog.cpp +++ b/src/transfersavesdialog.cpp @@ -276,8 +276,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(); if (info == nullptr) { @@ -285,10 +283,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(save)); } -- cgit v1.3.1 From e261fffa8d88e385a21cadb2f45b68e6c96b5d67 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Mon, 28 Sep 2020 20:30:19 +0200 Subject: Fix transfer saves for recursive saves. --- src/transfersavesdialog.cpp | 25 +++++++++++++++++-------- src/transfersavesdialog.h | 5 +++-- 2 files changed, 20 insertions(+), 10 deletions(-) (limited to 'src/transfersavesdialog.cpp') diff --git a/src/transfersavesdialog.cpp b/src/transfersavesdialog.cpp index ea1861d5..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); @@ -326,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 &method, char const *errmsg) { @@ -339,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 &method, char const *errmsg); }; -- cgit v1.3.1