/*
http://download.skype.com/msi/SkypeSetup_6.20.0.104.msi
*/
!define RELEASURL	"http://download.skype.com/msi"
!define MSI ; Delete if setup not msi
!define APPSIZE	"28900" # kB
!define DLVER	"6.x.x.x"
!define APPVER 	"0.0.0.0"
!define APPNAME "Skype"
!define APP 	"Skype"
!define DLNAME	"Skype"
!define APPLANG	"Multilingual_Online"
!define FOLDER	"SkypePortable"
!define FINISHRUN ; Delete if not Finish pages
!define SOURCES ; Delete if no Sources
; !define DESCRIPTION	"Free internet calls" ; Delete if no AppInfo
!define INPUTBOX ; Delete if no InputBox

SetCompressor /SOLID lzma
SetCompressorDictSize 32

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

!insertmacro MUI_LANGUAGE "Arabic"
!insertmacro MUI_LANGUAGE "Bulgarian"
!insertmacro MUI_LANGUAGE "Czech"
!insertmacro MUI_LANGUAGE "Danish"
!insertmacro MUI_LANGUAGE "Dutch"
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "Estonian"
!insertmacro MUI_LANGUAGE "Finnish"
!insertmacro MUI_LANGUAGE "French"
!insertmacro MUI_LANGUAGE "German"
!insertmacro MUI_LANGUAGE "Greek"
!insertmacro MUI_LANGUAGE "Hebrew"
!insertmacro MUI_LANGUAGE "Hungarian"
!insertmacro MUI_LANGUAGE "Indonesian"
!insertmacro MUI_LANGUAGE "Italian"
!insertmacro MUI_LANGUAGE "Japanese"
!insertmacro MUI_LANGUAGE "Korean"
!insertmacro MUI_LANGUAGE "Latvian"
!insertmacro MUI_LANGUAGE "Lithuanian"
!insertmacro MUI_LANGUAGE "Norwegian"
!insertmacro MUI_LANGUAGE "Polish"
!insertmacro MUI_LANGUAGE "Portuguese"
!insertmacro MUI_LANGUAGE "PortugueseBR"
!insertmacro MUI_LANGUAGE "Romanian"
!insertmacro MUI_LANGUAGE "Russian"
!insertmacro MUI_LANGUAGE "SimpChinese"
!insertmacro MUI_LANGUAGE "Spanish"
!insertmacro MUI_LANGUAGE "Swedish"
!insertmacro MUI_LANGUAGE "TradChinese"
!insertmacro MUI_LANGUAGE "Turkish"
!insertmacro MUI_LANGUAGE "Ukrainian"

Var InputVer
Var VER
Function nsDialogsPage
	nsDialogs::Create 1018
	Pop $0
	${NSD_CreateLabel} 0 0 100% 12u "Enter Version Number:"
	Pop $0
	${NSD_CreateText} 0 13u 100% 12u ""
	Pop $InputVer
	nsDialogs::Show
FunctionEnd
Function nsDialogsPageLeave
	${NSD_GetText} $InputVer $R0
StrCmp $R0 "" 0 +3
	MessageBox MB_ICONEXCLAMATION `You must enter a version number!`
Abort
	StrCpy $VER "$R0"
FunctionEnd

Section "${APPNAME} Portable" main
SectionIn RO

DetailPrint "Installing ${APPNAME} Portable"

${If} ${FileExists} "$EXEDIR\SkypeSetup_$VER.msi"
	nsExec::Exec `"$SYSDIR\msiexec.exe" /a "$EXEDIR\SkypeSetup_$VER.msi" TARGETDIR="$TEMP\${APP}PortableTemp\SkypeSetup" /qn`
${Else}
Call CheckConnected
	inetc::get "${RELEASURL}/SkypeSetup_$VER.msi" "$TEMP\${APP}PortableTemp\SkypeSetup_$VER.msi" /END
	Pop $0
StrCmp $0 "OK" +3
	MessageBox MB_ICONEXCLAMATION "SkypeSetup_$VER.msi not found in $EXEDIR and download: $0"
	Abort
	nsExec::Exec `"$SYSDIR\msiexec.exe" /a "$TEMP\${APP}PortableTemp\SkypeSetup_$VER.msi" TARGETDIR="$TEMP\${APP}PortableTemp\SkypeSetup" /qn`
${EndIf}

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

	SetOutPath "$INSTDIR\App\${APP}\Phone"
	CopyFiles /SILENT "$TEMP\${APP}PortableTemp\SkypeSetup\Program Files\Skype\Phone\Skype.exe" "$INSTDIR\App\${APP}\Phone\"
	SetOutPath "$INSTDIR\App\${APP}"
	CopyFiles /SILENT "$TEMP\${APP}PortableTemp\SkypeSetup\Program Files\Skype\Redist\Skype\Skype4COM.dll" "$INSTDIR\App\${APP}\"
	CopyFiles /SILENT "$TEMP\${APP}PortableTemp\SkypeSetup\Program Files\Skype\third-party_attributions.txt" "$INSTDIR\App\${APP}\"

	File "/oname=$TEMP\${APP}PortableTemp\7za.exe" "..\_Include\7-Zip\7za.exe"
	nsExec::Exec `"$TEMP\${APP}PortableTemp\7za.exe" x "$TEMP\${APP}PortableTemp\SkypeSetup\Program Files\Skype\Phone\Login.cab" -aoa -o"$INSTDIR\App\DefaultData\Skype\Apps\login"`

  md5dll::GetMD5File "$TEMP\${APP}PortableTemp\SkypeSetup\Program Files\Skype\Phone\Login.cab"
  Pop $0
FileOpen $1 "$INSTDIR\App\DefaultData\${APP}\Apps\login.md5" w
FileWrite $1 "$0$\r$\n"
FileClose $1

FileOpen $2 "$INSTDIR\App\DefaultData\${APP}\Apps\login.js" w
FileWrite $2 ";$\r$\n"
FileClose $2


!ifdef DESCRIPTION
Call AppInfo
!endif
!ifdef SOURCES
Call Sources
!endif
!ifdef SOURCES & DESCRIPTION
Call SourceInfo
!endif

SectionEnd

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