Archive: passing data from custom page drop down menu to a "leave page" with functions.


passing data from custom page drop down menu to a "leave page" with functions.
As part of the setup process in the install script, right after the welcome page, is a custom InstallOptions .ini page with a drop down menu. This menu has ListItems with worded selections, and numbered ListValues related to the ListItems.

As I understand it, the ListValues is associated to an integer where ListItem 1 has a ListValue of 0 and ListItem 2 would have a ListValue of 1. Is this correct?

If so, what I would like to do is pass the ListValue selected by the ListItem through to the "leave page" which will use a ReplaceInFile function to write to a config.xml file that is put into the installation directory. It will modify a special URL with the ListValue number in the part where ReplaceInFile sees _ID_ or something to that effect.

To be more descriptive at the risk of sounding redundant:

What I need to do is have a user who is installing the software, select and option from the drop down menu on step 2 of the entire installation, or the page right after the default welcome page. Depending upon what they select, a corresponding number (From ListValue) will be passed to the "leave page" which will have a function to write to a config.xml file the number of the ListValue and is then going to be put into the installation directory.

Also, they must make a selection, so if the default "Make a Selection" at ListValue 0 is still there, it would be assumed that they have not made a selection and they cannot continue until they make a selection.

Does this sound possible?

If so, how should I go about it?


List values aren't associated to any integer.
The selected by the user item is written to the state under the field # which represents the droplist control.
If you spend some time to examine-compile-execute the example I've posted on the other thread, you'll get the point to achieve what you want,

http://forums.winamp.com/showthread....32#post2155232


One thing about that though, there is going to be 60+ options to choose from. What would be the trick to convert a word based list into numbers, like ID's based on what they select without actually revealing an ID number in the list?


Then, what would I do to grab that resulting data and use it for a ReplaceInFile routine?


60+ options means 60+ different actions right?
You need to compare the input with each one of the 60+ available options in order to execute the corresponding action.

In leave function you read the state of dropdown control from the ini so if state is option one action to perform is action one and so one.
If state is a something like "Plese select an option" the action is a warning message and abort which means do not proceed stay on page.
See below, you may copy/paste this, compile it and execute it, won't harm you.

showinstdetails show
outfile 'test.exe'
Installdir "$PROGRAMFILES\My Application"

!include logiclib.nsh

page custom customcreate customleave
page directory
page instfiles

section
#####
sectionend

function customleave ;custon page leave function
ReadINIStr $0 "$PLUGINSDIR\custom.ini" "settings" "state"
${If} $0 == 0
ReadINIStr $0 "$PLUGINSDIR\custom.ini" "field 2" "state"
${AndIf} $0 == "Select an option"
MessageBox MB_OK "Please select an option to continue"
Abort
${EndIf}
ReadINIStr $0 "$PLUGINSDIR\custom.ini" "field 2" "state"
${If} $0 == "Option one"
# user selected option one
# write now the xml with what represents option one
${elseif} $0 == "Option two"
# user selected option two
# write now the xml with what represents option two
${else}
# user selected option three
# write now the xml with what represents option three
${EndIf}
functionend

function customcreate ;custom page create function
InstallOptions::Dialog "$PLUGINSDIR\custom.ini"
pop $0
functionend

function .onInit
InitPluginsDir

WriteIniStr "$PLUGINSDIR\custom.ini" "settings" "numfields" "2"

WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "type" "groupbox"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "left" "0"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "right" "-1"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "top" "10"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "bottom" "-11"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "text" "Select an option"

WriteIniStr "$PLUGINSDIR\custom.ini" "field 2" "type" "droplist"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 2" "left" "40"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 2" "right" "-40"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 2" "top" "30"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 2" "bottom" "80"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 2" "Listitems" "Select an option|Option one|Option two|Option three"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 2" "state" "Select an option"
functionend

Ok I think I understand what you mean now and that part does now work. Thank you!

The next question is, how do I use ReplaceInFile to write to a config.xml which is going to ultimately be put into the $INSDIR after it was modified to show the proper ID#? I seem to have some confusion with that too.

The below might illustrate what I am trying to do, but this is kind of advanced yet for me and I could use your help.

Here is what I have:



!include LogicLib.nsh
!include StrRep.nsh
!include ReplaceInFile.nsh

!macro ReplaceInFile SOURCE_FILE SEARCH_TEXT REPLACEMENT
Push "${SOURCE_FILE}"
Push "${SEARCH_TEXT}"
Push "${REPLACEMENT}"
Call RIF
!macroend

Var ID_NUMBER

function SelectLeave

