/*
STABLE version:
http://clients2.google.com/service/update2/crx?response=redirect&x=id%3D{8A69D345-D564-463C-AFF1-A69D9E530F96}%26uc

BETA version:
http://clients2.google.com/service/update2/crx?response=redirect&x=id%3D{8A69D345-D564-463C-AFF1-A69D9E530F96}%26uc&ap=1.1-beta

DEV version:
http://clients2.google.com/service/update2/crx?response=redirect&x=id%3D{8A69D345-D564-463C-AFF1-A69D9E530F96}%26uc&ap=2.0-dev

CANARY version:
http://clients2.google.com/service/update2/crx?response=redirect&x=id%3D{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}%26uc

http://cache.pack.google.com/edgedl/chrome/win/279BD2981B6AC7FE/26.0.1410.3_chrome_installer.exe
http://cache.pack.google.com/edgedl/chrome/win/3C2DA80513166507/25.0.1364.84_chrome_installer.exe
http://cache.pack.google.com/edgedl/chrome/win/43E0121506A116F0/24.0.1312.57_chrome_installer.exe
*/
; !define APPSIZE	"93500" # kB
!define DLVER	"Multiversion_Online"
!define APPVER 	"0.0.0.0"
!define APPNAME "Chrome"
!define APP 	"Chrome"
!define DLNAME	"Chrome"
!define APPLANG	"Multilingual"
!define FOLDER	"ChromePortable"
!define FINISHRUN
!define OPTIONS ; Delete if no Components
; !define DESCRIPTION	"Google Internet browser"
!define SOURCES

SetCompressor /SOLID lzma
SetCompressorDictSize 32

!include "..\_Include\Installer.nsh"
!include "LogicLib.nsh"

!insertmacro MUI_LANGUAGE "Arabic"
!insertmacro MUI_LANGUAGE "Bulgarian"
!insertmacro MUI_LANGUAGE "Catalan"
!insertmacro MUI_LANGUAGE "Czech"
!insertmacro MUI_LANGUAGE "Danish"
!insertmacro MUI_LANGUAGE "German"
!insertmacro MUI_LANGUAGE "Greek"
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SpanishInternational"
!insertmacro MUI_LANGUAGE "Estonian"
!insertmacro MUI_LANGUAGE "Farsi"
!insertmacro MUI_LANGUAGE "Finnish"
!insertmacro MUI_LANGUAGE "French"
!insertmacro MUI_LANGUAGE "Hebrew"
!insertmacro MUI_LANGUAGE "Croatian"
!insertmacro MUI_LANGUAGE "Hungarian"
!insertmacro MUI_LANGUAGE "Indonesian"
!insertmacro MUI_LANGUAGE "Italian"
!insertmacro MUI_LANGUAGE "Japanese"
!insertmacro MUI_LANGUAGE "Korean"
!insertmacro MUI_LANGUAGE "Lithuanian"
!insertmacro MUI_LANGUAGE "Latvian"
!insertmacro MUI_LANGUAGE "Malay"
!insertmacro MUI_LANGUAGE "Dutch"
!insertmacro MUI_LANGUAGE "PortugueseBR"
!insertmacro MUI_LANGUAGE "Portuguese"
!insertmacro MUI_LANGUAGE "Romanian"
!insertmacro MUI_LANGUAGE "Russian"
!insertmacro MUI_LANGUAGE "Slovak"
!insertmacro MUI_LANGUAGE "Slovenian"
!insertmacro MUI_LANGUAGE "Serbian"
!insertmacro MUI_LANGUAGE "Swedish"
!insertmacro MUI_LANGUAGE "Thai"
!insertmacro MUI_LANGUAGE "Turkish"
!insertmacro MUI_LANGUAGE "Ukrainian"
!insertmacro MUI_LANGUAGE "SimpChinese"
!insertmacro MUI_LANGUAGE "TradChinese"

Var RELEASURL
Var OLDVER
Var NEWVER

Function Install

	RMDir "/r" "$TEMP\${APP}PortableTemp"
	CreateDirectory "$TEMP\${APP}PortableTemp"
	inetc::get "$RELEASURL" "$TEMP\${APP}PortableTemp\chrome_installer.exe" /END

	Pop $0
StrCmp $0 "OK" +3
	MessageBox MB_USERICON "Download of chrome_installer.exe: $0"
