This class implements a simple name-value storage represented on disk by an INI file. These files
are suitable for low-volume high-latency human-readable information storage, such as for
configuration. Cuberite itself uses INI files for settings and options.
The objects of this class are created empty. You need to either load a file using ReadFile(), or
insert values by hand. Then you can store the object's contents to a disk file using WriteFile(), or
just forget everything by destroying the object. Note that the file operations are quite slow.
Cuberite will write the characters '\n' in place of line breaks in the values of the cIniFile when
it is being stored into a file. It will also replace '\n' with line breaks when it reads an INI
file.
Name | Parameters | Return value | Notes |
() (constructor) |
|
|
Creates a new empty cIniFile object. |
|
|
Adds a comment to be stored in the file header. |
KeyName | string | Comment | string |
|
|
Adds a comment to be stored in the file under the specified key |
|
|
Adds a comment to be stored in the file under the specified key |
AddKeyName |
|
|
Adds a new key of the specified name. Returns the KeyID of the new key. |
AddValue |
KeyName | string | ValueName | string | Value | string |
|
|
Adds a new value of the specified name to the specified key. If another value of the same name exists in the key, both are kept (nonstandard INI file) |
AddValueB |
KeyName | string | ValueName | string | Value | boolean |
|
|
Adds a new bool value of the specified name to the specified key. If another value of the same name exists in the key, both are kept (nonstandard INI file) |
AddValueF |
KeyName | string | ValueName | string | Value | number |
|
|
Adds a new float value of the specified name to the specified key. If another value of the same name exists in the key, both are kept (nonstandard INI file) |
AddValueI |
KeyName | string | ValueName | string | Value | number |
|
|
Adds a new integer value of the specified name to the specified key. If another value of the same name exists in the key, both are kept (nonstandard INI file) |
CaseInsensitive |
|
|
Sets key names' and value names' comparisons to case insensitive (default). |
CaseSensitive |
|
|
Sets key names and value names comparisons to case sensitive. |
Clear |
|
|
Removes all the in-memory data. Note that , like all the other operations, this doesn't affect any file data. |
|
|
Deletes the specified header comment. Returns true if successful. |
|
|
Deletes all headers comments. |
DeleteKey |
|
|
Deletes the specified key, and all values in that key. Returns true if successful. |
KeyName | string | CommentID | number |
|
|
Deletes the specified key comment. Returns true if successful. |
KeyID | number | CommentID | number |
|
|
Deletes the specified key comment. Returns true if successful. |
|
|
Deletes all comments for the specified key. Returns true if successful. |
|
|
Deletes all comments for the specified key. Returns true if successful. |
DeleteValue |
KeyName | string | ValueName | string |
|
|
Deletes the specified value. Returns true if successful. |
DeleteValueByID |
|
|
Deletes the specified value. Returns true if successful. |
FindKey |
|
|
Returns the KeyID for the specified key name, or the noID constant if the key doesn't exist. |
FindValue |
KeyID | number | ValueName | string |
|
|
Returns the ValueID for the specified value name, or the noID constant if the specified key doesn't contain a value of that name. |
Flush |
|
|
Writes the data stored in the object to the file that was last associated with the object (ReadFile() or WriteFile()). Returns true on success, false on failure. |
|
|
Returns the specified header comment, or an empty string if such comment doesn't exist |
KeyID | number | CommentID | number |
|
|
Returns the specified key comment, or an empty string if such a comment doesn't exist |
KeyName | string | CommentID | number |
|
|
Returns the specified key comment, or an empty string if such a comment doesn't exist |
GetKeyName |
|
|
Returns the key name for the specified key ID. Inverse for FindKey(). |
|
|
Retuns the number of header comments. |
|
|
Returns the number of comments under the specified key |
|
|
Returns the number of comments under the specified key |
GetNumKeys |
|
|
Returns the total number of keys. This is the range for the KeyID (0 .. GetNumKeys() - 1) |
GetNumValues |
|
|
Returns the number of values stored under the specified key. |
GetNumValues |
|
|
Returns the number of values stored under the specified key. |
GetValue |
KeyID | number | ValueID | number | DefaultValue | string |
|
|
Returns the value of the specified name under the specified key. Returns DefaultValue (empty string if not given) if the value doesn't exist. |
GetValue |
KeyName | string | ValueName | string | DefaultValue | string |
|
|
Returns the value of the specified name under the specified key. Returns DefaultValue (empty string if not given) if the value doesn't exist. |
GetValueB |
KeyName | string | ValueName | string | DefaultValue | boolean |
|
|
Returns the value of the specified name under the specified key, as a bool. Returns DefaultValue (false if not given) if the value doesn't exist. |
GetValueF |
KeyName | string | ValueName | string | DefaultValue | number |
|
|
Returns the value of the specified name under the specified key, as a floating-point number. Returns DefaultValue (zero if not given) if the value doesn't exist. |
GetValueI |
KeyName | string | ValueName | string | DefaultValue | number |
|
|
Returns the value of the specified name under the specified key, as an integer. Returns DefaultValue (zero if not given) if the value doesn't exist. |
GetValueName |
|
|
Returns the name of the value specified by its ID. Inverse for FindValue(). |
GetValueName |
KeyName | string | ValueID | number |
|
|
Returns the name of the value specified by its ID. Inverse for FindValue(). |
GetValueSet |
KeyName | string | ValueName | string | DefaultValue | string |
|
|
Returns the value of the specified name under the specified key. If the value doesn't exist, creates it with the specified default (empty string if not given). |
GetValueSetB |
KeyName | string | ValueName | string | DefaultValue | boolean |
|
|
Returns the value of the specified name under the specified key, as a bool. If the value doesn't exist, creates it with the specified default (false if not given). |
GetValueSetF |
KeyName | string | ValueName | string | DefaultValue | number |
|
|
Returns the value of the specified name under the specified key, as a floating-point number. If the value doesn't exist, creates it with the specified default (zero if not given). |
GetValueSetI |
KeyName | string | ValueName | string | DefaultValue | number |
|
|
Returns the value of the specified name under the specified key, as an integer. If the value doesn't exist, creates it with the specified default (zero if not given). |
HasValue |
KeyName | string | ValueName | string |
|
|
Returns true if the specified value is present. |
ReadFile |
FileName | string | AllowExampleFallback | boolean |
|
|
Reads the values from the specified file. Previous in-memory contents are lost. If the file cannot be opened, and AllowExample is true, another file, "filename.example.ini", is loaded and then saved as "filename.ini". Returns true if successful, false if not. |
SetValue |
KeyName | string | ValueName | string | NewValue | string | CreateIfNotExists | boolean |
|
|
Overwrites the specified value with a new value. If CreateIfNotExists is true (default) and the value doesn't exist, it is first created. Returns true if the value was successfully set, false if not (didn't exists, CreateIfNotExists false). |
SetValue |
KeyID | number | ValueID | number | NewValue | string |
|
|
Overwrites the specified value with a new value. If the specified value doesn't exist, returns false (doesn't add). |
SetValueB |
KeyName | string | ValueName | string | NewValue | boolean | CreateIfNotExists | boolean |
|
|
Overwrites the specified value with a new bool value. If CreateIfNotExists is true (default) and the value doesn't exist, it is first created. Returns true if the value was successfully set, false if not (didn't exists, CreateIfNotExists false). |
SetValueF |
KeyName | string | ValueName | string | NewValue | number | CreateIfNotExists | boolean |
|
|
Overwrites the specified value with a new floating-point number value. If CreateIfNotExists is true (default) and the value doesn't exist, it is first created. Returns true if the value was successfully set, false if not (didn't exists, CreateIfNotExists false). |
SetValueI |
KeyName | string | ValueName | string | NewValue | number | CreateIfNotExists | boolean |
|
|
Overwrites the specified value with a new integer value. If CreateIfNotExists is true (default) and the value doesn't exist, it is first created. Returns true if the value was successfully set, false if not (didn't exists, CreateIfNotExists false). |
WriteFile |
|
|
Writes the current in-memory data into the specified file. Returns true if successful, false if not. |
The following code logs all keynames and their valuenames into the server log: