Hello, i've tried making this work for a weeks time with lots of reading inbetween and still nothing, so would much appreciate some help, thanks.
I have added an additional option/checkbox underneath the others on the components page, to enable a portable install. There I will just change $instdir and bypass all the non-portable stuff, but I cannot even get through first pass of changing shown install dir of the directory page following.
I have tried lots of stuff, e.g. first defining installdir in script as $PROGRAMFILES64\foo, and then in the new section added to components I just run: "StrCpy $INSTDIR "$EXEDIR\Deluge""
This dosen't work, as the directory page coming next doesn't reflect the change when selecting the option under components.
Then I tried adding a "var portable" and then from the components section added, I run "StrCpy $portable 1"
And in pre-callback to directory page e.g. : "!define MUI_PAGE_CUSTOMFUNCTION_PRE GetDir", or the same as *_LEAVE for components page, or even both, still dosen't work with the following, or the if/else variant with logiclib.nsh enabled:
Function GetDir
StrCmp $portable "" NoDir DirOK
NoDir:
StrCpy $INSTDIR "$PROGRAMFILES64\Deluge"
DirOK:
StrCpy $INSTDIR "$EXEDIR\Deluge"
FunctionEnd
(The names seem strange, but I didn't bothered change them, as was copied from others, while till appliable). It still just takes the last one. I also tried not using installdir initially, and changing above function to set instdir to either this or that based on the variable, but don't work.
Maybe it works, but atleast isn't reflected on the shown path of the directory page, and that's a big issue, as instdir gets overwritten with the value listed there when user presses OK!
Much appreciate any help again, as driving me insane soon 🙂
Change $instdir and directory page issue.
7 posts
What does your component page leave function look like? Make sure you are reading the checkbox correctly.
Dynamically updating $instdir on a page before the directory page should work.
Dynamically updating $instdir on a page before the directory page should work.
Thanks Anders!
I've read you state that to many others asking likewise question, but I must be a moron or something then 🙂
Let's take a simple example with simply setting another instdir dynamically based on added components page section:
InstallDir "$PROGRAMFILES64\Deluge
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
Section /o "Portable" Section5
StrCpy $INSTDIR "$EXEDIR\Deluge"
SectionEnd
About my last post and your questions, then I have added the previously posted GetDir function as either a pre/leave callback to directory/components page, or even both(same GetDir function used for callback in both) as stated before also without success and just having "StrCpy $portable 1" as code in the added "portable" section, which GetDir checks for and sets instdir conditionally.
I don't understand when you say to make sure the checkbox is enabled in your components leave function. If setting a var when enabling the section, and checking for it in leave callback, then i've done that correct? I mean the code is only run when checking box, and I read vars are global to all later sections.
Thanks again!
I've read you state that to many others asking likewise question, but I must be a moron or something then 🙂
Let's take a simple example with simply setting another instdir dynamically based on added components page section:
InstallDir "$PROGRAMFILES64\Deluge
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
Section /o "Portable" Section5
StrCpy $INSTDIR "$EXEDIR\Deluge"
SectionEnd
About my last post and your questions, then I have added the previously posted GetDir function as either a pre/leave callback to directory/components page, or even both(same GetDir function used for callback in both) as stated before also without success and just having "StrCpy $portable 1" as code in the added "portable" section, which GetDir checks for and sets instdir conditionally.
I don't understand when you say to make sure the checkbox is enabled in your components leave function. If setting a var when enabling the section, and checking for it in leave callback, then i've done that correct? I mean the code is only run when checking box, and I read vars are global to all later sections.
Thanks again!
I see the problem now. Sections are executed on the InstFiles page!
To get what you want you need to use the helper macros in LogicLib.nsh/Sections.nsh to check the state of the portable component in the leave callback of your component page and set $InstDir in that callback.
To get what you want you need to use the helper macros in LogicLib.nsh/Sections.nsh to check the state of the portable component in the leave callback of your component page and set $InstDir in that callback.
Thank you so much Anders, I really appreciate your help! I'm so happy I don't have to continue retest endlessly with small variations, and use your debugging tool to check instdir throughout etc, and rereading the same posts about this on the net, all while pulling hairs out for not understanding the underlying issue lol 🙂
Works beatifully 🙂 Thanks again!
-Martin.
Works beatifully 🙂 Thanks again!
-Martin.
InstallDir "$ProgramFiles\MyApp"
!include MUI2.nsh
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE MyCompLeave
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
Section ""
SetOutPath $InstDir
File mystuff\myapp.exe
SectionEnd
Section "Start Menu" SID_SM
CreateShortcut "$SMPrograms\MyApp.lnk" "$InstDir\MyApp.exe"
SectionEnd
Section /o "Portable Install" SID_P
SectionEnd
!include Sections.nsh
!include LogicLib.nsh
Function .onSelChange
${If} $0 = ${SID_P}
${AndIf} ${SectionIsSelected} ${SID_P}
!insertmacro UnselectSection ${SID_SM} ; Turn start menu link off
${EndIf}
FunctionEnd
Function MyCompLeave
${If} ${SectionIsSelected} ${SID_P}
StrCpy $InstDir "$ExeDir\MyApp"
${EndIf}
FunctionEnd Thanks again Anders, my code was the same, thanks to your helpfull guidance! 🙂 I also added some stuff like when enabling the portable checkbox under components-page, then auto-unselect the two other checkboxes which would install reg-associations, and set them as read-only.
(I'm brand new to nsis since two weeks'ish, and needing to learn it because I started make and release unofficial deluge torrent client installers for windows, as there isn't any official ones for newest version currently(only linux, which I also only use myself, and just make these installers in a windows VM to help out), and I wanted a portable section added also + change some other stuff etc.)
Thanks again, really appreciate your help! Take care.
(I'm brand new to nsis since two weeks'ish, and needing to learn it because I started make and release unofficial deluge torrent client installers for windows, as there isn't any official ones for newest version currently(only linux, which I also only use myself, and just make these installers in a windows VM to help out), and I wanted a portable section added also + change some other stuff etc.)
Thanks again, really appreciate your help! Take care.