;========================================================================
;=== Created by OwD : 15.05.2003. Last modified : 17.02.2004. ver : 3 ===
;========================================================================
;General
;=======
!define VER_NAME "X Codec Pack"
!define VER_NAMES "xcodecpack"
!define VER_MAJOR 1
!define VER_MINOR 6
!define VER_REVISION 1
!define VER_BUILD 83
!define VER_FILE "${VER_MAJOR}${VER_MINOR}${VER_REVISION}"
!define VER_DISPLAY "${VER_MAJOR}.${VER_MINOR}${VER_REVISION} build ${VER_BUILD}"

;Configuration
;=============
OutFile "${VER_NAMES}.exe"

InstallDir "$PROGRAMFILES\${VER_NAME}"
InstallDirRegKey HKLM "Software\${VER_NAME}" ""

;Header Files
;============
!include "MUI.nsh"
!include "Sections.nsh"
!include "LogicLib.nsh"

;Configuration / Names
;=====================
Name "${VER_NAME}"

;User / Variables
;================
Var STARTMENU_FOLDER

;Pages
;=====
!insertmacro MUI_PAGE_WELCOME
 !define MUI_STARTMENUPAGE_REGISTRY_ROOT HKCU
 !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\${VER_NAME}"
 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"
!insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
!insertmacro MUI_PAGE_INSTFILES

;Languages
;=========
!insertmacro MUI_LANGUAGE "English"


;Version Information
;===================
VIProductVersion "1.6.0.0"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "${VER_NAME}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "OwD Software"
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "© OwD Software"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "X Codec Pack"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${VER_FILE}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "Build Number" "${VER_BUILD}"

;Installer Sections
;==================
SubSection /e !Codecs

SubSection /e "DivX Codec"
	
Section /O "version 5.05b" SecDivX01
SectionEnd

Section "version 5.11" SecDivX02
SectionEnd

SubSectionEnd

SubSection /e "XviD Codec"

Section "version 0.92 CVS (Nic's)" SecXviD01
SectionEnd

Section /O "version 1.0 RC1 (Koepi's)" SecXviD02
SectionEnd

SubSectionEnd

SubSectionEnd

SubSection /e !Filters

Section "AC3 Filter 0.70b" SecAC3
SectionEnd

Section "Matrix Mixer 0.30b" SecMM
SectionEnd

Section "DivX AntiFreeze 0.4" SecAF
SectionEnd

Section "DivX G400 2.83" SecG400
SectionEnd

SubSectionEnd

;Installer Functions
;===================
Section -post
  SetDetailsPrint textonly
  DetailPrint "X Codec Pack | Creating shortcuts & registry entries..."
  SetDetailsPrint listonly

	SetOutPath $INSTDIR

  SectionGetFlags ${SecDivX01} $0
	SectionGetFlags ${SecDivX02} $1
	${if} $0 == 1
		WriteRegStr HKCU "Software\${VER_NAME}\Sections" "01" $0
	${else}
		WriteRegStr HKCU "Software\${VER_NAME}\Sections" "01" $1
	${endif}
  SectionGetFlags ${SecXviD01} $0
	SectionGetFlags ${SecXviD02} $1
	${if} $0 == 1
		WriteRegStr HKCU "Software\${VER_NAME}\Sections" "02" $0
	${else}
		WriteRegStr HKCU "Software\${VER_NAME}\Sections" "02" $1
	${endif}
  SectionGetFlags ${SecAC3} $0
  WriteRegStr HKCU "Software\${VER_NAME}\Sections" "03" $0
	SectionGetFlags ${SecMM} $0
  WriteRegStr HKCU "Software\${VER_NAME}\Sections" "04" $0
  SectionGetFlags ${SecAF} $0
  WriteRegStr HKCU "Software\${VER_NAME}\Sections" "05" $0
  SectionGetFlags ${SecG400} $0
  WriteRegStr HKCU "Software\${VER_NAME}\Sections" "06" $0

	WriteRegStr HKCU "Software\${VER_NAME}" "" $INSTDIR
	WriteRegStr HKCU "Software\${VER_NAME}" "Installer Language" $LANGUAGE
	WriteRegExpandStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${VER_NAME}" "UninstallString" "$INSTDIR\Uninstall.exe"
	WriteRegExpandStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${VER_NAME}" "InstallLocation" "$INSTDIR"

	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${VER_NAME}" "DisplayName" "${VER_NAME}"
	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${VER_NAME}" "DisplayIcon" "$INSTDIR\Uninstall.exe"
	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${VER_NAME}" "DisplayVersion" "${VER_DISPLAY}"
	WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${VER_NAME}" "VersionMajor" "${VER_MAJOR}"
	WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${VER_NAME}" "VersionMinor" "${VER_MINOR}${VER_REVISION}"
	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${VER_NAME}" "URLInfoAbout" "http://www.owd.go.ro"
	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${VER_NAME}}" "Publisher" "OwD Software"
	WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${VER_NAME}" "Contact" "owd@go.ro"
	WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NSIS" "NoRepair" "1"

	WriteRegStr HKLM "Software\${VER_NAME}" "" $INSTDIR
	WriteRegDWORD HKLM "Software\${VER_NAME}" "VersionMajor" "${VER_MAJOR}"
	WriteRegDWORD HKLM "Software\${VER_NAME}" "VersionMinor" "${VER_MINOR}"
	WriteRegDWORD HKLM "Software\${VER_NAME}" "VersionRevision" "${VER_REVISION}"
	WriteRegDWORD HKLM "Software\${VER_NAME}" "VersionBuild" "${VER_BUILD}"

	Call SMShortCuts
