summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Tanner <trtanner@btinternet.com>2015-12-13 18:30:40 +0000
committerThomas Tanner <trtanner@btinternet.com>2015-12-13 18:30:40 +0000
commitba176e5e9b639ac0770192987833a3b40e71409a (patch)
tree2c1a82d3fcede23e82bddf5b31768e03982d8950
parentc344714661a2404a54428439f0cf7dbb1573d01f (diff)
Remove dependency of TransferSave on SaveGameBryo, part of fix for #418
Added a method to Profile class to get location of save games for the profile. I haven't added this to IProfile as am in two minds. Aside from this have done cleanups of issues suggested by include-what-you-use, and some OCD sorting of #includes
-rw-r--r--src/aboutdialog.cpp8
-rw-r--r--src/aboutdialog.h7
-rw-r--r--src/iuserinterface.h1
-rw-r--r--src/mainwindow.cpp2
-rw-r--r--src/profile.cpp36
-rw-r--r--src/profile.h19
-rw-r--r--src/profilesdialog.cpp24
-rw-r--r--src/profilesdialog.h15
-rw-r--r--src/transfersavesdialog.cpp409
-rw-r--r--src/transfersavesdialog.h34
10 files changed, 314 insertions, 241 deletions
diff --git a/src/aboutdialog.cpp b/src/aboutdialog.cpp
index 6fce2acb..3657a10d 100644
--- a/src/aboutdialog.cpp
+++ b/src/aboutdialog.cpp
@@ -22,6 +22,14 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "ui_aboutdialog.h"
#include <utility.h>
+#include <QApplication>
+#include <QLabel>
+#include <QListWidget>
+#include <QListWidgetItem>
+#include <QTextBrowser>
+#include <QVariant>
+#include <Qt>
+
AboutDialog::AboutDialog(const QString &version, QWidget *parent)
: QDialog(parent)
diff --git a/src/aboutdialog.h b/src/aboutdialog.h
index c3b38c10..103a0d2f 100644
--- a/src/aboutdialog.h
+++ b/src/aboutdialog.h
@@ -22,10 +22,11 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#define ABOUTDIALOG_H
#include <QDialog>
-#include <QListWidgetItem>
+class QListWidgetItem;
+#include <QObject>
+#include <QString>
+
#include <map>
-#include <vector>
-#include <utility>
namespace Ui {
class AboutDialog;
diff --git a/src/iuserinterface.h b/src/iuserinterface.h
index bcf800b7..e03bcde2 100644
--- a/src/iuserinterface.h
+++ b/src/iuserinterface.h
@@ -7,6 +7,7 @@
#include <ipluginmodpage.h>
#include <delayedfilewriter.h>
+class QSettings;
class IUserInterface
{
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index f30e46f1..a85a0fb3 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1262,7 +1262,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(
diff --git a/src/profile.cpp b/src/profile.cpp
index 77f6ebd1..b0b8db46 100644
--- a/src/profile.cpp
+++ b/src/profile.cpp
@@ -19,30 +19,40 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "profile.h"
-#include "windows_error.h"
#include "modinfo.h"
#include "safewritefile.h"
#include <utility.h>
-#include <util.h>
#include <error_report.h>
-#include <appconfig.h>
+#include "appconfig.h"
#include <iplugingame.h>
#include <report.h>
#include <bsainvalidation.h>
#include <dataarchives.h>
-#include <QMessageBox>
#include <QApplication>
-#include <QSettings>
-#include <QTemporaryFile>
+#include <QFile> // for QFile
+#include <QFlags> // for operator|, QFlags
+#include <QIODevice> // for QIODevice, etc
+#include <QMessageBox>
+#include <QScopedArrayPointer>
+#include <QStringList> // for QStringList
+#include <QtDebug> // for qDebug, qWarning, etc
+#include <QtGlobal> // for qPrintable
+
+#include <Windows.h>
+#include <assert.h> // for assert
+#include <limits.h> // for UINT_MAX, INT_MAX, etc
+#include <stddef.h> // for size_t
+#include <string.h> // for wcslen
+
+#include <algorithm> // for max, min
+#include <exception> // for exception
#include <functional>
+#include <set> // for set
+#include <utility> // for find
#include <stdexcept>
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <shlobj.h>
-
using namespace MOBase;
using namespace MOShared;
@@ -687,6 +697,12 @@ QString Profile::absolutePath() const
return QDir::cleanPath(m_Directory.absolutePath());
}
+QString Profile::savePath() const
+{
+ return QDir::cleanPath(m_Directory.absoluteFilePath("saves"));
+
+}
+
void Profile::rename(const QString &newName)
{
QDir profileDir(qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::profilesPath()));
diff --git a/src/profile.h b/src/profile.h
index e33ac674..39e8ff5f 100644
--- a/src/profile.h
+++ b/src/profile.h
@@ -25,12 +25,16 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <iprofile.h>
#include <delayedfilewriter.h>
-#include <QString>
+#include <QByteArray>
#include <QDir>
-#include <QSettings>
+#include <QObject>
+#include <QString>
-#include <vector>
+#include <boost/shared_ptr.hpp>
+
+#include <string>
#include <tuple>
+#include <vector>
namespace MOBase { class IPluginGame; }
@@ -172,6 +176,15 @@ public:
**/
QString absolutePath() const;
+ /**
+ * @return path to this profile's save games
+ **/
+ QString savePath() const;
+
+ /**
+ * @brief rename profile
+ * @param newName new name of profile
+ */
void rename(const QString &newName);
/**
diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp
index b21aee53..4d0b3389 100644
--- a/src/profilesdialog.cpp
+++ b/src/profilesdialog.cpp
@@ -19,22 +19,28 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "profilesdialog.h"
#include "ui_profilesdialog.h"
+
+#include "appconfig.h"
+#include "bsainvalidation.h"
+#include "iplugingame.h"
+#include "profile.h"
+#include "profileinputdialog.h"
#include "report.h"
-#include "utility.h"
#include "transfersavesdialog.h"
-#include "profileinputdialog.h"
-#include "mainwindow.h"
-#include "aboutdialog.h"
-#include <iplugingame.h>
-#include <bsainvalidation.h>
-#include <appconfig.h>
-#include <QListWidgetItem>
+#include "utility.h"
+
+#include <Qt>
+#include <QDir>
+#include <QDirIterator>
#include <QInputDialog>
#include <QLineEdit>
-#include <QDirIterator>
+#include <QListWidgetItem>
#include <QMessageBox>
#include <QWhatsThis>
+#include <Windows.h>
+
+#include <exception>
using namespace MOBase;
using namespace MOShared;
diff --git a/src/profilesdialog.h b/src/profilesdialog.h
index 073d92b7..0e79b94b 100644
--- a/src/profilesdialog.h
+++ b/src/profilesdialog.h
@@ -21,17 +21,16 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#define PROFILESDIALOG_H
#include "tutorabledialog.h"
-#include <QListWidgetItem>
-#include "profile.h"
+class Profile;
+class QListWidget;
+class QListWidgetItem;
+#include <QObject>
+class QString;
-namespace Ui {
- class ProfilesDialog;
-}
+namespace Ui { class ProfilesDialog; }
-namespace MOBase {
- class IPluginGame;
-}
+namespace MOBase { class IPluginGame; }
/**
diff --git a/src/transfersavesdialog.cpp b/src/transfersavesdialog.cpp
index 48fc4548..710a33b9 100644
--- a/src/transfersavesdialog.cpp
+++ b/src/transfersavesdialog.cpp
@@ -21,19 +21,70 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "ui_transfersavesdialog.h"
#include "iplugingame.h"
-#include "savegamegamebyro.h"
-#include "utility.h"
+#include "isavegame.h"
+#include "savegameinfo.h"
+#include "scriptextender.h"
+#include <QtDebug>
+#include <QDateTime>
#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+#include <QFlags>
+#include <QLabel>
+#include <QListWidget>
+#include <QListWidgetItem>
#include <QMessageBox>
+#include <QPushButton>
+#include <QStringList>
-#include <Shlwapi.h>
-#include <shlobj.h>
-
+class QWidget; //Do we /really/ need this?
using namespace MOBase;
using namespace MOShared;
+//These two classes give the save-transfer box a smidgin of useful info even
+//if save game isn't supported yet.
+namespace {
+
+class DummySave : public ISaveGame
+{
+public:
+ DummySave(QString const &filename) :
+ m_File(filename)
+ {}
+
+ ~DummySave() {}
+
+ virtual QString getFilename() const override
+ {
+ return m_File;
+ }
+
+ virtual QDateTime getCreationTime() const override
+ {
+ return QFileInfo(m_File).created();
+ }
+
+ virtual QString getIdentifier() const override
+ {
+ return m_File;
+ }
+
+private:
+ QString m_File;
+};
+
+class DummyInfo : public SaveGameInfo
+{
+public:
+ virtual MOBase::ISaveGame const *getSaveGameInfo(QString const &file) const override
+ {
+ return new DummySave(file);
+ }
+};
+
+} //end anonymous namespace
TransferSavesDialog::TransferSavesDialog(const Profile &profile, IPluginGame const *gamePlugin, QWidget *parent)
: TutorableDialog("TransferSaves", parent)
@@ -42,6 +93,7 @@ TransferSavesDialog::TransferSavesDialog(const Profile &profile, IPluginGame con
, m_GamePlugin(gamePlugin)
{
ui->setupUi(this);
+ ui->label_2->setText(tr("Characters for profile %1").arg(m_Profile.name()));
refreshGlobalSaves();
refreshLocalSaves();
refreshGlobalCharacters();
@@ -53,84 +105,27 @@ TransferSavesDialog::~TransferSavesDialog()
delete ui;
}
-
void TransferSavesDialog::refreshGlobalSaves()
{
- m_GlobalSaves.clear();
- QDir savesDir(m_GamePlugin->savesDirectory());
- savesDir.setNameFilters(QStringList() << QString("*.%1").arg(m_GamePlugin->savegameExtension()));
-
- QStringList files = savesDir.entryList(QDir::Files, QDir::Time);
-
- for (const QString &filename : files) {
- SaveGameGamebryo *save = new SaveGameGamebryo(this, savesDir.absoluteFilePath(filename), m_GamePlugin);
- save->setParent(this);
- m_GlobalSaves.push_back(save);
- }
+ refreshSaves(m_GlobalSaves, m_GamePlugin->savesDirectory().absolutePath());
}
void TransferSavesDialog::refreshLocalSaves()
{
- m_LocalSaves.clear();
-
- QDir savesDir(m_Profile.absolutePath() + "/saves");
-
- savesDir.setNameFilters(QStringList() << QString("*.%1").arg(m_GamePlugin->savegameExtension()));
-
- QStringList files = savesDir.entryList(QDir::Files, QDir::Time);
-
- foreach (const QString &filename, files) {
- SaveGameGamebryo *save = new SaveGameGamebryo(this, savesDir.absoluteFilePath(filename), m_GamePlugin);
- save->setParent(this);
- m_LocalSaves.push_back(save);
- }
+ refreshSaves(m_LocalSaves, m_Profile.savePath());
}
void TransferSavesDialog::refreshGlobalCharacters()
{
- std::set<QString> characters;
- for (std::vector<SaveGame*>::const_iterator iter = m_GlobalSaves.begin();
- iter != m_GlobalSaves.end(); ++iter) {
- characters.insert((*iter)->pcName());
- }
- ui->globalCharacterList->clear();
- for (std::set<QString>::const_iterator iter = characters.begin();
- iter != characters.end(); ++iter) {
- ui->globalCharacterList->addItem(*iter);
- }
- if (ui->globalCharacterList->count() > 0) {
- ui->globalCharacterList->setCurrentRow(0);
- ui->copyToLocalBtn->setEnabled(true);
- ui->moveToLocalBtn->setEnabled(true);
- } else {
- ui->copyToLocalBtn->setEnabled(false);
- ui->moveToLocalBtn->setEnabled(false);
- }
+ refreshCharacters(m_GlobalSaves, ui->globalCharacterList, ui->copyToLocalBtn, ui->moveToLocalBtn);
}
void TransferSavesDialog::refreshLocalCharacters()
{
- std::set<QString> characters;
- for (std::vector<SaveGame*>::const_iterator iter = m_LocalSaves.begin();
- iter != m_LocalSaves.end(); ++iter) {
- characters.insert((*iter)->pcName());
- }
- ui->localCharacterList->clear();
- for (std::set<QString>::const_iterator iter = characters.begin();
- iter != characters.end(); ++iter) {
- ui->localCharacterList->addItem(*iter);
- }
- if (ui->localCharacterList->count() > 0) {
- ui->localCharacterList->setCurrentRow(0);
- ui->copyToGlobalBtn->setEnabled(true);
- ui->moveToGlobalBtn->setEnabled(true);
- } else {
- ui->copyToGlobalBtn->setEnabled(false);
- ui->moveToGlobalBtn->setEnabled(false);
- }
+ refreshCharacters(m_LocalSaves, ui->localCharacterList, ui->copyToGlobalBtn, ui->moveToGlobalBtn);
}
@@ -152,153 +147,71 @@ bool TransferSavesDialog::testOverwrite(OverwriteMode &overwriteMode, const QStr
return res == QMessageBox::Yes;
}
+#define MOVE_SAVES "Move all save games of character \"%1\""
+#define COPY_SAVES "Copy all save games of character \"%1\""
+
+#define TO_PROFILE "to the profile?"
+#define TO_GLOBAL "to the global location? Please be aware that this will mess up the running number of save games."
+
void TransferSavesDialog::on_moveToLocalBtn_clicked()
{
- QString selectedCharacter = ui->globalCharacterList->currentItem()->text();
- if (QMessageBox::question(this, tr("Confirm"),
- tr("Copy all save games of character \"%1\" to the profile?").arg(selectedCharacter),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
- QString destination = m_Profile.absolutePath() + "/saves";
- OverwriteMode overwriteMode = OVERWRITE_ASK;
-
- for (std::vector<SaveGame*>::const_iterator iter = m_GlobalSaves.begin();
- iter != m_GlobalSaves.end(); ++iter) {
- if ((*iter)->pcName() == selectedCharacter) {
- QStringList files = (*iter)->saveFiles();
- foreach (const QString &file, files) {
- QFileInfo fileInfo(file);
- QString destinationFile = destination + "/" + fileInfo.fileName();
- if (QFile::exists(destinationFile)) {
- if (testOverwrite(overwriteMode, destinationFile)) {
- QFile::remove(destinationFile);
- } else {
- continue;
- }
- }
- if (!QFile::rename(fileInfo.absoluteFilePath(), destinationFile)) {
- qCritical("failed to move %s to %s",
- fileInfo.absoluteFilePath().toUtf8().constData(),
- destinationFile.toUtf8().constData());
- }
- }
- }
- }
+ QString character = ui->globalCharacterList->currentItem()->text();
+ if (transferCharacters(character,
+ MOVE_SAVES TO_PROFILE,
+ m_GlobalSaves[character],
+ m_Profile.savePath(),
+ QFile::rename,
+ "Failed to move %s to %s"))
+ {
+ refreshGlobalSaves();
+ refreshGlobalCharacters();
+ refreshLocalSaves();
+ refreshLocalCharacters();
}
- refreshGlobalSaves();
- refreshGlobalCharacters();
- refreshLocalSaves();
- refreshLocalCharacters();
}
void TransferSavesDialog::on_copyToLocalBtn_clicked()
{
- QString selectedCharacter = ui->globalCharacterList->currentItem()->text();
- if (QMessageBox::question(this, tr("Confirm"),
- tr("Copy all save games of character \"%1\" to the profile?").arg(selectedCharacter),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
- QString destination = m_Profile.absolutePath() + "/saves";
- OverwriteMode overwriteMode = OVERWRITE_ASK;
- for (std::vector<SaveGame*>::const_iterator iter = m_GlobalSaves.begin();
- iter != m_GlobalSaves.end(); ++iter) {
- if ((*iter)->pcName() == selectedCharacter) {
- QStringList files = (*iter)->saveFiles();
- foreach (const QString &file, files) {
- QFileInfo fileInfo(file);
- QString destinationFile = destination + "/" + fileInfo.fileName();
- if (QFile::exists(destinationFile)) {
- if (testOverwrite(overwriteMode, destinationFile)) {
- QFile::remove(destinationFile);
- } else {
- continue;
- }
- }
- if (!QFile::copy(fileInfo.absoluteFilePath(), destinationFile)) {
- qCritical("failed to copy %s to %s",
- fileInfo.absoluteFilePath().toUtf8().constData(),
- destinationFile.toUtf8().constData());
- }
- }
- }
- }
+ QString character = ui->globalCharacterList->currentItem()->text();
+ if (transferCharacters(character,
+ COPY_SAVES TO_PROFILE,
+ m_GlobalSaves[character],
+ m_Profile.savePath(),
+ QFile::copy,
+ "Failed to copy %s to %s")) {
+ refreshLocalSaves();
+ refreshLocalCharacters();
}
- refreshLocalSaves();
- refreshLocalCharacters();
}
void TransferSavesDialog::on_moveToGlobalBtn_clicked()
{
- QString selectedCharacter = ui->localCharacterList->currentItem()->text();
- if (QMessageBox::question(this, tr("Confirm"),
- tr("Move all save games of character \"%1\" to the global location? Please be aware "
- "that this will mess up the running number of save games.").arg(selectedCharacter),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
-
- QDir destination = m_GamePlugin->savesDirectory();
- OverwriteMode overwriteMode = OVERWRITE_ASK;
- for (std::vector<SaveGame*>::const_iterator iter = m_LocalSaves.begin();
- iter != m_LocalSaves.end(); ++iter) {
- if ((*iter)->pcName() == selectedCharacter) {
- QStringList files = (*iter)->saveFiles();
- foreach (const QString &file, files) {
- QFileInfo fileInfo(file);
- QString destinationFile = destination.filePath(fileInfo.fileName());
- if (QFile::exists(destinationFile)) {
- if (testOverwrite(overwriteMode, destinationFile)) {
- QFile::remove(destinationFile);
- } else {
- continue;
- }
- }
- if (!QFile::rename(fileInfo.absoluteFilePath(), destinationFile)) {
- qCritical("failed to move %s to %s",
- fileInfo.absoluteFilePath().toUtf8().constData(),
- destinationFile.toUtf8().constData());
- }
- }
- }
- }
+ QString character = ui->localCharacterList->currentItem()->text();
+ if (transferCharacters(character,
+ MOVE_SAVES TO_GLOBAL,
+ m_LocalSaves[character],
+ m_GamePlugin->savesDirectory().absolutePath(),
+ QFile::rename,
+ "Failed to move %s to %s")) {
+ refreshGlobalSaves();
+ refreshGlobalCharacters();
+ refreshLocalSaves();
+ refreshLocalCharacters();
}
- refreshGlobalSaves();
- refreshGlobalCharacters();
- refreshLocalSaves();
- refreshLocalCharacters();
}
void TransferSavesDialog::on_copyToGlobalBtn_clicked()
{
- QString selectedCharacter = ui->localCharacterList->currentItem()->text();
- if (QMessageBox::question(this, tr("Confirm"),
- tr("Copy all save games of character \"%1\" to the global location? Please be aware "
- "that this will mess up the running number of save games.").arg(selectedCharacter),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
-
- QDir destination = m_GamePlugin->savesDirectory();
- OverwriteMode overwriteMode = OVERWRITE_ASK;
- for (std::vector<SaveGame*>::const_iterator iter = m_LocalSaves.begin();
- iter != m_LocalSaves.end(); ++iter) {
- if ((*iter)->pcName() == selectedCharacter) {
- QStringList files = (*iter)->saveFiles();
- foreach (const QString &file, files) {
- QFileInfo fileInfo(file);
- QString destinationFile = destination.filePath(fileInfo.fileName());
- if (QFile::exists(destinationFile)) {
- if (testOverwrite(overwriteMode, destinationFile)) {
- QFile::remove(destinationFile);
- } else {
- continue;
- }
- }
- if (!QFile::copy(fileInfo.absoluteFilePath(), destinationFile)) {
- qCritical("failed to copy %s to %s",
- fileInfo.absoluteFilePath().toUtf8().constData(),
- destinationFile.toUtf8().constData());
- }
- }
- }
- }
+ QString character = ui->localCharacterList->currentItem()->text();
+ if (transferCharacters(character,
+ COPY_SAVES TO_GLOBAL,
+ m_LocalSaves[character],
+ m_GamePlugin->savesDirectory().absolutePath(),
+ QFile::copy,
+ "Failed to copy %s to %s")) {
+ refreshGlobalSaves();
+ refreshGlobalCharacters();
}
- refreshGlobalSaves();
- refreshGlobalCharacters();
}
void TransferSavesDialog::on_doneButton_clicked()
@@ -309,10 +222,12 @@ void TransferSavesDialog::on_doneButton_clicked()
void TransferSavesDialog::on_globalCharacterList_currentTextChanged(const QString &currentText)
{
ui->globalSavesList->clear();
- for (std::vector<SaveGame*>::const_iterator iter = m_GlobalSaves.begin();
- iter != m_GlobalSaves.end(); ++iter) {
- if ((*iter)->pcName() == currentText) {
- ui->globalSavesList->addItem(QFileInfo((*iter)->fileName()).fileName());
+ //sadly this can get called while we're resetting the list, with an invalid
+ //name, so we have to check.
+ SaveCollection::const_iterator saveList = m_GlobalSaves.find(currentText);
+ if (saveList != m_GlobalSaves.end()) {
+ for (SaveListItem const &save : saveList->second) {
+ ui->globalSavesList->addItem(QFileInfo(save->getFilename()).fileName());
}
}
}
@@ -320,10 +235,98 @@ void TransferSavesDialog::on_globalCharacterList_currentTextChanged(const QStrin
void TransferSavesDialog::on_localCharacterList_currentTextChanged(const QString &currentText)
{
ui->localSavesList->clear();
- for (std::vector<SaveGame*>::const_iterator iter = m_LocalSaves.begin();
- iter != m_LocalSaves.end(); ++iter) {
- if ((*iter)->pcName() == currentText) {
- ui->localSavesList->addItem(QFileInfo((*iter)->fileName()).fileName());
+ //sadly this can get called while we're resetting the list, with an invalid
+ //name, so we have to check.
+ SaveCollection::const_iterator saveList = m_LocalSaves.find(currentText);
+ if (saveList != m_LocalSaves.end()) {
+ for (SaveListItem const &save : saveList->second) {
+ ui->localSavesList->addItem(QFileInfo(save->getFilename()).fileName());
+ }
+ }
+}
+
+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) {
+ static DummyInfo dummyInfo;
+ 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);
+ saveCollection[save->getIdentifier()].push_back(
+ std::unique_ptr<MOBase::ISaveGame const>(save));
+ }
+}
+
+void TransferSavesDialog::refreshCharacters(const SaveCollection &saveCollection,
+ QListWidget *charList, QPushButton *copy, QPushButton *move)
+{
+ charList->clear();
+ for (SaveCollection::value_type const &val : saveCollection) {
+ charList->addItem(val.first);
+ }
+ if (charList->count() > 0) {
+ charList->setCurrentRow(0);
+ copy->setEnabled(true);
+ move->setEnabled(true);
+ } else {
+ copy->setEnabled(false);
+ move->setEnabled(false);
+ }
+}
+
+bool TransferSavesDialog::transferCharacters(QString const &character,
+ char const *message,
+ SaveList &saves,
+ QString const &dest,
+ bool (method)(QString const &, QString const &),
+ char const *errmsg)
+{
+ if (QMessageBox::question(this, tr("Confirm"),
+ tr(message).arg(character),
+ QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) {
+ return false;
+ }
+
+ OverwriteMode overwriteMode = OVERWRITE_ASK;
+
+ QStringList extensions = { m_GamePlugin->savegameExtension() };
+ {
+ ScriptExtender *ext = m_GamePlugin->feature<ScriptExtender>();
+ if (ext != nullptr) {
+ extensions += ext->saveGameAttachmentExtensions();
+ }
+ }
+ QDir destination(dest);
+ for (SaveListItem const &save : saves) {
+ QFileInfo const saveFile = save->getFilename();
+ for (QString const &ext : extensions) {
+ QFileInfo sourceFile(saveFile.absoluteDir().absoluteFilePath(saveFile.completeBaseName() + "." + ext));
+ QString destinationFile = destination.absoluteFilePath(sourceFile.fileName());
+
+ //If the file is already there, let them skip (or not).
+ if (QFile::exists(destinationFile)) {
+ if (! testOverwrite(overwriteMode, destinationFile)) {
+ continue;
+ }
+ //OK, they want to remove it.
+ QFile::remove(destinationFile);
+ }
+
+ if (! method(sourceFile.absoluteFilePath(), destinationFile)) {
+ qCritical(errmsg,
+ sourceFile.absoluteFilePath().toUtf8().constData(),
+ destinationFile.toUtf8().constData());
+ }
}
}
+ return true;
}
diff --git a/src/transfersavesdialog.h b/src/transfersavesdialog.h
index e2c556b4..d3f079e3 100644
--- a/src/transfersavesdialog.h
+++ b/src/transfersavesdialog.h
@@ -23,10 +23,19 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "tutorabledialog.h"
#include "profile.h"
+class QListWidget;
+#include <QObject>
+class QPushButton;
+#include <QString>
+class QWidget;
+
+#include <memory>
+#include <map>
+#include <vector>
+
namespace Ui { class TransferSavesDialog; }
namespace MOBase { class IPluginGame; }
-
-class SaveGame;
+namespace MOBase { class ISaveGame; }
class TransferSavesDialog : public MOBase::TutorableDialog
{
@@ -76,8 +85,25 @@ private:
MOBase::IPluginGame const *m_GamePlugin;
- std::vector<SaveGame*> m_GlobalSaves;
- std::vector<SaveGame*> m_LocalSaves;
+ typedef std::unique_ptr<MOBase::ISaveGame const> SaveListItem;
+ typedef std::vector<SaveListItem> SaveList;
+ typedef std::map<QString, SaveList> SaveCollection;
+ SaveCollection m_GlobalSaves;
+ SaveCollection m_LocalSaves;
+
+ void refreshSaves(SaveCollection &saveCollection, const QString &savedir);
+ void refreshCharacters(SaveCollection const &saveCollection,
+ QListWidget *charList,
+ QPushButton *copy,
+ QPushButton *move);
+
+ bool transferCharacters(QString const &character,
+ char const *message,
+ SaveList &saves,
+ QString const &dest,
+ bool (method)(QString const &, QString const &),
+ char const *errmsg
+ );
};