# Auto-generated by EclipseNSIS Script Wizard
# 17 juil. 2006 10:17:56

#
# COMPANY, PRODUCT and VERSION
# are supplied by the ant script
# that launches the build process
#

Name "${COMPANY} ${PRODUCT}"

# Defines
!define REGKEY "SOFTWARE\${PRODUCT}"
!define URL http://www.example.com
#!define VERSION 1.0
#!define COMPANY "The Example Company"
#!define PRODUCT "The Example Product Name"

# MUI defines
!define MUI_ICON ".\icon.ico"
!define MUI_UNICON ".\icon.ico"
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP ".\header.bmp"
!define MUI_HEADERIMAGE_UNBITMAP ".\header.bmp"

!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_STARTMENUPAGE_REGISTRY_ROOT HKLM
!define MUI_STARTMENUPAGE_NODISABLE
!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\${PRODUCT}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME StartMenuGroup
!define MUI_STARTMENUPAGE_DEFAULT_FOLDER "Bureau Veritas"
!define MUI_UNFINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_RUN_TEXT "Start ${PRODUCT} now"
!define MUI_FINISHPAGE_RUN "$INSTDIR\application.exe"

# Included files
!include Sections.nsh
!include MUI.nsh
!include FontName.nsh
!include FontReg.nsh

# Reserved Files

# Variables
Var StartMenuGroup
Var RUN_BY_ADMIN

# Installer pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE ..\..\data\license.txt
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
#!insertmacro MUI_PAGE_STARTMENU Application $StartMenuGroup
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

# Installer languages
!insertmacro MUI_LANGUAGE English

# Installer attributes
OutFile setup.exe
InstallDir "$PROGRAMFILES\${COMPANY}\myapplication\${PRODUCT}"
CRCCheck on
XPStyle on
ShowInstDetails show
VIProductVersion 1.0.0.0
VIAddVersionKey ProductName "${PRODUCT}"
VIAddVersionKey ProductVersion "${VERSION}"
VIAddVersionKey CompanyName "${COMPANY}"
VIAddVersionKey CompanyWebsite "${URL}"
VIAddVersionKey FileVersion ""
VIAddVersionKey FileDescription ""
VIAddVersionKey LegalCopyright ""
InstallDirRegKey HKLM "${REGKEY}" Path
ShowUninstDetails show

InstType "Full (Recommended)"           ## corresponds to 1
InstType "Minimal (CD-ROM required)"    ## corresponds to 2
InstType /NOCUSTOM                      ## no changes to install sets allowed

### INSTALL REQUIRED FONTS
Section "Required Fonts" SEC_FONTS
    ### FONT INSTALLATION
    SectionIn 1 2
    StrCpy $FONT_DIR $FONTS
    !insertmacro InstallTTFFont "fonts\ariabn__.ttf"
    !insertmacro InstallTTFFont 'fonts\Mtextra.ttf'
SectionEnd

###
Section "Application Data" SEC_APPLICATION
    SectionIn 1
    ;SetShellVarContext all
    SetOutPath $INSTDIR
    SetOverwrite on
    File /r ..\..\runtime\cdrom\*
    WriteRegStr HKLM "${REGKEY}\Components" Main 1
SectionEnd

###
Section "Shortcut to CD-ROM" SEC_SHORTCUTS_CDROM
    SectionIn 2
    SetOutPath $DESKTOP
    CreateShortcut "$DESKTOP\${COMPANY} ${PRODUCT}.lnk"\
     "$EXEDIR\myapplication.exe" "" "$EXEDIR\myapplication.exe" 0 SW_SHOWNORMAL \
     "" "Launch application from the CD-ROM" 
SectionEnd

###
Section "Shortcut to application" SEC_SHORTCUTS_HARDDISK
    SectionIn 1     ## install only when "full" install selected

    ### SHORTCUT ON THE DESKTOP
    SetOutPath $DESKTOP
    CreateShortcut "$DESKTOP\${COMPANY} ${PRODUCT}.lnk"\
     "$INSTDIR\myapplication.exe" "" "" 0 SW_SHOWNORMAL \
     "" "Launch ${PRODUCT}" 

    ### SHORTCUT IN THE START MENU
    SetOutPath "$SMPROGRAMS\${COMPANY}\myapplication\${PRODUCT}"    
    CreateShortcut "$SMPROGRAMS\${COMPANY}\myapplication\${PRODUCT}\${PRODUCT}.lnk" \
    "$INSTDIR\myapplication.exe" "" "" 0 SW_SHOWNORMAL \
    "" "Launch ${PRODUCT}"

