Archive: ExecToLog and MUI_INSTALLOPTIONS_READ


ExecToLog and MUI_INSTALLOPTIONS_READ
I have problem with using these two directives together.

for example code like this:
Var MY_DB_VALUE

!insertmacro MUI_INSTALLOPTIONS_READ $MY_DB_VALUE "cleandir.ini" "Field 10" "State"
MessageBox MB_OK "DBRUN1: $MY_DB_VALUE"

ReadEnvStr $R0 COMSPEC
nsExec::ExecToLog '"$R0" /C "$INSTDIR\dbpromo\dbauto\dbauto.exe"'

!insertmacro MUI_INSTALLOPTIONS_READ $MY_DB_VALUE "cleandir.ini" "Field 10" "State"
MessageBox MB_OK "DBRUN2: $MY_DB_VALUE"


When I execute first block works and I get message:
DBRUN1: 1
Then ExecToLog executed, but after ExecToLog all calls to MUI_INSTALLOPTIONS_READ macro do not return values, so I always got message:
DBRUN2:

If I comment out ExecToLog second call to MUI_INSTALLOPTIONS_READ starting to work and I get message DBRUN2: 1

what am I missing? Should I do some POP, PUSH around ExecToLog or something?


Any chance your application clears the temporary folder?

Stu


I found problem. That was very deep and only appeared in Silent mode installation.

In short I dynamically generate .ini file by calling WriteIni function in Custom dialog. But Custom dialog does not get called in silent mode, so I detect silent mode and call WriteIni in .onInit.

Problem here that I missed call to:
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "my.ini"
in my SilentInstall function.

Now the weird part. If I don't have this call in my silent mode WriteInit function in silent mode create my.ini in root C:\. And it works. But as soon as I call ExecToLog in creates temporary directory to put nsExec.dll. From that moment MUI_INSTALLOPTIONS_READ stops reading from C:\my.ini but trying to find it in Temp/nscxxx/my.ini

I think MUI_INSTALLOPTIONS_READ first look if temporary ditrectory has been created if not it looks for ini file in ROOT, but if in the middle some other function created temporary directory MUI_INSTALLOPTIONS_READ starting to look there and failing to find .ini file.

Calling !insertmacro MUI_INSTALLOPTIONS_EXTRACT "my.ini" guaranteed creating of temporary directory and it all works fine.

there is part of my .nsi file:

Var MY_DB_VALUE

!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
Page custom CleanDirPage
!insertmacro MUI_PAGE_INSTFILES

Function .onInit

call SilentInstall
FunctionEnd

Function SilentInstall
;run only for silent mode

IfSilent 0 end
;if I uncoment next line it all starting to work
;!insertmacro MUI_INSTALLOPTIONS_EXTRACT "my.ini"
call WriteIni
end:
FunctionEnd

Section "Test ExecToLog"

SetOutPath $INSTDIR\dev
File TestExecToLog.nsi

!insertmacro MUI_INSTALLOPTIONS_READ $MY_DB_VALUE "my.ini" "Field 1" "State"
MessageBox MB_OK "DBRUN1: $MY_DB_VALUE"

ReadEnvStr $R0 COMSPEC
nsExec::ExecToLog '"$R0" /C "dir"'

!insertmacro MUI_INSTALLOPTIONS_READ $MY_DB_VALUE "my.ini" "Field 1" "State"
MessageBox MB_OK "DBRUN2: $MY_DB_VALUE"
SectionEnd

Function CleanDirPage
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "my.ini"
call WriteIni

!insertmacro MUI_HEADER_TEXT "Installation of $MY_INST_TYPE environment configuration" "Select installation and deployment options"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "my.ini"

FunctionEnd

function WriteIni
!insertmacro MUI_INSTALLOPTIONS_WRITE 'my.ini' 'Settings' 'NumFields' '1'
!insertmacro MUI_INSTALLOPTIONS_WRITE 'my.ini' 'Field 1' 'Type' 'Checkbox'
!insertmacro MUI_INSTALLOPTIONS_WRITE 'my.ini' 'Field 1' 'Left' '10'
!insertmacro MUI_INSTALLOPTIONS_WRITE 'my.ini' 'Field 1' 'Top' '125'
!insertmacro MUI_INSTALLOPTIONS_WRITE 'my.ini' 'Field 1' 'Right' '-40'
!insertmacro MUI_INSTALLOPTIONS_WRITE 'my.ini' 'Field 1' 'Bottom' '135'
!insertmacro MUI_INSTALLOPTIONS_WRITE 'my.ini' 'Field 1' 'Text' 'Run DB promotion'
!insertmacro MUI_INSTALLOPTIONS_WRITE 'my.ini' 'Field 1' 'State' 1
FunctionEnd