diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/archivefiletree.cpp | 42 | ||||
| -rw-r--r-- | src/archivefiletree.h | 6 | ||||
| -rw-r--r-- | src/installationmanager.cpp | 284 | ||||
| -rw-r--r-- | src/installationmanager.h | 43 | ||||
| -rw-r--r-- | src/selfupdater.cpp | 30 | ||||
| -rw-r--r-- | src/selfupdater.h | 2 |
6 files changed, 184 insertions, 223 deletions
diff --git a/src/archivefiletree.cpp b/src/archivefiletree.cpp index 37d80537..1fbf3195 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<FileData*> 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<const ArchiveFileTreeImpl&>(*entry); QString tmp = path + archiveEntry.name(); if (archiveEntry.m_Index != -1) { - data[archiveEntry.m_Index]->addOutputFileName(tmp); + data[archiveEntry.m_Index]->addOutputFilePath(tmp.toStdWString()); } mapToArchive(*archiveEntry.astree(), tmp, data); } else { const ArchiveFileEntry& archiveFileEntry = dynamic_cast<const ArchiveFileEntry&>(*entry); if (archiveFileEntry.m_Index != -1) { - data[archiveFileEntry.m_Index]->addOutputFileName(path + archiveFileEntry.name()); + data[archiveFileEntry.m_Index]->addOutputFilePath((path + archiveFileEntry.name()).toStdWString()); } } } @@ -120,11 +120,8 @@ public: // Overrides: /** * */ - void mapToArchive(Archive* archive) const override { - FileData* const* data; - size_t size; - archive->getFileList(data, size); - mapToArchive(*this, "", data); + void mapToArchive(Archive &archive) const override { + mapToArchive(*this, "", archive.getFileList()); } protected: @@ -217,17 +214,18 @@ private: mutable std::vector<File> m_Files; }; -std::shared_ptr<ArchiveFileTree> ArchiveFileTree::makeTree(Archive* archive) { - - FileData* const* data; - size_t size; - archive->getFileList(data, size); +std::shared_ptr<ArchiveFileTree> ArchiveFileTree::makeTree(Archive const& archive) +{ + auto const& data = archive.getFileList(); std::vector<ArchiveFileTreeImpl::File> 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]->getArchiveFilePath()).replace("\\", "/").split("/", Qt::SkipEmptyParts), + data[i]->isDirectory(), + (int) i)); } auto tree = std::make_shared<ArchiveFileTreeImpl>(nullptr, "", -1, std::move(files)); @@ -241,13 +239,13 @@ std::shared_ptr<ArchiveFileTree> ArchiveFileTree::makeTree(Archive* archive) { * */ template <class It> -void mapToArchive(FileData* const* data, It begin, It end) { +void mapToArchive(std::vector<FileData*> const& data, It begin, It end) { for (auto it = begin; it != end; ++it) { auto entry = *it; auto* aentry = dynamic_cast<const ArchiveFileEntry*>(entry.get()); if (aentry->m_Index != -1) { - data[aentry->m_Index]->addOutputFileName(aentry->path()); + data[aentry->m_Index]->addOutputFilePath(aentry->path().toStdWString()); } if (entry->isDir()) { @@ -257,10 +255,6 @@ void mapToArchive(FileData* const* data, It begin, It end) { } } -void ArchiveFileTree::mapToArchive(Archive* archive, std::vector<std::shared_ptr<const FileTreeEntry>> const& entries) { - FileData* const* data; - size_t size; - archive->getFileList(data, size); - - ::mapToArchive(data, 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 79f5ee91..9d64a6f3 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) { @@ -85,25 +81,37 @@ InstallationManager::InstallationManager() : m_ParentWidget(nullptr), m_SupportedExtensions({"zip", "rar", "7z", "fomod", "001"}), m_IsRunning(false) { - QLibrary archiveLib(QCoreApplication::applicationDirPath() + - "\\dlls\\archive.dll"); - if (!archiveLib.load()) { - throw MyException(QObject::tr("archive.dll not loaded: \"%1\"") - .arg(archiveLib.errorString())); - } - - CreateArchiveType CreateArchiveFunc - = resolveFunction<CreateArchiveType>(archiveLib, "CreateArchive"); - - m_ArchiveHandler = CreateArchiveFunc(); + m_ArchiveHandler = CreateArchive(); if (!m_ArchiveHandler->isValid()) { throw MyException(getErrorString(m_ArchiveHandler->getLastError())); } + m_ArchiveHandler->setLogCallback([](auto level, auto const& message) { + using LogLevel = Archive::LogLevel; + switch (level) { + case LogLevel::Debug: + log::debug("{}", message); + break; + case LogLevel::Info: + log::info("{}", message); + break; + case LogLevel::Warning: + log::warn("{}", message); + break; + case LogLevel::Error: + log::error("{}", message); + break; + } + }); + + // Connect the query password slot - This is the only way I found to be able to query user + // from a separate thread. We use a BlockingQueuedConnection so that calling passwordRequested() + // will block until the end of the slot. + connect(this, &InstallationManager::passwordRequested, + this, &InstallationManager::queryPassword, Qt::BlockingQueuedConnection); } InstallationManager::~InstallationManager() { - delete m_ArchiveHandler; } void InstallationManager::setParentWidget(QWidget *widget) @@ -119,70 +127,114 @@ void InstallationManager::setURL(QString const &url) m_URL = url; } -void InstallationManager::queryPassword(QString *password) -{ - *password = QInputDialog::getText(nullptr, tr("Password required"), - tr("Password"), QLineEdit::Password); +void InstallationManager::queryPassword() { + m_Password = QInputDialog::getText(m_ParentWidget, tr("Password required"), + tr("Password"), QLineEdit::Password); } - -bool InstallationManager::extractFiles(QDir extractPath) +bool InstallationManager::extractFiles(QString extractPath, QString title, bool showFilenames) { - m_InstallationProgress = new QProgressDialog(m_ParentWidget); - ON_BLOCK_EXIT([this]() { - m_InstallationProgress->cancel(); - m_InstallationProgress->hide(); - m_InstallationProgress->deleteLater(); - m_InstallationProgress = nullptr; - m_Progress = 0; - }); - m_InstallationProgress->setWindowFlags( - m_InstallationProgress->windowFlags() & (~Qt::WindowContextHelpButtonHint)); - m_InstallationProgress->setWindowTitle(tr("Extracting files")); - m_InstallationProgress->setWindowModality(Qt::WindowModal); - m_InstallationProgress->setFixedSize(600, 100); - m_InstallationProgress->setAutoReset(false); - m_InstallationProgress->show(); + QProgressDialog *installationProgress = new QProgressDialog(m_ParentWidget); + ON_BLOCK_EXIT([=]() { + installationProgress->cancel(); + installationProgress->hide(); + installationProgress->deleteLater(); + }); + installationProgress->setWindowFlags( + installationProgress->windowFlags() & (~Qt::WindowContextHelpButtonHint)); + if (!title.isEmpty()) { + installationProgress->setWindowTitle(title); + } + installationProgress->setWindowModality(Qt::WindowModal); + installationProgress->setFixedSize(600, 100); + + // Turn off auto-reset otherwize the progress dialog is reset before the end. This + // is kind of annoying because updateProgress consider percentage of progression + // through the archive (pack), while we are waiting for extracting archive entries, so + // the percentage of in updateProgress is not really related to the percentage of files + // extracted... + installationProgress->setAutoReset(false); + + // Connect signals emitted by the extraction callback to the progress dialog slots: + connect(this, &InstallationManager::progressUpdate, installationProgress, &QProgressDialog::setValue); + connect(this, &InstallationManager::progressFileChange, installationProgress, &QProgressDialog::setLabelText); + + // Cancelling progress only cancel the extraction, we do not force exiting the event-loop: + connect(installationProgress, &QProgressDialog::canceled, [this]() { m_ArchiveHandler->cancel(); }); + + installationProgress->show(); + + // Variable updated by the callbacks: + QString errorMessage; + + // The callbacks: + auto progressCallback = [this](auto progressType, uint64_t current, uint64_t total) { + if (progressType == Archive::ProgressType::EXTRACTION) { + int progress = static_cast<int>(100 * current / total); + emit progressUpdate(progress); + } + }; + Archive::FileChangeCallback fileChangeCallback = [this](auto changeType, std::wstring const& file) { + if (changeType == Archive::FileChangeType::EXTRACTION_START) { + emit progressFileChange(QString::fromStdWString(file)); + } + }; + auto errorCallback = [&errorMessage, this](std::wstring const& message) { + m_ArchiveHandler->cancel(); + errorMessage = QString::fromStdWString(message); + }; + + auto start = std::chrono::system_clock::now(); + + // Future watcher to exit the loop: + QFutureWatcher<bool> futureWatcher; + + QEventLoop loop(this); + connect( + &futureWatcher, &QFutureWatcher<bool>::finished, + &loop, &QEventLoop::quit, + Qt::QueuedConnection); // unpack only the files we need for the installer - QFuture<bool> future = QtConcurrent::run([&]() -> bool { + futureWatcher.setFuture(QtConcurrent::run([&]() -> bool { return m_ArchiveHandler->extract( - QDir::tempPath(), - new MethodCallback<InstallationManager, void, float>(this, &InstallationManager::updateProgress), - nullptr, - new MethodCallback<InstallationManager, void, QString const&>(this, &InstallationManager::report7ZipError) + extractPath.toStdWString(), + progressCallback, + showFilenames ? fileChangeCallback : nullptr, + errorCallback ); - }); - do { - if (m_Progress != m_InstallationProgress->value()) - m_InstallationProgress->setValue(m_Progress); - QCoreApplication::processEvents(); - } while (!future.isFinished()); + })); + + // Wait for future to complete: + loop.exec(); + auto future = futureWatcher.future(); + + // Check the result: if (!future.result()) { - if (m_ArchiveHandler->getLastError() == Archive::ERROR_EXTRACT_CANCELLED) { - if (!m_ErrorMessage.isEmpty()) { - throw MyException(tr("Extraction failed: %1").arg(m_ErrorMessage)); + if (m_ArchiveHandler->getLastError() == Archive::Error::ERROR_EXTRACT_CANCELLED) { + if (!errorMessage.isEmpty()) { + throw MyException(tr("Extraction failed: %1").arg(errorMessage)); } else { return false; } } else { - throw MyException(tr("Extraction failed: %1").arg(m_ArchiveHandler->getLastError())); + throw MyException(tr("Extraction failed: %1").arg(static_cast<int>(m_ArchiveHandler->getLastError()))); } } + log::debug("Extraction took {:.3f}s.", std::chrono::duration<double>(std::chrono::system_clock::now() - start).count()); + return true; } - QString InstallationManager::extractFile(std::shared_ptr<const FileTreeEntry> entry) { QStringList result = this->extractFiles({ entry }); return result.isEmpty() ? QString() : result[0]; } - QStringList InstallationManager::extractFiles(std::vector<std::shared_ptr<const FileTreeEntry>> const& entries) { // Remove the directory since mapToArchive would add them: @@ -191,7 +243,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; @@ -202,7 +254,7 @@ QStringList InstallationManager::extractFiles(std::vector<std::shared_ptr<const m_TempFilesToDelete.insert(path); } - if (!extractFiles(QDir::tempPath())) { + if (!extractFiles(QDir::tempPath(), tr("Extracting files"), false)) { return QStringList(); } @@ -273,31 +325,6 @@ IPluginInstaller::EInstallResult InstallationManager::installArchive(GuessedValu return install(archiveName, modName, iniTweaks, modId); } -void InstallationManager::updateProgress(float percentage) -{ - if (m_InstallationProgress != nullptr) { - m_Progress = static_cast<int>(percentage * 100.0); - - if (m_InstallationProgress->wasCanceled()) { - m_ArchiveHandler->cancel(); - m_InstallationProgress->reset(); - } - } -} - - -void InstallationManager::updateProgressFile(QString const &fileName) -{ - m_ProgressFile = fileName; -} - - -void InstallationManager::report7ZipError(QString const &errorMessage) -{ - m_ErrorMessage = errorMessage; - m_ArchiveHandler->cancel(); -} - QString InstallationManager::generateBackupName(const QString &directoryName) const { @@ -424,55 +451,8 @@ IPluginInstaller::EInstallResult InstallationManager::doInstall(GuessedValue<QSt QString targetDirectoryNative = QDir::toNativeSeparators(targetDirectory); log::debug("installing to \"{}\"", targetDirectoryNative); - - // Extract the archive: - m_InstallationProgress = new QProgressDialog(m_ParentWidget); - ON_BLOCK_EXIT([this] () { - m_InstallationProgress->cancel(); - m_InstallationProgress->hide(); - m_InstallationProgress->deleteLater(); - m_InstallationProgress = nullptr; - m_Progress = 0; - m_ProgressFile = QString(); - }); - - // Turn off auto-reset otherwize the progress dialog is reset before the end. This - // is kind of annoying because updateProgress consider percentage of progression - // through the archive (pack), while we are waiting for extracting archive entries, so - // the percentage of in updateProgress is not really related to the percentage of files - // extracted... - m_InstallationProgress->setAutoReset(false); - - m_InstallationProgress->setWindowFlags( - m_InstallationProgress->windowFlags() & (~Qt::WindowContextHelpButtonHint)); - m_InstallationProgress->setWindowModality(Qt::WindowModal); - m_InstallationProgress->setFixedSize(600, 100); - m_InstallationProgress->show(); - QFuture<bool> future = QtConcurrent::run([&]() -> bool { - return m_ArchiveHandler->extract( - targetDirectory, - new MethodCallback<InstallationManager, void, float>(this, &InstallationManager::updateProgress), - new MethodCallback<InstallationManager, void, QString const &>(this, &InstallationManager::updateProgressFile), - new MethodCallback<InstallationManager, void, QString const &>(this, &InstallationManager::report7ZipError) - ); - }); - do { - if (m_Progress != m_InstallationProgress->value()) - m_InstallationProgress->setValue(m_Progress); - if (m_ProgressFile != m_InstallationProgress->labelText()) - m_InstallationProgress->setLabelText(m_ProgressFile); - QCoreApplication::processEvents(); - } while (!future.isFinished()); - if (!future.result()) { - if (m_ArchiveHandler->getLastError() == Archive::ERROR_EXTRACT_CANCELLED) { - if (!m_ErrorMessage.isEmpty()) { - throw MyException(tr("Extraction failed: %1").arg(m_ErrorMessage)); - } else { - return IPluginInstaller::RESULT_CANCELED; - } - } else { - throw MyException(tr("Extraction failed: %1").arg(m_ArchiveHandler->getLastError())); - } + if (!extractFiles(targetDirectory, "", true)) { + return IPluginInstaller::RESULT_CANCELED; } // Copy the created files: @@ -539,7 +519,7 @@ IPluginInstaller::EInstallResult InstallationManager::doInstall(GuessedValue<QSt bool InstallationManager::wasCancelled() const { - return m_ArchiveHandler->getLastError() == Archive::ERROR_EXTRACT_CANCELLED; + return m_ArchiveHandler->getLastError() == Archive::Error::ERROR_EXTRACT_CANCELLED; } bool InstallationManager::isRunning() const @@ -662,8 +642,23 @@ IPluginInstaller::EInstallResult InstallationManager::install(const QString &fil m_ArchiveHandler->close(); // open the archive and construct the directory tree the installers work on - bool archiveOpen = m_ArchiveHandler->open(fileName, - new MethodCallback<InstallationManager, void, QString *>(this, &InstallationManager::queryPassword)); + + bool archiveOpen = m_ArchiveHandler->open( + fileName.toStdWString(), [this]() -> std::wstring { + m_Password = QString(); + + // Note: If we are not in the Qt event thread, we cannot use queryPassword() directly, + // so we emit passwordRequested() that is connected to queryPassword(). The connection is + // made using Qt::BlockingQueuedConnection, so the emit "call" is actually blocking. We + // cannot use emit if we are in the even thread, otherwize we have a deadlock. + if (QThread::currentThread() != QApplication::instance()->thread()) { + emit passwordRequested(); + } + else { + queryPassword(); + } + return m_Password.toStdWString(); + }); if (!archiveOpen) { log::debug("integrated archiver can't open {}: {} ({})", fileName, @@ -673,7 +668,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) { @@ -717,7 +712,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); @@ -788,33 +783,31 @@ IPluginInstaller::EInstallResult InstallationManager::install(const QString &fil return installResult; } - - QString InstallationManager::getErrorString(Archive::Error errorCode) { switch (errorCode) { - case Archive::ERROR_NONE: { + case Archive::Error::ERROR_NONE: { return tr("no error"); } break; - case Archive::ERROR_LIBRARY_NOT_FOUND: { + case Archive::Error::ERROR_LIBRARY_NOT_FOUND: { return tr("7z.dll not found"); } break; - case Archive::ERROR_LIBRARY_INVALID: { + case Archive::Error::ERROR_LIBRARY_INVALID: { return tr("7z.dll isn't valid"); } break; - case Archive::ERROR_ARCHIVE_NOT_FOUND: { + case Archive::Error::ERROR_ARCHIVE_NOT_FOUND: { return tr("archive not found"); } break; - case Archive::ERROR_FAILED_TO_OPEN_ARCHIVE: { + case Archive::Error::ERROR_FAILED_TO_OPEN_ARCHIVE: { return tr("failed to open archive"); } break; - case Archive::ERROR_INVALID_ARCHIVE_FORMAT: { + case Archive::Error::ERROR_INVALID_ARCHIVE_FORMAT: { return tr("unsupported archive type"); } break; - case Archive::ERROR_LIBRARY_ERROR: { + case Archive::Error::ERROR_LIBRARY_ERROR: { return tr("internal library error"); } break; - case Archive::ERROR_ARCHIVE_INVALID: { + case Archive::Error::ERROR_ARCHIVE_INVALID: { return tr("archive invalid"); } break; default: { @@ -824,7 +817,6 @@ QString InstallationManager::getErrorString(Archive::Error errorCode) } } - void InstallationManager::registerInstaller(IPluginInstaller *installer) { m_Installers.push_back(installer); diff --git a/src/installationmanager.h b/src/installationmanager.h index cb355641..1d94151f 100644 --- a/src/installationmanager.h +++ b/src/installationmanager.h @@ -189,14 +189,6 @@ public: private: - void queryPassword(QString *password); - void updateProgress(float percentage); - void updateProgressFile(const QString &fileName); - void report7ZipError(const QString &errorMessage); - - // Recursive worker function for mapToArchive (takes raw reference for "speed"). - bool unpackSingleFile(const QString &fileName); - MOBase::IPluginInstaller::EInstallResult doInstall(MOBase::GuessedValue<QString> &modName, QString gameName, int modID, const QString &version, const QString &newestVersion, int categoryID, int fileCategoryID, const QString &repository); @@ -212,10 +204,29 @@ private: void postInstallCleanup(); +private slots: + + /** + * @brief Query user for password and update the m_Password field. + */ + void queryPassword(); + signals: - void progressUpdate(float percentage); - void progressUpdate(QString const fileName); + /** + * @brief Emitted when a password is requested from the archive wrapper. + */ + void passwordRequested(); + + /** + * @brief Progress update from the extraction. + */ + void progressUpdate(int percentage); + + /** + * @brief File change update from the extraction. + */ + void progressFileChange(QString const& value); private: @@ -244,7 +255,7 @@ private: * @return true if the extraction was successful, false if the extraciton was * cancelled. If an error occured, an exception is thrown. */ - bool extractFiles(QDir extractPath); + bool extractFiles(QString extractPath, QString title, bool showFilenames); private: @@ -258,18 +269,14 @@ 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; - QString m_ErrorMessage; + QString m_Password; // Map from entries in the tree that is used by the installer and absolute // paths to temporary files: std::map<std::shared_ptr<const MOBase::FileTreeEntry>, QString> m_CreatedFiles; - - QProgressDialog *m_InstallationProgress { nullptr }; - int m_Progress; - QString m_ProgressFile; - std::set<QString> m_TempFilesToDelete; QString m_URL; diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index 501c7ed1..1f56fd62 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -19,10 +19,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "selfupdater.h"
-#include "archive.h"
-#include "callback.h"
#include "utility.h"
-#include "installationmanager.h"
#include "iplugingame.h"
#include "messagedialog.h"
#include "downloadmanager.h"
@@ -71,45 +68,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;
|
