Package: parsec47 / 0.2.dfsg1-6

dotfile.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
61
62
63
64
# Copyright (C) 2007  Peter De Wachter <pdewacht@gmail.com>
# Distributed under the same license as the game. See debian/copyright.

--- a/src/abagames/p47/P47PrefManager.d
+++ b/src/abagames/p47/P47PrefManager.d
@@ -7,6 +7,8 @@
 
 private:
 import std.stream;
+import std.string;
+import std.c.stdlib;
 import abagames.util.PrefManager;
 
 /**
@@ -16,7 +18,7 @@
  public:
   static const int PREV_VERSION_NUM = 10;
   static const int VERSION_NUM = 20;
-  static const char[] PREF_FILE = "p47.prf";
+  static const char[] PREF_FILE = ".p47.prf";
   static const int MODE_NUM = 2;
   static const int DIFFICULTY_NUM = 4;
   static const int REACHED_PARSEC_SLOT_NUM = 10;
@@ -24,6 +26,13 @@
   int reachedParsec[MODE_NUM][DIFFICULTY_NUM];
   int selectedDifficulty, selectedParsecSlot, selectedMode;
 
+  public static char[] home_dir() {
+    char * home = getenv("HOME");
+    if (home is null)
+      throw new Error("HOME environment variable is not defined");
+    return std.string.toString(home);
+  }
+
   private void init() {
     for (int k = 0; k < MODE_NUM; k++) {
       for (int i = 0; i < DIFFICULTY_NUM; i++) {
@@ -53,7 +62,7 @@
     auto File fd = new File;
     try {
       int ver;
-      fd.open(PREF_FILE);
+      fd.open(home_dir() ~ "/" ~ PREF_FILE);
       fd.read(ver);
       if (ver == PREV_VERSION_NUM) {
 	init();
@@ -74,7 +83,7 @@
       fd.read(selectedDifficulty);
       fd.read(selectedParsecSlot);
       fd.read(selectedMode);
-    } catch (Error e) {
+    } catch (Exception e) {
       init();
     } finally {
       fd.close();
@@ -83,7 +92,7 @@
 
   public void save() {
     auto File fd = new File;
-    fd.create(PREF_FILE);
+    fd.create(home_dir ~ "/" ~ PREF_FILE);
     fd.write(VERSION_NUM);
     for (int k = 0; k < MODE_NUM; k++) {
       for (int i = 0; i < DIFFICULTY_NUM; i++) {