# Copyright (C) 2007  Peter De Wachter <pdewacht@gmail.com>
# Distributed under the same license as the game. See debian/copyright.

Index: titanion_0.3.dfsg1/src/abagames/ttn/replay.d
===================================================================
--- titanion_0.3.dfsg1.orig/src/abagames/ttn/replay.d	2007-08-26 22:20:21.000000000 +0200
+++ titanion_0.3.dfsg1/src/abagames/ttn/replay.d	2007-08-26 22:20:26.000000000 +0200
@@ -8,13 +8,13 @@
 private import std.stream;
 private import abagames.util.sdl.pad;
 private import abagames.util.sdl.recordableinput;
+private import abagames.ttn.preference;
 
 /**
  * Save/Load a replay data.
  */
 public class ReplayData {
  public:
-  static const char[] DIR = "replay";
   static const int VERSION_NUM = 30;
   InputRecord!(PadState) inputRecord;
   long seed;
@@ -24,7 +24,7 @@
  private:
 
   public void save(char[] fileName) {
-    auto File fd = new File(DIR ~ "/" ~ fileName, FileMode.OutNew);
+    auto File fd = new File(Preference.pref_dir() ~ "/" ~ fileName, FileMode.OutNew);
     fd.write(VERSION_NUM);
     fd.write(seed);
     fd.write(score);
@@ -35,7 +35,7 @@
   }
 
   public void load(char[] fileName) {
-    auto File fd = new File(DIR ~ "/" ~ fileName, FileMode.In);
+    auto File fd = new File(Preference.pref_dir() ~ "/" ~ fileName, FileMode.In);
     int ver;
     fd.read(ver);
     if (ver != VERSION_NUM)
Index: titanion_0.3.dfsg1/src/abagames/ttn/preference.d
===================================================================
--- titanion_0.3.dfsg1.orig/src/abagames/ttn/preference.d	2007-08-26 22:20:21.000000000 +0200
+++ titanion_0.3.dfsg1/src/abagames/ttn/preference.d	2007-08-26 23:15:14.000000000 +0200
@@ -6,6 +6,9 @@
 module abagames.ttn.preference;
 
 private import std.stream;
+private import std.file;
+private import std.c.stdlib;
+private import std.string;
 private import abagames.util.preference;
 
 /**
@@ -21,10 +24,24 @@
   int[RANKING_NUM][MODE_NUM] _highScore;
   int _lastMode;
 
+  public static char[] pref_dir()
+  {
+    char * home = getenv("HOME");
+    if (home is null)
+      throw new Error("HOME environment variable not defined");
+    char[] dir = std.string.toString(home) ~ "/.titanion";
+    try {
+      mkdir(dir);
+    } catch (FileException e) {
+    }
+    return dir;
+  }
+
+
   public void load() {
     auto File fd = null;
     try {
-      fd = new File(PREF_FILE_NAME, FileMode.In);
+      fd = new File(pref_dir() ~ "/" ~ PREF_FILE_NAME, FileMode.In);
       int ver;
       fd.read(ver);
       if (ver != VERSION_NUM)
@@ -50,7 +67,7 @@
   }
 
   public void save() {
-    auto File fd = new File(PREF_FILE_NAME, FileMode.OutNew);
+    auto File fd = new File(pref_dir() ~ "/" ~ PREF_FILE_NAME, FileMode.OutNew);
     fd.write(VERSION_NUM);
     fd.write(_lastMode);
     for(int j = 0; j < MODE_NUM; j++)
