Package: projectl / 1.001.dfsg1-7

put_prefs_in_home_dir.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Description: store preferences in ~/.projectl
Author: Peter De Wachter <pdewacht@gmail.com>

--- a/src/br/prefmanager.d
+++ b/src/br/prefmanager.d
@@ -3,6 +3,9 @@
 private import std.stream;
 private import util.record;
 private import br.stage;
+private import std.c.stdlib;
+private import std.string;
+private import std.file;
 
 public class PrefManager{
 	
@@ -19,7 +22,7 @@
 	    auto File fd = new File;
 	    try {
 	      int ver;
-	      fd.open(PREF_FILE);
+	      fd.open(prefDir() ~ "/" ~ PREF_FILE);
 	      fd.read(ver);
 	      if (ver != VERSION_NUM)
 	        throw new Error("Wrong version num");
@@ -33,7 +36,7 @@
  	}
 	public void save(){
 		auto File fd = new File;
-	    fd.create(PREF_FILE);
+	    fd.create(prefDir() ~ "/" ~ PREF_FILE);
 	    fd.write(VERSION_NUM);
 	    _prefData.save(fd);
 	    fd.close();
@@ -41,7 +44,18 @@
 	public PrefData prefData() {
     	return _prefData;
   	}
-	
+
+        static char[] prefDir() {
+            char * home = getenv("HOME");
+            if (home is null)
+                throw new Error("HOME environment variable not defined");
+            char dir[] = std.string.toString(home) ~ "/.projectl";
+            try {
+                mkdir(dir);
+            } catch (FileException e) {
+            }
+            return dir;
+        }
 }
 
 public class PrefData {
@@ -90,4 +104,4 @@
 	public Record record(){
 		return _record;
 	}
-}
\ No newline at end of file
+}