1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.ninjasoft.igallery.data;
18
19 import java.util.*;
20 import java.io.*;
21
22 /***
23 * Class to load/save application properties. It is mindful of the
24 * multiuser nature of the OS and sets permissions on the saved file
25 * such that nobody else can read it (because it may contain a password).
26 *
27 * @author enigma
28 */
29 public class ApplicationProperties extends Properties {
30 private String filename = "";
31 public ApplicationProperties() throws IOException {
32 super();
33 filename = System.getProperty("user.home") + "/Library/Preferences/org.ninjasoft.igallery.properties";
34 this.load();
35 }
36
37 public void load() throws IOException {
38 File f = new File(filename);
39 InputStream in = null;
40 if (!f.exists())
41 return;
42 in = new FileInputStream(f);
43 this.load(in);
44 in.close();
45 }
46
47 public void save() throws IOException {
48 File saveFile = new File(filename);
49 File tempFile = new File(filename + ".temp");
50 if (tempFile.exists())
51 tempFile.delete();
52 tempFile.createNewFile();
53
54 Runtime.getRuntime().exec("/bin/chmod 600 " + tempFile.getCanonicalPath());
55 OutputStream out = new FileOutputStream(tempFile, true);
56 this.store(out, "");
57 out.close();
58 saveFile.delete();
59 tempFile.renameTo(saveFile);
60
61 Runtime.getRuntime().exec("/bin/chmod 600 " + saveFile.getCanonicalPath());
62 }
63 }