Skip to content

Commit 9973522

Browse files
committed
core: Discoverer; InstallLocation
- Discoverer has distinct functions to read Registry and to search folders - mbs uses Discoverer - mbs, openocd & qemu use both InstallLocation and deprecated InstallFolder
1 parent 48fc54b commit 9973522

File tree

5 files changed

+198
-167
lines changed

5 files changed

+198
-167
lines changed

ilg.gnuarmeclipse.core/src/ilg/gnuarmeclipse/core/preferences/Discoverer.java

Lines changed: 62 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,6 @@ public class Discoverer {
4242

4343
// ------------------------------------------------------------------------
4444

45-
/**
46-
* Find where the executable might have been installed. The returned path is
47-
* known to be an existing folder.
48-
*
49-
* @param executableName
50-
* @param searchPath
51-
* a string with a sequence of folders.
52-
* @param registrySubKey
53-
* @param registryName
54-
* @return a String with the absolute folder path, or null if not found.
55-
*/
56-
public static String discoverInstallFolder(String executableName,
57-
String searchPath, String registrySubKey, String registryName) {
58-
59-
return discoverInstallFolder(executableName, searchPath, "bin",
60-
registrySubKey, registryName);
61-
}
62-
6345
/**
6446
* Find where the executable might have been installed. The returned path is
6547
* known to be an existing folder.
@@ -69,55 +51,12 @@ public static String discoverInstallFolder(String executableName,
6951
* a string with a sequence of folders.
7052
* @param binFolder
7153
* a String, usually "bin", or null.
72-
* @param registrySubKey
73-
* @param registryName
7454
* @return a String with the absolute folder path, or null if not found.
7555
*/
76-
public static String discoverInstallFolder(String executableName,
77-
String searchPath, String binFolder, String registrySubKey,
78-
String registryName) {
56+
public static String searchInstallFolder(String executableName,
57+
String searchPath, String binFolder) {
7958

8059
String value = null;
81-
if (EclipseUtils.isWindows()) {
82-
83-
WindowsRegistry registry = WindowsRegistry.getRegistry();
84-
85-
if (registry != null) {
86-
value = getRegistryValue(registry, REG_PREFIX, registrySubKey,
87-
registryName);
88-
if (value == null) {
89-
// If on 64-bit, check the 32-bit registry too.
90-
value = getRegistryValue(registry, REG32_PREFIX,
91-
registrySubKey, registryName);
92-
}
93-
94-
if (binFolder != null && value != null
95-
&& !value.endsWith("\\" + binFolder)) {
96-
value += "\\" + binFolder;
97-
}
98-
99-
if (value != null) {
100-
IPath path = new Path(value);
101-
// Make portable
102-
value = path.toString(); // includes /bin, if it exists
103-
if (Activator.getInstance().isDebugging()) {
104-
System.out
105-
.println("Discoverer.discoverInstallFolder() WinReg "
106-
+ registryName + " " + value);
107-
}
108-
109-
File folder = path.append(executableName).toFile();
110-
if (folder.isFile()) {
111-
if (Activator.getInstance().isDebugging()) {
112-
System.out
113-
.println("Discoverer.discoverInstallFolder() WinReg="
114-
+ value);
115-
}
116-
return value;
117-
}
118-
}
119-
}
120-
}
12160

12261
if (searchPath == null || searchPath.isEmpty()) {
12362
return null;
@@ -159,7 +98,7 @@ public static String discoverInstallFolder(String executableName,
15998

16099
if (Activator.getInstance().isDebugging()) {
161100
System.out
162-
.println("Discoverer.discoverInstallFolder() resolved path "
101+
.println("Discoverer.searchInstallFolder() resolved path "
163102
+ resolvedPath);
164103
}
165104

@@ -174,6 +113,65 @@ public static String discoverInstallFolder(String executableName,
174113
return null;
175114
}
176115

116+
/**
117+
* Get key value from registry and validate the executable. The returned
118+
* path is known to be an existing folder.
119+
*
120+
* @param executableName
121+
* @param binFolder
122+
* a String, usually "bin", or null.
123+
* @param registrySubKey
124+
* @param registryName
125+
* @return a String with the absolute folder path, or null if not found.
126+
*/
127+
public static String getRegistryInstallFolder(String executableName,
128+
String binFolder, String registrySubKey, String registryName) {
129+
130+
String value = null;
131+
if (EclipseUtils.isWindows()) {
132+
133+
WindowsRegistry registry = WindowsRegistry.getRegistry();
134+
135+
if (registry != null) {
136+
value = getRegistryValue(registry, REG_PREFIX, registrySubKey,
137+
registryName);
138+
if (value == null) {
139+
// If on 64-bit, check the 32-bit registry too.
140+
value = getRegistryValue(registry, REG32_PREFIX,
141+
registrySubKey, registryName);
142+
}
143+
144+
if (binFolder != null && value != null
145+
&& !value.endsWith("\\" + binFolder)) {
146+
value += "\\" + binFolder;
147+
}
148+
149+
if (value != null) {
150+
IPath path = new Path(value);
151+
// Make portable
152+
value = path.toString(); // includes /bin, if it exists
153+
if (Activator.getInstance().isDebugging()) {
154+
System.out
155+
.println("Discoverer.getRegistryInstallFolder() "
156+
+ registryName + " " + value);
157+
}
158+
159+
File folder = path.append(executableName).toFile();
160+
if (folder.isFile()) {
161+
if (Activator.getInstance().isDebugging()) {
162+
System.out
163+
.println("Discoverer.getRegistryInstallFolder()="
164+
+ value);
165+
}
166+
return value;
167+
}
168+
}
169+
}
170+
}
171+
172+
return null;
173+
}
174+
177175
/**
178176
* Get the value of a registry key. It first tests the current user key,
179177
* then the local machine key.

ilg.gnuarmeclipse.debug.gdbjtag.jlink/src/ilg/gnuarmeclipse/debug/gdbjtag/jlink/DefaultPreferenceInitializer.java

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ public void finalizeInitializationsDefaultPreferences() {
227227
executableName += ".exe";
228228
}
229229

230+
// Check if the search path is defined in the default
231+
// preferences.
232+
String searchPath = DefaultPreferences.getSearchPath();
233+
if (searchPath.isEmpty()) {
234+
235+
// If not defined, get the OS Specific default
236+
// from preferences.ini.
237+
searchPath = DefaultPreferences.getSearchPathOs();
238+
if (!searchPath.isEmpty()) {
239+
// Store the search path in the preferences
240+
DefaultPreferences.putSearchPath(searchPath);
241+
}
242+
}
243+
230244
// J-Link GDB Server install folder
231245
// Check if the toolchain path is explictly defined in the
232246
// default preferences.
@@ -239,34 +253,24 @@ public void finalizeInitializationsDefaultPreferences() {
239253
folder = "";
240254
}
241255
}
242-
if (folder.isEmpty()) {
243256

244-
// Check if the search path is defined in the default
245-
// preferences.
246-
String searchPath = DefaultPreferences.getSearchPath();
247-
if (searchPath.isEmpty()) {
248-
249-
// If not defined, get the OS Specific default
250-
// from preferences.ini.
251-
searchPath = DefaultPreferences.getSearchPathOs();
252-
if (!searchPath.isEmpty()) {
253-
// Store the search path in the preferences
254-
DefaultPreferences.putSearchPath(searchPath);
255-
}
256-
}
257+
if (folder.isEmpty()) {
257258

258-
if (!searchPath.isEmpty()) {
259+
// If the search path is known, discover toolchain.
260+
folder = Discoverer.getRegistryInstallFolder(executableName,
261+
"bin", REG_SUBKEY, REG_NAME);
259262

260-
// If the search path is known, discover toolchain.
261-
folder = Discoverer.discoverInstallFolder(executableName,
262-
searchPath, null, REG_SUBKEY, REG_NAME);
263-
if (folder != null && !folder.isEmpty()) {
264-
// If the install folder was finally discovered, store
265-
// it in the preferences.
266-
DefaultPreferences.putInstallFolder(folder);
267-
}
263+
if (folder == null) {
264+
folder = Discoverer.searchInstallFolder(executableName,
265+
searchPath, null);
268266
}
269267
}
268+
269+
if (folder != null && !folder.isEmpty()) {
270+
// If the install folder was finally discovered, store
271+
// it in the preferences.
272+
DefaultPreferences.putInstallFolder(folder);
273+
}
270274
}
271275
}
272276

ilg.gnuarmeclipse.debug.gdbjtag.openocd/src/ilg/gnuarmeclipse/debug/gdbjtag/openocd/DefaultPreferenceInitializer.java

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ public class DefaultPreferenceInitializer extends AbstractPreferenceInitializer
3434

3535
// ------------------------------------------------------------------------
3636

37-
// LOCAL_MACHINE
37+
// HKCU & HKLM LOCAL_MACHINE
3838
private static final String REG_SUBKEY = "\\GNU ARM Eclipse\\OpenOCD";
39-
private static final String REG_NAME = "InstallFolder";
39+
// Standard Microsoft recommendation.
40+
private static final String REG_NAME = "InstallLocation";
41+
// Custom name, used before reading the standard.
42+
private static final String REG_NAME_DEPRECATED = "InstallFolder";
4043

4144
// ------------------------------------------------------------------------
4245

@@ -136,6 +139,21 @@ public void finalizeInitializationsDefaultPreferences() {
136139
executableName += ".exe";
137140
}
138141

142+
// Check if the search path is defined in the default
143+
// preferences.
144+
String searchPath = DefaultPreferences.getSearchPath();
145+
if (searchPath.isEmpty()) {
146+
147+
// If not defined, get the OS Specific default
148+
// from preferences.ini.
149+
searchPath = DefaultPreferences.getSearchPathOs();
150+
151+
if (!searchPath.isEmpty()) {
152+
// Store the search path in the preferences
153+
DefaultPreferences.putSearchPath(searchPath);
154+
}
155+
}
156+
139157
// OpenOCD install folder
140158
// Check if the toolchain path is explictly defined in the
141159
// default preferences.
@@ -148,34 +166,31 @@ public void finalizeInitializationsDefaultPreferences() {
148166
folder = "";
149167
}
150168
}
169+
151170
if (folder.isEmpty()) {
152171

153-
// Check if the search path is defined in the default
154-
// preferences.
155-
String searchPath = DefaultPreferences.getSearchPath();
156-
if (searchPath.isEmpty()) {
157-
158-
// If not defined, get the OS Specific default
159-
// from preferences.ini.
160-
searchPath = DefaultPreferences.getSearchPathOs();
161-
if (!searchPath.isEmpty()) {
162-
// Store the search path in the preferences
163-
DefaultPreferences.putSearchPath(searchPath);
164-
}
165-
}
172+
// If the search path is known, discover toolchain.
173+
folder = Discoverer.getRegistryInstallFolder(executableName,
174+
"bin", REG_SUBKEY, REG_NAME);
166175

167-
if (!searchPath.isEmpty()) {
176+
// Search the non standard key too.
177+
if (folder == null) {
178+
folder = Discoverer.getRegistryInstallFolder(
179+
executableName, "bin", REG_SUBKEY,
180+
REG_NAME_DEPRECATED);
181+
}
168182

169-
// If the search path is known, discover toolchain.
170-
folder = Discoverer.discoverInstallFolder(executableName,
171-
searchPath, REG_SUBKEY, REG_NAME);
172-
if (folder != null && !folder.isEmpty()) {
173-
// If the install folder was finally discovered, store
174-
// it in the preferences.
175-
DefaultPreferences.putInstallFolder(folder);
176-
}
183+
if (folder == null) {
184+
folder = Discoverer.searchInstallFolder(executableName,
185+
searchPath, "bin");
177186
}
178187
}
188+
189+
if (folder != null && !folder.isEmpty()) {
190+
// If the install folder was finally discovered, store
191+
// it in the preferences.
192+
DefaultPreferences.putInstallFolder(folder);
193+
}
179194
}
180195
}
181196

0 commit comments

Comments
 (0)