3

enter image description here

I want that if none of the RadioButtons are selected , then ,when the Next button is pressed, then it should give an alert that PLEASE CHOSE ATLEAST ONE ITEM, and it should not go to the next Dialog.

Also, I want that if the user selects the option : UPDATE EXISTING SOFTWARE, then only some files are copied, and if the other radiobutton is selected , then all files are copied,

Is this possible using sections or functions have to be used? can i call a Section, like if RadioButton 1 is chosen, then SECTION CREATEALLFILES is called, else SECTION CREATEONLYTWOFILES is called?

According to me, i think i want the code to HOW TO HOLD THE ids of these two RadioButtons and use them accordingly , to call different sections or functions. What would be the code? Please help?

Also, after pressing NEXT on this page, the next dialog will come as in image below: i want to show a LABEL , whether DEMO is done, or UPDATE is running, for this i will add a Label using Resource Hacker, but how to display that Label and hide it according to user choice of RadioButton enter image description here

Machavity
  • 30,841
  • 27
  • 92
  • 100
sqlchild
  • 8,754
  • 28
  • 105
  • 167

1 Answers1

2

You can select/unselect sections or just put the logic in a single section, this example does both:

!include nsDialogs.nsh
!include Sections.nsh

var InstallType

Section 
#Install common files...
${If} $InstallType == DEMO
    #Do demo specific stuff
${Else}
    #Do update specific stuff
${EndIf}
SectionEnd

Section "" SEC_DEMO
#Install demo..
SectionEnd

Section "" SEC_UPDATE
#Do update..
SectionEnd

Page custom InstTypePageCreate InstTypePageLeave

Function InstTypePageCreate
nsDialogs::Create 1018
pop $0
${NSD_CreateRadioButton} 0 50u 100% 10u "Demo"
pop $1
${IfThen} $InstallType == DEMO ${|} ${NSD_Check} $1 ${|}
${NSD_CreateRadioButton} 0 70u 100% 10u "Update"
pop $2
${IfThen} $InstallType == UPDATE ${|} ${NSD_Check} $2 ${|}
nsDialogs::Show
FunctionEnd

Function InstTypePageLeave
${NSD_GetState} $1 $0
${If} $0 = ${BST_CHECKED}
    StrCpy $InstallType DEMO
    !insertmacro UnselectSection ${SEC_UPDATE}
    !insertmacro SelectSection ${SEC_DEMO}
${Else}
    ${NSD_GetState} $2 $0
    ${If} $0 = ${BST_CHECKED}
        StrCpy $InstallType UPDATE
        !insertmacro UnselectSection ${SEC_DEMO}
        !insertmacro SelectSection ${SEC_UPDATE}
    ${Else}
        MessageBox MB_ICONSTOP "You must select something!"
        Abort
    ${EndIf}
${EndIf}
FunctionEnd

To set the text on the next page, just use ${NSD_SetText} $hwndYourLabel "Text" and ShowWindow inside a if block that tests $InstallType (This code needs to be in the show function callback (MUI_PAGE_CUSTOMFUNCTION_SHOW) for that page)

