summaryrefslogtreecommitdiffstats
path: root/games/glest/patches/glest-home-directory.patch
blob: a92002ab6080dbffcfe053561e089763ad2f2a1d (about) (plain) (blame)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
--- source/glest_game/ai/ai_interface.h	2009-04-15 11:17:19.000000000 +0400
+++ source/glest_game/ai/ai_interface.h	2009-04-15 12:25:04.000000000 +0400
@@ -84,7 +84,11 @@
 	bool isFreeCells(const Vec2i &pos, int size, Field field);
 
 private:
-	string getLogFilename() const	{return "ai"+intToStr(factionIndex)+".log";}
+	string getLogFilename() const	{
+	  string logfn=getenv("HOME");
+	  logfn+="/.glest/ai"+intToStr(factionIndex)+".log";
+	  return logfn;
+	}
 };
 
 }}//end namespace
--- source/glest_game/ai/ai_rule.cpp	2009-04-15 11:17:19.000000000 +0400
+++ source/glest_game/ai/ai_rule.cpp	2009-04-15 11:19:02.000000000 +0400
@@ -17,6 +17,8 @@
 #include "unit.h"
 #include "leak_dumper.h"
 
+#include <limits.h>
+
 using Shared::Graphics::Vec2i;
 
 namespace Glest{ namespace Game{
--- source/glest_game/game/game.cpp	2009-04-15 11:17:19.000000000 +0400
+++ source/glest_game/game/game.cpp	2009-04-15 12:21:29.000000000 +0400
@@ -443,7 +443,8 @@
 		}
 		else if(key=='E'){
 			for(int i=0; i<100; ++i){
-				string path= "screens/screen" + intToStr(i) + ".tga";
+				string path=getenv("HOME");
+				path+="/.glest/screens/screen" + intToStr(i) + ".tga";
 				
 				FILE *f= fopen(path.c_str(), "rb");
 				if(f==NULL){
--- source/glest_game/main/main.cpp	2009-04-15 11:17:19.000000000 +0400
+++ source/glest_game/main/main.cpp	2009-04-15 12:32:04.000000000 +0400
@@ -114,6 +114,17 @@
 // =====================================================
 
 int glestMain(int argc, char** argv){
+	if (!getenv("HOME"))
+		throw runtime_error("HOME external variable is not set");
+
+	char path[PATH_MAX];
+	snprintf(path, PATH_MAX, "%s/.glest", getenv("HOME"));
+	mkdir(path, 0750);
+
+	snprintf(path, PATH_MAX, "%s/.glest/screens", getenv("HOME"));
+	mkdir(path, 0750);
+
+	chdir("/usr/share/glest");
 
 	MainWindow *mainWindow= NULL;
 	Program *program= NULL;
--- source/glest_game/main/program.cpp	2009-04-15 11:17:19.000000000 +0400
+++ source/glest_game/main/program.cpp	2009-04-15 12:11:51.000000000 +0400
@@ -196,9 +196,11 @@
 	updateTimer.init(GameConstants::updateFps, maxTimes);
 	updateCameraTimer.init(GameConstants::cameraFps, maxTimes);
 
-    //log start
-	Logger &logger= Logger::getInstance();
-	logger.setFile("glest.log");
+    //log start
+ 	char path[PATH_MAX];
+	snprintf(path, PATH_MAX, "%s/.glest/glest.log", getenv("HOME"));
+ 	Logger &logger= Logger::getInstance();
+	logger.setFile(path);
 	logger.clear();
 
 	//lang
--- source/shared_lib/sources/util/leak_dumper.cpp	2009-04-15 11:17:19.000000000 +0400
+++ source/shared_lib/sources/util/leak_dumper.cpp	2009-04-15 12:04:49.000000000 +0400
@@ -52,7 +52,9 @@
 }
 
 AllocRegistry::~AllocRegistry(){
-	dump("leak_dump.log");
+	char path[PATH_MAX];
+	snprintf(path, PATH_MAX, "%s/.glest/leak_dump.log", getenv("HOME"));
+	dump(path);
 }
 
 void AllocRegistry::allocate(AllocInfo info){
--- source/shared_lib/sources/util/profiler.cpp	2009-04-15 11:17:19.000000000 +0400
+++ source/shared_lib/sources/util/profiler.cpp	2009-04-15 12:01:52.000000000 +0400
@@ -71,9 +71,11 @@
 Profiler::~Profiler(){
 	rootSection->stop();
 
-	FILE *f= fopen("profiler.log", "w");
+	char path[PATH_MAX];
+	snprintf(path, PATH_MAX, "%s/.glest/profiler.log", getenv("HOME"));
+	FILE *f= fopen(path, "w");
 	if(f==NULL)
-		throw runtime_error("Can not open file: profiler.log");
+		throw runtime_error("Can not open file: %s",path);
 
 	fprintf(f, "Profiler Results\n\n");
 
--- source/shared_lib/sources/util/properties.cpp	2009-04-15 11:17:19.000000000 +0400
+++ source/shared_lib/sources/util/properties.cpp	2009-04-15 13:09:33.000000000 +0400
@@ -15,6 +15,9 @@
 #include <stdexcept>
 #include <cstring>
 
+#include <limits.h>
+#include <stdlib.h>
+
 #include "conversion.h"
 #include "leak_dumper.h"
 
@@ -34,9 +37,13 @@
 
 	this->path= path;
 
-	fileStream.open(path.c_str(), ios_base::in);
+	char str[PATH_MAX];
+	snprintf(str, PATH_MAX, "%s/.glest/%s", getenv("HOME"), path.c_str());
+	fileStream.open(str, ios_base::in);
 	if(fileStream.fail()){
-		throw runtime_error("Can't open propertyMap file: " + path);
+		fileStream.open(path.c_str(), ios_base::in); // use defaults
+		if(fileStream.fail())
+		throw runtime_error("Can't open propertyMap file: " + path + " cwd: "+ getenv("PWD"));
 	}
 
 	propertyMap.clear();
@@ -71,7 +78,9 @@
 void Properties::save(const string &path){
 	ofstream fileStream;
 
-	fileStream.open(path.c_str(), ios_base::out | ios_base::trunc);
+	char str[PATH_MAX];
+	snprintf(str, PATH_MAX, "%s/.glest/%s", getenv("HOME"), path.c_str());
+	fileStream.open(str, ios_base::out | ios_base::trunc);
 
 	fileStream << "; === propertyMap File === \n";	
 	fileStream << '\n';