Click here to Skip to main content
Licence 
First Posted 30 May 2000
Views 67,609
Bookmarked 43 times

CIniEx - Class with Extended INI file support

By | 16 Apr 2001 | Article
Class CIniEx carries out an extended set of INI file functions in memory

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;   // 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 is included in the demo project ZIP file as a sample of how to use the CIniEx class.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Oscar Kogosov



Israel Israel

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralIni Management PinmemberMember 30271108:03 3 Jan '08  
GeneralBug & Fix for the use of the function ReadFile(...) Pinmemberalanlive0:01 24 Jun '05  
GeneralCProfile.cpp File PinmemberWilliamD21:37 31 Aug '04  
GeneralThe Zip File CIniEx_demo is corrupted PinmemberHector T4:58 25 Mar '03  
GeneralUsing CIniEx without MFC (dll included) PinmemberPacoGM12:12 27 Jan '03  
GeneralKeys are length limited PinmemberAntanael6:51 11 Oct '01  
GeneralRe: Keys are length limited Pinmemberalanlive12:20 24 Jun '05  
Questioncan not find CProfile.cpp PinsussXia5:09 5 Jun '00  
AnswerRe: can not find CProfile.cpp PinsussOscar17:54 7 Jun '00  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 17 Apr 2001
Article Copyright 2000 by Oscar Kogosov
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid