[Title] change appdate path in case of windows xp
authorYoonKi Park <yoonki.park@samsung.com>
Fri, 13 Jan 2012 10:24:43 +0000 (19:24 +0900)
committerYoonKi Park <yoonki.park@samsung.com>
Fri, 13 Jan 2012 10:24:43 +0000 (19:24 +0900)
Change-Id: Iab462b9a4fc0afe168bd6bf3ddc68d4d59d1a3ac

com.samsung.tizen.common/src/com/samsung/tizen/common/properties/InstallPathConfig.java

index b06744d..01ebd39 100644 (file)
 
 package com.samsung.tizen.common.properties;
 
+import java.io.BufferedReader;
 import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
 
 import com.samsung.tizen.common.util.DialogUtil;
 import com.samsung.tizen.common.util.HostUtil;
@@ -35,16 +38,24 @@ import com.samsung.tizen.common.util.OSChecker;
 final public class InstallPathConfig {
         
        private static String sdkInstallPath;
-       private final static String SDKSUFFIX = File.separatorChar+".TizenSDK"+File.separatorChar+"tizensdkpath";
+       private final static String SDKSUFFIX = ".TizenSDK"+File.separatorChar+"tizensdkpath";
        private final static String EMULATOR_PATH = "Emulator";
        private final static String INSTALLER_PATH = "InstallManager";
        
+       // Registry Key
+       private static final String REGISTRY_PATH_OF_SHELL_FOLDER = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
+       // public static final String REGISTRY_APP_DATA_OF_SHELL_FOLDER = "AppData";
+       private static final String REGISTRY_LOCAL_APP_DATA_OF_SHELL_FOLDER = "\"Local AppData\"";
+       // Value Column
+       private static final String REG_SZ = "REG_SZ";
+
        static {
                // FIXME : don't need the following lines if using environment variable 
                String sdkPath;
                
                if (OSChecker.isWindows()) {
-                       sdkPath = System.getenv("localappdata") + File.separatorChar + SDKSUFFIX;                               
+                       String appdataPath = getRegistryValue(REGISTRY_PATH_OF_SHELL_FOLDER,REGISTRY_LOCAL_APP_DATA_OF_SHELL_FOLDER) ;
+                       sdkPath = appdataPath + File.separatorChar + SDKSUFFIX;                         
                        loadSdkPath(sdkPath);
                } else if (OSChecker.isLinux() == true || OSChecker.isUnix() == true || OSChecker.isMAC() == true) {
                        sdkPath= System.getProperty("user.home") + File.separatorChar + SDKSUFFIX;      
@@ -86,6 +97,40 @@ final public class InstallPathConfig {
                        System.exit(0);
                }
        }
-}
-
-
+       private static String getRegistryValue(String node, String key) {
+               if (!OSChecker.isWindows())
+                       return null;
+               
+               BufferedReader br = null;
+               String value = "";
+               
+               String query = "reg query " + "\"" + node + "\" /v " + key;
+               try {
+                       Process process = Runtime.getRuntime().exec(query);
+                       
+                       br = new BufferedReader(new InputStreamReader(process.getInputStream(), System.getProperty("file.encoding")));
+                       
+                       String line = null;
+                       while((line = br.readLine()) != null) {
+                               int index = line.indexOf(REG_SZ);
+                               if (index >= 0) {
+                                       value = line.substring(index + REG_SZ.length()).trim();
+                               }
+                       }
+               } catch (IOException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } finally {
+                       if (br != null) {
+                               try {
+                                       br.close();
+                               } catch (IOException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+                       }
+               }
+               
+               return value;
+       }
+}
\ No newline at end of file