/* Copyright (C) 2001-2004 Stephane Magnenat & Luc-Olivier de Charrière for any question or comment contact us at or This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Settings.h" #include "Utilities.h" #include #include #include #include #include #include #include "boost/lexical_cast.hpp" using namespace GAGCore; Settings::Settings() { // set default values in settings or load them char *newUsername; # ifdef WIN32 newUsername=getenv("USERNAME"); # else // angel > case of unix and MacIntosh Systems newUsername=getenv("USER"); # endif if (!newUsername) newUsername="player"; username=newUsername; screenFlags = GraphicContext::RESIZABLE | GraphicContext::CUSTOMCURSOR; screenWidth = 640; screenHeight = 480; optionFlags = 0; defaultLanguage = 0; musicVolume = 255; mute = 0; rememberUnit = 1; tempUnit = 1; tempUnitFuture = 1; scrollWheelEnabled=true; for(int n=0; n parsed; InputStream *stream = new BinaryInputStream(Toolkit::getFileManager()->openInputStreamBackend(filename)); if (stream->isEndOfStream()) { std::cerr << "Settings::load(\"" << filename << "\") : error, can't open file." << std::endl; } else { // load and parse file char *dest, *varname, *token; char buffer[256]; while ((dest = Utilities::gets(buffer, 256, stream))!=NULL) { token = strtok(dest,"\t\n\r=;"); if ((!token) || (strcmp(token,"//")==0)) continue; varname = token; token = strtok(NULL,"\t\n\r="); if (token) parsed[varname] = token; } // read values READ_PARSED_STRING(username); READ_PARSED_STRING(password); READ_PARSED_INT(screenWidth); READ_PARSED_INT(screenHeight); READ_PARSED_INT(screenFlags); READ_PARSED_INT(optionFlags); READ_PARSED_INT(defaultLanguage); READ_PARSED_INT(musicVolume); READ_PARSED_INT(mute); READ_PARSED_INT(rememberUnit); READ_PARSED_INT(scrollWheelEnabled); for(int n=0; n(n)+"]["+boost::lexical_cast(t)+"]"; if(parsed.find(keyname)!=parsed.end()) defaultUnitsAssigned[n][t] = boost::lexical_cast(parsed[keyname]); } } READ_PARSED_INT(cloudPatchSize); READ_PARSED_INT(cloudMaxAlpha); READ_PARSED_INT(cloudMaxSpeed); READ_PARSED_INT(cloudWindStability); READ_PARSED_INT(cloudStability); READ_PARSED_INT(cloudSize); READ_PARSED_INT(cloudHeight); } delete stream; } void Settings::save(const char *filename) { OutputStream *stream = new BinaryOutputStream(Toolkit::getFileManager()->openOutputStreamBackend(filename)); // std::fstream f(filename); if (stream->isEndOfStream()) // if (!f.is_open()) { //std::cerr << "Settings::save(\"" << filename << "\") : error, can't open file." << std::endl; } else { Utilities::streamprintf(stream, "username=%s\n", username.c_str()); Utilities::streamprintf(stream, "password=%s\n", password.c_str()); Utilities::streamprintf(stream, "screenWidth=%d\n", screenWidth); Utilities::streamprintf(stream, "screenHeight=%d\n", screenHeight); Utilities::streamprintf(stream, "screenFlags=%d\n", screenFlags); Utilities::streamprintf(stream, "optionFlags=%d\n", optionFlags); Utilities::streamprintf(stream, "defaultLanguage=%d\n", defaultLanguage); Utilities::streamprintf(stream, "musicVolume=%d\n", musicVolume); Utilities::streamprintf(stream, "mute=%d\n", mute); Utilities::streamprintf(stream, "rememberUnit=%d\n", rememberUnit); Utilities::streamprintf(stream, "scrollWheelEnabled=%d\n", scrollWheelEnabled); for(int n=0; n(n)+"]["+boost::lexical_cast(t)+"]"; Utilities::streamprintf(stream, "%s=%i\n", keyname.c_str(), defaultUnitsAssigned[n][t]); } } Utilities::streamprintf(stream, "cloudPatchSize=%d\n", cloudPatchSize); Utilities::streamprintf(stream, "cloudMaxAlpha=%d\n", cloudMaxAlpha); Utilities::streamprintf(stream, "cloudMaxSpeed=%d\n", cloudMaxSpeed); Utilities::streamprintf(stream, "cloudWindStability=%d\n", cloudWindStability); Utilities::streamprintf(stream, "cloudStability=%d\n", cloudStability); Utilities::streamprintf(stream, "cloudSize=%d\n", cloudSize); Utilities::streamprintf(stream, "cloudHeight=%d\n", cloudHeight); } delete stream; }