2016-04-06 6 views
1

Je ne suis pas un pro NSIS mais je me débrouille! Je suis en train de mettre en place un nouveau programme d'installation pour un nouveau logiciel que nous sommes en train de construire, j'ai configuré l'installation avec 2 chemins potentiels, installer ou mettre à niveau. L'idée est que lorsqu'un utilisateur sélectionne l'une des options de mise à niveau, toutes les options pouvant être sélectionnées pour l'installation sont désélectionnées et vice versa. Ce qui se passe pour l'instant, c'est lorsqu'un utilisateur, par exemple, sélectionne une option sous le chemin d'installation, toutes les options pour ce chemin sont sélectionnées et ne peuvent être désélectionnées sauf si vous sélectionnez une option sous le chemin de mise à niveau, après ce qui est intéressant, la sélection des options semble alors se comporter comme souhaité?NSIS options sélectionnées comportement impair

Voici mon code, quelle est la chose évidente qui me manque ici ??

;-------------------------------- 
;Includes 
;-------------------------------- 

    !include "MUI2.nsh" 
    !include "nsDialogs.nsh" 
    !include "LogicLib.nsh" 
    !include "Sections.nsh" 
    !include "oledb.nsh" 
    !include "WinMessages.nsh" 
    !include "ReplaceInFile.nsh" 



;-------------------------------- 
;General 
;-------------------------------- 

    ;Name and file 
    Name "App" 
    OutFile "AppName ${Version}.exe" 

    ;Default installation folder 
    InstallDir "C:\appFolder" 

    ;Request application privileges for Windows Vista + 
    RequestExecutionLevel admin 

;-------------------------------- 
;Interface Settings 
;-------------------------------- 

    !define MUI_ABORTWARNING 
    Var Dialog 
    Var SQLServer 
    Var SQLUsername 
    Var SQLPassword 
    Var SDatabase 
    Var CoreDatabase 
    Var UIDatabase 

    ShowInstDetails "show" 

;-------------------------------- 
;Pages 
;-------------------------------- 

    !insertmacro MUI_PAGE_WELCOME 
    !insertmacro MUI_PAGE_LICENSE "LIC.rtf" 
    !insertmacro MUI_PAGE_COMPONENTS 
    Page Custom SQLConnectionDetails SQLConnectionDetailsPageLeave 
    Page Custom DatabaseDetails DatabaseDetailsLeave 
    !insertmacro MUI_PAGE_DIRECTORY 
    !insertmacro MUI_PAGE_INSTFILES 
    !insertmacro MUI_PAGE_FINISH 

;-------------------------------- 
;onInit 
;-------------------------------- 

Function .onInit 
    InitPluginsDir 
    StrCpy $1 "SecMain" 

FunctionEnd 

;-------------------------------- 
;Page functions 
;-------------------------------- 

Function SQLConnectionDetails 
    !insertmacro MUI_HEADER_TEXT $(SQLServerDetailsTitle) $(SQLServerDetailsSubTitle) 
    nsDialogs::Create 1018 
    pop $Dialog 
    ${If} $Dialog == error 
     Abort 
    ${EndIf} 

    ;x, y, width, height and text 
    ${NSD_CreateLabel} 0 0 100% 10u "Enter the name of the SQL server that AppName is to be installed on" 
    pop $1 
    ${NSD_CreateText} 0 10u 150u 12u "" 
    pop $SQLServer 

    ${NSD_CreateLabel} 0 25u 100% 10u "Enter the database name" 
    pop $2 
    ${NSD_CreateText} 0 35u 100u 12u "" 
    pop $SDatabase 

    ${NSD_CreateLabel} 0 50u 100% 10u "Enter SQL username" 
    pop $3 
    ${NSD_CreateText}} 0 60u 100u 12u "" 
    pop $SQLUsername 

    ${NSD_CreateLabel} 0 75u 100% 10u "Enter SQL password" 
    pop $4 
    ${NSD_CreatePassword} 0 85u 100u 12u "" 
    pop $SQLPassword 

    nsDialogs::Show 
FunctionEnd 

Function SQLConnectionDetailsPageLeave 
    ${NSD_GetText} $SQLServer $SQLServer 
    ${NSD_GetText} $SQLUsername $SQLUsername 
    ${NSD_GetText} $SQLPassword $SQLPassword 
    ${NSD_GetText} $SDatabase $SDatabase 
    messagebox MB_OK "We will now attempt to connect to the database server." 
    MSSQL_OLEDB::SQL_Logon "$SQLServer" "$SQLUsername" "$SQLPassword" 
    pop $0 

    ${If} $0 = 0 
     ;messagebox MB_OK "Connection sucessful" 
    ${Else} 
     messagebox MB_OK "I encountered an issue whilst trying to connect to the database. Please check your details and try again." 
     abort 
    ${EndIf} 

    MSSQL_OLEDB::SQL_Logout 
FunctionEnd 

