mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
Merge pull request #2012 from matthijskooijman/ide-1.5.x-platform-preferences
Fix platform-specific preferences in some cases
This commit is contained in:
commit
225c76be43
@ -77,6 +77,19 @@ public class PreferencesMap extends LinkedHashMap<String, String> {
|
||||
load(new FileInputStream(file));
|
||||
}
|
||||
|
||||
protected String processPlatformSuffix(String key, String suffix, boolean isCurrentPlatform) {
|
||||
if (key == null)
|
||||
return null;
|
||||
// Key does not end with the given suffix? Process as normal
|
||||
if (!key.endsWith(suffix))
|
||||
return key;
|
||||
// Not the current platform? Ignore this key
|
||||
if (!isCurrentPlatform)
|
||||
return null;
|
||||
// Strip the suffix from the key
|
||||
return key.substring(0, key.length() - suffix.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a property list stream and put key/value pairs into the Map
|
||||
*
|
||||
@ -91,28 +104,15 @@ public class PreferencesMap extends LinkedHashMap<String, String> {
|
||||
|
||||
int equals = line.indexOf('=');
|
||||
if (equals != -1) {
|
||||
String key = line.substring(0, equals);
|
||||
String value = line.substring(equals + 1);
|
||||
put(key.trim(), value.trim());
|
||||
}
|
||||
}
|
||||
String key = line.substring(0, equals).trim();
|
||||
String value = line.substring(equals + 1).trim();
|
||||
|
||||
// This is needed to avoid ConcurrentAccessExceptions
|
||||
Set<String> keys = new LinkedHashSet<String>(keySet());
|
||||
key = processPlatformSuffix(key, ".linux", Base.isLinux());
|
||||
key = processPlatformSuffix(key, ".windows", Base.isWindows());
|
||||
key = processPlatformSuffix(key, ".macosx", Base.isMacOS());
|
||||
|
||||
// Override keys that have OS specific versions
|
||||
for (String key : keys) {
|
||||
boolean replace = false;
|
||||
if (Base.isLinux() && key.endsWith(".linux"))
|
||||
replace = true;
|
||||
if (Base.isWindows() && key.endsWith(".windows"))
|
||||
replace = true;
|
||||
if (Base.isMacOS() && key.endsWith(".macos"))
|
||||
replace = true;
|
||||
if (replace) {
|
||||
int dot = key.lastIndexOf('.');
|
||||
String overridenKey = key.substring(0, dot);
|
||||
put(overridenKey, get(key));
|
||||
if (key != null)
|
||||
put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user