;!define INC_DOT_NET "TEST"

!include "MUI.nsh"
!include "Sections.nsh"

;------------------------------------
; Add Defines Here
;------------------------------------

!define MUI_PRODUCT "ZXFusion"
!define MUI_VERSION "4.0"
!define MUI_UI "${NSISDIR}\Contrib\UIs\default.exe"
!define MUI_ICON "COMMON\ICONS\INST.ICO"
!define MUI_UNICON "COMMON\ICONS\UNINST.ICO"
!define MUI_CHECKBITMAP "COMMON\GRAPHICS\Checks_Sajal_Nails.bmp"
!define MUI_BRANDINGTEXT "Atcom Computer Services (c) 2000-2003 "


!define MUI_WELCOMEPAGE
   ;!define MUI_SPECIALBITMAP "COMMON\GRAPHICS\WELCOME.BMP"
   !define MUI_SPECIALBITMAP "COMMON\GRAPHICS\zxflogorot.bmp"

!define MUI_CUSTOMPAGECOMMANDS

!define MUI_COMPONENTSPAGE
  !define MUI_COMPONENTSPAGE_NODESC
  ;!define MUI_HEADERBITMAP "COMMON\GRAPHICS\BANNER.BMP"
  !define MUI_HEADERBITMAP "COMMON\GRAPHICS\zxflogo.BMP"

!define MUI_DIRECTORYPAGE
  !define MUI_CUSTOMFUNCTION_DIRECTORY_PRE DirectoryPre
  !define MUI_CUSTOMFUNCTION_DIRECTORY_SHOW DirectoryShow
  !define MUI_CUSTOMFUNCTION_DIRECTORY_LEAVE DirectoryLeave

!define MUI_CUSTOMFUNCTION_INSTFILES_LEAVE InstFilesLeave

!define MUI_CUSTOMFUNCTION_COMPONENTS_LEAVE ComponentPost


!define MUI_FINISHPAGE
  ;!define MUI_FINISHPAGE_RUN "$2\ZX Fusion.exe"
  !define MUI_FINISHPAGE_NOREBOOTSUPPORT

!define MUI_ABORTWARNING
!define MUI_UNINSTALLER

!define DIR_ZXFUSION "1"
!define DIR_EXCHANGE "2"


;-------------------------------------
; Macro Insertions Here
;-------------------------------------
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_PAGECOMMAND_WELCOME
!insertmacro MUI_PAGECOMMAND_COMPONENTS
!insertmacro MUI_PAGECOMMAND_DIRECTORY
!insertmacro MUI_PAGECOMMAND_DIRECTORY
!insertmacro MUI_PAGECOMMAND_INSTFILES
!insertmacro MUI_PAGECOMMAND_FINISH



;--------------------------------
;Reserve Files

  ;Things that need to be extracted on first (keep these lines before any File command!)
  ;Only useful for BZIP2 compression
  !insertmacro MUI_RESERVEFILE_WELCOMEFINISHPAGE

;-------------------------------------
; Config Section
;-------------------------------------
 ;  Outfile "ZXFSetup.exe"
   ShowInstDetails "nevershow"
   ShowUninstDetails "nevershow"
   CRCCheck on
   XPStyle On





;================================================================================
; Section Routines
;================================================================================
Section "-General Program Files"

SectionEnd

!IfDef INC_DOT_NET
   Section ".Net FrameWork 1.1" DNF
     SetShellVarContext ALL
     AddSize 30720

     CreateDirectory "$2\FrameWork"
     SetOutPath "$2\FrameWork"
     File "COMMON\FRAMEWORK\DOTNETFX.EXE"

   SectionEnd
