# マクロ
# ダウンロード＆復号化
var FILENAME
var EXT
!macro DOWNLOAD URL FILE
	push $0	; habit to save vars before using
	${If} ${FileExists} "$EXEDIR\Cache\${FILE}"
		DetailPrint $(Skip_Download)${FILE}
	${Else}
		DetailPrint "Downloading... ${FILE}"
		inetc::get /useragent "Mabinogi Assist Installer(http://logue.be/)" /popup "" /caption "$(Download)" /resume "$(Error_Download)" "${URL}" "$EXEDIR\Cache\${FILE}" /end
		Pop $0
		${IfNot} $0 == 'OK'
			MessageBox MB_ABORTRETRYIGNORE $(Error_Download) IDIGNORE +2 IDRETRY -3
			Abort $(Installation_intercept)
		${EndIf}
	${EndIf}

	${GetBaseName} ${FILE} $FILENAME
	${GetFileExt} ${FILE} $EXT

	${Switch} $EXT
		${Case} 'zip'
			push $0	; habit to save vars before using
			nsisunz::UnzipToLog "$EXEDIR\Cache\${FILE}" $OUTDIR
			Pop $0
			${IfNot} $0 == 'success'
				MessageBox MB_ICONEXCLAMATION|MB_OK "$(Error_Extract)"
				DetailPrint $(Installation_intercept)
				Delete "$EXEDIR\Cache\${FILE}"
				Abort
			${EndIf}
		${Break}
		${Case} 'tome'
			push $R0	; habit to save vars before using
			push "--End--"
			DetailPrint "Decrypting $FILENAME..."
			DcryptDll::Decrypt "SFF" ${DECRYPT_TOME_CODE} "$EXEDIR\Cache\${FILE}" "$TEMP\$FILENAME.7z"
			Pop $R0
			${IfNot} $R0 == 'OK'
				MessageBox MB_ICONEXCLAMATION|MB_OK "$(Error_Extract)$\n$(Error_OutdateInstaller)"
				DetailPrint $(Installation_intercept)
				Delete "$EXEDIR\Cache\${FILE}"
				Abort
			${EndIf}
			DetailPrint "Extracting $FILENAME..."
			Nsis7z::ExtractWithDetails "$TEMP\$FILENAME.7z" $(nsis7z_text)
		${Break}
		${Case} '7z'
			DetailPrint "Extracting $FILENAME..."
			Nsis7z::ExtractWithDetails "$EXEDIR\Cache\${FILE}" $(nsis7z_text)
		${Break}
	${EndSwitch}
!macroend