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
|
--- source/glest_game/main/main.cpp
+++ source/glest_game/main/main.cpp
@@ -13,6 +13,7 @@
#include <string>
#include <cstdlib>
+#include <sys/stat.h>
#include "game.h"
#include "main_menu.h"
@@ -129,6 +130,17 @@
ExceptionHandler exceptionHandler;
exceptionHandler.install();
+ if (!getenv("HOME"))
+ throw runtime_error("HOME not set!");
+
+ char str[PATH_MAX];
+ snprintf(str, PATH_MAX, "%s/.glest", getenv("HOME"));
+ mkdir(str, 0750);
+ chdir(str);
+ mkdir("screens", 0750);
+
+ chdir("GENTOO_DATADIR");
+
try{
Config &config = Config::getInstance();
--- source/glest_game/main/program.cpp
+++ source/glest_game/main/program.cpp
@@ -65,8 +65,11 @@
updateCameraTimer.init(config.getInt("CameraFps"), maxTimes);
//log start
+ char str[PATH_MAX];
+ snprintf(str, PATH_MAX, "%s/.glest/glest.log", getenv("HOME"));
+
Logger &logger= Logger::getInstance();
- logger.setFile("glest.log");
+ logger.setFile(str);
logger.clear();
srand(time(NULL));
@@ -134,9 +137,10 @@
//save screen
if(key=='T'){
for(int i=0; i<100; ++i){
- string path= "screens/screen" + intToStr(i) + ".tga";
+ char path[PATH_MAX];
+ snprintf(path, PATH_MAX, "%s/.glest/screens/screen%d.tga", getenv("HOME"), i);
- FILE *f= fopen(path.c_str(), "rb");
+ FILE *f= fopen(path, "rb");
if(f==NULL){
Renderer::getInstance().saveScreen(path);
break;
--- source/shared_lib/sources/util/properties.cpp
+++ source/shared_lib/sources/util/properties.cpp
@@ -33,9 +33,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 properties file: " + path);
+ fileStream.open(path.c_str(), ios_base::in); // use defaults
+ if(fileStream.fail())
+ throw runtime_error("Can't open properties file: " + path);
}
properties.clear();
@@ -70,7 +74,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 << "; === Properties File === \n";
fileStream << '\n';
|