24
24
25
25
import cc .arduino .os .windows .FolderFinderInWindowsEnvVar ;
26
26
import cc .arduino .os .windows .FolderFinderInWindowsRegistry ;
27
- import com .sun .jna .platform .win32 .Advapi32Util ;
28
- import com .sun .jna .platform .win32 .WinReg ;
29
27
import org .apache .commons .exec .CommandLine ;
30
28
import org .apache .commons .exec .DefaultExecutor ;
31
29
import org .apache .commons .exec .Executor ;
44
42
import java .util .LinkedList ;
45
43
import java .util .List ;
46
44
import java .util .Map ;
47
- import java .util .regex .Matcher ;
48
45
49
46
50
47
public class Platform extends processing .app .Platform {
@@ -68,6 +65,14 @@ private void recoverSettingsFolderPath() throws Exception {
68
65
this .settingsFolder = path .resolve ("Arduino15" ).toFile ();
69
66
}
70
67
68
+ private Path recoverOldSettingsFolderPath () throws Exception {
69
+ FolderFinderInWindowsRegistry findInUserShellFolders = new FolderFinderInWindowsRegistry (null , "Documents" , "Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Explorer\\ User Shell Folders" , "AppData" );
70
+ FolderFinderInWindowsRegistry findInShellFolders = new FolderFinderInWindowsRegistry (findInUserShellFolders , "Documents" , "Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Explorer\\ Shell Folders" , "AppData" );
71
+
72
+ Path path = findInShellFolders .find ();
73
+ return path .resolve ("Arduino15" );
74
+ }
75
+
71
76
private void recoverDefaultSketchbookFolder () throws Exception {
72
77
FolderFinderInWindowsEnvVar findInUserProfile = new FolderFinderInWindowsEnvVar (null , "Documents" , "USERPROFILE" );
73
78
FolderFinderInWindowsRegistry findInUserShellFolders = new FolderFinderInWindowsRegistry (findInUserProfile , "Documents" , "Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Explorer\\ User Shell Folders" , "Personal" );
@@ -77,19 +82,6 @@ private void recoverDefaultSketchbookFolder() throws Exception {
77
82
this .defaultSketchbookFolder = path .resolve ("Arduino" ).toFile ();
78
83
}
79
84
80
- private String readRegistryEntry (String [] lastPathElements , String key ) {
81
- for (String lastPathElement : lastPathElements ) {
82
- try {
83
- String value = Advapi32Util .registryGetStringValue (WinReg .HKEY_CURRENT_USER , "Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Explorer\\ " + lastPathElement , key );
84
- value = value .replaceAll ("%[uU][sS][eE][rR][pP][rR][oO][fF][iI][lL][eE]%" , Matcher .quoteReplacement (System .getenv ("USERPROFILE" )));
85
- return value ;
86
- } catch (Exception e ) {
87
- //ignore
88
- }
89
- }
90
- throw new IllegalStateException ("Unable to find " + key + " key in Windows registry" );
91
- }
92
-
93
85
/**
94
86
* Remove extra quotes, slashes, and garbage from the Windows PATH.
95
87
*/
@@ -255,21 +247,20 @@ public void chmod(File file, int mode) throws IOException, InterruptedException
255
247
}
256
248
257
249
@ Override
258
- public void fixSettingsLocation () throws IOException {
259
- String path = Advapi32Util .registryGetStringValue (WinReg .HKEY_CURRENT_USER , "Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Explorer\\ Shell Folders" , "AppData" );
260
- Path previousSettingsFolder = Paths .get (path , "Arduino15" );
261
- if (!Files .exists (previousSettingsFolder )) {
250
+ public void fixSettingsLocation () throws Exception {
251
+ Path oldSettingsFolder = recoverOldSettingsFolderPath ();
252
+ if (!Files .exists (oldSettingsFolder )) {
262
253
return ;
263
254
}
264
255
265
- if (!Files .exists (previousSettingsFolder .resolve (Paths .get ("preferences.txt" )))) {
256
+ if (!Files .exists (oldSettingsFolder .resolve (Paths .get ("preferences.txt" )))) {
266
257
return ;
267
258
}
268
259
269
260
if (settingsFolder .exists ()) {
270
261
return ;
271
262
}
272
263
273
- Files .move (previousSettingsFolder , settingsFolder .toPath ());
264
+ Files .move (oldSettingsFolder , settingsFolder .toPath ());
274
265
}
275
266
}
0 commit comments