From 6e802d7327495bbd64153e503b1aff44a80f0e0f Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Tue, 29 Dec 2020 01:07:36 +0100 Subject: Do not move installed mod after merge/replace. --- src/installationmanager.h | 77 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 20 deletions(-) (limited to 'src/installationmanager.h') diff --git a/src/installationmanager.h b/src/installationmanager.h index 277c276a..a5ec11d9 100644 --- a/src/installationmanager.h +++ b/src/installationmanager.h @@ -37,15 +37,48 @@ along with Mod Organizer. If not, see . #include "modinfo.h" #include "plugincontainer.h" +// contains installation result from the manager, internal class +// for MO2 that is not forwarded to plugin +class InstallationResult { +public: + + // result status of the installation + // + auto result() const { return m_result; } + + // information about the installation, only valid for successful + // installation + // + QString name() const { return m_name; } + bool backupCreated() const { return m_backup; } + bool merged() const { return m_merged; } + bool replaced() const { return m_replaced; } + bool hasIniTweaks() const { return m_iniTweaks; } + bool mergedOrReplaced() const { return merged() || replaced(); } + + // check if the installation was a success + // + explicit operator bool() const { return result() == MOBase::IPluginInstaller::EInstallResult::RESULT_SUCCESS; } + +private: + + friend class InstallationManager; + + // create a failed result + InstallationResult(MOBase::IPluginInstaller::EInstallResult result = MOBase::IPluginInstaller::EInstallResult::RESULT_FAILED); + + MOBase::IPluginInstaller::EInstallResult m_result; + + QString m_name; + + bool m_iniTweaks; + bool m_backup; + bool m_merged; + bool m_replaced; + +}; + -/** - * @brief manages the installation of mod archives - * This currently supports two special kind of archives: - * - "simple" archives: properly packaged archives without options, so they can be extracted to the (virtual) data directory directly - * - "complex" bain archives: archives with options for the bain system. - * All other archives are managed through the manual "InstallDialog" - * @todo this may be a good place to support plugins - **/ class InstallationManager : public QObject, public MOBase::IInstallationManager { Q_OBJECT @@ -79,7 +112,7 @@ public: * @param result The result of the installation process. * @param currentMod The newly install mod, if result is SUCCESS, a null pointer otherwise. */ - void notifyInstallationEnd(MOBase::IPluginInstaller::EInstallResult result, ModInfo::Ptr newMod); + void notifyInstallationEnd(const InstallationResult& result, ModInfo::Ptr newMod); /** * @brief update the directory where mods are to be installed @@ -107,7 +140,7 @@ public: * @return true if the archive was installed, false if installation failed or was refused * @exception std::exception an exception may be thrown if the archive can't be opened (maybe the format is invalid or the file is damaged) **/ - MOBase::IPluginInstaller::EInstallResult install(const QString &fileName, MOBase::GuessedValue &modName, bool &hasIniTweaks, int modID = 0); + InstallationResult install(const QString &fileName, MOBase::GuessedValue &modName, int modID = 0); /** * @return true if the installation was canceled @@ -148,7 +181,7 @@ public: * @note The temporary file is automatically cleaned up after the installation. * @note This call can be very slow if the archive is large and "solid". */ - virtual QString extractFile(std::shared_ptr entry, bool silent = false) override; + QString extractFile(std::shared_ptr entry, bool silent = false) override; /** * @brief Extract the specified files from the currently opened archive to a temporary location. @@ -171,7 +204,7 @@ public: * IFileTree and thus to given a list of entries flattened (this was not possible with the * QStringList version since these were based on the name of the file inside the archive). */ - virtual QStringList extractFiles(std::vector> const& entries, bool silent = false) override; + QStringList extractFiles(std::vector> const& entries, bool silent = false) override; /** * @brief Create a new file on the disk corresponding to the given entry. @@ -184,7 +217,7 @@ public: * * @return the path to the created file. */ - virtual QString createFile(std::shared_ptr entry) override; + QString createFile(std::shared_ptr entry) override; /** * @brief Installs the given archive. @@ -195,22 +228,26 @@ public: * * @return the installation result. */ - virtual MOBase::IPluginInstaller::EInstallResult installArchive(MOBase::GuessedValue &modName, const QString &archiveName, int modId = 0) override; + MOBase::IPluginInstaller::EInstallResult installArchive(MOBase::GuessedValue &modName, const QString &archiveName, int modId = 0) override; /** - * @brief test if the specified mod name is free. If not, query the user how to proceed * @param modName current possible names for the mod - * @param merge if this value is not null, the value will be set to whether the use chose to merge or replace - * @return true if we can proceed with the installation, false if the user canceled or in case of an unrecoverable error + * + * @return an installation result containing information from the user. */ - virtual MOBase::IPluginInstaller::EInstallResult testOverwrite(MOBase::GuessedValue &modName, bool *merge = nullptr); + InstallationResult testOverwrite(MOBase::GuessedValue& modName); QString generateBackupName(const QString &directoryName) const; private: - MOBase::IPluginInstaller::EInstallResult doInstall(MOBase::GuessedValue &modName, QString gameName, - int modID, const QString &version, const QString &newestVersion, int categoryID, int fileCategoryID, const QString &repository); + // actually perform the installation (write files to the disk, etc.), returns the + // installation result + // + InstallationResult doInstall( + MOBase::GuessedValue &modName, QString gameName, + int modID, const QString &version, const QString &newestVersion, + int categoryID, int fileCategoryID, const QString &repository); /** * @brief Clean the list of created files by removing all entries that are not -- cgit v1.3.1