|
|
/*********************************************************************
|
|
|
*文件说明: 配置文件库
|
|
|
*作者: logos
|
|
|
*日期: 2018/09/01
|
|
|
*修改日志: 2018/09/01 logos 从comm剥离
|
|
|
|
|
|
***********************************************************************/
|
|
|
#pragma once
|
|
|
#ifndef DLL_INCLUDE_CONFIG_H
|
|
|
#define DLL_INCLUDE_CONFIG_H
|
|
|
|
|
|
#ifndef EXPORT_C
|
|
|
#define EXPORT_C extern "C"
|
|
|
#endif
|
|
|
|
|
|
#ifndef WINAPI
|
|
|
#define WINAPI __stdcall
|
|
|
#endif
|
|
|
|
|
|
#ifndef MAX_NAME_LEN
|
|
|
#define MAX_NAME_LEN 32
|
|
|
#endif
|
|
|
|
|
|
#ifndef KEY_LEN
|
|
|
#define KEY_LEN 128 //字段长度
|
|
|
#endif
|
|
|
|
|
|
struct TConfig
|
|
|
{//配置项列表
|
|
|
char key[KEY_LEN]; //段落名
|
|
|
char name[KEY_LEN]; //配置项名
|
|
|
};
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 初始化配置模块
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0 ,失败返回错误码
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI cfg_init();
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 关闭配置模块
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI cfg_deinit();
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取当前日志保存目录
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回日志保存目录<256字节,失败返回NULL
|
|
|
*PS: 除非严重错误,否则不可能失败,默认返回当前目录
|
|
|
*PS: 该配置保存在系统配置文件
|
|
|
******************************************************/
|
|
|
EXPORT_C const char* WINAPI get_log_path();
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取当前日志保存目录
|
|
|
*Intput: NULL
|
|
|
*Output: path 当前日志保存目录 保证256字节
|
|
|
*Return: 成功返回0 失败返回错误码
|
|
|
*PS: 该配置保存在系统配置文件
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI get_log_paths(char* path);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 设置当前日志保存目录
|
|
|
*Intput: path 待设置目录 <256字节
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回日志保存目录,失败返回NULL
|
|
|
*PS: 必须保证该目录是存在的,否则设置会失败
|
|
|
*PS: 该配置保存在系统配置文件
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI set_log_path(const char* path);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 加载项目配置
|
|
|
*Intput: file 配置文件目录 <256字节
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
*PS: 项目配置默认是空,需要手动加载
|
|
|
*PS: 若不传入文件路径,则使用上一次的路径加载
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI cfg_load(const char* file = 0);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 增加/修改一个配置项 -- 项目配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
lpValue 值 ?=xxx <256字节
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI modify_cfg(const char* key, const char* name, const char* lpValue);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取一个配置项 -- 项目配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回读取到的值<256字节,失败返回NULL
|
|
|
******************************************************/
|
|
|
EXPORT_C const char* WINAPI get_cfg(const char* key, const char* name);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取一个配置项 -- 项目配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
*Output: pval 配置值 -- 保证传入256个字节
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI get_cfgs(const char* key, const char* name, char* pval);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 增加/修改一个配置项(int型) -- 项目配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
iValue 值 ?=xxx (int)
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI modify_cfg_int(const char* key, const char* name, int iValue);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取一个配置项(int型) -- 项目配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回读取到的值(int),失败返回0
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI get_cfg_int(const char* key, const char* name);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 增加/修改一个配置项(double型) -- 项目配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
dValue 值 ?=xxx (double)
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI modify_cfg_double(const char* key, const char* name, double dValue);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取一个配置项(double型) -- 项目配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回读取到的值(double),失败返回0
|
|
|
******************************************************/
|
|
|
EXPORT_C double WINAPI get_cfg_double(const char* key, const char* name);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 保存配置到文件 -- 包含项目配置和系统配置
|
|
|
*Intput: NULL
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码< 0
|
|
|
*PS: 仅修改后才会保存到文件
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI save_cfg_file();
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取项目配置所有配置项 -- 系统配置不支持
|
|
|
*Intput: plist 配置项内容
|
|
|
nsize 缓冲区大小
|
|
|
*Output: plist 配置项内容
|
|
|
*Return: 返回获取到的配置项数量
|
|
|
*PS: 可以先传入NULL获取大小,保证缓冲区够大后再获取数据
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI get_cfg_list(TConfig* plist = 0, int nsize = 0);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 把一字符串写入一文件,首次写入会打开文件,如果文件存在,
|
|
|
则打开并移到最后,若不存在,则创建并打开。反初始化时会自动关闭
|
|
|
*Intput: file 文件名/相对路径 <128字节
|
|
|
msgFormat 字符串格式,与printf用法相同
|
|
|
后面可加N个参数,最大支持1024个字节
|
|
|
*Output: 无
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
*PS: 基于日志配置目录读写
|
|
|
*PS: 此接口需要外部写入换行符
|
|
|
*PS: 假设日志目录为:"D:\\log" 传入file: "123.dat"
|
|
|
则实际写入文件目录为"D:\\log\\123.dat"
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI files_write(const char* file, const char *pszFormat, ...);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 与files_write功能类似 -- 不支持格式化写入,不限制单次写入长度
|
|
|
*Intput: file 文件名 <128字节
|
|
|
pszContent 要写入的内容
|
|
|
npos 可选参数,默认-1为从文件结尾写入
|
|
|
*Output: 无
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
*PS: 基于日志配置目录读写
|
|
|
*PS: 此接口需要外部写入换行符
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI files_writes(const char* file, const char *pszContent, int npos = -1);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 逐行读取文件内容,可以传NULL获取文件大小
|
|
|
*Intput: file 文件名/相对路径 <128字节
|
|
|
pszContent 要读取的内容缓冲区,必须外部保证缓冲区大小
|
|
|
nline 可选参数,读取第几行,从0开始?默认-1为从当前位置读取
|
|
|
*Output: 无
|
|
|
*Return: 成功返回读取到的字节大小,失败返回错误码<0,文件结尾返回0
|
|
|
*PS: 基于日志配置目录读写
|
|
|
*PS: 若不传入pszContent 则返回该文件大小,但不会实际读取
|
|
|
*PS: 打开文件后,默认游标会在文件开始
|
|
|
*PS: 此接口会自动过滤换行符
|
|
|
*PS: nline<0时从当前位置读取,并移动游标到读取后
|
|
|
*PS: nline>=0时从指定行开始读取,并移动游标到读取后
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI files_read(const char* file, char *pszContent = 0, int nline = -1);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 关闭并保存一个已经打开的文件
|
|
|
*Intput: file 文件名/相对路径 <128字节
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
*PS: 基于日志配置目录读写
|
|
|
*PS: file 传NULL时,关闭所有文件
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI files_close(const char* file = 0);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 保存一个已经打开的文件到硬盘,不关闭
|
|
|
*Intput: file 文件名/相对路径 基于日志目录下创建 <128字节
|
|
|
newname 新文件名,若指定,则会另存一个拷贝 <128字节
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
*PS: 基于日志配置目录读写
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI files_save(const char* file, const char* newname = 0);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取所有已经打开的文件名(路径),以'/0'(0结束符)隔开
|
|
|
*Intput: pszFileList 文件名/相对路径 缓冲区
|
|
|
*Output: NULL
|
|
|
*Return: 若不存在文件名(路径)返回0,否则返回所有文件名总长度
|
|
|
*PS: 每个文件名总长度包含文件名实际长度+1(0结束符)
|
|
|
*PS: 基于日志配置目录读写
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI files_get_list(char* pszFileList = 0);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 增加/修改一个系统配置项 -- 系统配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
lpValue 值 ?=xxx <256字节
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
*PS: 基于系统配置目录 //data//sys.cfg
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI modify_sys_cfg(const char* key, const char* name, const char* lpValue);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取一个系统配置项 -- 系统配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回读取到的值 <256字节,失败返回NULL
|
|
|
*PS: 基于系统配置目录 //data//sys.cfg
|
|
|
******************************************************/
|
|
|
EXPORT_C const char* WINAPI get_sys_cfg(const char* key, const char* name);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取一个系统配置项 -- 系统配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
*Output: pval 配置值 -- 保证传入256个字节
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
*PS: 基于系统配置目录 //data//sys.cfg
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI get_sys_cfgs(const char* key, const char* name, char* pval);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 增加/修改一个配置项(int型) -- 系统配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
iValue 值 ?=xxx (int)
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
*PS: 基于系统配置目录 //data//sys.cfg
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI modify_sys_cfg_int(const char* key, const char* name, int iValue);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取一个配置项(int型) -- 系统配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回读取到的值(int),失败返回0
|
|
|
*PS: 基于系统配置目录 //data//sys.cfg
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI get_sys_cfg_int(const char* key, const char* name);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 增加/修改一个配置项(double型) -- 系统配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
dValue 值 ?=xxx (double)
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回0,失败返回错误码
|
|
|
*PS: 基于系统配置目录 //data//sys.cfg
|
|
|
******************************************************/
|
|
|
EXPORT_C int WINAPI modify_sys_cfg_double(const char* key, const char* name, double dValue);
|
|
|
|
|
|
/****************************************************
|
|
|
*Function: 获取一个配置项(double型) -- 系统配置
|
|
|
*Intput: key 段落名 [xxx] -- 不能包含'/' <32字节
|
|
|
name 关键字 xxx=? <32字节
|
|
|
*Output: NULL
|
|
|
*Return: 成功返回读取到的值(double),失败返回0
|
|
|
*PS: 基于系统配置目录 //data//sys.cfg
|
|
|
******************************************************/
|
|
|
EXPORT_C double WINAPI get_sys_cfg_double(const char* key, const char* name);
|
|
|
|
|
|
#endif //防止重复包含头文件
|