Archive: Choosing Between 2 Registry Path Options


Choosing Between 2 Registry Path Options
I need to ask the customer to choose between installing our product to FSX or Prepar3D. Both programs have Registry Keys...

It seems like a simple enough task, but so far I've found nothing remotely similar in any of the documentation, examples, or even searching this forum.

I am using "MUI2.nsh" just for sake of information.

Desired binary dialog:
==================
To which of these simulator programs do you wish to install this product?
[ ] FSX
[ ] Prepar3D
==================

if FSX
InstallDirRegKey HKLM "Software\Microsoft\Microsoft Games\flight simulator\10.0" SetupPath
InstallDir "$PROGRAMFILES\Microsoft Games\Microsoft Flight Simulator X\"

else if Prepar3D
InstallDirRegKey HKLM "Software\LockheedMartin\Prepar3D" SetupPath
InstallDir "$PROGRAMFILES\Prepar3D\"

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "MilViz_F86_vR1.121026.exe"

ShowInstDetails hide

Section "MainSection" SEC01

SetOverwrite on
SetOutPath "$INSTDIR\Sound\MilViz"
File "F:\Installer Build Folders\F86 Build Folder\Sound\MilViz\*.*"

;...snipped remainder of file for brevity...

SectionEnd

Section -Post
SectionEnd


If the key and value specified by InstallDirRegKey exists it is copied to $instdir before any of your code runs, if you need something more advanced you have to do it yourself.

If you want check/radiobuttons on the components page/custom page to change $instdir you must do it with ReadRegStr


Simply readregstr the proper value into $INSTDIR in your option page's leave function.


Thank you both for your replies, which I'm sure are excellent suggestions. While I am not inexperienced with coding logic, I am completely ignorant of this scripting language and its myriad options, nor quite honestly do I have any "free time" to devote to learning enough to answer my own question... :(

The problem -which it appears that I have not made clear enough- is that I have no idea whatever how to create this dialog page to begin with, nor how to integrate it into my existing installer script...

Desired binary dialog page:
==================
To which of these simulator programs do you wish to install this product?
[ ] FSX
[ ] Prepar3D
==================
As it exists now, the customer can manually use the Browse option to search for and select the install path for his/her FSX or Prepar3D root folder, but I'd prefer to save them from that effort by simply allowing them to choose one or the other from a simple dialog page.

This part is pseudo-code to illustrate the desired logic. At the moment, I have to build two separate installers for each of the two target simulator programs and comment out (;) the two opposite lines, which seems to be very inefficient and clumsy:


;if FSX
InstallDirRegKey HKLM "Software\Microsoft\Microsoft Games\flight simulator\10.0" SetupPath
InstallDir "$PROGRAMFILES\Microsoft Games\Microsoft Flight Simulator X\"

;else if Prepar3D
;InstallDirRegKey HKLM "Software\LockheedMartin\Prepar3D" SetupPath
;InstallDir "$PROGRAMFILES\Prepar3D\"

Read the tutorial on nsDialogs; then you can create a custom page with two radio buttons. In the exit (leave) function you will read the button states and can perform the if/else (${IF} / ${Else} / ${EndIf} ) logic to set the installation directory and registry keys.


Originally posted by demiller9
Read the tutorial on nsDialogs; then you can create a custom page with two radio buttons. In the exit (leave) function you will read the button states and can perform the if/else (${IF} / ${Else} / ${EndIf} ) logic to set the installation directory and registry keys.
Actually, I did just that yesterday afternoon. Unfortunately, I didn't find any help there either. Simply trying to add any of the examples to my existing script caused a compiler error.

I'll give it another go though. Maybe this time it'll work out for me. :igor:

Okay, I've made some progress, but I cannot figure out how to select only one of the two options. I was hoping that the ${if} statement would work, but obviously I've not got it correct yet:


XPStyle on
Var Dialog
Var Label
Var Text
Var Text_State
Var Checkbox
Var Checkbox2
Var Checkbox_State
Var Checkbox2_State

Page custom nsDialogsPage nsDialogsPageLeave

Function nsDialogsPage

nsDialogs::Create 1018
Pop $Dialog

${If} $Dialog == error
Abort
${EndIf}

${NSD_CreateLabel} 0 0 100% 12u "Please Choose Your Simulator Version!"
Pop $Label

${NSD_CreateCheckbox} 0 20u 100% 10u "&FSX"
Pop $Checkbox

