From 70fe708474ff236bdb1ace78fdbdebec6fdd5e5a Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Mon, 1 Jun 2020 14:55:19 +0200 Subject: Remove usage of QString in FileData following archive change. --- src/archivefiletree.cpp | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'src/archivefiletree.cpp') diff --git a/src/archivefiletree.cpp b/src/archivefiletree.cpp index 37d80537..1f410b34 100644 --- a/src/archivefiletree.cpp +++ b/src/archivefiletree.cpp @@ -86,7 +86,7 @@ public: // Overrides: /** * */ - static void mapToArchive(IFileTree const& tree, QString path, FileData* const* data) + static void mapToArchive(IFileTree const& tree, QString path, std::vector const& data) { if (path.length() > 0) { // when using a long windows path (starting with \\?\) we apparently can have redundant @@ -104,14 +104,14 @@ public: // Overrides: const ArchiveFileTreeImpl& archiveEntry = dynamic_cast(*entry); QString tmp = path + archiveEntry.name(); if (archiveEntry.m_Index != -1) { - data[archiveEntry.m_Index]->addOutputFileName(tmp); + data[archiveEntry.m_Index]->addOutputFileName(tmp.toStdWString()); } mapToArchive(*archiveEntry.astree(), tmp, data); } else { const ArchiveFileEntry& archiveFileEntry = dynamic_cast(*entry); if (archiveFileEntry.m_Index != -1) { - data[archiveFileEntry.m_Index]->addOutputFileName(path + archiveFileEntry.name()); + data[archiveFileEntry.m_Index]->addOutputFileName((path + archiveFileEntry.name()).toStdWString()); } } } @@ -121,10 +121,7 @@ public: // Overrides: * */ void mapToArchive(Archive* archive) const override { - FileData* const* data; - size_t size; - archive->getFileList(data, size); - mapToArchive(*this, "", data); + mapToArchive(*this, "", archive->getFileList()); } protected: @@ -217,17 +214,18 @@ private: mutable std::vector m_Files; }; -std::shared_ptr ArchiveFileTree::makeTree(Archive* archive) { - - FileData* const* data; - size_t size; - archive->getFileList(data, size); +std::shared_ptr ArchiveFileTree::makeTree(Archive* archive) +{ + auto const& data = archive->getFileList(); std::vector files; - files.reserve(size); + files.reserve(data.size()); - for (size_t i = 0; i < size; ++i) { - files.push_back(std::make_tuple(data[i]->getFileName().replace("\\", "/").split("/", Qt::SkipEmptyParts), data[i]->isDirectory(), (int) i)); + for (size_t i = 0; i < data.size(); ++i) { + files.push_back(std::make_tuple( + QString::fromStdWString(data[i]->getFileName()).replace("\\", "/").split("/", Qt::SkipEmptyParts), + data[i]->isDirectory(), + (int) i)); } auto tree = std::make_shared(nullptr, "", -1, std::move(files)); @@ -241,13 +239,13 @@ std::shared_ptr ArchiveFileTree::makeTree(Archive* archive) { * */ template -void mapToArchive(FileData* const* data, It begin, It end) { +void mapToArchive(std::vector const& data, It begin, It end) { for (auto it = begin; it != end; ++it) { auto entry = *it; auto* aentry = dynamic_cast(entry.get()); if (aentry->m_Index != -1) { - data[aentry->m_Index]->addOutputFileName(aentry->path()); + data[aentry->m_Index]->addOutputFileName(aentry->path().toStdWString()); } if (entry->isDir()) { @@ -258,9 +256,5 @@ void mapToArchive(FileData* const* data, It begin, It end) { } void ArchiveFileTree::mapToArchive(Archive* archive, std::vector> const& entries) { - FileData* const* data; - size_t size; - archive->getFileList(data, size); - - ::mapToArchive(data, entries.cbegin(), entries.cend()); + ::mapToArchive(archive->getFileList(), entries.cbegin(), entries.cend()); } -- cgit v1.3.1 From b8a1365dacd7ffa8705bbb3dcaf2e2dc6613e6fb Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Tue, 2 Jun 2020 12:40:46 +0200 Subject: Update after change to CreateArchive. Remove unused archive handler from self-updater. --- src/archivefiletree.cpp | 12 ++++++------ src/archivefiletree.h | 6 +++--- src/installationmanager.cpp | 11 +++-------- src/installationmanager.h | 5 ++--- src/selfupdater.cpp | 27 --------------------------- src/selfupdater.h | 2 -- 6 files changed, 14 insertions(+), 49 deletions(-) (limited to 'src/archivefiletree.cpp') 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 m_Files; }; -std::shared_ptr ArchiveFileTree::makeTree(Archive* archive) +std::shared_ptr ArchiveFileTree::makeTree(Archive const& archive) { - auto const& data = archive->getFileList(); + auto const& data = archive.getFileList(); std::vector files; files.reserve(data.size()); @@ -255,6 +255,6 @@ void mapToArchive(std::vector const& data, It begin, It end) { } } -void ArchiveFileTree::mapToArchive(Archive* archive, std::vector> const& entries) { - ::mapToArchive(archive->getFileList(), entries.cbegin(), entries.cend()); +void ArchiveFileTree::mapToArchive(Archive &archive, std::vector> 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 makeTree(Archive* archive); + static std::shared_ptr 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> const& entries); + static void mapToArchive(Archive &archive, std::vector> 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 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::vectorisFile(); }); // 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 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 m_Installers; std::set m_SupportedExtensions; - Archive *m_ArchiveHandler; + // Archive management: + std::unique_ptr 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 . using namespace MOBase; using namespace MOShared; - -typedef Archive* (*CreateArchiveType)(); - - -template static T resolveFunction(QLibrary &lib, const char *name) -{ - T temp = reinterpret_cast(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(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; -- cgit v1.3.1 From 8fa905cde626067f7cb4dcec473049228b831d9d Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Fri, 5 Jun 2020 17:50:26 +0200 Subject: Update to follow changes in FileData from archive. --- src/archivefiletree.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/archivefiletree.cpp') diff --git a/src/archivefiletree.cpp b/src/archivefiletree.cpp index 4bedeb41..1fbf3195 100644 --- a/src/archivefiletree.cpp +++ b/src/archivefiletree.cpp @@ -104,14 +104,14 @@ public: // Overrides: const ArchiveFileTreeImpl& archiveEntry = dynamic_cast(*entry); QString tmp = path + archiveEntry.name(); if (archiveEntry.m_Index != -1) { - data[archiveEntry.m_Index]->addOutputFileName(tmp.toStdWString()); + data[archiveEntry.m_Index]->addOutputFilePath(tmp.toStdWString()); } mapToArchive(*archiveEntry.astree(), tmp, data); } else { const ArchiveFileEntry& archiveFileEntry = dynamic_cast(*entry); if (archiveFileEntry.m_Index != -1) { - data[archiveFileEntry.m_Index]->addOutputFileName((path + archiveFileEntry.name()).toStdWString()); + data[archiveFileEntry.m_Index]->addOutputFilePath((path + archiveFileEntry.name()).toStdWString()); } } } @@ -223,7 +223,7 @@ std::shared_ptr ArchiveFileTree::makeTree(Archive const& archiv for (size_t i = 0; i < data.size(); ++i) { files.push_back(std::make_tuple( - QString::fromStdWString(data[i]->getFileName()).replace("\\", "/").split("/", Qt::SkipEmptyParts), + QString::fromStdWString(data[i]->getArchiveFilePath()).replace("\\", "/").split("/", Qt::SkipEmptyParts), data[i]->isDirectory(), (int) i)); } @@ -245,7 +245,7 @@ void mapToArchive(std::vector const& data, It begin, It end) { auto* aentry = dynamic_cast(entry.get()); if (aentry->m_Index != -1) { - data[aentry->m_Index]->addOutputFileName(aentry->path().toStdWString()); + data[aentry->m_Index]->addOutputFilePath(aentry->path().toStdWString()); } if (entry->isDir()) { -- cgit v1.3.1