GO2cam Javascript API  6.11
GO2SIniFile Class Reference

Class for managing ini files. More...

Inherits QObject.

Public Member Functions

 GO2SIniFile (String fileName)
 Constructs a GO2SIniFile object for accessing the settings stored in the file called fileName. If the file doesn't already exist, it is created.
 
void BeginGroup (String prefix)
 Appends prefix to the current group.
 
Number BeginReadArray (String prefix)
 Adds prefix to the current group and starts reading from an array. Returns the size of the array.
 
void BeginWriteArray (String prefix, Number size=-1)
 Adds prefix to the current group and starts writing an array of size size. If size is -1 (the default), it is automatically determined based on the indexes of the entries written.
 
void Clear ()
 Removes all entries in the primary location associated to this object.
 
Boolean Contains (String key)
 Returns true if there exists a setting called key; returns false otherwise.
 
void EndArray ()
 Closes the array that was started using BeginReadArray() or BeginWriteArray()
 
void EndGroup ()
 Resets the group to what it was before the corresponding BeginGroup() call.
 
Array< String > GetAllKeys ()
 Returns a list of all keys, including subkeys, that can be read.
 
Array< String > GetChildGroups ()
 Returns a list of all key top-level groups that contain keys that can be read.
 
Array< String > GetChildKeys ()
 Returns a list of all top-level keys that can be read.
 
String GetCurrentGroup ()
 Returns the current group.
 
any GetValue (String key, any defaultValue)
 Returns the value for setting key. If the setting does not exist, returns defaultValue.
 
void Remove (String key)
 Removes the setting key and any sub-settings of key.
 
void SetArrayIndex (Number i)
 Sets the current array index to i.
 
void SetValue (String key, any value)
 Sets the value of setting key to value. If the key already exists, the previous value is overwritten.
 

Detailed Description

Class for managing ini files.

Version
6.11.203
var ini = new GO2SIniFile ("U:\\test.ini");
ini.Clear(); // remove all
ini.BeginGroup("FRIDGE");
ini.SetValue("color", "White");
ini.SetValue("height", 100);
ini.EndGroup();
ini.BeginGroup("ROOM");
ini.SetValue("sofa", true);
ini.SetValue("tv", false);
ini.EndGroup();
var keys = ini.GetAllKeys();
// keys: [FRIDGE/color, FRIDGE/height, ROOM/sofa, ROOM/tv ]
console.log(keys);
ini.BeginGroup("FRIDGE");
keys = ini.GetChildKeys();
ini.EndGroup();
// keys: [color, height]
console.log(keys);
ini.BeginGroup("FRIDGE");
var color = ini.GetValue("color", "blue");
var height = ini.GetValue("height", 10);
var width = ini.GetValue("width", 50); // not exists in file
ini.EndGroup();
console.log(color); // White
console.log(height); //100
console.log(width); // 50
// array write sample
ini.BeginGroup("ANIMAL");
ini.BeginWriteArray("cats");
ini.SetArrayIndex(0);
ini.SetValue("name", "Sheba");
ini.SetValue("age",5);
ini.SetArrayIndex(1);
ini.SetValue("name", "Kitty");
ini.SetValue("age",12);
ini.EndArray();
ini.EndGroup()