【问题标题】:NSIS nsDialog has disabled back/next/cancel buttons?NSIS nsDialog 已禁用后退/下一步/取消按钮?
【发布时间】:2013-12-20 17:51:55
【问题描述】:

我关注NSIS nsDialog tutorial 的目标是收集一些用户输入,以便稍后写入配置文件。 NSISEclipse 插件生成了一个 MUI2 模板,它让我开始并成功安装了文件。

我使用 nsDialog 教程生成了一个对话框,该对话框确实会在我想要的位置发出,但由于某种原因,“后退/下一个/取消”按钮都是灰色的。我在 nsDialog 文档中看不到启用/禁用这些按钮的位置。

这是我的代码:

Var Dialog
Var Label
Var MyTextBox
Section configLocationDialog
   nsDialogs::Create 1018
   Pop $Dialog
   ${If} $Dialog == error
       Abort
   ${EndIf}

   ${NSD_CreateLabel} 0 0 100% 12u "Hello, welcome to nsDialogs!"
   Pop $Label

   ${NSD_CreateText} 10% 20u 80% 12u "Hello World"
   Pop $MyTextbox

   nsDialogs::Show
SectionEnd

而且,对话框一旦显示:

我需要更改什么来告诉 NSIS 允许返回/下一步/取消?

EDIT 要求提供更多代码。这就是它现在存在的全部内容。

# Auto-generated by EclipseNSIS Script Wizard
# Dec 19, 2013 3:48:34 PM
Name SecureKeypad

# General Symbol Definitions
!define REGKEY "SOFTWARE\$(^Name)"
!define VERSION 1.0.0
!define COMPANY **COMPANY**
!define URL http://www.**COMPANY**.com

# MultiUser Symbol Definitions
!define MULTIUSER_EXECUTIONLEVEL Standard
!define MULTIUSER_INSTALLMODE_COMMANDLINE
!define MULTIUSER_INSTALLMODE_INSTDIR $PROGRAMFILES\SecureKeypad
!define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_KEY "${REGKEY}"
!define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUE "Path"

# MUI Symbol Definitions
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install-colorful.ico"
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_STARTMENUPAGE_REGISTRY_ROOT HKLM
!define MUI_STARTMENUPAGE_NODISABLE
!define MUI_STARTMENUPAGE_REGISTRY_KEY ${REGKEY}
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME StartMenuGroup
!define MUI_STARTMENUPAGE_DEFAULTFOLDER SecureKeypad
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall-colorful.ico"
!define MUI_UNFINISHPAGE_NOAUTOCLOSE

# Included files
#!include MultiUser.nsh
!include LogicLib.nsh
!include nsDialogs.nsh
!include AdvReplaceInFile.nsh
!include Sections.nsh
!include MUI2.nsh

# Variables
Var StartMenuGroup

# Installer pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_STARTMENU Application $StartMenuGroup
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

# Installer languages
!insertmacro MUI_LANGUAGE English

# Installer attributes
OutFile setup.exe
CRCCheck on
InstallDir $PROGRAMFILES\${COMPANY}\SecureKeypad
XPStyle on
ShowInstDetails show
VIProductVersion 1.0.0.0
VIAddVersionKey ProductName SecureKeypad
VIAddVersionKey ProductVersion "${VERSION}"
VIAddVersionKey CompanyName "${COMPANY}"
VIAddVersionKey CompanyWebsite "${URL}"
VIAddVersionKey FileVersion "${VERSION}"
VIAddVersionKey FileDescription ""
VIAddVersionKey LegalCopyright ""
InstallDirRegKey HKLM "${REGKEY}" Path
ShowUninstDetails show

# Input dialogs
Var Dialog
Var Label
Var MyTextbox
#Page custom configLocationDialog configLocationDialogLeave
#Page custom doConfiguration
Section configLocationDialog
    nsDialogs::Create 1018
    Pop $Dialog
    ${If} $Dialog == error
        Abort
    ${EndIf}

    GetFunctionAddress $0 "configLocationDialogLeave"
    nsDialogs::OnBack $Dialog $0
    #nsDialogs::OnNext $Dialog

    ${NSD_CreateLabel} 0 0 100% 12u "Hello, welcome to nsDialogs!"
    Pop $Label

    ${NSD_CreateText} 10% 20u 80% 12u "Hello World"
    Pop $MyTextbox

    nsDialogs::Show
