Skip to content

Commit ea55a2e

Browse files
author
Federico Fissore
committed
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 arduino#2902
1 parent 62e5e01 commit ea55a2e

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

arduino-core/src/processing/app/BaseNoGui.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ static public void populateImportToLibraryTable() {
962962
}
963963
}
964964

965-
static public void initParameters(String args[]) {
965+
static public void initParameters(String args[]) throws IOException {
966966
String preferencesFile = null;
967967

968968
// Do a first pass over the commandline arguments, the rest of them

arduino-core/src/processing/app/Platform.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,8 @@ public void chmod(File file, int mode) throws IOException, InterruptedException
245245
Process process = Runtime.getRuntime().exec(new String[]{"chmod", Integer.toOctalString(mode), file.getAbsolutePath()}, null, null);
246246
process.waitFor();
247247
}
248+
249+
public void fixSettingsLocation() throws IOException {
250+
//noop
251+
}
248252
}

arduino-core/src/processing/app/PreferencesData.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ public class PreferencesData {
3131
static boolean doSave = true;
3232

3333

34-
static public void init(File file) {
34+
static public void init(File file) throws IOException {
35+
if (file == null) {
36+
BaseNoGui.getPlatform().fixSettingsLocation();
37+
}
3538
if (file != null) {
3639
preferencesFile = file;
3740
} else {

arduino-core/src/processing/app/windows/Platform.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
import java.io.ByteArrayOutputStream;
3636
import java.io.File;
3737
import java.io.IOException;
38+
import java.nio.file.Files;
39+
import java.nio.file.Path;
40+
import java.nio.file.Paths;
3841
import java.util.LinkedList;
3942
import java.util.List;
4043
import java.util.Map;
@@ -54,7 +57,7 @@ public void init() throws IOException {
5457
}
5558

5659
private void recoverSettingsFolderPath() throws IOException {
57-
String path = Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "AppData");
60+
String path = Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Local AppData");
5861
this.settingsFolder = new File(path, "Arduino15");
5962
}
6063

@@ -220,4 +223,23 @@ public void link(File something, File somewhere) throws IOException, Interrupted
220223

221224
public void chmod(File file, int mode) throws IOException, InterruptedException {
222225
}
226+
227+
@Override
228+
public void fixSettingsLocation() throws IOException {
229+
String path = Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "AppData");
230+
Path previousSettingsFolder = Paths.get(path, "Arduino15");
231+
if (!Files.exists(previousSettingsFolder)) {
232+
return;
233+
}
234+
235+
if (!Files.exists(previousSettingsFolder.resolve(Paths.get("preferences.txt")))) {
236+
return;
237+
}
238+
239+
if (settingsFolder.exists()) {
240+
return;
241+
}
242+
243+
Files.move(previousSettingsFolder, settingsFolder.toPath());
244+
}
223245
}

0 commit comments

Comments
 (0)