check AppDataDir at startup
This commit is contained in:
+37
-16
@@ -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<configList.size(); i++) {
|
||||
|
||||
for (i=0; i<configList.size(); i++) {
|
||||
|
||||
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( configList[i].name ).ToElement();
|
||||
|
||||
if ( conf ) {
|
||||
// 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);
|
||||
// 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
|
||||
|
||||
@@ -76,6 +76,8 @@ private:
|
||||
|
||||
ConfigState myConfigState;
|
||||
QtToolsInterface *myQtToolsInterface;
|
||||
|
||||
char **myArgv;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+12
-12
@@ -145,22 +145,22 @@
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<property name="leftMargin" >
|
||||
<number>9</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin" >
|
||||
<number>9</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin" >
|
||||
<number>9</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin" >
|
||||
<number>9</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="horizontalSpacing" >
|
||||
<number>5</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="verticalSpacing" >
|
||||
<number>5</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item row="0" column="0" >
|
||||
<widget class="MyLeftTabWidget" name="tabWidget_Left" >
|
||||
@@ -563,22 +563,22 @@
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<property name="leftMargin" >
|
||||
<number>9</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin" >
|
||||
<number>9</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin" >
|
||||
<number>9</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin" >
|
||||
<number>9</number>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="horizontalSpacing" >
|
||||
<number>6</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="verticalSpacing" >
|
||||
<number>6</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item row="0" column="0" >
|
||||
<widget class="MyRightTabWidget" name="tabWidget_Right" >
|
||||
|
||||
@@ -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; }");
|
||||
|
||||
Reference in New Issue
Block a user