SectionEnd

Function configLocationDialogLeave
    ${NSD_GetText} $MyTextbox $0
    MessageBox mb_ok $0
FunctionEnd

# Installer sections
Section -Main SEC0000
    SetOutPath $INSTDIR
    SetOverwrite on
    File installable-content\CYBSSecurity.dll
    File installable-content\SecureKeypad.exe
    File installable-content\SecureKeypad.exe.config
    File installable-content\SecureKeypad.config
    File installable-content\SecureKeypad.frmSecureKeypad.resources
    WriteRegStr HKLM "${REGKEY}\Components" Main 1

    !insertmacro AdvReplaceInFile $INSTDIR\SecureKeypad.exe.config "@@configFile@@" $INSTDIR
SectionEnd

Section -post SEC0001
    WriteRegStr HKLM "${REGKEY}" Path $INSTDIR
    SetOutPath $INSTDIR
    WriteUninstaller $INSTDIR\uninstall.exe
    !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
    SetOutPath $SMPROGRAMS\$StartMenuGroup
    CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk" $INSTDIR\uninstall.exe
    !insertmacro MUI_STARTMENU_WRITE_END
    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayName "$(^Name)"
    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayVersion "${VERSION}"
    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" Publisher "${COMPANY}"
    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" URLInfoAbout "${URL}"
    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayIcon $INSTDIR\uninstall.exe
    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" UninstallString $INSTDIR\uninstall.exe
    WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoModify 1
    WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1
SectionEnd

# Macro for selecting uninstaller sections
!macro SELECT_UNSECTION SECTION_NAME UNSECTION_ID
    Push $R0
    ReadRegStr $R0 HKLM "${REGKEY}\Components" "${SECTION_NAME}"
    StrCmp $R0 1 0 next${UNSECTION_ID}
    !insertmacro SelectSection "${UNSECTION_ID}"
    GoTo done${UNSECTION_ID}
next${UNSECTION_ID}:
    !insertmacro UnselectSection "${UNSECTION_ID}"
done${UNSECTION_ID}:
    Pop $R0
!macroend

# Uninstaller sections
Section /o -un.Main UNSEC0000
    Delete /REBOOTOK $INSTDIR\SecureKeypad.frmSecureKeypad.resources
    Delete /REBOOTOK $INSTDIR\SecureKeypad.exe.config
    Delete /REBOOTOK $INSTDIR\SecureKeypad.exe
    Delete /REBOOTOK $INSTDIR\<sensored>.dll
    DeleteRegValue HKLM "${REGKEY}\Components" Main
SectionEnd

Section -un.post UNSEC0001
    DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
    Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk"
    Delete /REBOOTOK $INSTDIR\uninstall.exe
    DeleteRegValue HKLM "${REGKEY}" StartMenuGroup
    DeleteRegValue HKLM "${REGKEY}" Path
    DeleteRegKey /IfEmpty HKLM "${REGKEY}\Components"
    DeleteRegKey /IfEmpty HKLM "${REGKEY}"
    RmDir /REBOOTOK $SMPROGRAMS\$StartMenuGroup
    RmDir /REBOOTOK $INSTDIR
SectionEnd

# Installer functions
Function .onInit
    InitPluginsDir
FunctionEnd

# Uninstaller functions
Function un.onInit
    !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuGroup
    !insertmacro SELECT_UNSECTION Main ${UNSEC0000}
FunctionEnd

【问题讨论】:

  • 请显示更多您的代码。例如,您是否声明了自定义页面?
  • 我尝试了自定义页面,但结果相同。这是使用Section 的第二次迭代。自定义页面在安装文件后运行,这不是我所希望的。

标签: nsis nsdialogs


【解决方案1】:

在section中调用nsDialogs::Create/Show是无效的,只能在自定义页面的create回调函数中调用。

instfiles 页面之后某些按钮将被禁用(已安装,无法取消或返回),但这是由 NSIS 本身完成的,而不是 nsDialogs...

