2424
2525import cc .arduino .os .windows .FolderFinderInWindowsEnvVar ;
2626import cc .arduino .os .windows .FolderFinderInWindowsRegistry ;
27- import com .sun .jna .platform .win32 .Advapi32Util ;
28- import com .sun .jna .platform .win32 .WinReg ;
2927import org .apache .commons .exec .CommandLine ;
3028import org .apache .commons .exec .DefaultExecutor ;
3129import org .apache .commons .exec .Executor ;
4442import java .util .LinkedList ;
4543import java .util .List ;
4644import java .util .Map ;
47- import java .util .regex .Matcher ;
4845
4946
5047public class Platform extends processing .app .Platform {
@@ -68,6 +65,14 @@ private void recoverSettingsFolderPath() throws Exception {
6865 this .settingsFolder = path .resolve ("Arduino15" ).toFile ();
6966 }
7067
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+
7176 private void recoverDefaultSketchbookFolder () throws Exception {
7277 FolderFinderInWindowsEnvVar findInUserProfile = new FolderFinderInWindowsEnvVar (null , "Documents" , "USERPROFILE" );
7378 FolderFinderInWindowsRegistry findInUserShellFolders = new FolderFinderInWindowsRegistry (findInUserProfile , "Documents" , "Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Explorer\\ User Shell Folders" , "Personal" );
@@ -77,19 +82,6 @@ private void recoverDefaultSketchbookFolder() throws Exception {
7782 this .defaultSketchbookFolder = path .resolve ("Arduino" ).toFile ();
7883 }
7984
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-
9385 /**
9486 * Remove extra quotes, slashes, and garbage from the Windows PATH.
9587 */
@@ -255,21 +247,20 @@ public void chmod(File file, int mode) throws IOException, InterruptedException
255247 }
256248
257249 @ 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 )) {
262253 return ;
263254 }
264255
265- if (!Files .exists (previousSettingsFolder .resolve (Paths .get ("preferences.txt" )))) {
256+ if (!Files .exists (oldSettingsFolder .resolve (Paths .get ("preferences.txt" )))) {
266257 return ;
267258 }
268259
269260 if (settingsFolder .exists ()) {
270261 return ;
271262 }
272263
273- Files .move (previousSettingsFolder , settingsFolder .toPath ());
264+ Files .move (oldSettingsFolder , settingsFolder .toPath ());
274265 }
275266}
0 commit comments