An initialization file (also known as INI file) is a plain text file with a distinct structure that allows for more convenient and organized data storage. An initialization file is convenient and permanent storage space, however it relatively slow compared to window buffers and hash tables. If speed is needed, a hash tables is a much superior choice.
Contents
File Structure
An ini file is composed of names, values, sections, and comments.
Property
A property is the basic item that makes up the ini file. An equal sign delimiter separates the name from the value (name being on the left of the equal sign). Every name has a value associated with it.
item = value
item2 = value 2
Section
Sections Parameters are grouped together into a section. The name of the section is placed on a line of its own (enclosed by a pair of square brackets). All parameters after the section are automatically associated with that section.
[section]
item = value
Storing Information
mIRC offers a number of convenient commands and identifiers to read/write from/to an ini file.
Writing to an ini file
The writeini command can be used to write an item (and its value) in a specific section of the ini file.
/writeini [-n] <inifile> <section> <item> <value>
The -n switch no longer exists on mIRC 7.x and newer. On older mIRCs: The -n switch is used when the file exceeds 65,536 bytes (64 KB). It's a good idea to place it there if you think the file will get pretty big in the future.
For example:
writeini reminder.ini birthday jenna 2/28/1983 writeini reminder.ini birthday Mike 10/10/1990
Will create the following file:
[birthday]
jenna = 2/28/1983
Mike = 10/10/1990
You can easily see the actual ini file using the following command:
//run notepad.exe reminder.ini
Reading from an INI
Reading a property from an INI file is pretty simple:
$readini(filename[, np], section, item)
The n switch is used when you do not want to evaluate the line. (This is especially helpful when you let the users save setting on your bot, you need to always think the worse of the users and how they might exploit your scripts)
The p switch is used to make mIRC evaluate pipes | as is instead of plain text.
For example (using the file we created in the previous example):
echo -a Mike: $readini(reminder.ini, n, birthday, mike) echo -a Jenna: $readini(reminder.ini, n, birthday, jenna)
Will output:
Mike: 10/10/1990 Jenna: 2/28/1983
Security Consideration
ALWAYS use the 'n' switch unless you have a very good reason to not use it!
Deleting Items and Sections
The remini can be used to delete an item or an entire section from an ini file:
;remove an item /remini <inifile> <section> <item> ;remove an entire section /remini <inifile> <section>
For example:
/remini reminder.ini birthday mike
will remove mike's entry from the ini file.