3

我正在使用通过电子生成器构建的电子应用程序。当我生成安装程序并开始使用它进行安装时,我看到取消按钮被禁用。

我查看了一些电子生成器文档并进行了一些谷歌搜索,但我似乎在这里空白。

编辑:发现我可以使用 build/installer.nsh 来实际修改 UI 元素,现在我只是想知道,如何访问按钮来启用/禁用它,我看到的示例使用 .ini 文件存储选项或类似的东西,但我得到了使用 nsDialogs 的建议。

nsDialogs 是我已经可以轻松访问的东西,还是我需要将某些东西导入到我的 installer.nsh 文件中才能使用 nsDialogs?

通过这个令牌,我将如何访问 nsDialogs 中的取消按钮?

是否有一个可配置的值使我能够...启用该取消按钮,以便用户可以在安装期间选择取消?

谢谢!

4

1 回答 1

2

NSIS 安装程序不支持在您进入 InstFiles 页面(或之后的任何页面)时取消安装。这是设计使然,因为脚本语言是如何工作的。

如果您不介意黑客攻击,您可以在安装阶段用户单击取消时调用卸载程序:

Var Cancel
!include LogicLib.nsh
!include WinMessages.nsh

Function .onUserAbort
    StrCmp $Cancel "" +3
        IntOp $Cancel $Cancel | 1
        Abort
FunctionEnd

!macro FakeWork c
!if "${c}" < 10
Sleep 333
DetailPrint .
!define /redef /math c "${c}" + 1
!insertmacro ${__MACRO__} "${c}"
!endif
!macroend

Section Uninstall
!insertmacro FakeWork 0
Delete "$InstDir\Uninst.exe"
RMDir "$InstDir"
SectionEnd

Function CheckCancel
${If} $Cancel = 1
    IntOp $Cancel $Cancel + 1
    GetDlgItem $0 $hwndParent 2
    EnableWindow $0 0
    DetailPrint "Canceling..."
    SetDetailsPrint none
    ExecWait '"$InstDir\Uninst.exe" /S _?=$InstDir'
    Delete "$InstDir\Uninst.exe"
    RMDir "$InstDir"
    SetDetailsPrint both
    Quit
${EndIf}
FunctionEnd


Section
SetOutPath $InstDir
WriteUninstaller "$InstDir\Uninst.exe"
StrCpy $Cancel 0 ; Allow special cancel mode
GetDlgItem $0 $hwndParent 2
EnableWindow $0 1 ; Enable cancel button

!insertmacro FakeWork 0 ; Replace these with File or other instructions
Call CheckCancel
!insertmacro FakeWork 0
Call CheckCancel
!insertmacro FakeWork 0
Call CheckCancel

StrCpy $Cancel "" ; We are done, ignore special cancel mode
SectionEnd

(我不知道如何将它与电子生成器集成,抱歉)

如果您想要正确的回滚安装程序,请尝试Inno SetupWiX (MSI)。

于 2021-11-30T00:39:13.370 回答