|
|
| |
#include <string> | #include <string> |
#include <cstdlib> | #include <cstdlib> |
|
#include <sys/stat.h> |
| |
#include "game.h" | #include "game.h" |
#include "main_menu.h" | #include "main_menu.h" |
|
|
ExceptionHandler exceptionHandler; | ExceptionHandler exceptionHandler; |
exceptionHandler.install(); | 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{ | try{ |
Config &config = Config::getInstance(); | Config &config = Config::getInstance(); |
| |
|
|
updateCameraTimer.init(config.getInt("CameraFps"), maxTimes); | updateCameraTimer.init(config.getInt("CameraFps"), maxTimes); |
| |
//log start | //log start |
|
char str[PATH_MAX]; |
|
snprintf(str, PATH_MAX, "%s/.glest/glest.log", getenv("HOME")); |
|
|
Logger &logger= Logger::getInstance(); | Logger &logger= Logger::getInstance(); |
logger.setFile("glest.log"); |
logger.setFile(str); |
logger.clear(); | logger.clear(); |
| |
srand(time(NULL)); | srand(time(NULL)); |
|
|
//save screen | //save screen |
if(key=='T'){ | if(key=='T'){ |
for(int i=0; i<100; ++i){ | 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){ | if(f==NULL){ |
Renderer::getInstance().saveScreen(path); | Renderer::getInstance().saveScreen(path); |
break; | break; |
|
|
| |
this->path= path; | 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()){ | 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(); | properties.clear(); |
|
|
void Properties::save(const string &path){ | void Properties::save(const string &path){ |
ofstream fileStream; | 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 << "; === Properties File === \n"; |
fileStream << '\n'; | fileStream << '\n'; |