!EndIf
Section "ZXFusion" ZXF
   SetShellVarContext ALL
   SetOutPath "$2"
   File "COMMON\ZXFusion\ZX Fusion.exe"
   File "COMMON\ZXFusion\Interop.ABCToolBox.dll"
   File "COMMON\ICONS\INST.ICO"
   File "COMMON\ICONS\UNINST.ICO"
   File "COMMON\ICONS\CONFIG.ICO"

   SetOutPath "$SYSDIR"
   File "COMMON\ZXFusion\ABCToolBox.dll"
   RegDLL "$SYSDIR\ABCToolBox.dll"
   RegDLL "$2\Interop.ABCToolBox.dll"



   ;---------------------------------------------
   ; Create the menu shortcuts
   ;---------------------------------------------
   CreateDirectory "$SMPROGRAMS\ZetaFax"
   CreateShortCut "$SMPROGRAMS\ZetaFax\ZXFusion Engine.lnk" "$2\ZX Fusion.exe" "" "" "" SW_SHOWMINIMIZED
   CreateShortCut "$SMPROGRAMS\ZetaFax\ZXFusion Configuration.lnk" "$2\ZX Fusion.exe" "/C"
   ; CreateShortCut "$SMPROGRAMS\Startup\ZXFusion Engine.lnk" "$2\ZX Fusion.exe" "" "" "" SW_SHOWMINIMIZED

   Call WriteZXFUnInstall

   WriteUninstaller "$WINDIR\ZXFUn.exe"
SectionEnd

Section "ZetaFax not found - Will not install ZXFusion" NZXF

SectionEnd


SubSection /E "Microsoft Exchange psuedo connector"
   Section "Exchange Server 5.5" Exch55
      SetShellVarContext ALL
      CreateDirectory "$3"
      CreateDirectory "$3\IN"
      CreateDirectory "$3\OUT"
      CreateDirectory "$3\ARCHIVE"
      SetOutPath "$3\OUT"
      File "COMMON\EXCH55\Version.dat"
      SetOutPath "$3"
      File "COMMON\ICONS\INST.ICO"
      File "COMMON\ICONS\UNINST.ICO"
      Call WriteExchUnInstall
   SectionEnd
   Section "Exchange Server 2000" Exch2K
      SetShellVarContext ALL
      CreateDirectory "$3"
      CreateDirectory "$3\IN"
      CreateDirectory "$3\OUT"
      CreateDirectory "$3\ARCHIVE"
      SetOutPath "$3\OUT"
      File "COMMON\EXCH2K\Version.dat"
      SetOutPath "$3"
      File "COMMON\ICONS\INST.ICO"
      File "COMMON\ICONS\UNINST.ICO"
      Call WriteExchUnInstall
   SectionEnd
SubSectionEnd

SubSection /E "Documentation"
   Section "ZXFusion User Manual" ZXFU
     SetShellVarContext ALL
     CreateDirectory "$2\Manuals"
     SetOutPath "$2\Manuals"
     File "COMMON\ZXFusion\Docs\Manual BF.PDF"
     File "COMMON\ZXFusion\Docs\Manual SP.PDF"
   SectionEnd
SubSectionEnd

SubSection /E "Supporting Files" SPF
   Section "Internet Explorer 6.0 With SP1" IE6
       MessageBox MB_OK|MB_ICONINFORMATION "After Internet Explorer 6.0 has been installed, you will have to re-run the installation program."
       ExecWait "$EXEDIR\Support\IE60SP1\IE6SETUP"
   SectionEnd
   Section "Windows 2000 Service Pack 3" WIN2KSP3
       MessageBox MB_OK|MB_ICONINFORMATION "After Internet Explorer 6.0 has been installed, you will have to re-run the installation program."
       ExecWait "$EXEDIR\SUPPORT\WIN2K\SP3\i386\update\Update.exe"
   SectionEnd
   Section "Windows NT 4.0 Service Pack 6A" WINNTSP6A
       MessageBox MB_OK|MB_ICONINFORMATION "After Internet Explorer 6.0 has been installed, you will have to re-run the installation program."
       ExecWait "$EXEDIR\SUPPORT\NT40\SP6A\update\update.exe"
   SectionEnd
SubSectionEnd


;================================================================================
; Installer Global Call Back Functions
;================================================================================

