From 97f71205b9846fc1a429facbea57e479992693f5 Mon Sep 17 00:00:00 2001 From: HipsterSloth Date: Thu, 28 Dec 2017 20:31:51 -0800 Subject: [PATCH 1/5] Adding PSMoveServiceAdmin.exe in windows builds --- src/psmoveservice/CMakeLists.txt | 38 +++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/psmoveservice/CMakeLists.txt b/src/psmoveservice/CMakeLists.txt index 0fcd4ba6..205828d0 100644 --- a/src/psmoveservice/CMakeLists.txt +++ b/src/psmoveservice/CMakeLists.txt @@ -207,11 +207,6 @@ add_executable(PSMoveService ${PSMOVESERVICE_SRC}) target_include_directories(PSMoveService PUBLIC ${PSMOVE_SERVICE_INCL_DIRS}) target_link_libraries(PSMoveService ${PSMOVE_SERVICE_REQ_LIBS}) -IF(MSVC) - # set the UAC level in the property sheet - set_target_properties(PSMoveService PROPERTIES LINK_FLAGS "/level='requireAdministrator' /uiAccess='false'") -ENDIF() - IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") add_dependencies(PSMoveService opencv) ENDIF() @@ -241,6 +236,39 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") ELSE() #Linux/Darwin ENDIF() +# On Windows builds we want to create an additional admin version of PSMS. +# This is used for when we want to pair new controllers. +# Part of the pairing process in Windows requires manually poking entries in the +# "SYSTEM\CurrentControlSet\Services\HidBth\Parameters\Devices" registry key folder, +# which only an admin account can do. +# Since you can't change the permissions of an exe after it's started +# and since relaunching a process as admin is un-reliable, having a second +# admin version of the PSMS exe is the simplest option +# https://stackoverflow.com/questions/19617955/c-run-program-as-administrator +# https://blogs.msdn.microsoft.com/winsdk/2013/03/22/how-to-launch-a-process-as-a-full-administrator-when-uac-is-enabled/ +IF(MSVC) + # Create the new PSMS admin exe (same code as PSMS) + add_executable(PSMoveServiceAdmin ${PSMOVESERVICE_SRC}) + target_include_directories(PSMoveServiceAdmin PUBLIC ${PSMOVE_SERVICE_INCL_DIRS}) + target_link_libraries(PSMoveServiceAdmin ${PSMOVE_SERVICE_REQ_LIBS}) + + add_dependencies(PSMoveServiceAdmin opencv) + + # set the UAC level in the property sheet + set_target_properties(PSMoveServiceAdmin PROPERTIES LINK_FLAGS "/level='requireAdministrator' /uiAccess='false'") + + install(TARGETS PSMoveServiceAdmin + CONFIGURATIONS Debug + RUNTIME DESTINATION ${PSM_DEBUG_INSTALL_PATH}/bin + LIBRARY DESTINATION ${PSM_DEBUG_INSTALL_PATH}/lib + ARCHIVE DESTINATION ${PSM_DEBUG_INSTALL_PATH}/lib) + install(TARGETS PSMoveServiceAdmin + CONFIGURATIONS Release + RUNTIME DESTINATION ${PSM_RELEASE_INSTALL_PATH}/bin + LIBRARY DESTINATION ${PSM_RELEASE_INSTALL_PATH}/lib + ARCHIVE DESTINATION ${PSM_RELEASE_INSTALL_PATH}/lib) +ENDIF() + IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows") IF(NOT(${CMAKE_C_SIZEOF_DATA_PTR} EQUAL 8)) IF(${CL_EYE_SDK_PATH} STREQUAL "CL_EYE_SDK_PATH-NOTFOUND") From 79aabdb93263b7755504edfbca262795edbd4936 Mon Sep 17 00:00:00 2001 From: HipsterSloth Date: Sun, 31 Dec 2017 22:37:33 -0800 Subject: [PATCH 2/5] Integrating gb2111's change e3ec72420ce70d8237488a2756e87c60226b6015 Add button to restart service in admin mode when the users wants to pair or unpair a controller --- .../AppStage_ControllerSettings.cpp | 169 +++++++++++++++++- 1 file changed, 161 insertions(+), 8 deletions(-) diff --git a/src/psmoveconfigtool/AppStage_ControllerSettings.cpp b/src/psmoveconfigtool/AppStage_ControllerSettings.cpp index cfbac874..aabab7ae 100644 --- a/src/psmoveconfigtool/AppStage_ControllerSettings.cpp +++ b/src/psmoveconfigtool/AppStage_ControllerSettings.cpp @@ -22,11 +22,146 @@ #include #include +#ifdef _WIN32 +#include // Required for data types +#include +#include +#include +#include +#include +#include // Device setup APIs +#include +#include +#include +#include +#include +#include +#endif // _WIN32 + #ifdef _MSC_VER #pragma warning (disable: 4996) // 'This function or variable may be unsafe': snprintf #define snprintf _snprintf #endif +#ifdef _WIN32 +class Win32AdminCheck { + +public: + BOOL psMoveServiceFound = FALSE; + BOOL psMoveServiceAdminFound = FALSE; + BOOL psMoveServiceElevated = FALSE; + BOOL psMoveServiceAdminElevated = FALSE; + DWORD psMoveServiceId = 0; + DWORD psMoveServiceAdminEId = 0; + + BOOL IsElevated(HANDLE hProcess) { + BOOL fRet = FALSE; + HANDLE hToken = NULL; + if (OpenProcessToken(hProcess, TOKEN_QUERY, &hToken)) { + TOKEN_ELEVATION Elevation; + DWORD cbSize = sizeof(TOKEN_ELEVATION); + if (GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize)) { + fRet = Elevation.TokenIsElevated; + } + } + if (hToken) { + CloseHandle(hToken); + } + return fRet; + } + + void CheckProcesses() { + + psMoveServiceFound = FALSE; + psMoveServiceAdminFound = FALSE; + psMoveServiceElevated = FALSE; + psMoveServiceAdminElevated = FALSE; + psMoveServiceId = 0; + psMoveServiceAdminEId = 0; + + + PROCESSENTRY32 entry; + entry.dwSize = sizeof(PROCESSENTRY32); + + HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); + + if (Process32First(snapshot, &entry) == TRUE) + { + while (Process32Next(snapshot, &entry) == TRUE) + { + if (stricmp(entry.szExeFile, "PSMoveService.exe") == 0) + { + psMoveServiceId = entry.th32ProcessID; + HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, entry.th32ProcessID); + + psMoveServiceFound = TRUE; + psMoveServiceElevated = IsElevated(hProcess); + + CloseHandle(hProcess); + } + + if (stricmp(entry.szExeFile, "PSMoveServiceAdmin.exe") == 0) + { + psMoveServiceAdminEId = entry.th32ProcessID; + HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, entry.th32ProcessID); + + psMoveServiceAdminFound = TRUE; + psMoveServiceAdminElevated = IsElevated(hProcess); + + CloseHandle(hProcess); + } + + } + } + + CloseHandle(snapshot); + } + + void RestartAdminMode() { + if (psMoveServiceId != 0 && !psMoveServiceElevated) + { + char moduleFileName[MAXCHAR]; + HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, psMoveServiceId); + if (hProcess != NULL) { + + GetModuleFileNameEx(hProcess, NULL, moduleFileName, MAXCHAR); + + TerminateProcess(hProcess, 0); + CloseHandle(hProcess); + + char drive[5]; + char dir[MAXCHAR]; + _splitpath_s(moduleFileName, drive, sizeof(drive), dir, sizeof(dir), NULL, 0, NULL, 0); + + std::string adminDir = drive; + adminDir = adminDir + dir; + std::string adminPath = adminDir + "PSMoveServiceAdmin.exe"; + + SHELLEXECUTEINFO ShExecInfo; + ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); + ShExecInfo.fMask = NULL; + ShExecInfo.hwnd = NULL; + ShExecInfo.lpVerb = NULL; + ShExecInfo.lpFile = adminPath.c_str(); + ShExecInfo.lpParameters = NULL; + ShExecInfo.lpDirectory = NULL; + ShExecInfo.nShow = SW_NORMAL; + ShExecInfo.hInstApp = NULL; + + BOOL create = ShellExecuteEx(&ShExecInfo); + } + } + } + + BOOL IsAnyElevated() { + return psMoveServiceElevated || psMoveServiceAdminElevated; + } + +}; + +Win32AdminCheck adminCheck; +#endif + //-- statics ---- const char *AppStage_ControllerSettings::APP_STAGE_NAME= "ControllerSettings"; const char *AppStage_ControllerSettings::GAMEPAD_COMBO_LABELS[MAX_GAMEPAD_LABELS] = { @@ -88,6 +223,10 @@ AppStage_ControllerSettings::AppStage_ControllerSettings(App *app) void AppStage_ControllerSettings::enter() { +#ifdef _WIN32 + adminCheck.CheckProcesses(); +#endif + m_app->setCameraType(_cameraFixed); request_controller_list(); @@ -324,22 +463,36 @@ void AppStage_ControllerSettings::renderUI() if (controllerInfo.ControllerType == PSMController_Move) { - if (controllerInfo.IsBluetooth) +#ifdef _WIN32 + if (adminCheck.IsAnyElevated()) { - if (ImGui::Button("Unpair Controller")) +#endif + if (controllerInfo.IsBluetooth) { - m_app->getAppStage()->request_controller_unpair(controllerInfo.ControllerID, controllerInfo.ControllerType); - m_app->setAppStage(AppStage_PairController::APP_STAGE_NAME); + if (ImGui::Button("Unpair Controller")) + { + m_app->getAppStage()->request_controller_unpair(controllerInfo.ControllerID, controllerInfo.ControllerType); + m_app->setAppStage(AppStage_PairController::APP_STAGE_NAME); + } + } + else + { + if (ImGui::Button("Pair Controller")) + { + m_app->getAppStage()->request_controller_pair(controllerInfo.ControllerID, controllerInfo.ControllerType); + m_app->setAppStage(AppStage_PairController::APP_STAGE_NAME); + } } +#ifdef _WIN32 } - else + else { - if (ImGui::Button("Pair Controller")) + if (ImGui::Button("Restart Service in Admin mode\nto Pair or Unpair Controller")) { - m_app->getAppStage()->request_controller_pair(controllerInfo.ControllerID, controllerInfo.ControllerType); - m_app->setAppStage(AppStage_PairController::APP_STAGE_NAME); + adminCheck.RestartAdminMode(); } } +#endif } if (!m_app->excludePositionSettings && From 38dda0e7b08031fc383743d79e31ff9375b4fd0e Mon Sep 17 00:00:00 2001 From: HipsterSloth Date: Sun, 31 Dec 2017 22:38:14 -0800 Subject: [PATCH 3/5] Fixing bug in AppStage_MainMenu.cpp that displayed the wrong message when disconnected from service --- src/psmoveconfigtool/AppStage_MainMenu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/psmoveconfigtool/AppStage_MainMenu.cpp b/src/psmoveconfigtool/AppStage_MainMenu.cpp index b5289af4..7419445f 100644 --- a/src/psmoveconfigtool/AppStage_MainMenu.cpp +++ b/src/psmoveconfigtool/AppStage_MainMenu.cpp @@ -188,7 +188,7 @@ bool AppStage_MainMenu::onClientAPIEvent( case PSMEventMessage::PSMEvent_disconnectedFromService: { // Tell the user that we failed to connect - m_menuState= AppStage_MainMenu::failedConnectionToService; + m_menuState= AppStage_MainMenu::disconnectedFromService; // If we weren't running this stage, make sure we are now if (m_app->getCurrentAppStage() != this) From 467e6aefbaed0866637332d7898f777ee82fc7c1 Mon Sep 17 00:00:00 2001 From: HipsterSloth Date: Sun, 31 Dec 2017 22:38:50 -0800 Subject: [PATCH 4/5] Add the dist folder to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4e7dc4ea..8eb10b6b 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ # Build directories build* bin* +dist* # Auto-downloaded Dependencies deps From c66e588ab8ccaf65ccbed5d21da069c1b90b4b71 Mon Sep 17 00:00:00 2001 From: HipsterSloth Date: Sun, 31 Dec 2017 22:40:10 -0800 Subject: [PATCH 5/5] Bumping release version to 0.9-alpha 8.10.0 --- src/psmoveprotocol/ProtocolVersion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/psmoveprotocol/ProtocolVersion.h b/src/psmoveprotocol/ProtocolVersion.h index fbae14d0..8de0c181 100644 --- a/src/psmoveprotocol/ProtocolVersion.h +++ b/src/psmoveprotocol/ProtocolVersion.h @@ -13,7 +13,7 @@ #define PSM_RELEASE_VERSION_MAJOR 9 #define PSM_RELEASE_VERSION_PHASE alpha #define PSM_RELEASE_VERSION_MINOR 8 -#define PSM_RELEASE_VERSION_RELEASE 9 +#define PSM_RELEASE_VERSION_RELEASE 10 #define PSM_RELEASE_VERSION_HOTFIX 0 /// "Product.Major-Phase Minor.Release.Hotfix"