diff options
author | jinhyung.jo <jinhyung.jo@samsung.com> | 2015-11-05 15:08:19 +0900 |
---|---|---|
committer | Jinhyung Jo <jinhyung.jo@samsung.com> | 2015-11-10 13:18:06 +0900 |
commit | b492cbfce5f19fd664e729a3941b1e47c367295e (patch) | |
tree | 907ef925c76ba98f912d05244b17f2c32b3b6429 | |
parent | 52b73c69e30e0fd4240c99916abe939beed9d1b6 (diff) | |
download | qemu-b492cbfce5f19fd664e729a3941b1e47c367295e.tar.gz qemu-b492cbfce5f19fd664e729a3941b1e47c367295e.tar.bz2 qemu-b492cbfce5f19fd664e729a3941b1e47c367295e.zip |
osutil-win32: get JavaHome path of current JRE
Currently, the emulator gets the java path by traverses the registry
subkeys of "\\SOFTWARE\\JavaSoft\\Java Runtime Environment".
This can cause side effects.
So modified to get the java path in the normal way.
It gets the JavaHome path of the CurrentVersion.
Change-Id: Ibfa41f3c939f01f3b0ffd5fe4cfa2bdb575be76a
Signed-off-by: Jinhyung Jo <jinhyung.jo@samsung.com>
-rw-r--r-- | tizen/src/util/osutil-win32.c | 136 |
1 files changed, 69 insertions, 67 deletions
diff --git a/tizen/src/util/osutil-win32.c b/tizen/src/util/osutil-win32.c index c56bae9cee..7fe2661b2c 100644 --- a/tizen/src/util/osutil-win32.c +++ b/tizen/src/util/osutil-win32.c @@ -295,94 +295,96 @@ int is_wow64(void) fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress( GetModuleHandle(TEXT("kernel32")), "IsWow64Process"); - if (NULL != fnIsWow64Process) { - if (!fnIsWow64Process(GetCurrentProcess(), &result)) { - /* No need to handle error, - just check whether is this WoW64 process */ - } + if (!fnIsWow64Process) { + WARN("GetProcAddress(IsWow64Process) failed, %s return false\n", + __func__); + return 0; } + /* No need to handle error, + just check whether is this WoW64 process */ + fnIsWow64Process(GetCurrentProcess(), &result); + return result; } +/* Gets the JavaHome path from the windows registry. + Must call the RegOpenKeyEx by using the following flag. + For details, "http://stackoverflow.com/questions/10533421/ + accessing-64-bit-registry-from-32-bit-application" */ #define MY_KEY_WOW64_64KEY 0x0100 static char wow64_java_path[PATH_MAX]; bool get_java_path(char **java_path) { - int index; LONG res; - HKEY hKey, hSubKey; - char strChoosenName[PATH_MAX] = {0}; - char strSubKeyName[PATH_MAX] = {0}; + HKEY hKey; + char strKey[PATH_MAX] = {0}; + char strVersion[PATH_MAX] = {0}; char strJavaHome[PATH_MAX] = {0}; - DWORD dwSubKeyNameMax = PATH_MAX; DWORD dwBufLen = PATH_MAX; - char strKeyList[4][64] = { - /* 64bit runtime */ - "SOFTWARE\\JavaSoft\\Java Runtime Environment", - "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); + g_strlcpy(*java_path, wow64_java_path, PATH_MAX); 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; - } + g_strlcpy(strKey, "SOFTWARE\\JavaSoft\\Java Runtime Environment", PATH_MAX); + + /* Opens above key to query the current version */ + res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + strKey, + 0, + KEY_QUERY_VALUE | + MY_KEY_WOW64_64KEY, + &hKey); + if (res != ERROR_SUCCESS) { + WARN("Java Runtime Environment key not found\n"); + goto javahome_not_found; } - if (res == ERROR_SUCCESS) { - index = 0; - do { - dwSubKeyNameMax = PATH_MAX; - res = RegEnumKeyEx(hKey, - index++, - (LPSTR)strSubKeyName, - &dwSubKeyNameMax, - NULL, NULL, NULL, NULL); - if (strcmp(strChoosenName, strSubKeyName) < 0) { - strcpy(strChoosenName, strSubKeyName); - } - } while (res == ERROR_SUCCESS); + /* Queries for the current version */ + res = RegQueryValueEx(hKey, + "CurrentVersion", + NULL, + NULL, + (LPBYTE)strVersion, + &dwBufLen); + RegCloseKey(hKey); + if (res != ERROR_SUCCESS) { + WARN("JRE CurrentVersion not found\n"); + goto javahome_not_found; + } - RegOpenKeyEx(hKey, strChoosenName, 0, - KEY_QUERY_VALUE | MY_KEY_WOW64_64KEY, &hSubKey); - RegQueryValueEx(hSubKey, "JavaHome", NULL, + /* Adds the current version to the key */ + g_strlcat(strKey, "\\", PATH_MAX); + g_strlcat(strKey, strVersion, PATH_MAX); + + /* Opens above key to query the JavaHome */ + res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + strKey, + 0, + KEY_QUERY_VALUE | + MY_KEY_WOW64_64KEY, + &hKey); + if (res == ERROR_SUCCESS) { + /* Queries for the JavaHome */ + dwBufLen = PATH_MAX; + RegQueryValueEx(hKey, "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[PATH_MAX] = {0,}; - dwRet = GetEnvironmentVariable("JAVA_HOME", - strJavaHomeVar, - PATH_MAX); - if (dwRet != 0 && dwRet < PATH_MAX) { - strcpy(strJavaHome, strJavaHomeVar); - } } - if (strJavaHome[0] != '\0') { - sprintf(*java_path, "\"%s\\bin\\javaw.exe\"", strJavaHome); - strcpy(wow64_java_path, *java_path); - } else { - return false; + RegCloseKey(hKey); + +javahome_not_found: + if (strJavaHome[0] == '\0') { + dwBufLen = GetEnvironmentVariable("JAVA_HOME", + strJavaHome, + PATH_MAX); + if (dwBufLen == 0) { + WARN("There is no JavaHome\n"); + return false; + } } - + g_sprintf(*java_path, "\"%s\\bin\\javaw.exe\"", strJavaHome); + g_strlcpy(wow64_java_path, *java_path, PATH_MAX); + INFO("JavaHome: %s\n", wow64_java_path); return true; } |