Jump to content


Photo

Powerful Ini File Management


  • Please log in to reply
117 replies to this topic

#1 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 22 May 2009 - 06:27 AM

I created a powerful INI editing DLL which is great for many things!

Why should I use this?
This DLL has all of the same functions as Game Makers "ini_..." functions so its easy to remember them. The DLL also has a few more functions such as "Section Delete" where you can delete whole sections at a time. Another reason to use this DLL is because each ini file is loaded into the memory so there is no constant file reading/parsing and writing. All of the sections/keys are stored where they can be quickly searched and changed. The changes are unloaded from the memory and written back on the ini file when the file is closed. Lastly, this DLL is instanced. This means you can operate on up to 700 ini files at the same time.

Download:
Download [Zip] - Includes GMK and DLL.
Information:
Written in C++ By Revel

Functions - See GMK scripts for more info on specific functions
rini_init();
rini_open(fname);
rini_close(ind);
rini_write(ind);
rini_read_real(ind,section,key,default);
rini_read_string(ind,section,key,default);
rini_write_real(ind,section,key,value);
rini_write_string(ind,section,key,string);
rini_section_exists(ind, section);
rini_key_exists(ind,section,key);
rini_key_rename(ind,section,key,newkeyname);
rini_section_rename(ind,section,newsectionname);
rini_section_delete(ind, section);
rini_key_delete(ind, section, key);
rini_section_find_first(ind);
rini_section_find_next(ind);
rini_key_find_first(ind,section)
rini_key_find_next(ind,section)

Please comment and leave your suggestions! I would love to add lots of handy features!

Version 2:
Basically the same with a few more features, tweaks and is a lot more stable.
  • Features new key finding functions to iterate through keys in a section
  • Function names are now all in lowercase
  • Removed the password/encryption functions since they weren't necessary... I don't think o.O
  • Added a function to write the ini file from memory back to Hard drive without closing the file.
  • The DLL was rewritten completely in MSVC, rather than GCC.. for anyone that cares.


How powerful is this? (This was for Version 1, Haven't updated it yet)

Each ini file has 200 sections with 200 keys each this was a total of 4000 keys. The GM functions generally took a couple minutes to complete while the DLL was always around 1 minute. The keys were written and read in a for (2 of them) loop in a creation event. Note that the times also include loading and unloading the ini file.
Posted Image


Edited by Revel, 30 August 2010 - 07:37 AM.

  • 4

#2 Yambam

Yambam

    GMC Member

  • GMC Member
  • 647 posts
  • Version:GM8

Posted 22 May 2009 - 09:15 AM

Thats great! i always wanted those functions! <_<
  • 0

#3 bombshell

bombshell

    GMC Member

  • GMC Member
  • 1607 posts

Posted 28 May 2009 - 01:43 PM

how much faster is this compared to GM functions?
  • 0
http://bombshell93.deviantart.com/

Our emotions each take the form of a Demon. These Demons roam our mind looking for little quirks they can take advantage of. It is up to us to control out Demons. Or they will consume us and control us. You need to find your angel before your Demons do. Or the devine hero saving the memories and thoughts that keep you going will fall.

#4 Schyler

Schyler

    Noskcirderf Derf

  • GMC Member
  • 2680 posts
  • Version:GM:Studio

Posted 28 May 2009 - 02:09 PM

Thats great! i always wanted those functions! :)

These functions are the same as the built in GM ones, although I would be interested in the speed difference?
  • 0

#5 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 28 May 2009 - 07:46 PM

As far as I know (I asked Revel a while ago), he wrote these functions and did not use any other method. If you look in the DLL itself you shouldn't see any DLL imports for the WinAPI INI functions.

This does not feature commenting, either.

Edited by GMREC1111, 28 May 2009 - 07:47 PM.

  • 0

#6 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 28 May 2009 - 08:45 PM

I never actually tested how much faster the DLL was than normal GM functions but I went ahead and tried them out and I was actually quite amazed at the results:

Each ini file has 200 sections with 200 keys each this was a total of 4000 keys. The GM functions generally took a couple minutes to complete while the DLL was always around 1 minute. The keys were written and read in a for (2 of them) loop in a creation event. Note that the times also include loading and unloading the ini file.

Posted Image


