2023-10-28 18:49:21 +08:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-02-20 23:39:56 +08:00
|
|
|
#define MAX_CONFIG_STRSIZE 256
|
2024-04-16 22:42:10 +08:00
|
|
|
#define MAX_CONFIG_VARIABLES 512
|
|
|
|
#define MAX_CONFIG_VARIABLE_NAME 40
|
2024-02-19 21:31:01 +08:00
|
|
|
|
2024-04-16 22:42:10 +08:00
|
|
|
enum CONFIG_VARTYPE
|
|
|
|
{
|
|
|
|
CONFIG_VARTYPE_NONE = 0,
|
|
|
|
CONFIG_VARTYPE_INT,
|
|
|
|
CONFIG_VARTYPE_STRING,
|
|
|
|
CONFIG_VARTYPE_FLOAT,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConfigVariable_s
|
|
|
|
{
|
|
|
|
char szVarName[MAX_CONFIG_VARIABLE_NAME+1];
|
|
|
|
BOOL bReadOnly;
|
|
|
|
CONFIG_VARTYPE VarType;
|
|
|
|
int iVarValue;
|
|
|
|
float fVarValue;
|
|
|
|
char* szVarValue;
|
|
|
|
};
|
2023-10-28 18:49:21 +08:00
|
|
|
|
|
|
|
class CConfig
|
|
|
|
{
|
|
|
|
private:
|
2024-04-16 22:42:10 +08:00
|
|
|
ConfigVariable_s m_Variables[MAX_CONFIG_VARIABLES];
|
|
|
|
BOOL m_bVariableSlotState[MAX_CONFIG_VARIABLES];
|
|
|
|
CHAR m_szConfigFileName[MAX_PATH+1];
|
|
|
|
int m_iUpperIndex;
|
2024-02-20 23:39:56 +08:00
|
|
|
|
2023-10-28 18:49:21 +08:00
|
|
|
public:
|
2024-04-16 22:42:10 +08:00
|
|
|
~CConfig();
|
|
|
|
void RecalcSize();
|
|
|
|
int FindVariableIndex(char *szName);
|
|
|
|
bool IsVariableExist(char *szName);
|
|
|
|
int AddVariable(char *szName);
|
|
|
|
int GetIntVariable(char *szName);
|
|
|
|
char *GetStringVariable(char *szName);
|
|
|
|
float GetFloatVariable(char *szName);
|
|
|
|
BOOL RemoveVariable(char *szName);
|
|
|
|
CONFIG_VARTYPE GetVariableType(char *szName);
|
|
|
|
ConfigVariable_s *GetVariableAtIndex(int iIndex);
|
|
|
|
CONFIG_VARTYPE DetermineDataType(char *szData);
|
|
|
|
BOOL WriteFile();
|
|
|
|
BOOL SetIntVariable(char *szName, int iValue, BOOL bReadOnly = FALSE);
|
|
|
|
BOOL SetStringVariable(char *szName, char *szValue, BOOL bReadOnly = FALSE);
|
|
|
|
BOOL SetFloatVariable(char *szName, float fValue, BOOL bReadOnly = FALSE);
|
|
|
|
void AddConfigEntry(char *szName, char *szData);
|
2024-02-19 21:31:01 +08:00
|
|
|
BOOL ReadFile();
|
2024-04-16 22:42:10 +08:00
|
|
|
CConfig(char* szFileName);
|
2023-10-28 18:49:21 +08:00
|
|
|
};
|