diff -urN megaglest-source-3.4.0.old/source/glest_game/ai/ai_interface.h megaglest-source-3.4.0/source/glest_game/ai/ai_interface.h --- megaglest-source-3.4.0.old/source/glest_game/ai/ai_interface.h 2011-02-04 18:30:23.000000000 +0300 +++ megaglest-source-3.4.0/source/glest_game/ai/ai_interface.h 2011-02-04 18:33:08.000000000 +0300 @@ -95,7 +95,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+="/.megaglest/ai"+intToStr(factionIndex)+".log"; + return logfn; + } bool executeCommandOverNetwork(); }; diff -urN megaglest-source-3.4.0.old/source/glest_game/main/main.cpp megaglest-source-3.4.0/source/glest_game/main/main.cpp --- megaglest-source-3.4.0.old/source/glest_game/main/main.cpp 2011-02-04 18:30:23.000000000 +0300 +++ megaglest-source-3.4.0/source/glest_game/main/main.cpp 2011-02-04 18:33:08.000000000 +0300 @@ -1408,6 +1408,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/.megaglest", getenv("HOME")); + mkdir(path, 0750); + + snprintf(path, PATH_MAX, "%s/.megaglest/screens", getenv("HOME")); + mkdir(path, 0750); + + chdir("@GENTOO_DATADIR@"); #ifdef SL_LEAK_DUMP AllocRegistry memoryLeaks = AllocRegistry::getInstance(); #endif diff -urN megaglest-source-3.4.0.old/source/glest_game/main/program.cpp megaglest-source-3.4.0/source/glest_game/main/program.cpp --- megaglest-source-3.4.0.old/source/glest_game/main/program.cpp 2011-02-04 18:30:23.000000000 +0300 +++ megaglest-source-3.4.0/source/glest_game/main/program.cpp 2011-02-04 18:33:08.000000000 +0300 @@ -488,7 +488,9 @@ //log start Logger &logger= Logger::getInstance(); - string logFile = "glest.log"; + string a=getenv("HOME"); + string b= "/.megaglest/glest.log"; + string logFile = a+b; if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") { logFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + logFile; } diff -urN megaglest-source-3.4.0.old/source/shared_lib/sources/util/leak_dumper.cpp megaglest-source-3.4.0/source/shared_lib/sources/util/leak_dumper.cpp --- megaglest-source-3.4.0.old/source/shared_lib/sources/util/leak_dumper.cpp 2011-02-04 18:30:23.000000000 +0300 +++ megaglest-source-3.4.0/source/shared_lib/sources/util/leak_dumper.cpp 2011-02-04 18:33:08.000000000 +0300 @@ -43,7 +43,9 @@ AllocRegistry::~AllocRegistry(){ - dump("leak_dump.log"); + char path[PATH_MAX]; + snprintf(path, PATH_MAX, "%s/.megaglest/leak_dump.log", getenv("HOME")); + dump(path); } void AllocRegistry::allocate(AllocInfo info){ diff -urN megaglest-source-3.4.0.old/source/shared_lib/sources/util/profiler.cpp megaglest-source-3.4.0/source/shared_lib/sources/util/profiler.cpp --- megaglest-source-3.4.0.old/source/shared_lib/sources/util/profiler.cpp 2011-02-04 18:30:23.000000000 +0300 +++ megaglest-source-3.4.0/source/shared_lib/sources/util/profiler.cpp 2011-02-04 18:33:08.000000000 +0300 @@ -76,9 +76,11 @@ if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") { profileLog = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + profileLog; } - FILE *f= fopen(profileLog.c_str(), "w"); + char path[PATH_MAX]; + snprintf(path, PATH_MAX, "%s/.magaglest/profiler.log", getenv("HOME")); + FILE *f= fopen(path, "w"); if(f==NULL) - throw runtime_error("Can not open file: " + profileLog); + throw runtime_error("Can not open file: %s",path); fprintf(f, "Profiler Results\n\n"); diff -urN megaglest-source-3.4.0.old/source/shared_lib/sources/util/properties.cpp megaglest-source-3.4.0/source/shared_lib/sources/util/properties.cpp --- megaglest-source-3.4.0.old/source/shared_lib/sources/util/properties.cpp 2011-02-04 18:30:23.000000000 +0300 +++ megaglest-source-3.4.0/source/shared_lib/sources/util/properties.cpp 2011-02-04 18:33:08.000000000 +0300 @@ -14,7 +14,8 @@ #include #include #include - +#include +#include #include "conversion.h" #include "util.h" #include "leak_dumper.h" @@ -38,10 +39,15 @@ //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); - fileStream.open(path.c_str(), ios_base::in); + char str[PATH_MAX]; + snprintf(str, PATH_MAX, "%s/.megaglest/%s", getenv("HOME"), path.c_str()); + fileStream.open(str, ios_base::in); if(fileStream.fail()){ - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); - throw runtime_error("Can't open propertyMap file: " + path); + fileStream.open(path.c_str(), ios_base::in); // use defaults + if(fileStream.fail()){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); + throw runtime_error("Can't open propertyMap file: " + path + " cwd: "+ getenv("PWD")); + } } //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str()); @@ -78,7 +84,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/.megaglest/%s", getenv("HOME"), path.c_str()); + fileStream.open(str, ios_base::out | ios_base::trunc); fileStream << "; === propertyMap File === \n"; fileStream << '\n';