emulator: Modified code about java path in WOW64
authorjinhyung.jo <jinhyung.jo@samsung.com>
Wed, 29 Jul 2015 08:30:43 +0000 (17:30 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 30 Jul 2015 10:49:24 +0000 (19:49 +0900)
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>
include/qemu-common.h
tizen/src/emulator_common.h
tizen/src/ui/menu/contextmenu.cpp
util/oslib-win32.c

index ebdd8bb67964c278deaec3b82d653e7bc97f003c..f8622141a80b44bc9e00609d63b529d67addc0b4 100644 (file)
@@ -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
index 34142b2df5ff08d252df9ac65e9596afddd00576..4aef16733f0b8ae2a36577fcb6fad74135b7d27b 100644 (file)
 
 #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
index 9b1f6e297c4a6014680ed3d970e0a23ddad8c7b7..0bc1b29eb0106b7b3fd3b1f507b001f2ae37325e 100644 (file)
@@ -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);
index 2df5de4bd20f1493b96cc6d25c030a3ce5e02bff..9149fa64e018a3075fe51a29494328bcefd44603 100644 (file)
 #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;
     }