implement minimal disc access for config-file
This commit is contained in:
+134
-77
@@ -21,11 +21,6 @@
|
|||||||
|
|
||||||
#include <qttoolswrapper.h>
|
#include <qttoolswrapper.h>
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <boost/shared_ptr.hpp>
|
|
||||||
#define MODUS 0711
|
#define MODUS 0711
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -35,7 +30,6 @@
|
|||||||
|
|
||||||
class QtToolsWrapper;
|
class QtToolsWrapper;
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
ConfigFile::ConfigFile(bool configFirstStart)
|
ConfigFile::ConfigFile(bool configFirstStart)
|
||||||
{
|
{
|
||||||
@@ -108,41 +102,6 @@ ConfigFile::ConfigFile(bool configFirstStart)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
configFileName += "config.xml";
|
|
||||||
|
|
||||||
if (configFirstStart) {
|
|
||||||
//Prüfen ob Configfile existiert --> sonst anlegen
|
|
||||||
TiXmlDocument doc(configFileName);
|
|
||||||
if(!doc.LoadFile()){
|
|
||||||
myConfigState = NONEXISTING;
|
|
||||||
updateConfig(myConfigState);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//Prüfen ob die Revision stimmt ansonsten löschen und neue anlegen
|
|
||||||
int temp = 0;
|
|
||||||
TiXmlHandle docHandle( &doc );
|
|
||||||
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( "ConfigRevision" ).ToElement();
|
|
||||||
if ( conf ) { conf->QueryIntAttribute("value", &temp ); }
|
|
||||||
if (temp < configRev) { /*löschen()*/
|
|
||||||
myConfigState = OLD;
|
|
||||||
updateConfig(myConfigState) ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ConfigFile::~ConfigFile()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigFile::updateConfig(ConfigState myConfigState) {
|
|
||||||
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
QtToolsInterface *myQtToolsInterface = new QtToolsWrapper;
|
|
||||||
|
|
||||||
vector<ConfigInfo> configList;
|
|
||||||
|
|
||||||
ostringstream tempIntToString;
|
ostringstream tempIntToString;
|
||||||
tempIntToString << configRev;
|
tempIntToString << configRev;
|
||||||
@@ -193,6 +152,79 @@ void ConfigFile::updateConfig(ConfigState myConfigState) {
|
|||||||
configList.push_back(ConfigInfo("LogInterval", CONFIG_TYPE_INT, "0"));
|
configList.push_back(ConfigInfo("LogInterval", CONFIG_TYPE_INT, "0"));
|
||||||
configList.push_back(ConfigInfo("DataDir", CONFIG_TYPE_STRING, dataDir));
|
configList.push_back(ConfigInfo("DataDir", CONFIG_TYPE_STRING, dataDir));
|
||||||
|
|
||||||
|
//fill tempList firstTime
|
||||||
|
configBufferList = configList;
|
||||||
|
|
||||||
|
// cout << configTempList[3].name << " " << configTempList[10].defaultValue << endl;
|
||||||
|
|
||||||
|
configFileName += "config.xml";
|
||||||
|
|
||||||
|
if (configFirstStart) {
|
||||||
|
//Prüfen ob Configfile existiert --> sonst anlegen
|
||||||
|
TiXmlDocument doc(configFileName);
|
||||||
|
if(!doc.LoadFile()){
|
||||||
|
myConfigState = NONEXISTING;
|
||||||
|
updateConfig(myConfigState);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//Prüfen ob die Revision stimmt ansonsten löschen und neue anlegen
|
||||||
|
int temp = 0;
|
||||||
|
TiXmlHandle docHandle( &doc );
|
||||||
|
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( "ConfigRevision" ).ToElement();
|
||||||
|
if ( conf ) { conf->QueryIntAttribute("value", &temp ); }
|
||||||
|
if (temp < configRev) { /*löschen()*/
|
||||||
|
myConfigState = OLD;
|
||||||
|
updateConfig(myConfigState) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fillBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ConfigFile::~ConfigFile()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ConfigFile::fillBuffer() {
|
||||||
|
|
||||||
|
QtToolsInterface *myQtToolsInterface = new QtToolsWrapper;
|
||||||
|
|
||||||
|
size_t i;
|
||||||
|
string tempString("");
|
||||||
|
|
||||||
|
TiXmlDocument doc(configFileName);
|
||||||
|
|
||||||
|
if(doc.LoadFile()) {
|
||||||
|
TiXmlHandle docHandle( &doc );
|
||||||
|
|
||||||
|
for (i=0; i<configBufferList.size(); i++) {
|
||||||
|
|
||||||
|
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).ToElement();
|
||||||
|
|
||||||
|
if ( conf ) {
|
||||||
|
|
||||||
|
const char *tmpStr = conf->Attribute("value");
|
||||||
|
if (tmpStr) tempString = tmpStr;
|
||||||
|
configBufferList[i].defaultValue = myQtToolsInterface->stringToUtf8(tempString);
|
||||||
|
}
|
||||||
|
else { cout << "Could not find the element to fill the config-buffer with!"; }
|
||||||
|
|
||||||
|
// cout << configBufferList[i].name << " " << configBufferList[i].defaultValue << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete myQtToolsInterface;
|
||||||
|
myQtToolsInterface = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigFile::updateConfig(ConfigState myConfigState) {
|
||||||
|
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
QtToolsInterface *myQtToolsInterface = new QtToolsWrapper;
|
||||||
|
|
||||||
if(myConfigState == NONEXISTING) {
|
if(myConfigState == NONEXISTING) {
|
||||||
|
|
||||||
@@ -281,57 +313,78 @@ void ConfigFile::updateConfig(ConfigState myConfigState) {
|
|||||||
|
|
||||||
string ConfigFile::readConfigString(string varName)
|
string ConfigFile::readConfigString(string varName)
|
||||||
{
|
{
|
||||||
|
size_t i;
|
||||||
string tempString("");
|
string tempString("");
|
||||||
|
|
||||||
TiXmlDocument doc(configFileName);
|
// TiXmlDocument doc(configFileName);
|
||||||
if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << configFileName << "\n"; }
|
// if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << configFileName << "\n"; }
|
||||||
TiXmlHandle docHandle( &doc );
|
// TiXmlHandle docHandle( &doc );
|
||||||
|
//
|
||||||
|
// TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement();
|
||||||
|
// if ( conf ) {
|
||||||
|
// const char *tmpStr = conf->Attribute("value");
|
||||||
|
// if (tmpStr) tempString = tmpStr;
|
||||||
|
// } /*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", defaultValue);
|
||||||
|
// if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
||||||
|
//
|
||||||
|
// return readConfigString(varName, defaultValue);
|
||||||
|
// }
|
||||||
|
// }*/
|
||||||
|
for (i=0; i<configBufferList.size(); i++) {
|
||||||
|
|
||||||
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement();
|
if (configBufferList[i].name == varName) {
|
||||||
if ( conf ) {
|
tempString = configBufferList[i].defaultValue;
|
||||||
const char *tmpStr = conf->Attribute("value");
|
}
|
||||||
if (tmpStr) tempString = tmpStr;
|
|
||||||
} /*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", defaultValue);
|
|
||||||
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
|
||||||
|
|
||||||
return readConfigString(varName, defaultValue);
|
|
||||||
}
|
}
|
||||||
}*/
|
|
||||||
|
|
||||||
return tempString;
|
return tempString;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigFile::readConfigInt(string varName)
|
int ConfigFile::readConfigInt(string varName)
|
||||||
{
|
{
|
||||||
|
size_t i;
|
||||||
|
string tempString("");
|
||||||
int tempInt=0;
|
int tempInt=0;
|
||||||
// cout << varName << " : " << tempInt << "\n";
|
|
||||||
TiXmlDocument doc(configFileName);
|
|
||||||
if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << configFileName << "\n"; }
|
|
||||||
TiXmlHandle docHandle( &doc );
|
|
||||||
|
|
||||||
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement();
|
|
||||||
if ( conf ) {
|
|
||||||
// cout << varName << " : " << tempInt << "\n";
|
// cout << varName << " : " << tempInt << "\n";
|
||||||
conf->QueryIntAttribute("value", &tempInt );
|
// TiXmlDocument doc(configFileName);
|
||||||
// cout << varName << " : " << tempInt << "\n";
|
// if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << configFileName << "\n"; }
|
||||||
} /*else {
|
// TiXmlHandle docHandle( &doc );
|
||||||
// Wenn nicht gefunden eines neues Anlegen
|
//
|
||||||
TiXmlElement* config = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).ToElement();
|
// TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement();
|
||||||
if ( config ) {
|
// if ( conf ) {
|
||||||
TiXmlElement * confElement1 = new TiXmlElement( varName );
|
// // cout << varName << " : " << tempInt << "\n";
|
||||||
config->LinkEndChild( confElement1 );
|
// conf->QueryIntAttribute("value", &tempInt );
|
||||||
confElement1->SetAttribute("value", defaultValue);
|
// // cout << varName << " : " << tempInt << "\n";
|
||||||
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
// } /*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", defaultValue);
|
||||||
|
// if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
||||||
|
//
|
||||||
|
// return readConfigInt(varName, defaultValue);
|
||||||
|
// }
|
||||||
|
// }*/
|
||||||
|
|
||||||
return readConfigInt(varName, defaultValue);
|
for (i=0; i<configBufferList.size(); i++) {
|
||||||
|
|
||||||
|
if (configBufferList[i].name == varName) {
|
||||||
|
tempString = configBufferList[i].defaultValue;
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
istringstream isst;
|
||||||
|
isst.str (tempString);
|
||||||
|
isst >> tempInt;
|
||||||
|
|
||||||
return tempInt;
|
return tempInt;
|
||||||
}
|
}
|
||||||
@@ -362,6 +415,9 @@ void ConfigFile::writeConfigInt(string varName, int varCont)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
||||||
|
|
||||||
|
fillBuffer();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigFile::writeConfigString(string varName, string varCont)
|
void ConfigFile::writeConfigString(string varName, string varCont)
|
||||||
@@ -386,5 +442,6 @@ void ConfigFile::writeConfigString(string varName, string varCont)
|
|||||||
}
|
}
|
||||||
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
||||||
|
|
||||||
|
fillBuffer();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,17 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
enum ConfigState { NONEXISTING, OLD };
|
enum ConfigState { NONEXISTING, OLD };
|
||||||
enum ConfigType { CONFIG_TYPE_INT, CONFIG_TYPE_STRING };
|
enum ConfigType { CONFIG_TYPE_INT, CONFIG_TYPE_STRING };
|
||||||
@@ -35,6 +46,8 @@ public:
|
|||||||
|
|
||||||
~ConfigFile();
|
~ConfigFile();
|
||||||
|
|
||||||
|
void fillBuffer();
|
||||||
|
|
||||||
void updateConfig(ConfigState);
|
void updateConfig(ConfigState);
|
||||||
|
|
||||||
std::string readConfigString(std::string varName);
|
std::string readConfigString(std::string varName);
|
||||||
@@ -55,6 +68,9 @@ private:
|
|||||||
std::string defaultValue;
|
std::string defaultValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
vector<ConfigInfo> configList;
|
||||||
|
vector<ConfigInfo> configBufferList;
|
||||||
|
|
||||||
std::string configFileName;
|
std::string configFileName;
|
||||||
std::string logDir;
|
std::string logDir;
|
||||||
std::string dataDir;
|
std::string dataDir;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Log::Log(mainWindowImpl* w, ConfigFile *c) : myW(w), myConfig(c)
|
Log::Log(mainWindowImpl* w, ConfigFile *c) : myW(w), myConfig(c), myLogDir(0), myLogFile(0)
|
||||||
{
|
{
|
||||||
myW->setLog(this);
|
myW->setLog(this);
|
||||||
|
|
||||||
@@ -1138,10 +1138,15 @@ QStringList Log::translateCardsValueCode(int cardsValueCode) {
|
|||||||
|
|
||||||
void Log::writeLogFileStream(QString streamString) {
|
void Log::writeLogFileStream(QString streamString) {
|
||||||
|
|
||||||
myLogFile->open( QIODevice::ReadWrite );
|
if(myLogFile) {
|
||||||
|
if(myLogFile->open( QIODevice::ReadWrite )) {
|
||||||
QTextStream stream( myLogFile );
|
QTextStream stream( myLogFile );
|
||||||
stream.readAll();
|
stream.readAll();
|
||||||
stream << streamString;
|
stream << streamString;
|
||||||
myLogFile->close();
|
myLogFile->close();
|
||||||
|
}
|
||||||
|
else { cout << "could not open log-file to write log-messages!" << endl; }
|
||||||
|
}
|
||||||
|
else { cout << "could not find log-file to write log-messages!" << endl; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ private:
|
|||||||
mainWindowImpl *myW;
|
mainWindowImpl *myW;
|
||||||
ConfigFile *myConfig;
|
ConfigFile *myConfig;
|
||||||
QTextStream stream;
|
QTextStream stream;
|
||||||
QFile *myLogFile;
|
|
||||||
QDir *myLogDir;
|
QDir *myLogDir;
|
||||||
|
QFile *myLogFile;
|
||||||
QString logFileStreamString;
|
QString logFileStreamString;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user