Introduction
The CIniEx
class contains the following methods to work with INI files:
- add sections, delete sections, update sections
- add key, delete key, update key, get key data
- clear data
- read INI file, save INI file
This class carries out all of the above-mentioned functions in memory.
It also allows you to save comments within an INI file. Comments must precede
the section or key that
they belong to.
Class CIniEx
supports formats of Wine
INI files Editor. Additional ability of Wine Ini files Editor is KeyType
Section, which keeps
for a key one of the following types: character, Boolean, integer, filename, directory, list, color, font, link.
But you can work without additional ability of Wine Ini files Editor.
The CIniEx
class header is as follows:
#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;
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
{
public:
CIniEx();
~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
is included in the demo project ZIP file as a sample of how to use the CIniEx
class.