首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RelGotoPage函数转到下一页,而不是返回

问RelGotoPage函数转到下一页,而不是返回
EN

Stack Overflow用户
提问于 2021-01-27 00:40:27
回答 1查看 33关注 0票数 0

我当前在安装程序中定义的页面顺序是:

代码语言:javascript
复制
!insertmacro MUI_PAGE_WELCOME                             ; Welcome page
!insertmacro MUI_PAGE_DIRECTORY                           ; Select a directory
!define MUI_PAGE_CUSTOMFUNCTION_PRE CheckInstallDirectory ; Check selected directory
!insertmacro MUI_PAGE_COMPONENTS                          ; Choose install components
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipLicense           ; Component1's check before license page
!insertmacro MUI_PAGE_LICENSE "license.txt"               ; Component1's license
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipLicenseForComp2   ; Component2's check before license page
!insertmacro MUI_PAGE_LICENSE "License2.txt"              ; Component2's license
!insertmacro CUSTOM_PAGES                                 ; Custom install pages
!insertmacro MUI_PAGE_INSTFILES                           ; Install components' files
!insertmacro MUI_PAGE_FINISH                              ; Finish page

在下面定义的CheckInstallDirectory函数中,它检查最终用户是否选择了已经包含.exe的目录,否则该目录将由安装程序安装。

如果该目录存在,则会向用户显示一个带有"OK“和"CANCEL”按钮的弹出消息框。"OK“选择应该简单地跳过接下来的几页并转到MUI_PAGE_INSTFILES页面。"CANCEL“选择应使用户返回到MUI_PAGE_DIRECTORY页面。

代码语言:javascript
复制
Function CheckInstallDirectory

  IfFileExists "$INSTDIR\Component1.exe" file_found end_of_check
  file_found:
  Var /GLOBAL ver_
  ${GetFileVersion} "$INSTDIR\Component1.exe" $ver_
  StrCpy $0 $ver_ 1 ; Determine the major version of the installed exe (1st char of the returned string)
  StrCpy $1 $ver_1 1 ; Determine the major version of the exe we are installing (1st char of the returned string)
  ${If} $0 == $1
    ; The major version between .exe's is the same
    MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "A copy of this software is already installed in the selected directory.$\nSelect $\"OK$\" if you would like to update the software to the latest version.$\nOtherwise select $\"Cancel$\" to go back and select a different installation directory." IDOK OK IDCANCEL CANCEL
    OK:
      ; User selected to update this software - continue with the installation like normal
      StrCpy $R9 "7" ; Skip to the installation page
      Call RelGotoPage
      goto end_of_check
    CANCEL:
      StrCpy $R9 "-1" ; Go back to directory selection page
      Call RelGotoPage
      goto end_of_check
  ${Else}
    ; The major version between the .exe's is NOT the same - cannot update
    MessageBox MB_OK "A copy of this software is already installed in the selected directory.$\nIt is not part of the latest major-version group and cannot be updated. To update this installation, uninstall and use the installer to install the latest version.$\nOtherwise, select$\"OK$\" to go back and select a different installation directory."
    StrCpy $R9 "-1" ; Go back to directory selection page
    Call RelGotoPage
    goto end_of_check
  ${EndIf}
  end_of_check:

FunctionEnd

我找到了NSIS关于如何在安装程序页面here之间移动的描述。

代码语言:javascript
复制
Function RelGotoPage
  IntCmp $R9 0 0 Move Move
    StrCmp $R9 "X" 0 Move
      StrCpy $R9 "120"

  Move:
  SendMessage $HWNDPARENT "0x408" "$R9" ""
FunctionEnd

出现的问题是StrCpy $R9 "7"确实成功地跳到了MUI_PAGE_INSTFILES页面。但是,StrCpy $R9 "-1"不会返回到上一页(应该是MUI_PAGE_DIRECTORY)。相反,如果在弹出消息中选择了"CANCEL“,安装程序将转到下一页MUI_PAGE_COMPONENTS。

这里有什么不正确的地方?有没有更好的方法来达到预期的结果?

任何帮助都是真诚的感谢!谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-27 02:35:21

在页面预回调中,页面没有完全加载,我认为这就是-1不能正常工作的原因。如果使用-1 \f25 MUI_PAGE_CUSTOMFUNCTION_SHOW -1\f6,则工作正常,但正确的方法是阻止页面更改:

代码语言:javascript
复制
!include MUI2.nsh
!insertmacro MUI_PAGE_WELCOME                             ; Welcome page
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE CheckInstallDirectory
!insertmacro MUI_PAGE_DIRECTORY
...

Function CheckInstallDirectory
;Snipped
    MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "A copy of this software is already installed in the selected directory.$\nSelect $\"OK$\" if you would like to update the software to the latest version.$\nOtherwise select $\"Cancel$\" to go back and select a different installation directory." IDOK OK IDCANCEL CANCEL
    OK:
      ; User selected to update this software - continue with the installation like normal
      StrCpy $R9 "7" ; Skip to the installation page
      Call RelGotoPage
      goto end_of_check
    CANCEL:
      Abort
;Snipped
  end_of_check:
FunctionEnd
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65905423

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档