Subversion Repositories DevTools

Rev

Blame | Last modification | View Log | RSS feed

;------------------------------------------------------------------------------
;
;   NSIS Installer script file for jats-installer
;
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
;
;   Include Modern UI
;   Provides an Installer that is similar to many other Windows-XP installers
;
;------------------------------------------------------------------------------

!include "MUI2.nsh"
!include "WordFunc.nsh"
!include "FileFunc.nsh"
!include "LogicLib.nsh"
;*****************
; Include this if you want edit dialogs to ask questions
!include "VixPageEditDialogs.nsh"
;*****************
!include "VixMacros.nsh"

!insertmacro VersionCompare

; Use String Functions
;*****************
; Include this if you want to use the ${textreplace::ReplaceInFile} macro to replace tags in files
!include "TextReplace.nsh"
;*****************
;!include "StrFunc.nsh"
;${StrRep}
!include "nsis_path.nsh"

;------------------------------------------------------------------------------
;
;   Set installer parameters - shown on various dialogs during the installation.
;
;   The following fields are pre-set by JATS (but can be overriden) :
;       Name            Package name and version, shown as package description.
;       BrandingText    Company name, shown near the bottom of the file installation dialog.
;       Caption         Package name, shown on title bar of all dialogs.
;
;------------------------------------------------------------------------------


;------------------------------------------------------------------------------
;
;   Set installer properties - shown when user hovers over executeable or
;   right clicks on 'properties'.
;
;   The following fields are pre-set by JATS (but can be overriden) :
;       CompanyName
;       LegalTrademarks
;       LegalCopyright
;       FileVersion
;
;   The following field must be set :
;       FileDescription
;
;------------------------------------------------------------------------------

!define          PACKAGE_LONGNAME       "JATS Build Tool"
!define          PACKAGE_DESCRIPTION    "VIX JATS Build and Make tools"

; Fudge the name seen when the package is installed
!undef           GBE_PACKAGE
!define          GBE_PACKAGE            "Jats"

VIAddVersionKey "FileDescription" "${PACKAGE_DESCRIPTION}"

;------------------------------------------------------------------------------
;
;   Set the installation folder - 
;
;------------------------------------------------------------------------------

;       Start with a sane default in case the registry key is not set

;InstallDir "$PROGRAMFILES\Vix\Jats"
;InstallDir "$LOCALAPPDATA\Vix\Jats"
InstallDir "C:\Jats"

;       Get installation folder from registry if available
!define InstallDirReg "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GBE_PACKAGE}"
InstallDirRegKey HKLM "${InstallDirReg}" "InstallLocation"


;------------------------------------------------------------------------------
;
;   Request application privileges for Windows Vista/7
;   Need admin privileges to modify registry, otherwise use user
;------------------------------------------------------------------------------

RequestExecutionLevel admin

;------------------------------------------------------------------------------
;
;   Modern Interface Settings
;
;------------------------------------------------------------------------------

#!define MUI_ABORTWARNING
 !define MUI_ICON                       "${GBE_NSISDATA}\VixIcon.ico"
 !define MUI_UNICON                     "${GBE_NSISDATA}\VixIcon.ico"
 !define MUI_HEADERIMAGE
 !define MUI_HEADERIMAGE_BITMAP         "${GBE_NSISDATA}\VixHeader.bmp"
 !define MUI_WELCOMEFINISHPAGE_BITMAP   "${GBE_NSISDATA}\VixPanel40.bmp"
 !define MUI_UNWELCOMEFINISHPAGE_BITMAP "${GBE_NSISDATA}\VixPanel40.bmp"
 !define MUI_FINISHPAGE_NOAUTOCLOSE
 !define MUI_UNFINISHPAGE_NOAUTOCLOSE
 !define MUI_WELCOMEPAGE_TITLE_3LINES
 !define MUI_FINISHPAGE_TITLE_3LINES

;------------------------------------------------------------------------------
;
;   Pages
;   List of Pages for the Modern UI to show
;
;------------------------------------------------------------------------------

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS

!define MUI_PAGE_CUSTOMFUNCTION_PRE CheckInstDirReg
!insertmacro MUI_PAGE_DIRECTORY

; User configuration
Var DpkgArchive
Var PerlPath

!define      VIX_PAGE_EDIT_TEXT     "JATS Configuration"
!define      VIX_PAGE_EDIT_SUBTEXT  "Specify Paths"
!define      VIX_PAGE_EDIT_TITLE    "Specify a directory that provides 'dpkg_archive'.$\r$\nNormally this will be a network share.$\r$\nThis installer will not mount this path."
!insertmacro VIX_PAGE_EDIT2 "dpkg_archive" $DpkgArchive "Perl Path" $PerlPath

!insertmacro MUI_PAGE_INSTFILES


!define MUI_FINISHPAGE_TEXT "JATS has been installed but may require some configuration by editing $INSTDIR\jats_config.bat"

