2016-07-26 19:31:47 +03:00
|
|
|
#pragma once
|
2016-07-26 03:22:47 +03:00
|
|
|
|
|
|
|
// Max length of line in config file.
|
|
|
|
#define MAX_CONF_LEN 1024
|
|
|
|
|
|
|
|
// Supported config value-types.
|
2016-07-26 19:31:47 +03:00
|
|
|
enum cf_type_t
|
|
|
|
{
|
|
|
|
CF_NONE = 0,
|
2016-07-26 03:22:47 +03:00
|
|
|
CF_INT,
|
|
|
|
CF_BOOL,
|
|
|
|
CF_STR,
|
|
|
|
CF_PATH,
|
2016-07-26 19:31:47 +03:00
|
|
|
};
|
2016-07-26 03:22:47 +03:00
|
|
|
|
2016-07-26 19:31:47 +03:00
|
|
|
struct option_t
|
|
|
|
{
|
|
|
|
char *name; // option name
|
|
|
|
cf_type_t type; // option type
|
|
|
|
void *dest; // addr of destination variable, or handler function
|
|
|
|
char *init; // initial value, as a string, just as config file would
|
|
|
|
};
|
2016-07-26 15:18:32 +03:00
|
|
|
|
2017-01-13 03:00:23 +03:00
|
|
|
class MConfig
|
|
|
|
{
|
2016-07-26 19:31:47 +03:00
|
|
|
public:
|
|
|
|
MConfig();
|
|
|
|
|
|
|
|
void init(option_t *global_options);
|
2016-07-30 02:03:01 +03:00
|
|
|
bool load(const char *filename);
|
|
|
|
bool set(const char *key, const char *value) const;
|
2016-07-26 19:31:47 +03:00
|
|
|
void show() const;
|
2017-01-18 18:14:02 +03:00
|
|
|
void set_directory();
|
|
|
|
const char *directory() const;
|
2016-07-26 19:31:47 +03:00
|
|
|
|
2017-01-13 03:00:23 +03:00
|
|
|
int m_debuglevel; // to use for meta_debug
|
2017-01-18 18:14:02 +03:00
|
|
|
char *m_gamedll; // string if specified in config.ini
|
|
|
|
char *m_exec_cfg; // ie exec.cfg
|
2017-01-13 03:00:23 +03:00
|
|
|
|
2016-07-26 19:31:47 +03:00
|
|
|
private:
|
2017-01-13 03:00:23 +03:00
|
|
|
option_t *m_list;
|
|
|
|
char *m_filename;
|
2017-01-18 18:14:02 +03:00
|
|
|
char m_directory[MAX_PATH];
|
2016-07-26 19:31:47 +03:00
|
|
|
|
|
|
|
option_t *find(const char *lookup) const;
|
2016-07-30 02:03:01 +03:00
|
|
|
static bool set(option_t *setp, const char *value);
|
2016-07-26 19:31:47 +03:00
|
|
|
// Private; to satisfy -Weffc++ "has pointer data members but does
|
|
|
|
// not override" copy/assignment constructor.
|
|
|
|
void operator=(const MConfig &src);
|
|
|
|
MConfig(const MConfig &src);
|
2016-07-26 03:22:47 +03:00
|
|
|
};
|
2017-01-18 18:14:02 +03:00
|
|
|
|
|
|
|
inline const char *MConfig::directory() const
|
|
|
|
{
|
|
|
|
return m_directory;
|
|
|
|
}
|