/*
http://download.ap.bittorrent.com/track/stable/endpoint/utorrent/os/windows
http://www.utorrent.com/downloads/complete/os/win/track/stable
http://download-new.utorrent.com/endpoint/utorrent/os/win/track/stable/
http://download-new.utorrent.com/endpoint/utorrent/os/windows/track/stable/
http://download-new.utorrent.com/endpoint/utorrent/os/windows/track/stable/
http://www.utorrent.com/downloads/win
http://www.utorrent.com/scripts/dl.php?track=stable&build=32278&client=utorrent
*/
!define RELEASURL	"http://download-new.utorrent.com/endpoint/utorrent/os/win/track/stable/"
!define LNGURL	"http://www.utorrent.com/scripts/dl.php?track=stable&build="
!define APPSIZE	"3270" # kB
!define DLVER	"3.x.x"
!define APPVER 	"0.0.0.0"
!define APPNAME "uTorrent"
!define APP 	"uTorrent"
!define DLNAME	"uTorrent"
!define APPLANG	"Multilingual_Online"
!define FOLDER	"uTorrentPortable"
!define FINISHRUN ; Delete if not Finish pages
!define SOURCES ; Delete if no Sources
; !define DESCRIPTION	"Tiny BitTorrent client" ; Delete if no AppInfo
!define INPUTBOX ; Delete if no InputBox

SetCompressor /SOLID lzma
SetCompressorDictSize 32

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

!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "Arabic"
!insertmacro MUI_LANGUAGE "Basque"
!insertmacro MUI_LANGUAGE "Belarusian"
!insertmacro MUI_LANGUAGE "Bosnian"
!insertmacro MUI_LANGUAGE "Bulgarian"
!insertmacro MUI_LANGUAGE "Catalan"
!insertmacro MUI_LANGUAGE "Croatian"
!insertmacro MUI_LANGUAGE "Czech"
!insertmacro MUI_LANGUAGE "Danish"
!insertmacro MUI_LANGUAGE "Esperanto"
!insertmacro MUI_LANGUAGE "Estonian"
!insertmacro MUI_LANGUAGE "Finnish"
!insertmacro MUI_LANGUAGE "French"
!insertmacro MUI_LANGUAGE "Greek"
!insertmacro MUI_LANGUAGE "Hebrew"
!insertmacro MUI_LANGUAGE "Hungarian"
!insertmacro MUI_LANGUAGE "Icelandic"
!insertmacro MUI_LANGUAGE "Indonesian"
!insertmacro MUI_LANGUAGE "Italian"
!insertmacro MUI_LANGUAGE "Japanese"
!insertmacro MUI_LANGUAGE "Korean"
!insertmacro MUI_LANGUAGE "Kurdish"
!insertmacro MUI_LANGUAGE "Latvian"
!insertmacro MUI_LANGUAGE "Lithuanian"
!insertmacro MUI_LANGUAGE "Macedonian"
!insertmacro MUI_LANGUAGE "Malay"
!insertmacro MUI_LANGUAGE "Mongolian"
!insertmacro MUI_LANGUAGE "Norwegian"
!insertmacro MUI_LANGUAGE "NorwegianNynorsk"
!insertmacro MUI_LANGUAGE "Polish"
!insertmacro MUI_LANGUAGE "Portuguese"
!insertmacro MUI_LANGUAGE "PortugueseBR"
!insertmacro MUI_LANGUAGE "Romanian"
!insertmacro MUI_LANGUAGE "Serbian"
!insertmacro MUI_LANGUAGE "SerbianLatin"
!insertmacro MUI_LANGUAGE "SimpChinese"
!insertmacro MUI_LANGUAGE "Slovak"
!insertmacro MUI_LANGUAGE "Slovenian"
!insertmacro MUI_LANGUAGE "Spanish"
!insertmacro MUI_LANGUAGE "Swedish"
!insertmacro MUI_LANGUAGE "TradChinese"
!insertmacro MUI_LANGUAGE "Turkish"
!insertmacro MUI_LANGUAGE "Ukrainian"
!insertmacro MUI_LANGUAGE "Vietnamese"
!insertmacro MUI_LANGUAGE "Welsh"

Var InputVer
Var VER
Function nsDialogsPage
	nsDialogs::Create 1018
	Pop $0
	${NSD_CreateLabel} 0 0 100% 12u "Enter language build: (skip if you need only english)"
	Pop $0
	${NSD_CreateText} 0 13u 100% 12u ""
	Pop $InputVer
	nsDialogs::Show
FunctionEnd
Function nsDialogsPageLeave
	${NSD_GetText} $InputVer $R0
	StrCpy $VER "$R0"
FunctionEnd


Section "${APPNAME} Portable" main

SectionIn RO

	; File "/oname=$TEMP\${APP}PortableTemp\upx.exe" "..\_Include\UPX\upx.exe"

DetailPrint "Installing ${APPNAME} Portable"

Call CheckConnected
	inetc::get "${RELEASURL}" "$TEMP\${APP}PortableTemp\${APP}.exe" /END
	Pop $0
StrCmp $0 "OK" +3
	MessageBox MB_ICONEXCLAMATION "download of ${APP}.exe: $0"
	Abort
StrCmp $VER "" +2
	inetc::get "${LNGURL}$VER&client=utorrent" "$TEMP\${APP}PortableTemp\${APP}.lng" /END

	SetOutPath "$TEMP\${APP}PortableTemp"
	; File "${APP}UPXPatch.exe"
	File "${APP}Patch.exe"
	; ExecWait `"$TEMP\${APP}PortableTemp\${APP}UPXPatch.exe" /silent`
	; nsExec::ExecToStack `"$TEMP\${APP}PortableTemp\upx.exe" -d ${APP}.exe`
	ExecWait `"$TEMP\${APP}PortableTemp\${APP}Patch.exe" /silent`
	nsExec::ExecToStack `"$TEMP\${APP}PortableTemp\upx.exe" ${APP}.exe`

DetailPrint "Installing ${APPNAME} Portable"

	SetOutPath "$INSTDIR"
		File "..\..\..\${FOLDER}\${APP}Portable.exe"

	SetOutPath "$INSTDIR\App\${APP}"
	CopyFiles /SILENT "$TEMP\${APP}PortableTemp\${APP}.exe" "$INSTDIR\App\${APP}"
	CopyFiles /SILENT "$TEMP\${APP}PortableTemp\${APP}.lng" "$INSTDIR\App\${APP}"

!ifdef DESCRIPTION
Call AppInfo
!endif
!ifdef SOURCES
Call Sources
	SetOutPath "$INSTDIR\Other\Source"
	File "settings.dat"
!endif
!ifdef SOURCES & DESCRIPTION
Call SourceInfo
!endif

SectionEnd

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