Jump to content

IniRead bug or expected behaviour? Reading keys from duplicated sections


ilko
 Share

Recommended Posts

Windows 2000/XP/2003 setup, in particular parsing txtsetup.sif, allows multiple sections with the same name, for example:

txtsetup.sif:

[Strings]
wkscd   = "Windows 2000 Professional CD"

[SetupData]
SetupSourcePath ="\WINSETUP\GENSP4\"
MajorVersion = 5
MinorVersion = 0
DefaultPath=\WINNT

[Strings]
wks_id       = "Microsoft Windows 2000 Professional"

IniRead seem to read just the first section:

MsgBox(0,"",IniRead("txtsetup.sif", "Strings", "wks_id", "Not found"))
Returns "Not Found".

Is this expected behaviour or a bug/limitation?

Any quick way to resolve similar issues?

Just updated to AutoIt v3.3.6.1 and got the same result.

Searched the forums and the bug tracker, but couldn't find this issue addressed.

Link to comment
Share on other sites

I'd say it is intended behaviour and not a bug whatsoever. It is the simpleast and easiest way to deal with an ini file and it should stay the same.

As a workaround: you can search for duplicate sections and rename one of them.

Here is a proof of concept:

#include<array.au3>
Global $Ini
$tt = IniReadSectionNames($Ini)
_ArrayDisplay($tt)
For $i=1 To UBound($tt)-1
    For $j=1 To UBound($tt)-1
        If $tt[$i] = $tt[$j] Then
            IniRenameSection($Ini, $tt[$i], $tt[$i]&"_1")
            $tt[$i] = $tt[$i]&"_1"
        EndIf
    Next
Next
$tt = IniReadSectionNames($Ini)
_ArrayDisplay($tt)

Test it and see what it does (on a copy of your ini file of course :idea:).

Note: my script handles successfully only 1 duplicate; if you have 2 or more duplicates, you will need to modify the script.

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Thanks for reply.

I am afraid I won't be able to rename sections, this is allowed (and often used) syntax according to (silly) MS rules for this particular case.

Merging them into a single one is fine, but leaving that as a last resort, if no other quick solutions exist.

Edited by ilko
Link to comment
Share on other sites

That's too bad.

It looks to me that you have 2 ways to deal with this:

- merge the sections (the easiest one)

- deal with this not the "ini" way but read the whole file to an array and use array elements. This isn't as easy but it is doable.

Good luck,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Everything is a bit fuzzy in this area. Not having any written specification for .INI and .SIF makes it possible that anyone invents some "clever" use that would break other products.

Say there are "conforming" (conforming to what is a mystery) .INI files which stick to the rules of unique section name (in one block) no multi-valued keys, ...

"Non-conforming" .INI may have dupplicate section names (or sections split in several blocks, depending on how they see it), multiple values in one key, multi-line keys, ...

Same for .SIF, where MS clearly changed its own .INI rules (split sections and the like)

It's not obvious that you can merge or otherwise rearrange split sections harmlessly in every file type. Some INI or SIF or similar "consumer" might expect things in a particular order, e.g.

[Product]

name=Product A...

...

[DLLs]

dll = some path,,, abc.dll

dll = another path , 2, 0, def.dll

.../...

[Product]

name=Product A...

...

[DLLs]

dll = some path,,, abc123.dll

dll = another path , 2, 0, def.dll

Here the installer relies on DLLs section following every Product section. Should you merge that all blindly, that becames a useless mess.

The .INI support in AutoIt is only dealing with "Conforming" .INI, excluding any derivative format.

You might find this post of use to deal with your problem.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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...