Function .onInit
; Must set $INSTDIR here to avoid adding ${MUI_PRODUCT} to the end of the
; path when user selects a new directory using the 'Browse' button.
   StrCpy $INSTDIR "$PROGRAMFILES\ACS\${MUI_PRODUCT}"
   StrCpy $8 "NONE"
   SectionSetFlags ${IE6} 0
   SectionSetFlags ${NZXF} 0
   SectionSetFlags ${WINNTSP6A} 0

!IfDef INC_DOT_NET
   Call IsDotNETInstalled
   Pop $0
   StrCmp $0 1 SkipDotNet AddDotNet
   AddDotNet:
      SectionSetFlags ${DNF} 1
      Goto CheckForSupport
   SkipDotNet:
      SectionSetFlags ${DNF} 0
      SectionSetText ${DNF} "Upgrade to .Net Framework 1.1"
      Goto CheckForSupport
!EndIf
   Goto CheckForSupport

   CheckForSupport:
      ifFileExists "$EXEDIR\SUPPORT\*.*" FunctionCalls DisableALL

   DisableAll:
      SectionSetText ${IE6} ""
      SectionSetText ${WIN2KSP3} ""
      SectionSetText ${WINNTSP6A} ""
      SectionSetText ${SPF} ""
      Goto Done

   FunctionCalls:
      Call CheckForWIN2KSP3
      Call CheckForWINNTSP6A
      Call CheckForIE6
      Call CheckForZXFusion
   Done:

FunctionEnd

;-------------------------------------------------------
; User makes his/her choices
;-------------------------------------------------------
Function .onSelChange

  Push $8
  SectionGetFlags ${Exch55} $0
  SectionGetFlags ${Exch2K} $1

  StrCmp $8 "NONE" CheckForExch55
  StrCmp $8 "55" CheckForExch2k
  StrCmp $8 "2K" CheckForExch55


  Goto CheckForExch55

  CheckForExch55:
       IntCmp $0 1 DeSelExch2K
       Goto CheckForExch2K

  CheckForExch2k:
       IntCmp $1 1 DeSelExch55
       Goto CheckComplete

  DeSelExch2k:
       StrCpy $8 "55"
       SectionSetFlags ${Exch2k} 0
       Goto CheckComplete

  DeSelExch55:
       StrCpy $8 "2K"
       SectionSetFlags ${Exch55} 0
       Goto CheckComplete


  CheckComplete:
       IntCmp $0 0 ChkEx2K
       Goto Finished
     ChkEx2K:
       IntCmp $1 1 Finished
       StrCpy $8 "NONE"

  Finished:


FunctionEnd

Function .onVerifyInstDir
  StrCmp $9 "2" DataPath All

  DataPath:
  ;all valid if UNC
    StrCpy $R2 $INSTDIR 2
    StrCmp $R2 "\\" PathOK
  All:
  ; Invalid path if root
    Push $INSTDIR
    call GetRoot
    Pop $R1
    StrCmp $R1 $INSTDIR "" PathOK
    Abort
  PathOK:

FunctionEnd

Function .onInstSuccess

!IfDef INC_DOT_NET
   SectionGetFlags ${DNF} $1
   IntCmp $1 1 RunDNFConfig
   Goto DNFDone
   RunDNFConfig:
     Exec "$2\FRAMEWORK\DOTNETFX.exe"
     Goto DNFDone
   DNFDone:
!EndIf

   SectionGetFlags ${ZXF} $1
   IntCmp $1 1 RunZXFConfig
   Goto Done
   RunZXFConfig:
     Exec "$2\ZX Fusion.exe /C"
     Exec "$2\ZX Fusion.exe"
     Goto Done

   Done:


FunctionEnd



;================================================================================
; Installer Form Call Back Functions
;================================================================================

Function ComponentPost
  StrCpy $6 ${DIR_ZXFUSION}
  StrCpy $7 ${DIR_ZXFUSION}
FunctionEnd

Function InstFilesLeave
  StrCpy $6 ${DIR_EXCHANGE}
  StrCpy $7 ${DIR_EXCHANGE}
