Archive: User Input via interface and Command Line


User Input via interface and Command Line
  Hello all,

I am new to the nullsoft installer so there is a distinct possibility that what I am about to ask is a typical "noob" question. That being said I cant find any specific information in the docs

I need to create an installer that has a custom page in it that asks the user for an ip address. My current project has 10 sections in it and this page should only be displayed if the user select the component that needs the information.

The second problem is that this installer will also have the ability to run silently (which installs all components). So I need to know how to pass this value into the installer. For example

MyInstaller.exe /silent /ip:"127.0.0.1"

Any help of guidance on this one would be greatly appreciated

EDIT :
I have been looking at this
http://nsis.sourceforge.net/archive/...instances=0,64

But dont fully instand whats going on. I have added the following to my script

!define MUI_ABORTWARNING

>!insertmacro MUI_PAGE_WELCOME
>!insertmacro MUI_PAGE_LICENSE "FileArchive\license.txt"
>!insertmacro MUI_PAGE_COMPONENTS
Page custom GetServerIp
>!insertmacro MUI_PAGE_INSTFILES
>!insertmacro MUI_PAGE_FINISH
>....
....
....
Function GetServerIp

SectionGetFlags${sec_} $R0
IntOp $R0 $R0& ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show

Abort

show:

;Ifnot using Modern UI use InstallOptions::dialog "iofile.ini"
!insertmacro MUI_HEADER_TEXT "Server Address" "Enter your servers ip address or name"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "serverip.ini"

>FunctionEnd
>
I have copied a custom page ini file from here :

http://nsis.sourceforge.net/archive/...instances=0,48

(the showUserList.ini which is now my serverip.ini)

But it doesnt seem to do anything, for testing purposes I added a MessageBox MB_OK to the section after the show: and it is displayed, so the code is being hit.

EDIT 2:

It looks like the first example I was looking at missed the following line :

!insertmacro MUI_INSTALLOPTIONS_EXTRACT "serverip.ini"

The custom page now works, now I need to work out how to put a input box on there and save the value into a variable

For your custom page, put it in in the order that you would want it displayed if the user checks the section that needs it (SEC04 in this example). Probably after the components page, but before you InstFiles page. In the top of the "SetPage" function that will display the custom page, add the commands:

SectionGetFlags $R0 ${SEC04}
StrCmp $R0 0 End

Just make sure you have the End: label at the very end of the SetPage function, and if section 4 is not selected, the custom page will not be displayed, and the installer will skip to the next page.

As for passing a parameter to a silent install, check out the help file, specifically 4.12 Silent Installers/Uninstallers. You will need to add GetParameters and StrStr functions, these can be found in appendix C.

Hope this helps.


Findings so far
  Well for the sake of anybody searching the forum in the future this is what I have so far (although I still have a few small problems)

Custom Page
I needed a custom page with a few labels and an input box, this page was only to be displayed if a specific section was selected.

Add the following function


GetServerIp

;sec_MySpecficSection is the name of the section
;that must be selected, if it isnt then the function
;aborts
SectionGetFlags${sec_MySpecficSection} $R0
IntOp $R0 $R0& ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show
Abort

show:
!
insertmacro MUI_INSTALLOPTIONS_EXTRACT "serverip.ini"
!insertmacro MUI_HEADER_TEXT "Server Address" "Enter your servers ip address or name"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "serverip.ini"
>FunctionEnd
>
I also added the following to the page definitions


define MUI_ABORTWARNING

>!insertmacro MUI_PAGE_WELCOME
>!insertmacro MUI_PAGE_LICENSE "license.txt"
>!insertmacro MUI_PAGE_COMPONENTS
>;THIS NEXT LINE WAS ADDED
Page custom GetServerIp
>!insertmacro MUI_PAGE_INSTFILES
>!insertmacro MUI_PAGE_FINISH
>!insertmacro MUI_UNPAGE_CONFIRM
>!insertmacro MUI_UNPAGE_INSTFILES
>
The serverip.ini file looks like this :


***93;

>NumFields=4

>***91;Field 1***93;
>Type=Label
Text
=Server Address
Left=0
Right=171
Top=0
Bottom=15

>***91;Field 2***93;
>Type=Text
State=192.168.0.1
Left=85
Right=226
Top=16
Bottom=29

>***91;Field 3***93;
>Type=Label
Text=How to obtain your server address
Left=0
Right=171
Top=35
Bottom=45

>***91;Field 4***93;
>Type=Label
Text=Description text explaining how to get the IP address
Left=0
Right=300
Top=50
Bottom=300
>
Command Line Params
To parse a command line parameter
1) Add the "StrStr" function from the NSIS docs
2) Add the "GetParameters" function from the NSIS docs
3) Add the "GetParameterValue" function from here :

http://nsis.sourceforge.net/archive/...ances=0,11,804

This is then called like this :

Push "PSN"          ; param name

Push"ERR_NO_PSN" ; default value
Call GetParameterValue
Pop$2
MessageBox MB_OK "Value of OUTPUT is '$2'"
So if you pass /PSN=127.0.0.1 $2 will contain the value 127.0.0.1. If you dont pass the command line parameters $2 will contain ERR_NO_PSN

The example on the website above copys the $2 param into another called $OUTPUT using the following line :


StrCpy $OUTPUT $2 

>
But this doesnt compile for me, not sure why.

A couple of questions

1) How do I get the value the user entered into the Server IP text box on the custom page?

Read it using MUI_INSTALLOPTIONS_READ from your first custom page INI file, then write it straight into your second custom page INI file using MUI_INSTALLOPTIONS_WRITE.

-Stu