Anders
  • 97,548
  • 12
  • 110
  • 164
  • @Anders : sir, please check my previous post on which you have also replied, i am waiting for another answer from you, ----http://stackoverflow.com/questions/5803182/fill-directory-textbox-on-button-click-in-mui-nsi-installer-using-buttonevent-p – sqlchild Apr 28 '11 at 10:56
  • @Anders: please explain me this line: ---${IfThen} $InstallType == DEMO ${|} ${NSD_Check} $1 ${|} – sqlchild Apr 28 '11 at 11:41
  • when will these functions be called,---------Section SEC_DEMO , SEC_UPDATE – sqlchild Apr 28 '11 at 11:43
  • also, sir, if user choses DEMO ,then i want to copy only few files , so where shall i write the code to copy only few files, in the SEC_DEMO or in the IF code of the UNNAMED SECTION---Section #Install common files... ${If} $InstallType == DEMO #Do demo specific stuff ${Else} #Do update specific stuff ${EndIf} SectionEnd , AM CONFUSED HERE???? – sqlchild Apr 28 '11 at 11:45
  • 1
    @sqlchild: "${IfThen} $InstallType == DEMO ${|} ${NSD_Check} $1 ${|}" is just to remember the previous state if you press the back button to go back to the page with the radio buttons – Anders Apr 28 '11 at 11:56
  • 1
    @sqlchild: You can use the if/else block in the unnamed section OR the two specific sections, they do the same job, just differently... – Anders Apr 28 '11 at 11:57
  • so can i remove this section ------Section #Install common files... ${If} $InstallType == DEMO #Do demo specific stuff ${Else} #Do update specific stuff ${EndIf} SectionEnd – sqlchild Apr 28 '11 at 12:10
  • Section "" SEC_DEMO --- is this also UNNAMED SECTION ? what is SEC_DEMO doing after the quotes? – sqlchild Apr 28 '11 at 12:12
  • 1
    @sqlchild: Each section has a index (Number starting from 0 IIRC) that you need when working with the Section* instructions and the sections.nsh macros, SEC_DEMO is just the name I used. If you are unsure about how this all works I suggest you give all the sections a name and add a component page after your radio selection page and just play around to get a feeling for how it all works... – Anders Apr 28 '11 at 12:19
  • ok, so when will this be called, where have you written this in the code? – sqlchild Apr 28 '11 at 12:20
  • "You can use the if/else block in the unnamed section OR the two specific sections, they do the same job, just differently.."-----you said this sir, so the actions to be performed when DEMO radiobutton is selected, should be written in which part,---------- SECTION "' SEC_DEMO or in this ------------Section #Install common files... ${If} $InstallType == DEMO #Do demo specific stuff------------here----- ${Else} – sqlchild Apr 28 '11 at 12:23
  • @sqlchild: It is very hard to put code here in the comments, can't you just replace ALL of the #Do xyz comments with a call to MessageBox and just test it yourself. – Anders Apr 28 '11 at 12:32
  • @Anders : sir, sorry to disturb you a lot, am just asking that in which section shall i put the DEMO code, in the SECTION "" SEC_DEMO ,,,,, or ,,,,,, in this- Section $InstallType==DEMO......SectionEnd – sqlchild Apr 28 '11 at 13:14
  • 1
    @sqlchild: Pick one of them and remove the other. Like I said, add some messageboxes and just TRY. – Anders Apr 28 '11 at 13:23
  • ok sir, also, i want to make SECTION "" SEC_DEMO - a section group , can i make it, what other changes will i have to do in your code except adding the Group phrase – sqlchild Apr 28 '11 at 13:41
  • @sqlchild: It is hard to say what needs to change without any code, but as long as the group does not contain read only sections you probably don't have to change anything. – Anders Apr 28 '11 at 13:57
  • @Anders: sir , can you please help me out with this Error : could not resolve label "_LogicLib_Label_64" in unnamed install section (5) Error - aborting creation process – sqlchild Apr 28 '11 at 14:11
  • sir, also, i want that if user choses UPDATE , then the Components page should not appear, how to do it? please mention the code – sqlchild Apr 28 '11 at 14:17
  • also, i have done, Var Label, now how to add it on the MUI_PAGE_DIRECTORY ? should i have to use Resource Hacker ? – sqlchild Apr 28 '11 at 14:21
  • its giving error: unknown variable/constant "{SEC_DEMO}" detected, ignoring (macro:SelectSection:4) ---------i have made SEC_DEMO a SectionGroup – sqlchild Apr 28 '11 at 14:28
  • 1
    The code that uses ${SEC_DEMO} has to come after the Section in your .nsi – Anders Apr 28 '11 at 14:34
  • sir, i have done, Var Label, now how to add it on the MUI_PAGE_DIRECTORY ? should i have to use Resource Hacker ? this label is the one which will be displayed on Directory Page, and its Text would be "YOU ARE INSTALLING A DEMO SOFTWARE" or "YOU ARE UPDATING YOUR EXISTING SOFTWARE" , if the user choses to install Demo or Update – sqlchild Apr 28 '11 at 15:07
  • 1
    @sqlchild: Yes, use resource hacker – Anders Apr 28 '11 at 15:10
  • sir, also, i want that if user choses UPDATE , then the Components page should not appear, how to do it? please mention the code, how do i skip the COMPONENTS page? – sqlchild Apr 28 '11 at 15:11
  • 1
    @sqlchild: You skip a page by calling Abort in the pre callback function for the page. – Anders Apr 28 '11 at 15:18
  • @Anders : sir, its working upto a close extent, am not full and final with it, actually when i select update radio button then also the Component Page appears, but if i use !define MUI_CUSTOMFUNCTION_PRE , then this is called if chose DEMO radiobutton , but i want that this PRE function is called only if the user choses the UPDATE radiobutton? how do i do it – sqlchild Apr 29 '11 at 06:02
  • @Anders: also, on chosing the UPDATE radiobutton, the SEC_DEMO is also called, is there some error? – sqlchild Apr 29 '11 at 06:03
  • sir, i want that , if the user choses the UPDATE radiobutton, then a SEC_UPDATE is called, it should be checked by default in the components page, but components page should not be displayed, and utomatically the code inside this section is executed . – sqlchild Apr 29 '11 at 06:07
  • 1
    @sqlchild: If the update section is never visible on the components page and only executed during update you can use a section without a name and just put all of the code in that section inside a ${If} $InstallType == UPDATE ... block – Anders Apr 29 '11 at 11:17
  • SIR, thanks a lot , now am stuck on the DISPLAY LABEL portion, when i choose DEMO, then the label text should be DEMO on the Directory Page or UPDATE , if i choose UPDATE, i have added the label from the Resource Hacker , you have told this-------{NSD_SetText} $hwndYourLabel "Text" ------but what shall write in place of $hwndYourLabel ? i mean, the label ID has to be written or what? – sqlchild Apr 29 '11 at 11:54