gpt4 book ai didi

nsis - 在函数中设置 InstallDir 的值,或者以某种方式设置自动填充值?

转载 作者:行者123 更新时间:2023-12-04 17:56:02 26 4
gpt4 key购买 nike

我正在使用 NSIS 创建安装程序。该安装程序实际上是在同一个安装程序的两个不同目录中安装两个程序。我正在使用现代用户界面 (MUI) 页面执行此操作,并简单地调用 MUI_PAGE_DIRECTORY 两次以指定不同的起始参数,并在 LEAVE 宏中捕获目录。我想知道的是,我能否以某种方式在函数中调用 InstallDir,或者在函数中设置自动目录填充值?或者甚至可能在返回浏览按钮后调用一个函数?

我想要这样做的原因是当用户单击两个目录页面中的任何一个中的浏览按钮时,在他们选择一个目录后,将附加在 InstallDir 中指定的最终目录的名称。

例如:
程序 1 的 InstallDir 值:c:\client
程序 2 的 InstallDir 值:c:\program files\server

用户单击浏览程序 1 并选择 c:\temp,结果路径为 c:\temp\client

用户单击浏览程序 2 并选择 c:\whatever 生成的路径是 c:\whatever\server

作为引用,这里是我所拥有的代码片段,但不处理自动附加浏览按钮行为:

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ClientDirectoryLeave
!insertmacro MUI_PAGE_DIRECTORY

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ServerDirectoryLeave
!insertmacro MUI_PAGE_DIRECTORY

; Setup the page display for the client install page
Function ShowPageClient
!insertmacro MUI_HEADER_TEXT "Client" "Client"
!insertmacro MUI_INNERDIALOG_TEXT 1006 "Client"

; setup intal directory
Push $0
StrCpy $0 $PROGRAMFILES 2 #
; CLIENT_FOLDER_NAME is defined as a folder, but this would basicaly
; result in C:\Client as the first 2 characters of $PROGRAMFILES
; is the hard drive with program files installed on it
StrCpy $INSTDIR "$0\${CLIENT_FOLDER_NAME}"
Pop $0

; set the inital value of the directory text box
!insertmacro MUI_INNERDIALOG_TEXT 1019 $INSTDIR

; find and disable the directory selection box
; We do not want users to type in this box
FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $R1 $R0 1019 ;Text Box
EnableWindow $R1 0
FunctionEnd


; Setup the page display for the server install location page
Function ShowPageServer
!insertmacro MUI_HEADER_TEXT "Server" "Server"
!insertmacro MUI_INNERDIALOG_TEXT 1006 "Server"

; setup intal directory
; SERVER_FOLDER_NAME is defined as a folder, but this would basicaly
; result in C:\Program Files\Server
StrCpy $INSTDIR "$PROGRAMFILES\${SERVER_FOLDER_NAME}"

; set the inital value of the directory text box
!insertmacro MUI_INNERDIALOG_TEXT 1019 $INSTDIR

; find and disable the directory selection box
; We do not want users to type in this box
FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $R1 $R0 1019 ;Text Box
EnableWindow $R1 0

FunctionEnd

注意:我可以使浏览按钮对目录页面之一起作用,但是当我在第二页上时,自动填充实际自动填充不正确

最佳答案

附加的文件夹名称是常量并在编译时设置,有一个 bug report与此有关。

我的建议是放弃附加功能,让用户完全控制两个目的地:

Name "NSIS Test"
InstallDir ""
!include MUI.nsh
Var DirClient
Var DirServer

Function .onInit
;Set default destinations
StrCpy $DirClient "$ProgramFiles\$(^Name)\Client"
StrCpy $DirServer "$ProgramFiles\$(^Name)\Server"
FunctionEnd

!macro ConfigureMyDirPage type var
!define MUI_DIRECTORYPAGE_VARIABLE ${var}
!define MUI_PAGE_HEADER_SUBTEXT "Choose the folder in which to install $(^NameDA) ${type}"
!define MUI_DIRECTORYPAGE_TEXT_TOP "Setup will install $(^NameDA) ${type} in the following folder. To install in a different folder, click Browse and select another folder. $_CLICK"
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION "${type} $(^DirSubText)"
!macroend

!insertmacro ConfigureMyDirPage "Client" $DirClient
!insertmacro MUI_PAGE_DIRECTORY

!insertmacro ConfigureMyDirPage "Server" $DirServer
!insertmacro MUI_PAGE_DIRECTORY

!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_LANGUAGE "English"

Section
DetailPrint DirClient=$DirClient
DetailPrint DirServer=$DirServer
SectionEnd

关于nsis - 在函数中设置 InstallDir 的值,或者以某种方式设置自动填充值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8706332/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com