diff options
author | jinhyung.jo <jinhyung.jo@samsung.com> | 2015-07-29 17:30:43 +0900 |
---|---|---|
committer | SeokYeon Hwang <syeon.hwang@samsung.com> | 2015-09-14 15:28:16 +0900 |
commit | 7a795678bd2608adfe438763c8385a9066e677f9 (patch) | |
tree | 310c4bf4f20be4c9cef6e80f1af43c8e9e4ff0ea /util | |
parent | e3fafdd0b8ef1c6047e427cbc0265ce387c0af88 (diff) | |
download | qemu-7a795678bd2608adfe438763c8385a9066e677f9.tar.gz qemu-7a795678bd2608adfe438763c8385a9066e677f9.tar.bz2 qemu-7a795678bd2608adfe438763c8385a9066e677f9.zip |
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 <jinhyung.jo@samsung.com>
(cherry picked from commit 6ba1131714016b47c49e79f361c66cd25d148bc0)
Diffstat (limited to 'util')
-rw-r--r-- | util/oslib-win32.c | 109 |
1 files changed, 74 insertions, 35 deletions
diff --git a/util/oslib-win32.c b/util/oslib-win32.c index fed8de3896..b5beed56ee 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -37,69 +37,108 @@ #include <shlobj.h> #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; } |