FunctionEnd

Function DirectoryPre

  StrCmp $6 ${DIR_ZXFUSION} CheckZXF
  StrCmp $6 ${DIR_EXCHANGE} CheckExch55
  Goto ErrorShow
  CheckZXF:
     SectionGetFlags ${ZXF} $0
     IntCmp $0 1 Continue
     StrCpy $9 "2"
     StrCpy $6 ${DIR_EXCHANGE}
     Abort
     Goto Continue
  CheckExch55:
     SectionGetFlags ${Exch55} $0
     IntCmp $0 1 Continue CheckExch2K CheckExch2K
  CheckExch2K:
     SectionGetFlags ${Exch2K} $0
     IntCmp $0 1 Continue
     StrCpy $9 "1"
     StrCpy $6 ${DIR_ZXFUSION}
     Abort
     Goto Continue
  ErrorShow:
     MessageBox MB_OK|MB_ICONSTOP "An Error has occured during the preloading of the directory pages. $\n Please contact your software vendor"
  Continue:

FunctionEnd


Function DirectoryShow

  StrCpy $7 $6
  StrCmp $6 "1" AppDirectoryPage
  StrCmp $6 "2" DataDirectoryPage
  StrCmp $6 "3" EndDirectoryShow

  Goto ErrorShow

  AppDirectoryPage:
    !insertmacro MUI_INNERDIALOG_TEXT 1041 "Destination Folder"
    !insertmacro MUI_INNERDIALOG_TEXT 1019 ""
    !insertmacro MUI_INNERDIALOG_TEXT 1019 "$PROGRAMFILES\ACS\${MUI_PRODUCT}"
    !insertmacro MUI_INNERDIALOG_TEXT 1006 "Setup will install ${MUI_PRODUCT} in the following folder.$\r$\n$\r$\nTo install in a different folder, click Browse and select another folder. Click Next to continue."
    StrCpy $6 ${DIR_EXCHANGE}
    StrCpy $7 ${DIR_ZXFUSION}
    Goto EndDirectoryShow

  DataDirectoryPage:
    !insertmacro MUI_HEADER_TEXT "Choose pseudo connector folder" "Choose the folder in which to install the Microsoft Exchange pseudo connector."
    !insertmacro MUI_INNERDIALOG_TEXT 1041 "Destination Folder"
    !insertmacro MUI_INNERDIALOG_TEXT 1019 ""
    !insertmacro MUI_INNERDIALOG_TEXT 1019 "$PROGRAMFILES\ACS\EXCHSRVR\Connect\Zetafax\"
    !insertmacro MUI_INNERDIALOG_TEXT 1006 "Setup will install ${MUI_PRODUCT} - pseudo connector in the following folder.$\r$\n$\r$\nTo install in a different folder, click Browse and select another folder. Click Install to start the installation."
    StrCpy $6 ${DIR_ZXFUSION}
    StrCpy $7 ${DIR_EXCHANGE}
    Goto EndDirectoryShow

  ErrorShow:
      MessageBox MB_OK|MB_ICONSTOP "An Error Has Occurred"

  EndDirectoryShow:


FunctionEnd

Function DirectoryLeave

  StrCmp $7 ${DIR_ZXFUSION} SaveZXFDir
  StrCmp $7 ${DIR_EXCHANGE} SaveEXCHDir
  Goto EndDirectoryLeave

  SaveZXFDir:
    StrCpy $2 $INSTDIR
    StrCpy $6 ${DIR_EXCHANGE}
    StrCpy $7 ${DIR_EXCHANGE}
    Goto EndDirectoryLeave

  SaveEXCHDir:
    StrCpy $3 $INSTDIR
    StrCpy $6 ${DIR_ZXFUSION}
    StrCpy $7 ${DIR_ZXFUSION}

  EndDirectoryLeave:
FunctionEnd




