[英]Why does my NSIS script appear to be skipping over installation pages like MUI_PAGE_INSTFILES when I add custom nsDialog pages?
這是我最新的 NSIS 安裝腳本,它已經成長為一個野獸。
我的問題是,如何將HW_DATA_DIR
、 HW_WORKSPACE_DIR
以及可能的%HEADWAVE_ROOT_DIR%
的所有部分放入一個頁面中? 我猜我必須以某種方式使用nsDialog 。 我的主管希望我這樣做,因為有很多單獨的安裝頁面,您必須在其中不斷單擊並單擊太多次才能完成安裝。
我嘗試了以下方法,但是在 function 中添加nsDialog
為Page custom HeadwaveConfiguration
似乎不太適合程序流程。 這是我的代碼修改:
Var headwaveConfigDialog
Var headwaveConfigDataDirLabel
Var headwaveConfigDataDirText
Var headwaveConfigWkDirLabel
Var headwaveConfigWkDirText
!define MUI_PAGE_CUSTOMFUNCTION_PRE SelectFilesCheck
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ComponentsLeave
!insertmacro MUI_PAGE_COMPONENTS
## This is the title on the Headwave Data Directory page
;!define MUI_DIRECTORYPAGE_TEXT_TOP "$(MUI_DIRECTORYPAGE_TEXT_TOP_HW)"
;!define MUI_PAGE_HEADER_TEXT "Headwave configuration"
; !define MUI_PAGE_HEADER_SUBTEXT "Select the folder which Headwave can use as a data storage."
Page custom HeadwaveConfiguration
; ; HW Data
; !define MUI_PAGE_CUSTOMFUNCTION_PRE hw_data_pre
; !define MUI_PAGE_CUSTOMFUNCTION_SHOW hw_data_dir
; !define MUI_DIRECTORYPAGE_VARIABLE $HW_DATA_DIR
; !insertmacro MUI_PAGE_DIRECTORY
; ## This is the title on the Headwave Workspace Directory page
; !define MUI_DIRECTORYPAGE_TEXT_TOP "$(MUI_DIRECTORYPAGE_TEXT_TOP_HW_WK)"
; !define MUI_PAGE_HEADER_TEXT "Choose Headwave Workspace directory"
; !define MUI_PAGE_HEADER_SUBTEXT "Select the folder which Headwave can use as a workspace."
; # HW Workspaces
; !define MUI_PAGE_CUSTOMFUNCTION_PRE hw_wk_pre
; !define MUI_PAGE_CUSTOMFUNCTION_SHOW hw_wk_dir
; !define MUI_DIRECTORYPAGE_VARIABLE $HW_WORKSPACE_DIR
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
## This is the title on the Headwave installation Directory page to obtain directory for %HEADWAVE_ROOT_DIR
!define MUI_DIRECTORYPAGE_TEXT_TOP "$(MUI_DIRECTORYPAGE_TEXT_TOP_HW_INST)"
!define MUI_PAGE_HEADER_TEXT "Choose Headwave Plugin installation directory"
!define MUI_PAGE_HEADER_SUBTEXT "Select the folder where Headwave is presently installed to set environment variable."
!define MUI_PAGE_CUSTOMFUNCTION_PRE SelectFilesHeadwaveProg
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
; ...
Function HeadwaveConfiguration
!insertmacro MUI_HEADER_TEXT "Headwave configuration" "Select the respective folders for Headwave."
nsDialogs::Create 1018
Pop $headwaveConfigDialog
${NSD_CreateLabel} 0 0 100% 12u "Select the folder which Headwave can use as a data storage:"
Pop $headwaveConfigDataDirLabel
${NSD_CreateText} 10% 20u 80% 12u "C:\HW-Data"
Pop $headwaveConfigDataDirText
StrCpy $HW_DATA_DIR $headwaveConfigDataDirText
${NSD_CreateLabel} 0 40u 80% 12u "Select the folder which Headwave can use as a workspace:"
Pop $headwaveConfigWkDirLabel
${NSD_CreateText} 10% 60u 80% 12u "C:\HW-Workspaces"
Pop $headwaveConfigWkDirText
StrCpy $HW_WORKSPACE_DIR $headwaveConfigWkDirText
;${NSD_CreateLabel} 0 80u 80% 12u "Select the folder where Headwave is installed:"
;Pop $headwaveConfigProgramDirLabel
;StrCpy $headwaveConfigProgramDirText $HeadwaveInstallDir
;${NSD_CreateText} 10% 100u 80% 12u $HeadwaveInstallDir
;Pop $headwaveConfigProgramDirText
;StrCpy $HeadwaveInstallDir $headwaveConfigProgramDirText
;MessageBox MB_OK 'HeadwaveConfiguration: HeadwaveInstallDir = $HeadwaveInstallDir; headwaveConfigProgramDirText = $headwaveConfigProgramDirText'
SetCtlColors $headwaveConfigHwnd 0xFF0000 0xFFFFFF
nsDialogs::Show
FunctionEnd
但問題是HeadwaveConfiguration nsDialog
頁面被調用以獲取HW_DATA_DIR
和HW_WORKSPACE_DIR
,但隨后它只是跳轉開始安裝MyApp
而不是首先安裝 Headwave 組件然后繼續安裝MyApp
有沒有人有什么建議? TIA。
更新:
這是我更新代碼的方式,但在跳轉到 MyApp 安裝頁面之前它仍然沒有安裝 Headwave 組件:
!define MUI_PAGE_CUSTOMFUNCTION_PRE SelectFilesCheck
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ComponentsLeave
!insertmacro MUI_PAGE_COMPONENTS
## This is the title on the Headwave Data Directory page
!define MUI_DIRECTORYPAGE_TEXT_TOP "$(MUI_DIRECTORYPAGE_TEXT_TOP_HW)"
!define MUI_PAGE_HEADER_TEXT "Headwave configuration"
!define MUI_PAGE_CUSTOMFUNCTION_PRE HeadwaveConfigurationPre
!define MUI_PAGE_CUSTOMFUNCTION_SHOW HeadwaveConfigurationShow
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
## This is the title on the Headwave installation Directory page to obtain directory for %HEADWAVE_ROOT_DIR%
!define MUI_DIRECTORYPAGE_TEXT_TOP "$(MUI_DIRECTORYPAGE_TEXT_TOP_HW_INST)"
!define MUI_PAGE_HEADER_TEXT "Choose Headwave Plugin installation directory"
!define MUI_PAGE_HEADER_SUBTEXT "Select the folder where Headwave is presently installed to set environment variable."
Function HeadwaveConfigurationPre
!insertmacro MUI_HEADER_TEXT "Headwave configuration" "Select the respective folders for Headwave."
nsDialogs::Create 1018
Pop $headwaveConfigDialog
${NSD_CreateLabel} 0 0 100% 12u "Select the folder which Headwave can use as a data storage:"
Pop $headwaveConfigDataDirLabel
${NSD_CreateText} 10% 20u 80% 12u "C:\HW-Data"
Pop $headwaveConfigDataDirText
StrCpy $HwDataDir $headwaveConfigDataDirText
${NSD_CreateLabel} 0 40u 80% 12u "Select the folder which Headwave can use as a workspace:"
Pop $headwaveConfigWkDirLabel
${NSD_CreateText} 10% 60u 80% 12u "C:\HW-Workspaces"
Pop $headwaveConfigWkDirText
StrCpy $HwWorkspaceDir $headwaveConfigWkDirText
;${NSD_CreateLabel} 0 80u 80% 12u "Select the folder where Headwave is installed:"
;Pop $headwaveConfigProgramDirLabel
;StrCpy $headwaveConfigProgramDirText $HeadwaveInstallDir
;${NSD_CreateText} 10% 100u 80% 12u $HeadwaveInstallDir
;Pop $headwaveConfigProgramDirText
;StrCpy $HeadwaveInstallDir $headwaveConfigProgramDirText
SetCtlColors $headwaveConfigHwnd 0xFF0000 0xFFFFFF
nsDialogs::Show
FunctionEnd
Function HeadwaveConfigurationShow
MessageBox MB_OK 'HeadwaveConfiguration: HeadwaveInstallDir = $HeadwaveInstallDir; headwaveConfigProgramDirText = $headwaveConfigProgramDirText'
FunctionEnd
## Section 1
Section "MyPartnerApp Plugin" SEC1
MessageBox MB_OK 'Headwave Plugin #1: INSTDIR = $INSTDIR'
${If} ${SectionIsSelected} ${SEC1}
${StrContains} $0 "MyPartnerApp" "$INSTDIR"
StrCmp $0 "" notfoundMyPartnerApp
Goto doneMyPartnerApp
doneMyPartnerApp:
MessageBox MB_OK 'Headwave Plugin #2: HW_DATA_DIR = $HW_DATA_DIR'
SetOutPath "$HW_DATA_DIR"
${StrContains} $0 "Data" "$HW_DATA_DIR"
StrCmp $0 "" notfoundHwData
Goto doneHwData
;MessageBox MB_OK 'Did not find MyApp string'
doneHwData:
##All the files in Group 0 will be installed to the same location, $HW_DATA_DIR
MessageBox MB_OK 'Headwave Plugin #3: HW_DATA_DIR = $HW_DATA_DIR'
SetOutPath "$HW_DATA_DIR"
CreateDirectory "$HW_DATA_DIR"
CreateDirectory "$HW_DATA_DIR\MyApp-Plugins"
CreateDirectory "$HW_DATA_DIR\MyApp-Plugins\ComputePlugin"
CreateDirectory "$HW_DATA_DIR\MyApp-Plugins\ExtensionPlugin"
File /oname=$HW_DATA_DIR\MyApp-Plugins\ComputePlugin\computeplugin.xplot.dll computeplugin.xplot.dll
File /oname=$HW_DATA_DIR\MyApp-Plugins\ComputePlugin\computeplugin.VirtualVolume.dll computeplugin.VirtualVolume.dll
File /oname=$HW_DATA_DIR\MyApp-Plugins\ExtensionPlugin\hwProxyInterface.MyApp.dll hwProxyInterface.MyApp.dll
# MyPartnerApp workspace
CreateDirectory "$HW_WORKSPACE_DIR"
##All the files in Group 1 will be installed to the same location, $INSTDIR
SetOutPath "$INSTDIR"
;messagebox mb_ok "MyPartnerApp Program: INSTDIR is $INSTDIR"
# set environment variable for current user
WriteRegExpandStr ${env_hkcu} HEADWAVE_ROOT_DIR $INSTDIR
# save the selected headwave program directory
StrCpy $MyPartnerAppSelectedInstallDir $INSTDIR
# make sure windows knows about the change
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
# Install Sound-MyApp python scripts
CreateDirectory $INSTDIR\python\hwtoolkits\MyCompany
File __init__.py
File MyAppConfig.py
File MyAppPlugin.py
CopyFiles $INSTDIR\*.py $INSTDIR\python\hwtoolkits\MyCompany
notfoundHwData:
notfoundMyPartnerApp:
; Do nothing
${Else}
Abort
${EndIf}
SectionEnd
我本來以為應該首先調用 HeadwaveConfigurationPre 以便$HW_DATA_DIR
應該是C:\HW-Data
但我添加的消息框之一顯示了這一點:
Headwave Plugin #2: HW_DATA_DIR = 6494062
更新 2:
感謝您的反饋,@Anders。
這是我最新的代碼,最初它獲取$HwDataDir
和$HwWorkspaceDir
的值:
https://pastebin.com/VsT0MJf1注意:我之前在https://pastebin.com/DJTLQ05D中僅粘貼了部分代碼
這是一個對話框,顯示最初獲取的值:
接下來進入插件安裝頁面:
但最終,它到達了這行代碼:
MessageBox MB_OK 'Headwave Plugin #2: HwDataDir = $HwDataDir'
在這種情況下, $HwDataDir
又有一個數字:
你能告訴我,怎么會這樣? 為什么值會從C:\HW-Data
變為 1181026? TIA。
您不能將 MUI_PAGE_CUSTOMFUNCTION_* 與 nsDialogs 一起使用。 在您上次更新 $HwDataDir 包含一個數字,因為它是文本控件的句柄,而不是它的文本。 即使你要求它的文本也是錯誤的時間,你應該在離開回調中這樣做。 自定義頁面只有 create 和 leave 回調,沒有 pre 和 show!
以下是 nsDialogs 文檔中的示例代碼的一部分:
Page custom nsDialogsPage nsDialogsPageLeave
Page instfiles
Function nsDialogsPage
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateLabel} 0 0 100% 12u "Hello, welcome to nsDialogs!"
Pop $Label
${NSD_CreateText} 0 13u 100% -13u "Type something here..."
Pop $Text
nsDialogs::Show
FunctionEnd
Function nsDialogsPageLeave
${NSD_GetText} $Text $0
MessageBox MB_OK "You typed:$\n$\n$0"
FunctionEnd
您的代碼包含其他問題,例如
Section "MyPartnerApp Plugin" SEC1
${If} ${SectionIsSelected} ${SEC1}
這是沒有意義的,你不能那樣檢查自己。 IsPROG0HwDataSelected function 已損壞,您應該使用 ${If} 和適當的節索引從頭開始重寫它。
更新 2:
在您的新代碼中, StrCpy $HwDataDir $headwaveConfigDataDirText
是句柄“損壞”的地方。 你不需要 StrCpy,你只需要離開 function 就是${NSD_GetText} $headwaveConfigDataDirText $HwDataDir
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.