From e8205728ce85c9d06c2c69cc2209dd101fe3f10b Mon Sep 17 00:00:00 2001 From: danteruiz Date: Fri, 27 Sep 2019 15:31:44 -0700 Subject: [PATCH] install and uninstall features --- launchers/qt/src/Helper.h | 2 +- .../qt/src/LauncherInstaller_windows.cpp | 53 ++++++++++++++++++- launchers/qt/src/LauncherInstaller_windows.h | 6 ++- launchers/qt/src/main.cpp | 7 ++- 4 files changed, 62 insertions(+), 6 deletions(-) diff --git a/launchers/qt/src/Helper.h b/launchers/qt/src/Helper.h index 975eb383d7..d26cacfa5c 100644 --- a/launchers/qt/src/Helper.h +++ b/launchers/qt/src/Helper.h @@ -17,5 +17,5 @@ bool replaceDirectory(const QString& orginalDirectory, const QString& newDirecto #endif #ifdef Q_OS_WIN -HRESULT createSymbolicLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszArgs); +HRESULT createSymbolicLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc, LPCSTR lpszArgs = (LPCSTR)""); #endif diff --git a/launchers/qt/src/LauncherInstaller_windows.cpp b/launchers/qt/src/LauncherInstaller_windows.cpp index dc49c7d738..ea35e86c64 100644 --- a/launchers/qt/src/LauncherInstaller_windows.cpp +++ b/launchers/qt/src/LauncherInstaller_windows.cpp @@ -10,8 +10,11 @@ LauncherInstaller::LauncherInstaller(const QString& applicationFilePath) { _launcherInstallDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/HQ"; + _launcherApplicationsDir = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/HQ"; qDebug() << "Launcher install dir: " << _launcherInstallDir.absolutePath(); + qDebug() << "Launcher Application dir: " << _launcherApplicationsDir.absolutePath(); _launcherInstallDir.mkpath(_launcherInstallDir.absolutePath()); + _launcherApplicationsDir.mkpath(_launcherApplicationsDir.absolutePath()); QFileInfo fileInfo(applicationFilePath); _launcherRunningFilePath = fileInfo.absoluteFilePath(); _launcherRunningDirPath = fileInfo.absoluteDir().absolutePath(); @@ -24,6 +27,7 @@ bool LauncherInstaller::runningOutsideOfInstallDir() { } void LauncherInstaller::install() { + //qDebug() << "Is install dir empty: " << _launcherInstallDir.isEmpty(); if (runningOutsideOfInstallDir()) { qDebug() << "Installing HQ Launcher...."; QString oldLauncherPath = _launcherInstallDir.absolutePath() + "/HQ Launcher.exe"; @@ -40,14 +44,59 @@ void LauncherInstaller::install() { } qDebug() << "LauncherInstaller: create uninstall link"; - QString uninstallLinkPath = _launcherInstallDir.absolutePath() + "/Uninstall HQ.link"; + QString uninstallLinkPath = _launcherInstallDir.absolutePath() + "/Uninstall HQ.lnk"; if (QFile::exists(uninstallLinkPath)) { QFile::remove(uninstallLinkPath); } + + + QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + QString applicationPath = _launcherApplicationsDir.absolutePath(); + + QString appStartLinkPath = applicationPath + "/HQ.lnk"; + QString uninstallAppStartLinkPath = applicationPath + "/Uninstall HQ.lnk"; + QString desktopAppLinkPath = desktopPath + "/HQ.lnk"; + + createSymbolicLink((LPCSTR)oldLauncherPath.toStdString().c_str(), (LPCSTR)uninstallLinkPath.toStdString().c_str(), (LPCSTR)("Click to Uninstall HQ"), (LPCSTR)("--uninstall")); + + createSymbolicLink((LPCSTR)oldLauncherPath.toStdString().c_str(), (LPCSTR)uninstallAppStartLinkPath.toStdString().c_str(), + (LPCSTR)("Click to Uninstall HQ"), (LPCSTR)("--uninstall")); + + createSymbolicLink((LPCSTR)oldLauncherPath.toStdString().c_str(), (LPCSTR)desktopAppLinkPath.toStdString().c_str(), + (LPCSTR)("Click to Setup and Launch HQ")); + + createSymbolicLink((LPCSTR)oldLauncherPath.toStdString().c_str(), (LPCSTR)appStartLinkPath.toStdString().c_str(), + (LPCSTR)("Click to Setup and Launch HQ")); + } else { + qDebug() << "FAILED!!!!!!!"; } } -void LauncherInstaller::uninstall() {} +void LauncherInstaller::uninstall() { + qDebug() << "Uninstall Launcher"; + QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + QString applicationPath = _launcherApplicationsDir.absolutePath(); + + QString uninstallLinkPath = _launcherInstallDir.absolutePath() + "/Uninstall HQ.lnk"; + if (QFile::exists(uninstallLinkPath)) { + QFile::remove(uninstallLinkPath); + } + + QString appStartLinkPath = applicationPath + "/HQ.lnk"; + if (QFile::exists(appStartLinkPath)) { + QFile::remove(appStartLinkPath); + } + + QString uninstallAppStartLinkPath = applicationPath + "/Uninstall HQ.lnk"; + if (QFile::exists(uninstallAppStartLinkPath)) { + QFile::remove(uninstallAppStartLinkPath); + } + + QString desktopAppLinkPath = desktopPath + "/HQ.lnk"; + if (QFile::exists(desktopAppLinkPath)) { + QFile::remove(desktopAppLinkPath); + } +} diff --git a/launchers/qt/src/LauncherInstaller_windows.h b/launchers/qt/src/LauncherInstaller_windows.h index 1aa10ce876..8791f9395f 100644 --- a/launchers/qt/src/LauncherInstaller_windows.h +++ b/launchers/qt/src/LauncherInstaller_windows.h @@ -8,9 +8,13 @@ public: void install(); void uninstall(); -private: bool runningOutsideOfInstallDir(); +private: + void createShortcuts(); + void deleteShortcuts(); + QDir _launcherInstallDir; + QDir _launcherApplicationsDir; QString _launcherRunningFilePath; QString _launcherRunningDirPath; }; diff --git a/launchers/qt/src/main.cpp b/launchers/qt/src/main.cpp index ed5cbe8138..6b2bd39fde 100644 --- a/launchers/qt/src/main.cpp +++ b/launchers/qt/src/main.cpp @@ -40,9 +40,12 @@ int main(int argc, char *argv[]) { CommandlineOptions* options = CommandlineOptions::getInstance(); options->parse(argc, argv); #ifdef Q_OS_WIN - if (options->contains("--restart")) { - LauncherInstaller launcherInstaller(argv[0]); + LauncherInstaller launcherInstaller(argv[0]); + if (options->contains("--restart") || launcherInstaller.runningOutsideOfInstallDir()) { launcherInstaller.install(); + } else if (options->contains("--uninstall")) { + launcherInstaller.uninstall(); + return 0; } #endif QString name { "High Fidelity" };