diff options
| author | Thomas Tanner <trtanner@btinternet.com> | 2015-09-27 13:29:04 +0100 |
|---|---|---|
| committer | Thomas Tanner <trtanner@btinternet.com> | 2015-09-27 13:29:04 +0100 |
| commit | 2fb491711188d413f65bdd8193644d25ae03c2c2 (patch) | |
| tree | 1b1e46b30d886ee0121ed4d8fc2354753eea9d29 | |
| parent | 364c385f1a5f71c3eb6a80b44c26ddd7af012ec8 (diff) | |
Changes to go with cleaned up archive library
| -rw-r--r-- | src/SConscript | 6 | ||||
| -rw-r--r-- | src/installationmanager.cpp | 113 | ||||
| -rw-r--r-- | src/installationmanager.h | 12 | ||||
| -rw-r--r-- | src/selfupdater.cpp | 50 | ||||
| -rw-r--r-- | src/selfupdater.h | 9 |
5 files changed, 85 insertions, 105 deletions
diff --git a/src/SConscript b/src/SConscript index 6783fd8b..540b2343 100644 --- a/src/SConscript +++ b/src/SConscript @@ -72,7 +72,11 @@ env.AppendUnique(CPPDEFINES = [ 'QT_MESSAGELOGCONTEXT'
])
-env.AppendUnique(CPPFLAGS = [ '-wd4100', '-wd4127', '-wd4512', '-wd4189' ])
+# Boost produces very long names with msvc truncates. Doesn't seem to cause
+# problems.
+# Also note to remove the -wd4100 I hacked the boost headers (tagged_argument.hpp)
+# appropriately.
+env.AppendUnique(CPPFLAGS = [ '-wd4503' ])
env.AppendUnique(LINKFLAGS = [
'/SUBSYSTEM:WINDOWS',
diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 75abd750..ead9b3dc 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -81,9 +81,9 @@ InstallationManager::InstallationManager() CreateArchiveType CreateArchiveFunc = resolveFunction<CreateArchiveType>(archiveLib, "CreateArchive");
- m_CurrentArchive = CreateArchiveFunc();
- if (!m_CurrentArchive->isValid()) {
- throw MyException(getErrorString(m_CurrentArchive->getLastError()));
+ m_ArchiveHandler = CreateArchiveFunc();
+ if (!m_ArchiveHandler->isValid()) {
+ throw MyException(getErrorString(m_ArchiveHandler->getLastError()));
}
m_InstallationProgress.setWindowFlags(m_InstallationProgress.windowFlags() & (~Qt::WindowContextHelpButtonHint));
@@ -92,7 +92,7 @@ InstallationManager::InstallationManager() InstallationManager::~InstallationManager()
{
- delete m_CurrentArchive;
+ delete m_ArchiveHandler;
}
void InstallationManager::setParentWidget(QWidget *widget)
@@ -104,34 +104,32 @@ void InstallationManager::setParentWidget(QWidget *widget) }
-void InstallationManager::queryPassword(LPSTR password)
+void InstallationManager::queryPassword(QString *password)
{
- QString result = QInputDialog::getText(nullptr, tr("Password required"), tr("Password"), QLineEdit::Password);
- strncpy(password, result.toLocal8Bit().constData(), MAX_PASSWORD_LENGTH);
+ *password = QInputDialog::getText(nullptr, tr("Password required"), tr("Password"), QLineEdit::Password);
}
-void InstallationManager::mapToArchive(const DirectoryTree::Node *node, std::wstring path, FileData * const *data)
+void InstallationManager::mapToArchive(const DirectoryTree::Node *node, QString path, FileData * const *data)
{
if (path.length() > 0) {
// when using a long windows path (starting with \\?\) we apparently can have redundant
// . components in the path. This wasn't a problem with "regular" path names.
- if (path == L".") {
+ if (path == ".") {
path.clear();
} else {
- path.append(L"\\");
+ path.append("\\");
}
}
for (DirectoryTree::const_leaf_iterator iter = node->leafsBegin(); iter != node->leafsEnd(); ++iter) {
- std::wstring temp = path + iter->getName().toStdWString();
- data[iter->getIndex()]->addOutputFileName(temp.c_str());
+ data[iter->getIndex()]->addOutputFileName(path + iter->getName().toQString());
}
for (DirectoryTree::const_node_iterator iter = node->nodesBegin(); iter != node->nodesEnd(); ++iter) {
- std::wstring temp = path + (*iter)->getData().name.toStdWString();
+ QString temp = path + (*iter)->getData().name.toQString();
if ((*iter)->getData().index != -1) {
- data[(*iter)->getData().index]->addOutputFileName(temp.c_str());
+ data[(*iter)->getData().index]->addOutputFileName(temp);
}
mapToArchive(*iter, temp, data);
}
@@ -142,11 +140,9 @@ void InstallationManager::mapToArchive(const DirectoryTree::Node *baseNode) {
FileData* const *data;
size_t size;
- m_CurrentArchive->getFileList(data, size);
+ m_ArchiveHandler->getFileList(data, size);
- std::wstring currentPath;
-
- mapToArchive(baseNode, currentPath, data);
+ mapToArchive(baseNode, "", data);
}
@@ -154,15 +150,15 @@ bool InstallationManager::unpackSingleFile(const QString &fileName) {
FileData* const *data;
size_t size;
- m_CurrentArchive->getFileList(data, size);
+ m_ArchiveHandler->getFileList(data, size);
QString baseName = QFileInfo(fileName).fileName();
bool available = false;
for (size_t i = 0; i < size; ++i) {
- if (_wcsicmp(data[i]->getFileName(), ToWString(fileName).c_str()) == 0) {
+ if (data[i]->getFileName().compare(fileName, Qt::CaseInsensitive) == 0) {
available = true;
- data[i]->addOutputFileName(ToWString(baseName).c_str());
+ data[i]->addOutputFileName(baseName);
m_TempFilesToDelete.insert(baseName);
}
}
@@ -177,10 +173,10 @@ bool InstallationManager::unpackSingleFile(const QString &fileName) m_InstallationProgress.setWindowModality(Qt::WindowModal);
m_InstallationProgress.show();
- bool res = m_CurrentArchive->extract(ToWString(QDir::toNativeSeparators(QDir::tempPath())).c_str(),
+ bool res = m_ArchiveHandler->extract(QDir::tempPath(),
new MethodCallback<InstallationManager, void, float>(this, &InstallationManager::updateProgress),
- new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::dummyProgressFile),
- new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::report7ZipError));
+ nullptr,
+ new MethodCallback<InstallationManager, void, QString const &>(this, &InstallationManager::report7ZipError));
m_InstallationProgress.hide();
@@ -223,25 +219,30 @@ QStringList InstallationManager::extractFiles(const QStringList &filesOrig, bool FileData* const *data;
size_t size;
- m_CurrentArchive->getFileList(data, size);
+ m_ArchiveHandler->getFileList(data, size);
for (size_t i = 0; i < size; ++i) {
- if (files.contains(ToQString(data[i]->getFileName()), Qt::CaseInsensitive)) {
- const wchar_t *targetFile = data[i]->getFileName();
+ //FIXME Use qstring all the way through
+ if (files.contains(data[i]->getFileName(), Qt::CaseInsensitive)) {
+ std::wstring temp = data[i]->getFileName().toStdWString();
+ wchar_t const * const origFile = temp.c_str();
+ const wchar_t *targetFile = origFile;
+ //Note: I don't think 'flatten' is ever set to true. so this code
+ //might never be executed
if (flatten) {
- targetFile = wcsrchr(data[i]->getFileName(), '\\');
+ targetFile = wcsrchr(origFile/*data[i]->getFileName()*/, '\\');
if (targetFile == nullptr) {
- targetFile = wcsrchr(data[i]->getFileName(), '/');
+ targetFile = wcsrchr(origFile/*data[i]->getFileName()*/, '/');
}
if (targetFile == nullptr) {
- qCritical("failed to find backslash in %ls", data[i]->getFileName());
+ qCritical() << "Failed to find backslash in " << data[i]->getFileName();
continue;
} else {
// skip the slash
++targetFile;
}
}
- data[i]->addOutputFileName(targetFile);
+ data[i]->addOutputFileName(ToQString(targetFile));
result.append(QDir::tempPath().append("/").append(ToQString(targetFile)));
@@ -256,12 +257,12 @@ QStringList InstallationManager::extractFiles(const QStringList &filesOrig, bool m_InstallationProgress.show();
// unpack only the files we need for the installer
- if (!m_CurrentArchive->extract(ToWString(QDir::toNativeSeparators(QDir::tempPath())).c_str(),
+ if (!m_ArchiveHandler->extract(QDir::tempPath(),
new MethodCallback<InstallationManager, void, float>(this, &InstallationManager::updateProgress),
- new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::dummyProgressFile),
- new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::report7ZipError))) {
+ nullptr,
+ new MethodCallback<InstallationManager, void, QString const &>(this, &InstallationManager::report7ZipError))) {
m_InstallationProgress.hide();
- throw MyException(QString("extracting failed (%1)").arg(m_CurrentArchive->getLastError()));
+ throw MyException(QString("extracting failed (%1)").arg(m_ArchiveHandler->getLastError()));
}
m_InstallationProgress.hide();
@@ -286,7 +287,7 @@ DirectoryTree *InstallationManager::createFilesTree() {
FileData* const *data;
size_t size;
- m_CurrentArchive->getFileList(data, size);
+ m_ArchiveHandler->getFileList(data, size);
QScopedPointer<DirectoryTree> result(new DirectoryTree);
@@ -296,7 +297,7 @@ DirectoryTree *InstallationManager::createFilesTree() // grouping the filenames first, but so far there doesn't seem to be an actual performance problem
DirectoryTree::Node *currentNode = result.data();
- QString fileName = ToQString(data[i]->getFileName());
+ QString fileName = data[i]->getFileName();
QStringList components = fileName.split("\\");
// iterate over all path-components of this filename (including the filename itself)
@@ -389,26 +390,22 @@ void InstallationManager::updateProgress(float percentage) {
m_InstallationProgress.setValue(static_cast<int>(percentage * 100.0));
if (m_InstallationProgress.wasCanceled()) {
- m_CurrentArchive->cancel();
+ m_ArchiveHandler->cancel();
m_InstallationProgress.reset();
}
}
-void InstallationManager::updateProgressFile(LPCWSTR fileName)
+void InstallationManager::updateProgressFile(QString const &fileName)
{
-#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
- m_InstallationProgress.setLabelText(QString::fromWCharArray(fileName));
-#else
- m_InstallationProgress.setLabelText(QString::fromUtf16(fileName));
-#endif
+ m_InstallationProgress.setLabelText(fileName);
}
-void InstallationManager::report7ZipError(LPCWSTR errorMessage)
+void InstallationManager::report7ZipError(QString const &errorMessage)
{
- reportError(QString::fromWCharArray(errorMessage));
- m_CurrentArchive->cancel();
+ reportError(errorMessage);
+ m_ArchiveHandler->cancel();
}
@@ -538,15 +535,15 @@ bool InstallationManager::doInstall(GuessedValue<QString> &modName, int modID, m_InstallationProgress.setValue(0);
m_InstallationProgress.setWindowModality(Qt::WindowModal);
m_InstallationProgress.show();
- if (!m_CurrentArchive->extract(ToWString("\\\\?\\" + targetDirectoryNative).c_str(),
+ if (!m_ArchiveHandler->extract(targetDirectory,
new MethodCallback<InstallationManager, void, float>(this, &InstallationManager::updateProgress),
- new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::updateProgressFile),
- new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::report7ZipError))) {
+ new MethodCallback<InstallationManager, void, QString const &>(this, &InstallationManager::updateProgressFile),
+ new MethodCallback<InstallationManager, void, QString const &>(this, &InstallationManager::report7ZipError))) {
m_InstallationProgress.hide();
- if (m_CurrentArchive->getLastError() == Archive::ERROR_EXTRACT_CANCELLED) {
+ if (m_ArchiveHandler->getLastError() == Archive::ERROR_EXTRACT_CANCELLED) {
return false;
} else {
- throw MyException(QString("extracting failed (%1)").arg(m_CurrentArchive->getLastError()));
+ throw MyException(QString("extracting failed (%1)").arg(m_ArchiveHandler->getLastError()));
}
}
@@ -587,13 +584,13 @@ bool InstallationManager::doInstall(GuessedValue<QString> &modName, int modID, bool InstallationManager::wasCancelled()
{
- return m_CurrentArchive->getLastError() == Archive::ERROR_EXTRACT_CANCELLED;
+ return m_ArchiveHandler->getLastError() == Archive::ERROR_EXTRACT_CANCELLED;
}
void InstallationManager::postInstallCleanup()
{
- m_CurrentArchive->close();
+ m_ArchiveHandler->close();
// directories we may want to remove. sorted from longest to shortest to ensure we remove subdirectories first.
auto longestFirst = [](const QString &LHS, const QString &RHS) -> bool {
@@ -679,13 +676,13 @@ bool InstallationManager::install(const QString &fileName, GuessedValue<QString> //If there's an archive already open, close it. This happens with the bundle
//installer when it uncompresses a split archive, then finds it has a real archive
//to deal with.
- m_CurrentArchive->close();
+ m_ArchiveHandler->close();
// open the archive and construct the directory tree the installers work on
- bool archiveOpen = m_CurrentArchive->open(ToWString(QDir::toNativeSeparators(fileName)).c_str(),
- new MethodCallback<InstallationManager, void, LPSTR>(this, &InstallationManager::queryPassword));
+ bool archiveOpen = m_ArchiveHandler->open(fileName,
+ new MethodCallback<InstallationManager, void, QString *>(this, &InstallationManager::queryPassword));
if (!archiveOpen) {
- qDebug("integrated archiver can't open %s. errorcode %d", qPrintable(fileName), m_CurrentArchive->getLastError());
+ qDebug("integrated archiver can't open %s. errorcode %d", qPrintable(fileName), m_ArchiveHandler->getLastError());
}
ON_BLOCK_EXIT(std::bind(&InstallationManager::postInstallCleanup, this));
diff --git a/src/installationmanager.h b/src/installationmanager.h index d4b4f7dc..d73f4653 100644 --- a/src/installationmanager.h +++ b/src/installationmanager.h @@ -147,12 +147,10 @@ public: private:
- void queryPassword(LPSTR password);
+ void queryPassword(QString *password);
void updateProgress(float percentage);
- void updateProgressFile(LPCWSTR fileName);
- void report7ZipError(LPCWSTR errorMessage);
-
- void dummyProgressFile(LPCWSTR) {}
+ void updateProgressFile(const QString &fileName);
+ void report7ZipError(const QString &errorMessage);
MOBase::DirectoryTree *createFilesTree();
@@ -161,7 +159,7 @@ private: void mapToArchive(const MOBase::DirectoryTree::Node *baseNode);
// recursive worker function for mapToArchive
- void mapToArchive(const MOBase::DirectoryTree::Node *node, std::wstring path, FileData * const *data);
+ void mapToArchive(const MOBase::DirectoryTree::Node *node, QString path, FileData * const *data);
bool unpackSingleFile(const QString &fileName);
@@ -205,7 +203,7 @@ private: std::vector<MOBase::IPluginInstaller*> m_Installers;
std::set<QString, CaseInsensitive> m_SupportedExtensions;
- Archive *m_CurrentArchive;
+ Archive *m_ArchiveHandler;
QString m_CurrentFile;
QProgressDialog m_InstallationProgress;
diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index ed34bfc2..724b89db 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -73,9 +73,9 @@ SelfUpdater::SelfUpdater(NexusInterface *nexusInterface) CreateArchiveType CreateArchiveFunc = resolveFunction<CreateArchiveType>(archiveLib, "CreateArchive");
- m_CurrentArchive = CreateArchiveFunc();
- if (!m_CurrentArchive->isValid()) {
- throw MyException(InstallationManager::getErrorString(m_CurrentArchive->getLastError()));
+ m_ArchiveHandler = CreateArchiveFunc();
+ if (!m_ArchiveHandler->isValid()) {
+ throw MyException(InstallationManager::getErrorString(m_ArchiveHandler->getLastError()));
}
connect(&m_Progress, SIGNAL(canceled()), this, SLOT(downloadCancel()));
@@ -90,7 +90,7 @@ SelfUpdater::SelfUpdater(NexusInterface *nexusInterface) SelfUpdater::~SelfUpdater()
{
- delete m_CurrentArchive;
+ delete m_ArchiveHandler;
}
void SelfUpdater::setUserInterface(QWidget *widget)
@@ -238,26 +238,25 @@ void SelfUpdater::installUpdate() QDir().mkdir(backupPath);
// rename files that are currently open so we can unpack the update
- if (!m_CurrentArchive->open(ToWString(QDir::toNativeSeparators(m_UpdateFile.fileName())).c_str(),
- new MethodCallback<SelfUpdater, void, LPSTR>(this, &SelfUpdater::queryPassword))) {
+ if (!m_ArchiveHandler->open(m_UpdateFile.fileName(), nullptr)) {
throw MyException(tr("failed to open archive \"%1\": %2")
.arg(m_UpdateFile.fileName())
- .arg(InstallationManager::getErrorString(m_CurrentArchive->getLastError())));
+ .arg(InstallationManager::getErrorString(m_ArchiveHandler->getLastError())));
}
// move all files contained in the archive out of the way,
// otherwise we can't overwrite everything
FileData* const *data;
size_t size;
- m_CurrentArchive->getFileList(data, size);
+ m_ArchiveHandler->getFileList(data, size);
for (size_t i = 0; i < size; ++i) {
- QString outputName = ToQString(data[i]->getFileName());
+ QString outputName = data[i]->getFileName();
if (outputName.startsWith("ModOrganizer\\", Qt::CaseInsensitive)) {
outputName = outputName.mid(13);
- data[i]->addOutputFileName(ToWString(outputName).c_str());
+ data[i]->addOutputFileName(outputName);
} else if (outputName != "ModOrganizer") {
- data[i]->addOutputFileName(ToWString(outputName).c_str());
+ data[i]->addOutputFileName(outputName);
}
QFileInfo file(mopath + "/" + outputName);
if (file.exists() && file.isFile()) {
@@ -270,14 +269,14 @@ void SelfUpdater::installUpdate() }
// now unpack the archive into the mo directory
- if (!m_CurrentArchive->extract(GameInfo::instance().getOrganizerDirectory().c_str(),
- new MethodCallback<SelfUpdater, void, float>(this, &SelfUpdater::updateProgress),
- new MethodCallback<SelfUpdater, void, LPCWSTR>(this, &SelfUpdater::updateProgressFile),
- new MethodCallback<SelfUpdater, void, LPCWSTR>(this, &SelfUpdater::report7ZipError))) {
+ if (!m_ArchiveHandler->extract(QString::fromStdWString(GameInfo::instance().getOrganizerDirectory()),
+ nullptr,
+ nullptr,
+ new MethodCallback<SelfUpdater, void, QString const &>(this, &SelfUpdater::report7ZipError))) {
throw std::runtime_error("extracting failed");
}
- m_CurrentArchive->close();
+ m_ArchiveHandler->close();
m_UpdateFile.remove();
@@ -292,24 +291,9 @@ void SelfUpdater::installUpdate() emit restart();
}
-void SelfUpdater::queryPassword(LPSTR)
+void SelfUpdater::report7ZipError(QString const &errorMessage)
{
- // nop
-}
-
-void SelfUpdater::updateProgress(float)
-{
- // nop
-}
-
-void SelfUpdater::updateProgressFile(LPCWSTR)
-{
- // nop
-}
-
-void SelfUpdater::report7ZipError(LPCWSTR errorMessage)
-{
- QMessageBox::critical(m_Parent, tr("Error"), ToQString(errorMessage));
+ QMessageBox::critical(m_Parent, tr("Error"), errorMessage);
}
diff --git a/src/selfupdater.h b/src/selfupdater.h index b5bbc406..ac9bddb3 100644 --- a/src/selfupdater.h +++ b/src/selfupdater.h @@ -65,7 +65,7 @@ public: * @param parent parent widget
* @todo passing the nexus interface is unneccessary
**/
- SelfUpdater(NexusInterface *nexusInterface);
+ explicit SelfUpdater(NexusInterface *nexusInterface);
virtual ~SelfUpdater();
@@ -115,10 +115,7 @@ private: void download(const QString &downloadLink, const QString &fileName);
void installUpdate();
- void queryPassword(LPSTR password);
- void updateProgress(float percentage);
- void updateProgressFile(LPCWSTR fileName);
- void report7ZipError(LPCWSTR errorMessage);
+ void report7ZipError(const QString &errorMessage);
QString retrieveNews(const QString &description);
void showProgress();
@@ -142,7 +139,7 @@ private: bool m_Canceled;
int m_Attempts;
- Archive *m_CurrentArchive;
+ Archive *m_ArchiveHandler;
};
|