As far as I know (I asked Revel a while ago), he wrote these functions and did not use any other method. If you look in the DLL itself you shouldn't see any DLL imports for the WinAPI INI functions.


Yep, I didn't even know windows had an API for ini managing until you told me later!


This does not feature commenting, either.


No it does not but I will add that soon :D

Edited by Revel, 28 May 2009 - 08:51 PM.

  • 0

#7 bombshell

bombshell

    GMC Member

  • GMC Member
  • 1607 posts

Posted 28 May 2009 - 08:57 PM

this is my final hope if my ini doesn't write with this then theres a problem with my code -.-'
I try but jack cr** happens and I don't know why I've tried a GEX but I'll try this now
EDIT:
WOOT! \..\>.</../
I love this IT WORKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

would it be okay if I use this in a commercial TDS engine?
I'll credit and pay you (if the engine does make money) as you wish

Edited by bombshell, 28 May 2009 - 09:07 PM.

  • 0
http://bombshell93.deviantart.com/

Our emotions each take the form of a Demon. These Demons roam our mind looking for little quirks they can take advantage of. It is up to us to control out Demons. Or they will consume us and control us. You need to find your angel before your Demons do. Or the devine hero saving the memories and thoughts that keep you going will fall.

#8 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 28 May 2009 - 09:11 PM

would it be okay if I use this in a commercial TDS engine?



Sure, not a problem! You don't have to pay me but some credit would be nice (however not required).
  • 0

#9 bombshell

bombshell

    GMC Member

  • GMC Member
  • 1607 posts

Posted 28 May 2009 - 09:14 PM

umm also could you make it so that if a folder doesn't exist it creates it
I deleted a file a while back because a virus got into it and apparently it had somthing to do with naming folders -.-'
now when I try it complains folder does not exist and renames it to the origional name -.-'
now I need to do it all through command prompt

Edited by bombshell, 28 May 2009 - 09:14 PM.

  • 0
http://bombshell93.deviantart.com/

Our emotions each take the form of a Demon. These Demons roam our mind looking for little quirks they can take advantage of. It is up to us to control out Demons. Or they will consume us and control us. You need to find your angel before your Demons do. Or the devine hero saving the memories and thoughts that keep you going will fall.

#10 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 28 May 2009 - 09:19 PM

umm also could you make it so that if a folder doesn't exist it creates it



What do you mean? Do you mean that if you try to open "Files/config.ini" then you want it to create "Files/" ?
  • 0

#11 bombshell

bombshell

    GMC Member

  • GMC Member
  • 1607 posts

Posted 28 May 2009 - 09:30 PM

yeh
it would make my life a whole lot easier :D
I did just create the folders I needed using command prompt,
but for future use.
also how should I address you when I'm crediting you?
  • 0
http://bombshell93.deviantart.com/

Our emotions each take the form of a Demon. These Demons roam our mind looking for little quirks they can take advantage of. It is up to us to control out Demons. Or they will consume us and control us. You need to find your angel before your Demons do. Or the devine hero saving the memories and thoughts that keep you going will fall.

#12 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 28 May 2009 - 09:49 PM

OK ill add that soon.

For crediting just use Revel (GMC)
  • 0

#13 bombshell

bombshell

    GMC Member

  • GMC Member
  • 1607 posts

Posted 28 May 2009 - 10:12 PM

kk also this is the fastest thing ever!
does it stop the game while saving many files?
just need to check because my engine may be used by excesive gun creators! (its the TDS one in my sig)
  • 0
http://bombshell93.deviantart.com/

Our emotions each take the form of a Demon. These Demons roam our mind looking for little quirks they can take advantage of. It is up to us to control out Demons. Or they will consume us and control us. You need to find your angel before your Demons do. Or the devine hero saving the memories and thoughts that keep you going will fall.

#14 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 28 May 2009 - 10:39 PM

does it stop the game while saving many files?


This DLL is not threaded so it will pause your game for a slight amount of time just like any other gm function.
  • 0

#15 Postality

Postality

    GMC Member

  • New Member
  • 244 posts

Posted 31 May 2009 - 03:16 AM

Sweet deal.

Can this open files anywhere, and can you use a relative path?

For example: say I'm running an EXE that's in the main folder, and I want it to read an INI file that's in a folder called "players" that's in the main folder the EXE is in. can the fname be "/players/player.ini" or goes it have to be the whole ini path? such as "C:\Games\My Game\players\player.ini".

