summaryrefslogtreecommitdiff
blob: 084059b73aa6f4ee094497a8a2ccfd5c766a2b00 (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
compile-time configurable state directory

From: eroen <eroen@occam.eroen.eu>

It'd be nice to write stuff somewhere writeable.
---
 CMakeLists.txt            |    4 ++++
 library/Console-linux.cpp |    4 ++++
 library/Core.cpp          |    8 ++++++++
 library/Hooks-egg.cpp     |    4 ++++
 library/Hooks-linux.cpp   |    4 ++++
 5 files changed, 24 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 77a8d97..73a4ac1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -64,6 +64,10 @@ SET(DFHACK_RELEASE "r3" CACHE STRING "Current release revision.")
 set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}")
 add_definitions(-DDFHACK_VERSION="${DFHACK_VERSION}")
 
+## where persistent things are written (and read) at runtime
+SET(DFHACK_STATEDIR "." CACHE PATH "DFHACK_STATEDIR")
+ADD_DEFINITIONS(-DDFHACK_STATEDIR="${DFHACK_STATEDIR}")
+
 ## where to install things (after the build is done, classic 'make install' or package structure)
 # the dfhack libraries will be installed here:
 IF(UNIX)
diff --git a/library/Console-linux.cpp b/library/Console-linux.cpp
index f32fa1c..be8d13b 100644
--- a/library/Console-linux.cpp
+++ b/library/Console-linux.cpp
@@ -658,7 +658,11 @@ bool Console::init(bool sharing)
         inited = false;
         return false;
     }
+    #ifdef DFHACK_STATEDIR
+    if (!freopen(DFHACK_STATEDIR "/stdout.log", "w", stdout))
+    #else
     if (!freopen("stdout.log", "w", stdout))
+    #endif
         ;
     d = new Private();
     // make our own weird streams so our IO isn't redirected
diff --git a/library/Core.cpp b/library/Core.cpp
index 89130a9..978fccd 100644
--- a/library/Core.cpp
+++ b/library/Core.cpp
@@ -769,7 +769,11 @@ void fIOthread(void * iodata)
     PluginManager * plug_mgr = ((IODATA*) iodata)->plug_mgr;
 
     CommandHistory main_history;
+    #ifdef DFHACK_STATEDIR
+    main_history.load(DFHACK_STATEDIR "/dfhack.history");
+    #else
     main_history.load("dfhack.history");
+    #endif
 
     Console & con = core->getConsole();
     if(plug_mgr == 0 || core == 0)
@@ -802,7 +806,11 @@ void fIOthread(void * iodata)
         {
             // a proper, non-empty command was entered
             main_history.add(command);
+            #ifdef DFHACK_STATEDIR
+            main_history.save(DFHACK_STATEDIR "/dfhack.history");
+            #else
             main_history.save("dfhack.history");
+            #endif
         }
         
         auto rv = core->runCommand(con, command);
diff --git a/library/Hooks-egg.cpp b/library/Hooks-egg.cpp
index c98cf5d..90df6af 100644
--- a/library/Hooks-egg.cpp
+++ b/library/Hooks-egg.cpp
@@ -37,7 +37,11 @@ distribution.
 DFhackCExport int egg_init(void)
 {
     // reroute stderr
+    #ifdef DFHACK_STATEDIR
+    freopen(DFHACK_STATEDIR "/stderr.log", "w", stderr);
+    #else
     freopen("stderr.log", "w", stderr);
+    #endif
     // we don't reroute stdout until  we figure out if this should be done at all
     // See: Console-linux.cpp
     fprintf(stderr,"dfhack: hooking successful\n");
diff --git a/library/Hooks-linux.cpp b/library/Hooks-linux.cpp
index 31c0323..42d86f3 100644
--- a/library/Hooks-linux.cpp
+++ b/library/Hooks-linux.cpp
@@ -114,7 +114,11 @@ static int (*_SDL_Init)(uint32_t flags) = 0;
 DFhackCExport int SDL_Init(uint32_t flags)
 {
     // reroute stderr
+    #ifdef DFHACK_STATEDIR
+    freopen(DFHACK_STATEDIR "/stderr.log", "w", stderr);
+    #else
     freopen("stderr.log", "w", stderr);
+    #endif
     // we don't reroute stdout until  we figure out if this should be done at all
     // See: Console-linux.cpp