SectionEnd

;Section "Shortcut in Startmenu" SEC_SHORTCUTS_STARTMENU
;    SectionIn 2 ## install only 
;
;    ### SHORTCUT IN THE START MENU
;    SetOutPath "$SMPROGRAMS\${COMPANY}\myapplication\${PRODUCT}"    
;    CreateShortcut "$SMPROGRAMS\${COMPANY}\myapplication\${PRODUCT}\${PRODUCT}.lnk" \
;    "$EXEDIR\myapplication.exe" "" "" 0 SW_SHOWNORMAL \
;    "" "Launch ${PRODUCT}"
;SectionEnd

Section -post SEC0001
    SectionIn 1
    WriteRegStr HKLM "${REGKEY}" Path $INSTDIR
    
    WriteUninstaller $INSTDIR\uninstall.exe
    ;!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
    SetOutPath "$SMPROGRAMS\${COMPANY}\myapplication\${PRODUCT}"
    CreateShortcut "$SMPROGRAMS\${COMPANY}\myapplication\${PRODUCT}\Uninstall.lnk" $INSTDIR\uninstall.exe
    ;!insertmacro MUI_STARTMENU_WRITE_END
    
    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" DisplayName "${PRODUCT}"
    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" DisplayVersion "${VERSION}"
    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" Publisher "${COMPANY}"
    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" URLInfoAbout "${URL}"
    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" DisplayIcon $INSTDIR\uninstall.exe
    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" UninstallString $INSTDIR\uninstall.exe
    WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" NoModify 1
    WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" NoRepair 1
SectionEnd

# Macro for selecting uninstaller sections
!macro SELECT_UNSECTION SECTION_NAME UNSECTION_ID
    Push $R0
    ReadRegStr $R0 HKLM "${REGKEY}\Components" "${SECTION_NAME}"
    StrCmp $R0 1 0 next${UNSECTION_ID}
    !insertmacro SelectSection "${UNSECTION_ID}"
    GoTo done${UNSECTION_ID}
next${UNSECTION_ID}:
    !insertmacro UnselectSection "${UNSECTION_ID}"
done${UNSECTION_ID}:
    Pop $R0
!macroend

# Uninstaller sections
Section /o un.Main UNSEC0000
    Delete /REBOOTOK $INSTDIR\*
    RmDir /REBOOTOK $INSTDIR
    Delete "$DESKTOP\${COMPANY} ${PRODUCT}.lnk"
    DeleteRegValue HKLM "${REGKEY}\Components" Main
SectionEnd

Section un.post UNSEC0001
    DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}"
    Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Uninstall ${PRODUCT}.lnk"
    Delete /REBOOTOK $INSTDIR\uninstall.exe
    DeleteRegValue HKLM "${REGKEY}" StartMenuGroup
    DeleteRegValue HKLM "${REGKEY}" Path
    DeleteRegKey /IfEmpty HKLM "${REGKEY}\Components"
    DeleteRegKey /IfEmpty HKLM "${REGKEY}"
    RmDir /REBOOTOK $SMPROGRAMS\$StartMenuGroup
    RmDir /REBOOTOK $INSTDIR
SectionEnd

# Installer functions
Function .onInit
    Call InitRoutine
    InitPluginsDir
FunctionEnd

# Uninstaller functions
Function un.onInit
    Call un.InitRoutine
    ReadRegStr $INSTDIR HKLM "${REGKEY}" Path
    ReadRegStr $StartMenuGroup HKLM "${REGKEY}" StartMenuGroup
    !insertmacro SELECT_UNSECTION Main ${UNSEC0000}
FunctionEnd