Thanx for all the effort here Revel I appreciate all the fine things you're doing.
  • 0

#16 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 31 May 2009 - 07:17 AM

I haven't actually tested that, but I'm almost 100% sure a relative path with work.
  • 0

#17 Mailas

Mailas

    Send in the Mail

  • GMC Member
  • 5900 posts
  • Version:GM:Studio

Posted 07 June 2009 - 05:26 AM

By instanced, does this mean you can do something like...add a new section to each ini created?
Like for something in an MMO, you have things like:
[Username]=""
[Password]=""
[LEVEL]=45
[Inventory1]="Shirt"
[Inventory2]="Pants"

And I have like......over 100 inis on my computer (for each persons account), and I wanted to add a new section:
[Inventory3], would your dll be able to do this to all ini files in the directory?
  • 0

omQasih.jpg


#18 Schyler

Schyler

    Noskcirderf Derf

  • GMC Member
  • 2680 posts
  • Version:GM:Studio

Posted 07 June 2009 - 06:28 AM

By instanced, does this mean you can do something like...add a new section to each ini created?
Like for something in an MMO, you have things like:
[Username]=""
[Password]=""
[LEVEL]=45
[Inventory1]="Shirt"
[Inventory2]="Pants"

And I have like......over 100 inis on my computer (for each persons account), and I wanted to add a new section:
[Inventory3], would your dll be able to do this to all ini files in the directory?

Just use GM to search for each file using file_find_next().
  • 0

#19 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 07 June 2009 - 03:34 PM

By instanced, does this mean you can do something like...add a new section to each ini created?
Like for something in an MMO, you have things like:
[Username]=""
[Password]=""
[LEVEL]=45
[Inventory1]="Shirt"
[Inventory2]="Pants"

And I have like......over 100 inis on my computer (for each persons account), and I wanted to add a new section:
[Inventory3], would your dll be able to do this to all ini files in the directory?


By instanced, I mean you can open multiple inis and manage them using an ID. You can open up all of your inis, and then perform the operation on each of them.

Just use file_find_next() to find them, open them, write the key/section and then close.
  • 0

#20 Skarik

Skarik

    GMC member

  • GMC Member
  • 1068 posts
  • Version:GM:Studio

Posted 14 June 2009 - 10:54 PM

Using this for the relative path support. Thanks.
  • 0

#21 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 17 June 2009 - 10:44 AM

Wow wicked =D I can't wait to run my tests. Dude this is lightning fast, fastest gm ini dll ive ever used by far.
My gm ini results we're 2181.40, the gm ini dll results we're 2640.35.
This 96.6 heck this is extremely fast, good work. =]
This is 22.5x faster then gm's built in ini functions in my test =]

Edited by Krisando, 17 June 2009 - 11:20 AM.

  • 0

Posted Image


#22 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 20 June 2009 - 05:44 PM

I have added Encryption! You can now hide you ini files from users by using an encryption password which makes the ini file unreadable to users.

Rini_Open now has a "Password" argument.

A new function "Rini_Set_Pass" can set the password to an ini file. The ini file wont be affected until you use Rini_Close()

Download
  • 0

#23 e_barroga

e_barroga

    ES Studios Leader

  • GMC Member
  • 2475 posts

Posted 23 June 2009 - 06:41 PM

You should add file existance check and creating non-existant files:

Opposed to:
f = file_text_write_open(...);
file_close(f);
f = Rini_Open(...);

  • 0

rsa_gmc_sig.png

 

logoGIF1.gif EXTENSION. PM TO PURCHASE LICENSE.


#24 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 24 June 2009 - 03:05 AM

And with a quick fix....Here is the new version which supports file creation, if it doesn't exist!
  • 0

#25 IamCalle

IamCalle

    GMC Member

  • GMC Member
  • 444 posts

Posted 12 July 2009 - 01:07 AM

Yet another INI handling- DLL, sweet.
This is added to my collection, perhaps this will be the fastest one. :P
I like the rename- functions.
  • 0

#26 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 15 July 2009 - 06:27 AM

Hmm another lil request
Rini_Find_Next(); //Finds next subsection in the file

Easily could do in text file reading although I'd say it would be quicker.
  • 0

Posted Image


#27 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 15 July 2009 - 06:49 AM

