# ini [v0.15.1]

作者: Tuncay 最近更新时间: 20100205

Operate on variables instead of files. An easy to use ini parser.
With the custom functions I wrote here, the user accessess on variables instead of files. This is super fast, in comparison to disk access. Ini files can be created by Ahk just like any other variable. But Ahk itself does not have any function to operate on ini strings (variables). If you read often from ini file, then this might for you.

ini_buildPath(_Path)
Ini_Delete(ByRef _Content, _Section, _Key = "")
ini_exportToGlobals(ByRef _Content, _CreateIndexVars = false, _Prefix = "ini", _Seperator = "_", _SectionSpaces = "", _PreserveSpace = False)
ini_getAllKeyNames(ByRef _Content, _Section = "", ByRef _count = "")
ini_getAllSectionNames(ByRef _Content, ByRef _count = "")
ini_getAllValues(ByRef _Content, _Section = "", ByRef _count = "")
ini_getKey(ByRef _Content, _Section, _Key)
ini_getSection(ByRef _Content, _Section)
ini_getValue(ByRef _Content, _Section, _Key, _PreserveSpace = False)
ini_insertKey(ini, "Section", "Key=" . A_Now)
ini_insertSection(ini, "Section", "Key1=ini`nKey2=Tuncay")
ini_insertValue(ini, "Section", "Key" ",ListItem")
ini_load(ByRef _Content, _Path = "", _convertNewLine = false)
ini_mergeKeys(ini1, ini2)
Ini_Read(ByRef _OutputVar, ByRef _Content, _Section, _Key, _Default = "ERROR")
ini_repair(_Content, _PreserveSpace = False, _CommentSymbols = ";#", _LineDelim = "`n")
ini_replaceKey(ini, "Section", "Key")
ini_replaceSection(ini, "Section", "[Section1]Key1=0`nKey2=1")
ini_replaceValue(ini, "Section", "Key", A_Now)
ini_save(ByRef _Content, _Path = "", _convertNewLine = true, _overwrite = true)
Ini_Write(_Value, ByRef _Content, _Section, _Key)

关于函数的参数和返回值, 请参阅其源码或 此文档.

#### 备注

关于此函数(集)的更新细节和注意事项, 请参见 AutoHotkey 论坛: http://www.autohotkey.com/forum/viewtopic.php?t=46226

#### 许可

此函数(集)是基于 GNU LGPL 许可的开源项目. 想了解许可详情, 请参见 lgpl-3.0.txt

#### 示例

    ; #Include ini.ahk
    #NoEnv
    SendMode Input
    SetWorkingDir %A_ScriptDir%

    ; ----- User Configuration -----
    ConfigFilePath := "settings.ini"

    ; ----- Main -----
    IfNotExist, %ConfigFilePath%
        createConfigFile(ConfigFilePath)

    FileRead, ini, %ConfigFilePath%
    value := ini_getValue(ini, "Config", "Started")
    value++
    ini_replaceValue(ini, "Config", "Started", value)
    updateConfigFile(ConfigFilePath, ini)

    FileRead, ini, %ConfigFilePath%
    value := ini_getValue(ini, "Config", "Started")
    MsgBox This script was started %value% time/s.

    RETURN ; End of AutoExec-section

    createConfigFile(Path)
    {
        Template =
        (LTrim
        [Config]
        Started=0
        )
        FileAppend, %Template%, %Path%
        Return
    }

    updateConfigFile(Path, ByRef Content)
    {
        FileDelete, %Path%
        FileAppend, %Content%, %Path%
        Return
    }