update install/uninstall and fix createProcess args

This commit is contained in:
danteruiz 2019-10-08 16:57:14 -07:00
parent 86f1286fac
commit 80f0293881
5 changed files with 85 additions and 13 deletions

View file

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

View file

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

View file

@ -1,4 +1,6 @@
#include "LauncherInstaller_windows.h"
#include "CommandlineOptions.h"
#include "Helper.h"
#include <string>
@ -9,12 +11,12 @@
#include <QStandardPaths>
#include <QFileInfo>
#include <QFile>
#include <QFile>
#include <QDebug>
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";

View file

@ -11,6 +11,7 @@ public:
bool runningOutsideOfInstallDir();
private:
void createShortcuts();
void uninstallOldLauncher();
void createApplicationRegistryKeys();
void deleteShortcuts();
void deleteApplicationRegistryKeys();

View file

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