Jump to content

Attempt at improved inireadsection


Recommended Posts

Hello, all..

My AutoIT is pretty terrible - but I get by with trawling here :)

I came across an issue where i had to parse a large key in a large ini file, and found that I was victim of inireadsection's limit of "Only the first 32767 chars are read for legacy reasons."

 

I've attempted to put together some terrible code that parses an ini section.

It's absolutely nowhere near good, but I figured I'd put it here so that folk who know what they're doing can laugh at improve it.

$Ini = @ScriptDir & "\bigini.ini"
Dim $IniArray[0][2]

$KeyName = "Person"

$R = FileOpen($Ini, 0)
$IniStr = FileRead($R)
FileClose($R)

$Start = StringInStr($iniStr, "[" & $KeyName & "]")

    If $Start = 0 then
    Msgbox(16, "Error", "String not found")
    Exit
    EndIf

$Stop = StringInStr($IniStr, @CRLF & "[", 0, 1, ($Start + 1))
    If $Stop = 0 then
    $Stop = StringLen($IniStr)
    EndIf

$String = StringMid($IniStr, $Start, ($Stop - $Start))
$Split = StringSplit($String, @CRLF, 1)
$KeyCount = 0
Dim $IniArray[65535][2]

    For $Loop = 1 to $Split[0]
    $Add = "Y"
    $Str = $Split[$Loop]
    $EQBreak = StringInStr($Str, "=")
        Select
        Case StringMid($Str, 1, 1) = ";"
        $Add = "N"
        
        Case $EQBreak = 0
        $Add = "N"
        
        Case Else
        $Add = "Y"
        EndSelect
    
        If $Add = "Y" then
        $KeyCount = $KeyCount + 1
        $Key = StringMid($Str, 1, ($EQBreak - 1))
        $Val = StringMid($Str, ($EQBreak + 1))
        $IniArray[$KeyCount][0] = $Key
        $IniArray[$KeyCount][1] = $Val
        EndIf
        
    Next

Redim $IniArray[$KeyCount +1][2]

; Add the number of hits to 00 to match inireadsection
$IniArray[0][0] = $KeyCount

_ArrayDisplay($IniArray)

; Do stuff with the Array like you would inireadsection

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...