Problem with DeleteINISec
Hi,
I seem to have a problem with DeleteINISec: I call that command in my function and then add the deleted section back in (with some modifications), at least that's the plan. But in reality, the INI file is empty on every other run of the installer, even though the details view shows $R0 having the correct value.
I can't use the normal INI functions, because I'm modifying wininit.ini.
If anyone can give me some hints, that would be very nice. Maybe I'm doing something obviously wrong, this is my first more complicated function for NSIS. (I'm using NSIS 2.0b2.)
Here's the function:
;
; AddToWininit - adds lines to the [Rename] section of wininit.ini
;
; Expects string with new lines on top of stack
; Returns nothing, error flag will be set on failure
;
; Make sure new lines end with "$\r$\n"
;
Function AddToWininit
Exch $R0 ; lines
Push $R1 ; file handle
Push $R2 ; read buffer
Push $R3 ; compare buffer
ClearErrors
IfFileExists "$WINDIR\wininit.ini" 0 WRITE
FileOpen $R1 "$WINDIR\wininit.ini" "r"
IfErrors SAFE_RETURN
SECTION_LOOP:
FileRead $R1 $R2
IfErrors READ_DONE
Push $R2
Call TrimNewlines
Pop $R2
StrCmp $R2 "[Rename]" 0 SECTION_LOOP
READ_LOOP:
FileRead $R1 $R2
IfErrors READ_DONE
Push $R2
Call TrimNewlines
Pop $R2
StrCmp $R2 "" READ_LOOP
StrCpy $R3 $R2 1
StrCmp $R3 "[" READ_DONE
StrCpy $R0 "$R0$R2$\r$\n"
Goto READ_LOOP
READ_DONE:
FileClose $R1
DeleteINISec "$WINDIR\wininit.ini" "Rename"
ClearErrors
WRITE:
FileOpen $R1 "$WINDIR\wininit.ini" "a"
IfErrors SAFE_RETURN
FileSeek $R1 0 END
FileWrite $R1 "$\r$\n[Rename]$\r$\n"
DetailPrint $R0
FileWrite $R1 $R0
FileClose $R1
SAFE_RETURN:
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd