platform/wm/tools/detool/detool.cpp in rhodes-3.3.2.beta.1 vs platform/wm/tools/detool/detool.cpp in rhodes-3.3.2.beta.2

- old
+ new

@@ -396,12 +396,13 @@ return false; } bool wceRunProcess(const char *process, const char *args) { - HRESULT hRapiResult; +#ifndef UNICODE HRESULT hr; +#endif PROCESS_INFORMATION pi; WCHAR wszProgram[MAX_PATH]; WCHAR wszArgs[MAX_PATH]; #ifdef UNICODE @@ -692,10 +693,79 @@ } WSACleanup(); } +void simulateKeyInput (int vk, BOOL bExtended, BOOL doDown, BOOL doUp) +{ + KEYBDINPUT kb = {0}; + INPUT Input = {0}; + if (doDown) { + // generate down + if (bExtended) + kb.dwFlags = KEYEVENTF_EXTENDEDKEY; + kb.wVk = vk; + Input.type = INPUT_KEYBOARD; + Input.ki = kb; + ::SendInput(1,&Input,sizeof(Input)); + } + if (doUp) { + // generate up + ::ZeroMemory(&kb,sizeof(KEYBDINPUT)); + ::ZeroMemory(&Input,sizeof(INPUT)); + kb.dwFlags = KEYEVENTF_KEYUP; + if (bExtended) + kb.dwFlags |= KEYEVENTF_EXTENDEDKEY; + kb.wVk = vk; + Input.type = INPUT_KEYBOARD; + Input.ki = kb; + ::SendInput(1,&Input,sizeof(Input)); + } +} + +bool doUseWMDC() { + OSVERSIONINFOW os_version; + ZeroMemory(&os_version, sizeof(OSVERSIONINFO)); + os_version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + ::GetVersionEx(&os_version); + return (os_version.dwMajorVersion >= 6); +} + +HWND findWMDCWindow() { + return FindWindow(NULL, L"Windows Mobile Device Center"); +} + +void startWMDC() { + if (doUseWMDC()) { + if (findWMDCWindow() == 0) { + _tprintf( TEXT("WMDC is not running. Starting WMDC...\n") ); + ::system("start %WINDIR%\\WindowsMobile\\wmdc.exe /show"); + ::Sleep(5000); + } + } +} + +void connectWMDC() { + if (doUseWMDC()) { + HWND hwnd = findWMDCWindow(); + if (hwnd == 0) { + _tprintf( TEXT("Cannot find WMDC window to establish network connection to device emulator.\n") ); + } else { + ::SetForegroundWindow(hwnd); + ::SetFocus(hwnd); + ::LockSetForegroundWindow(LSFW_LOCK); + ::Sleep(100); + simulateKeyInput(VK_MENU, TRUE, TRUE, FALSE); + ::Sleep(20); + simulateKeyInput('C', FALSE, TRUE, TRUE); + ::Sleep(20); + simulateKeyInput(VK_MENU, TRUE, FALSE, TRUE); + ::LockSetForegroundWindow(LSFW_UNLOCK); + } + } +} + int _tmain(int argc, _TCHAR* argv[]) { TCHAR *emu_name = NULL; TCHAR *cab_file = NULL; TCHAR *bundle_path = NULL; @@ -794,10 +864,12 @@ if (!wceConnect ()) { printf ("Failed to connect to remote device.\n"); goto stop_emu_deploy; } else { + // start Windows Mobile Device Center for network connectivity of the device emulator (if applicable) + startWMDC(); hFind = CeFindFirstFile(app_dir, &findData); if (INVALID_HANDLE_VALUE == hFind) { _tprintf( TEXT("Application directory on device was no found\n")); @@ -844,10 +916,13 @@ if (copyBundle(bundle_path, _T("/"), remote_bundle_path) == EXIT_FAILURE) { printf ("Failed to copy bundle\n"); goto stop_emu_deploy; } + // establish network connectivity of the device emulator from Windows Mobile Device Center (if applicable) + connectWMDC(); + emuBringToFront(emu_name); _tprintf( TEXT("Starting application...")); _tcscpy(params_buf, TEXT("\\Program Files\\")); _tcscat(params_buf, app_name); @@ -891,10 +966,13 @@ _tprintf( TEXT("FAILED\n")); goto stop_emu_deploy; } _tprintf( TEXT("DONE\n")); + // start Windows Mobile Device Center for network connectivity of the device emulator (if applicable) + startWMDC(); + _tprintf( TEXT("Loading cab file...")); if (!wcePutFile (T2A(cab_file), "")) { _tprintf( TEXT("FAILED\n")); goto stop_emu_deploy; } @@ -904,11 +982,11 @@ if (!wcePutFile (RHOSETUP_DLL, "")) { _tprintf( TEXT("FAILED\n")); goto stop_emu_deploy; } _tprintf( TEXT("DONE\n")); - + _tprintf( TEXT("Setup application...")); //FIXME: rake gives pathname with unix-like '/' file separators, //so if we want to use this tool outside of rake, we should remember this //or check and convert cab_file @@ -921,10 +999,13 @@ _tprintf( TEXT("FAILED\n")); goto stop_emu_deploy; } _tprintf( TEXT("DONE\n")); + // establish network connectivity of the device emulator from Windows Mobile Device Center (if applicable) + connectWMDC(); + emuBringToFront(emu_name); _tprintf( TEXT("Starting application...")); _tcscpy(params_buf, TEXT("\\Program Files\\")); _tcscat(params_buf, app_name); @@ -932,11 +1013,11 @@ _tcscat(params_buf, app_name); _tcscat(params_buf, _T(".exe")); TCHAR params[128]; _tcscpy(params, _T("-log=")); - _tcscpy(params, log_port); + _tcscat(params, log_port); if(!wceRunProcess(T2A(params_buf), T2A(params))) { _tprintf( TEXT("FAILED\n")); goto stop_emu_deploy; } @@ -1025,11 +1106,11 @@ _tcscat(params_buf, _T(".exe")); _tprintf( TEXT("%s\n"), params_buf); TCHAR params[128]; _tcscpy(params, _T("-log=")); - _tcscpy(params, log_port); + _tcscat(params, log_port); if(!wceRunProcess(T2A(params_buf), T2A(params))) { _tprintf( TEXT("FAILED\n")); goto stop_emu_deploy; } @@ -1098,11 +1179,11 @@ _tcscat(params_buf, app_name); _tcscat(params_buf, _T(".exe")); TCHAR params[128]; _tcscpy(params, _T("-log=")); - _tcscpy(params, log_port); + _tcscat(params, log_port); if(!wceRunProcess (T2A(params_buf), T2A(params))) { _tprintf( TEXT("FAILED\n")); goto stop_emu_deploy; } @@ -1159,11 +1240,11 @@ _tprintf( TEXT("DONE\n")); } if (deploy_type == DEPLOY_EMU_WEBKIT) { - HANDLE hFind; - CE_FIND_DATA findData; + //HANDLE hFind; + //CE_FIND_DATA findData; _tprintf( TEXT("Searching for Windows CE device...")); if (SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) {