SectionEnd

Function SMShortCuts
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
    CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"
			CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
		  SectionGetFlags ${SecDivX01} $0
			${if} $0 == '1'
				CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\DivX Codec Configuration.lnk" "$INSTDIR\DivX\Config.exe"
			${endif}
			SectionGetFlags ${SecDivX02} $0
			${if} $0 == '1'
				CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\DivX Codec Configuration.lnk" "$INSTDIR\DivX\Config.exe"
			${endif}
			SectionGetFlags ${SecAC3} $0
			${if} $0 == '1'
				CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\AC3 Configuration.lnk" "$SYSDIR\ac3filter.cpl" "" "$INSTDIR\icons.icl" 3 "SW_SHOWNORMAL" "" ""
			${endif}
			SectionGetFlags ${SecMM} $0
			${if} $0 == '1'
				Call SMShortCutsMM
			${endif}
			SectionGetFlags ${SecAF} $0
			${if} $0 == '1'
				Call SMShortCutsAF
			${endif}
			SectionGetFlags ${SecG400} $0
			${if} $0 == '1'
				Call SMShortCutsG400
			${endif}
	!insertmacro MUI_STARTMENU_WRITE_END
FunctionEnd

Function SMShortCutsMM
	Call GetWindowsVersion
	Pop $R0
	Dumpstate::debug
	${Select} $R0
		${Case} "95"
			Goto win9x
		${Case} "98"
			Goto win9x
		${Case} "ME"
			Goto win9x
    ${Case} "2000"
      Goto winnt
		${Case} "XP"
			Goto winnt
		${Case} "2003"
			Goto winnt
  ${EndSelect}
	win9x:
		CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Matrix Mixer Configuration.lnk" "$WINDIR\rundll32.exe" '"$INSTDIR\MatrixMixer\matrix_mixer.ax",config'
	Goto end
	winnt:
		CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\Matrix Mixer Configuration.lnk" "$SYSDIR\rundll32.exe" '"$INSTDIR\MatrixMixer\matrix_mixer.ax",config'
	Goto end
	end:
FunctionEnd

Function SMShortCutsAF
	Call GetWindowsVersion
	Pop $R0
	${Select} $R0
		${Case} "95"
			Goto win9x
		${Case} "98"
			Goto win9x
		${Case} "ME"
			Goto win9x
    ${Case} "2000"
      Goto winnt
		${Case} "XP"
			Goto winnt
		${Case} "2003"
			Goto winnt
  ${EndSelect}
	win9x:
		CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\DivX Anti-Freeze Configuration.lnk" "$WINDIR\rundll32.exe" DivXAF.ax,Configure
	Goto end
	winnt:
		CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\DivX Anti-Freeze Configuration.lnk" "$SYSDIR\rundll32.exe" DivXAF.ax,Configure
	Goto end
	end:
FunctionEnd

Function SMShortCutsG400
	Call GetWindowsVersion
	Pop $R0
	${Select} $R0
		${Case} "95"
			Goto win9x
		${Case} "98"
			Goto win9x
		${Case} "ME"
			Goto win9x
    ${Case} "2000"
      Goto winnt
		${Case} "XP"
			Goto winnt
		${Case} "2003"
			Goto winnt
  ${EndSelect}
	win9x:
		CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\DivX G400 Filter Configuration.lnk" "$WINDIR\rundll32.exe" DivXG400.ax,Configure
	Goto end
	winnt:
		CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\DivX G400 Filter Configuration.lnk" "$SYSDIR\rundll32.exe" DivXG400.ax,Configure
	Goto end
	end:
FunctionEnd

Function GetWindowsVersion

	Push $R3
	Push $R4

	ReadRegStr $R3 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion

	IfErrors 0 lbl_winnt

	; we are not NT
	ReadRegStr $R3 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion" VersionNumber

	StrCpy $R4 $R3 1
	StrCmp $R4 '4' 0 lbl_error

	StrCpy $R4 $R3 3

	StrCmp $R4 '4.0' lbl_win32_95
	StrCmp $R4 '4.9' lbl_win32_ME lbl_win32_98

	lbl_win32_95:
		StrCpy $R3 '95'
	Goto lbl_done

	lbl_win32_98:
		StrCpy $R3 '98'
	Goto lbl_done

	lbl_win32_ME:
		StrCpy $R3 'ME'
	Goto lbl_done

	lbl_winnt:
		StrCpy $R4 $R3 1
 
	StrCmp $R4 '3' lbl_winnt_x
	StrCmp $R4 '4' lbl_winnt_x

	StrCpy $R4 $R3 3

	StrCmp $R4 '5.0' lbl_winnt_2000
	StrCmp $R4 '5.1' lbl_winnt_XP
	StrCmp $R4 '5.2' lbl_winnt_2003 lbl_error

	lbl_winnt_x:
		StrCpy $R3 "NT $R3" 6
	Goto lbl_done

	lbl_winnt_2000:
		Strcpy $R3 '2000'
	Goto lbl_done

	lbl_winnt_XP:
		Strcpy $R3 'XP'
	Goto lbl_done

	lbl_winnt_2003:
		Strcpy $R3 '2003'
	Goto lbl_done

	lbl_error:
		Strcpy $R3 ''
	lbl_done:

	Pop $R4
	Exch $R3
	Dumpstate::debug
FunctionEnd