00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "ExCOptions.h"
00025
00026 ExCOptions::ExCOptions () {
00027 type_of_debug = EXC_NORMAL;
00028 #ifdef UNIX_SRC
00029 std::string where = getenv ("HOME");
00030 where += EXNIHILO_REP_NAME;
00031 where += "/options";
00032 options_file = new ExCFile (where);
00033 #endif
00034
00035
00036 resolution_x = 800;
00037 resolution_y = 600;
00038 depth = 16;
00039 rate = 75;
00040
00041 fullscreen = "yes";
00042 fps = "yes";
00043
00044 debug_style = EXC_NORMAL;
00045 }
00046
00047 bool ExCOptions::create_options_file (void) {
00048 #ifdef UNIX_SRC
00049 std::string where = getenv ("HOME");
00050 where += EXNIHILO_REP_NAME;
00051
00052
00053 struct stat stbuf;
00054 if (stat (where.data (), &stbuf) == 0) {
00055 if (! S_ISDIR (stbuf.st_mode)) {
00056 std::cout << where << " is not a directory, please remove it !!!"
00057 << std::endl;
00058 return false;
00059 } else {
00060 std::cout << where << " created" << std::endl;
00061 }
00062 } else {
00063 if (mkdir (where.data (), 0755) != 0) {
00064 std::cout << "Can not create " << where << std::endl;
00065 return false;
00066 } else {
00067 std::cout << where << " created" << std::endl;
00068 }
00069 }
00070
00071 options_file->add ("# ExNihilo Options file");
00072 options_file->add ("# you can comment a line with '#'");
00073 options_file->addLine ();
00074
00075
00076 options_file->add ("# type of debug : NORMAL, DEBUG, TRACE, LOG");
00077 options_file->add ("# you need to compile ExNihilo with debug enabled to use this option");
00078 options_file->add ("debug.type: NORMAL");
00079 options_file->addLine ();
00080
00081
00082 options_file->add ("# resolution of the screen : format WidthxHeigth:bpp@frequency");
00083 options_file->add ("# WARNING: a too big frequency may damage your screen and/or video card");
00084 options_file->add ("screen.resolution: 800x600:16@75");
00085 options_file->addLine ();
00086 options_file->add ("# start in fullscreen ? [true|false]");
00087 options_file->add ("screen.fullscreen: yes");
00088 options_file->addLine ();
00089 options_file->add ("# show fps ? [true|false]");
00090 options_file->add ("screen.fps: yes");
00091 options_file->addLine ();
00092
00093 #endif // UNIX_SRC
00094
00095 return true;
00096 }
00097
00098 bool ExCOptions::init (void) {
00099 #ifdef UNIX_SRC
00100 options_file->setOpenMode (RO);
00101 if (! options_file->exist ()) {
00102 create_options_file ();
00103 }
00104 #endif
00105 load (EXC_OPTIONS_ALL);
00106
00107 return true;
00108 }
00109
00110 bool ExCOptions::load (int type) {
00111 #ifdef UNIX_SRC
00112 options_file->setOpenMode (RO);
00113
00114 std::vector<std::string> v = options_file->getContent ();
00115
00116 std::vector<std::string>::iterator i = v.begin ();
00117 std::string analyze;
00118 while (i != v.end ()) {
00119 analyze = *i++;
00120 if (analyze[0] == '#')
00121
00122 continue;
00123 else {
00124 if (analyze.find ('.') < analyze.size ()) {
00125 string type = analyze.substr (0, analyze.find ('.'));
00126 string under_type = analyze.substr (analyze.find ('.') + 1, analyze.size ());
00127 under_type = analyze.substr (analyze.find ('.') + 1, analyze.find (':') - analyze.find ('.') - 1);
00128 string value = analyze.substr (analyze.find (':') + 2, analyze.size ());
00129
00130 if (type == "debug") {
00131 if (under_type == "type") {
00132 if (value == "NORMAL")
00133 debug_style = EXC_NORMAL;
00134 else if (value == "DEBUG")
00135 debug_style = EXC_DEBUG;
00136 else if (value == "TRACE")
00137 debug_style = EXC_TRACE;
00138 else if (value == "LOG")
00139 debug_style = EXC_LOG;
00140 }
00141 } else if (type == "screen") {
00142 if (under_type == "resolution") {
00143 resolution_x = atoi (value.substr (0, value.find ('x')).data ());
00144 value.erase (0, value.find ('x') + 1);
00145 resolution_y = atoi (value.substr (0, value.find (':')).data ());
00146 value.erase (0, value.find (':') + 1);
00147 depth = atoi (value.substr (0, value.find ('@')).data ());
00148 value.erase (0, value.find ('@') + 1);
00149 rate = atoi (value.data ());
00150 } else if (under_type == "fullscreen") {
00151 fullscreen = value;
00152 } else if (under_type == "fps") {
00153 fps = value;
00154 }
00155 }
00156 }
00157 }
00158 }
00159 #endif
00160 return true;
00161 }
00162
00163 bool ExCOptions::load (void) {
00164 return load (EXC_OPTIONS_ALL);
00165 }
00166
00167 bool ExCOptions::reload (void) {
00168 return load (EXC_OPTIONS_RELOAD);
00169 }
00170
00171 bool ExCOptions::getWindowFullscreen (void) {
00172 return (fullscreen == "yes") ? true : false;
00173 }
00174
00175 bool ExCOptions::getWindowShowfps (void) {
00176 return (fps == "yes") ? true : false;
00177 }