Skip to content
⌘ NSIS Forum Archive

ReWriting INI files (the hard way?) :-(

5 posts

dbach#

ReWriting INI files (the hard way?) :-(

Hi together.

I am currently writing an upgrade installation for one of our products.
In the old ini file I have some sectionnames that have to move to a new ini file - but as values!

Example:
; Old.ini
[AETITLE:MachineName]
a=b
x=y
[AETITLE:AnotherMachineName]
l=m
n=o 
I need the Name of the Section without AETITLE. The result should look like this:

; New.ini
[network]
MachineName=one-setting,more-settings,yadada
AnotherMachineName=one-setting,more-settings,yadada 
I do not need the values/keys from the old.ini sections but part of the sectionname as value for the new.ini.

Any ideas how to handle this? :|

Thank you very much.
dbach#
thanks for your reply.

my problem is that i don't know the section names yet. they all start with [AETITLE:something], so I will need a loop. but I didn't program a loop so far. Any hints about looping trough my problem? or can anyone point me to a good example with loops which also I can unterstand? 😉

thnx
Yathosho#
try this

 ClearErrors
Loop:
 ${ConfigRead} "old.ini" "[AETITLE" $var ; sets errorflag if not found
 IfErrors EndLoop
 StrCpy $var $var -1 ; deletes the "]"
 WriteIniStr "new.ini" "network" $var "what you want to add"
 DeleteINISec "old.ini" "[AETITLE$var]"
 Goto Loop
EndLoop: 
the DeleteIniSec part is probably undesired and clumsy, but you get the idea with the loop
dbach#
Originally posted by Yathosho
try this

 ClearErrors
Loop:
 ${ConfigRead} "old.ini" "[AETITLE" $var ; sets errorflag if not found
 IfErrors EndLoop
 StrCpy $var $var -1 ; deletes the "]"
 WriteIniStr "new.ini" "network" $var "what you want to add"
 DeleteINISec "old.ini" "[AETITLE$var]"
 Goto Loop
EndLoop: 
the DeleteIniSec part is probably undesired and clumsy, but you get the idea with the loop
thank you very very much! thats exactly what I need.