2016-04-06 59 views
1

我不是NSIS的專業人士,但我得到了!我正在爲我們正在構建的新軟件設置一個新的安裝程序,我已經爲安裝程序配置了2個潛在路徑,即安裝或升級。NSIS選擇選項奇數行爲

這個想法是,當用戶選擇任何升級選項時,可以選擇安裝的所有選項都被取消選擇,反之亦然。

目前發生的情況是,當用戶例如選擇安裝路徑下的一個選項時,該路徑的所有選項都被選中,並且不可取消選擇,除非在升級路徑下選擇一個選項,之後有趣的是,選擇的選擇似乎表現得像想要的那樣?

這是我的代碼,我在這裏丟失了什麼明顯的東西?

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

回答

1

我已經回答了我自己的問題! 這個問題涉及到時間和我的onInit函數的問題。我已將我的onInit函數移動到我的部分組下方,並更正了StrCpy以包含正確的部分參考,請參閱下面的更正代碼:

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