(C++) Class for reading Windows-INI-like files

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Bad news:

My hoster kilu.de got hacked and all user accounts and data has been deleted and couldn't be restored.

The real bad thing is, that I didn't have any local backups of the website so I have to create a new one which will take some time.

Don't worry the projects themselves are backed up ;)

However the hack has its good sites, too.
The new site will be hosted on an root server running only two websites (mine plus another).

So the performance should be very high.
You can reach my site with this url (the old domain doesn't work on the root server... strange)
http://btbsoft.org
Last edited by Sylence on Sat Dec 27, 2008 8:08 pm, edited 1 time in total.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
MickeyKnox
Posts: 58
Joined: Tue Apr 10, 2007 7:49 pm
Location: Karlsruhe

Post by MickeyKnox »

Hi, i think i found a bug in getValueW:

you're creating a local variable str and returning a pointer to it's content.
But when conrol exits this method, the local variable is destroyed and the
pointer points anywhere.

I fixed it for me this way:

Code: Select all

const wchar_t* CIniFileReaderStub::getValueW(const c8* section, const c8* key)
{
  w_value = core::stringw(getValue(section,key));
  return w_value.c_str();
}
with w_value being a private class variable.
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Thanks a lot!

This bug and the one MasterGod posted are fixed. The archive on the site is updated.

Thanks for finding the bugs :)
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

@Sylence: Any updates with the actual code?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

No sorry. I was very busy the last time and I somehow lost the overview of what have to be done with it. Still trying to figure out a way to make it more easily expandable but I just can't figure out a way of dealing with the different Irrlicht types in a more abstract way (and of all the features I want to have in the conversation to irrlicht core types is the number 1)

Either it's now bug-free because there hasn't been a bug report for a while now, or no one is using this anymore...
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Ok did a coding marathon and made version 0.3 in a few hours :)
I'm afraid I did more damage than I repaired ^^

Finally fixed that empty line thing at the end of the file =)

Check it out at my site
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Sylence wrote:Finally fixed that empty line thing at the end of the file =)
Well what was it then? How did you fix it?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Actually I don't really know. I used strtok to read the lines of the file and now I switched to string::findFirst and string::findNext and now it works...
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Half a year later I finally managed to find some time to implement comments.

When you load a file with comments (starting with ; or ##) they will be stored and will be written to the file when saved.
Also you can add / change comments during runtime.

A comment is always associated with the section or key that follows the comment.

Download can be found here
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Reiko
Posts: 105
Joined: Sun Aug 16, 2009 7:06 am
Location: Australia

Post by Reiko »

Dont know if you still visit the site but I tried your IrrIni. I realise this is 2 years old :P. It still works with the newest version of Irrlicht, so that's nice.

It's good for the most part, but I have some comments.

I'm not sure why you would just convert an unsigned int to a signed one. Values larger than 2,147,483,647 will go into negative.

Code: Select all

void CIrrIniStub::setValue(const c8* section, const c8* key, u32 value)
{
	setValue(section,key,(s32)value);
}
So instead I changed it to:

Code: Select all

void CIrrIniStub::setValue(const c8* section, const c8* key, u32 value)
{
	c8 buf[20];
	sprintf(buf,"%u",value);
	setValue(section,key,buf);
}
I don't think that using random fixed size buffers like that is the best programming practice (eg 20), especially using Irrlicht, where you could just use Irrlicht's stringc. But this matches the behaviour of the other methods.

Also, in CIrrIniStub::addSection() I added if (!getSection(name)). Otherwise, adding a section with the same name again creates multiple sections with the same name, and adding to the section will always just add to the first one found. If you wanted you could make setValue() add the section if it doesn't exist too, I suppose.

Also in your constructor for CIrrIniStub, the first part of the code (the block that uses an IReadFile) you create a file but you never drop the file, this causes a memory leak. Changing it to look like this resolves the issue:

Code: Select all

			IReadFile* readFile = fileSystem->createAndOpenFile(file);
			if(readFile)
			{
				s32 size = readFile->getSize();
				c8* buffer = new c8[size+2];	
				readFile->read(buffer,size);
				buffer[size+1] = 0x0;
				Content = buffer;
				delete [] buffer;
				readFile->drop(); // <- added this line
			}
Lastly I wish you had used wide chars, so that values in say Japanese or whatever could be used in the ini files. But I guess that's being picky.

Overall though from my experience so far, it works well and I'll be using it. Saves me time to write my own one. I haven't thoroughly tested it though, I guess I'll post again if I find any other issues.

Cheers.
Post Reply