Goto cancelled

	File "/oname=$TEMP\${APP}PortableTemp\7za.exe" "..\_Include\7-Zip\7za.exe"
	nsExec::Exec `"$TEMP\${APP}PortableTemp\7za.exe" x "$TEMP\${APP}PortableTemp\chrome_installer.exe" -o"$TEMP\${APP}PortableTemp"`
	nsExec::Exec `"$TEMP\${APP}PortableTemp\7za.exe" x "$TEMP\${APP}PortableTemp\chrome.7z" -o"$TEMP\${APP}PortableTemp"`


FindFirst $0 $1 "$TEMP\${APP}PortableTemp\Chrome-bin\*.*"
FindNext $0 $1
FindNext $0 $1
FindClose $0
StrCpy $NEWVER "$1"

${If} ${FileExists} "$INSTDIR\App\${APP}\chrome.dll"
GetDllVersion "$INSTDIR\App\${APP}\chrome.dll" $R0 $R1
IntOp $R2 $R0 / 0x00010000
IntOp $R3 $R0 & 0x0000FFFF
IntOp $R4 $R1 / 0x00010000
IntOp $R5 $R1 & 0x0000FFFF
StrCpy $0 "$R2.$R3.$R4.$R5"
MessageBox MB_OKCANCEL "Replace $0 with $NEWVER ?" IDOK extract IDCANCEL cancelled
${Else}
MessageBox MB_OKCANCEL "Install $NEWVER ?" IDOK extract IDCANCEL cancelled
${EndIf}

extract:
	SetOutPath "$INSTDIR"
		File "..\..\..\${FOLDER}\${APP}Portable.exe"
	SetOutPath "$INSTDIR\App\DefaultData\${APP}\Default"
		File "Default\Preferences"
		File "Default\Bookmarks"
	SetOutPath "$INSTDIR\App\${APP}"
	FileOpen $0 "$INSTDIR\App\${APP}\First Run" w
	FileClose $0
	CopyFiles /SILENT /FILESONLY "$TEMP\${APP}PortableTemp\Chrome-bin\*.*" "$INSTDIR\App\${APP}"
	CopyFiles /SILENT "$TEMP\${APP}PortableTemp\Chrome-bin\$NEWVER\*.*" "$INSTDIR\App\${APP}"

!ifdef DESCRIPTION
	Call AppInfo
!endif
!ifdef SOURCES
	Call Sources
	SetOutPath "$INSTDIR\Other\_Include\7-Zip"
	File "..\_Include\7-Zip\7za.exe"
	SetOutPath "$INSTDIR\Other\Source\Default"
	File "Default\Preferences"
!endif
!ifdef SOURCES & DESCRIPTION
	Call SourceInfo
!endif

cancelled:
FunctionEnd

Function .onGUIEnd
	RMDir "/r" "$TEMP\${APP}PortableTemp"
FunctionEnd

Section "Chrome Stable" SEC_STABLE 
	SectionIn 1
StrCpy $RELEASURL "http://clients2.google.com/service/update2/crx?response=redirect&x=id%3D{8A69D345-D564-463C-AFF1-A69D9E530F96}%26uc"
	Call Install
SectionEnd
 
Section /o "Chrome Beta" SEC_BETA 
  SectionIn 2
StrCpy $RELEASURL "http://clients2.google.com/service/update2/crx?response=redirect&x=id%3D{8A69D345-D564-463C-AFF1-A69D9E530F96}%26uc&ap=1.1-beta"
	Call Install
SectionEnd
 
Section /o "Chrome Dev" SEC_DEV 
  SectionIn 3
StrCpy $RELEASURL "http://clients2.google.com/service/update2/crx?response=redirect&x=id%3D{8A69D345-D564-463C-AFF1-A69D9E530F96}%26uc&ap=2.0-dev"
	Call Install
SectionEnd
 
Section /o "Chrome Canary" SEC_CANARY 
  SectionIn 4
StrCpy $RELEASURL "http://clients2.google.com/service/update2/crx?response=redirect&x=id%3D{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}%26uc"
	Call Install
SectionEnd

Function Init
SectionSetSize ${SEC_STABLE} 93500 # kB
SectionSetSize ${SEC_BETA} 93500 # kB
SectionSetSize ${SEC_DEV} 93500 # kB
SectionSetSize ${SEC_CANARY} 93500 # kB
StrCpy $1 ${SEC_STABLE}
FunctionEnd
 
Function .onSelChange
  !insertmacro StartRadioButtons $1
   !insertmacro RadioButton ${SEC_STABLE}
   !insertmacro RadioButton ${SEC_BETA}
   !insertmacro RadioButton ${SEC_DEV}
   !insertmacro RadioButton ${SEC_CANARY}
  !insertmacro EndRadioButtons
FunctionEnd