;================================================================================
; User Defined Functions
;================================================================================
Function CheckForWIN2KSP3
   SectionSetFlags ${WIN2KSP3} 0
   Goto CheckSupport
   CheckSupport:
      ifFileExists "$EXEDIR\SUPPORT\*.*" CheckWin2K Disable
   CheckWin2K:
      ifFileExists "$EXEDIR\SUPPORT\WIN2K\*.*" CheckSP3 Disable
   CheckSP3:
      ifFileExists "$EXEDIR\SUPPORT\WIN2K\SP3\*.*" CheckI386 Disable
   CheckI386:
      ifFileExists "$EXEDIR\SUPPORT\WIN2K\SP3\i386\*.*" CheckUpdate Disable
   CheckUpdate:
      ifFileExists "$EXEDIR\SUPPORT\WIN2K\SP3\i386\update\*.*" CheckUpdateExe Disable
   CheckUpdateExe:
      ifFileExists "$EXEDIR\SUPPORT\WIN2K\SP3\i386\update\Update.exe" CheckComplete Disable
   Disable:
      SectionSetText ${WIN2KSP3} ""
      Goto CheckComplete
   CheckComplete:
FunctionEnd
Function CheckForWINNTSP6A
   SectionSetFlags ${WINNTSP6A} 0
   Goto CheckSupport
   CheckSupport:
      ifFileExists "$EXEDIR\SUPPORT\*.*" CheckNT40 Disable
   CheckNT40:
      ifFileExists "$EXEDIR\SUPPORT\NT40\*.*" CheckSP6A Disable
   CheckSP6A:
      ifFileExists "$EXEDIR\SUPPORT\NT40\SP6A\*.*" CheckI386 Disable
   CheckI386:
      ifFileExists "$EXEDIR\SUPPORT\NT40\SP6A\i386\*.*" CheckUpdate Disable
   CheckUpdate:
      ifFileExists "$EXEDIR\SUPPORT\NT40\SP6A\i386\update\*.*" CheckUpdateExe Disable
   CheckUpdateExe:
      ifFileExists "$EXEDIR\SUPPORT\NT40\SP6A\i386\update\Update.exe" CheckComplete Disable
   Disable:
      SectionSetText ${WINNTSP6A} ""
      Goto CheckComplete
   CheckComplete:
FunctionEnd
Function CheckForIE6
   SectionSetFlags ${IE6} 0
   Goto CheckSupport
   CheckSupport:
      ifFileExists "$EXEDIR\SUPPORT\*.*" CheckIE60SP1 Disable
   CheckIE60SP1:
      ifFileExists "$EXEDIR\SUPPORT\IE60SP1\*.*" CheckIE6SetupEXE Disable
   CheckIE6SetupEXE:
      ifFileExists "$EXEDIR\SUPPORT\IE60SP1\IE6SETUP.EXE" CheckComplete Disable
   Disable:
      SectionSetText ${IE6} ""
      Goto CheckComplete
   CheckComplete:
FunctionEnd
Function CheckForZXFusion
   Call IsZetafax
   StrCmp $0 "True" AddZXF SkipZXF
   AddZXF:
      SectionSetFlags ${ZXF} 1
      SectionSetText ${NZXF} ""
      Goto Done
   SkipZXF:
      SectionSetFlags ${ZXF} 0
      SectionSetText ${ZXF} ""
      Goto Done
   Done:
FunctionEnd


Function WriteZXFUnInstall
   ;---------------------------------------------
   ; Add the entries to create the Uninstall information in Add/Remove Programs
   ;---------------------------------------------
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "ZX Fusion" '"$2\ZX Fusion.exe"'
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "PATH_APP" "$2"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "PATH_EXH" "$3"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "DisplayName" "${MUI_PRODUCT}"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "UninstallString" "$WINDIR\ZXFUn.exe /Z"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "InstallLocation" "$2"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "DisplayIcon" "$2\UNINST.ICO"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "Publisher" "Atcom Computer Services"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "RegOwner" "Atcom Computer Services"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "RegCompany" "Atcom Computer Services"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "HelpLink" "http://www.atcom.co.za"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "DisplayVersion" "${MUI_VERSION}"
   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "NoModify" 1
   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "NoRepair" 1
