diff --git a/cmake/macros/AutoScribeShader.cmake b/cmake/macros/AutoScribeShader.cmake index 9a18005424..f5a497962c 100755 --- a/cmake/macros/AutoScribeShader.cmake +++ b/cmake/macros/AutoScribeShader.cmake @@ -147,7 +147,12 @@ macro(AUTOSCRIBE_SHADER) MATH(EXPR SHADER_COUNT "${SHADER_COUNT}+1") endmacro() +# This function takes in the list of defines, which would look like: +# (normalmap;translucent:f)/shadow;deformed:v +# and handles parentheses and slashes, producing the semicolon-separated final list of all combinations, which in that case will look like: +# normalmap;translucent:f;normalmap_translucent:f;shadow;normalmap_deformed:v;translucent:f_deformed:v;normalmap_translucent:f_deformed:v;shadow_deformed:v function(GENERATE_DEFINES_LIST_HELPER INPUT_LIST RETURN_LIST) + # This while loop handles parentheses, looking for matching ( and ) and then calling GENERATE_DEFINES_LIST_HELPER recursively on the text in between string(LENGTH "${INPUT_LIST}" STR_LENGTH) set(OPEN_INDEX -1) set(STR_INDEX 0) @@ -183,6 +188,7 @@ function(GENERATE_DEFINES_LIST_HELPER INPUT_LIST RETURN_LIST) MATH(EXPR STR_INDEX "${STR_INDEX}+1") endwhile() + # Here we handle the base case, the recursive case, and slashes list(LENGTH INPUT_LIST NUM_DEFINES) if (NUM_DEFINES EQUAL 1) string(REPLACE "/" ";" INPUT_LIST "${INPUT_LIST}") @@ -301,6 +307,9 @@ macro(AUTOSCRIBE_SHADER_LIB) foreach(DEFINES ${DEFINES_LIST}) set(ORIG_DEFINES "${DEFINES}") + # Below here we handle :v and :f. The program name includes both, but the vertex and fragment names + # remove the elements with :f and :v respectively, and only have to call AUTOSCRIBE_SHADER if they don't have those + # (because the shaders without them will have already been generated) string(REPLACE ":v" "" VERTEX_DEFINES "${ORIG_DEFINES}") string(FIND "${ORIG_DEFINES}" ":f" HAS_FRAGMENT) if (HAS_FRAGMENT EQUAL -1) diff --git a/launchers/win32/LauncherApp.cpp b/launchers/win32/LauncherApp.cpp index 244d618fcb..a432a0b116 100644 --- a/launchers/win32/LauncherApp.cpp +++ b/launchers/win32/LauncherApp.cpp @@ -32,6 +32,11 @@ CLauncherApp theApp; // CLauncherApp initialization BOOL CLauncherApp::InitInstance() { + // Close interface if is running + int interfacePID = -1; + if (LauncherUtils::IsProcessRunning(L"interface.exe", interfacePID)) { + LauncherUtils::shutdownProcess(interfacePID, 0); + } int iNumOfArgs; LPWSTR* pArgs = CommandLineToArgvW(GetCommandLine(), &iNumOfArgs); bool isUninstalling = false; diff --git a/launchers/win32/LauncherDlg.cpp b/launchers/win32/LauncherDlg.cpp index 6016424563..83af659208 100644 --- a/launchers/win32/LauncherDlg.cpp +++ b/launchers/win32/LauncherDlg.cpp @@ -629,7 +629,8 @@ void CLauncherDlg::OnTimer(UINT_PTR nIDEvent) { ::SetForegroundWindow(_applicationWND); ::SetActiveWindow(_applicationWND); } - if (LauncherUtils::IsProcessRunning(L"interface.exe")) { + int interfacePID = -1; + if (LauncherUtils::IsProcessRunning(L"interface.exe", interfacePID)) { exit(0); } } @@ -653,7 +654,8 @@ void CLauncherDlg::OnTimer(UINT_PTR nIDEvent) { } _splashStep++; } else if (theApp._manager.shouldShutDown()) { - if (LauncherUtils::IsProcessRunning(L"interface.exe")) { + int interfacePID = -1; + if (LauncherUtils::IsProcessRunning(L"interface.exe", interfacePID)) { exit(0); } } diff --git a/launchers/win32/LauncherManager.cpp b/launchers/win32/LauncherManager.cpp index 2916f614cb..619ebe9c42 100644 --- a/launchers/win32/LauncherManager.cpp +++ b/launchers/win32/LauncherManager.cpp @@ -15,13 +15,10 @@ #include "LauncherManager.h" -LauncherManager::LauncherManager() -{ +LauncherManager::LauncherManager() { } - -LauncherManager::~LauncherManager() -{ +LauncherManager::~LauncherManager() { } void LauncherManager::init() { @@ -113,8 +110,11 @@ BOOL LauncherManager::installLauncher() { // The installer is not running on the desired location and has to be installed // Kill of running before self-copy addToLog(_T("Installing Launcher.")); - if (LauncherUtils::IsProcessRunning(LAUNCHER_EXE_FILENAME)) { - ShellExecute(NULL, NULL, L"taskkill", L"/F /T /IM " + LAUNCHER_EXE_FILENAME, NULL, SW_HIDE); + int launcherPID = -1; + if (LauncherUtils::IsProcessRunning(LAUNCHER_EXE_FILENAME, launcherPID)) { + if (!LauncherUtils::shutdownProcess(launcherPID, 0)) { + addToLog(_T("Error shutting down the Launcher")); + } } CopyFile(appPath, instalationPath, FALSE); } @@ -308,7 +308,8 @@ LauncherUtils::ResponseError LauncherManager::readConfigJSON(CString& version, C } Json::Value config; configFile >> config; - if (config["version"].isString() && config["domain"].isString() && + if (config["version"].isString() && + config["domain"].isString() && config["content"].isString()) { loggedIn = config["loggedIn"].asBool(); version = config["version"].asCString(); diff --git a/launchers/win32/LauncherUtils.cpp b/launchers/win32/LauncherUtils.cpp index 9365dd52a1..39964cc457 100644 --- a/launchers/win32/LauncherUtils.cpp +++ b/launchers/win32/LauncherUtils.cpp @@ -37,7 +37,19 @@ CString LauncherUtils::urlEncodeString(const CString& url) { 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; PROCESSENTRY32 entry; entry.dwSize = sizeof(PROCESSENTRY32); @@ -48,6 +60,7 @@ BOOL LauncherUtils::IsProcessRunning(const wchar_t *processName) { while (Process32Next(snapshot, &entry)) { if (!_wcsicmp(entry.szExeFile, processName)) { exists = true; + processID = entry.th32ProcessID; break; } } diff --git a/launchers/win32/LauncherUtils.h b/launchers/win32/LauncherUtils.h index a6f124e18d..f5ce04b386 100644 --- a/launchers/win32/LauncherUtils.h +++ b/launchers/win32/LauncherUtils.h @@ -73,7 +73,8 @@ public: static std::string cStringToStd(CString cstring); static BOOL getFont(const CString& fontName, int fontSize, bool isBold, CFont& fontOut); 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, DWORD value); static BOOL deleteFileOrDirectory(const CString& dirPath, bool noRecycleBin = true);