2007-01-21 16:01:37 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
* Copyright (C) 2006 by Felix Hammer *
|
|
|
|
|
* f.hammer@web.de *
|
|
|
|
|
* *
|
|
|
|
|
* 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 2 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 "configfile.h"
|
|
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <fstream>
|
2007-02-02 09:16:27 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#define MODUS 0711
|
2007-01-21 16:01:37 +00:00
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2007-04-13 22:10:55 +00:00
|
|
|
#include <windows.h>
|
2007-01-21 16:01:37 +00:00
|
|
|
#include <direct.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2007-04-18 00:11:24 +00:00
|
|
|
ConfigFile::ConfigFile(std::string path)
|
|
|
|
|
: myPath(path)
|
|
|
|
|
{
|
2007-01-21 16:01:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConfigFile::~ConfigFile()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-03 22:47:16 +00:00
|
|
|
string ConfigFile::readConfigString(string varName)
|
2007-01-21 16:01:37 +00:00
|
|
|
{
|
2007-01-22 21:29:51 +00:00
|
|
|
string tempString("");
|
2007-01-21 16:01:37 +00:00
|
|
|
|
2007-04-18 00:11:24 +00:00
|
|
|
TiXmlDocument doc(myPath.c_str());
|
|
|
|
|
if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << myPath << "\n"; }
|
2007-01-21 16:01:37 +00:00
|
|
|
TiXmlHandle docHandle( &doc );
|
|
|
|
|
|
2007-01-22 21:29:51 +00:00
|
|
|
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement();
|
|
|
|
|
if ( conf ) {
|
2007-01-23 00:49:45 +00:00
|
|
|
const char *tmpStr = conf->Attribute("value");
|
|
|
|
|
if (tmpStr) tempString = tmpStr;
|
|
|
|
|
} /*else {
|
2007-01-22 21:29:51 +00:00
|
|
|
//Wenn nicht gefunden eines neues Anlegen
|
|
|
|
|
TiXmlElement* config = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).ToElement();
|
|
|
|
|
if ( config ) {
|
|
|
|
|
TiXmlElement * confElement1 = new TiXmlElement( varName );
|
|
|
|
|
config->LinkEndChild( confElement1 );
|
|
|
|
|
confElement1->SetAttribute("value", defaultValue);
|
2007-04-18 00:11:24 +00:00
|
|
|
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; }
|
2007-01-22 21:29:51 +00:00
|
|
|
|
|
|
|
|
return readConfigString(varName, defaultValue);
|
|
|
|
|
}
|
2007-01-23 00:49:45 +00:00
|
|
|
}*/
|
2007-01-22 21:29:51 +00:00
|
|
|
|
|
|
|
|
return tempString;
|
2007-01-21 16:01:37 +00:00
|
|
|
}
|
|
|
|
|
|
2007-02-03 22:47:16 +00:00
|
|
|
int ConfigFile::readConfigInt(string varName)
|
2007-01-21 22:44:11 +00:00
|
|
|
{
|
2007-01-22 12:04:47 +00:00
|
|
|
int tempInt=0;
|
2007-01-23 00:49:45 +00:00
|
|
|
// cout << varName << " : " << tempInt << "\n";
|
2007-04-18 00:11:24 +00:00
|
|
|
TiXmlDocument doc(myPath.c_str());
|
|
|
|
|
if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << myPath << "\n"; }
|
2007-01-21 22:44:11 +00:00
|
|
|
TiXmlHandle docHandle( &doc );
|
2007-01-23 00:49:45 +00:00
|
|
|
|
2007-01-21 22:44:11 +00:00
|
|
|
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement();
|
|
|
|
|
if ( conf ) {
|
2007-01-23 00:49:45 +00:00
|
|
|
// cout << varName << " : " << tempInt << "\n";
|
|
|
|
|
conf->QueryIntAttribute("value", &tempInt );
|
|
|
|
|
// cout << varName << " : " << tempInt << "\n";
|
|
|
|
|
} /*else {
|
|
|
|
|
// Wenn nicht gefunden eines neues Anlegen
|
2007-01-22 21:29:51 +00:00
|
|
|
TiXmlElement* config = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).ToElement();
|
|
|
|
|
if ( config ) {
|
|
|
|
|
TiXmlElement * confElement1 = new TiXmlElement( varName );
|
|
|
|
|
config->LinkEndChild( confElement1 );
|
|
|
|
|
confElement1->SetAttribute("value", defaultValue);
|
2007-04-18 00:11:24 +00:00
|
|
|
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; }
|
2007-01-22 21:29:51 +00:00
|
|
|
|
|
|
|
|
return readConfigInt(varName, defaultValue);
|
|
|
|
|
}
|
2007-01-23 00:49:45 +00:00
|
|
|
}*/
|
2007-01-21 22:44:11 +00:00
|
|
|
|
|
|
|
|
return tempInt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-01-22 21:29:51 +00:00
|
|
|
void ConfigFile::writeConfigInt(string varName, int varCont)
|
|
|
|
|
{
|
|
|
|
|
|
2007-04-18 00:11:24 +00:00
|
|
|
TiXmlDocument doc(myPath.c_str());
|
|
|
|
|
if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << myPath << "\n"; }
|
2007-01-22 21:29:51 +00:00
|
|
|
TiXmlHandle docHandle( &doc );
|
|
|
|
|
|
|
|
|
|
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement();
|
|
|
|
|
if ( conf ) {
|
|
|
|
|
conf->SetAttribute("value", varCont );
|
2007-04-18 00:11:24 +00:00
|
|
|
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; }
|
2007-01-22 21:29:51 +00:00
|
|
|
} else {
|
|
|
|
|
//Wenn nicht gefunden eines neues Anlegen
|
|
|
|
|
TiXmlElement* config = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).ToElement();
|
|
|
|
|
|
|
|
|
|
if ( config ) {
|
|
|
|
|
|
|
|
|
|
TiXmlElement * confElement1 = new TiXmlElement( varName );
|
|
|
|
|
config->LinkEndChild( confElement1 );
|
|
|
|
|
confElement1->SetAttribute("value", varCont);
|
|
|
|
|
|
2007-04-18 00:11:24 +00:00
|
|
|
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; }
|
2007-01-22 21:29:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-04-18 00:11:24 +00:00
|
|
|
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; }
|
2007-01-21 16:01:37 +00:00
|
|
|
}
|
2007-01-21 22:44:11 +00:00
|
|
|
|
2007-01-22 21:29:51 +00:00
|
|
|
void ConfigFile::writeConfigString(string varName, string varCont)
|
2007-01-21 22:44:11 +00:00
|
|
|
{
|
2007-01-22 21:29:51 +00:00
|
|
|
|
2007-04-18 00:11:24 +00:00
|
|
|
TiXmlDocument doc(myPath.c_str());
|
|
|
|
|
if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << myPath << "\n"; }
|
2007-01-22 21:29:51 +00:00
|
|
|
TiXmlHandle docHandle( &doc );
|
2007-01-21 22:44:11 +00:00
|
|
|
|
2007-01-22 21:29:51 +00:00
|
|
|
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement();
|
|
|
|
|
if ( conf ) {
|
|
|
|
|
conf->SetAttribute("value", varCont );
|
|
|
|
|
} else {
|
|
|
|
|
//Wenn nicht gefunden eines neues Anlegen
|
|
|
|
|
TiXmlElement* config = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).ToElement();
|
|
|
|
|
if ( config ) {
|
|
|
|
|
TiXmlElement * confElement1 = new TiXmlElement( varName );
|
|
|
|
|
config->LinkEndChild( confElement1 );
|
|
|
|
|
confElement1->SetAttribute("value", varCont);
|
2007-04-18 00:11:24 +00:00
|
|
|
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; }
|
2007-01-22 21:29:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-04-18 00:11:24 +00:00
|
|
|
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << myPath << "\n"; }
|
2007-01-21 22:44:11 +00:00
|
|
|
|
|
|
|
|
|
2007-01-23 00:49:45 +00:00
|
|
|
}
|