Jump to content

Recommended Posts

Posted

Hello,

"inireadsection()" is a natively buildin function, not added as needed by including some AU3. So I cannot dig into its logic (edit the function).

Is there a way to get around this limitation, documented in the help file "Only the first 32767 chars are read for legacy reasons."?

the opposit function "iniwritesection()" does *NOT* have this limitation: That one is doing  writes beyond 32767 chars without any constraints.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Posted

This UDF might help: 

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

You can use the native WinAPI GetPrivateProfileSection.  It says that :

Quote

Note: In earlier Windows versions, the maximum profile section size is 32,767 characters.
Windows 7 and newer versions don't have this limitation.

Here my take on it :

#include <Array.au3>

Local $aSection = IniReadSectionEx("C:\Apps\AutoIt\SQLite\Sudoku.ini", "Setting")
_ArrayDisplay($aSection)

Func IniReadSectionEx($sFile, $sSection, $iBuffer = 64000, $iEntry = 1000, $iLine = 100)
  Local $tData = DllStructCreate("byte [" & $iBuffer & "]")
  Local $pData = DllStructGetPtr($tData)

  Local $aRet = DllCall("Kernel32.dll", "int", "GetPrivateProfileSection", "str", $sSection, "struct*", $tData, "int", $iBuffer, "str", $sFile)

  Local $tString, $aList[$iEntry + 1][2] = [[0]], $aSplit
  For $i = 1 To $iEntry
    $tString = DllStructCreate("char string[" & $iLine & "]", $pData)
    $sString = $tString.string
    If Not $sString Then ExitLoop
    $aList[0][0] += 1
    $aSplit = StringSplit($sString, "=", $STR_NOCOUNT)

    $aList[$i][0] = $aSplit[0]
    $aList[$i][1] = $aSplit[1]

    $pData += StringLen($sString) + 1
  Next

  ReDim $aList[$i][2]
  Return $aList
EndFunc   ;==>IniReadSectionEx

 

Edited by Nine
made example script
Posted (edited)

I'm not sure if this helps - but to look at it from another angle, we're talking about 30kb worth of plain text.  (I think those INI funcs deal in ansi strings).

Just in case the concern was around headroom...

Edit: Oops KB not MB!

Edited by MattyD
Posted

I tried the example and it works, but it leaves a lot to be desired having to specify buffer size, maximum line length, and number of elements. To be useful it has to work no matter what I throw at it, as certainly I would never know before-hand any of this without making the default limits very large to cover all bases. I mean, you could make the buffer equal to the file size and process elements in chunks of 1000, but how to know the maximum line length other than to make it overly large? Is there a better way?

But the biggest issue is speed. Throwing a 200KB section at it with 3674 elements (most with line lengths of 50, max less than 100) took 59ms on my computer. Not too bad.

However, I previously solved the 32KB section limit by reading the file as text and parsing it. My solution by comparison takes only 36ms; I expected the example using GetPrivateProfileSection to be faster. Perhaps someone more advanced could do it.

Posted

Thanks to all of you for the input. The IniEx UDF is a very interesting one.

Basically I have a "system" of a couple of AU3 files that I started to write  at least 15 years ago, to manage my call history and mobile phone book entries. When I started, of course I was far away from hitting the 32k limitation.

 

In genearal all that would need a rewrite from the scratch, especially preserving the data in TXT files would need to be replaced by some database solution. But DB usage with autoit is definitely and unfortunately not a thing, I'm familiar with.

So what I did for now as a QND workaround was to use _FileReadToArray and _FileWriteFromArray instead of ini read/write: The particular INI has just one section, so this was a very easy going approach.

Tx.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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
×
×
  • Create New...