FunctionEnd
Function WriteExchUnInstall

   WriteUninstaller "$WINDIR\ZXFUn.exe"
   SetOutPath "$3"
   file "COMMON\ICONS\UNINST.ICO"
   ;---------------------------------------------
   ; Add the entries to create the Uninstall information in Add/Remove Programs
   ;---------------------------------------------
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "PATH_APP" "$2"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "PATH_EXH" "$3"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "DisplayName" "${MUI_PRODUCT} - Exchange psuedo connector"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "UninstallString" "$WINDIR\ZXFUn.exe /E"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "InstallLocation" "$3"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "DisplayIcon" "$3\UNINST.ICO"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "Publisher" "Atcom Computer Services"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "RegOwner" "Atcom Computer Services"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "RegCompany" "Atcom Computer Services"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "HelpLink" "http://www.atcom.co.za"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "DisplayVersion" "${MUI_VERSION}"
   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "NoModify" 1
   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "NoRepair" 1
FunctionEnd

; GetParameters
; input, none
; output, top of stack (replaces, with e.g. whatever)
; modifies no other variables.

Function Un.GetParameters
   Push $R0
   Push $R1
   Push $R2
   StrCpy $R0 $CMDLINE 1
   StrCpy $R1 '"'
   StrCpy $R2 1
   StrCmp $R0 '"' loop
   StrCpy $R1 ' ' ; we're scanning for a space instead of a quote
   loop:
      StrCpy $R0 $CMDLINE 1 $R2
      StrCmp $R0 $R1 loop2
      StrCmp $R0 "" loop2
      IntOp $R2 $R2 + 1
      Goto loop

   loop2:
      IntOp $R2 $R2 + 1
      StrCpy $R0 $CMDLINE 1 $R2
      StrCmp $R0 " " loop2

   StrCpy $R0 $CMDLINE "" $R2
   Pop $R2
   Pop $R1
   Exch $R0
FunctionEnd

Function GetRoot
   Exch $0
   Push $1
   Push $2
   Push $3
   Push $4

   StrCpy $1 $0 2
   StrCmp $1 "\\" UNC
     StrCpy $0 $1
     Goto done

    UNC:
      StrCpy $2 3
      StrLen $3 $0
      loop:
        IntCmp $2 $3 "" "" loopend
        StrCpy $1 $0 1 $2
        IntOp $2 $2 + 1
        StrCmp $1 "\" loopend loop
      loopend:
        StrCmp $4 "1" +3
          StrCpy $4 1
          Goto loop
        IntOp $2 $2 - 1
        StrCpy $0 $0 $2

    done:
      Pop $4
      Pop $3
      Pop $2
      Pop $1
      Exch $0

FunctionEnd



 ; IsDotNETInstalled
 ;
 ; Usage:
 ;   Call IsDotNETInstalled
 ;   Pop $0
 ;   StrCmp $0 1 found.NETFramework no.NETFramework

!IfDef INC_DOT_NET

Function IsDotNETInstalled
  Push $0
  Push $1
  Push $2
  Push $3
  Push $4

  ReadRegStr $4 HKEY_LOCAL_MACHINE \
    "Software\Microsoft\.NETFramework" "InstallRoot"
  # remove trailing back slash
  Push $4
  Exch $EXEDIR
  Exch $EXEDIR
  Pop $4
  # if the root directory doesn't exist .NET is not installed
  IfFileExists $4 0 noDotNET

  StrCpy $0 0

  EnumStart:

    EnumRegKey $2 HKEY_LOCAL_MACHINE \
      "Software\Microsoft\.NETFramework\Policy"  $0
    IntOp $0 $0 + 1
    StrCmp $2 "" noDotNET

    StrCpy $1 0

    EnumPolicy:

      EnumRegValue $3 HKEY_LOCAL_MACHINE \
        "Software\Microsoft\.NETFramework\Policy\$2" $1
      IntOp $1 $1 + 1
       StrCmp $3 "" EnumStart
        IfFileExists "$4\$2.$3" foundDotNET EnumPolicy

  noDotNET:
    StrCpy $0 0
    Goto done

  foundDotNET:
    StrCpy $0 1

  done:
    Pop $4
    Pop $3
    Pop $2
    Pop $1
    Exch $0
