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.
Name | Parameters | Return value | Notes |
() (constructor) |
|
cIniFile |
Creates a new empty cIniFile object. |
AddHeaderComment |
Comment |
|
Adds a comment to be stored in the file header. |
AddKeyComment |
KeyID, Comment |
|
Adds a comment to be stored in the file under the specified key |
AddKeyComment |
KeyName, Comment |
|
Adds a comment to be stored in the file under the specified key |
AddKeyName |
KeyName |
|
Adds a new key of the specified name. Returns the KeyID of the new key. |
AddValue |
KeyName, ValueName, Value |
|
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, ValueName, Value |
|
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, ValueName, Value |
|
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, ValueName, Value |
|
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. |
DeleteHeaderComment |
CommentID |
bool |
Deletes the specified header comment. Returns true if successful. |
DeleteHeaderComments |
|
|
Deletes all headers comments. |
DeleteKey |
KeyName |
bool |
Deletes the specified key, and all values in that key. Returns true if successful. |
DeleteKeyComment |
KeyID, CommentID |
bool |
Deletes the specified key comment. Returns true if successful. |
DeleteKeyComment |
KeyName, CommentID |
bool |
Deletes the specified key comment. Returns true if successful. |
DeleteKeyComments |
KeyID |
bool |
Deletes all comments for the specified key. Returns true if successful. |
DeleteKeyComments |
KeyName |
bool |
Deletes all comments for the specified key. Returns true if successful. |
DeleteValue |
KeyName, ValueName |
bool |
Deletes the specified value. Returns true if successful. |
DeleteValueByID |
KeyID, ValueID |
bool |
Deletes the specified value. Returns true if successful. |
FindKey |
KeyName |
number |
Returns the KeyID for the specified key name, or the noID constant if the key doesn't exist. |
FindValue |
KeyID, ValueName |
numebr |
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 |
|
boolean |
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. |
GetHeaderComment |
CommentID |
string |
Returns the specified header comment, or an empty string if such comment doesn't exist |
GetKeyComment |
KeyID, CommentID |
string |
Returns the specified key comment, or an empty string if such a comment doesn't exist |
GetKeyComment |
KeyName, CommentID |
string |
Returns the specified key comment, or an empty string if such a comment doesn't exist |
GetKeyName |
KeyID |
string |
Returns the key name for the specified key ID. Inverse for FindKey(). |
GetNumHeaderComments |
|
number |
Retuns the number of header comments. |
GetNumKeyComments |
KeyID |
number |
Returns the number of comments under the specified key |
GetNumKeyComments |
KeyName |
number |
Returns the number of comments under the specified key |
GetNumKeys |
|
number |
Returns the total number of keys. This is the range for the KeyID (0 .. GetNumKeys() - 1) |
GetNumValues |
KeyID |
number |
Returns the number of values stored under the specified key. |
GetNumValues |
KeyName |
number |
Returns the number of values stored under the specified key. |
GetValue |
KeyID, ValueID, [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, ValueName, [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, ValueName, [DefaultValue] |
bool |
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, ValueName, [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, ValueName, [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 |
KeyID, ValueID |
string |
Returns the name of the value specified by its ID. Inverse for FindValue(). |
GetValueName |
KeyName, ValueID |
string |
Returns the name of the value specified by its ID. Inverse for FindValue(). |
GetValueSet |
KeyName, ValueName, [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, ValueName, [DefaultValue] |
bool |
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, ValueName, [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, ValueName, [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, ValueName |
bool |
Returns true if the specified value is present. |
ReadFile |
FileName, [AllowExampleFallback] |
bool |
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 |
KeyID, ValueID, NewValue |
bool |
Overwrites the specified value with a new value. If the specified value doesn't exist, returns false (doesn't add). |
SetValue |
KeyName, ValueName, NewValue, [CreateIfNotExists] |
bool |
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). |
SetValueB |
KeyName, ValueName, NewValueBool, [CreateIfNotExists] |
bool |
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, ValueName, NewValueFloat, [CreateIfNotExists] |
bool |
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, ValueName, NewValueInt, [CreateIfNotExists] |
bool |
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 |
FileName |
bool |
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: