From: jinhyung.jo Date: Wed, 29 Jul 2015 08:30:43 +0000 (+0900) Subject: emulator: Modified code about java path in WOW64 X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.2~286^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6ba1131714016b47c49e79f361c66cd25d148bc0;p=sdk%2Femulator%2Fqemu.git emulator: Modified code about java path in WOW64 Use more registry keys and the environment variable in oder to find more precise 'Java Home'. Removed redundant code. Change-Id: I9ef2d3e87cd47cb31ee0c4389269cca2708fcc4d Signed-off-by: Jinhyung Jo --- diff --git a/include/qemu-common.h b/include/qemu-common.h index ebdd8bb679..f8622141a8 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -474,11 +474,4 @@ int parse_debug_env(const char *name, int max, int initial); const char *qemu_ether_ntoa(const MACAddr *mac); -#if defined(CONFIG_MARU) && defined(CONFIG_WIN32) -#include "../tizen/src/emulator_common.h" - -int is_wow64(void); -bool get_java_path(char **java_path); -#endif - #endif diff --git a/tizen/src/emulator_common.h b/tizen/src/emulator_common.h index 34142b2df5..4aef16733f 100644 --- a/tizen/src/emulator_common.h +++ b/tizen/src/emulator_common.h @@ -75,6 +75,14 @@ #ifdef CONFIG_WIN32 #define MY_KEY_WOW64_64KEY 0x0100 +#ifdef __cplusplus +extern "C" { +#endif +int is_wow64(void); +bool get_java_path(char **java_path); +#ifdef __cplusplus +} +#endif #else #define JAVA_EXEFILE_PATH "java" #endif diff --git a/tizen/src/ui/menu/contextmenu.cpp b/tizen/src/ui/menu/contextmenu.cpp index 9b1f6e297c..0bc1b29eb0 100644 --- a/tizen/src/ui/menu/contextmenu.cpp +++ b/tizen/src/ui/menu/contextmenu.cpp @@ -575,80 +575,6 @@ void ContextMenu::slotShell() shellOpener->openShell(vmName); } -#ifdef CONFIG_WIN32 -#define JAVA_MAX_COMMAND_LENGTH 1024 -#define MY_KEY_WOW64_64KEY 0x0100 - -typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); -LPFN_ISWOW64PROCESS menu_fnIsWow64Process; - -static int menu_is_wow64(void) -{ - int result = 0; - - /* IsWow64Process is not available on all supported versions of Windows. - Use GetModuleHandle to get a handle to the DLL that contains the function - and GetProcAddress to get a pointer to the function if available. */ - - menu_fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress( - GetModuleHandle(TEXT("kernel32")),"IsWow64Process"); - - if (NULL != menu_fnIsWow64Process) { - if (!menu_fnIsWow64Process(GetCurrentProcess(),&result)) { - // handle error - //fprintf(stderr, "Cannot find 'IsWow64Process'\n"); - } - } - return result; -} - -static bool menu_get_java_path(char** java_path) -{ - HKEY hKeyNew; - HKEY hKey; - //char strJavaRuntimePath[JAVA_MAX_COMMAND_LENGTH] = {0}; - char strChoosenName[JAVA_MAX_COMMAND_LENGTH] = {0}; - char strSubKeyName[JAVA_MAX_COMMAND_LENGTH] = {0}; - char strJavaHome[JAVA_MAX_COMMAND_LENGTH] = {0}; - int index; - DWORD dwSubKeyNameMax = JAVA_MAX_COMMAND_LENGTH; - DWORD dwBufLen = JAVA_MAX_COMMAND_LENGTH; - - RegOpenKeyEx(HKEY_LOCAL_MACHINE, - "SOFTWARE\\JavaSoft\\Java Runtime Environment", - 0, - KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | MY_KEY_WOW64_64KEY, - &hKey); - RegEnumKeyEx(hKey, 0, (LPSTR)strSubKeyName, &dwSubKeyNameMax, - NULL, NULL, NULL, NULL); - strcpy(strChoosenName, strSubKeyName); - - index = 1; - while (ERROR_SUCCESS == - RegEnumKeyEx(hKey, index, (LPSTR)strSubKeyName, &dwSubKeyNameMax, - NULL, NULL, NULL, NULL)) { - if (strcmp(strChoosenName, strSubKeyName) < 0) { - strcpy(strChoosenName, strSubKeyName); - } - index++; - } - - RegOpenKeyEx(hKey, strChoosenName, 0, - KEY_QUERY_VALUE | MY_KEY_WOW64_64KEY, &hKeyNew); - RegQueryValueEx(hKeyNew, "JavaHome", NULL, - NULL, (LPBYTE)strJavaHome, &dwBufLen); - RegCloseKey(hKey); - - if (strJavaHome[0] != '\0') { - sprintf(*java_path, "%s\\bin\\javaw.exe", strJavaHome); - } else { - return false; - } - - return true; -} -#endif - void ContextMenu::slotControlPanel() { qDebug("Control Panel"); @@ -677,10 +603,10 @@ void ContextMenu::slotControlPanel() char* path = (char*)malloc(JAVA_MAX_COMMAND_LENGTH); memset(path, 0, sizeof(char) * JAVA_MAX_COMMAND_LENGTH); - if (menu_is_wow64()) { + if (is_wow64()) { arguments << "-d64"; - if (menu_get_java_path(&path)) { + if (get_java_path(&path)) { command = QString::fromLocal8Bit(path); } else { showMsgBox(QMessageBox::Warning, FAILED_TO_GET_JAVA_PATH); diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 2df5de4bd2..9149fa64e0 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -41,69 +41,108 @@ #include #ifdef CONFIG_MARU +#include "tizen/src/emulator_common.h" + typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); -LPFN_ISWOW64PROCESS fnIsWow64Process; int is_wow64(void) { int result = 0; + LPFN_ISWOW64PROCESS fnIsWow64Process; /* IsWow64Process is not available on all supported versions of Windows. Use GetModuleHandle to get a handle to the DLL that contains the function and GetProcAddress to get a pointer to the function if available. */ - fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress( - GetModuleHandle(TEXT("kernel32")),"IsWow64Process"); + fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress( + GetModuleHandle(TEXT("kernel32")), "IsWow64Process"); if (NULL != fnIsWow64Process) { - if (!fnIsWow64Process(GetCurrentProcess(),&result)) { - // handle error - fprintf(stderr, "Cannot find 'IsWow64Process'\n"); + if (!fnIsWow64Process(GetCurrentProcess(), &result)) { + /* No need to handle error, + just check whether is this WoW64 process */ } } return result; } -bool get_java_path(char** java_path) +static char wow64_java_path[JAVA_MAX_COMMAND_LENGTH]; +bool get_java_path(char **java_path) { - HKEY hKeyNew; - HKEY hKey; - //char strJavaRuntimePath[JAVA_MAX_COMMAND_LENGTH] = {0}; + int index; + LONG res; + HKEY hKey, hSubKey; char strChoosenName[JAVA_MAX_COMMAND_LENGTH] = {0}; char strSubKeyName[JAVA_MAX_COMMAND_LENGTH] = {0}; char strJavaHome[JAVA_MAX_COMMAND_LENGTH] = {0}; - int index; DWORD dwSubKeyNameMax = JAVA_MAX_COMMAND_LENGTH; DWORD dwBufLen = JAVA_MAX_COMMAND_LENGTH; - - RegOpenKeyEx(HKEY_LOCAL_MACHINE, + char strKeyList[4][64] = { + /* 64bit runtime */ "SOFTWARE\\JavaSoft\\Java Runtime Environment", - 0, - KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | MY_KEY_WOW64_64KEY, - &hKey); - RegEnumKeyEx(hKey, 0, (LPSTR)strSubKeyName, &dwSubKeyNameMax, - NULL, NULL, NULL, NULL); - strcpy(strChoosenName, strSubKeyName); - - index = 1; - while (ERROR_SUCCESS == - RegEnumKeyEx(hKey, index, (LPSTR)strSubKeyName, &dwSubKeyNameMax, - NULL, NULL, NULL, NULL)) { - if (strcmp(strChoosenName, strSubKeyName) < 0) { - strcpy(strChoosenName, strSubKeyName); + "SOFTWARE\\JavaSoft\\Java Development Kit", + /* 32bit runtime */ + "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Runtime Environment", + "SOFTWARE\\Wow6432Node\\JavaSoft\\Java Development Kit" + }; + + if (wow64_java_path[0] != '\0') { + strcpy(*java_path, wow64_java_path); + return true; + } + + for (index = 0; index < ARRAY_SIZE(strKeyList); index++) { + res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + strKeyList[index], + 0, + KEY_QUERY_VALUE | + KEY_ENUMERATE_SUB_KEYS | + MY_KEY_WOW64_64KEY, + &hKey); + if (res == ERROR_SUCCESS) { + break; } - index++; } - RegOpenKeyEx(hKey, strChoosenName, 0, - KEY_QUERY_VALUE | MY_KEY_WOW64_64KEY, &hKeyNew); - RegQueryValueEx(hKeyNew, "JavaHome", NULL, - NULL, (LPBYTE)strJavaHome, &dwBufLen); - RegCloseKey(hKey); + if (res == ERROR_SUCCESS) { + RegEnumKeyEx(hKey, 0, (LPSTR)strSubKeyName, &dwSubKeyNameMax, + NULL, NULL, NULL, NULL); + strcpy(strChoosenName, strSubKeyName); + + index = 1; + while (ERROR_SUCCESS == + RegEnumKeyEx(hKey, index, + (LPSTR)strSubKeyName, &dwSubKeyNameMax, + NULL, NULL, NULL, NULL)) { + if (strcmp(strChoosenName, strSubKeyName) < 0) { + strcpy(strChoosenName, strSubKeyName); + } + index++; + } + + RegOpenKeyEx(hKey, strChoosenName, 0, + KEY_QUERY_VALUE | MY_KEY_WOW64_64KEY, &hSubKey); + RegQueryValueEx(hSubKey, "JavaHome", NULL, + NULL, (LPBYTE)strJavaHome, &dwBufLen); + RegCloseKey(hSubKey); + RegCloseKey(hKey); + } else { + /* TODO: + get from %winDir%\System32 + but, is this really needed? + */ + DWORD dwRet = 0; + char strJavaHomeVar[JAVA_MAX_COMMAND_LENGTH] = {0,}; + dwRet = GetEnvironmentVariable("JAVA_HOME", + strJavaHomeVar, + JAVA_MAX_COMMAND_LENGTH); + if (dwRet != 0 && dwRet < JAVA_MAX_COMMAND_LENGTH) { + strcpy(strJavaHome, strJavaHomeVar); + } + } if (strJavaHome[0] != '\0') { - sprintf(*java_path, "\"%s\\bin\\java\"", strJavaHome); - //strcpy(*java_path, strJavaHome); - //strcat(*java_path, "\\bin\\java"); + sprintf(*java_path, "\"%s\\bin\\javaw.exe\"", strJavaHome); + strcpy(wow64_java_path, *java_path); } else { return false; }