From d93df95dcfcaf0170f7fb273e9955ef6070fbaa5 Mon Sep 17 00:00:00 2001 From: TheBloke Date: Fri, 11 Jul 2014 01:29:33 +0100 Subject: - Save game management: re-factored getting of filenames including .skse -- New - SaveGame->saveFiles(), returns all filenames for save (eg. ess + skse) -- Moved - SaveGameGameBryo->attachedFiles() to SaveGame->attachedFiles() -- This allows the getting of save file names with just a SaveGame object, not a GameBryo object, which would do a full file read including plugins and image etc. -- Therefore SaveGame is no longer abstract. - Transfer Saves: re-factored to use new SaveGame->saveFiles() method -- Removed - TransferSavesDialog->getFilesToProcess, now redundant as information is now provided by SaveGame class itself. --- src/savegame.cpp | 148 +++++++++++++++++------------- src/savegame.h | 219 ++++++++++++++++++++++---------------------- src/savegamegamebryo.cpp | 11 +-- src/savegamegamebyro.h | 171 +++++++++++++++++----------------- src/transfersavesdialog.cpp | 15 +-- src/transfersavesdialog.h | 1 - 6 files changed, 283 insertions(+), 282 deletions(-) (limited to 'src') diff --git a/src/savegame.cpp b/src/savegame.cpp index 0ddd5fd2..d09f291c 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -17,68 +17,86 @@ You should have received a copy of the GNU General Public License along with Mod Organizer. If not, see . */ -#include "savegame.h" -#include -#include -#include -#include "gameinfo.h" -#include -#include -#include - - -SaveGame::SaveGame(QObject *parent) - : QObject(parent), m_FileName(), m_PCName(), m_PCLevel(0), m_PCLocation(), m_SaveNumber(0), m_Screenshot() -{ -} - - -SaveGame::SaveGame(QObject *parent, const QString &filename) - : QObject(parent), m_FileName(filename), m_PCName(), m_PCLevel(0), m_PCLocation(), m_SaveNumber(0), m_Screenshot() -{ -} - - -SaveGame::SaveGame(const SaveGame& reference) - : m_FileName(reference.m_FileName), m_PCName(reference.m_PCName), m_PCLevel(reference.m_PCLevel), - m_PCLocation(reference.m_PCLocation), m_SaveNumber(reference.m_SaveNumber), - m_Screenshot(reference.m_Screenshot) -{ -} - - -SaveGame& SaveGame::operator=(const SaveGame &reference) -{ - if (&reference != this) { - m_FileName = reference.m_FileName; - m_PCName = reference.m_PCName; - m_PCLevel = reference.m_PCLevel; - m_PCLocation = reference.m_PCLocation; - m_SaveNumber = reference.m_SaveNumber; - m_Screenshot = reference.m_Screenshot; - } - return *this; -} - - -SaveGame::~SaveGame() -{ -} - - -void SaveGame::setCreationTime(const QString &fileName) -{ - QFileInfo creationTime(fileName); - QDateTime modified = creationTime.lastModified(); - memset(&m_CreationTime, 0, sizeof(SYSTEMTIME)); - - m_CreationTime.wDay = static_cast(modified.date().day()); - m_CreationTime.wDayOfWeek = static_cast(modified.date().dayOfWeek()); - m_CreationTime.wMonth = static_cast(modified.date().month()); - m_CreationTime.wYear =static_cast( modified.date().year()); - - m_CreationTime.wHour = static_cast(modified.time().hour()); - m_CreationTime.wMinute = static_cast(modified.time().minute()); - m_CreationTime.wSecond = static_cast(modified.time().second()); - m_CreationTime.wMilliseconds = static_cast(modified.time().msec()); -} +#include "savegame.h" +#include +#include +#include +#include "gameinfo.h" +#include +#include +#include + + +SaveGame::SaveGame(QObject *parent) + : QObject(parent), m_FileName(), m_PCName(), m_PCLevel(0), m_PCLocation(), m_SaveNumber(0), m_Screenshot() +{ +} + + +SaveGame::SaveGame(QObject *parent, const QString &filename) + : QObject(parent), m_FileName(filename), m_PCName(), m_PCLevel(0), m_PCLocation(), m_SaveNumber(0), m_Screenshot() +{ +} + + +SaveGame::SaveGame(const SaveGame& reference) + : m_FileName(reference.m_FileName), m_PCName(reference.m_PCName), m_PCLevel(reference.m_PCLevel), + m_PCLocation(reference.m_PCLocation), m_SaveNumber(reference.m_SaveNumber), + m_Screenshot(reference.m_Screenshot) +{ +} + + +SaveGame& SaveGame::operator=(const SaveGame &reference) +{ + if (&reference != this) { + m_FileName = reference.m_FileName; + m_PCName = reference.m_PCName; + m_PCLevel = reference.m_PCLevel; + m_PCLocation = reference.m_PCLocation; + m_SaveNumber = reference.m_SaveNumber; + m_Screenshot = reference.m_Screenshot; + } + return *this; +} + + +SaveGame::~SaveGame() +{ +} + +QStringList SaveGame::attachedFiles() const +{ + QStringList result; + QString seFileFile = fileName().mid(0).replace(".ess", ".skse"); + QFileInfo seFile(seFileFile); + if (seFile.exists()) { + result.append(seFile.absoluteFilePath()); + } + return result; +} + +QStringList SaveGame::saveFiles() const +{ + QStringList result = attachedFiles(); + result.append(fileName()); + return result; +} + + +void SaveGame::setCreationTime(const QString &fileName) +{ + QFileInfo creationTime(fileName); + QDateTime modified = creationTime.lastModified(); + memset(&m_CreationTime, 0, sizeof(SYSTEMTIME)); + + m_CreationTime.wDay = static_cast(modified.date().day()); + m_CreationTime.wDayOfWeek = static_cast(modified.date().dayOfWeek()); + m_CreationTime.wMonth = static_cast(modified.date().month()); + m_CreationTime.wYear =static_cast( modified.date().year()); + + m_CreationTime.wHour = static_cast(modified.time().hour()); + m_CreationTime.wMinute = static_cast(modified.time().minute()); + m_CreationTime.wSecond = static_cast(modified.time().second()); + m_CreationTime.wMilliseconds = static_cast(modified.time().msec()); +} diff --git a/src/savegame.h b/src/savegame.h index e3eb8546..9a5f7036 100644 --- a/src/savegame.h +++ b/src/savegame.h @@ -17,110 +17,115 @@ You should have received a copy of the GNU General Public License along with Mod Organizer. If not, see . */ -#ifndef SAVEGAME_H -#define SAVEGAME_H - - -#include -#include -#include -#include -#include -#include - -#define WIN32_LEAN_AND_MEAN -#include - - -/** - * @brief represents a single save game - **/ -class SaveGame : public QObject { - -Q_OBJECT - -public: - - /** - * @brief construct an empty object - **/ - SaveGame(QObject *parent = 0); - - /** - * @brief construct a save game and immediately read out information from the file - * - * @param filename absolute path of the save game file - **/ - SaveGame(QObject *parent, const QString &filename); - - SaveGame(const SaveGame& reference); - - SaveGame& operator=(const SaveGame &reference); - - ~SaveGame(); - - /** - * @brief read out information from a savegame - * - * @param fileName absolute path of the save game file - **/ - virtual void readFile(const QString &fileName) = 0; - - /** - * @return filename of this savegame - */ - const QString &fileName() const { return m_FileName; } - - /** - * @return a list of additional files that belong to this savegame - */ - virtual QStringList attachedFiles() const { return QStringList(); } - - /** - * @return name of the player character - **/ - const QString &pcName() const { return m_PCName; } - - /** - * @return level of the player character - **/ - unsigned short pcLevel() const { return m_PCLevel; } - - /** - * @return location of the player character - **/ - const QString &pcLocation() const { return m_PCLocation; } - - /** - * @return index of the save game - **/ - unsigned long saveNumber() const { return m_SaveNumber; } - - /** - * @return creation time of the save game - **/ - SYSTEMTIME creationTime() const { return m_CreationTime; } - - /** - * @return screenshot in the savegame - **/ - const QImage &screenshot() const { return m_Screenshot; } - -private: - - void setCreationTime(const QString &fileName); - -protected: - - QString m_FileName; - QString m_PCName; - unsigned short m_PCLevel; - QString m_PCLocation; - unsigned long m_SaveNumber; - SYSTEMTIME m_CreationTime; - QImage m_Screenshot; - -}; - - -#endif // SAVEGAME_H +#ifndef SAVEGAME_H +#define SAVEGAME_H + + +#include +#include +#include +#include +#include +#include + +#define WIN32_LEAN_AND_MEAN +#include + + +/** + * @brief represents a single save game + **/ +class SaveGame : public QObject { + +Q_OBJECT + +public: + + /** + * @brief construct an empty object + **/ + SaveGame(QObject *parent = 0); + + /** + * @brief construct a save game and immediately read out information from the file + * + * @param filename absolute path of the save game file + **/ + SaveGame(QObject *parent, const QString &filename); + + SaveGame(const SaveGame& reference); + + SaveGame& operator=(const SaveGame &reference); + + ~SaveGame(); + + /** + * @brief read out information from a savegame + * + * @param fileName absolute path of the save game file + **/ + virtual void readFile(const QString) { } + + /** + * @return filename of this savegame + */ + const QString &fileName() const { return m_FileName; } + + /** + * @return a list of additional files that belong to this savegame + */ + virtual QStringList attachedFiles() const; + + /** + * @return a list of all files that belong to this savegame + */ + virtual QStringList saveFiles() const; + + /** + * @return name of the player character + **/ + const QString &pcName() const { return m_PCName; } + + /** + * @return level of the player character + **/ + unsigned short pcLevel() const { return m_PCLevel; } + + /** + * @return location of the player character + **/ + const QString &pcLocation() const { return m_PCLocation; } + + /** + * @return index of the save game + **/ + unsigned long saveNumber() const { return m_SaveNumber; } + + /** + * @return creation time of the save game + **/ + SYSTEMTIME creationTime() const { return m_CreationTime; } + + /** + * @return screenshot in the savegame + **/ + const QImage &screenshot() const { return m_Screenshot; } + +private: + + void setCreationTime(const QString &fileName); + +protected: + + QString m_FileName; + QString m_PCName; + unsigned short m_PCLevel; + QString m_PCLocation; + unsigned long m_SaveNumber; + SYSTEMTIME m_CreationTime; + QImage m_Screenshot; + +}; + + +#endif // SAVEGAME_H diff --git a/src/savegamegamebryo.cpp b/src/savegamegamebryo.cpp index f3794347..bf113254 100644 --- a/src/savegamegamebryo.cpp +++ b/src/savegamegamebryo.cpp @@ -117,16 +117,7 @@ SaveGameGamebryo::~SaveGameGamebryo() } -QStringList SaveGameGamebryo::attachedFiles() const -{ - QStringList result; - QString seFileFile = fileName().mid(0).replace(".ess", ".skse"); - QFileInfo seFile(seFileFile); - if (seFile.exists()) { - result.append(seFile.absoluteFilePath()); - } - return result; -} + void SaveGameGamebryo::readSkyrimFile(QFile &saveFile) diff --git a/src/savegamegamebyro.h b/src/savegamegamebyro.h index 25822b0c..70400636 100644 --- a/src/savegamegamebyro.h +++ b/src/savegamegamebyro.h @@ -17,91 +17,86 @@ You should have received a copy of the GNU General Public License along with Mod Organizer. If not, see . */ -#ifndef SAVEGAMEGAMEBRYO_H -#define SAVEGAMEGAMEBRYO_H - - -#include "savegame.h" -#include -#include -#include -#include -#include -#include - -#define WIN32_LEAN_AND_MEAN -#include - - -/** - * @brief represents a single save game - **/ -class SaveGameGamebryo : public SaveGame { - -Q_OBJECT - -public: - - /** - * @brief construct an empty object - **/ - SaveGameGamebryo(QObject *parent = 0); - - /** - * @brief construct a save game and immediately read out information from the file - * - * @param filename absolute path of the save game file - **/ - SaveGameGamebryo(QObject *parent, const QString &filename); - - - SaveGameGamebryo(const SaveGameGamebryo &reference); - - SaveGameGamebryo &operator=(const SaveGameGamebryo &reference); - - ~SaveGameGamebryo(); - - /** - * @return a list of additional files that belong to this savegame - */ - virtual QStringList attachedFiles() const; - - /** - * @brief read out information from a savegame - * - * @param fileName absolute path of the save game file - **/ - virtual void readFile(const QString &fileName); - - /** - * @return number of plugins that were enabled when the save game was created - **/ - int numPlugins() const { return m_Plugins.size(); } - - /** - * retrieve the name of one of the plugins that were enabled when the save game - * was created. valid indices are in the range between [0, numPlugins()[ - * @param index plugin index - * @return name of the plugin - **/ - const QString &plugin(int index) const { return m_Plugins.at(index); } - - -private: - - void readESSFile(QFile &saveFile); - void readFOSFile(QFile &saveFile, bool newVegas); - void readSkyrimFile(QFile &saveFile); - - void setCreationTime(const QString &fileName); - -private: - - std::vector m_Plugins; - -}; - -Q_DECLARE_METATYPE(SaveGameGamebryo) -Q_DECLARE_METATYPE(SaveGameGamebryo*) - -#endif // SAVEGAMEGAMEBRYO_H +#ifndef SAVEGAMEGAMEBRYO_H +#define SAVEGAMEGAMEBRYO_H + + +#include "savegame.h" +#include +#include +#include +#include +#include +#include + +#define WIN32_LEAN_AND_MEAN +#include + + +/** + * @brief represents a single save game + **/ +class SaveGameGamebryo : public SaveGame { + +Q_OBJECT + +public: + + /** + * @brief construct an empty object + **/ + SaveGameGamebryo(QObject *parent = 0); + + /** + * @brief construct a save game and immediately read out information from the file + * + * @param filename absolute path of the save game file + **/ + SaveGameGamebryo(QObject *parent, const QString &filename); + + + SaveGameGamebryo(const SaveGameGamebryo &reference); + + SaveGameGamebryo &operator=(const SaveGameGamebryo &reference); + + ~SaveGameGamebryo(); + + /** + * @brief read out information from a savegame + * + * @param fileName absolute path of the save game file + **/ + virtual void readFile(const QString &fileName); + + /** + * @return number of plugins that were enabled when the save game was created + **/ + int numPlugins() const { return m_Plugins.size(); } + + /** + * retrieve the name of one of the plugins that were enabled when the save game + * was created. valid indices are in the range between [0, numPlugins()[ + * @param index plugin index + * @return name of the plugin + **/ + const QString &plugin(int index) const { return m_Plugins.at(index); } + + +private: + + void readESSFile(QFile &saveFile); + void readFOSFile(QFile &saveFile, bool newVegas); + void readSkyrimFile(QFile &saveFile); + + void setCreationTime(const QString &fileName); + +private: + + std::vector m_Plugins; + +}; + +Q_DECLARE_METATYPE(SaveGameGamebryo) +Q_DECLARE_METATYPE(SaveGameGamebryo*) + +#endif // SAVEGAMEGAMEBRYO_H diff --git a/src/transfersavesdialog.cpp b/src/transfersavesdialog.cpp index e69e4ab2..8e2b9b59 100644 --- a/src/transfersavesdialog.cpp +++ b/src/transfersavesdialog.cpp @@ -151,13 +151,6 @@ bool TransferSavesDialog::testOverwrite(OverwriteMode &overwriteMode, const QStr return res == QMessageBox::Yes; } -QStringList TransferSavesDialog::getFilesToProcess(const SaveGame *save) -{ - QStringList result = save->attachedFiles(); - result.append(save->fileName()); - return result; -} - void TransferSavesDialog::on_moveToLocalBtn_clicked() { QString selectedCharacter = ui->globalCharacterList->currentItem()->text(); @@ -170,7 +163,7 @@ void TransferSavesDialog::on_moveToLocalBtn_clicked() for (std::vector::const_iterator iter = m_GlobalSaves.begin(); iter != m_GlobalSaves.end(); ++iter) { if ((*iter)->pcName() == selectedCharacter) { - QStringList files = getFilesToProcess(*iter); + QStringList files = (*iter)->saveFiles(); foreach (const QString &file, files) { QFileInfo fileInfo(file); QString destinationFile = destination.mid(0).append("/").append(fileInfo.fileName()); @@ -207,7 +200,7 @@ void TransferSavesDialog::on_copyToLocalBtn_clicked() for (std::vector::const_iterator iter = m_GlobalSaves.begin(); iter != m_GlobalSaves.end(); ++iter) { if ((*iter)->pcName() == selectedCharacter) { - QStringList files = getFilesToProcess(*iter); + QStringList files = (*iter)->saveFiles(); foreach (const QString &file, files) { QFileInfo fileInfo(file); QString destinationFile = destination.mid(0).append("/").append(fileInfo.fileName()); @@ -244,7 +237,7 @@ void TransferSavesDialog::on_moveToGlobalBtn_clicked() for (std::vector::const_iterator iter = m_LocalSaves.begin(); iter != m_LocalSaves.end(); ++iter) { if ((*iter)->pcName() == selectedCharacter) { - QStringList files = getFilesToProcess(*iter); + QStringList files = (*iter)->saveFiles(); foreach (const QString &file, files) { QFileInfo fileInfo(file); QString destinationFile = destination.mid(0).append("/").append(fileInfo.fileName()); @@ -283,7 +276,7 @@ void TransferSavesDialog::on_copyToGlobalBtn_clicked() for (std::vector::const_iterator iter = m_LocalSaves.begin(); iter != m_LocalSaves.end(); ++iter) { if ((*iter)->pcName() == selectedCharacter) { - QStringList files = getFilesToProcess(*iter); + QStringList files = (*iter)->saveFiles(); foreach (const QString &file, files) { QFileInfo fileInfo(file); QString destinationFile = destination.mid(0).append("/").append(fileInfo.fileName()); diff --git a/src/transfersavesdialog.h b/src/transfersavesdialog.h index 923259f6..4306b960 100644 --- a/src/transfersavesdialog.h +++ b/src/transfersavesdialog.h @@ -67,7 +67,6 @@ private: void refreshGlobalSaves(); void refreshLocalSaves(); bool testOverwrite(OverwriteMode &overwriteMode, const QString &destinationFile); - QStringList getFilesToProcess(const SaveGame *save); private: -- cgit v1.3.1