Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 1st September 2010, 05:59   #1
rajWRT
Junior Member
 
Join Date: Aug 2010
Posts: 5
How to create desktop and quicklaunch options in NSIS installer

Hi
I want to create a desktop and quicklaunch option in my NSIS installer screen (ideally finish page ) i.e if user checks these check-boxes then shortcuts will be created .pls help me how to implement this.

Also i am including XPUI.nsh i.e all installer screen layout are XPUI based i.e it has piece of code like
!insertmacro XPUI_PAGE_INSTFILES
!insertmacro XPUI_PAGE_FINISH


Thanks,
Raj
rajWRT is offline   Reply With Quote
Old 1st September 2010, 06:54   #2
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
You can either create a section called "Create Shortcuts", or use nsDialogs to create a custom page. See the nsDialogs readme for a tutorial.
MSG is offline   Reply With Quote
Old 2nd September 2010, 05:02   #3
rajWRT
Junior Member
 
Join Date: Aug 2010
Posts: 5
Thanks MSG, i used the nsDiaglogue to create custom page . It is also displaying desktop shortcut creation option on the page but is not creating shortcuts on desktop.I am sending piece of code.



; Environment page
Page custom AdditionalTasks AdditionalTasksLeave

Function AdditionalTasks

Var /GLOBAL DESKTOP_ICON

Var /GLOBAL MUI_PAGE_CUSTOM

; Var /GLOBAL Checkbox_State
;Var /GLOBAL Checkbox
; Var /GLOBAL QUICKLAUCH_ICON

!include LogicLib.nsh
!include nsDialogs.nsh
!insertmacro MUI_HEADER_TEXT " Choose Additional Tasks" " Choose the additional tasks to be performed."

nsDialogs::Create /NOUNLOAD 1018
Pop $MUI_PAGE_CUSTOM

${If} $MUI_PAGE_CUSTOM == error
Abort
${EndIf}

${NSD_CreateCheckBox} 5 110 100% 20 "Create a desktop icon"
Pop $DESKTOP_ICON
${NSD_SetState} $DESKTOP_ICON ${BST_CHECKED}


nsDialogs::Show
FunctionEnd

Function AdditionalTasksLeave
;Var /GLOBAL CURRENTUSER
Var /GLOBAL DESKTOPUSER
;Var /GLOBAL PATH
${NSD_GetState} $DESKTOP_ICON $DESKTOPUSER

FunctionEnd


Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
Call DesktopIcon
SectionEnd

Function DesktopIcon
; Create desktop icon
${If} $DESKTOPUSER == 1

DetailPrint "Creating desktop icon, please wait..."

; SetOutPath "$INSTDIR\bin"
CreateShortCut "$DESKTOP\${NOKIA} ${NOKIAWDE_INST_DIR} ${VERSION}.lnk" "$INSTDIR\${NOKIAWDE_INST_DIR}\NokiaWDE.exe"
${EndIF}
FunctionEnd



Pls help me .. where i am doing mistake.
Thanks
rajWRT is offline   Reply With Quote
Old 2nd September 2010, 06:41   #4
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
1) You can't !include files like logiclib or nsdialogs inside a function. If that code compiles, it's beyond me how that would be possible.
2) You never declared $DESKTOPUSER
3) You may have to use SetOutPath to define the starting directory for the shortcut ('work folder').
MSG is offline   Reply With Quote
Old 2nd September 2010, 10:05   #5
rajWRT
Junior Member
 
Join Date: Aug 2010
Posts: 5
MSG,
I am still struggling as it is still not creating the desktop shortcuts.I am sending the complete code:

; Script generated by the HM NIS Edit Script Wizard.

; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "My application"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "My company, Inc."
!define PRODUCT_WEB_SITE "http://www.google.com"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

!include nsDialogs.nsh
!include LogicLib.nsh
Var Checkbox
Var Checkbox_State
Name nsDialogs
XPStyle on

; MUI 1.67 compatible ------
!include "MUI.nsh"

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!define MUI_LICENSEPAGE_CHECKBOX
!insertmacro MUI_PAGE_LICENSE "C:\Program Files\NSIS\license.txt"
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES

Page custom AdditionalTasks AdditionalTasksLeave
; Finish page
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"

; MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\My application"
ShowInstDetails show
ShowUnInstDetails show

Section "MainSection" SEC01
SectionEnd



Function AdditionalTasks

;Var /GLOBAL DESKTOP_ICON

Var /GLOBAL MUI_PAGE_CUSTOM

; Var /GLOBAL Checkbox_State
;Var /GLOBAL Checkbox
; Var /GLOBAL QUICKLAUCH_ICON
!insertmacro MUI_HEADER_TEXT " Choose Additional Tasks" " Choose the additional tasks to be performed."

nsDialogs::Create /NOUNLOAD 1018
Pop $MUI_PAGE_CUSTOM

${If} $MUI_PAGE_CUSTOM == error
Abort
${EndIf}

${NSD_CreateCheckBox} 5 110 100% 20 "Create a desktop icon"
Pop $Checkbox

${If} $Checkbox_State == ${BST_CHECKED}
${NSD_Check} $Checkbox
${EndIf}



; Pop $DESKTOP_ICON
;${NSD_SetState} $DESKTOP_ICON ${BST_CHECKED}


