/*
https://go.skype.com/skype.download
https://endpoint920510.azureedge.net/s4l/s4l/download/win/Skype-8.52.0.138.exe
https://endpoint920510.azureedge.net/s4l/s4l/download/win/Skype-8.16.0.4.exe
*/
; !define RELEASURL	"https://go.skype.com/skype.download"
!define RELEASURL	"https://endpoint920510.azureedge.net/s4l/s4l/download/win"
!define INNO ; Delete if setup not Inno
!define APPSIZE	"185000" # kB
; !define DLVER	"latest"
!define DLVER	"Multiversion"
!define INPUTBOX ; Delete if no InputBox
!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

SetCompressor /SOLID lzma
SetCompressorDictSize 32

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

!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "Arabic"
!insertmacro MUI_LANGUAGE "Bulgarian"
!insertmacro MUI_LANGUAGE "Czech"
!insertmacro MUI_LANGUAGE "Danish"
!insertmacro MUI_LANGUAGE "Dutch"
!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"

; --- Delete if no InputBox
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\Skype-$VER.exe"
	nsExec::Exec `"$TEMP\${APP}PortableTemp\innounp.exe" -x -a -y -d"$TEMP\${APP}PortableTemp\${APP}Setup" "$EXEDIR\Skype-$VER.exe"`
${Else}

Call CheckConnected
	; inetc::get "${RELEASURL}" "$TEMP\${APP}PortableTemp\SkypeSetup.exe" /END
	inetc::get "${RELEASURL}/Skype-$VER.exe" "$TEMP\${APP}PortableTemp\Skype-$VER.exe" /END
	Pop $0
StrCmp $0 "OK" +3
	; MessageBox MB_ICONEXCLAMATION "download: $0"
	MessageBox MB_ICONEXCLAMATION "Skype-$VER.exe not found in $EXEDIR and download: $0"
	Abort
	nsExec::Exec `"$TEMP\${APP}PortableTemp\innounp.exe" -x -a -y -d"$TEMP\${APP}PortableTemp\${APP}Setup" "$TEMP\${APP}PortableTemp\Skype-$VER.exe"`
	Sleep 1000
${EndIf}

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

	SetOutPath "$INSTDIR\App\${APP}"
	CopyFiles /SILENT "$TEMP\${APP}PortableTemp\${APP}Setup\{app}\*.*" "$INSTDIR\App\${APP}"
	SetOutPath "$INSTDIR\App\DefaultData\Skype for Desktop"
	File "settings.json"
SectionEnd

Function .onGUIEnd
!ifdef DESCRIPTION
	Call AppInfo
!endif
!ifdef SOURCES
	Call Sources
!endif
!ifdef SOURCES & DESCRIPTION
	Call SourceInfo
!endif
!ifndef TEST
	RMDir "/r" "$TEMP\${APP}PortableTemp"
!endif
FunctionEnd