【讨论】:

  • 我确实在自定义页面中尝试过此操作(请参阅完整列表中注释掉的 Page custom,其中 Section/SectionEnd 仅替换为 Function/FunctionEnd),但对话框在安装屏幕之后运行,这不是我想要的,后退按钮会使安装程序崩溃。
【解决方案2】:

如果您在某个部分中调用nsDialogs:Create,它将在安装程序安装文件等时运行。在这种状态下,您将无法继续浏览安装程序中的页面,并且您会被卡住。

您对在安装程序结束时运行的自定义页面的通知确实是您应该尝试解决的问题,而不是将其视为错误的方式(这是唯一的方式)。 NSIS 脚本在很多方面都非常简单。例如,页面按照声明的顺序加载。所以当你声明你想要MUI_PAGE_WELCOMEMUI_PAGE_DIRECTORY 和其他人时,你也在设置它们的顺序。

# Installer pages
!insertmacro MUI_PAGE_WELCOME                                 # First page
!insertmacro MUI_PAGE_DIRECTORY                               # Second page
!insertmacro MUI_PAGE_STARTMENU Application $StartMenuGroup   # Third page
!insertmacro MUI_PAGE_INSTFILES                               # Etc
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

因此,如果您随后尝试将所有代码放在一起并将自定义页面与处理它的函数一起添加,那么毫无疑问它将是该顺序中的最后一个页面。

# Installer pages
!insertmacro MUI_PAGE_WELCOME                                 # First page
!insertmacro MUI_PAGE_DIRECTORY                               # Second page
!insertmacro MUI_PAGE_STARTMENU Application $StartMenuGroup   # Third page

...

# Input dialogs
Var Dialog
Var Label
Var MyTextbox
Page custom configLocationDialog configLocationDialogLeave    # Last page
Section configLocationDialog
  nsDialogs::Create 1018
  Pop $Dialog

为了说明这一点,我将您的代码精简为您想要的页面。

    # Included files
!include LogicLib.nsh
!include nsDialogs.nsh
!include Sections.nsh
!include MUI2.nsh

# Installer pages
!insertmacro MUI_PAGE_WELCOME                                 # First page
Page custom configLocationDialog configLocationDialogLeave    # Second page!
!insertmacro MUI_PAGE_FINISH                                  # Last page

# Installer languages
!insertmacro MUI_LANGUAGE English

# Input dialogs
Var Dialog
Var Label
Var MyTextbox

Function configLocationDialog
    nsDialogs::Create 1018
    Pop $Dialog
    ${If} $Dialog == error
    Abort
    ${EndIf}

    GetFunctionAddress $0 "configLocationDialogLeave"
    nsDialogs::OnBack $Dialog $0

    ${NSD_CreateLabel} 0 0 100% 12u "Hello, welcome to nsDialogs!"
    Pop $Label

    ${NSD_CreateText} 10% 20u 80% 12u "Hello World"
    Pop $MyTextbox

    nsDialogs::Show
FunctionEnd

Function configLocationDialogLeave
    ${NSD_GetText} $MyTextbox $0
    MessageBox mb_ok $0
FunctionEnd

Section -Main SEC0000

SectionEnd

【讨论】:

    【解决方案3】:

    NSISEclipse 插件生成大量代码,包括一组执行显示的各种页面的宏:

    # Installer pages
    !insertmacro MUI_PAGE_WELCOME
    !insertmacro MUI_PAGE_DIRECTORY
    !insertmacro MUI_PAGE_STARTMENU Application $StartMenuGroup
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_PAGE_FINISH
    !insertmacro MUI_UNPAGE_CONFIRM
    !insertmacro MUI_UNPAGE_INSTFILES
    

    诀窍是在正确的步骤注入页面调用。

    # Installer pages
    !insertmacro MUI_PAGE_WELCOME
    !insertmacro MUI_PAGE_DIRECTORY
    !insertmacro MUI_PAGE_STARTMENU Application $StartMenuGroup
    Page custom configLocationDialog configLocationDialogLeave
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_PAGE_FINISH
    !insertmacro MUI_UNPAGE_CONFIRM
    !insertmacro MUI_UNPAGE_INSTFILES
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-09
      • 1970-01-01
      相关资源
      最近更新 更多