Skip to content

Commit d2505a0

Browse files
Process platform-specific suffixes immediately
In preferences files, platform-specific versions can be indicated by a .linux, .windows or .macos suffix on the key name. Previously, these keys were loaded as normal and then afterwards, all keys were scanned after loading them and any platform-specific versions replaced the regular ones. However, this means that these platform-specific versions get an unexpected form of priority. Normally, when a single key is set twice, the latter overrides the first. However, the platform-specific values could override the regular versions, even when the regular version occurs later in the file. This problem was particularly confusing when using the new platform.local.txt: a regular preference in platform.local.txt did not override a platform-specific preference in platform.txt. This commit changes behaviour to process these suffixes directly as they are read from the preference files. If a suffix for the current platform is found, the line is processed as if the suffix was not present. If a suffix for another platform is found, the line is ignored altogether. This can slightly change the way preferences files are parsed, but as long as platform-specific preferences are defined after the corresponding regular preferences, the behaviour should be the same.
1 parent f0738fd commit d2505a0

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Diff for: app/src/processing/app/helpers/PreferencesMap.java

+20-20
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ public void load(File file) throws IOException {
7777
load(new FileInputStream(file));
7878
}
7979

80+
protected String processPlatformSuffix(String key, String suffix, boolean isCurrentPlatform) {
81+
if (key == null)
82+
return null;
83+
// Key does not end with the given suffix? Process as normal
84+
if (!key.endsWith(suffix))
85+
return key;
86+
// Not the current platform? Ignore this key
87+
if (!isCurrentPlatform)
88+
return null;
89+
// Strip the suffix from the key
90+
return key.substring(0, key.length() - suffix.length());
91+
}
92+
8093
/**
8194
* Parse a property list stream and put key/value pairs into the Map
8295
*
@@ -91,28 +104,15 @@ public void load(InputStream input) throws IOException {
91104

92105
int equals = line.indexOf('=');
93106
if (equals != -1) {
94-
String key = line.substring(0, equals);
95-
String value = line.substring(equals + 1);
96-
put(key.trim(), value.trim());
97-
}
98-
}
107+
String key = line.substring(0, equals).trim();
108+
String value = line.substring(equals + 1).trim();
99109

100-
// This is needed to avoid ConcurrentAccessExceptions
101-
Set<String> keys = new LinkedHashSet<String>(keySet());
110+
key = processPlatformSuffix(key, ".linux", Base.isLinux());
111+
key = processPlatformSuffix(key, ".windows", Base.isWindows());
112+
key = processPlatformSuffix(key, ".macos", Base.isMacOS());
102113

103-
// Override keys that have OS specific versions
104-
for (String key : keys) {
105-
boolean replace = false;
106-
if (Base.isLinux() && key.endsWith(".linux"))
107-
replace = true;
108-
if (Base.isWindows() && key.endsWith(".windows"))
109-
replace = true;
110-
if (Base.isMacOS() && key.endsWith(".macos"))
111-
replace = true;
112-
if (replace) {
113-
int dot = key.lastIndexOf('.');
114-
String overridenKey = key.substring(0, dot);
115-
put(overridenKey, get(key));
114+
if (key != null)
115+
put(key, value);
116116
}
117117
}
118118
}

0 commit comments

Comments
 (0)