(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.
TheRLG
Posts: 372
Joined: Thu Oct 07, 2004 11:20 pm

Post by TheRLG »

Correct me if I'm wrong, but I don't think you're supposed to be calling "drop()" on the CfgFile, it caused me errors doing that.
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Actually the class derives from IUnknown so you should be able to call drop on it without any errors...

Could you send me the code? I'll take a look at it and try to fix it
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
TheRLG
Posts: 372
Joined: Thu Oct 07, 2004 11:20 pm

Post by TheRLG »

Obviously, I renamed a few things... but this is what broke it:

Code: Select all

	CINIFileReader* tSettingsFile = new CINIFileReader("Goalygon.ini",false); 
	if (!tSettingsFile->load()) return initialize();

	SGameInitParameters parameters;
	parameters.Title		= tSettingsFile->getValue("game","title");
	parameters.WindowWidth	= tSettingsFile->getValueInt("game","screen-x");
	parameters.WindowHeight	= tSettingsFile->getValueInt("game","screen-y");
	parameters.BitsPerPixel	= tSettingsFile->getValueInt("game","bits");
	parameters.Fullscreen	= tSettingsFile->getValueBool("game","fullscreen");

	mKeymap.Up		= tSettingsFile->getValueKey("keys","up");
	mKeymap.Down	= tSettingsFile->getValueKey("keys","down");
	mKeymap.Right	= tSettingsFile->getValueKey("keys","right");
	mKeymap.Left	= tSettingsFile->getValueKey("keys","left");
tSettingsFile->drop();
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Hm... strange... i got the same error here... it breakes on

Code: Select all

if(fullfile)
   delete [] fullfile;
hm... i don't know why, but i created a work around.

I've updated the code in my first post, but basicly it just replaces the char array fullfile with an irr::core::string<char>

You have to modify following things:
change the defenition of fullfile to

Code: Select all

core::stringc fullfilename
and replace the 2nd constructor, the destructor, and the save method with my updated ones.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
TheRLG
Posts: 372
Joined: Thu Oct 07, 2004 11:20 pm

Post by TheRLG »

Hmm this code is actually useful, maybe it should be included in Irrlicht as a CINIFileReader or something similar.
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

this would be a great honor for me, but i think this code is not good enough to included in irrlicht
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

why not good enaugh? it works good, what else do we need?
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

when i started learning programming, i was told a simple rule:
First make it run, and than make it run better
I'd say the first step is complete... and now i'll work on the second one ^^
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

hey sylence,can you tell me why this piece of code doesn't work as it's suppose to do?

Code: Select all

void IUserControls::loadConfigFromINIFile(c8* iniFile)
{
    CfgFile* IniRdr = new CfgFile(iniFile,false);
    IniRdr->load();
    
    controltable[0] = IniRdr->getValueK("controls","hit");
    changeListBoxItem(0,controltable[0]);

    controltable[1] = IniRdr->getValueK("controls","incpower");
    changeListBoxItem(1,controltable[1]);
    
    controltable[2] = IniRdr->getValueK("controls","decpower");
    changeListBoxItem(2,controltable[2]);
    
    IniRdr->drop(); 
}
The getValueK-function return not the correct value.

Ini file

Code: Select all

[controls]
hit=mouse_l
incpower=q
decpower=y
Image
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

hm... your code seems to be all right.
What values does the function return ?
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

There are only two possiblities what getValueK("controls","hit"); can return, aren't they?
Either "(EKEY_CODE)0x0;" or "KEY_LBUTTON". So I think it returns the first one, 'cause my code works properly assigning KEY_LBUTTON....
Image
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

There should be a lot more than 2 values that getValueK can return...
Did you change anything in the functions ?
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

When "mouse_l" is the value getValueK() should return KEY_LBUTTON. Another possibility schould not exist.
I think I didn't change the code of getValueK(), but I only can confirm this by checking my source code. Unfortunately I can do this on tuesday soonest.
I'll inform you... :wink:
Image
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

Here I am :D

The return value of getValueK("controls","hit") is 0 as a decimal value.... :(

I didn't change the IrrCon class, so I really don't know what might be the mistake.... :cry:

EDIT: "getValue();" returns a string which contains one or two (non visible) extra signs at the end. Is this right? For this reason "getKey(stringc str)" returns the wrong value. Is this a bug or did I miss anything important?
Image
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Argh... not that bug again... i thought i killed it :D
I guess the value is the last one in your file? If so you have to add a new line to the end of the file
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Post Reply