MrMR
4th January 2011 11:49 UTC
nsDialog page re-use
Hi,
I am wondering the best way to achieve this...
I have to collect data from the installer multiple times based on a user input integer.
As far as I am aware I can't add pages in dynamically I have to add a bunch in and then skip them (please correct me if I am wrong :) )
I know I can add the same page multiple times by simply calling
Page custom pageName
multiple times. The problem arises when I need to collect the data from the page to process it on installation. Is there a simple way to customise the variable names to make them unique without defining the pages multiple times?
All help appreciated!
Cheers
T.Slappy
4th January 2011 15:10 UTC
I am not sure whether you mean this, but you can have a try:
You can define a symbol with some "prefix" or string in it like here:
!define MUI_${MUI_PAGE_UNINSTALLER_PREFIX}WELCOMEFINISHPAGE_GUINIT
where
!define MUI_PAGE_UNINSTALLER_PREFIX "UN"
So you can call functions like this:
Function ${MUI_PAGE_UNINSTALLER_FUNCPREFIX}mui.FinishPage.GUIInit
!ifdef MUI_${MUI_PAGE_UNINSTALLER_PREFIX}PAGE_FUNCTION_GUIINIT
Call "${MUI_${MUI_PAGE_UNINSTALLER_PREFIX}PAGE_FUNCTION_GUIINIT}"
!endif
Hope it helps...
I found this in MUI2.nsh related files, maybe you could check them.
blh83
4th January 2011 16:31 UTC
As you probably know, Variables in NSIS are global no matter where they are declared (top of file, function, or section. See: http://nsis.sourceforge.net/Docs/Chapter4.html#4.2). If you declare them in a function, you have to place /GLOBAL in front of it to indicate this. When you declare a custom page to use:
page custom MyPage MyPageLeave ;where MyPage is the function to define the page and MyPageLeave is called when the page is left.
Then you would have two fxns somewhere in your nsi file:
Function MyPage
Var /GLOBAL someVar
;some code to define and display your page
FunctionEnd
Function MyPageLeave
;maybe manipulate the user provided integer here.
FunctionEnd
It is possible that if you manipulate the user provided integer right away, you could do so in the MyPageLeave function and only ever need one variable for this integer. However, if you obtain a series of integers before you do anything with them, then you likely need to create separate variables for however many instances you will need. So if you will display the page five times and require five inputs, declare five variables (kind of ugly, I know and someone may have a better suggestion). Also, I suggest you consider using an array for this if it fits what you are trying to do because it could be cleaner. Hope this helps.
MrMR
5th January 2011 09:39 UTC
Thank you.
I have located the Array plugin (NSISArray) which is working well.
I have created a function for each page and another for the page leave. Inside the functions I am calling a macro with a unique id from the calling page (function). All the UI widgets for the common pages are created in the macro (which makes the code cleaner) and the unique id is used to index the data in the array.
I am also using the integer passed in from the user to let the page decide if it should show its self (Abort) or not which makes the pages (appear to) show dynamically.