#************************************ Enter script definitions **********************************#

!define APP_NAME "Test Installer"

;..................................................................................................
;Following two definitions required. Uninstall log will use these definitions.
;You may use these definitions also, when you want to set up the InstallDirRagKey,
;store the language selection, store Start Menu folder etc.
;Enter the windows uninstall reg sub key to add uninstall information to Add/Remove Programs also.
!define INSTDIR_REG_ROOT "HKLM"
!define INSTDIR_REG_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}"


#************************************* Include NSIS Headers ***********************************#
!include MUI2.nsh
!include AdvUninstLog.nsh
!include LogicLib.nsh

# Install attributes
Name "${APP_NAME}"
OutFile "${APP_NAME}.exe"
ShowInstDetails show
ShowUninstDetails show
InstallDir "$PROGRAMFILES\${APP_NAME}"
InstallDirRegKey ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "InstallDir"

# Defines the pages in the ModernUI
!insertmacro INTERACTIVE_UNINSTALL
!insertmacro MUI_PAGE_WELCOME
;!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\License.txt"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
!insertmacro MUI_LANGUAGE "English"

# Folder is only created if this section is uncommented
;Section "DummyFile"
;        SetOutPath $INSTDIR
;        File "C:\Documents and Settings\trobertson\Desktop\teapot.nif"
;SectionEnd

Section "Start Menu Shortcuts" StartMenuShortcuts
        CreateDirectory '$SMPROGRAMS\${APP_NAME}'
        CreateShortcut '$SMPROGRAMS\${APP_NAME}\uninstall.lnk' '${UNINST_EXE}'
SectionEnd

Section "-InstallRegistryValues"
        WriteRegStr ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "InstallDir" "$INSTDIR"
        WriteRegStr ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "DisplayName" "${APP_NAME}"
        ;Same as create shortcut you need to use ${UNINST_EXE} instead of anything else.
        WriteRegStr ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "UninstallString" "${UNINST_EXE}"
SectionEnd


#################################### Install Callbacks #####################################
Function .onInit
        ;prepare log always within .onInit function
        !insertmacro UNINSTALL.LOG_PREPARE_INSTALL
FunctionEnd


Function .onInstSuccess
         ;create/update log always within .onInstSuccess function
         !insertmacro UNINSTALL.LOG_UPDATE_INSTALL
FunctionEnd


##################################### Uninstall Sections ######################################
Section UnInstall
        !insertmacro UNINSTALL.LOG_BEGIN_UNINSTALL
        !insertmacro UNINSTALL.LOG_UNINSTALL "$INSTDIR"
        !insertmacro UNINSTALL.LOG_END_UNINSTALL

        Delete "$SMPROGRAMS\${APP_NAME}\uninstall.lnk"
        RmDir "$SMPROGRAMS\${APP_NAME}"

        DeleteRegKey /ifempty ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}"
SectionEnd