;------------------------------------------------------------------------------
; ADS1298ECG-FE Software Installer
;
; This application installs the ADS1298ECG-FE software for use with the EVM and MMB0 platform.
;
; Edited: Greg Hupp
; File Updated: 16NOV10
;
;
;-------------------------------------------------------------------------------

;-----------------------------------------------------------------------------
; Constant declarations

!define APP_NAME "ADS1298ECG-FE"
!define COMP_NAME "Texas Instruments Inc."
#!define WEB_SITE "http://www.ti.com/"
!define VERSION "1.0.0"
!define BUILD "0"
!define RELEASE_DATE "16NOV10"
!define COPYRIGHT "(c)2010 Texas Instruments Inc."
!define DESCRIPTION "ADS1298EVM software"
!define CPL_LICENSE_TXT "C:\work\adcpro\LICENSE.txt"
!define NI_LICENSE_TXT "C:\work\adcpro\NI_LICENSE.rtf"
!define INSTALL_TYPE "SetShellVarContext current"
!define MAIN_APP_EXE "ads1298evm.exe"
!define REG_ROOT "HKCU"
!define REG_APP_PATH "Software\Microsoft\Windows\CurrentVersion\App Paths\${APP_NAME}"

;-----------------------------------------------------------------------
; Switches for installer builds
# Uncomment below define for release versions
#!define RELEASE

# Uncomment below define for installer with LVRT
#!define WITH_LVRT

;-----------------------------------------------------------------------
; Variable declarations

Var iniSearchPath

;-----------------------------------------------------------------------
; Installer File Version

VIProductVersion  "${VERSION}.${BUILD}"
VIAddVersionKey "ProductName"  "${APP_NAME}"
VIAddVersionKey "CompanyName"  "${COMP_NAME}"
VIAddVersionKey "LegalCopyright"  "${COPYRIGHT}"
VIAddVersionKey "FileDescription"  "${DESCRIPTION}"
VIAddVersionKey "FileVersion"  "${VERSION}.${BUILD}"

;-----------------------------------------------------------------------
; General Installer Information

SetCompressor /SOLID Bzip2
Name "${APP_NAME}"
Caption "${APP_NAME}"
!ifdef WITH_LVRT
  !ifdef RELEASE
    OutFile "ads1298ecg-fe-${VERSION}.exe"
  !else
    OutFile "ads1298-ecg-fe-${VERSION}.${BUILD}.exe"
  !endif
!else
  !ifdef RELEASE
    OutFile "ads1298-ecg-fe-norelease-${VERSION}.exe"
  !else
    OutFile "ads1298-ecg-fe-norelease-${VERSION}.${BUILD}.exe"
  !endif
!endif
BrandingText "${APP_NAME}"
InstallDir "$PROGRAMFILES\${APP_NAME}"

;-----------------------------------------------------------------------
; Include Files

!include "MUI.nsh"
!include "driver.nsh"
!include "ADCPro.nsh"
!include "LogicLib.nsh"
!include "WordFunc.nsh"

;-----------------------------------------------------------------------
; General configuration

!define MUI_ABORTWARNING
!define MUI_UNABORTWARNING

!define MUI_ICON "..\..\adcpro\shell\StdDir.ico"
!define MUI_UNICON "..\..\adcpro\shell\StdDir.ico"

;------------------------------------------------------------------------
; Installer Page Configuration

!insertmacro MUI_PAGE_WELCOME

!ifdef CPL_LICENSE_TXT
  !insertmacro MUI_PAGE_LICENSE "${CPL_LICENSE_TXT}"
!endif
!ifdef NI_LICENSE_TXT
  !insertmacro MUI_PAGE_LICENSE "${NI_LICENSE_TXT}"
!endif

!insertmacro MUI_PAGE_INSTFILES
  !define MUI_FINISHPAGE_RUN "$INSTDIR\${MAIN_APP_EXE}"
  !define MUI_FINISHPAGE_RUN_NOTCHECKED
!insertmacro MUI_PAGE_FINISH

;-------------------------------------------------------------
; Uninstall pages Configuration

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH

!insertmacro MUI_LANGUAGE "English"

;;--------------------------------------------------------------------------
; Install Plug-in
; This section installs the plug-in files to the plug-in folder and common files directory

Section Plugin SectionPlugin

# Install the files
	SetOutPath $INSTDIR
	File /r /x data app\*.*