FunctionEnd
!EndIf

Function IsZetaFax
   IfFileExists '$WINDIR\ZetaFax.ini'  FileExists FileDoesNotExist

   FileExists:
       StrCpy $0 "True"
       Goto Continue

   FileDoesNotExist:
      StrCpy $0 "False"
      Goto Continue
   Continue:



FunctionEnd

;================================================================================
; UnInstall
;================================================================================

Section Uninstall



  Call Un.GetParameters
  Pop $0


  StrCmp $0 "/E" RemoveEx
  StrCmp $0 "/Z" RemoveZX
  Goto RemoveALL

  RemoveEx:
     ReadRegStr $2 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "PATH_APP"
     ReadRegStr $3 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange" "PATH_EXH"
     StrCpy $INSTDIR "$3"
     ifFileExists "$INSTDIR\OUT" RemoveExch CompEx
     RemoveExch:
        Delete "$INSTDIR\*.*"
        Delete "$INSTDIR\ARCHIVE\*.*"
        Delete "$INSTDIR\OUT\*.*"
        Delete "$INSTDIR\IN\*.*"
        RMDir "$INSTDIR\ARCHIVE"
        RMDir "$INSTDIR\IN"
        RMDir "$INSTDIR\OUT"
        RMDir "$INSTDIR"
        Goto CompEx
     CompEx:
        DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange"
        Goto Completed
  RemoveZX:
     ReadRegStr $2 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "PATH_APP"
     ReadRegStr $3 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion" "PATH_EXH"
     StrCpy $INSTDIR "$2"
     ifFileExists "$INSTDIR" RemoveZXF CompZX
     RemoveZXF:
        UnRegDLL "$2\Interop.ABCToolBox.dll"
        Delete "$INSTDIR\*.*"
        Delete "$SMPROGRAMS\ZetaFax\ZXFusion Engine.lnk"
        Delete "$SMPROGRAMS\ZetaFax\ZXFusion Configuration.lnk"
        Delete "$SMPROGRAMS\ZetaFax\Uninstall ZXFusion.lnk"
        RMDir "$SMPROGRAMS\ZetaFax"
     CompZX:
        DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion"
        DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "ZX Fusion"
        Goto Completed


  RemoveALL:

;     StrCpy $INSTDIR "$3"
;     ifFileExists "$INSTDIR\OUT" RemoveAllE CompAllE
;     RemoveAllE:
;        Delete "$INSTDIR\*.*"
;        Delete "$INSTDIR\ARCHIVE\*.*"
;        Delete "$INSTDIR\OUT\*.*"
;        Delete "$INSTDIR\IN\*.*"
;        RMDir "$INSTDIR\ARCHIVE"
;        RMDir "$INSTDIR\IN"
;        RMDir "$INSTDIR\OUT"
;        RMDir "$INSTDIR"
;        Goto CompAllE
;     CompAllE:
;        DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion - Exchange"
;
;        StrCpy $INSTDIR "$2"
;        ifFileExists "$INSTDIR" RemoveAllZ CompAllZ
;        Goto RemoveALL
;
;     RemoveAllZ:
;        Delete "$INSTDIR\*.*"
;        Delete "$SMPROGRAMS\ZetaFax\ZXFusion Engine.lnk"
;        Delete "$SMPROGRAMS\ZetaFax\ZXFusion Configuration.lnk"
;        Delete "$SMPROGRAMS\ZetaFax\Uninstall ZXFusion.lnk"
;        RMDir "$SMPROGRAMS\ZetaFax"
;     CompAllZ:
;        DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ZXFusion"
;        Goto Completed
;
  Completed:




SectionEnd