Old 1st November 2012, 22:12   #1
n4gix
Junior Member
 
Join Date: Nov 2012
Posts: 8
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
n4gix is offline   Reply With Quote
Old 2nd November 2012, 00:34   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,106
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

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 2nd November 2012, 04:10   #3
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Simply readregstr the proper value into $INSTDIR in your option page's leave function.
MSG is offline   Reply With Quote
Old 2nd November 2012, 16:22   #4
n4gix
Junior Member
 
Join Date: Nov 2012
Posts: 8
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...
Quote:
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:

code:

;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\"


Last edited by n4gix; 2nd November 2012 at 18:11.
n4gix is offline   Reply With Quote
Old 2nd November 2012, 17:54   #5
demiller9
Senior Member
 
Join Date: Mar 2006
Location: Dallas
Posts: 462
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.
demiller9 is offline   Reply With Quote
Old 2nd November 2012, 18:08   #6
n4gix
Junior Member
 
Join Date: Nov 2012
Posts: 8
Quote:
Originally Posted by demiller9 View Post
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.
n4gix is offline   Reply With Quote
Old 2nd November 2012, 21:54   #7
n4gix
Junior Member
 
Join Date: Nov 2012
Posts: 8
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:
code:

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

n4gix is offline   Reply With Quote
Old 2nd November 2012, 22:22   #8
redxii
Senior Member
 
Join Date: Nov 2005
Posts: 115
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".
redxii is offline   Reply With Quote
Old 2nd November 2012, 22:33   #9
n4gix
Junior Member
 
Join Date: Nov 2012
Posts: 8
Quote:
Originally Posted by redxii View Post
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...

Quote:
Error: command InstallDirRegKey not valic in Function
code:

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

n4gix is offline   Reply With Quote
Old 2nd November 2012, 22:41   #10
redxii
Senior Member
 
Join Date: Nov 2005
Posts: 115
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
redxii is offline   Reply With Quote
Old 2nd November 2012, 23:03   #11
n4gix
Junior Member
 
Join Date: Nov 2012
Posts: 8
Quote:
Originally Posted by redxii View Post
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.

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

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

n4gix is offline   Reply With Quote
Old 2nd November 2012, 23:32   #12
n4gix
Junior Member
 
Join Date: Nov 2012
Posts: 8
Nevermind the previous. I found that this works well enough for my purposes...

code:
PageEx license
LicenseData F86_License.txt
LicenseForceSelection checkbox
PageExEnd

n4gix is offline   Reply With Quote
Old 3rd November 2012, 02:16   #13
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,106
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

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump