From ea55a2edc33550d2ec0b2366dec4c55ce391f6a4 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Tue, 23 Jun 2015 15:58:11 +0200 Subject: [PATCH] Windows: migrating from AppData\Roaming\Arduino15 to AppData\Local\Arduino15. Migration occurs when NO preferences file location is provided (CLI only), when new location does not exist and when there is something to migrate. Fixes #2902 --- .../src/processing/app/BaseNoGui.java | 2 +- arduino-core/src/processing/app/Platform.java | 4 ++++ .../src/processing/app/PreferencesData.java | 5 +++- .../src/processing/app/windows/Platform.java | 24 ++++++++++++++++++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index b39b306cd..8aeffcc15 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -962,7 +962,7 @@ public class BaseNoGui { } } - static public void initParameters(String args[]) { + static public void initParameters(String args[]) throws IOException { String preferencesFile = null; // Do a first pass over the commandline arguments, the rest of them diff --git a/arduino-core/src/processing/app/Platform.java b/arduino-core/src/processing/app/Platform.java index 1d39b27eb..dee2df451 100644 --- a/arduino-core/src/processing/app/Platform.java +++ b/arduino-core/src/processing/app/Platform.java @@ -245,4 +245,8 @@ public class Platform { Process process = Runtime.getRuntime().exec(new String[]{"chmod", Integer.toOctalString(mode), file.getAbsolutePath()}, null, null); process.waitFor(); } + + public void fixSettingsLocation() throws IOException { + //noop + } } diff --git a/arduino-core/src/processing/app/PreferencesData.java b/arduino-core/src/processing/app/PreferencesData.java index a273221a3..8e49c2f1b 100644 --- a/arduino-core/src/processing/app/PreferencesData.java +++ b/arduino-core/src/processing/app/PreferencesData.java @@ -31,7 +31,10 @@ public class PreferencesData { static boolean doSave = true; - static public void init(File file) { + static public void init(File file) throws IOException { + if (file == null) { + BaseNoGui.getPlatform().fixSettingsLocation(); + } if (file != null) { preferencesFile = file; } else { diff --git a/arduino-core/src/processing/app/windows/Platform.java b/arduino-core/src/processing/app/windows/Platform.java index 394a915ce..b1f726ca9 100644 --- a/arduino-core/src/processing/app/windows/Platform.java +++ b/arduino-core/src/processing/app/windows/Platform.java @@ -35,6 +35,9 @@ import processing.app.legacy.PConstants; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -54,7 +57,7 @@ public class Platform extends processing.app.Platform { } private void recoverSettingsFolderPath() throws IOException { - String path = Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "AppData"); + String path = Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Local AppData"); this.settingsFolder = new File(path, "Arduino15"); } @@ -220,4 +223,23 @@ public class Platform extends processing.app.Platform { public void chmod(File file, int mode) throws IOException, InterruptedException { } + + @Override + public void fixSettingsLocation() throws IOException { + String path = Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "AppData"); + Path previousSettingsFolder = Paths.get(path, "Arduino15"); + if (!Files.exists(previousSettingsFolder)) { + return; + } + + if (!Files.exists(previousSettingsFolder.resolve(Paths.get("preferences.txt")))) { + return; + } + + if (settingsFolder.exists()) { + return; + } + + Files.move(previousSettingsFolder, settingsFolder.toPath()); + } }