Jump to content

Help for IniReadSection's limit


Recommended Posts

Hi

I looked at my script when I saw that the verification of all values in an .ini file didn't work for the last keys.The ini file has more than 1000 keys,and I found out that the limit of the "memory" of the IniReadSection function is till 945 lines...(with an script that counts the times the verification were succesfull)

Here is an piece of my script

If FileExists(@WorkingDir&"\ipstock.ini")Then
    
    $var = IniReadSection( @WorkingDir & "/ipstock.ini", "ip")
    If @error Then 
    ;MsgBox(4096, "", "Error occured, probably no INI file.")
    else
        For $i = 1 To $var[0][0]
            
            $stockedip = $var[$i][0]
            ;MsgBox(0,"",$stockedip)
                While $NowIp = $stockedip
                    
                    $ipasdate = $var[$i][1]
                     _DateTimeSplit($ipasdate,$MyDate,$MyTime)
                    $datediff = _DateDiff('s', $ipasdate , _NowCalc() )
                        If $datediff > "86500" Then
                            IniWrite ( @WorkingDir & "/ipstock.ini", "ip", $stockedip,_NowCalc() )
                            IniWrite ( @WorkingDir & "/HISipstock.ini", "his", $stockedip,$ipasdate&'---'&$datediff&'---'&_NowCalc() )
                            $ipgood = "good"
                            ;MsgBox(0,"",$ipasdate&'---'&$datediff&'---'&_NowCalc())
                            ExitLoop
                        Else
                            $ipblocked = $ipblocked +1
                            GUICtrlSetData($badcount,$ipblocked)
                        EndIf
                        

                    
                    $TimesIpChanged = $TimesIpChanged + 1
                    GUICtrlSetData($IpChanged , $TimesIpChanged )
                    Run("rasdial /d")
                    ProcessWaitClose("rasdial.exe")
                    sleep(100)
                    $name1 = GUICtrlRead($coname)
                    $id1 = GUICtrlRead($idname)
                    $pass1 = GUICtrlRead($pass)
                    $comp = "rasdial "  & '"' & $name1 & '" "' & $id1 & '" "' & $pass1 & '"'
                    Run($comp)
                    ProcessWaitClose("rasdial.exe")
                    $NowIp = _GetIP()
                    sleep(100)
                    GUICtrlSetData($log,$NowIp)
                Wend 
                if $ipgood = "good" Then
                    ExitLoop
                EndIf
                
            
        Next

Please can someone help me how to fix this problem?

I thought about separating the data in 2 sections,but then how to analyse the whole thing?

thanx for your help :D

Link to comment
Share on other sites

The maximum supported size of an INI file is 64KB. The maximum size of an individual INI section is 32KB. You are running into one of those two limits, not some arbitrary line number limit. As for work-arounds, parse the INI file yourself if you must use an INI file with large amounts of data. The INI functions are currently only going to support the lowest common denominator which in this case means it only supports the maximum sizes Windows 95 can handle.

Link to comment
Share on other sites

i had a question about the INI size limit.

lets say i have a 34KB INI file, and i only search for certain INI Section Names, will it limit. for example, i am only wanting the monthly sections, and i have the section names as 07 - 01 - 2006 and so on for the whole month, will it limit, will it crash, will it only take long to process the search?

thanks in advanced for your suggestions and help...

Link to comment
Share on other sites

i had a question about the INI size limit.

lets say i have a 34KB INI file,

This by itself is not a problem, the limit on the file is 64KB.

and i only search for certain INI Section Names, will it limit.

What do you mean "search"?

for example, i am only wanting the monthly sections, and i have the section names as 07 - 01 - 2006 and so on for the whole month, will it limit, will it crash, will it only take long to process the search?

Any data in a section past the first 32KB will not be read. The first 32KB will be read. You can't read or write to that data. The same goes for data appearing after the 64KB mark. This also depends on your operating system and which function you are using. I believe that IniRead() and IniWrite() on Windows XP can read/write past the AutoIt limits but other functions can not so th effective limit is 64KB per file, 32KB per section.
Link to comment
Share on other sites

  • Moderators

I was getting bored this evening, and remembered this thread. I made an __IniReadSection(), that could be used using FileRead() rather than the standard INI options, which should remove the 32kb problem.

Admittingly, I didn't need it, so I haven't done alot of Error Checking, and I can see where non standard ways of writing an INI could cause issues. But it works how I write them.

It should also return INI/TXT whatever values even if there is no Key...

Hope it helps

$File = '\SomeIni.ini'
$Array = __IniReadSection($File, 'SomeSection')
For $i = 1 To $Array[0][0]
    MsgBox(64, 'Info:', 'Key = ' & $Array[$i][0] & @CR & 'Value = ' & $Array[$i][1])
Next

Func __IniReadSection($sFile, $sSection)
    Local $hRead = FileRead($sFile), $aSplit = StringSplit($hRead, @LF)
    Local $sSectionNames = '', $iStart = 0, $iEnd = 0
    For $iCount = 1 To UBound($aSplit) - 1
        $aSplit[$iCount] = StringStripWS($aSplit[$iCount], 7)
        If StringLeft($aSplit[$iCount], 1) = '[' Then
            $aString = StringSplit($aSplit[$iCount], '[')
            $sValue = StringReplace($aString[2], ']', '')
            If @extended = 1 Then
                If $sValue = $sSection Then
                    $iStart = $iCount + 1
                ElseIf $iStart Then
                    $iEnd = $iCount - 1
                    ExitLoop
                EndIf
            EndIf
        EndIf
    Next
    If $iStart And Not $iEnd Then 
        $iEnd = UBound($aSplit) - 1
    ElseIf Not $iStart Then
        Return SetError(0, 0, 0)
    EndIf
    Local $sKeyName = '', $sValueReturn = '', $sLine = '', $nSeperator = ''
    For $xCount = $iStart To $iEnd
        $sLine = FileReadLine($sFile, $xCount)
        $nSeperator = StringInStr($sLine, '=', 0, 1)
        If $nSeperator Then
            $sKeyName &= StringLeft($sLine, $nSeperator - 1) & @LF
            $sValueReturn &= StringTrimLeft($sLine, $nSeperator) & @LF
        Else
            $sKeyName &= '' & @LF
            $sValueReturn &= StringTrimLeft($sLine, $nSeperator) & @LF
        EndIf
    Next
    $sKeyName = StringSplit(StringTrimRight($sKeyName, 1), @LF)
    $sValueReturn = StringSplit(StringTrimRight($sValueReturn, 1), @LF)
    Local $aReturn[UBound($sKeyName)][2]
    $aReturn[0][0] = $sKeyName[0]
    For $iCount = 1 To $sKeyName[0]
        $aReturn[$iCount][0] = $sKeyName[$iCount]
        $aReturn[$iCount][1] = $sValueReturn[$iCount]
    Next
    Return $aReturn
EndFunc

Edit:

I might add this should only be used in extreme circumstances, I hadn't tested the speed of this at all and thought I would before bed, low and behold, the standard _IniReadSection() is about 2000 x's faster :D

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • 1 month later...
  • Moderators

Wrote a new one in case someone sees this one it can be found here:

http://www.autoitscript.com/forum/index.ph...mp;#entry229487

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...