${NSD_CreateCheckbox} 0 40u 100% 10u "&Prepar3D"
Pop $Checkbox2

${If} $Checkbox2_State == ${BST_CHECKED}
${NSD_Uncheck} $Checkbox
${EndIf}

nsDialogs::Show

FunctionEnd

Function nsDialogsPageLeave

${NSD_GetText} $Text $Text_State
${NSD_GetState} $Checkbox $Checkbox_State
MessageBox MB_OK "You Chose:$\n$\n$Checkbox_State $\n$\n$Checkbox2_State"

FunctionEnd

Use ${NSD_CreateRadioButton} instead, since you say only one option can be selected. Also you didn't get the state of 'Checkbox2' and you don't have an item named "Text".


Originally posted by redxii
Use ${NSD_CreateRadioButton} instead, and you didn't get the state of 'Checkbox2'.
I did change already to the RadioButton. Now the problem is that this script won't allow me to use the InstallDirRegKey... within the Function... :eek:

Error: command InstallDirRegKey not valic in Function

Function nsDialogsPageLeave

${NSD_GetState} $RadioButton $RadioButton_State
${NSD_GetState} $RadioButton2 $RadioButton2_State

${If} $RadioButton_State == 1
InstallDirRegKey HKLM "Software\Microsoft\Microsoft Games\flight simulator\10.0" SetupPath
InstallDir "$PROGRAMFILES\Microsoft Games\Microsoft Flight Simulator X\"
${EndIf}

${If} $RadioButton2_State == 1
InstallDirRegKey HKLM "Software\LockheedMartin\Prepar3D" SetupPath
InstallDir "$PROGRAMFILES\Prepar3D\"
${EndIf}

FunctionEnd

You can't use InstallDirRegKey or InstallDir in a function/section.

Use ReadRegStr to read the key to change $INSTDIR. For example:

ReadRegStr $INSTDIR HKLM "Software\LockheedMartin\Prepar3D" SetupPath


Originally posted by redxii
You can't use InstallDirRegKey or InstallDir in a function/section.

Use ReadRegStr to read the key to change $INSTDIR. For example:

ReadRegStr $INSTDIR HKLM "Software\LockheedMartin\Prepar3D" SetupPath
Thank you so very much! That was the final bit that was holding me back...

Now my Radio Buttons are correctly selecting the install path and I can move on. Pity it took so long, but since every project uses this same template, I won't have to mess with it again.

While I have attention though, could someone explain how to use this?

Page license

I have a license text file already that I've been using with this function from HM NIS Edit":

!insertmacro MUI_PAGE_LICENSE "F86_License.txt"

It would simply look nicer to have it in better integrated with the nsDialogs if possible. :p

In case someone else as "slow" as myself happens to need this, here is the completed script:

XPStyle on
Var Dialog
Var Label
Var RadioButton
Var RadioButton2
Var RadioButton_State
Var RadioButton2_State

Page custom nsDialogsPage nsDialogsPageLeave
;Page license

Function nsDialogsPage

nsDialogs::Create 1018
Pop $Dialog

${If} $Dialog == error
Abort
${EndIf}

${NSD_CreateLabel} 0 0 100% 12u "Please Choose Your Simulator Version!"
Pop $Label

${NSD_CreateRadioButton} 0 20u 100% 10u "&FSX"
Pop $RadioButton

${NSD_CreateRadioButton} 0 40u 100% 10u "&Prepar3D"
Pop $RadioButton2

nsDialogs::Show

FunctionEnd

Function nsDialogsPageLeave

${NSD_GetState} $RadioButton $RadioButton_State
${NSD_GetState} $RadioButton2 $RadioButton2_State

${If} $RadioButton_State == 1
ReadRegStr $INSTDIR HKLM "Software\Microsoft\Microsoft Games\flight simulator\10.0" SetupPath
${EndIf}

${If} $RadioButton2_State == 1
ReadRegStr $INSTDIR HKLM "Software\LockheedMartin\Prepar3D" SetupPath
${EndIf}

FunctionEnd

Nevermind the previous. I found that this works well enough for my purposes...

 PageEx license
LicenseData F86_License.txt
LicenseForceSelection checkbox
PageExEnd

Most of the MUI page macros are wrappers around the built-in NSIS pages and they can be configured with the MUI defines listed in the MUI readme, in your case MUI_LICENSEPAGE_CHECKBOX