NSIS选择了奇怪的选择行为

时间:2016-04-06 14:53:36

标签: nsis

我不是NSIS专业人士,但我顺便过去了!我正在为我们正在构建的新软件设置一个新的安装程序,我已经为安装程序配置了2个可能的路径,安装或升级。

这个想法是,当用户选择任何升级选项时,可以取消选择可以选择安装的所有选项,反之亦然。

目前我发生的事情是,例如,当用户在安装路径下选择一个选项时,该路径的所有选项都被选中,除非您在升级路径下选择一个选项,否则不能取消选择该选项,之后有趣的是,选择的选项似乎表现得像想要的那样?

这是我的代码,我在这里找不到什么明显的东西?

;--------------------------------
;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 个答案:

答案 0 :(得分: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