Archive: Help needed on having user pass data to installer


Help needed on having user pass data to installer
Any help/example with this would be super-appreciated...

So I have a function that replaces, during the install, a variable called @IPADDRESS@ with an actual value (e.g. 255.255.255.0). Problem is, right now I am hardcoding the 255.255.255.0 in the function itself.

What I would love to be able to do, is to have a custom screen displayed to the user that asks for that information, stores it into a variable and then passes it to the stringreplace function i have. Below is what i am talking about. I'd like to replace that 255.255.255.0 with a variable coming from the custom screen:

Section "Update Configuration Files"
; Replace IP address with hardcoded value for config.txt
Push @IPADDRESS@ #text to be replaced
Push "255.255.255.0" #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push C:\TestInstall\ZipExample2\Config1\config.txt #file to replace in
Call AdvReplaceInFile
SectionEnd


THANKS!!!!


Hi again,

Use InstallOption (this example is for Modern UI)
*)NSIS\Contrib\InstallOptions\Readme.html
*)NSIS\Contrib\Modern UI\Readme.html


1) create ini file with description of your dialog:

[Settings]
NumFields=1

[Field 1]
Type=Text
State=255.255.255.0
Left=6
Right=130
Top=7
Bottom=20
2) in your script in .onInit section
Function .onInit
...
InitPluginsDir
SetOutPath $PLUGINSDIR
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "IniFile"
;optionally - change default value in $0
!insertmacro MUI_INSTALLOPTIONS_WRITE "IniFile" "Field 1" "State" "$0"
...
FunctionEnd
3) in your script among other pages
Page custom yourPage yourPageValidate
4) somewhere in your script
Function yourPage 
...
!insertmacro MUI_INSTALLOPTIONS_INITDIALOG "IniFile"
...
!insertmacro MUI_INSTALLOPTIONS_SHOW
...
FunctionEnd
5) somewhere in your script
Function yourPageValidate 
...
ReadINIStr $0 "$PLUGINSDIR\IniFile" "Settings" "State"
StrCmp $0 1 validateAddr
Abort
validateAddr:
;do some validation
Abort
FunctionEnd
6) get the value passed by user
  !insertmacro MUI_INSTALLOPTIONS_WRITE "IniFile" "Field 1" "State" "$0"  
MessageBox MB_OK "Value: $0"


Uff..., I hope there is no mistake ... ;)

Kobus

thanks! ill try all that


