License: New BSD License
Download (~31 kb)
The archive contains the library, a demo script and full documentation.Online Documentation
Ini files are used mostly as configuration files. In general, they have the ".ini"-extension. It is a simple standardized organization of text data. Many other simple programs use them for storing text.
AutoHotkey provides three commands IniDelete, IniRead and IniWrite. These commands are stable, but they have some disadvantages. First disadvantage is, that they access the file directly. The file on the disk is opened, load into memory and then read or manipulated and then saved with every single command.
With the custom functions I wrote here, the user accessess on variables instead of files. This is super fast, in comparison to disk access. Ini files can be created by Ahk just like any other variable. But Ahk itself does not provide any function to operate on ini strings (variables). If you work often with ini files, then this might for you.
No other framework or library is required, no special object files are created; just work on ordinary ini file contents or variables. The load and save functions are added for comfort reason and are not really needed.
First do this:
FileRead, [color=olive]ini[/color], config.inior load default file with:
ini_load([color=olive]ini[/color])or create the content yourself:
[color=olive]ini = ([/color] [color=orange][Tip][/color] [color=blue]TimeStamp[/color] = [color=green]20090716194758[/color] [color=orange][Recent File List][/color] [color=blue]File1[/color]=[color=green]F:\testfile.ahk[/color] [color=blue]File2[/color]=[color=green]Z:\tempfile.tmp[/color] [color=olive])[/color]The orange part is a section name. The section have some variables, called keys. Every key is part of a section. In this example, the section "[Tip]" have one key "TimeStamp". And every key have a content, called value. The "TimeStamp" key have the value "20090716194758".
After that, you can access and modify the content of the ini variable with the following functions. But the modifications are only temporary and must be saved to disk. This should be done by overwriting the source (not appending).
Some usage examples
[*:13ckdnjd]Get value of a key.
value := ini_getValue(ini, "Tip", "TimeStamp")[*:13ckdnjd]Get key/value pair.
key := ini_getKey(ini, "Tip", "TimeStamp")[*:13ckdnjd]Get full section with all keys.
section := ini_getSection(ini, "Tip")[*:13ckdnjd]Update value of a key.
ini_replaceValue(ini, "Tip", "TimeStamp", A_Now)[*:13ckdnjd]Delete a key.
ini_replaceKey(ini, "Tip", "Timestamp")[*:13ckdnjd]Replace a full section with all its keys.
ini_replaceSection(ini, "Tip", "[Time]HH=12`nMM=34`nSS=10")[*:13ckdnjd]Add a key/value pair.
ini_insertKey(ini, "Tip", "Timenow=" . A_Now)[*:13ckdnjd]Add a value to existing value.
ini_insertValue(ini, "Section", "Key" ",ListItem")[*:13ckdnjd]Add a section.
ini_insertSection(ini, "Meta", "Name=ini`nAuthor=Tuncay")[*:13ckdnjd]Get value of first found key.
value := ini_getValue(ini, "", "TimeStamp")Simple example
path := ini_load(ini) last := ini_getValue(ini, "Tip", "TimeStamp") ... ini_replaceValue(ini, "Tip", "TimeStamp", A_Now) ini_save(ini, path)
Special thanks goes to Fry, for testing and who was the person why I made this.
Special thanks goes to Mystiq for testing and reworking on an important regex.
In current state, the functions are tested. It seems so as if there would be no problem... but if you know regex, you know what I mean.
I need some testers and helpers. Please look at the regex and give hints if you have some. Test the funtions on real ini files. Report to me.