--nowriteaccess first steps
This commit is contained in:
+145
-99
@@ -31,77 +31,96 @@
|
|||||||
class QtToolsWrapper;
|
class QtToolsWrapper;
|
||||||
|
|
||||||
|
|
||||||
ConfigFile::ConfigFile(bool configFirstStart)
|
ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0)
|
||||||
{
|
{
|
||||||
// !!!! Revisionsnummer der Configdefaults !!!!!
|
int i;
|
||||||
configRev = 18;
|
|
||||||
|
|
||||||
// Pfad und Dateinamen setzen
|
for (i=0; i<argc; i++) {
|
||||||
#ifdef _WIN32
|
if(strcmp(argv[i], "--nowriteaccess") == 0) { noWriteAccess = 1; }
|
||||||
const char *appDataPath = getenv("AppData");
|
|
||||||
if (appDataPath && appDataPath[0] != 0) {
|
|
||||||
configFileName = appDataPath;
|
|
||||||
}
|
}
|
||||||
else {
|
// !!!! Revisionsnummer der Configdefaults !!!!!
|
||||||
const int MaxPathSize = 1024;
|
configRev = 20;
|
||||||
char curDir[MaxPathSize + 1];
|
|
||||||
curDir[0] = 0;
|
//standard defaults
|
||||||
_getcwd(curDir, MaxPathSize);
|
logOnOffDefault = "1";
|
||||||
curDir[MaxPathSize] = 0;
|
claNoWriteAccess = "0";
|
||||||
configFileName = curDir;
|
|
||||||
// Testen ob das Verzeichnis beschreibbar ist
|
|
||||||
ofstream tmpFile;
|
if(!noWriteAccess) {
|
||||||
const char *tmpFileName = "pokerth_test.tmp";
|
// Pfad und Dateinamen setzen
|
||||||
tmpFile.open((configFileName + "\\" + tmpFileName).c_str());
|
#ifdef _WIN32
|
||||||
if (tmpFile) {
|
const char *appDataPath = getenv("AppData");
|
||||||
// Erfolgreich, Verzeichnis beschreibbar.
|
if (appDataPath && appDataPath[0] != 0) {
|
||||||
// Datei wieder loeschen.
|
configFileName = appDataPath;
|
||||||
tmpFile.close();
|
|
||||||
remove((configFileName + "\\" + tmpFileName).c_str());
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Fehlgeschlagen, Verzeichnis nicht beschreibbar
|
const int MaxPathSize = 1024;
|
||||||
|
char curDir[MaxPathSize + 1];
|
||||||
curDir[0] = 0;
|
curDir[0] = 0;
|
||||||
GetTempPathA(MaxPathSize, curDir);
|
_getcwd(curDir, MaxPathSize);
|
||||||
curDir[MaxPathSize] = 0;
|
curDir[MaxPathSize] = 0;
|
||||||
configFileName = curDir;
|
configFileName = curDir;
|
||||||
|
// Testen ob das Verzeichnis beschreibbar ist
|
||||||
|
ofstream tmpFile;
|
||||||
|
const char *tmpFileName = "pokerth_test.tmp";
|
||||||
|
tmpFile.open((configFileName + "\\" + tmpFileName).c_str());
|
||||||
|
if (tmpFile) {
|
||||||
|
// Erfolgreich, Verzeichnis beschreibbar.
|
||||||
|
// Datei wieder loeschen.
|
||||||
|
tmpFile.close();
|
||||||
|
remove((configFileName + "\\" + tmpFileName).c_str());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Fehlgeschlagen, Verzeichnis nicht beschreibbar
|
||||||
|
curDir[0] = 0;
|
||||||
|
GetTempPathA(MaxPathSize, curDir);
|
||||||
|
curDir[MaxPathSize] = 0;
|
||||||
|
configFileName = curDir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
//define app-dir
|
||||||
//define app-dir
|
configFileName += "\\pokerth\\";
|
||||||
configFileName += "\\pokerth\\";
|
////define log-dir
|
||||||
////define log-dir
|
logDir = configFileName;
|
||||||
logDir = configFileName;
|
logDir += "log-files\\";
|
||||||
logDir += "log-files\\";
|
////define data-dir
|
||||||
////define data-dir
|
dataDir = configFileName;
|
||||||
dataDir = configFileName;
|
dataDir += "data\\";
|
||||||
dataDir += "data\\";
|
//create directories on first start of app
|
||||||
//create directories on first start of app
|
|
||||||
if (configFirstStart) {
|
|
||||||
mkdir(configFileName.c_str());
|
mkdir(configFileName.c_str());
|
||||||
mkdir(logDir.c_str());
|
mkdir(logDir.c_str());
|
||||||
mkdir(dataDir.c_str());
|
mkdir(dataDir.c_str());
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
//define app-dir
|
//define app-dir
|
||||||
const char *homePath = getenv("HOME");
|
const char *homePath = getenv("HOME");
|
||||||
if(homePath) {
|
if(homePath) {
|
||||||
configFileName = homePath;
|
configFileName = homePath;
|
||||||
configFileName += "/.pokerth/";
|
configFileName += "/.pokerth/";
|
||||||
////define log-dir
|
////define log-dir
|
||||||
logDir = configFileName;
|
logDir = configFileName;
|
||||||
logDir += "log-files/";
|
logDir += "log-files/";
|
||||||
////define data-dir
|
////define data-dir
|
||||||
dataDir = configFileName;
|
dataDir = configFileName;
|
||||||
dataDir += "data/";
|
dataDir += "data/";
|
||||||
//create directories on first start of app
|
//create directories on first start of app
|
||||||
if (configFirstStart) {
|
|
||||||
mkdir(configFileName.c_str(), MODUS) ;
|
mkdir(configFileName.c_str(), MODUS) ;
|
||||||
mkdir(logDir.c_str(), MODUS);
|
mkdir(logDir.c_str(), MODUS);
|
||||||
mkdir(dataDir.c_str(), MODUS);
|
mkdir(dataDir.c_str(), MODUS);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//no writeaccess
|
||||||
|
configFileName = "";
|
||||||
|
logDir = "";
|
||||||
|
dataDir = "";
|
||||||
|
logOnOffDefault = "0";
|
||||||
|
claNoWriteAccess = "1";
|
||||||
|
}
|
||||||
|
|
||||||
ostringstream tempIntToString;
|
ostringstream tempIntToString;
|
||||||
tempIntToString << configRev;
|
tempIntToString << configRev;
|
||||||
@@ -146,20 +165,21 @@ ConfigFile::ConfigFile(bool configFirstStart)
|
|||||||
configList.push_back(ConfigInfo("Opponent5Avatar", CONFIG_TYPE_STRING, ""));
|
configList.push_back(ConfigInfo("Opponent5Avatar", CONFIG_TYPE_STRING, ""));
|
||||||
configList.push_back(ConfigInfo("Opponent6Name", CONFIG_TYPE_STRING, "Player 6"));
|
configList.push_back(ConfigInfo("Opponent6Name", CONFIG_TYPE_STRING, "Player 6"));
|
||||||
configList.push_back(ConfigInfo("Opponent6Avatar", CONFIG_TYPE_STRING, ""));
|
configList.push_back(ConfigInfo("Opponent6Avatar", CONFIG_TYPE_STRING, ""));
|
||||||
configList.push_back(ConfigInfo("LogOnOff", CONFIG_TYPE_INT, "1"));
|
configList.push_back(ConfigInfo("LogOnOff", CONFIG_TYPE_INT, logOnOffDefault));
|
||||||
configList.push_back(ConfigInfo("LogDir", CONFIG_TYPE_STRING, logDir));
|
configList.push_back(ConfigInfo("LogDir", CONFIG_TYPE_STRING, logDir));
|
||||||
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("DataDir", CONFIG_TYPE_STRING, dataDir));
|
configList.push_back(ConfigInfo("DataDir", CONFIG_TYPE_STRING, dataDir));
|
||||||
|
configList.push_back(ConfigInfo("CLA_NoWriteAccess", CONFIG_TYPE_INT, claNoWriteAccess));
|
||||||
|
|
||||||
//fill tempList firstTime
|
//fill tempList firstTime
|
||||||
configBufferList = configList;
|
configBufferList = configList;
|
||||||
|
|
||||||
// cout << configTempList[3].name << " " << configTempList[10].defaultValue << endl;
|
// cout << configTempList[3].name << " " << configTempList[10].defaultValue << endl;
|
||||||
|
|
||||||
configFileName += "config.xml";
|
if(!noWriteAccess) {
|
||||||
|
configFileName += "config.xml";
|
||||||
if (configFirstStart) {
|
|
||||||
//Prüfen ob Configfile existiert --> sonst anlegen
|
//Prüfen ob Configfile existiert --> sonst anlegen
|
||||||
TiXmlDocument doc(configFileName);
|
TiXmlDocument doc(configFileName);
|
||||||
if(!doc.LoadFile()){
|
if(!doc.LoadFile()){
|
||||||
@@ -177,9 +197,10 @@ ConfigFile::ConfigFile(bool configFirstStart)
|
|||||||
updateConfig(myConfigState) ;
|
updateConfig(myConfigState) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fillBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
fillBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -392,56 +413,81 @@ int ConfigFile::readConfigInt(string varName)
|
|||||||
|
|
||||||
void ConfigFile::writeConfigInt(string varName, int varCont)
|
void ConfigFile::writeConfigInt(string varName, int varCont)
|
||||||
{
|
{
|
||||||
|
if(!noWriteAccess) {
|
||||||
TiXmlDocument doc(configFileName);
|
//writeaccess
|
||||||
if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << configFileName << "\n"; }
|
TiXmlDocument doc(configFileName);
|
||||||
TiXmlHandle docHandle( &doc );
|
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 ) {
|
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement();
|
||||||
conf->SetAttribute("value", varCont );
|
if ( conf ) {
|
||||||
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
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);
|
|
||||||
|
|
||||||
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\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", varCont);
|
||||||
|
|
||||||
|
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
||||||
|
|
||||||
|
fillBuffer();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//no writeaccess
|
||||||
|
size_t i;
|
||||||
|
string tempString;
|
||||||
|
ostringstream intToString;
|
||||||
|
|
||||||
|
for (i=0; i<configBufferList.size(); i++) {
|
||||||
|
|
||||||
|
if (configBufferList[i].name == varName) {
|
||||||
|
intToString << varCont;
|
||||||
|
configBufferList[i].defaultValue = intToString.str();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
||||||
TiXmlDocument doc(configFileName);
|
if(!noWriteAccess) {
|
||||||
if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << configFileName << "\n"; }
|
//writeaccess
|
||||||
TiXmlHandle docHandle( &doc );
|
TiXmlDocument doc(configFileName);
|
||||||
|
if(!doc.LoadFile()) { cout << "Could Not Load Config-File!!! " << configFileName << "\n"; }
|
||||||
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement();
|
TiXmlHandle docHandle( &doc );
|
||||||
if ( conf ) {
|
|
||||||
conf->SetAttribute("value", varCont );
|
TiXmlElement* conf = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).FirstChild( varName ).ToElement();
|
||||||
} else {
|
if ( conf ) {
|
||||||
//Wenn nicht gefunden eines neues Anlegen
|
conf->SetAttribute("value", varCont );
|
||||||
TiXmlElement* config = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).ToElement();
|
} else {
|
||||||
if ( config ) {
|
//Wenn nicht gefunden eines neues Anlegen
|
||||||
TiXmlElement * confElement1 = new TiXmlElement( varName );
|
TiXmlElement* config = docHandle.FirstChild( "PokerTH" ).FirstChild( "Configuration" ).ToElement();
|
||||||
config->LinkEndChild( confElement1 );
|
if ( config ) {
|
||||||
confElement1->SetAttribute("value", varCont);
|
TiXmlElement * confElement1 = new TiXmlElement( varName );
|
||||||
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
config->LinkEndChild( confElement1 );
|
||||||
|
confElement1->SetAttribute("value", varCont);
|
||||||
|
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
||||||
|
|
||||||
|
fillBuffer();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//no writeaccess
|
||||||
|
size_t i;
|
||||||
|
for (i=0; i<configBufferList.size(); i++) {
|
||||||
|
if (configBufferList[i].name == varName) { configBufferList[i].defaultValue = varCont; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!doc.SaveFile()) { cout << "Could Not Save Config-File!!! " << configFileName << "\n"; }
|
|
||||||
|
|
||||||
fillBuffer();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ enum ConfigType { CONFIG_TYPE_INT, CONFIG_TYPE_STRING };
|
|||||||
|
|
||||||
class ConfigFile{
|
class ConfigFile{
|
||||||
public:
|
public:
|
||||||
ConfigFile(bool configFirstStart =0);
|
ConfigFile(int, char **);
|
||||||
|
|
||||||
~ConfigFile();
|
~ConfigFile();
|
||||||
|
|
||||||
@@ -75,6 +75,10 @@ private:
|
|||||||
std::string logDir;
|
std::string logDir;
|
||||||
std::string dataDir;
|
std::string dataDir;
|
||||||
int configRev;
|
int configRev;
|
||||||
|
bool noWriteAccess;
|
||||||
|
|
||||||
|
std::string logOnOffDefault;
|
||||||
|
std::string claNoWriteAccess;
|
||||||
|
|
||||||
ConfigState myConfigState;
|
ConfigState myConfigState;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,6 +34,13 @@ joinNetworkGameDialogImpl::joinNetworkGameDialogImpl(QWidget *parent, ConfigFile
|
|||||||
// QShortcut *connectKey = new QShortcut(QKeySequence(Qt::Key_Enter), this);
|
// QShortcut *connectKey = new QShortcut(QKeySequence(Qt::Key_Enter), this);
|
||||||
// connect( connectKey, SIGNAL(activated() ), pushButton_connect, SLOT( click() ) );
|
// connect( connectKey, SIGNAL(activated() ), pushButton_connect, SLOT( click() ) );
|
||||||
|
|
||||||
|
if (myConfig->readConfigInt("CLA_NoWriteAccess")) {
|
||||||
|
|
||||||
|
pushButton_save->setDisabled(TRUE);
|
||||||
|
pushButton_delete->setDisabled(TRUE);
|
||||||
|
treeWidget->setDisabled(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
connect( pushButton_connect, SIGNAL( clicked() ), this, SLOT( startClient() ) );
|
connect( pushButton_connect, SIGNAL( clicked() ), this, SLOT( startClient() ) );
|
||||||
connect( pushButton_save, SIGNAL( clicked() ), this, SLOT( saveServerProfile() ) );
|
connect( pushButton_save, SIGNAL( clicked() ), this, SLOT( saveServerProfile() ) );
|
||||||
connect( pushButton_delete, SIGNAL( clicked() ), this, SLOT( deleteServerProfile() ) );
|
connect( pushButton_delete, SIGNAL( clicked() ), this, SLOT( deleteServerProfile() ) );
|
||||||
|
|||||||
+1
-2
@@ -64,8 +64,7 @@ class GuiWrapper;
|
|||||||
int main( int argc, char **argv )
|
int main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
//create defaultconfig
|
//create defaultconfig
|
||||||
bool configFirstStart = 1;
|
ConfigFile *myConfig = new ConfigFile(argc, argv);
|
||||||
ConfigFile *myConfig = new ConfigFile(configFirstStart);
|
|
||||||
|
|
||||||
//ENABLE_LEAK_CHECK();
|
//ENABLE_LEAK_CHECK();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user