nsDialogs::Show
FunctionEnd

Function AdditionalTasksLeave
;Var /GLOBAL CURRENTUSER
; Var /GLOBAL DESKTOPUSER
;Var /GLOBAL PATH
;${NSD_GetState} $DESKTOP_ICON $DESKTOPUSER
${NSD_GetState} $Checkbox $Checkbox_State

FunctionEnd




Section -AdditionalIcons
SetOutPath $INSTDIR
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateDirectory "$SMPROGRAMS\My application"
CreateShortCut "$SMPROGRAMS\My application\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\My application\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd

Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
Call DesktopIcon
SectionEnd

Function DesktopIcon
; Create desktop icon
;SetOutPath $INSTDIR
DetailPrint "hello world"
${If} $Checkbox_State == 1
SetOutPath "$INSTDIR"
CreateShortCut "$DESKTOP\${PRODUCT_NAME} ${PRODUCT_VERSION}.lnk" ""
DetailPrint "hello world Checkbox_State"
${EndIf}

FunctionEnd

Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
FunctionEnd

Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
Abort
FunctionEnd

Section Uninstall
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"

Delete "$SMPROGRAMS\My application\Uninstall.lnk"
Delete "$SMPROGRAMS\My application\Website.lnk"

RMDir "$SMPROGRAMS\My application"

DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
SetAutoClose true
SectionEnd

Pls check were i am doing mistake.
rajWRT is offline   Reply With Quote
Old 2nd September 2010, 14:38   #6
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
CreateShortCut "$DESKTOP\${PRODUCT_NAME} ${PRODUCT_VERSION}.lnk" ""

I don't know about you, but I would try to actually make the shortcut POINT to something... -__-
MSG is offline   Reply With Quote
Old 3rd September 2010, 05:35   #7
rajWRT
Junior Member
 
Join Date: Aug 2010
Posts: 5
MSG,

CreateShortCut "$DESKTOP\${PRODUCT_NAME} ${PRODUCT_VERSION}.lnk" ""

this is just a dummy desktop shortcut, which does not have any link to open the product, to verify that our approach is correct.

One quick query , can we achieve the state of check box ( check box option to create the desktop shortcut) from custom page to the XPUI / MUI finish page.

Because i am creating desktop shortcut only after finish page i.e Section -Post only decides whether to create a desktop icons.
rajWRT is offline   Reply With Quote
Old 3rd September 2010, 06:14   #8
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Quote:
Originally Posted by rajWRT View Post
this is just a dummy desktop shortcut, which does not have any link to open the product, to verify that our approach is correct.
So in order to test whether your code is working, you're using a codeline that may very well not be valid NSIS script? Like I said, I would try to create it WITH an actual link, "to verify that your approach is correct".

Quote:
Originally Posted by rajWRT View Post
One quick query , can we achieve the state of check box ( check box option to create the desktop shortcut) from custom page to the XPUI / MUI finish page.
Please rephrase the question.

Quote:
Originally Posted by rajWRT View Post
Because i am creating desktop shortcut only after finish page i.e Section -Post only decides whether to create a desktop icons.
All sections are executed in the INSTFILES page. NOT in the finish page.
MSG is offline   Reply With Quote
Old 3rd September 2010, 07:08   #9
rajWRT
Junior Member
 
Join Date: Aug 2010
Posts: 5
Only thing i want is the desktop shortcuts should be created after the finish page.
rajWRT is offline   Reply With Quote
Old 3rd September 2010, 09:15   #10
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
You could try replacing the run or readme checkbox text and letting it execute a function instead of its regular action. See the MUI2 readme.
MSG is offline   Reply With Quote
Old 6th September 2010, 04:53   #11
jiake
Senior Member
 
jiake's Avatar
 
Join Date: Oct 2007
Location: Xi'an, China
Posts: 206
I found there are some mistakes in your script:

1.This is numbers comparation, not strings, using "=" not "==":
${If} $Checkbox_State == ${BST_CHECKED}
${If} $Checkbox_State == 1
Should be:
${If} $Checkbox_State = ${BST_CHECKED}
${If} $Checkbox_State = 1

If you are using "${If} $Checkbox_State == 1", it will also work, but this is not the correct usage. $Checkbox_State and 1 are compared as strings. But If you are using ${If} $Checkbox_State == ${BST_CHECKED}, in case the BST_CHECKED constant is defined to 1, 0x1, 0x0001 or 0x00000001, only if it is defined to 1, this expresstion is true. Using "=" for number comparation, the above four values are all equal to 1.

2. Code in Section (such as the CreateShortcut command) are executed in INSTFILES page, so you must first insert your custom page and then insert the INSTFILES page:

Page custom AdditionalTasks AdditionalTasksLeave
!insertmacro MUI_PAGE_INSTFILES

Finally, I suggest that you include MUI2.nsh, for MUI2 uses the nsDialogs plugin for WELCOME and FINISH page. Your installer will be smaller because it doesn't include the "InstallOptions" plugin in. Also, MUI2.nsh already include LogicLib.nsh and nsDialogs.nsh, you can include this header only.

Also you may do as MSG said, using the checkbox on the finish page to create shortcut.
jiake is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump