| 35 | |
| 36 | |
| 37 | static public void init(File file) throws Exception { |
| 38 | if (file == null) { |
| 39 | BaseNoGui.getPlatform().fixSettingsLocation(); |
| 40 | } |
| 41 | if (file != null) { |
| 42 | preferencesFile = file; |
| 43 | } else { |
| 44 | preferencesFile = BaseNoGui.getSettingsFile(PREFS_FILE); |
| 45 | } |
| 46 | |
| 47 | try { |
| 48 | BaseNoGui.getPlatform().fixPrefsFilePermissions(preferencesFile); |
| 49 | } catch (Exception e) { |
| 50 | //ignore |
| 51 | } |
| 52 | |
| 53 | // Start with a clean slate |
| 54 | prefs = new PreferencesMap(); |
| 55 | |
| 56 | // start by loading the defaults, in case something |
| 57 | // important was deleted from the user prefs |
| 58 | try { |
| 59 | prefs.load(new File(BaseNoGui.getContentFile("lib"), PREFS_FILE)); |
| 60 | } catch (IOException e) { |
| 61 | BaseNoGui.showError(null, tr("Could not read default settings.\n" + |
| 62 | "You'll need to reinstall Arduino."), e); |
| 63 | } |
| 64 | |
| 65 | // set some runtime constants (not saved on preferences file) |
| 66 | File hardwareFolder = BaseNoGui.getHardwareFolder(); |
| 67 | prefs.put("runtime.ide.path", hardwareFolder.getParentFile().getAbsolutePath()); |
| 68 | prefs.put("runtime.ide.version", "" + BaseNoGui.REVISION); |
| 69 | |
| 70 | // clone the hash table |
| 71 | defaults = new PreferencesMap(prefs); |
| 72 | |
| 73 | if (preferencesFile.exists()) { |
| 74 | // load the previous preferences file |
| 75 | try { |
| 76 | prefs.load(preferencesFile); |
| 77 | } catch (IOException ex) { |
| 78 | BaseNoGui.showError(tr("Error reading preferences"), |
| 79 | I18n.format(tr("Error reading the preferences file. " |
| 80 | + "Please delete (or move)\n" |
| 81 | + "{0} and restart Arduino."), |
| 82 | preferencesFile.getAbsolutePath()), ex); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | // load the I18n module for internationalization |
| 87 | String lang = get("editor.languages.current"); |
| 88 | if (lang == null || !Languages.have(lang)) { |
| 89 | lang = ""; |
| 90 | set("editor.languages.current", ""); |
| 91 | } |
| 92 | try { |
| 93 | I18n.init(lang); |
| 94 | } catch (MissingResourceException e) { |