ReadINIStr $0 "$PLUGINSDIR\Select.ini" "settings" "state"
${If} $0 == 0
ReadINIStr $0 "$PLUGINSDIR\Select.ini" "field 2" "state"
${AndIf} $0 == "[Select Your Township Here]"
MessageBox MB_OK "Please select an option to continue Setup"
Abort
${EndIf}
ReadINIStr $0 "$PLUGINSDIR\Select.ini" "field 2" "state"
${If} $0 == "Abington Township"
MessageBox MB_OK "You have selected Abington Township"
!insertmacro ReplaceInFile "$INSTDIR\Config.xml" "__ID__" "$ID_NUMBER"
${elseif} $0 == "Ambler Borough"
MessageBox MB_OK "You have selected Ambler Borough"
!insertmacro ReplaceInFile "$INSTDIR\Config.xml" "__ID__" "$ID_NUMBER"
${elseif} $0 == "Bridgeport Borough"
MessageBox MB_OK "You have selected Bridgeport Borough"
!insertmacro ReplaceInFile "$INSTDIR\Config.xml" "__ID__" "$ID_NUMBER"
${elseif} $0 == "Bryn Athyn Borough"
MessageBox MB_OK "You have selected Bryn Athyn Borough"
!insertmacro ReplaceInFile "$INSTDIR\Config.xml" "__ID__" "$ID_NUMBER"
${elseif} $0 == "Cheltenham Township"
MessageBox MB_OK "You have selected Cheltenham Township"
!insertmacro ReplaceInFile "$INSTDIR\Config.xml" "__ID__" "$ID_NUMBER"
${elseif} $0 == "Collegeville Borough"
MessageBox MB_OK "You have selected Collegeville Borough"
!insertmacro ReplaceInFile "$INSTDIR\Config.xml" "__ID__" "$ID_NUMBER"
${elseif} $0 == "Conshohocken Borough"
MessageBox MB_OK "You have selected Conshohocken Borough"
!insertmacro ReplaceInFile "$INSTDIR\Config.xml" "__ID__" "$ID_NUMBER"
${else}
MessageBox MB_OK "You have Selected Douglass Township"
!insertmacro ReplaceInFile "$INSTDIR\Config.xml" "__ID__" "$ID_NUMBER"
${EndIf}

functionend



First, the proper messages are coming up depending upon which "state" they select. So thank you for that.

Next, I believe I am missing a step as I will need to convert the "state" that they selected from the name of the state to a number depending on the state they select. In production the message box will be removed and it will be a silent thing to modify the Config.xml file not yet copied to the $INSTDIR. But even if I can get it to write to Config.xml, it looks like it will just put in the raw "state" as selected and not a number. So somehow I have to convert to a number and I am not sure how.

Also, it seems that nothing is being written to the config.xml file. Where I have __ID__ it just stays as __ID__ so it seems I might be having confusion as to what directory $INSTDIR or otherwise, ReplaceInFile should be looking in to find this file find that tag and then replace it with the ID number based on the selection that is made from the drop down menu.

One thing to note, the Config.xml I believe hasn't been copied to $INSTDIR yet because as I understand it $INSTDIR is the resulting directory the files are "installed" to. Correct? Since that happens later upon setup, where would I be able to make this change while Config.xml is "in limbo" before it is copied to the $INSTDIR ?

Thank you so much for your help on this.

If I remember correctly there are 3 plugins at wiki related to editing XMLs.
The $INSTDIR has not been created yet so you should extract your xml in $TEMP
or $PLUGINSDIR edit it and later within the install section where $INSTDIR is created copy or move it there.
Things are pretty clear I guess :)
${If} $0 == "Abington Township" ; I know that this going to be 1,
${elseif} $0 == "Ambler Borough" ; I know that this going to be 2,
and so on

or

!define Abington_Township "1"
!define Ambler_Borough "2"

function SelectLeave
............
............

ReadINIStr $0 "$PLUGINSDIR\Select.ini" "field 2" "state"
${If} $0 == "Abington Township"
MessageBox MB_OK "You have selected Abington Township"
!insertmacro ReplaceInFile "$INSTDIR\Config.xml" "__ID__" "${Abington_Township}"
${elseif} $0 == "Ambler Borough"
MessageBox MB_OK "You have selected Ambler Borough"
!insertmacro ReplaceInFile "$INSTDIR\Config.xml" "__ID__" "${Ambler_Borough}"

............
............
functionend

Also, simplified without the need of extracting the file first in $TEMP or elsewhere

!define Abington_Township "1"
!define Ambler_Borough "2"

Var ID_NUMBER

function SelectLeave
.............
.............

ReadINIStr $0 "$PLUGINSDIR\Select.ini" "field 2" "state"
${If} $0 == "Abington Township"
MessageBox MB_OK "You have selected Abington Township"
StrCpy "$ID_NUMBER" "${Abington_Township}
${elseif} $0 == "Ambler Borough"
MessageBox MB_OK "You have selected Ambler Borough"
StrCpy "$ID_NUMBER" "${Ambler_Borough}"

.............
.............
functionend

Section -Install
SetOutPath "$INSTDIR"
File "LOCAL_PATH\config.xml"
!insertmacro ReplaceInFile "$INSTDIR\Config.xml" "__ID__" "$ID_NUMBER"

................
................
SectionEnd

You are a beautiful person Red Wine. Thank you so much for your help!


lol I suspect I should change my avatar :D