2014-10-14 13:11:37 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Colobot: Gold Edition source code
|
2016-02-13 13:11:30 +00:00
|
|
|
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
|
2015-08-22 14:40:02 +00:00
|
|
|
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
2014-10-14 13:11:37 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see http://gnu.org/licenses
|
|
|
|
*/
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-09 15:51:10 +00:00
|
|
|
/**
|
2015-07-19 13:30:30 +00:00
|
|
|
* \file common/config_file.h
|
2012-09-09 15:51:10 +00:00
|
|
|
* \brief Class for loading profile (currently for loading ini config file)
|
|
|
|
*/
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2012-09-09 15:51:10 +00:00
|
|
|
#include "common/singleton.h"
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-10-17 19:55:45 +00:00
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
|
2012-09-09 15:51:10 +00:00
|
|
|
#include <string>
|
2013-03-17 18:01:32 +00:00
|
|
|
|
2012-08-12 13:00:37 +00:00
|
|
|
|
|
|
|
/**
|
2015-07-19 13:30:30 +00:00
|
|
|
* \class CConfigFile
|
2012-08-12 13:00:37 +00:00
|
|
|
*
|
2015-07-19 13:30:30 +00:00
|
|
|
* \brief Class for loading config file
|
2012-08-12 13:00:37 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-07-19 13:30:30 +00:00
|
|
|
class CConfigFile : public CSingleton<CConfigFile>
|
2012-08-09 21:04:29 +00:00
|
|
|
{
|
2013-05-26 15:47:54 +00:00
|
|
|
public:
|
2015-07-19 13:30:30 +00:00
|
|
|
CConfigFile();
|
|
|
|
virtual ~CConfigFile();
|
2013-05-26 15:47:54 +00:00
|
|
|
|
2014-08-12 19:24:33 +00:00
|
|
|
/** Set flag to force using ini file from current directory */
|
|
|
|
void SetUseCurrentDirectory(bool useCurrentDirectory);
|
2014-08-12 18:03:56 +00:00
|
|
|
|
2015-07-19 13:30:30 +00:00
|
|
|
/** Loads colobot.ini
|
2014-08-12 19:24:33 +00:00
|
|
|
* \return return true on success
|
|
|
|
*/
|
|
|
|
bool Init();
|
2013-05-26 15:47:54 +00:00
|
|
|
|
2015-07-19 19:35:55 +00:00
|
|
|
/** Saves colobot.ini
|
|
|
|
* \return return true on success
|
|
|
|
*/
|
|
|
|
bool Save();
|
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
/** Sets string value in section under specified key
|
2014-08-12 19:24:33 +00:00
|
|
|
* \return return true on success
|
|
|
|
*/
|
|
|
|
bool SetStringProperty(std::string section, std::string key, std::string value);
|
2013-05-26 15:47:54 +00:00
|
|
|
|
|
|
|
/** Gets string value in section under specified key
|
2014-08-12 19:24:33 +00:00
|
|
|
* \return return true on success
|
|
|
|
*/
|
2015-08-15 16:26:27 +00:00
|
|
|
bool GetStringProperty(std::string section, std::string key, std::string& value);
|
2013-05-26 15:47:54 +00:00
|
|
|
|
|
|
|
/** Sets int value in section under specified key
|
2014-08-12 19:24:33 +00:00
|
|
|
* \return return true on success
|
|
|
|
*/
|
|
|
|
bool SetIntProperty(std::string section, std::string key, int value);
|
2013-05-26 15:47:54 +00:00
|
|
|
|
2015-08-15 16:26:27 +00:00
|
|
|
/** Sets bool value in section under specified key
|
|
|
|
* \return return true on success
|
|
|
|
*/
|
|
|
|
bool SetBoolProperty(std::string section, std::string key, bool value);
|
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
/** Gets int value in section under specified key
|
2015-08-15 16:26:27 +00:00
|
|
|
* \a value will only be changed if key exists
|
2014-08-12 19:24:33 +00:00
|
|
|
* \return return true on success
|
|
|
|
*/
|
|
|
|
bool GetIntProperty(std::string section, std::string key, int &value);
|
2013-05-26 15:47:54 +00:00
|
|
|
|
|
|
|
/** Sets float value in section under specified key
|
2015-08-15 16:26:27 +00:00
|
|
|
* \a value will only be changed if key exists
|
2014-08-12 19:24:33 +00:00
|
|
|
* \return return true on success
|
|
|
|
*/
|
|
|
|
bool SetFloatProperty(std::string section, std::string key, float value);
|
2013-05-26 15:47:54 +00:00
|
|
|
|
|
|
|
/** Gets float value in section under specified key
|
2015-08-15 16:26:27 +00:00
|
|
|
* \a value will only be changed if key exists
|
2014-08-12 19:24:33 +00:00
|
|
|
* \return return true on success
|
|
|
|
*/
|
|
|
|
bool GetFloatProperty(std::string section, std::string key, float &value);
|
2013-05-26 15:47:54 +00:00
|
|
|
|
2015-08-15 16:26:27 +00:00
|
|
|
/** Gets bool value in section under specified key
|
|
|
|
* \a value will only be changed if key exists
|
|
|
|
* \return return true on success
|
|
|
|
*/
|
|
|
|
bool GetBoolProperty(std::string section, std::string key, bool &value);
|
|
|
|
|
2013-05-26 15:47:54 +00:00
|
|
|
private:
|
|
|
|
boost::property_tree::ptree m_propertyTree;
|
2015-07-19 19:35:55 +00:00
|
|
|
bool m_needsSave;
|
2014-08-12 19:24:33 +00:00
|
|
|
bool m_useCurrentDirectory;
|
2015-07-19 13:30:30 +00:00
|
|
|
bool m_loaded;
|
2012-08-09 21:04:29 +00:00
|
|
|
};
|
2012-08-12 13:00:37 +00:00
|
|
|
|
2016-03-26 17:34:26 +00:00
|
|
|
//! Global function to get config file instance
|
2015-07-19 13:30:30 +00:00
|
|
|
inline CConfigFile & GetConfigFile()
|
2013-05-26 15:47:54 +00:00
|
|
|
{
|
2016-03-26 17:34:26 +00:00
|
|
|
return CConfigFile::GetInstance();
|
2012-08-12 13:00:37 +00:00
|
|
|
}
|