mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-19 08:52:15 +01:00
Windows: even old settings folder may be missing from the registry. Fixes #4124
This commit is contained in:
parent
49a0f768a1
commit
46d1c89073
@ -973,7 +973,7 @@ public class BaseNoGui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void initParameters(String args[]) throws IOException {
|
static public void initParameters(String args[]) throws Exception {
|
||||||
String preferencesFile = null;
|
String preferencesFile = null;
|
||||||
|
|
||||||
// Do a first pass over the commandline arguments, the rest of them
|
// Do a first pass over the commandline arguments, the rest of them
|
||||||
|
@ -252,7 +252,7 @@ public class Platform {
|
|||||||
process.waitFor();
|
process.waitFor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fixSettingsLocation() throws IOException {
|
public void fixSettingsLocation() throws Exception {
|
||||||
//noop
|
//noop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public class PreferencesData {
|
|||||||
static boolean doSave = true;
|
static boolean doSave = true;
|
||||||
|
|
||||||
|
|
||||||
static public void init(File file) throws IOException {
|
static public void init(File file) throws Exception {
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
BaseNoGui.getPlatform().fixSettingsLocation();
|
BaseNoGui.getPlatform().fixSettingsLocation();
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,6 @@ package processing.app.windows;
|
|||||||
|
|
||||||
import cc.arduino.os.windows.FolderFinderInWindowsEnvVar;
|
import cc.arduino.os.windows.FolderFinderInWindowsEnvVar;
|
||||||
import cc.arduino.os.windows.FolderFinderInWindowsRegistry;
|
import cc.arduino.os.windows.FolderFinderInWindowsRegistry;
|
||||||
import com.sun.jna.platform.win32.Advapi32Util;
|
|
||||||
import com.sun.jna.platform.win32.WinReg;
|
|
||||||
import org.apache.commons.exec.CommandLine;
|
import org.apache.commons.exec.CommandLine;
|
||||||
import org.apache.commons.exec.DefaultExecutor;
|
import org.apache.commons.exec.DefaultExecutor;
|
||||||
import org.apache.commons.exec.Executor;
|
import org.apache.commons.exec.Executor;
|
||||||
@ -44,7 +42,6 @@ import java.nio.file.Paths;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
|
|
||||||
|
|
||||||
public class Platform extends processing.app.Platform {
|
public class Platform extends processing.app.Platform {
|
||||||
@ -68,6 +65,14 @@ public class Platform extends processing.app.Platform {
|
|||||||
this.settingsFolder = path.resolve("Arduino15").toFile();
|
this.settingsFolder = path.resolve("Arduino15").toFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Path recoverOldSettingsFolderPath() throws Exception {
|
||||||
|
FolderFinderInWindowsRegistry findInUserShellFolders = new FolderFinderInWindowsRegistry(null, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", "AppData");
|
||||||
|
FolderFinderInWindowsRegistry findInShellFolders = new FolderFinderInWindowsRegistry(findInUserShellFolders, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "AppData");
|
||||||
|
|
||||||
|
Path path = findInShellFolders.find();
|
||||||
|
return path.resolve("Arduino15");
|
||||||
|
}
|
||||||
|
|
||||||
private void recoverDefaultSketchbookFolder() throws Exception {
|
private void recoverDefaultSketchbookFolder() throws Exception {
|
||||||
FolderFinderInWindowsEnvVar findInUserProfile = new FolderFinderInWindowsEnvVar(null, "Documents", "USERPROFILE");
|
FolderFinderInWindowsEnvVar findInUserProfile = new FolderFinderInWindowsEnvVar(null, "Documents", "USERPROFILE");
|
||||||
FolderFinderInWindowsRegistry findInUserShellFolders = new FolderFinderInWindowsRegistry(findInUserProfile, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", "Personal");
|
FolderFinderInWindowsRegistry findInUserShellFolders = new FolderFinderInWindowsRegistry(findInUserProfile, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", "Personal");
|
||||||
@ -77,19 +82,6 @@ public class Platform extends processing.app.Platform {
|
|||||||
this.defaultSketchbookFolder = path.resolve("Arduino").toFile();
|
this.defaultSketchbookFolder = path.resolve("Arduino").toFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readRegistryEntry(String[] lastPathElements, String key) {
|
|
||||||
for (String lastPathElement : lastPathElements) {
|
|
||||||
try {
|
|
||||||
String value = Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\" + lastPathElement, key);
|
|
||||||
value = value.replaceAll("%[uU][sS][eE][rR][pP][rR][oO][fF][iI][lL][eE]%", Matcher.quoteReplacement(System.getenv("USERPROFILE")));
|
|
||||||
return value;
|
|
||||||
} catch (Exception e) {
|
|
||||||
//ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Unable to find " + key + " key in Windows registry");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove extra quotes, slashes, and garbage from the Windows PATH.
|
* Remove extra quotes, slashes, and garbage from the Windows PATH.
|
||||||
*/
|
*/
|
||||||
@ -255,14 +247,13 @@ public class Platform extends processing.app.Platform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fixSettingsLocation() throws IOException {
|
public void fixSettingsLocation() throws Exception {
|
||||||
String path = Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "AppData");
|
Path oldSettingsFolder = recoverOldSettingsFolderPath();
|
||||||
Path previousSettingsFolder = Paths.get(path, "Arduino15");
|
if (!Files.exists(oldSettingsFolder)) {
|
||||||
if (!Files.exists(previousSettingsFolder)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Files.exists(previousSettingsFolder.resolve(Paths.get("preferences.txt")))) {
|
if (!Files.exists(oldSettingsFolder.resolve(Paths.get("preferences.txt")))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,6 +261,6 @@ public class Platform extends processing.app.Platform {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Files.move(previousSettingsFolder, settingsFolder.toPath());
|
Files.move(oldSettingsFolder, settingsFolder.toPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user