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

This commit is contained in:
kervala 2016-06-19 20:50:23 +02:00
parent ababfe0553
commit de2dc037fd
3 changed files with 76 additions and 7 deletions

View file

@ -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();

View file

@ -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;
}

View file

@ -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