- NSIS Discussion
- conditional display of MUI_PAGE_DIRECTORY
Archive: conditional display of MUI_PAGE_DIRECTORY
deritrus
23rd November 2004 20:05 UTC
conditional display of MUI_PAGE_DIRECTORY
I'm trying to create an installer (using the Modern UI) that will skip over the MUI_PAGE_DIRECTORY page if the installer detects the software is already installed. The idea is to prevent the same piece of software being installed into two or more different directories. Subsequent reinstallations would overwrite the original without giving the user a chance to alter the installation path.
Here is an outline of the process.
1) The installer is run for the first time. The MUI_PAGE_DIRECTORY appears to let the user (if they wish) to change the default install directory.
2) The software is installed, let's say, to "C:\Program Files\MyApp".
3) The installer writes a string in the registry "InstallLocation" = "C:\Program Files\MyApp".
4) The installer finishes successfully. The software is used and provides much joy to the user. Time passes. The user's toenails grow longer.
5) For whatever reason, the installer is run a second time.
6) The installer looks in the registry for the "InstallLocation" string. If it finds it, the installer uses that as $INSTDIR (by way of InstallDirRegKey) and does not display MUI_PAGE_DIRECTORY.
I can't figure out how to write code to skip past the "!insertmacro MUI_PAGE_DIRECTORY" line. Commands like ReadRegStr and StrCmp can only be placed in sections or functions. And the MUI_PAGE_DIRECTORY macro cannot be inserted in a section or a function because the macro contains the PageEx command.
Any ideas how I can accomplish this? Thanks!
Afrow UK
23rd November 2004 20:43 UTC
!define MUI_PAGE_CUSTOMFUNCTION_SHOW CheckInstDirReg
!insertmacro MUI_PAGE_DIRECTORY
Function CheckInstDirReg
ReadRegStr $R0 HKLM "...Uninstall\MyApp" "InstallLocation"
StrCmp $R0 "" +2
Abort ## InstallLocation present: Skip directory page!
FunctionEnd
-Stu :)
deritrus
23rd November 2004 21:13 UTC
Stu, you're brilliant! I knew it had to be something simple.
One small correction with your code:
!define MUI_PAGE_CUSTOMFUNCTION_PRE CheckInstDirReg
Thanks very much for your help!
deritrus
23rd November 2004 22:27 UTC
As a continuation of my efforts, I want to change the text of the Next button on the Welcome page.
!define MUI_PAGE_CUSTOMFUNCTION_SHOW ChangeButtonText
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipPage
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
Function ChangeButtonText
ReadRegStr $R0 HKLM "${REG_UNINST_KEY}" "InstallLocation"
StrCmp $R0 "" +2
MiscButtonText "" "Install"
FunctionEnd
Function SkipPage
ReadRegStr $R0 HKLM "${REG_UNINST_KEY}" "InstallLocation"
StrCmp $R0 "" +2
Abort
FunctionEnd
I thought something like this would be achieved in a "show" function, but the compiler kindly informs me MiscButtonText cannot be in a function. Also, MiscButtonText isn't the ideal solution (even if I
could get it to work) since it changes all the Next buttons, and I only want to change the Welcome page. Unfortunately, I can't simply
!define MUI_WELCOMEPAGE_BUTTON "Install" ... well, technically I can, but MUI.nsh won't do anything with it :)
Any thoughts? Thanks!
Afrow UK
24th November 2004 14:07 UTC
Hmm. This would require some modifications to the MUI InstallOptions ini file (ioSpecial.ini).
Something like this should work:
!define MUI_PAGE_CUSTOMFUNCTION_SHOW ChangeButtonText
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ResetButtonText
!insertmacro MUI_PAGE_WELCOME
Function ChangeButtonText
ReadRegStr $R0 HKLM "${REG_UNINST_KEY}" "InstallLocation"
StrCmp $R0 "" noChange
WriteINIStr "$PLUGINSDIR\ioSpecial.ini" "Settings" "NextButtonText" "Blah! >"
noChange:
FunctionEnd
Function ResetButtonText
DeleteINIStr "$PLUGINSDIR\ioSpecial.ini" "Settings" "NextButtonText"
FunctionEnd
First the NextButtonText is set, and then we must delete the setting (because otherwise the new NextButtonText will be there on the finish page too because the same ioSpecial.ini is used for both Welcome and Finish pages.)
-Stu
deritrus
24th November 2004 15:14 UTC
Stu, once again, amazing! From the two snippets of code you have provided me, you've made me really realize how flexible NSIS is!
Again, I had to make one little change to your code by using MUI_PAGE_CUSTOMFUNCTION_PRE instead of MUI_PAGE_CUSTOMFUNCTION_SHOW.
Thanks very much!
deritrus
25th November 2004 17:12 UTC
The saga continues. Now I want to conditionally change the header and subheader on MUI_PAGE_INSTFILES.
!define MUI_PAGE_HEADER_TEXT "Original Header Text"
!define MUI_PAGE_HEADER_SUBTEXT "Original Subheader Text"
!define MUI_PAGE_CUSTOMFUNCTION_PRE ChangeHeaders
!insertmacro MUI_PAGE_INSTFILES
Function ChangeHeaders
ReadRegStr $R0 HKLM "${REG_UNINST_KEY}" "InstallLocation"
StrCmp $R0 "" NoChange
; code to change MUI_PAGE_HEADER_TEXT
; code to change MUI_PAGE_HEADER_SUBTEXT
NoChange:
FunctionEnd
MUI_PAGE_INSTFILES doesn't appear to use
ioSpecial.ini. So I tried something tricky like
StrCpy ${MUI_PAGE_HEADER_TEXT} "New Header Text" but, as I expected, the compiler would have none of that. :D
On a similar note, is there any way to redefine a definition at runtime? For example:
!define MY_DEFINITION
MY_DEFINITION gets defined at compile time. Is it possible to alter MY_DEFINITION during runtime?
Any ideas? Thanks!
kichik
25th November 2004 17:26 UTC
Defines are compile time only.
You can set the define to use a variable as its value. You can then change that variable according to any condition you choose.
Afrow UK
25th November 2004 17:40 UTC
So what Kichik is saying:
Var MUIHeaderText
Var MUIHeaderSubText
!define MUI_PAGE_HEADER_TEXT "$MUIHeaderText"
!define MUI_PAGE_HEADER_SUBTEXT "$MUIHeaderSubText"
!define MUI_PAGE_CUSTOMFUNCTION_PRE ChangeHeaders
!insertmacro MUI_PAGE_INSTFILES
Function ChangeHeaders
ReadRegStr $R0 HKLM "${REG_UNINST_KEY}" "InstallLocation"
StrCmp $R0 "" NoChange
StrCpy $MUIHeaderText "My bloomin' heading text!"
StrCpy $MUIHeaderSubText "My bloomin' sub-heading text!"
NoChange:
FunctionEnd
-Stu
deritrus
25th November 2004 18:10 UTC
kichik and Stu, thanks once more! That did the trick.
FitzChivalry
30th November 2004 16:35 UTC
Wow! Y'all rock! I'm just reading through the posts before I go search for the answer to the question I have, and I came across this thread. I hadn't even *thought* of eliminating the directory choice screen, but it *totally* makes sense! Thanks, Deritrus, for the great idea! (And Stu and KiCHiK for the technical answers.) My life is getting easier....