Function DatabaseDetails 
    !insertmacro MUI_HEADER_TEXT $(DatabaseNamesTitle) $(DatabaseNamesSubTitle) 
    nsDialogs::Create 1018 
    pop $Dialog 
    ${If} $Dialog == error 
     Abort 
    ${EndIf} 

    ;x, y, width, height and text 
    ${NSD_CreateLabel} 0 0 100% 10u "Enter the name to be given to the Core database" 
    pop $1 
    ${NSD_CreateText} 0 10u 150u 12u "" 
    pop $CoreDatabase 

    ${NSD_CreateLabel} 0 25u 100% 10u "Enter the name to be given to the UI database" 
    pop $2 
    ${NSD_CreateText} 0 35u 100u 12u "" 
    pop $UIDatabase 

    nsDialogs::Show 
FunctionEnd 

Function DatabaseDetailsLeave 
${NSD_GetText} $CoreDatabase $CoreDatabase 
${NSD_GetText} $UIDatabase $UIDatabase 
FunctionEnd 

;-------------------------------- 
;Languages 
;-------------------------------- 

    !insertmacro MUI_LANGUAGE "English" 

;-------------------------------- 
;Installer Sections 
;-------------------------------- 
InstType "New Install" 
InstType "New Install - Full" 
InstType "Upgrade" 

;------------ 
;New Install 
;------------ 

SectionGroup /e "!Install" SecGroupNewInstall 
    Section "Main App" SecMain 

    SectionEnd 

    Section /o "App1" SecApp1 

    SectionEnd 

    Section /o "App2" SecApp2 

    SectionEnd 

    Section /o "App3" SecApp3 

    SectionEnd 

    Section /o "App4" SecApp4 

    SectionEnd 

    SectionGroup /e "Optional" SubSecGroupNewInstall 
     Section /o "App5" SecApp5 

     SectionEnd 

     Section /o "App6" SecApp6 

     SectionEnd 

     Section /o "App7" SecApp7 

     SectionEnd 
    SectionGroupEnd 
SectionGroupEnd 

SectionGroup /e "!Upgrade" SecGroupUpgrade 
    Section /o "Upgrade Main App" SecMainUpgrade   
    SectionEnd 
SectionGroupEnd 

;-------------------------------- 
;onSelChange 
;-------------------------------- 

Function .onSelChange 

    !insertmacro StartRadioButtons $1 
     !insertmacro RadioButton ${SecMain} 
     !insertmacro RadioButton ${SecMainUpgrade} 
    !insertmacro EndRadioButtons 

    !insertmacro SectionFlagIsSet ${SecMain} ${SF_SELECTED} InstisSel InstnotSel 
     InstnotSel: 
      !insertmacro UnselectSection ${SecGroupNewInstall} 
     InstisSel: 

    !insertmacro SectionFlagIsSet ${SecMainUpgrade} ${SF_SELECTED} UpgisSel UpgnotSel 
     UpgnotSel: 
    !insertmacro UnselectSection ${SecGroupUpgrade} 
     UpgisSel: 

FunctionEnd 

Répondre

1

J'ai répondu à ma propre question !! Le problème était dû à la fois au timing et à un problème avec ma fonction onInit. J'ai déplacé ma fonction onInit au-dessous de mes groupes de section et ai corrigé le StrCpy pour inclure maintenant la référence de section correcte, voir le code corrigé ci-dessous:

;-------------------------------- 
;Includes 
;-------------------------------- 

    !include "MUI2.nsh" 
    !include "nsDialogs.nsh" 
    !include "LogicLib.nsh" 
    !include "Sections.nsh" 
    !include "oledb.nsh" 
    !include "WinMessages.nsh" 
    !include "ReplaceInFile.nsh" 



;-------------------------------- 
;General 
;-------------------------------- 

    ;Name and file 
    Name "App" 
    OutFile "AppName ${Version}.exe" 

    ;Default installation folder 
    InstallDir "C:\appFolder" 

    ;Request application privileges for Windows Vista + 
    RequestExecutionLevel admin 

;-------------------------------- 
;Interface Settings 
;-------------------------------- 

    !define MUI_ABORTWARNING 
    Var Dialog 
    Var SQLServer 
    Var SQLUsername 
    Var SQLPassword 
    Var SDatabase 
    Var CoreDatabase 
    Var UIDatabase 

    ShowInstDetails "show" 

;-------------------------------- 
;Pages 
;-------------------------------- 

    !insertmacro MUI_PAGE_WELCOME 
    !insertmacro MUI_PAGE_LICENSE "LIC.rtf" 
    !insertmacro MUI_PAGE_COMPONENTS 
    Page Custom SQLConnectionDetails SQLConnectionDetailsPageLeave 
    Page Custom DatabaseDetails DatabaseDetailsLeave 
    !insertmacro MUI_PAGE_DIRECTORY 
    !insertmacro MUI_PAGE_INSTFILES 
    !insertmacro MUI_PAGE_FINISH 

;-------------------------------- 
;Page functions 
;-------------------------------- 

