From b0f049dae1548d2f16d7939b29f332b2c789210d Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 19 Jun 2016 20:50:23 +0200 Subject: [PATCH] Changed: Copy Installer in TEMP directory under Windows (to be able to uninstall it) --- .../tools/client/ryzom_installer/src/main.cpp | 18 +++++- .../client/ryzom_installer/src/utils.cpp | 59 +++++++++++++++++-- .../tools/client/ryzom_installer/src/utils.h | 6 +- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/main.cpp b/code/ryzom/tools/client/ryzom_installer/src/main.cpp index 97ba78ce9..4c13e2d25 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/main.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/main.cpp @@ -21,6 +21,7 @@ #include "installdialog.h" #include "uninstalldialog.h" #include "operationdialog.h" +#include "utils.h" #ifdef HAVE_CONFIG_H #include "config.h" @@ -60,7 +61,22 @@ int main(int argc, char *argv[]) QApplication::setApplicationVersion(RYZOM_VERSION); QApplication::setWindowIcon(QIcon(":/icons/ryzom.ico")); - // TODO: if not launched from TEMP dir, copy files to TEMP, restart it and exit +#if defined(Q_OS_WIN) && !defined(_DEBUG) + QString tempPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation); + + // check if launched from TEMP directory + if (QApplication::applicationDirPath() != tempPath) + { + // copy installer and required files to TEMP directory + if (copyInstallerExecutable(tempPath)) + { + QString tempFile = tempPath + "/" + QFileInfo(QApplication::applicationFilePath()).fileName(); + + // launch copy in TEMP directory with same arguments + if (QProcess::startDetached(tempFile, QApplication::arguments())) return 0; + } + } +#endif QLocale locale = QLocale::system(); diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp index d9ebda4c0..ba65bd2ad 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp @@ -111,7 +111,7 @@ wchar_t* qToWide(const QString &str) // Shell link, stored in the Comment field of the link // properties. -bool CreateLink(const QString &pathObj, const QString &pathLink, const QString &arguments, const QString &workingDir, const QString &desc) +bool createLink(const QString &pathObj, const QString &pathLink, const QString &arguments, const QString &workingDir, const QString &desc) { IShellLinkW* psl; @@ -163,7 +163,7 @@ bool CreateLink(const QString &pathObj, const QString &pathLink, const QString & // Shell link, stored in the Comment field of the link // properties. -bool ResolveLink(const QWidget &window, const QString &linkFile, QString &path) +bool resolveLink(const QWidget &window, const QString &linkFile, QString &path) { IShellLinkW* psl; WIN32_FIND_DATAW wfd; @@ -232,14 +232,65 @@ bool ResolveLink(const QWidget &window, const QString &linkFile, QString &path) #else -bool CreateLink(const QString &pathObj, const QString &pathLink, const QString &arguments, const QString &workingDir, const QString &desc) +bool createLink(const QString &pathObj, const QString &pathLink, const QString &arguments, const QString &workingDir, const QString &desc) { + // TODO: create .desktop file under Linux + return false; } -bool ResolveLink(const QWidget &window, const QString &pathLink, QString &pathObj) +bool resolveLink(const QWidget &window, const QString &pathLink, QString &pathObj) { return false; } #endif + +bool copyInstallerExecutable(const QString &destination) +{ + QString path = QApplication::applicationDirPath(); + + QStringList files; +#ifdef Q_OS_WIN + + // VC++ runtimes +#if _MSC_VER == 1900 + files << "msvcp140.dll"; + files << "msvcr140.dll"; +#else _MSC_VER == 1600 + files << "msvcp100.dll"; + files << "msvcr100.dll"; +#endif + +#else +#endif + + files << QFileInfo(QApplication::applicationFilePath()).fileName(); + + foreach(const QString &file, files) + { + // convert to absolute path + QString srcPath = path + "/" + file; + QString dstPath = destination + "/" + file; + + if (QFile::exists(srcPath)) + { + if (QFile::exists(dstPath)) + { + if (!QFile::remove(dstPath)) + { + qDebug() << "Unable to delete" << dstPath; + } + } + + if (!QFile::copy(srcPath, dstPath)) + { + qDebug() << "Unable to copy" << srcPath << "to" << dstPath; + + return false; + } + } + } + + return true; +} diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.h b/code/ryzom/tools/client/ryzom_installer/src/utils.h index 6c2533076..c729ba2cb 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.h +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.h @@ -48,7 +48,9 @@ QString qFromWide(const wchar_t *str); wchar_t* qToWide(const QString &str); -bool CreateLink(const QString &pathObj, const QString &pathLink, const QString &arguments, const QString &workingDir, const QString &desc); -bool ResolveLink(const QWidget &window, const QString &pathLink, QString &pathObj); +bool createLink(const QString &pathObj, const QString &pathLink, const QString &arguments, const QString &workingDir, const QString &desc); +bool resolveLink(const QWidget &window, const QString &pathLink, QString &pathObj); + +bool copyInstallerExecutable(const QString &destination); #endif