arduino / arduino/Arduino

"settings.path" parameter in <<Arduino folder>>/lib/preferences.txt file is ignored at startup

Open
#3,474 10 comments 0 reactions 0 assignees View on GitHub
Component: IDE Type: Bug
Dominant language
Java
Stars
14.6k
Forks
7k
PR merge metrics
No merged PRs in 30d

Description

**OS** : Windows 8.1
**Arduino version** : 1.6.5

When Arduino starts, it loads `<>/lib/preferences.txt` file.

About `settings.path` parameter from this file :

```
# if you don't want settings to go into "application data" on windows
# and "library" on macosx, set this to the alternate location.
#settings.path=data
```

If I uncomment this parameter and if I set a specific folder to it, **this value is ignored by Arduino**.
See `//##` comments below in code.

**`processing.app.PreferencesData` class** :

``` java
static public void init(File file) {
if (file != null) {
preferencesFile = file;
} else {
//########################################################
//## read path of default "preferences.txt" file
preferencesFile = BaseNoGui.getSettingsFile(PREFS_FILE);
//## see explanations in processing.app.BaseNoGui below
//## preferencesFile is loaded by C:\Users\<>\AppData\Roaming\Arduino15\preferences.txt
//## and "settings.path" parameter is ignored
}

try {
BaseNoGui.getPlatform().fixPrefsFilePermissions(preferencesFile);
} catch (Exception e) {
//ignore
}

// start by loading the defaults, in case something
// important was deleted from the user prefs
try {
prefs.load(new File(BaseNoGui.getContentFile("lib"), PREFS_FILE));
} catch (IOException e) {
BaseNoGui.showError(null, _("Could not read default settings.\n" +
"You'll need to reinstall Arduino."), e);
}

// set some runtime constants (not saved on preferences file)
File hardwareFolder = BaseNoGui.getHardwareFolder();
prefs.put("runtime.ide.path", hardwareFolder.getParentFile().getAbsolutePath());
prefs.put("runtime.ide.version", "" + BaseNoGui.REVISION);

// clone the hash table
defaults = new PreferencesMap(prefs);

if (preferencesFile.exists()) {
// load the previous preferences file
try {
prefs.load(preferencesFile);
} catch (IOException ex) {
BaseNoGui.showError(_("Error reading preferences"),
I18n.format(_("Error reading the preferences file. "
+ "Please delete (or move)\n"
+ "{0} and restart Arduino."),
preferencesFile.getAbsolutePath()), ex);
}
}

// load the I18n module for internationalization
try {
I18n.init(get("editor.languages.current"));
} catch (MissingResourceException e) {
I18n.init("en");
set("editor.languages.current", "en");
}

// set some other runtime constants (not saved on preferences file)
set("runtime.os", PConstants.platformNames[PApplet.platform]);

fixPreferences();
}
```

**`processing.app.BaseNoGui` class** :

``` java
static public File getSettingsFile(String filename) {
return new File(getSettingsFolder(), filename);
}

static public File getSettingsFolder() {
if (getPortableFolder() != null)
return getPortableFolder();

File settingsFolder = null;

//########################################################
//## here PreferencesData class is not yet loaded :
//## so PreferencesData.get("settings.path") returns null value
String preferencesPath = PreferencesData.get("settings.path");
if (preferencesPath != null) {
settingsFolder = absoluteFile(preferencesPath);

} else {
try {
settingsFolder = getPlatform().getSettingsFolder();
//########################################################
//## so settingsFolder is initialized by getPlatform().getSettingsFolder()
//## the value is read in Windows registry :
//## HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\AppData
//## there is after a concatenation with Arduino15
//## e.g. : C:\Users\<>\AppData\Roaming\Arduino15
} catch (Exception e) {
showError(_("Problem getting data folder"),
_("Error getting the Arduino data folder."), e);
}
}

// create the folder if it doesn't exist already
if (!settingsFolder.exists()) {
if (!settingsFolder.mkdirs()) {
showError(_("Settings issues"),
_("Arduino cannot run because it could not\n" +
"create a folder to store your settings."), null);
}
}
return settingsFolder;
}
```

Contributor guide

Open the contributing guide

Research direction

Start with processing.app.PreferencesData.init and processing.app.BaseNoGui.getSettingsFolder, using the shown startup path from lib/preferences.txt. Trace how settings.path is read before PreferencesData is initialized and verify that the configured folder is used at startup instead of the platform default. Done means a configured settings.path is honored when Arduino launches.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.