!define MUI_FINISHPAGE_RUN_TEXT "Edit config with notepad"
!define MUI_FINISHPAGE_RUN "notepad.exe"
!define MUI_FINISHPAGE_RUN_PARAMETERS "$INSTDIR\jats_config.bat"
!define MUI_FINISHPAGE_RUN_NOTCHECKED
;!define MUI_FINISHPAGE_SHOWREADME_TEXT "Read Me"
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\jats.html"
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

;------------------------------------------------------------------------------
;
;   Languages
;   System will select default language
;
;------------------------------------------------------------------------------

!insertmacro MUI_LANGUAGE "English"


;------------------------------------------------------------------------------
;
;   Installer Sections
;   Each section will show up as a 'component', if that page is shown
;
;------------------------------------------------------------------------------
CRCCheck on ; (can be off)

;------------------------------------------------------------------------------
;
;   Display stuff
;
;------------------------------------------------------------------------------
Section -

    DetailPrint "INSTDIR: $INSTDIR"
    DetailPrint "dpkg_archive: $DpkgArchive"
    DetailPrint "Perl Dir: $PerlPath"

SectionEnd

;------------------------------------------------------------------------------
;
;   Install Prerequisites
;
;------------------------------------------------------------------------------
Section "Active State Perl 5.8.9" SecAsPerl
  ClearErrors
  DetailPrint "---- Install Prerequisites section"
  SetOutPath $INSTDIR

  File "ActivePerl-5.8.9.827-MSWin32-x86-291969.msi"
  ExecWait '"msiexec" /i "$INSTDIR\ActivePerl-5.8.9.827-MSWin32-x86-291969.msi"'
  ${IfThen} ${Errors} ${|} Abort "Error installing ActiveState Perl" ${|}

  Delete "$INSTDIR\ActivePerl-5.8.9.827-MSWin32-x86-291969.msi"

SectionEnd

;------------------------------------------------------------------------------
;
;   Section to Install application files & configure
;
;------------------------------------------------------------------------------
Section "Jats Script (required)" SecJats

    DetailPrint "---- Install Application section"
    ClearErrors

    StrCpy $0 "$PerlPath\bin\perl.exe"
    ${IfNot} ${FileExists} $0
        MessageBox MB_ICONEXCLAMATION|MB_OKCANCEL "$0 not found" /SD IDCANCEL IDOK +4
        DetailPrint "Abort: File not found: $0"
        Abort
    ${EndIf}

    ;   Does not appear to work on a network share
    ;   
    ;StrCpy $0 "$DpkgArchive"
    ;${IfNot} ${FileExists} $0 
    ;    MessageBox MB_ICONEXCLAMATION|MB_OKCANCEL "$0 not found" /SD IDCANCEL IDOK +4
    ;    DetailPrint "Abort: File not found: $0"
    ;    Abort
    ;${EndIf}

    SetOutPath "$INSTDIR"
    File "jats.bat"
    File "jats.html"

    ${If} ${FileExists} "jats_config.bat"
        DetailPrint "Retain original jats_config.bat"
        File /oname=jats_config_new.bat jats_config.bat
    ${Else}
        SetOverwrite off
        File "jats_config.bat"
        SetOverwrite on
    ${EndIf}


    ${IfThen} ${Errors} ${|} Abort "Error installing one or more application files" ${|}

    StrCpy $2 "$INSTDIR\jats.bat"
    DetailPrint "Configuring $2"
    ${textreplace::ReplaceInFile}  $2  $2  "<REPLACETAG-DPKG_ARCHIVE>"  $DpkgArchive   "/S=1" $1
    ${textreplace::ReplaceInFile}  $2  $2  "<REPLACETAG-PERLDIR>"  $PerlPath   "/S=1" $1
    ${textreplace::ReplaceInFile}  $2  $2  "<REPLACETAG-PACKAGE>"  ${GBE_PACKAGE}   "/S=1" $1
    ${textreplace::ReplaceInFile}  $2  $2  "<REPLACETAG-VERSION>"  ${GBE_VERSION_FULL}   "/S=1" $1

    StrCpy $2 "$INSTDIR\jats.html"
    DetailPrint "Configuring $2"
    ${textreplace::ReplaceInFile}  $2  $2  "<REPLACETAG-DPKG_ARCHIVE>"  $DpkgArchive   "/S=1" $1
    ${textreplace::ReplaceInFile}  $2  $2  "<REPLACETAG-INSTDIR>"       $INSTDIR   "/S=1" $1
    ${textreplace::ReplaceInFile}  $2  $2  "<REPLACETAG-PERLDIR>"  $PerlPath   "/S=1" $1


    ${IfThen} ${Errors} ${|} Abort "Error configuring $2" ${|}


SectionEnd

;------------------------------------------------------------------------------
;
;   Configuration section
;
;------------------------------------------------------------------------------
Section "-Config"

    DetailPrint "---- Install Config section"
    ; make sure plugings dir is initialised
    InitPluginsDir
    ClearErrors

    DetailPrint "Adding to Path"
    ${nsis_path::PrependSystemPath} "$INSTDIR"

    ${IfThen} ${Errors} ${|} Abort "Error Modifying PATH Environment" ${|}

    ; make sure windows knows about the change
    DetailPrint "Notify OS of change to PATH"
    SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=3000

