Merge pull request #15879 from luiscuenca/WLcloseInterface

BUGZ-845: Shut down interface when executing the Windows Launcher
This commit is contained in:
Shannon Romano 2019-07-03 18:06:01 -07:00 committed by GitHub
commit a87072a23d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 12 deletions

View file

@ -32,6 +32,11 @@ CLauncherApp theApp;
// CLauncherApp initialization // CLauncherApp initialization
BOOL CLauncherApp::InitInstance() { BOOL CLauncherApp::InitInstance() {
// Close interface if is running
int interfacePID = -1;
if (LauncherUtils::IsProcessRunning(L"interface.exe", interfacePID)) {
LauncherUtils::shutdownProcess(interfacePID, 0);
}
int iNumOfArgs; int iNumOfArgs;
LPWSTR* pArgs = CommandLineToArgvW(GetCommandLine(), &iNumOfArgs); LPWSTR* pArgs = CommandLineToArgvW(GetCommandLine(), &iNumOfArgs);
bool isUninstalling = false; bool isUninstalling = false;

View file

@ -629,7 +629,8 @@ void CLauncherDlg::OnTimer(UINT_PTR nIDEvent) {
::SetForegroundWindow(_applicationWND); ::SetForegroundWindow(_applicationWND);
::SetActiveWindow(_applicationWND); ::SetActiveWindow(_applicationWND);
} }
if (LauncherUtils::IsProcessRunning(L"interface.exe")) { int interfacePID = -1;
if (LauncherUtils::IsProcessRunning(L"interface.exe", interfacePID)) {
exit(0); exit(0);
} }
} }
@ -653,7 +654,8 @@ void CLauncherDlg::OnTimer(UINT_PTR nIDEvent) {
} }
_splashStep++; _splashStep++;
} else if (theApp._manager.shouldShutDown()) { } else if (theApp._manager.shouldShutDown()) {
if (LauncherUtils::IsProcessRunning(L"interface.exe")) { int interfacePID = -1;
if (LauncherUtils::IsProcessRunning(L"interface.exe", interfacePID)) {
exit(0); exit(0);
} }
} }

View file

@ -15,13 +15,10 @@
#include "LauncherManager.h" #include "LauncherManager.h"
LauncherManager::LauncherManager() LauncherManager::LauncherManager() {
{
} }
LauncherManager::~LauncherManager() {
LauncherManager::~LauncherManager()
{
} }
void LauncherManager::init() { void LauncherManager::init() {
@ -113,8 +110,11 @@ BOOL LauncherManager::installLauncher() {
// The installer is not running on the desired location and has to be installed // The installer is not running on the desired location and has to be installed
// Kill of running before self-copy // Kill of running before self-copy
addToLog(_T("Installing Launcher.")); addToLog(_T("Installing Launcher."));
if (LauncherUtils::IsProcessRunning(LAUNCHER_EXE_FILENAME)) { int launcherPID = -1;
ShellExecute(NULL, NULL, L"taskkill", L"/F /T /IM " + LAUNCHER_EXE_FILENAME, NULL, SW_HIDE); if (LauncherUtils::IsProcessRunning(LAUNCHER_EXE_FILENAME, launcherPID)) {
if (!LauncherUtils::shutdownProcess(launcherPID, 0)) {
addToLog(_T("Error shutting down the Launcher"));
}
} }
CopyFile(appPath, instalationPath, FALSE); CopyFile(appPath, instalationPath, FALSE);
} }
@ -308,7 +308,8 @@ LauncherUtils::ResponseError LauncherManager::readConfigJSON(CString& version, C
} }
Json::Value config; Json::Value config;
configFile >> config; configFile >> config;
if (config["version"].isString() && config["domain"].isString() && if (config["version"].isString() &&
config["domain"].isString() &&
config["content"].isString()) { config["content"].isString()) {
loggedIn = config["loggedIn"].asBool(); loggedIn = config["loggedIn"].asBool();
version = config["version"].asCString(); version = config["version"].asCString();

View file

@ -37,7 +37,19 @@ CString LauncherUtils::urlEncodeString(const CString& url) {
return stringOut; return stringOut;
} }
BOOL LauncherUtils::IsProcessRunning(const wchar_t *processName) { BOOL LauncherUtils::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;
}
BOOL LauncherUtils::IsProcessRunning(const wchar_t *processName, int& processID) {
bool exists = false; bool exists = false;
PROCESSENTRY32 entry; PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32); entry.dwSize = sizeof(PROCESSENTRY32);
@ -48,6 +60,7 @@ BOOL LauncherUtils::IsProcessRunning(const wchar_t *processName) {
while (Process32Next(snapshot, &entry)) { while (Process32Next(snapshot, &entry)) {
if (!_wcsicmp(entry.szExeFile, processName)) { if (!_wcsicmp(entry.szExeFile, processName)) {
exists = true; exists = true;
processID = entry.th32ProcessID;
break; break;
} }
} }

View file

@ -73,7 +73,8 @@ public:
static std::string cStringToStd(CString cstring); static std::string cStringToStd(CString cstring);
static BOOL getFont(const CString& fontName, int fontSize, bool isBold, CFont& fontOut); static BOOL getFont(const CString& fontName, int fontSize, bool isBold, CFont& fontOut);
static BOOL launchApplication(LPCWSTR lpApplicationName, LPTSTR cmdArgs = _T("")); static BOOL launchApplication(LPCWSTR lpApplicationName, LPTSTR cmdArgs = _T(""));
static BOOL IsProcessRunning(const wchar_t *processName); static BOOL IsProcessRunning(const wchar_t *processName, int& processID);
static BOOL shutdownProcess(DWORD dwProcessId, UINT uExitCode);
static BOOL insertRegistryKey(const std::string& regPath, const std::string& name, const std::string& value); static BOOL insertRegistryKey(const std::string& regPath, const std::string& name, const std::string& value);
static BOOL insertRegistryKey(const std::string& regPath, const std::string& name, DWORD value); static BOOL insertRegistryKey(const std::string& regPath, const std::string& name, DWORD value);
static BOOL deleteFileOrDirectory(const CString& dirPath, bool noRecycleBin = true); static BOOL deleteFileOrDirectory(const CString& dirPath, bool noRecycleBin = true);