# Install libmmb0 files
	File /r /x .svn* /x "LED Segment" /x PLLCalculation ..\..\LabView_Files\LV86\libmmb0
# Install ASD1298 register file information
	CreateDirectory "$INSTDIR\start-up"
	SetOutPath "$INSTDIR\start-up"
	File "..\1298 Register Map.txt"
	File "..\Modules\Estyx\*.txt"

# Install Analysis Pop-up display
	SetOutPath "$INSTDIR\Modules"
	File "..\Modules\StatTable_Popup.vi"
	
# Install firmware files
	SetOutPath "$INSTDIR\fw"
	File /r ..\fw_1298\*.bin

# Install libadcpro files need for this software (not installing libadcpro in whole)
	SetOutPath "$INSTDIR\lib1298"
	File /r /x .svn* ..\..\LabView_Files\LV86\libadcpro\EVMCommon\Queue
	File /r /x .svn* ..\..\LabView_Files\LV86\libadcpro\ErrorLogging
	File "..\..\LabView_Files\LV86\libadcpro\EVMCommon\Interface\EVM_ProgressBar.vi"
	File "..\..\LabView_Files\LV86\libadcpro\EVMCommon\Constants\CST_EVM Plugin pointers.vi"
	File "..\..\LabView_Files\LV86\libadcpro\EVMCommon\Controls\TYP_EVM Plugin Pointers.ctl"
	File "..\..\LabView_Files\LV86\libadcpro\Utility\LogCase.vi"

# Install Common Files
	SetOutPath "$INSTDIR\CommonFiles"
	File /r /x .svn* ..\Distribution\*.*
	
SectionEnd
;-------------------------------------------------------------------------
; USB Driver Section
; This section installs the correct USB Drivers to the correct location

Section "USB drivers" SectionUSBDrivers
	SetOutPath "$INSTDIR\driver"
	File ..\..\LabView_Files\LV86\libmmb0\Styx\nivisa5509.inf
	File ..\..\LabView_Files\LV86\libmmb0\Styx\driver-win32\usbstyx.*
	File ..\..\LabView_Files\LV86\libmmb0\Styx\driver-win32\libusb0.*
	Push "$INSTDIR\driver"
	Push "$INSTDIR\driver\nivisa5509.inf"
	Push "USB\VID_0451&PID_9001"
	Call InstallUpgradeDriver
	Push "$INSTDIR\driver"
	Push "$INSTDIR\driver\usbstyx.inf"
	Push "USB\VID_0451&PID_5718"
	Call InstallUpgradeDriver
	SetOutPath "$SYSDIR"
	SetOverwrite ifnewer
	File ..\..\LabView_Files\LV86\libmmb0\Styx\driver-win32\libusb0.dll
SectionEnd

;-------------------------------------------------------------------------
; Install LabView Runtime Engine
# LV runtime -- define WITH_LVRT to activate

!ifdef WITH_LVRT 
  !define NI_DOWNLOADS "..\..\..\National_Instruments_Downloads"
  !define LVRT_MSIDIR "LabVIEW\8.6.1\English\Products"
  !define VISART_MSIDIR "NI-VISA\4.0\products\visa\runtime"
; !define VISART_MSIDIR "NI-VISA\4.5a\Products"

Section "LabVIEW Runtime Engine" SectionRuntime
#	SectionIn RO
	SectionSetFlags SectionRuntime SF_SELECTED=1

# Install different components of the LabVIEW Runtime Engine
#	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\Datasocket\DSC.DS.450" DataSocket.msi
	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\LabVIEW_Deployable_License_86\LVDepLic" NIDepLic.msi
	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\LabVIEW_Runtime_Engine_86\lvrte" lv86runtime.msi
	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\MDFSupport\MDF" EULADepot.msi
	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\MDFSupport\MDF" MDFSupport.msi
	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\MetaUninstaller\MU" MetaUninstaller.msi
	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\MKL\MKL700" mkl.msi
#	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\MXS" mxs.msi
	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\NI_License_Manager\nilm" nilm.msi
#	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\NI_Logos\logos500" logos.msi
	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\NI-RPC" rpcSetup.msi
#	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\NI-RPC_RT" rpcSetupLVRT.msi
	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\NI-USI" NI-USI.msi
#	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\OPC_Support\opcsupp.msi" opcsupp.msi
	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\Service_Locator\svcloc" svcloc.msi
#	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\TDMS\tdms" tdms.msi
#	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${LVRT_MSIDIR}\Variable_Engine\ve220" nive.msi
# below for VISA 4.0
	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} ${VISART_MSIDIR} NIVISAruntime.msi
