From 80f02938810c97d001295bebc3994c6a1b9297a9 Mon Sep 17 00:00:00 2001 From: danteruiz Date: Tue, 8 Oct 2019 16:57:14 -0700 Subject: [PATCH] update install/uninstall and fix createProcess args --- launchers/qt/src/Helper.cpp | 1 + launchers/qt/src/Helper_windows.cpp | 4 +- .../qt/src/LauncherInstaller_windows.cpp | 81 ++++++++++++++++++- launchers/qt/src/LauncherInstaller_windows.h | 1 + launchers/qt/src/main.cpp | 11 +-- 5 files changed, 85 insertions(+), 13 deletions(-) diff --git a/launchers/qt/src/Helper.cpp b/launchers/qt/src/Helper.cpp index 30de16cdcc..42f76fe0fa 100644 --- a/launchers/qt/src/Helper.cpp +++ b/launchers/qt/src/Helper.cpp @@ -57,6 +57,7 @@ void messageHandler(QtMsgType type, const QMessageLogContext& context, const QSt QTextStream textStream(&outFile); std::cout << txt.toStdString() << "\n"; textStream << txt << "\n"; + outFile.close(); } void swapLaunchers(const QString& oldLauncherPath, const QString& newLauncherPath) { diff --git a/launchers/qt/src/Helper_windows.cpp b/launchers/qt/src/Helper_windows.cpp index ebbf1fab72..662e64daae 100644 --- a/launchers/qt/src/Helper_windows.cpp +++ b/launchers/qt/src/Helper_windows.cpp @@ -16,7 +16,7 @@ void launchClient(const QString& clientPath, const QString& homePath, const QStr const QString& displayName, const QString& contentCachePath, QString loginResponseToken) { // TODO Fix parameters - QString params = "--url \"" + homePath + "\"" + QString params = "\"" + clientPath + "\"" + " --url \"" + homePath + "\"" + " --setBookmark \"hqhome=" + homePath + "\"" + " --defaultScriptsOverride \"file:///" + defaultScriptsPath + "\"" + " --cache \"" + contentCachePath + "\"" @@ -58,7 +58,7 @@ void launchClient(const QString& clientPath, const QString& homePath, const QStr } void launchAutoUpdater(const QString& autoUpdaterPath) { - QString params = "--restart --noUpdate"; + QString params = "\"" + QCoreApplication::applicationFilePath() + "\"" + " --restart --noUpdate"; STARTUPINFO si; PROCESS_INFORMATION pi; diff --git a/launchers/qt/src/LauncherInstaller_windows.cpp b/launchers/qt/src/LauncherInstaller_windows.cpp index e8f1d785a7..3423815d7c 100644 --- a/launchers/qt/src/LauncherInstaller_windows.cpp +++ b/launchers/qt/src/LauncherInstaller_windows.cpp @@ -1,4 +1,6 @@ #include "LauncherInstaller_windows.h" + +#include "CommandlineOptions.h" #include "Helper.h" #include @@ -9,12 +11,12 @@ #include #include -#include +#include #include LauncherInstaller::LauncherInstaller(const QString& applicationFilePath) { - _launcherInstallDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/HQ"; - _launcherApplicationsDir = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/HQ"; + _launcherInstallDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); + _launcherApplicationsDir = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/Launcher"; qDebug() << "Launcher install dir: " << _launcherInstallDir.absolutePath(); qDebug() << "Launcher Application dir: " << _launcherApplicationsDir.absolutePath(); _launcherInstallDir.mkpath(_launcherInstallDir.absolutePath()); @@ -33,6 +35,7 @@ bool LauncherInstaller::runningOutsideOfInstallDir() { void LauncherInstaller::install() { if (runningOutsideOfInstallDir()) { qDebug() << "Installing HQ Launcher...."; + uninstallOldLauncher(); QString oldLauncherPath = _launcherInstallDir.absolutePath() + "/HQ Launcher.exe"; if (QFile::exists(oldLauncherPath)) { @@ -83,10 +86,46 @@ void LauncherInstaller::createShortcuts() { void LauncherInstaller::uninstall() { qDebug() << "Uninstall Launcher"; deleteShortcuts(); + CommandlineOptions* options = CommandlineOptions::getInstance(); + if (!options->contains("--resumeUninstall")) { + QDir tmpDirectory = QStandardPaths::writableLocation(QStandardPaths::TempLocation); + QString destination = tmpDirectory.absolutePath() + "/HQ Launcher.exe"; + qDebug() << destination; + if (QFile::exists(destination)) { + QFile::remove(destination); + } + bool copied = QFile::copy(_launcherRunningFilePath, destination); + if (copied) { + QString params = "\"" + _launcherRunningFilePath + "\"" + " --resumeUninstall"; + STARTUPINFO si; + PROCESS_INFORMATION pi; + + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + ZeroMemory(&pi, sizeof(pi)); + + BOOL success = CreateProcess( + destination.toUtf8().data(), + params.toUtf8().data(), + nullptr, // Process handle not inheritable + nullptr, // Thread handle not inheritable + FALSE, // Set handle inheritance to FALSE + CREATE_NEW_CONSOLE, // Opens file in a separate console + nullptr, // Use parent's environment block + nullptr, // Use parent's starting directory + &si, // Pointer to STARTUPINFO structure + &pi // Pointer to PROCESS_INFORMATION structure + ); + } else { + qDebug() << "Failed to complete uninstall launcher"; + } + return; + } QString launcherPath = _launcherInstallDir.absolutePath() + "/HQ Launcher.exe"; if (QFile::exists(launcherPath)) { - QFile::remove(launcherPath); + bool removed = QFile::remove(launcherPath); + qDebug() << "Successfully removed " << launcherPath << ": " << removed; } deleteApplicationRegistryKeys(); } @@ -116,6 +155,40 @@ void LauncherInstaller::deleteShortcuts() { } } +void LauncherInstaller::uninstallOldLauncher() { + QDir localAppPath = QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation).value(0) + "/../../HQ"; + QDir startAppPath = QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation).value(0) + "/HQ"; + QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + + qDebug() << localAppPath.absolutePath(); + qDebug() << startAppPath.absolutePath(); + QString desktopAppLinkPath = desktopPath + "/HQ Launcher.lnk"; + if (QFile::exists(desktopAppLinkPath)) { + QFile::remove(desktopAppLinkPath); + } + + QString uninstallLinkPath = localAppPath.absolutePath() + "/Uninstall HQ.lnk"; + if (QFile::exists(uninstallLinkPath)) { + QFile::remove(uninstallLinkPath); + } + + QString applicationPath = localAppPath.absolutePath() + "/HQ Launcher.exe"; + if (QFile::exists(applicationPath)) { + QFile::remove(applicationPath); + } + + QString appStartLinkPath = startAppPath.absolutePath() + "/HQ Launcher.lnk"; + if (QFile::exists(appStartLinkPath)) { + QFile::remove(appStartLinkPath); + } + + QString uninstallAppStartLinkPath = startAppPath.absolutePath() + "/Uninstall HQ.lnk"; + if (QFile::exists(uninstallAppStartLinkPath)) { + QFile::remove(uninstallAppStartLinkPath); + } +} + + void LauncherInstaller::createApplicationRegistryKeys() { const std::string REGISTRY_PATH = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\HQ"; diff --git a/launchers/qt/src/LauncherInstaller_windows.h b/launchers/qt/src/LauncherInstaller_windows.h index 6ddd74f53f..3bd9d0242a 100644 --- a/launchers/qt/src/LauncherInstaller_windows.h +++ b/launchers/qt/src/LauncherInstaller_windows.h @@ -11,6 +11,7 @@ public: bool runningOutsideOfInstallDir(); private: void createShortcuts(); + void uninstallOldLauncher(); void createApplicationRegistryKeys(); void deleteShortcuts(); void deleteApplicationRegistryKeys(); diff --git a/launchers/qt/src/main.cpp b/launchers/qt/src/main.cpp index 7526ccc8be..ee3256dc66 100644 --- a/launchers/qt/src/main.cpp +++ b/launchers/qt/src/main.cpp @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) { QString name { "High Fidelity" }; QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setOrganizationName(name); - QCoreApplication::setApplicationName("HQ Launcher"); + QCoreApplication::setApplicationName("Launcher"); Q_INIT_RESOURCE(resources); cleanLogFile(); qInstallMessageHandler(messageHandler); @@ -51,11 +51,11 @@ int main(int argc, char *argv[]) { options->parse(argc, argv); #ifdef Q_OS_WIN LauncherInstaller launcherInstaller(argv[0]); - if (options->contains("--restart") || launcherInstaller.runningOutsideOfInstallDir()) { - launcherInstaller.install(); - } else if (options->contains("--uninstall")) { + if (options->contains("--uninstall") || options->contains("--resumeUninstall")) { launcherInstaller.uninstall(); return 0; + } else if (options->contains("--restart") || launcherInstaller.runningOutsideOfInstallDir()) { + launcherInstaller.install(); } int interfacePID = -1; @@ -64,9 +64,6 @@ int main(int argc, char *argv[]) { } #endif - Launcher launcher(argc, argv); - return launcher.exec(); - }