Skip to content

Fix platform-specific preferences in some cases #2012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions app/src/processing/app/helpers/PreferencesMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ public void load(File file) throws IOException {
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
*
Expand All @@ -91,28 +104,15 @@ public void load(InputStream input) throws IOException {

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);
}
}
}
Expand Down