<!-- 
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 -->
<j:jelly
  xmlns:ant="jelly:ant"
  xmlns:j="jelly:core"
  xmlns:maven="jelly:maven"
  xmlns:util="jelly:util"
  xmlns="dummy"
  trim="false">


; Author Kristen Gillard
; Author Dion Gillard
; Installation Script for Maven
; http://maven.apache.org/

; add directories for the source if it exists, and the plugin
<util:available file="${maven.nsis.src}">
; add project source onto the include list
!addincludedir "${maven.nsis.src}"
</util:available>
; add generated files onto the include list
!addincludedir "${maven.build.dir}"
; add plugin supplied files onto the include list
!addincludedir "${plugin.resources}"

; macro for the image on the install screen
!include "BrandingImage.nsh"
!include "JDK.nsh"
!include "Environment.nsh"

; include project specific details
!include "project.nsh"

; Do a Cyclic Redundancy Check to make sure the installer is not corrupt
CRCCheck on

; The name of the installer
Name "$${PROJECT_NAME}"

; Maven Setup executable
OutFile "$${PROJECT_BUILD_DIR}\$${PROJECT_FINAL_NAME}.exe"

; Adds an XP manifest to the installer
XPStyle on

; branding with logo
; FIXME: position and size need to be properties
!ifdef PROJECT_LOGO
  AddBrandingImage ${maven.nsis.logo.position} ${maven.nsis.logo.widthHeight}
!endif

; Sets the font of the installer
SetFont "Arial" 8

!ifdef PROJECT_LICENSE_FILE
  ; License Information
  LicenseText "$${PROJECT_LICENSE_TEXT}"
  LicenseData "$${PROJECT_LICENSE_FILE}"
!endif

; The default installation directory
InstallDir "$$PROGRAMFILES\$${ORGANIZATION}\$${PROJECT_NAME} $${PROJECT_VERSION}"
; Registry key to check for directory (so if you upgrade, it will 
; overwrite the old one automatically)
InstallDirRegKey HKLM "$${PROJECT_REG_KEY}" "Install_Dir"

; The text to prompt the user to enter a directory
ComponentText "This will install $${PROJECT_NAME} on your computer."
; The text to prompt the user to enter a directory
DirText "$${PROJECT_NAME} Home Directory"

; -------------------------------------------------------------- Package up the files to be installed
Section "$${PROJECT_NAME} v$${PROJECT_VERSION} Binaries"
  ; Set output path to the installation directory.
  SetOutPath $$INSTDIR
  ; Put files and directories there
  ; the script will be run from a directory below Maven
  File /r "$${PROJECT_DIST_DIR}\*.*"

  ; Write the installation path into the registry
  WriteRegStr HKLM "$${PROJECT_REG_KEY}" "Install_Dir" "$$INSTDIR"

  ; Write the environment variables to the Registry
  <util:available file="${maven.nsis.src}/registry.nsh">
    !include "registry.nsh"
  </util:available>

  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "$${PROJECT_REG_UNINSTALL_KEY}" "DisplayName" "$${PROJECT_NAME} $${PROJECT_VERSION} (remove only)"
  WriteRegStr HKLM "$${PROJECT_REG_UNINSTALL_KEY}" "UninstallString" '"$$INSTDIR\Uninst.exe"'
SectionEnd

<util:available file="${maven.nsis.src}/startmenu-shortcuts.nsh">
; -------------------------------------------------------------- Create Shortcuts
Section "Create Start Menu Shortcut(s)"
  CreateDirectory "$${PROJECT_STARTMENU_FOLDER}"
  !include "startmenu-shortcuts.nsh"
SectionEnd
</util:available>

<util:available file="${maven.nsis.src}/desktop-shortcuts.nsh">
; OPTIONAL Desktop Shortcut 
Section "Create Desktop Shortcut"
  !include "desktop-shortcuts.nsh"
;SectionEnd
</util:available>

; -------------------------------------------------------------- Section to Install the Uninstaller
Section "Install Uninstaller"
   ; write the uninstaller to the installation directory
   WriteUninstaller "$$INSTDIR\Uninst.exe"
SectionEnd

; -------------------------------------------------------------- Maven Uninstaller
Section "Uninstall"
  ; remove registry keys
  DeleteRegKey HKLM "$${PROJECT_REG_UNINSTALL_KEY}"
  DeleteRegKey HKLM "$${PROJECT_REG_KEY}"

  <util:available file="${maven.nsis.src}/registry-uninstall.nsh">
    !include "registry-uninstall.nsh"
  </util:available>

  ; remove files
  Delete $$INSTDIR\*.*

  ; MUST REMOVE UNINSTALLER, too
  Delete $$INSTDIR\Uninst.exe

  ; remove shortcuts, if any.
  Delete "$${PROJECT_STARTMENU_FOLDER}\*.*"
  RMDir "$${PROJECT_STARTMENU_FOLDER}"
  ; Delete "$$DESKTOP\$${PROJECT_NAME}.lnk"

  ; Recursively remove files and directories used
  ; this should also take care of the installer  
  RMDir /r "$$INSTDIR"
  
  MessageBox MB_OK|MB_ICONEXCLAMATION "$${PROJECT_NAME} has been uninstalled"
SectionEnd

; -------------------------------------------------------------- Add Images to the Installer / UnInstaller
Function .onGUIInit
   !ifdef PROJECT_LOGO
     !insertmacro BrandingImage "$${PROJECT_LOGO}" ""
   !endif
   <util:available file="${maven.nsis.src}/before-install.nsh">
     !include "before-install.nsh"
   </util:available>
FunctionEnd

; add the logo to the un-installer
Function un.onGUIInit
   !ifdef PROJECT_LOGO
     !insertmacro BrandingImage "$${PROJECT_LOGO}" ""
   !endif
FunctionEnd

; -------------------------------------------------------------- End of File
</j:jelly>