Ok, i know i sound totally clueless with this (maybe it's cause i am...).. I have the following items in my page and function sections. Yet my debug messages are not returning anything...And the custom screen is not displayed when i test the installer...

Page custom configPage "" "Configuration Options"

Function .onInit
File /oname=configPage.ini configPage.ini
FunctionEnd

Function configPage
Push $R0
InstallOptions::dialog "configPage.ini"
MessageBox MB_OK 'The ini file is called "$R0"'
Pop $R0
ReadINIStr $R1 "configPage.ini" "Field 2" "Machine"
MessageBox MB_OK 'The machine name entered was "$R1"'
Pop $R1
FunctionEnd


try this ...

Function .onInit
InitPluginsDir
File /oname=$PLUGINSDIR\configPage.ini "configPage.ini"
FunctionEnd

Function configPage
...
InstallOptions::dialog "$PLUGINSDIR\configPage.ini"
...
FunctionEnd

I've got the following, but it's not working. The first message box does return the temp location of the ini file, but the second one does not return anything for the "machine". Am i not doing the pop/push right or something?
Again, your help is v. much appreciated!


Function .onInit
File /oname=configPage.ini configPage.ini
FunctionEnd

Function configurationPage
GetTempFileName $R0
File /oname=$R0 configPage.ini
InstallOptions::dialog $R0
MessageBox MB_OK 'The ini file is called "$R0"'
ReadINIStr $0 "configPage.ini" "Field 2" "Machine"
MessageBox MB_OK 'Machine name is:"$0"'

FunctionEnd


change
ReadINIStr $0 "configPage.ini" "Field 2" "Machine"
to
ReadINIStr $0 "configPage.ini" "Field 2" "State"

should work
Kobus


It still doesn't work. Why would State work better than Machine anyway?
I really don't see what my problem is, because i'm doing what many posts say i should do, yet it doesn't work...I'm attaching my nsi file, maybe you could take a look at it:

Name "zipexample2"
OutFile "zipexample2.exe"
InstallDir C:\TestInstall\ZipExample2

;--------------------------------
; Pages

Page components
Page custom configurationPage "" ": Configuration Options"
Page directory
Page instfiles

;--------------------------------
; Sections

Section "Main Install"
SetOutPath $INSTDIR
File /r "ExeRoot\*.*"
SectionEnd

Section "Update Configuration Files"
; Replace IP address with hardcoded value for config.txt
Push @IPADDRESS@ #text to be replaced
Push "255.255.255.0" #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push C:\TestInstall\ZipExample2\Config1\config.txt #file to replace in
Call AdvReplaceInFile
SectionEnd




;--------------------------------
; Functions

Function AdvReplaceInFile
Exch $0 ;file to replace in
Exch
Exch $1 ;number to replace after
Exch
Exch 2
Exch $2 ;replace and onwards
Exch 2
Exch 3
Exch $3 ;replace with
Exch 3
Exch 4
Exch $4 ;to replace
Exch 4
Push $5 ;minus count
Push $6 ;universal
Push $7 ;end string
Push $8 ;left string
Push $9 ;right string
Push $R0 ;file1
Push $R1 ;file2
Push $R2 ;read
Push $R3 ;universal
Push $R4 ;count (onwards)
Push $R5 ;count (after)
Push $R6 ;temp file name

GetTempFileName $R6
FileOpen $R1 $0 r ;file to search in
FileOpen $R0 $R6 w ;temp file
StrLen $R3 $4
StrCpy $R4 -1
StrCpy $R5 -1

loop_read:
ClearErrors
FileRead $R1 $R2 ;read line
IfErrors exit

StrCpy $5 0
StrCpy $7 $R2

loop_filter:
IntOp $5 $5 - 1
StrCpy $6 $7 $R3 $5 ;search
StrCmp $6 "" file_write2
StrCmp $6 $4 0 loop_filter

StrCpy $8 $7 $5 ;left part
IntOp $6 $5 + $R3
StrCpy $9 $7 "" $6 ;right part
StrCpy $7 $8$3$9 ;re-join

IntOp $R4 $R4 + 1
StrCmp $2 all file_write1
StrCmp $R4 $2 0 file_write2
IntOp $R4 $R4 - 1

IntOp $R5 $R5 + 1
StrCmp $1 all file_write1
StrCmp $R5 $1 0 file_write1
IntOp $R5 $R5 - 1
Goto file_write2

file_write1:
FileWrite $R0 $7 ;write modified line
Goto loop_read

file_write2:
FileWrite $R0 $R2 ;write unmodified line
Goto loop_read

exit:
FileClose $R0
FileClose $R1

SetDetailsPrint none
Delete $0
Rename $R6 $0
Delete $R6
SetDetailsPrint both

Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
Pop $9
Pop $8
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd

Function .onInit
; InitPluginsDir
File /oname=configPage.ini configPage.ini
FunctionEnd

Function configurationPage
GetTempFileName $R0
File /oname=$R0 configPage.ini
InstallOptions::dialog $R0
MessageBox MB_OK 'The ini file is called "$R0"'
ReadINIStr $0 "configPage.ini" "Field 3" "State"
MessageBox MB_OK 'Machine name is:"$0"'

FunctionEnd


attach your configPage.ini also ...


this work for me ..., (I've generated some ini file with 3 text fields for testing :) )


Function .onInit
;set output path - in here all files from now goes to user temporary directory
SetOutPath $TEMP
;extract configPage.ini to user temporary directory
File configPage.ini
FunctionEnd

Function configurationPage
InstallOptions::dialog $TEMP\configPage.ini
MessageBox MB_OK 'The ini file is called "$TEMP\configPage.ini"'
;There is nothing like "Machine" value in configPage.ini
;value of the field is stored in State
ReadINIStr $0 "$TEMP\configPage.ini" "Field 3" "State"
MessageBox MB_OK 'Machine name is:"$0"'
FunctionEnd

This is my ini file:

; Ini file generated by the HM NIS Edit IO designer.
[Settings]
NumFields=4

[Field 1]
Type=Groupbox
Text=Groupbox
Left=13
Right=240
Top=7
Bottom=100

[Field 2]
Type=Label
Text=MachineName
Left=26
Right=72
Top=78
Bottom=86

[Field 3]
Type=Text
Left=87
Right=211
Top=76
Bottom=89

[Field 4]
Type=Label
Text=Please enter the following required information. \r\nThe Install will not be successful without it
Left=49
Right=222
Top=19
Bottom=62


kobus, please help!! :)