;--------------------------------
;Product Info
Name "__PROGRAM__ __VERSION__" ;Define your own software name here
!define PRODUCT "__PROGRAM__" ;Define your own software name here
!define VERSION "__VERSION__" ;Define your own software version here

CRCCheck On
; Script create for version 2.0b4 1.40 (from 09.sep.03) with GUI NSIS (c) by Dirk Paehl. Thank you for use my program

 !include "MUI.nsh"
 !include "x64.nsh"
 
 Function .onInit
	${If} ${RunningX64}
	${EnableX64FSRedirection}
	${else}
	MessageBox MB_OK "Sorry this version only runs on windows 64 bit. Download the 32bit version"
	Abort
	${EndIf}
FunctionEnd


; For icon association
!define SHCNE_ASSOCCHANGED 0x08000000
!define SHCNF_IDLIST 0
 
Function RefreshShellIcons
  ; By jerome tremblay - april 2003
  System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v \
  (${SHCNE_ASSOCCHANGED}, ${SHCNF_IDLIST}, 0, 0)'
FunctionEnd

 
;--------------------------------
;Configuration
 
   OutFile "__OUTFILE__"

   ;Folder selection page
   InstallDir "$PROGRAMFILES64\${PRODUCT} ${VERSION}"


;Remember install folder
InstallDirRegKey HKCU "Software\${PRODUCT} ${VERSION}" ""

;--------------------------------
;Pages
!insertmacro MUI_PAGE_LICENSE "__LICENSE_FILE__"
  !insertmacro MUI_PAGE_DIRECTORY
  !insertmacro MUI_PAGE_INSTFILES
  !insertmacro MUI_PAGE_FINISH
  !insertmacro MUI_UNPAGE_CONFIRM
  !insertmacro MUI_UNPAGE_INSTFILES

 !define MUI_ABORTWARNING

 
;--------------------------------
 ;Language
 
  !insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Icon "${NSISDIR}\Contrib\Graphics\Icons\win-install.ico"
Icon "__ICON_PATH__"
UninstallIcon "${NSISDIR}\Contrib\Graphics\Icons\win-uninstall.ico"

;Installer Sections
     
Section "section_1" section_1
SetOutPath "$INSTDIR"
FILE /r "__SOURCE_DIRECTORY__\*.*"
SectionEnd

Section Shortcuts
SetOutPath "$PROFILE"
Call RefreshShellIcons   
CreateDirectory "$SMPROGRAMS\${PRODUCT} ${VERSION}"
WriteIniStr "$INSTDIR\PyMca.url" "InternetShortcut" "URL" "http://pymca.sourceforge.net/"
CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\PyMca Home page.lnk" "$INSTDIR\PyMca.url" "" "$INSTDIR\PyMca.url" 0
CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\PyMca.lnk" "$INSTDIR\PyMcaMain.exe" "" "$INSTDIR\PyMcaMain.exe" 0
CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\PyMca Fresh Start.lnk" "$INSTDIR\PyMcaMain.exe" "-f" "$INSTDIR\PyMcaMain.exe" 0
CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\Identify Peak.lnk" "$INSTDIR\PeakIdentifier.exe" "" "$INSTDIR\PeakIdentifier.exe" 0
CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\Elements.lnk" "$INSTDIR\ElementsInfo.exe" "" "$INSTDIR\ElementsInfo.exe" 0
CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\PyMcaBatch.lnk" "$INSTDIR\PyMcaBatch.exe" "" "$INSTDIR\PyMcaBatch.exe" 0
CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\EDF Viewer.lnk" "$INSTDIR\EdfFileSimpleViewer.exe" "" "$INSTDIR\EdfFileSimpleViewer.exe" 0
;CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\Fit to Spec Converter.lnk" "$INSTDIR\Fit2Spec.exe" "" "$INSTDIR\Fit2Spec.exe" 0
CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\Mca to Edf Converter.lnk" "$INSTDIR\Mca2Edf.exe" "" "$INSTDIR\Mca2Edf.exe" 0
CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\RGB Correlator.lnk" "$INSTDIR\PyMcaPostBatch.exe" "" "$INSTDIR\PyMcaPostBatch.exe" 0
CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\ROI Imaging Tool.lnk" "$INSTDIR\QStackWidget.exe" "" "$INSTDIR\QStackWidget.exe" 0
#CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\ROI Imaging Tool (OLD).lnk" "$INSTDIR\QStackWidget.exe" "--old" "$INSTDIR\QStackWidget.exe" 0
;CreateShortCut "$SMPROGRAMS\${PRODUCT}${VERSION}\EDF Binning Tool.lnk" "$INSTDIR\EdfBinWidget.exe" "" "$INSTDIR\EdfBinWidget.exe" 0
;CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\Xia Correction Tool.lnk" "$INSTDIR\XiaCorrect.exe" "" "$INSTDIR\XiaCorrect.exe" 0
SectionEnd

