Reputation: 7676
Here is my latest NSIS installation script, which has grown into quite a beast.
My question is, how can I put all of the sections for HW_DATA_DIR
, HW_WORKSPACE_DIR
, and possibly %HEADWAVE_ROOT_DIR%
into a single page? I am guessing that I would have to use nsDialog somehow. My supervisor wants me to do this because there are so many separate install pages where you have to keep clicking and clicking too many times to complete the installation.
I have tried the following, but adding an nsDialog
as Page custom HeadwaveConfiguration
does in a function does not seem to fit well within the program flow. Here are my code modifications:
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
But the problem is that it the HeadwaveConfiguration nsDialog
page gets calls to obtain HW_DATA_DIR
and HW_WORKSPACE_DIR
, but then it just jumps to start installing MyApp
instead of first installing the Headwave components and then moving on to install MyApp
Does anyone have any suggestions? TIA.
UPDATE:
Here is how I have updated the code, but it still does not install the Headwave components before it jumps to the MyApp install page:
!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
I would have thought since HeadwaveConfigurationPre should be called first so that $HW_DATA_DIR
should be C:\HW-Data
but instead one of the messageboxes I added shows this:
Headwave Plugin #2: HW_DATA_DIR = 6494062
UPDATE 2:
Thanks for the feedback, @Anders.
Here is my latest code, where initially it is getting the values for $HwDataDir
and $HwWorkspaceDir
:
https://pastebin.com/VsT0MJf1 NOTE: I previously pasted only partial code in https://pastebin.com/DJTLQ05D
Here is a dialog box that shows the values are being obtained initially:
Next it gets to the plugin installation page:
But then eventually, it gets to this line of code:
MessageBox MB_OK 'Headwave Plugin #2: HwDataDir = $HwDataDir'
In which case the $HwDataDir
has a number again:
Could you please tell me, how could that happen? Why would the value change from C:\HW-Data
to 1181026? TIA.
Upvotes: 0
Views: 414
Reputation: 101569
You cannot use MUI_PAGE_CUSTOMFUNCTION_* with nsDialogs. In your last update $HwDataDir contains a number because it is the handle to the text control, not its text. Even if you asked for its text it would be the wrong time, you should do that in the leave callback. Custom pages only have create and leave callbacks, not pre and show!
Here is part of the example code from the nsDialogs documentation:
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
Your code contains other issues like
Section "MyPartnerApp Plugin" SEC1
${If} ${SectionIsSelected} ${SEC1}
which makes no sense, you can't check itself like that. The IsPROG0HwDataSelected function is so broken you should rewrite it from scratch with ${If} and a proper section index.
Update 2:
In your new code, StrCpy $HwDataDir $headwaveConfigDataDirText
is where it gets "corrupted" with the handle. You don't need StrCpy, all you need in the leave function is ${NSD_GetText} $headwaveConfigDataDirText $HwDataDir
.
Upvotes: 2