From e9b9693ad97a5adde8faca845599add01e603839 Mon Sep 17 00:00:00 2001 From: doitux Date: Mon, 17 Sep 2007 23:06:10 +0000 Subject: [PATCH] check AppDataDir at startup --- src/config/configfile.cpp | 53 +++++++++++++++++------- src/config/configfile.h | 2 + src/gui/qt/mainwindow.ui | 24 +++++------ src/gui/qt/mainwindow/mainwindowimpl.cpp | 6 ++- 4 files changed, 56 insertions(+), 29 deletions(-) diff --git a/src/config/configfile.cpp b/src/config/configfile.cpp index 76b8cb4e..0c798c12 100644 --- a/src/config/configfile.cpp +++ b/src/config/configfile.cpp @@ -45,6 +45,8 @@ class QtToolsWrapper; ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0) { + + myArgv = argv; int i; myQtToolsInterface = new QtToolsWrapper; @@ -53,7 +55,7 @@ ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0) if(strcmp(argv[i], "--nowriteaccess") == 0) { noWriteAccess = 1; } } // !!!! Revisionsnummer der Configdefaults !!!!! - configRev = 34; + configRev = 35; //standard defaults logOnOffDefault = "1"; @@ -148,6 +150,7 @@ ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0) ostringstream tempIntToString; tempIntToString << configRev; configList.push_back(ConfigInfo("ConfigRevision", CONFIG_TYPE_INT, tempIntToString.str())); + configList.push_back(ConfigInfo("AppDataDir", CONFIG_TYPE_STRING, myQtToolsInterface->getDataPathStdString(startPath.remove_leaf().directory_string()))); configList.push_back(ConfigInfo("Language", CONFIG_TYPE_INT, myQtToolsInterface->getDefaultLanguage())); configList.push_back(ConfigInfo("ShowLeftToolBox", CONFIG_TYPE_INT, "1")); configList.push_back(ConfigInfo("ShowRightToolBox", CONFIG_TYPE_INT, "1")); @@ -212,7 +215,6 @@ ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0) configList.push_back(ConfigInfo("LogStoreDuration", CONFIG_TYPE_INT, "2")); configList.push_back(ConfigInfo("LogInterval", CONFIG_TYPE_INT, "0")); configList.push_back(ConfigInfo("UserDataDir", CONFIG_TYPE_STRING, dataDir)); - configList.push_back(ConfigInfo("AppDataDir", CONFIG_TYPE_STRING, myQtToolsInterface->getDataPathStdString(startPath.remove_leaf().directory_string()))); configList.push_back(ConfigInfo("CacheDir", CONFIG_TYPE_STRING, cacheDir)); configList.push_back(ConfigInfo("CLA_NoWriteAccess", CONFIG_TYPE_INT, claNoWriteAccess)); @@ -231,12 +233,20 @@ ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0) updateConfig(myConfigState); } else { - //Prüfen ob die Revision stimmt ansonsten löschen und neue anlegen - int temp = 0; + //Check if config revision and AppDataDir is ok. Otherwise --> update() + int tempRevision = 0; + string tempAppDataPath (""); + TiXmlHandle docHandle( &doc ); - TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( "ConfigRevision" ).ToElement(); - if ( conf ) { conf->QueryIntAttribute("value", &temp ); } - if (temp < configRev) { /*löschen()*/ + TiXmlElement* confRevision = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( "ConfigRevision" ).ToElement(); + if ( confRevision ) { confRevision->QueryIntAttribute("value", &tempRevision ); } + TiXmlElement* confAppDataPath = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( "AppDataDir" ).ToElement(); + if ( confAppDataPath ) { + const char *tmpStr = confAppDataPath->Attribute("value"); + if (tmpStr) tempAppDataPath = tmpStr; + } + + if (tempRevision < configRev || tempAppDataPath != myQtToolsInterface->getDataPathStdString(startPath.remove_leaf().directory_string()) ) { /*löschen()*/ myConfigState = OLD; updateConfig(myConfigState) ; } @@ -317,6 +327,7 @@ void ConfigFile::writeBuffer() const { void ConfigFile::updateConfig(ConfigState myConfigState) { boost::mutex::scoped_lock lock(m_configMutex); + boost::filesystem::path startPath(myArgv[0]); size_t i; @@ -366,24 +377,34 @@ void ConfigFile::updateConfig(ConfigState myConfigState) { config = new TiXmlElement( "Configuration" ); root->LinkEndChild( config ); + //change configRev and AppDataPath TiXmlElement * confElement0 = new TiXmlElement( "ConfigRevision" ); config->LinkEndChild( confElement0 ); confElement0->SetAttribute("value", configRev); + TiXmlElement * confElement1 = new TiXmlElement( "AppDataDir" ); + config->LinkEndChild( confElement1 ); + confElement1->SetAttribute("value", myQtToolsInterface->getDataPathStdString(startPath.remove_leaf().directory_string())); + TiXmlHandle docHandle( &oldDoc ); - // not i=0 because ConfigRevision is already set ^^ - for (i=1; i take over the saved values - TiXmlElement *tmpElement = new TiXmlElement(configList[i].name); - config->LinkEndChild( tmpElement ); - - const char *tmpStr = conf->Attribute("value"); - if (tmpStr) tempString = tmpStr; - tmpElement->SetAttribute("value", tempString); + // not for ConfigRevision and AppDataDir becaus it was already set ^ + if(configList[i].name != "ConfigRevision" && configList[i].name != "AppDataDir") { + + // if element is already there --> take over the saved values + TiXmlElement *tmpElement = new TiXmlElement(configList[i].name); + config->LinkEndChild( tmpElement ); + + const char *tmpStr = conf->Attribute("value"); + if (tmpStr) tempString = tmpStr; + tmpElement->SetAttribute("value", tempString); + } } else { // if element is not there --> set it with defaultValue diff --git a/src/config/configfile.h b/src/config/configfile.h index 1e37c349..0098e545 100644 --- a/src/config/configfile.h +++ b/src/config/configfile.h @@ -76,6 +76,8 @@ private: ConfigState myConfigState; QtToolsInterface *myQtToolsInterface; + + char **myArgv; }; #endif diff --git a/src/gui/qt/mainwindow.ui b/src/gui/qt/mainwindow.ui index 0ddc1563..733eef01 100644 --- a/src/gui/qt/mainwindow.ui +++ b/src/gui/qt/mainwindow.ui @@ -145,22 +145,22 @@ - 9 + 6 - 9 + 6 - 9 + 6 - 9 + 6 - 5 + 1 - 5 + 1 @@ -563,22 +563,22 @@ - 9 + 6 - 9 + 6 - 9 + 6 - 9 + 6 - 6 + 1 - 6 + 1 diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index ec5b7c6c..710a2663 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -400,7 +400,11 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent) textBrowser_Log->setStyleSheet("QTextBrowser { "+ font1String +" font-size: 11px; color: #F0F0F0; background-color: #1D3B00; border:none; }"); #else textBrowser_Log->setStyleSheet("QTextBrowser { "+ font1String +" font-size: 10px; color: #F0F0F0; background-color: #1D3B00; border:none; }"); -// textBrowser_Log->verticalScrollBar()->setPalette(QColor(0,20,20)); + +// QScrollBar *myLogScrollBar = textBrowser_Log->verticalScrollBar(); +// myLogScrollBar->setStyleSheet("QScrollBar { border: 2px solid grey; background: #32CC99; height: 15px; margin: 0px 20px 0 20px;} QScrollBar::handle { background: white; min-width: 20px;} QScrollBar::add-line { border: 2px solid grey; background: #32CC99; width: 20px; subcontrol-position: right; subcontrol-origin: margin; } QScrollBar::sub-line {border: 2px solid grey; background: #32CC99; width: 20px; subcontrol-position: left; subcontrol-origin: margin;}"); +// textBrowser_Log->setVerticalScrollBar(myLogScrollBar); + // textBrowser_Log->verticalScrollBar()->setAutoFillBackground ( TRUE ); textBrowser_Chat->setStyleSheet("QTextBrowser { "+ font1String +" font-size: 10px; color: #F0F0F0; background-color: #1D3B00; border:none; }");