Skip to content

Commit c53c7da

Browse files
committed
Add support for preferences file override and path normalization
Allows overriding the preferences file location via the 'processing.app.preferences.file' system property. Also normalizes slashes in preference values to forward slashes. Updates tests to verify path normalization and override behavior.
1 parent 3524622 commit c53c7da

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

app/src/processing/app/Preferences.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,13 @@ static public void init() {
8787
setBoolean("editor.input_method_support", true);
8888
}
8989

90+
9091
// next load user preferences file
9192
preferencesFile = Base.getSettingsFile(PREFS_FILE);
93+
var preferencesFileOverride = System.getProperty("processing.app.preferences.file");
94+
if (preferencesFileOverride != null && !preferencesFileOverride.isEmpty()) {
95+
preferencesFile = new File(preferencesFileOverride);
96+
}
9297
boolean firstRun = !preferencesFile.exists();
9398
if (!firstRun) {
9499
try {
@@ -179,9 +184,11 @@ static public void load(InputStream input) throws IOException {
179184

180185
String[] lines = PApplet.loadStrings(input); // Reads as UTF-8
181186
for (String line : lines) {
182-
if ((line.length() == 0) ||
187+
if ((line.isEmpty()) ||
183188
(line.charAt(0) == '#')) continue;
184189

190+
line = line.replace("\\", "/"); // normalize slashes in paths
191+
185192
// this won't properly handle = signs being in the text
186193
int equals = line.indexOf('=');
187194
if (equals != -1) {

app/test/processing/app/PreferencesKtTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import java.util.*
99
import kotlin.io.path.createFile
1010
import kotlin.io.path.createTempDirectory
1111
import kotlin.test.Test
12+
import kotlin.test.assertEquals
1213

1314
class PreferencesKtTest{
1415
@OptIn(ExperimentalTestApi::class)
@@ -75,6 +76,7 @@ class PreferencesKtTest{
7576

7677
val value = "C:\\Users\\Test\\Documents"
7778
tempPreferences.writeText("$testKey=$value")
79+
val replacedValue = value.replace("\\", "/")
7880

7981
setContent {
8082
PreferencesProvider {
@@ -83,6 +85,9 @@ class PreferencesKtTest{
8385
}
8486
}
8587

86-
onNodeWithTag("text").assertTextEquals(value.replace("\\", "/"))
88+
onNodeWithTag("text").assertTextEquals(replacedValue)
89+
90+
Preferences.init()
91+
assertEquals(replacedValue, Preferences.get(testKey))
8792
}
8893
}

0 commit comments

Comments
 (0)