CIniEx - 具有扩展 INI 文件支持的类






2.60/5 (5投票s)
2000年5月31日

82445

2921
类 CIniEx 在内存中执行一系列扩展的 INI 文件功能
引言
CIniEx
类包含以下方法来处理 INI 文件
- 添加节、删除节、更新节
- 添加键、删除键、更新键、获取键数据
- 清除数据
- 读取 INI 文件、保存 INI 文件
该类在内存中执行上述所有功能。
它还允许您在 INI 文件中保存注释。注释必须位于它们所属的节或键之前。
类 CIniEx
支持 Wine INI 文件编辑器 的格式。 Wine Ini 文件编辑器的附加功能是 KeyType
节,它为键保留以下类型之一:字符、布尔值、整数、文件名、目录、列表、颜色、字体、链接。但您可以无需 Wine Ini 文件编辑器的附加功能即可工作。
CIniEx
类的头文件如下
#define CINIEX_CHARACTER 0 #define CINIEX_BOOLEAN 1 #define CINIEX_INTEGER 2 #define CINIEX_FILENAME 3 #define CINIEX_DIRECTORY 4 #define CINIEX_LIST 5 #define CINIEX_COLOR 6 #define CINIEX_FONT 7 #define CINIEX_LINK 8 #define CINIEX_TYPE_MAX 9 #define CINIEX_EMPTY 9 typedef struct { DWORD UpdateFlag; // 0 - normal // 1 - updated // 2 - deleted CString Comment; CString Key; CString Value; } KEY_STRUCT; class CSection : public CObject { public: DWORD UpdateFlag; CString Comment; CString Name; CArray <KEY_STRUCT,KEY_STRUCT> key; }; typedef struct { CString Section; CString Key; } LINK_STRUCT; //-------------------------------- typedef struct { int index; CString Type; } KEYTYPE_STRUCT; ///////////////////////////////////////////////////////////////////////////// class CIniEx { // Construction public: CIniEx(); // standard constructor ~CIniEx(); BOOL ReadFile(char* s); void ShowSetOfSections(); int GetIndexForKey(char* Section,char* Key); BOOL GetKeyData(char* Section,char* Key,char* Value, char* Comment,char* Type); int GetIndexForSection(char* Section); void ClearMemory(); BOOL GetDataFromKeyTypeSection(char* Section, char* Key, KEYTYPE_STRUCT* pkt); BOOL GetDataFromKeyTypeSection(char* Key, KEYTYPE_STRUCT* pkt); char* GetKeyTypeString(DWORD type); BOOL AddKeyToKeyTypeSection(char* Section, char* Key, char* Type); BOOL AddKeyToKeyTypeSection(char* Section, char* Key, DWORD Type); int DeleteIndexFromKeyTypeSection(char* Key); SaveFile(char* s); BOOL AddNewSection(char* section,char* comment,int* pindex); BOOL AddKeyTypeSection(int* pindex); BOOL DeleteSection(char* section); BOOL AddNewKey(char* section, char* key, char* value, char* comment, char* type, int* pindex); BOOL AddNewKey(char* section, char* key, char* value, char* comment, DWORD type, int* pindex); BOOL DeleteKey(char* section,char* key); BOOL UpdateSection(char* sectionOldName, char* sectionNewName, char* comment); BOOL UpdateKey(char* section, char* keyOld, char* keyNew, char* value, char* comment, char* type); BOOL UpdateKey(char* section, char* keyOld, char* keyNew, char* value, char* comment, DWORD type); CObArray SetOfSections; char FullName[FILENAME_MAX]; };
CIniExDemo
包含在演示项目 ZIP 文件中,作为如何使用 CIniEx
类的一个示例。