Archive: .ini


.ini
the software my installer is for saves the settings in a .ini file that looks like this:

[service 1]
setting_1=blabla
setting_2=blabla

[service 2]
setting_1=blabla
setting_2=blabla


is there a possibility to query for the highest number of the service ([service x])? the problem is, that the software does not except numbers that dont follow each other. service 1, service 2, service 999 - the last one would be ignored. if possible the installer checks the highest number and adds one using the value+1.

Killahbite,

I would suggest that you write a small Dll, because here you will need to compare successive numbers (<, > or =) and the first two are not possible using NSIS (I think). So just write a dll that takes to values (in the stack or in user variables) and returns the highest one.

Good luck,
greetz, Hendri.


i wish i could do that


What is the problem?

-Hn3.


In NSIS, just try to create a loop that reads all sections:
"service $0"

During this loop, read the ini for this section and if the resulting string is nonempty, the section apparently exists, so set $R9 to this section number and continue in the loop.
In the end $R9 will contain the highest number of sections used.

But this could be slow, you could try...

Good luck, greetz,
Hendri.


Compare integers
Hi killahbite,

here's a dll to compare integers. Now it should be possible to write a script that finds the maximum. Just read every new section and if the number is larger than what you already have (using the dll) update the maximum. BTW, you will have to use FileRead instead of ReadIniStr because than you can just check the available sections and nothing more (more efficient!). Example script included.

Good luck, greetz,
Hendri.


The script to check an ini for highest numbered section
Hi killahbite,

as a special treat: here's the script to do the job. Please let me know if it's working like you would like to.

Greetz,
-Hn3.


Hi Hendri,

Um, can't you just use IntCmp to compare two integers?

Sorry to be the bearer of bad news, after all that hard work... :)

--
Dave


Eccles, indeed, you could use IntCmp, :(

but I never used it before and I use all the other commands almost every day, so I forgot about this command...

Indeed, hard work for nothing...

Killahbite, implement IntCmp in the checkini script. Much more efficient :(

Good luck, greetz,
Hendri.


ah cool, will check it tomorrow! thank you!


Hi killahbite,

a modified source, now using IntCmp...

Good luck with it, have fun, greetz,
-Hendri.


Jan,

here's the requested modification of checkini -> checkini1.zip

Good luck, greetz,
Hendri.


Someone might be interested in this:

a function that searches an ini for the number of keys starting with a numeric value (0,1,2,3,4,5,6,7,8 or 9) within a section you can choose yourself.

Have fun,
greetz, Hendri.


thank you very much hendri, you rock :D


Killahbite,

thx for the appreciation, it's nice to do something for people who appreciate it :).

Greetz, Hendri.