Table of Contents

IniFile

This object allows you to read and write to a INI file.

Quick Use

Usable example:

var myObject= new IniFile();
myObject.load("config.ini");
myObject.setSection("SomeSettingsSection");
if (myObject.keyExists("SomeKey")){
	mytext = myObject.keyValue("SomeKey");
	newtext = mytext + "Bar";
	myObject.setKeyValue("SomeKey", newtext);
}else{
	myObject.setKeyValue("SomeKey", "Foo" );
	mytext = cfgini.keyValue("SomeKey");
}
myObject.save("config.ini");

Will result in value "Bar" being appended ever run, except first. Defaults to "Foo" if Key is unset:

Functions

IniFile

Constructor function.

Syntax

var myObject = new IniFile();
var myObject = new IniFile(parameters);

Arguments

  1. parameters - (object) parameters
    • delimiter - (char) the delimiter to use
    • commentchar - (char) the comment character
    • encoding - (Encoding) the encoding to use

Exceptions

Example

Create a IniFile object.

var myObject = new IniFile();

Create a IniFile object with parameters.

var myObject = new IniFile({
	delimiter: "=",
	commentCharacter: "$"
});

Methods

load

Loads a file.

Syntax

myObject.load(filename);

Arguments

  1. filename - (string) the filename of the file to open

Returns

Exceptions

save

Saves a file.

Syntax

myObject.save(filename);

Arguments

  1. filename - (string) the filename of the file to save

Returns

Exceptions

clear

Clear the file.

Syntax

myObject.clear();

Returns

preserveDeletedData

Preserve the deleted data as comments.

Syntax

myObject.preserveDeletedData(preserve);

Arguments

  1. preserve - (boolean) should the deleted data preserved as comments

Returns

setDelimiter

Set the value/data delimiter. Default is =.

Syntax

myObject.setDelimiter(delimiter);

Arguments

  1. delimiter - (char) the delimiter to use

Returns

setCommentCharacter

Set the comment character. Default is #.

Syntax

myObject.setCommentCharacter(commentchar);

Arguments

  1. commentchar - (char) the comment character

Returns

setSection

Sets the current INI section.

Syntax

myObject.setSection(sectionName);
myObject.setSection(sectionName, create);

Arguments

  1. sectionName - (string) the section name
  2. create - (boolean) create the section if it doesn't exists (default: true)

Returns

Exceptions

setEncoding

Sets the encoding to use.

Syntax

myObject.setEncoding(encoding);

Arguments

  1. encoding - (Encoding) the encoding to use

Returns

sectionAt

Returns the section name at index sectionIndex.

Syntax

myObject.sectionAt(sectionIndex);

Arguments

  1. sectionIndex - (integer) the section index

Returns

Exceptions

deleteSection

Deletes a section.

Syntax

myObject.deleteSection(sectionName);

Arguments

  1. sectionName - (string) the section name

Returns

Exceptions

sectionCount

Returns the number of sections.

Syntax

myObject.sectionCount();

Returns

keyExists

Returns true if a key with keyName exists.

Syntax

myObject.keyExists(keyName);

Arguments

  1. keyName - (string) the key name

Returns

keyAt

Returns the name of the key at index keyIndex.

Syntax

myObject.keyAt(keyIndex);

Arguments

  1. keyIndex - (integer) the key index

Returns

Exceptions

keyValue

Returns the value of the key keyName.

Syntax

myObject.keyValue(keyName);

Arguments

  1. keyName - (string) the key name

Returns

Exceptions

setKeyValue

Sets the value of the key keyName.

Syntax

myObject.setKeyValue(keyName, value);

Arguments

  1. keyName - (string) the key name
  2. value - (string) the key value

Returns

deleteKey

Delete the key keyName.

Syntax

myObject.deleteKey(keyName);

Arguments

  1. keyName - (string) the key name

Returns

Exceptions

keyCount

Returns the key count.

Syntax

myObject.keyCount();

Returns