# below for VISA 4.5
;	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${VISART_MSIDIR}\MStudioCommon2008" MstudioCommon.2008.msi
;	!insertmacro InstallLVRTComponent ${NI_DOWNLOADS} "${VISART_MSIDIR}\NI-VISA_Runtime" NIVISAruntime.msi
	
SectionEnd
!endif

;-------------------------------------------------------------------------
; Update INI files

Section -UpdateINI_VersionFiles
# Update INI file
#	Update search path with installed location
	ReadINIStr $9 "$INSTDIR\ADS1298EVM.ini" ADS1298EVM viSearchPath
	StrCpy $iniSearchPath $9
	StrCpy $iniSearchPath "$iniSearchPath $INSTDIR\*; $INSTDIR\CommonFiles\*; $INSTDIR\libmmb0\*; $INSTDIR\lib1298\*;"
	WriteINIStr "$INSTDIR\ADS1298EVM.ini" ADS1298EVM viSearchPath $iniSearchPath
#	Update DXP version information
	WriteINIStr "$INSTDIR\ADS1298EVM.ini" ADS1298EVM Version "${VERSION}"
	WriteINIStr "$INSTDIR\ADS1298EVM.ini" ADS1298EVM Build "${BUILD}"
	WriteINIStr "$INSTDIR\ADS1298EVM.ini" ADS1298EVM Date ${__DATE__}
	
SectionEnd

;-------------------------------------------------------------------------
; Create Icon and Shortcuts

Section -Icons_Create
SetOutPath "$INSTDIR"
WriteUninstaller "$INSTDIR\uninstall.exe"

# Create an DXP folder and appropriate shortcuts in the Windows Start Menu
!ifdef REG_START_MENU
  !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
  CreateDirectory "$SMPROGRAMS\$SM_Folder"
  CreateShortCut "$SMPROGRAMS\$SM_Folder\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}"
  CreateShortCut "$SMPROGRAMS\$SM_Folder\Uninstall ${APP_NAME}.lnk" "$INSTDIR\uninstall.exe"
  !insertmacro MUI_STARTMENU_WRITE_END
!endif

# Create an DXP folder and appropriate shortcuts in the Windows Start Menu
!ifndef REG_START_MENU
  CreateDirectory "$SMPROGRAMS\ADS1298ECG"
  CreateShortCut "$SMPROGRAMS\ADS1298ECG\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}"
  CreateShortCut "$SMPROGRAMS\ADS1298ECG\Uninstall ${APP_NAME}.lnk" "$INSTDIR\uninstall.exe"
!endif

# Prompt for creating shortcut on desktop  
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Would you like to create a shortcut on your desktop?" IDNO +2
  CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${MAIN_APP_EXE}"

SectionEnd

;-------------------------------------------------------------------------
; Un-Installer
# Creation of the un-installer for DXP

Section Uninstall
${INSTALL_TYPE}

Delete "$INSTDIR\${MAIN_APP_EXE}"
Delete "$INSTDIR\uninstall.exe"

Delete "$INSTDIR\*.ini"
Delete "$INSTDIR\*.dll"

!ifdef REG_START_MENU
  !insertmacro MUI_STARTMENU_GETFOLDER "Application" $SM_Folder
  Delete "$SMPROGRAMS\$SM_Folder\${APP_NAME}.lnk"
  Delete "$SMPROGRAMS\$SM_Folder\Uninstall ${APP_NAME}.lnk"
!ifdef WEB_SITE
  Delete "$SMPROGRAMS\$SM_Folder\${APP_NAME} Website.lnk"
!endif
  RmDir "$SMPROGRAMS\$SM_Folder"
  Delete "$DESKTOP\${APP_NAME}.lnk"
!endif

!ifndef REG_START_MENU
  Delete "$SMPROGRAMS\ADS1298ECG\${APP_NAME}.lnk"
  Delete "$SMPROGRAMS\ADS1298ECG\Uninstall ${APP_NAME}.lnk"
!ifdef WEB_SITE
  Delete "$SMPROGRAMS\ADS1298ECG\${APP_NAME} Website.lnk"
!endif
  RmDir "$SMPROGRAMS\ADS1298ECG-FE"
  Delete "$DESKTOP\${APP_NAME}.lnk"
!endif

# Remove files and directories
RMDir /r "$INSTDIR"
SectionEnd
