Changed: Copy Installer in TEMP directory under Windows (to be able to uninstall it)

--HG--
branch : develop
feature/pipeline-tools
kervala 9 years ago
parent 83c97c6c36
commit 438744f3bf

@ -21,6 +21,7 @@
#include "installdialog.h" #include "installdialog.h"
#include "uninstalldialog.h" #include "uninstalldialog.h"
#include "operationdialog.h" #include "operationdialog.h"
#include "utils.h"
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
@ -60,7 +61,22 @@ int main(int argc, char *argv[])
QApplication::setApplicationVersion(RYZOM_VERSION); QApplication::setApplicationVersion(RYZOM_VERSION);
QApplication::setWindowIcon(QIcon(":/icons/ryzom.ico")); 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(); QLocale locale = QLocale::system();

@ -111,7 +111,7 @@ wchar_t* qToWide(const QString &str)
// Shell link, stored in the Comment field of the link // Shell link, stored in the Comment field of the link
// properties. // 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; 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 // Shell link, stored in the Comment field of the link
// properties. // properties.
bool ResolveLink(const QWidget &window, const QString &linkFile, QString &path) bool resolveLink(const QWidget &window, const QString &linkFile, QString &path)
{ {
IShellLinkW* psl; IShellLinkW* psl;
WIN32_FIND_DATAW wfd; WIN32_FIND_DATAW wfd;
@ -232,14 +232,65 @@ bool ResolveLink(const QWidget &window, const QString &linkFile, QString &path)
#else #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; return false;
} }
bool ResolveLink(const QWidget &window, const QString &pathLink, QString &pathObj) bool resolveLink(const QWidget &window, const QString &pathLink, QString &pathObj)
{ {
return false; return false;
} }
#endif #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;
}

@ -48,7 +48,9 @@ QString qFromWide(const wchar_t *str);
wchar_t* qToWide(const QString &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 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 resolveLink(const QWidget &window, const QString &pathLink, QString &pathObj);
bool copyInstallerExecutable(const QString &destination);
#endif #endif

Loading…
Cancel
Save