2011-07-02 23:03:18 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
* PokerTH - The open source texas holdem engine *
|
2012-12-25 15:06:23 +01:00
|
|
|
* Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
|
2011-07-02 23:03:18 +00:00
|
|
|
* *
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU Affero General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
2012-12-25 15:06:23 +01:00
|
|
|
* *
|
|
|
|
|
* *
|
|
|
|
|
* Additional permission under GNU AGPL version 3 section 7 *
|
|
|
|
|
* *
|
|
|
|
|
* If you modify this program, or any covered work, by linking or *
|
|
|
|
|
* combining it with the OpenSSL project's OpenSSL library (or a *
|
|
|
|
|
* modified version of that library), containing parts covered by the *
|
|
|
|
|
* terms of the OpenSSL or SSLeay licenses, the authors of PokerTH *
|
|
|
|
|
* (Felix Hammer, Florian Thauer, Lothar May) grant you additional *
|
|
|
|
|
* permission to convey the resulting work. *
|
|
|
|
|
* Corresponding Source for a non-source form of such a combination *
|
|
|
|
|
* shall include the source code for the parts of OpenSSL used as well *
|
|
|
|
|
* as that of the covered work. *
|
2011-07-03 19:45:08 +00:00
|
|
|
*****************************************************************************/
|
2012-12-25 15:06:23 +01:00
|
|
|
|
2011-07-03 19:45:08 +00:00
|
|
|
#ifndef CONFIGFILE_H
|
2007-01-21 16:01:37 +00:00
|
|
|
#define CONFIGFILE_H
|
|
|
|
|
|
2007-05-16 01:08:01 +00:00
|
|
|
#include <vector>
|
2007-05-22 22:40:44 +00:00
|
|
|
#include <string>
|
2007-05-16 01:08:01 +00:00
|
|
|
|
2013-08-29 17:26:08 +02:00
|
|
|
#ifndef Q_MOC_RUN
|
2007-08-22 23:01:32 +00:00
|
|
|
#include <boost/thread.hpp>
|
2013-08-29 17:26:08 +02:00
|
|
|
#endif
|
2007-05-16 01:08:01 +00:00
|
|
|
|
2010-07-11 20:36:50 +00:00
|
|
|
enum ConfigState { NONEXISTING, OLD, OK };
|
2009-03-28 20:34:23 +00:00
|
|
|
enum ConfigType { CONFIG_TYPE_INT, CONFIG_TYPE_STRING, CONFIG_TYPE_INT_LIST, CONFIG_TYPE_STRING_LIST };
|
2007-01-21 16:01:37 +00:00
|
|
|
|
2007-06-16 22:08:52 +00:00
|
|
|
class QtToolsInterface;
|
2007-04-21 20:42:50 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
class ConfigFile
|
|
|
|
|
{
|
2007-01-21 16:01:37 +00:00
|
|
|
public:
|
2008-02-10 12:38:12 +00:00
|
|
|
ConfigFile(char *argv0, bool readonly);
|
2007-01-21 16:01:37 +00:00
|
|
|
|
2007-05-22 22:40:44 +00:00
|
|
|
~ConfigFile();
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2007-05-16 01:08:01 +00:00
|
|
|
void fillBuffer();
|
2012-01-09 18:40:51 +00:00
|
|
|
void checkAndCorrectBuffer();
|
2007-08-22 20:01:08 +00:00
|
|
|
void writeBuffer() const;
|
2007-05-16 01:08:01 +00:00
|
|
|
|
2007-05-08 20:54:36 +00:00
|
|
|
void updateConfig(ConfigState);
|
2011-10-20 11:36:41 +00:00
|
|
|
ConfigState getConfigState() const;
|
2007-04-20 08:18:18 +00:00
|
|
|
|
2007-08-22 20:01:08 +00:00
|
|
|
std::string readConfigString(std::string varName) const;
|
2009-03-28 20:34:23 +00:00
|
|
|
std::list<std::string> readConfigStringList(std::string varName) const;
|
2007-05-22 22:40:44 +00:00
|
|
|
void writeConfigString(std::string varName, std::string varCont);
|
2009-03-28 20:34:23 +00:00
|
|
|
void writeConfigStringList(std::string varName, std::list<std::string> varCont);
|
2007-08-22 20:01:08 +00:00
|
|
|
int readConfigInt(std::string varName) const;
|
2007-09-22 23:58:17 +00:00
|
|
|
std::list<int> readConfigIntList(std::string varName) const;
|
2007-01-22 21:29:51 +00:00
|
|
|
void writeConfigInt(std::string varName, int varCont);
|
2007-09-22 23:58:17 +00:00
|
|
|
void writeConfigIntList(std::string varName, std::list<int> varCont);
|
2012-01-06 08:17:56 +00:00
|
|
|
void deleteConfigFile();
|
2007-04-18 00:11:24 +00:00
|
|
|
|
2012-01-09 18:40:51 +00:00
|
|
|
protected:
|
|
|
|
|
void checkAndCorrectPlayerNames();
|
|
|
|
|
|
2007-04-20 23:14:08 +00:00
|
|
|
private:
|
2007-08-22 20:01:08 +00:00
|
|
|
|
2007-09-30 13:08:24 +00:00
|
|
|
mutable boost::recursive_mutex m_configMutex;
|
2007-05-08 20:54:36 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
struct ConfigInfo {
|
2007-09-22 23:58:17 +00:00
|
|
|
ConfigInfo(const std::string &n, ConfigType t, const std::string &d, const std::list<std::string> &l =std::list<std::string>()) : name(n), type(t), defaultValue(d), defaultListValue(l) {}
|
2007-05-08 20:54:36 +00:00
|
|
|
std::string name;
|
|
|
|
|
ConfigType type;
|
|
|
|
|
std::string defaultValue;
|
2007-09-22 23:58:17 +00:00
|
|
|
std::list<std::string> defaultListValue;
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2007-05-08 20:54:36 +00:00
|
|
|
};
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2007-05-22 22:40:44 +00:00
|
|
|
std::vector<ConfigInfo> configList;
|
|
|
|
|
std::vector<ConfigInfo> configBufferList;
|
2007-05-08 20:54:36 +00:00
|
|
|
|
2007-04-20 23:14:08 +00:00
|
|
|
std::string configFileName;
|
|
|
|
|
std::string logDir;
|
|
|
|
|
std::string dataDir;
|
2007-09-08 18:53:59 +00:00
|
|
|
std::string cacheDir;
|
2009-03-28 20:34:23 +00:00
|
|
|
std::string defaultGameTableStyle;
|
|
|
|
|
std::string defaultCardDeck;
|
|
|
|
|
|
2007-04-20 08:18:18 +00:00
|
|
|
int configRev;
|
2007-05-16 08:55:49 +00:00
|
|
|
bool noWriteAccess;
|
|
|
|
|
|
|
|
|
|
std::string logOnOffDefault;
|
2007-05-05 20:11:49 +00:00
|
|
|
|
2007-05-08 20:54:36 +00:00
|
|
|
ConfigState myConfigState;
|
2007-06-16 22:08:52 +00:00
|
|
|
QtToolsInterface *myQtToolsInterface;
|
2007-09-17 23:06:10 +00:00
|
|
|
|
2007-10-01 00:33:05 +00:00
|
|
|
char *myArgv0;
|
2007-01-21 16:01:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|