check AppDataDir at startup

This commit is contained in:
doitux
2007-09-17 23:06:10 +00:00
parent f3f6dd1a08
commit e9b9693ad9
4 changed files with 56 additions and 29 deletions
+30 -9
View File
@@ -45,6 +45,8 @@ class QtToolsWrapper;
ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0) ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0)
{ {
myArgv = argv;
int i; int i;
myQtToolsInterface = new QtToolsWrapper; myQtToolsInterface = new QtToolsWrapper;
@@ -53,7 +55,7 @@ ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0)
if(strcmp(argv[i], "--nowriteaccess") == 0) { noWriteAccess = 1; } if(strcmp(argv[i], "--nowriteaccess") == 0) { noWriteAccess = 1; }
} }
// !!!! Revisionsnummer der Configdefaults !!!!! // !!!! Revisionsnummer der Configdefaults !!!!!
configRev = 34; configRev = 35;
//standard defaults //standard defaults
logOnOffDefault = "1"; logOnOffDefault = "1";
@@ -148,6 +150,7 @@ ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0)
ostringstream tempIntToString; ostringstream tempIntToString;
tempIntToString << configRev; tempIntToString << configRev;
configList.push_back(ConfigInfo("ConfigRevision", CONFIG_TYPE_INT, tempIntToString.str())); 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("Language", CONFIG_TYPE_INT, myQtToolsInterface->getDefaultLanguage()));
configList.push_back(ConfigInfo("ShowLeftToolBox", CONFIG_TYPE_INT, "1")); configList.push_back(ConfigInfo("ShowLeftToolBox", CONFIG_TYPE_INT, "1"));
configList.push_back(ConfigInfo("ShowRightToolBox", 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("LogStoreDuration", CONFIG_TYPE_INT, "2"));
configList.push_back(ConfigInfo("LogInterval", CONFIG_TYPE_INT, "0")); configList.push_back(ConfigInfo("LogInterval", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("UserDataDir", CONFIG_TYPE_STRING, dataDir)); 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("CacheDir", CONFIG_TYPE_STRING, cacheDir));
configList.push_back(ConfigInfo("CLA_NoWriteAccess", CONFIG_TYPE_INT, claNoWriteAccess)); configList.push_back(ConfigInfo("CLA_NoWriteAccess", CONFIG_TYPE_INT, claNoWriteAccess));
@@ -231,12 +233,20 @@ ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0)
updateConfig(myConfigState); updateConfig(myConfigState);
} }
else { else {
//Prüfen ob die Revision stimmt ansonsten löschen und neue anlegen //Check if config revision and AppDataDir is ok. Otherwise --> update()
int temp = 0; int tempRevision = 0;
string tempAppDataPath ("");
TiXmlHandle docHandle( &doc ); TiXmlHandle docHandle( &doc );
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( "ConfigRevision" ).ToElement(); TiXmlElement* confRevision = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( "ConfigRevision" ).ToElement();
if ( conf ) { conf->QueryIntAttribute("value", &temp ); } if ( confRevision ) { confRevision->QueryIntAttribute("value", &tempRevision ); }
if (temp < configRev) { /*löschen()*/ 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; myConfigState = OLD;
updateConfig(myConfigState) ; updateConfig(myConfigState) ;
} }
@@ -317,6 +327,7 @@ void ConfigFile::writeBuffer() const {
void ConfigFile::updateConfig(ConfigState myConfigState) { void ConfigFile::updateConfig(ConfigState myConfigState) {
boost::mutex::scoped_lock lock(m_configMutex); boost::mutex::scoped_lock lock(m_configMutex);
boost::filesystem::path startPath(myArgv[0]);
size_t i; size_t i;
@@ -366,17 +377,26 @@ void ConfigFile::updateConfig(ConfigState myConfigState) {
config = new TiXmlElement( "Configuration" ); config = new TiXmlElement( "Configuration" );
root->LinkEndChild( config ); root->LinkEndChild( config );
//change configRev and AppDataPath
TiXmlElement * confElement0 = new TiXmlElement( "ConfigRevision" ); TiXmlElement * confElement0 = new TiXmlElement( "ConfigRevision" );
config->LinkEndChild( confElement0 ); config->LinkEndChild( confElement0 );
confElement0->SetAttribute("value", configRev); 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 ); TiXmlHandle docHandle( &oldDoc );
// not i=0 because ConfigRevision is already set ^^
for (i=1; i<configList.size(); i++) { for (i=0; i<configList.size(); i++) {
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).ToElement(); TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).ToElement();
if ( conf ) { if ( conf ) {
// 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 // if element is already there --> take over the saved values
TiXmlElement *tmpElement = new TiXmlElement(configList[i].name); TiXmlElement *tmpElement = new TiXmlElement(configList[i].name);
config->LinkEndChild( tmpElement ); config->LinkEndChild( tmpElement );
@@ -385,6 +405,7 @@ void ConfigFile::updateConfig(ConfigState myConfigState) {
if (tmpStr) tempString = tmpStr; if (tmpStr) tempString = tmpStr;
tmpElement->SetAttribute("value", tempString); tmpElement->SetAttribute("value", tempString);
} }
}
else { else {
// if element is not there --> set it with defaultValue // if element is not there --> set it with defaultValue
TiXmlElement *tmpElement = new TiXmlElement(configList[i].name); TiXmlElement *tmpElement = new TiXmlElement(configList[i].name);
+2
View File
@@ -76,6 +76,8 @@ private:
ConfigState myConfigState; ConfigState myConfigState;
QtToolsInterface *myQtToolsInterface; QtToolsInterface *myQtToolsInterface;
char **myArgv;
}; };
#endif #endif
+12 -12
View File
@@ -145,22 +145,22 @@
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout" >
<property name="leftMargin" > <property name="leftMargin" >
<number>9</number> <number>6</number>
</property> </property>
<property name="topMargin" > <property name="topMargin" >
<number>9</number> <number>6</number>
</property> </property>
<property name="rightMargin" > <property name="rightMargin" >
<number>9</number> <number>6</number>
</property> </property>
<property name="bottomMargin" > <property name="bottomMargin" >
<number>9</number> <number>6</number>
</property> </property>
<property name="horizontalSpacing" > <property name="horizontalSpacing" >
<number>5</number> <number>1</number>
</property> </property>
<property name="verticalSpacing" > <property name="verticalSpacing" >
<number>5</number> <number>1</number>
</property> </property>
<item row="0" column="0" > <item row="0" column="0" >
<widget class="MyLeftTabWidget" name="tabWidget_Left" > <widget class="MyLeftTabWidget" name="tabWidget_Left" >
@@ -563,22 +563,22 @@
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout" >
<property name="leftMargin" > <property name="leftMargin" >
<number>9</number> <number>6</number>
</property> </property>
<property name="topMargin" > <property name="topMargin" >
<number>9</number> <number>6</number>
</property> </property>
<property name="rightMargin" > <property name="rightMargin" >
<number>9</number> <number>6</number>
</property> </property>
<property name="bottomMargin" > <property name="bottomMargin" >
<number>9</number> <number>6</number>
</property> </property>
<property name="horizontalSpacing" > <property name="horizontalSpacing" >
<number>6</number> <number>1</number>
</property> </property>
<property name="verticalSpacing" > <property name="verticalSpacing" >
<number>6</number> <number>1</number>
</property> </property>
<item row="0" column="0" > <item row="0" column="0" >
<widget class="MyRightTabWidget" name="tabWidget_Right" > <widget class="MyRightTabWidget" name="tabWidget_Right" >
+5 -1
View File
@@ -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; }"); textBrowser_Log->setStyleSheet("QTextBrowser { "+ font1String +" font-size: 11px; color: #F0F0F0; background-color: #1D3B00; border:none; }");
#else #else
textBrowser_Log->setStyleSheet("QTextBrowser { "+ font1String +" font-size: 10px; color: #F0F0F0; background-color: #1D3B00; border:none; }"); 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_Log->verticalScrollBar()->setAutoFillBackground ( TRUE );
textBrowser_Chat->setStyleSheet("QTextBrowser { "+ font1String +" font-size: 10px; color: #F0F0F0; background-color: #1D3B00; border:none; }"); textBrowser_Chat->setStyleSheet("QTextBrowser { "+ font1String +" font-size: 10px; color: #F0F0F0; background-color: #1D3B00; border:none; }");