MCPcopy Index your code
hub / github.com/benfry/processing4 / save

Method save

app/src/processing/app/Preferences.java:222–266  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

220
221
222 static public void save() {
223 // On startup, this is null, but ignore it. It's trying to update the
224 // prefs for the open sketch before Preferences.init() has been called.
225 if (preferencesFile != null) {
226 try {
227 File dir = preferencesFile.getParentFile();
228 File preferencesTemp = File.createTempFile("preferences", ".txt", dir);
229 if (!preferencesTemp.setWritable(true, false)) {
230 throw new IOException("Could not set " + preferencesTemp + " writable");
231 }
232
233 // Fix for 0163 to properly use Unicode when writing preferences.txt
234 PrintWriter writer = PApplet.createWriter(preferencesTemp);
235
236 String[] keyList = table.keySet().toArray(new String[0]);
237 // Sorting is really helpful for debugging, diffing, and finding keys
238 keyList = PApplet.sort(keyList);
239 for (String key : keyList) {
240 writer.println(key + "=" + table.get(key)); //$NON-NLS-1$
241 }
242 writer.flush();
243 writer.close();
244
245 // Rename preferences.txt to preferences.old
246 File oldPreferences = new File(dir, "preferences.old");
247 if (oldPreferences.exists()) {
248 if (!oldPreferences.delete()) {
249 throw new IOException("Could not delete preferences.old");
250 }
251 }
252 if (preferencesFile.exists() &&
253 !preferencesFile.renameTo(oldPreferences)) {
254 throw new IOException("Could not replace preferences.old");
255 }
256 // Make the temporary file into the real preferences
257 if (!preferencesTemp.renameTo(preferencesFile)) {
258 throw new IOException("Could not move preferences file into place");
259 }
260
261 } catch (IOException e) {
262 Messages.showWarning("Preferences",
263 "Could not save the Preferences file.", e);
264 }
265 }
266 }
267
268
269 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Callers 8

clearRunningMethod · 0.95
startServerMethod · 0.95
initMethod · 0.95
handleQuitMethod · 0.95
setCurrentIndexMethod · 0.95
handleCloseMethod · 0.95
applyFrameMethod · 0.95
updateExpandedMethod · 0.95

Calls 11

createWriterMethod · 0.95
sortMethod · 0.95
showWarningMethod · 0.95
createTempFileMethod · 0.80
renameToMethod · 0.80
getMethod · 0.65
toArrayMethod · 0.45
printlnMethod · 0.45
flushMethod · 0.45
closeMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected