diff --git a/launchers/qt/src/Helper.h b/launchers/qt/src/Helper.h index 8c685acc7c..a41b55b233 100644 --- a/launchers/qt/src/Helper.h +++ b/launchers/qt/src/Helper.h @@ -32,6 +32,9 @@ HRESULT createSymbolicLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszD bool insertRegistryKey(const std::string& regPath, const std::string& name, const std::string& value); bool insertRegistryKey(const std::string& regPath, const std::string& name, DWORD value); bool deleteRegistryKey(const std::string& regPath); + +BOOL isProcessRunning(const char* processName, int& processID); +BOOL shutdownProcess(DWORD dwProcessId, UINT uExitCode); #endif QString getHTTPUserAgent(); diff --git a/launchers/qt/src/Helper_windows.cpp b/launchers/qt/src/Helper_windows.cpp index 84673e85b2..fda6a455f0 100644 --- a/launchers/qt/src/Helper_windows.cpp +++ b/launchers/qt/src/Helper_windows.cpp @@ -18,7 +18,8 @@ void launchClient(const QString& clientPath, const QString& homePath, const QStr + " --setBookmark \"hqhome=" + homePath + "\"" + " --defaultScriptsOverride \"file:///" + defaultScriptsPath + "\"" + " --displayName \"" + displayName + "\"" - + " --cache \"" + contentCachePath + "\""; + + " --cache \"" + contentCachePath + "\"" + + " --suppress-settings-reset --no-launcher --no-updater"; if (!loginResponseToken.isEmpty()) { params += " --tokens \"" + loginResponseToken.replace("\"", "\\\"") + "\""; @@ -147,3 +148,36 @@ bool deleteRegistryKey(const std::string& regPath) { } return false; } + + +BOOL isProcessRunning(const char* processName, int& processID) { + bool exists = false; + PROCESSENTRY32 entry; + entry.dwSize = sizeof(PROCESSENTRY32); + + HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); + + if (Process32First(snapshot, &entry)) { + while (Process32Next(snapshot, &entry)) { + if (!_stricmp(entry.szExeFile, processName)) { + exists = true; + processID = entry.th32ProcessID; + break; + } + } + } + CloseHandle(snapshot); + return exists; +} + +BOOL shutdownProcess(DWORD dwProcessId, UINT uExitCode) { + DWORD dwDesiredAccess = PROCESS_TERMINATE; + BOOL bInheritHandle = FALSE; + HANDLE hProcess = OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId); + if (hProcess == NULL) { + return FALSE; + } + BOOL result = TerminateProcess(hProcess, uExitCode); + CloseHandle(hProcess); + return result; +} diff --git a/launchers/qt/src/LauncherState.cpp b/launchers/qt/src/LauncherState.cpp index 7d00acd453..582b416b85 100644 --- a/launchers/qt/src/LauncherState.cpp +++ b/launchers/qt/src/LauncherState.cpp @@ -29,6 +29,7 @@ //#define BREAK_ON_ERROR +const QString configHomeLocationKey { "homeLocation" }; const QString configLoggedInKey{ "loggedIn" }; const QString configLauncherPathKey{ "launcherPath" }; @@ -223,6 +224,9 @@ void LauncherState::getCurrentClientVersion() { if (root.contains(configLoggedInKey)) { _config.loggedIn = root["loggedIn"].toBool(); } + if (root.contains(configHomeLocationKey)) { + _config.homeLocation = root["homeLocation"].toString(); + } } else { qDebug() << "Failed to open config.json"; } @@ -353,15 +357,15 @@ void LauncherState::requestSettings() { connect(request, &UserSettingsRequest::finished, this, [this, request]() { auto userSettings = request->getUserSettings(); if (userSettings.homeLocation.isEmpty()) { - _homeLocation = "hifi://hq"; + _config.homeLocation = "hifi://hq"; _contentCacheURL = ""; } else { - _homeLocation = userSettings.homeLocation; - auto host = QUrl(_homeLocation).host(); + _config.homeLocation = userSettings.homeLocation; + auto host = QUrl(_config.homeLocation).host(); _contentCacheURL = "http://orgs.highfidelity.com/host-content-cache/" + host + ".zip"; } - qDebug() << "Home location is: " << _homeLocation; + qDebug() << "Home location is: " << _config.homeLocation; qDebug() << "Content cache url is: " << _contentCacheURL; downloadClient(); @@ -640,6 +644,7 @@ void LauncherState::launchClient() { if (configFile.open(QIODevice::WriteOnly)) { QJsonDocument doc = QJsonDocument::fromJson(configFile.readAll()); doc.setObject({ + { configHomeLocationKey, _config.homeLocation }, { configLoggedInKey, _config.loggedIn }, { configLauncherPathKey, _config.launcherPath }, }); @@ -655,7 +660,7 @@ void LauncherState::launchClient() { QString contentCachePath = _launcherDirectory.filePath("cache"); - ::launchClient(clientPath, _homeLocation, defaultScriptsPath, _displayName, contentCachePath, _loginTokenResponse); + ::launchClient(clientPath, _config.homeLocation, defaultScriptsPath, _displayName, contentCachePath, _loginTokenResponse); } void LauncherState::setApplicationStateError(QString errorMessage) { diff --git a/launchers/qt/src/LauncherState.h b/launchers/qt/src/LauncherState.h index 4f59eb101b..324a653854 100644 --- a/launchers/qt/src/LauncherState.h +++ b/launchers/qt/src/LauncherState.h @@ -13,8 +13,9 @@ #include "BuildsRequest.h" struct LauncherConfig { - QString launcherPath{ QString::null }; + QString launcherPath{ "" }; bool loggedIn{ false }; + QString homeLocation{ "" }; }; class LauncherState : public QObject { @@ -168,7 +169,6 @@ private: QString _buildTag { QString::null }; QString _contentCacheURL; QString _loginTokenResponse; - QString _homeLocation; QFile _clientZipFile; QFile _launcherZipFile; QFile _contentZipFile; diff --git a/launchers/qt/src/main.cpp b/launchers/qt/src/main.cpp index d1de92b45a..0965a5742f 100644 --- a/launchers/qt/src/main.cpp +++ b/launchers/qt/src/main.cpp @@ -51,6 +51,12 @@ int main(int argc, char *argv[]) { launcherInstaller.uninstall(); return 0; } + + int interfacePID = -1; + if (isProcessRunning("interface.exe", interfacePID)) { + shutdownProcess(interfacePID, 0); + } + #endif QString name { "High Fidelity" }; QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);