SectionEnd


;------------------------------------------------------------------------------
;
;   Section to create the Core of the ininstaller 
;   This will be hidden and will be installed first
;
;------------------------------------------------------------------------------
Section "-Core"

    ; Create uninstaller and copy it into the install directory
    DetailPrint "---- Install -Core section"

    ; Use default uninstaller location and name and registry keys
    ; defines 
    ; VIX_UNISTALL_EXE          - The uninstaller location
    ; VIX_UNINSTALL_KEY         - The uninstall registry key where all the uninstall values are written
    ${VIX_CREATE_UNINSTALLER_AND_REGISTRY}
    ${IfThen} ${Errors} ${|} Abort "Error creating uninstaller information" ${|}

SectionEnd


;------------------------------------------------------------------------------
;
;   Uninstall Configuration section first
;
;------------------------------------------------------------------------------
Section "-un.Config"

    DetailPrint "---- Uninstall Config section"
    ClearErrors

    ; Remove path elements 
    DetailPrint "Remove from PATH: $INSTDIR"
    ${nsis_path::DeleteSystemPath} "$INSTDIR"
    ${IfThen} ${Errors} ${|} Abort "Error Modifying PATH Environment" ${|}

    DetailPrint "Notify OS of change to PATH"
    SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=3000
     
SectionEnd

;------------------------------------------------------------------------------
;
;   Uninstaller Sections
;   Uninstaller for files installed by the user
;
;------------------------------------------------------------------------------

Section "un.Application"

    DetailPrint "---- UnInstall Application section"
     
    ; Remove files that we installed

    Delete "$INSTDIR\jats.bat"
    Delete "$INSTDIR\jats.html"
    Delete "$INSTDIR\jats_config_new.bat"
    Delete "$INSTDIR\jats_config.bat"

    ; Dont recurse, just remove if empty
    RmDir $INSTDIR

    DetailPrint "---- UnInstall Application section done"
SectionEnd


;------------------------------------------------------------------------------
;
;   Uninistaller section to uninstall keys
;   That have been installed as a part of the core installer
;
;------------------------------------------------------------------------------
Section "-un.Core"

    DetailPrint "---- Uninstall -Core section"

    ; Delete Uninstaller and associated uninstall registry 
    ${VIX_REMOVE_UNINSTALLER_AND_REGISTRY}

    ; Dont recurse, just remove if empty
    RmDir $INSTDIR
    RmDir "$INSTDIR\.."

SectionEnd


;--------------------------------
;Descriptions

!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${SecAsPerl} "ActiveState Perl is required in order to run Jats."
  !insertmacro MUI_DESCRIPTION_TEXT ${SecJats} "Install a batch file that will invoke JATS held on a network share"
!insertmacro MUI_FUNCTION_DESCRIPTION_END

;--------------------------------
Function .onInit

    StrCpy $DpkgArchive "v:\dpkg_archive"
    StrCpy $PerlPath "c:\perl"
    DetailPrint "---- On Init"

    IntOp $0 ${SF_SELECTED} | ${SF_RO}
    SectionSetFlags ${SecJats} $0
    Call TestForPerl

    ; If a version is already installed get & set install dir used in last install as defaults for this Install
    ; otherwise INSTDIR is left as is
    ; ***** IF INSTDIR IS FIXED THIS CAN BE REMOVED *****
    ;${VIX_SETINSTDIR_IFINSTALLED}

FunctionEnd

;--------------------------------
;   Check for an installation of Perl
;   Will not check that its suitable, just that Perl.exe exists
;   Will set $PerlPath and unselect SecAsPerl  
;
Function TestForPerl
    Push $1
    StrCpy $0 0

    StrCpy $1 "C:\Perl_5.8.9\bin\perl.exe"
    IfFileExists $1 Found 0

    StrCpy $1 "C:\Perl\bin\perl.exe"
    IfFileExists $1 Found 0

    StrCpy $1 "$$PROGRAMFILES\Perl\bin\perl.exe"
    IfFileExists $1 Found 0

    StrCpy $1 "$$PROGRAMFILES32\Perl\bin\perl.exe"
    IfFileExists $1 Found 0

    StrCpy $1 "$$PROGRAMFILES64\Perl\bin\perl.exe"
    IfFileExists $1 Found End

Found:
    StrCpy $PerlPath $1 -13

    SectionGetFlags ${SecAsPerl} $1
        IntOp $1 $1 ^ ${SF_SELECTED}
    SectionSetFlags ${SecAsPerl} $1

    StrCpy $0 1

End:
    Pop $1

FunctionEnd

;--------------------------------
;   Check if a previous version exists
;   This function is used to prevent the user from installing into multiple directories
Function CheckInstDirReg

  ReadRegStr $R0 HKLM "${InstallDirReg}" "InstallLocation"
  StrCmp $R0 "" NotFound
    IfFileExists $R0 0 NotFound
        Abort ## InstallLocation present: Skip directory page!

NotFound:

FunctionEnd