-
Notifications
You must be signed in to change notification settings - Fork 79
/
SDFS_DP_Changes_after_100821_till_071221.patch
180 lines (166 loc) · 5.89 KB
/
SDFS_DP_Changes_after_100821_till_071221.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
diff --git a/src/org/opendedup/sdfs/windows/utils/WinRegistry.java b/src/org/opendedup/sdfs/windows/utils/WinRegistry.java
index 8fd690d1..cf1d4d13 100644
--- a/src/org/opendedup/sdfs/windows/utils/WinRegistry.java
+++ b/src/org/opendedup/sdfs/windows/utils/WinRegistry.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2016 Sam Silverberg [email protected]
+ * Copyright (C) 2016 Sam Silverberg [email protected]
*
* This file is part of OpenDedupe SDFS.
*
@@ -21,65 +21,97 @@ package org.opendedup.sdfs.windows.utils;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
+import java.lang.reflect.InvocationTargetException;
+import org.opendedup.logging.SDFSLogger;
-
-public class WinRegistry {
- public static final int HKEY_LOCAL_MACHINE = 0x80000002;
-
+public class WinRegistry {
public static final int KEY_SZ = 0;
public static final int KEY_DWORD = 1;
+ private static final String REG_QUERY = "reg query ";
+ private static final String REG_STR = "REG_SZ";
+ private static final String REG_DWORD = "REG_DWORD";
+ static String readRegistryRegQuery(String key) throws IOException {
+ String useKey = REG_QUERY + key;
+ int keyType = -1;
- public static final String readRegistry(String location, String key){
- try {
- // Run reg query, then read output with StreamReader (internal class)
- Process process = Runtime.getRuntime().exec("reg query " +
- '"'+ location + "\" /v " + key);
+ Process process = Runtime.getRuntime().exec(useKey);
+ StreamReader reader = new StreamReader(process.getInputStream());
- StreamReader reader = new StreamReader(process.getInputStream());
- reader.start();
+ reader.start();
+ try {
process.waitFor();
reader.join();
- String output = reader.getResult();
-
- // Output has the following format:
- // \n<Version information>\n\n<key>\t<registry type>\t<value>
- if( ! output.contains("\t")){
- return null;
- }
+ } catch (InterruptedException e) {
+ SDFSLogger.getLog().error(e.getMessage());
+ Thread.currentThread().interrupt();
+ }
- // Parse out the value
- String[] parsed = output.split("\t");
- return parsed[parsed.length-1];
+ String result = reader.getResult();
+ int p = -1;
+ if (result.contains(REG_STR)) {
+ p = result.indexOf(REG_STR);
+ keyType = KEY_SZ;
+ } else if (result.contains(REG_DWORD)) {
+ p = result.indexOf(REG_DWORD);
+ keyType = KEY_DWORD;
}
- catch (Exception e) {
+
+ if (p == -1) {
return null;
}
+ switch (keyType) {
+ case KEY_SZ:
+ return result.substring(p + REG_STR.length()).trim();
+ case KEY_DWORD:
+ String temp = result.substring(p + REG_DWORD.length()).trim();
+ return Integer.toString((Integer.parseInt(temp.substring("0x".length()), 16)));
+ default:
+ return "";
+ }
}
static class StreamReader extends Thread {
- private InputStream is;
- private StringWriter sw= new StringWriter();
+ private final InputStream mIs;
+
+ private final StringWriter mSw;
- public StreamReader(InputStream is) {
- this.is = is;
+ StreamReader(InputStream is) {
+ mIs = is;
+ mSw = new StringWriter();
}
+ @Override
public void run() {
+ int c;
try {
- int c;
- while ((c = is.read()) != -1)
- sw.write(c);
+ while ((c = mIs.read()) != -1) {
+ mSw.write(c);
+ }
+ } catch (IOException e) {
+ SDFSLogger.getLog().error(e.getMessage());
}
- catch (IOException e) {
- }
+
}
- public String getResult() {
- return sw.toString();
+ String getResult() {
+ return mSw.toString();
}
}
+ public static String readRegistry(String location, String key) throws IOException {
+ String pathkey = "\"" +
+ location +
+ "\" /v " +
+ key;
+ return readRegistryRegQuery(pathkey);
+ }
+ public static void main(String[] args) throws IllegalArgumentException,
+ IllegalAccessException, InvocationTargetException {
+ //System.out.println(WinRegistry.readString(HKEY_LOCAL_MACHINE,
+ // "SOFTWARE\\Wow6432Node\\SDFS", "path"));
+ System.out.println("Running Winregistry class");
+ }
}
diff --git a/src/org/opendedup/util/OSValidator.java b/src/org/opendedup/util/OSValidator.java
index 4a82c493..d83ca3b3 100644
--- a/src/org/opendedup/util/OSValidator.java
+++ b/src/org/opendedup/util/OSValidator.java
@@ -67,13 +67,13 @@ public class OSValidator {
}
public static String getProgramBasePath() {
- if (isUnix() || isMac())
- if(Main.sdfsBasePath.equals("")) {
- return "/opt/sdfs/";
- } else {
- return Main.sdfsBasePath;
- }
- else {
+ if (isUnix() || isMac()) {
+ if(Main.sdfsBasePath.equals("")) {
+ return "/opt/sdfs/";
+ } else {
+ return Main.sdfsBasePath;
+ }
+ } else {
try {
return WinRegistry.readRegistry(
"HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\SDFS", "path") + File.separator;
@@ -85,9 +85,9 @@ public class OSValidator {
}
public static String getConfigPath() {
- if (isUnix() || isMac())
- return "/etc/sdfs/";
- else
+ if (isUnix() || isMac()) {
+ return Main.sdfsBasePath + "/etc/sdfs/";
+ } else
try {
return WinRegistry.readRegistry(
"HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\SDFS", "path")