; Author: Lilla (lilla@earthlink.net) 2003-06-13
; function IsUserAdmin uses plugin \NSIS\PlusgIns\UserInfo.dll
; This function is based upon code in \NSIS\Contrib\UserInfo\UserInfo.nsi
; This function was tested under NSIS 2 beta 4 (latest CVS as of this writing).
;
; Usage:
;   Call IsUserAdmin
;   Pop $R0   ; at this point $R0 is "true" or "false"
;
Function IsUserAdmin
    Push $R0
    Push $R1
    Push $R2
     
    ClearErrors
    UserInfo::GetName
    IfErrors Win9x
    Pop $R1
    UserInfo::GetAccountType
    Pop $R2
     
    StrCmp $R2 "Admin" 0 Continue
    ; Observation: I get here when running Win98SE. (Lilla)
    ; The functions UserInfo.dll looks for are there on Win98 too, 
    ; but just don't work. So UserInfo.dll, knowing that admin isn't required
    ; on Win98, returns admin anyway. (per kichik)
    ; MessageBox MB_OK 'User "$R1" is in the Administrators group'
    StrCpy $R0 "true"
    Goto Done
     
    Continue:
    ; You should still check for an empty string because the functions
    ; UserInfo.dll looks for may not be present on Windows 95. (per kichik)
    StrCmp $R2 "" Win9x
    StrCpy $R0 "false"
    ;MessageBox MB_OK 'User "$R1" is in the "$R2" group'
    Goto Done
     
    Win9x:
    ; comment/message below is by UserInfo.nsi author:
    ; This one means you don't need to care about admin or
    ; not admin because Windows 9x doesn't either
    ;MessageBox MB_OK "Error! This DLL can't run under Windows 9x!"
    StrCpy $R0 "true"
     
    Done:
    ;MessageBox MB_OK 'User= "$R1"  AccountType= "$R2"  IsUserAdmin= "$R0"'
     
    Pop $R2
    Pop $R1
    Exch $R0
FunctionEnd

Function un.IsUserAdmin
    Push $R0
    Push $R1
    Push $R2
     
    ClearErrors
    UserInfo::GetName
    IfErrors Win9x
    Pop $R1
    UserInfo::GetAccountType
    Pop $R2
     
    StrCmp $R2 "Admin" 0 Continue
    ; Observation: I get here when running Win98SE. (Lilla)
    ; The functions UserInfo.dll looks for are there on Win98 too, 
    ; but just don't work. So UserInfo.dll, knowing that admin isn't required
    ; on Win98, returns admin anyway. (per kichik)
    ; MessageBox MB_OK 'User "$R1" is in the Administrators group'
    StrCpy $R0 "true"
    Goto Done
     
    Continue:
    ; You should still check for an empty string because the functions
    ; UserInfo.dll looks for may not be present on Windows 95. (per kichik)
    StrCmp $R2 "" Win9x
    StrCpy $R0 "false"
    ;MessageBox MB_OK 'User "$R1" is in the "$R2" group'
    Goto Done
     
    Win9x:
    ; comment/message below is by UserInfo.nsi author:
    ; This one means you don't need to care about admin or
    ; not admin because Windows 9x doesn't either
    ;MessageBox MB_OK "Error! This DLL can't run under Windows 9x!"
    StrCpy $R0 "true"
     
    Done:
    ;MessageBox MB_OK 'User= "$R1"  AccountType= "$R2"  IsUserAdmin= "$R0"'
     
    Pop $R2
    Pop $R1
    Exch $R0
FunctionEnd

Function InitRoutine
    Call IsUserAdmin
    Pop $R0
    StrCpy $RUN_BY_ADMIN $R0 ; saving information
    StrCmp $R0 "true" is_admin
    ; not an admin
    MessageBox MB_OK|MB_ICONSTOP "You need administrator's privileges to install this application."
    Abort
;   goto done_init
    is_admin:
;    done_init:
FunctionEnd

Function un.InitRoutine
    Call un.IsUserAdmin
    Pop $R0
    StrCpy $RUN_BY_ADMIN $R0 ; saving information
    StrCmp $R0 "true" is_admin
    ; not an admin
    MessageBox MB_OK|MB_ICONSTOP "You need administrator's privileges to install this application."
    Abort
;   goto done_init
    is_admin:
;    done_init:
FunctionEnd