Section Uninstaller
CreateShortCut "$SMPROGRAMS\${PRODUCT} ${VERSION}\Uninstall.lnk" "$INSTDIR\uninst.exe" "" "$INSTDIR\uninst.exe" 0
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT} ${VERSION}" "DisplayName" "${PRODUCT} ${VERSION}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT} ${VERSION}" "DisplayVersion" "${VERSION}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT} ${VERSION}" "URLInfoAbout" "http://pymca.sourceforge.net"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT} ${VERSION}" "Publisher" "V.A. Sol� - ESRF Software Group"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT} ${VERSION}" "UninstallString" "$INSTDIR\Uninst.exe"
WriteRegStr HKCU "Software\${PRODUCT} ${VERSION}" "" $INSTDIR
WriteUninstaller "$INSTDIR\Uninst.exe"
 
 
SectionEnd
 
;--------------------------------  
;Descriptions 
                                    
 
;--------------------------------
    
;Uninstaller Section
   
Section "Uninstall" 
 
  ;Add your stuff here  
   
  ;Delete Files 
 Delete "$INSTDIR\mpl-data\*.*" 
 Delete "$INSTDIR\.matplotlib\*.*" 
 Delete "$INSTDIR\attdata\*.*" 
 Delete "$INSTDIR\HTML\IMAGES\*.*" 
 Delete "$INSTDIR\HTML\PyMCA_files\*.*" 
 Delete "$INSTDIR\HTML\*.*" 
 Delete "$INSTDIR\*.*"
   
  ;Delete Start Menu Shortcuts
  Delete "$SMPROGRAMS\PyMca ${VERSION}\*.*"
  RmDir "$SMPROGRAMS\PyMca ${VERSION}"
  SetShellVarContext all
  Delete "$SMPROGRAMS\PyMca ${VERSION}\*.*"
  RmDir "$SMPROGRAMS\PyMca ${VERSION}"
  ;Delete Uninstaller And Unistall Registry Entries
  DeleteRegKey HKEY_CLASSES_ROOT "Applications\PyMcaPostBatch.exe"
  DeleteRegKey HKEY_CLASSES_ROOT "Applications\QEDFStackWidget.exe"
  DeleteRegKey HKEY_CLASSES_ROOT "Applications\EdfFileSimpleViewer.exe"
  DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\PyMca ${VERSION}"
  DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PyMca ${VERSION}"
  DeleteRegKey HKEY_CURRENT_USER "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu\Programs\PyMca ${VERSION}"
  DeleteRegKey HKEY_CURRENT_USER "SOFTWARE\PyMca ${VERSION}"
  RMDir "$INSTDIR\mpl-data"
  RMDir "$INSTDIR\.matplotlib"
  RMDir "$INSTDIR\attdata"
  RMDir "$INSTDIR\HTML\IMAGES"
  RMDir "$INSTDIR\HTML\PyMCA_files"
  RMDir "$INSTDIR\HTML"
  RMDir /r "$INSTDIR"
             
SectionEnd
               
;eof