Hmm another lil request
Rini_Find_Next(); //Finds next subsection in the file

Easily could do in text file reading although I'd say it would be quicker.




Are you talking about searching for the [sections] within an INI file?

I'll add it as soon as possible, along with an Rini_Find_First() To initiate the search.
  • 0

#28 slayer_jojo

slayer_jojo

    GMC Member

  • New Member
  • 181 posts

Posted 16 July 2009 - 06:24 AM

After running the demo, settings.ini turns into this:

5oâQsÐe6…èÛ)!
ÖjBÑOÛI.߶?hoa(ƧdPyÀñCŠ` #
‘³{r_9t¢&

Is this supposed to work on Vista?
  • 0

#29 JJN

JJN

    GMC Member

  • New Member
  • 315 posts

Posted 16 July 2009 - 07:11 AM

@slayer, The demo includes the Rini_Set_Pass command, which encrypts the INI file. Remove that line and the file shows normal text.

Really great DLL, Revel. I'll be using this for my current project with credit :D
  • 0
AKA Tantalum or ArgonWire.
Complete: ArcBall
Current Project: A turn-based strategy similar to Worms (working title PixElement)
Concept: [|||||||||-] Resources: [||--------] Engine: [|||-------] Server: [|||-------]

#30 slayer_jojo

slayer_jojo

    GMC Member

  • New Member
  • 181 posts

Posted 16 July 2009 - 07:31 PM

I would recommend having encryption off by default..

anyways, I'm going to use this
  • 0

#31 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 16 July 2009 - 09:57 PM

It is off by default. I just included it in the example to show how it works.
  • 0

#32 slayer_jojo

slayer_jojo

    GMC Member

  • New Member
  • 181 posts

Posted 16 July 2009 - 11:16 PM

It is off by default. I just included it in the example to show how it works.


I see.. It seems to work well, thanks!

BTW, the naming convention I find kind of annoying. It's faster to type Rini_read_real than Rini_Read_Real and looks more natural to me

also it pollutes the global namespace - you may want to store the variables in an object (for instance an object named 'ini'). Then in the object create event you call Rini_create(). Then a user can just drop the object in a room he would like to use the ini methods, or create the object with instance_create()
  • 0

#33 slayer_jojo

slayer_jojo

    GMC Member

  • New Member
  • 181 posts

Posted 16 July 2009 - 11:20 PM

the ini object could also maintain a list of currently opened ini files. Then on game_end(), it would make sure to close them. Or maybe that would be better to implant directly into the dll..
  • 0

#34 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 17 July 2009 - 12:47 AM

Are you talking about searching for the [sections] within an INI file?

I'll add it as soon as possible, along with an Rini_Find_First() To initiate the search.

Thankyou that's exactly what I am seeking ;)
  • 0

Posted Image


#35 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 19 July 2009 - 04:07 PM

Sorry the new functions are taking so long, but I found a large bug in the DLL that crashed the game.

Here is the new version:

Download

Bug fixed, and the section search functions are now added.
  • 0

#36 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 20 July 2009 - 04:58 AM

I love you <3, thankyou.
  • 0

Posted Image


#37 slayer_jojo

slayer_jojo

    GMC Member

  • New Member
  • 181 posts

Posted 20 July 2009 - 05:49 AM

Thanks, this is useful work here
  • 0

#38 e_barroga

e_barroga

    ES Studios Leader

  • GMC Member
  • 2475 posts

Posted 20 July 2009 - 11:02 AM

Sorry the new functions are taking so long, but I found a large bug in the DLL that crashed the game.

Here is the new version:

Download

Bug fixed, and the section search functions are now added.


What was the bug? I haven't had any crash issues with it.
  • 0

rsa_gmc_sig.png

 

logoGIF1.gif EXTENSION. PM TO PURCHASE LICENSE.


#39 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 20 July 2009 - 11:22 AM

It had something to do with deleting and creating sections over and over again.
  • 0

#40 MM3

MM3

    GMC Member

  • GMC Member
  • 200 posts
  • Version:GM:Studio

Posted 20 July 2009 - 12:47 PM

Thank You for the great dll!
But I have a question. What is the maximum sections and keys each and in total for an ini file?
  • 0

#41 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 20 July 2009 - 05:33 PM

I have built the DLL to handle unlimited sections and keys (Provided you have enough memory to store all of the text), however you can only have 700 INI files open at the same time.
  • 0

#42 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 21 July 2009 - 07:26 AM

I have built the DLL to handle unlimited sections and keys (Provided you have enough memory to store all of the text).

When you write to an ini file does it write it to memory or write it directly to the file untile the file has been closed?
  • 0

Posted Image


#43 e_barroga

e_barroga

    ES Studios Leader

  • GMC Member
  • 2475 posts

Posted 21 July 2009 - 02:29 PM

I have built the DLL to handle unlimited sections and keys (Provided you have enough memory to store all of the text).

When you write to an ini file does it write it to memory or write it directly to the file untile the file has been closed?


Memory, you need to close the ini file to make the changes.
  • 0

rsa_gmc_sig.png

 

logoGIF1.gif EXTENSION. PM TO PURCHASE LICENSE.


#44 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 21 July 2009 - 11:09 PM

There seems to be some kind of bug, I cannot find next section within an ini while a text file is still open.
Although it could be if they are both reading the same file at once.

[!Bugged]
file = file_text_open_read(directory+"\Id_"+get_type(i)+".ini");
INI_HANDLE=Rini_Open(directory+"\Id_"+get_type(i)+".ini");
show_message(string(Rini_Find_First(INI_HANDLE)));

[!Works]
file = file_text_open_read(directory+"\Id_"+get_type(i)+".ini");
file_text_close(file);
INI_HANDLE=Rini_Open(directory+"\Id_"+get_type(i)+".ini");
show_message(string(Rini_Find_First(INI_HANDLE)));
  • 0

Posted Image


#45 e_barroga

e_barroga

    ES Studios Leader

  • GMC Member
  • 2475 posts

Posted 21 July 2009 - 11:58 PM

There seems to be some kind of bug, I cannot find next section within an ini while a text file is still open.
Although it could be if they are both reading the same file at once.

[!Bugged]
file = file_text_open_read(directory+"\Id_"+get_type(i)+".ini");
INI_HANDLE=Rini_Open(directory+"\Id_"+get_type(i)+".ini");
show_message(string(Rini_Find_First(INI_HANDLE)));

[!Works]
file = file_text_open_read(directory+"\Id_"+get_type(i)+".ini");
file_text_close(file);
INI_HANDLE=Rini_Open(directory+"\Id_"+get_type(i)+".ini");
show_message(string(Rini_Find_First(INI_HANDLE)));


What's the point of this:
file = file_text_open_read(directory+"\Id_"+get_type(i)+".ini");

  • 0

rsa_gmc_sig.png

 

logoGIF1.gif EXTENSION. PM TO PURCHASE LICENSE.


#46 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 22 July 2009 - 12:57 AM

What's the point of this:

file = file_text_open_read(directory+"\Id_"+get_type(i)+".ini");

You wouldn't understand :)
  • 0

Posted Image


#47 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 22 July 2009 - 12:59 AM

Perhaps because you forgot the second Argument on "Rini_Open" which is the password for the file or "" for no password.

Try opening the ini File with the DLL before you open as a text file with GM.
  • 0

#48 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 22 July 2009 - 04:16 AM

Perhaps because you forgot the second Argument on "Rini_Open" which is the password for the file or "" for no password.

Try opening the ini File with the DLL before you open as a text file with GM.

I thought that aswell but it made no difference, it was definately because GM was reading the text file. Worked once closed.
  • 0

Posted Image


#49 Revel

Revel

    ɹǝqɯǝɯ ɔɯƃ

  • GMC Member
  • 4935 posts
  • Version:GM8

Posted 22 July 2009 - 06:57 PM

So you got it working?
  • 0

#50 e_barroga

e_barroga

    ES Studios Leader

  • GMC Member
  • 2475 posts

Posted 22 July 2009 - 07:11 PM

Perhaps because you forgot the second Argument on "Rini_Open" which is the password for the file or "" for no password.

Try opening the ini File with the DLL before you open as a text file with GM.

I thought that aswell but it made no difference, it was definately because GM was reading the text file. Worked once closed.


So why wouldn't I understand? Seems you didn't? Get my drift, grasshopper?
  • 0

rsa_gmc_sig.png

 

logoGIF1.gif EXTENSION. PM TO PURCHASE LICENSE.