;------------------------------------------------------------------------
;Modify the entries in this section for your own purposes
;
;BaseName: The base name of the iconpack
;BuildVer: Version (must be in x.x.x.x format)

!define BaseName "Tomethicons"
!define BuildVer "3.1.1.3"
!define LegalCopyright "© Thomas Elmer 2005"

; That's all that's required, you can leave the rest alone.  
; You may want to change the files in the "stuff to install" section
; if you want to include other files in the install.
; also, you can tweak things further in the section below


;------------------------------------------------------------------------
;Leave this section alone

!include "MUI.nsh"
!define MUI_WELCOMEPAGE
!define MUI_DIRECTORYPAGE
!define MUI_INSTFILESPAGE
!define MUI_FINISHPAGE
!define MUI_ABORTWARNING
!insertmacro MUI_LANGUAGE "English"


;------------------------------------------------------------------------
;possible things to tweak

;Name displayed in the installer
Name "${BaseName}"

;Name of the folder to install to.
!define IconFolder "${BaseName}"

;The install file to write
OutFile "${BaseName}_Installer.exe"

;Anyone feel free to add languages :)

;Various other version info for the installer
VIProductVersion "${BuildVer}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "${LegalCopyright}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "${BaseName} Trillian icon pack"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${BuildVer}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "${BaseName}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "${BuildVer}"

;Text used in the installer
LangString MUI_TEXT_DIRECTORY_SUBTITLE ${LANG_ENGLISH} "Choose the Trillian 3+ folder in which to install $(^Name)."
LangString MUI_TEXT_WELCOME_INFO_TITLE ${LANG_ENGLISH} "Welcome to the $(^Name) installer (version ${BuildVer})"
LangString MUI_TEXT_WELCOME_INFO_TEXT ${LANG_ENGLISH} "This wizard will guide you through the installation of $(^Name).\r\n\r\n'$(^Name)' is an icon pack for Trillian 3.0+.\r\n\r\n$_CLICK"
LangString MUI_TEXT_FINISH_INFO_TITLE ${LANG_ENGLISH} "Setup Completed"
LangString ^DirText ${LANG_ENGLISH} "Setup will install $(^Name) under the following Trillian folder.  To install in a different folder, click Browse and select another folder.  (Note: you MUST select a folder where Trillian 3.0+ is installed.). $_CLICK"


;------------------------------------------------------------------------

; The default installation directory
InstallDir "C:\Program files\Trillian"

;Get install folder from registry if available
InstallDirRegKey HKLM \
                 "Software\Microsoft\Windows\CurrentVersion\Uninstall\Trillian" \
                 "UninstallString"

; automatically close the installer when done.
AutoCloseWindow false

; hide the "show details" box
ShowInstDetails hide
InstallColors 00ffff 000000
InstProgressFlags smooth colored
SetFont "Microsoft Sans Serif" "8"

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES


;------------------------------------------------------------------------

; The stuff to install

Section ""
	SetOutPath "$INSTDIR\stixe\icons\${IconFolder}"

	;Modify these if you want to add more files not included in this set
	File "*.ico"
	File "*.png"
	File "*.dtd"
	File "*.xml"
	File "*.ini"
	File "*.txt"
SectionEnd

;Display the Finish header
!insertmacro MUI_PAGE_FINISH


;------------------------------------------------------------------------
;Test that the installation directory is a Trillian 3+ directory

Function .onVerifyInstDir
	Push $R0
	Push $R1
	Push $R2
	Push $R3
	Push $R4
	Push $R5
	
	IfFileExists "$INSTDIR\trillian.exe" Good
		Abort
	Good:

	GetDLLVersion "$INSTDIR\trillian.exe" $R0 $R1
	IntOp $R2 $R0 / 0x00010000
	IntOp $R3 $R0 & 0x0000FFFF
	IntOp $R4 $R1 / 0x00010000
	IntOp $R5 $R1 & 0x0000FFFF
	IntCmp $R2 3 VerEnd VerNewer VerEnd
	VerNewer:
		MessageBox MB_OK "Iconpacks require Trillian 3.0+"
		Abort
	VerEnd:

	Pop $R5
	Pop $R4
	Pop $R3
	Pop $R2
	Pop $R1
	Pop $R0
FunctionEnd


;------------------------------------------------------------------------
;Initialize to the directory pointed to by the Trillian uninstall path

Function .onInit
;GetTrillianInstPath

  Push $0
  Push $1
  Push $2

  ReadRegStr $0 HKLM \
     "Software\Microsoft\Windows\CurrentVersion\Uninstall\Trillian" \ 
     "UninstallString"
  StrCmp $0 "" fin
    StrCpy $1 $0 1 0 ; get firstchar
    StrCmp $1 '"' "" getparent 
      ; if first char is ", let's remove "'s first.
      StrCpy $0 $0 "" 1
      StrCpy $1 0
      rqloop:
        StrCpy $2 $0 1 $1
        StrCmp $2 '"' rqdone
        StrCmp $2 "" rqdone
        IntOp $1 $1 + 1
        Goto rqloop
      rqdone:
      StrCpy $0 $0 $1
    getparent:
    ; the uninstall string goes to an EXE, let's get the directory.
;//***** -23
    StrCpy $1 -1
    gploop:
      StrCpy $2 $0 1 $1
      StrCmp $2 "" gpexit
      StrCmp $2 "\" gpexit
      IntOp $1 $1 - 1
      Goto gploop
    gpexit:
    StrCpy $0 $0 $1

    StrCmp $0 "" fin
    IfFileExists $0\trillian.exe fin
      StrCpy $0 ""
  fin:

	StrCmp $0 "" trildefault
		StrCpy $INSTDIR "$0"
		Goto skip
	trildefault:
		IfFileExists "c:\program files\trillian\trillian.exe" trildefexists
			;you might set a default $INSTDIR here
			Goto skip
		trildefexists:
			StrCpy $0 "c:\program files\trillian"
			StrCpy $INSTDIR "$0"
	skip:

  Pop $2
  Pop $1
  Exch $0
  
FunctionEnd
