diff options
| -rw-r--r-- | src/archivefiletree.cpp | 12 | ||||
| -rw-r--r-- | src/archivefiletree.h | 6 | ||||
| -rw-r--r-- | src/installationmanager.cpp | 11 | ||||
| -rw-r--r-- | src/installationmanager.h | 5 | ||||
| -rw-r--r-- | src/selfupdater.cpp | 27 | ||||
| -rw-r--r-- | src/selfupdater.h | 2 |
6 files changed, 14 insertions, 49 deletions
diff --git a/src/archivefiletree.cpp b/src/archivefiletree.cpp index 1f410b34..4bedeb41 100644 --- a/src/archivefiletree.cpp +++ b/src/archivefiletree.cpp @@ -120,8 +120,8 @@ public: // Overrides: /** * */ - void mapToArchive(Archive* archive) const override { - mapToArchive(*this, "", archive->getFileList()); + void mapToArchive(Archive &archive) const override { + mapToArchive(*this, "", archive.getFileList()); } protected: @@ -214,9 +214,9 @@ private: mutable std::vector<File> m_Files; }; -std::shared_ptr<ArchiveFileTree> ArchiveFileTree::makeTree(Archive* archive) +std::shared_ptr<ArchiveFileTree> ArchiveFileTree::makeTree(Archive const& archive) { - auto const& data = archive->getFileList(); + auto const& data = archive.getFileList(); std::vector<ArchiveFileTreeImpl::File> files; files.reserve(data.size()); @@ -255,6 +255,6 @@ void mapToArchive(std::vector<FileData*> const& data, It begin, It end) { } } -void ArchiveFileTree::mapToArchive(Archive* archive, std::vector<std::shared_ptr<const FileTreeEntry>> const& entries) { - ::mapToArchive(archive->getFileList(), entries.cbegin(), entries.cend()); +void ArchiveFileTree::mapToArchive(Archive &archive, std::vector<std::shared_ptr<const FileTreeEntry>> const& entries) { + ::mapToArchive(archive.getFileList(), entries.cbegin(), entries.cend()); } diff --git a/src/archivefiletree.h b/src/archivefiletree.h index 0041acd6..e4a5cbdd 100644 --- a/src/archivefiletree.h +++ b/src/archivefiletree.h @@ -37,7 +37,7 @@ public: * * @return a file tree representing the given archive. */ - static std::shared_ptr<ArchiveFileTree> makeTree(Archive* archive); + static std::shared_ptr<ArchiveFileTree> makeTree(Archive const& archive); /** * @brief Update the given archive to reflect change in this tree. @@ -48,7 +48,7 @@ public: * @param archive The archive to update. Must be the one used to * create the tree. */ - virtual void mapToArchive(Archive *archive) const = 0; + virtual void mapToArchive(Archive &archive) const = 0; /** * @brief Update the given archive to prepare for the extraction @@ -61,7 +61,7 @@ public: * @param entries List of entries to mark for extraction. All the entries must * come from a tree created with the given archive. */ - static void mapToArchive(Archive* archive, std::vector<std::shared_ptr<const FileTreeEntry>> const& entries); + static void mapToArchive(Archive &archive, std::vector<std::shared_ptr<const FileTreeEntry>> const& entries); protected: diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 0a97225e..dad5b436 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -64,10 +64,6 @@ using namespace MOBase; using namespace MOShared; -typedef Archive* (*CreateArchiveType)(); - - - template <typename T> static T resolveFunction(QLibrary &lib, const char *name) { @@ -116,7 +112,6 @@ InstallationManager::InstallationManager() InstallationManager::~InstallationManager() { - delete m_ArchiveHandler; } void InstallationManager::setParentWidget(QWidget *widget) @@ -238,7 +233,7 @@ QStringList InstallationManager::extractFiles(std::vector<std::shared_ptr<const [](auto const& entry) { return entry->isFile(); }); // Update the archive: - ArchiveFileTree::mapToArchive(m_ArchiveHandler, files); + ArchiveFileTree::mapToArchive(*m_ArchiveHandler, files); // Retrieve the file path: QStringList result; @@ -663,7 +658,7 @@ IPluginInstaller::EInstallResult InstallationManager::install(const QString &fil ON_BLOCK_EXIT(std::bind(&InstallationManager::postInstallCleanup, this)); std::shared_ptr<IFileTree> filesTree = - archiveOpen ? ArchiveFileTree::makeTree(m_ArchiveHandler) : nullptr; + archiveOpen ? ArchiveFileTree::makeTree(*m_ArchiveHandler) : nullptr; IPluginInstaller::EInstallResult installResult = IPluginInstaller::RESULT_NOTATTEMPTED; std::sort(m_Installers.begin(), m_Installers.end(), [] (IPluginInstaller *LHS, IPluginInstaller *RHS) { @@ -707,7 +702,7 @@ IPluginInstaller::EInstallResult InstallationManager::install(const QString &fil // stops at this root): p->detach(); - p->mapToArchive(m_ArchiveHandler); + p->mapToArchive(*m_ArchiveHandler); // Clean the created files: cleanCreatedFiles(filesTree); diff --git a/src/installationmanager.h b/src/installationmanager.h index 328272e1..1b0c6d73 100644 --- a/src/installationmanager.h +++ b/src/installationmanager.h @@ -256,10 +256,9 @@ private: std::vector<MOBase::IPluginInstaller*> m_Installers; std::set<QString, CaseInsensitive> m_SupportedExtensions; - Archive *m_ArchiveHandler; + // Archive management: + std::unique_ptr<Archive> m_ArchiveHandler; QString m_CurrentFile; - - // Current password: QString m_Password; // Map from entries in the tree that is used by the installer and absolute diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index 501c7ed1..dfe11880 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -71,45 +71,18 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. using namespace MOBase;
using namespace MOShared;
-
-typedef Archive* (*CreateArchiveType)();
-
-
-template <typename T> static T resolveFunction(QLibrary &lib, const char *name)
-{
- T temp = reinterpret_cast<T>(lib.resolve(name));
- if (temp == nullptr) {
- throw std::runtime_error(QObject::tr("invalid 7-zip32.dll: %1").arg(lib.errorString()).toLatin1().constData());
- }
- return temp;
-}
-
-
SelfUpdater::SelfUpdater(NexusInterface *nexusInterface)
: m_Parent(nullptr)
, m_Interface(nexusInterface)
, m_Reply(nullptr)
, m_Attempts(3)
{
- QLibrary archiveLib(QCoreApplication::applicationDirPath() + "\\dlls\\archive.dll");
- if (!archiveLib.load()) {
- throw MyException(tr("archive.dll not loaded: \"%1\"").arg(archiveLib.errorString()));
- }
-
- CreateArchiveType CreateArchiveFunc = resolveFunction<CreateArchiveType>(archiveLib, "CreateArchive");
-
- m_ArchiveHandler = CreateArchiveFunc();
- if (!m_ArchiveHandler->isValid()) {
- throw MyException(InstallationManager::getErrorString(m_ArchiveHandler->getLastError()));
- }
-
m_MOVersion = createVersionInfo();
}
SelfUpdater::~SelfUpdater()
{
- delete m_ArchiveHandler;
}
void SelfUpdater::setUserInterface(QWidget *widget)
diff --git a/src/selfupdater.h b/src/selfupdater.h index 0c81efc5..8ff14326 100644 --- a/src/selfupdater.h +++ b/src/selfupdater.h @@ -140,8 +140,6 @@ private: bool m_Canceled;
int m_Attempts;
- Archive *m_ArchiveHandler;
-
GitHub m_GitHub;
QJsonObject m_UpdateCandidate;
|