Function SQLConnectionDetails 
    !insertmacro MUI_HEADER_TEXT $(SQLServerDetailsTitle) $(SQLServerDetailsSubTitle) 
    nsDialogs::Create 1018 
    pop $Dialog 
    ${If} $Dialog == error 
     Abort 
    ${EndIf} 

    ;x, y, width, height and text 
    ${NSD_CreateLabel} 0 0 100% 10u "Enter the name of the SQL server that AppName is to be installed on" 
    pop $1 
    ${NSD_CreateText} 0 10u 150u 12u "" 
    pop $SQLServer 

    ${NSD_CreateLabel} 0 25u 100% 10u "Enter the database name" 
    pop $2 
    ${NSD_CreateText} 0 35u 100u 12u "" 
    pop $SDatabase 

    ${NSD_CreateLabel} 0 50u 100% 10u "Enter SQL username" 
    pop $3 
    ${NSD_CreateText}} 0 60u 100u 12u "" 
    pop $SQLUsername 

    ${NSD_CreateLabel} 0 75u 100% 10u "Enter SQL password" 
    pop $4 
    ${NSD_CreatePassword} 0 85u 100u 12u "" 
    pop $SQLPassword 

    nsDialogs::Show 
FunctionEnd 

Function SQLConnectionDetailsPageLeave 
    ${NSD_GetText} $SQLServer $SQLServer 
    ${NSD_GetText} $SQLUsername $SQLUsername 
    ${NSD_GetText} $SQLPassword $SQLPassword 
    ${NSD_GetText} $SDatabase $SDatabase 
    messagebox MB_OK "We will now attempt to connect to the database server." 
    MSSQL_OLEDB::SQL_Logon "$SQLServer" "$SQLUsername" "$SQLPassword" 
    pop $0 

    ${If} $0 = 0 
     ;messagebox MB_OK "Connection sucessful" 
    ${Else} 
     messagebox MB_OK "I encountered an issue whilst trying to connect to the database. Please check your details and try again." 
     abort 
    ${EndIf} 

    MSSQL_OLEDB::SQL_Logout 
FunctionEnd 

Function DatabaseDetails 
    !insertmacro MUI_HEADER_TEXT $(DatabaseNamesTitle) $(DatabaseNamesSubTitle) 
    nsDialogs::Create 1018 
    pop $Dialog 
    ${If} $Dialog == error 
     Abort 
    ${EndIf} 

    ;x, y, width, height and text 
    ${NSD_CreateLabel} 0 0 100% 10u "Enter the name to be given to the Core database" 
    pop $1 
    ${NSD_CreateText} 0 10u 150u 12u "" 
    pop $CoreDatabase 

    ${NSD_CreateLabel} 0 25u 100% 10u "Enter the name to be given to the UI database" 
    pop $2 
    ${NSD_CreateText} 0 35u 100u 12u "" 
    pop $UIDatabase 

    nsDialogs::Show 
FunctionEnd 

Function DatabaseDetailsLeave 
${NSD_GetText} $CoreDatabase $CoreDatabase 
${NSD_GetText} $UIDatabase $UIDatabase 
FunctionEnd 

;-------------------------------- 
;Languages 
;-------------------------------- 

    !insertmacro MUI_LANGUAGE "English" 

;-------------------------------- 
;Installer Sections 
;-------------------------------- 
InstType "New Install" 
InstType "New Install - Full" 
InstType "Upgrade" 

;------------ 
;New Install 
;------------ 

SectionGroup /e "!Install" SecGroupNewInstall 
    Section "Main App" SecMain 

    SectionEnd 

    Section /o "App1" SecApp1 

    SectionEnd 

    Section /o "App2" SecApp2 

    SectionEnd 

    Section /o "App3" SecApp3 

    SectionEnd 

    Section /o "App4" SecApp4 

    SectionEnd 

    SectionGroup /e "Optional" SubSecGroupNewInstall 
     Section /o "App5" SecApp5 

     SectionEnd 

     Section /o "App6" SecApp6 

     SectionEnd 

     Section /o "App7" SecApp7 

     SectionEnd 
    SectionGroupEnd 
SectionGroupEnd 

SectionGroup /e "!Upgrade" SecGroupUpgrade 
    Section /o "Upgrade Main App" SecMainUpgrade   
    SectionEnd 
SectionGroupEnd 

;-------------------------------- 
;onInit 
;-------------------------------- 

Function .onInit 
    InitPluginsDir 
    StrCpy $1 ${SecMain} 

FunctionEnd 

;-------------------------------- 
;onSelChange 
;-------------------------------- 

Function .onSelChange 

    !insertmacro StartRadioButtons $1 
     !insertmacro RadioButton ${SecMain} 
     !insertmacro RadioButton ${SecMainUpgrade} 
    !insertmacro EndRadioButtons 

    !insertmacro SectionFlagIsSet ${SecMain} ${SF_SELECTED} InstisSel InstnotSel 
     InstnotSel: 
      !insertmacro UnselectSection ${SecGroupNewInstall} 
     InstisSel: 

    !insertmacro SectionFlagIsSet ${SecMainUpgrade} ${SF_SELECTED} UpgisSel UpgnotSel 
     UpgnotSel: 
    !insertmacro UnselectSection ${SecGroupUpgrade} 
     UpgisSel: 

FunctionEnd