save and restore config files like ini

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Epsilon
Posts: 38
Joined: Fri Jan 09, 2004 1:46 pm
Location: Argentina

save and restore config files like ini

Post by Epsilon »

hi, how can i save some information like the keys configuration in an ini file and restore this later.

and to write information of a saved game in a binary format?

there is some class for this?

thanks.
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

there is not currently a class for serialization, no.

I suggest using an XML library, such as tinyXML.

In my own code, I am currently using a non-compliant XML class I wrote called qXML:
http://www.skyesurfer.net/keless/IrrLicht/ICE/ (look at version 1.3)

but I plan on switching over to use tinyXML
a screen cap is worth 0x100000 DWORDS
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Re: save and restore config files like ini

Post by rt »

Epsilon wrote:hi, how can i save some information like the keys configuration in an ini file and restore this later.

and to write information of a saved game in a binary format?

there is some class for this?

thanks.
use libxml2. simple and powerful interface. http://www.xmlsoft.org/

here is a quick example of loading an xml file

Code: Select all

   xmlDoc *doc = NULL;
    xmlNode *root_element = NULL,*curr=NULL;
	doc = xmlParseFile("config.xml");
    if (doc == NULL) {
        DOUT("WARNING: could not xml parse config file,using defaults\n");
    } else {
		//Get the root element node
		root_element = xmlDocGetRootElement(doc);
		int size_x = xmlReadInt(root_element,"screen_size_x");
		char name[80];
		strcpy(name,xmlReadString(root_element,"username");
		/*free the document */
		xmlFreeDoc(doc);
		xmlCleanupParser();
i use it in my projects to read/write xml files. very helpful since it loads the xml file into a tree-like structure which can be traversed and edited quickly and easily. to keep the filesize low we also compress the config files using a gzip file class, but i think libxml2 has it's own compression as well.
Epsilon
Posts: 38
Joined: Fri Jan 09, 2004 1:46 pm
Location: Argentina

Post by Epsilon »

Can an XML parser write and read INI files ??

An INI file is more easy to config than an XML, besides, i dont know xml language. :oops:

thanks.
madinitaly
Posts: 92
Joined: Sat Nov 29, 2003 8:30 pm
Contact:

Post by madinitaly »

If you're programming under Windows, you can simply use functions from Win32 API: GetPrivateProfileSectionNames, GetPrivateProfileString, GetPrivateProfileInt, WritePrivateProfileString and so on... Just look at the Win32 API reference, or here at the MSDN page.
Epsilon
Posts: 38
Joined: Fri Jan 09, 2004 1:46 pm
Location: Argentina

Post by Epsilon »

OK, thanks i find in sourceforge and i get the libini, that have all i need and is SO independent.

thanks.
Post Reply