Salome HOME
NewStudyAction is improved. Specific business method for creation of a new study...
[tools/siman.git] / Workspace / Siman / src / org / splat / launcher / WindowsRegistry.java
1 package org.splat.launcher;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
7 import java.io.StringWriter;
8
9
10 public class WindowsRegistry {
11
12     static class StreamReader extends Thread {
13 //  ----------------------------------------
14       private InputStream  is;
15       private StringWriter sw= new StringWriter();;
16
17       public StreamReader(InputStream is) {
18         this.is = is;
19       }
20       public void run() {
21         try {
22           int c;
23           while ((c = is.read()) != -1) sw.write(c);
24         }
25         catch (IOException e) { 
26         }
27       }
28       public String getResult() {
29         return sw.toString();
30       }
31     }
32
33     public static final String readValue (String location, String key) {
34 //  ------------------------------------------------------------------
35       try {
36 //      Run reg query, then read output with StreamReader (internal class)
37         if (key.length() == 0) key = "/ve";     // Looking for the default key
38         else                   key = "/v " + key;
39         
40         Process        process = Runtime.getRuntime().exec("reg query " + location + " " + key);
41         BufferedReader buffer  = new BufferedReader( new InputStreamReader(process.getInputStream()) );
42         
43 //      Output has the following format:
44 //      \n<Version information>\n\n<key>\t<registry type>\t<value>
45         String  output = null;
46         String  value  = "REG_SZ";
47         while ((output = buffer.readLine()) != null) {  
48           if (output.contains(value)) {
49                 int  index = output.indexOf(value) + value.length() + 1;
50             return  output.substring(index).trim();
51           }
52         }
53         return null;
54 //        StreamReader reader  = new StreamReader(process.getInputStream());
55
56 //        reader.start();
57 //        process.waitFor();
58 //        reader.join();
59 //        String output = reader.getResult();
60
61 //      Output has the following format:
62 //      \n<Version information>\n\n<key>\t<registry type>\t<value>
63 //        if( ! output.contains("\t") ){
64 //          return null;
65 //        }
66 //      Parse out the value
67 //        String[] parsed = output.split("\t");
68 //        return parsed[parsed.length-1];
69       }
70       catch (Exception e) {
71         return null;
72       }
73     }
74 }