Archive: newbie question: nsdialog example


newbie question: nsdialog example
hi all,

I'm trying to make an installer for my application, from examples and wiki I managed to make NSIS script which compiles and does the requested job, now I'm trying to add a simple dialog option which would give the user an option to put shortcuts on desktop and in quick launch (I know how to create shortcuts, but "option screen" is beyond me....

Would someone experienced be willing to make an example how to accomplish this ?

my script so far:


; basic script template for NSIS installers
;
; Written by Philip Chu
; Copyright (c) 2004-2005 Technicat, LLC
;
; This software is provided 'as-is', without any express or implied warranty.
; In no event will the authors be held liable for any damages arising from the use of this software.

; Permission is granted to anyone to use this software for any purpose,
; including commercial applications, and to alter it ; and redistribute
; it freely, subject to the following restrictions:

; 1. The origin of this software must not be misrepresented; you must not claim that
; you wrote the original software. If you use this software in a product, an
; acknowledgment in the product documentation would be appreciated but is not required.

; 2. Altered source versions must be plainly marked as such, and must not be
; misrepresented as being the original software.

; 3. This notice may not be removed or altered from any source distribution.

!define setup "@Magic_Navigator_setup.exe"

; change this to wherever the files to be packaged reside
!define srcdir "C:\Program Files\NSIS\test_magic\"
!define company "BS"
!define prodname "@Magic Navigator"
!define exec "MagicNavigator.exe"
!define helpfile "manual.pdf"
!define deinstall "uninstall.exe"
; optional stuff

; text file to open in notepad after installation
; !define notefile "README.txt"

; license text file
; !define licensefile license.txt

; icons must be Microsoft .ICO files
!define icon "magic_ikona.ico"
!define deicon "delete.ico"

; installer background screen
; !define screenimage background.bmp

; file containing list of file-installation commands
; !define files "files.nsi"

; file containing list of file-uninstall commands
; !define unfiles "unfiles.nsi"

; registry stuff

!define regkey "Software\${company}\${prodname}"
!define uninstkey "Software\Microsoft\Windows\CurrentVersion\Uninstall\${prodname}"
!define regkey-UN "Software\Siemens\Magic Navigator"
!define startmenu "$SMPROGRAMS\${prodname}"
!define uninstaller "uninstall.exe"

;--------------------------------

XPStyle on
ShowInstDetails hide
ShowUninstDetails hide

Name "${prodname}"
Caption "${prodname}"

!ifdef icon
Icon "${icon}"
!endif

OutFile "${setup}"

SetDateSave on
SetDatablockOptimize on
CRCCheck on
SilentInstall normal

InstallDir "$PROGRAMFILES\${company}\${prodname}"
InstallDirRegKey HKLM "${regkey}" ""

!ifdef licensefile
LicenseText "License"
LicenseData "${srcdir}\${licensefile}"
!endif

; pages
; we keep it simple - leave out selectable installation types

!ifdef licensefile
Page license
!endif

; Page components
Page directory
Page instfiles

UninstPage uninstConfirm
UninstPage instfiles

;--------------------------------

AutoCloseWindow false
ShowInstDetails show


!ifdef screenimage

; set up background image
; uses BgImage plugin

Function .onGUIInit
; extract background BMP into temp plugin directory
InitPluginsDir
File /oname=$PLUGINSDIR\1.bmp "${screenimage}"

BgImage::SetBg /NOUNLOAD /FILLSCREEN $PLUGINSDIR\1.bmp
BgImage::Redraw /NOUNLOAD
FunctionEnd

Function .onGUIEnd
; Destroy must not have /NOUNLOAD so NSIS will be able to unload and delete BgImage before it exits
BgImage::Destroy
FunctionEnd

!endif

; beginning (invisible) section
Section

WriteRegStr HKLM "${regkey}" "Install_Dir" "$INSTDIR"
; write uninstall strings
WriteRegStr HKLM "${uninstkey}" "DisplayName" "${prodname} (remove only)"
WriteRegStr HKLM "${uninstkey}" "UninstallString" '"$INSTDIR\${uninstaller}"'

!ifdef filetype
WriteRegStr HKCR "${filetype}" "" "${prodname}"
!endif

WriteRegStr HKCR "${prodname}\Shell\open\command\" "" '"$INSTDIR\${exec} "%1"'

!ifdef icon
WriteRegStr HKCR "${prodname}\DefaultIcon" "" "$INSTDIR\${icon}"
!endif

SetOutPath $INSTDIR


; package all files, recursively, preserving attributes
; assume files are in the correct places
File /r /x install_script.nsi "${srcdir}\"

!ifdef licensefile
File /a "${srcdir}\${licensefile}"
!endif

!ifdef notefile
File /a "${srcdir}\${notefile}"
!endif

!ifdef icon
File /a "${srcdir}\${icon}"
!endif

; any application-specific files
!ifdef files
!include "${files}"
!endif

WriteUninstaller "${uninstaller}"

SectionEnd

; create shortcuts
Section

CreateDirectory "${startmenu}"
SetOutPath $INSTDIR ; for working directory
!ifdef icon
CreateShortCut "${startmenu}\${prodname}.lnk" "$INSTDIR\${exec}" "" "$INSTDIR\${icon}"
!else
CreateShortCut "${startmenu}\${prodname}.lnk" "$INSTDIR\${exec}"
!endif

!ifdef notefile
CreateShortCut "${startmenu}\Release Notes.lnk "$INSTDIR\${notefile}"
!endif

!ifdef helpfile
CreateShortCut "${startmenu}\User manual.lnk "$INSTDIR\${helpfile}"
!endif

!ifdef deinstall
CreateShortCut "${startmenu}\uninstaller.lnk "$INSTDIR\${deinstall}" "" "$INSTDIR\${deicon}"
!endif

!ifdef website
WriteINIStr "${startmenu}\web site.url" "InternetShortcut" "URL" ${website}
; CreateShortCut "${startmenu}\Web Site.lnk "${website}" "URL"
!endif

!ifdef notefile
ExecShell "open" "$INSTDIR\${notefile}"
!endif

SectionEnd

Section "Quick Launch icon" SecQuick
StrCmp $QUICKLAUNCH $TEMP +2
CreateShortcut "$QUICKLAUNCH\@MagicNavigator.lnk" "$INSTDIR\${exec}" "" "$INSTDIR\${icon}"
SectionEnd

; Uninstaller
; All section names prefixed by "Un" will be in the uninstaller

UninstallText "This will uninstall ${prodname}."

!ifdef icon
UninstallIcon "${icon}"
!endif

Section "Uninstall"

DeleteRegKey HKLM "${uninstkey}"
DeleteRegKey HKLM "${regkey}"
DeleteRegKey HKCU "${regkey-UN}"
Delete "${startmenu}\*.*"
Delete "$QUICKLAUNCH\@MagicNavigator.lnk"
Delete "${startmenu}"
Delete "$INSTDIR\*.*"
RMDir /r "$INSTDIR\@Magic_Navigator_User_Manual_hr_files\"
RMDir /r "$INSTDIR\Config"
RMDir /r "$INSTDIR\WebHelp"
RMDir /r "$INSTDIR\imageformats"
RMDir "$INSTDIR"
!ifdef licensefile
Delete "$INSTDIR\${licensefile}"
!endif

!ifdef notefile
Delete "$INSTDIR\${notefile}"
!endif

!ifdef icon
Delete "$INSTDIR\${icon}"
!endif

Delete "$INSTDIR\${exec}"

!ifdef unfiles
!include "${unfiles}"
!endif


SectionEnd

There are several ways how to do it:
1) simple MessageBox with yes/no buttons askin "Do you want to place shortcut of Your_Software on Desktop?"
or
2) Create nsDialogs forms with two checkboxes - a) shortcuts on desktop b) in quick launch
in dialog Leave function simply check whether boxes are checked -> if yes then do the same as in 1

P.S.: Use pastebin for huge scripts :)


There's an excellent tutorial in the nsDialogs readme: http://nsis.sourceforge.net/Docs/nsDialogs/Readme.html

And yes, please use pastebin or attachments for huge scripts.


hi again,

found some time to work on installer, so far I've got this "code"
http://pastebin.com/Q5Gbh4BG

GUI representation is OK but installer always writes shortcuts (not dependent on checkbox selection).

thanks in advance


You should not create shortcuts in a page function, you should do it in a section. (Otherwise you're making changes to a system before the user has started the actual installation process!) Also, I've no idea what you're trying to accomplish by comparing $DESKTOP to $TEMP... o__O

Try this:
http://pastebin.com/MN3uHy6h


thanks mate, your example worked nicely (I had to change state "0" to "1"). as you can see the original thread title is truthful :), I'm a newbie and that comparison is not needed at all....

cheers