Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # • URLDownloadToFile
- #==============================================================================
- # Autor: Dax
- # Versão: 1.0
- # Site: www.dax-soft.weebly.com
- # Requerimento: Dax Core
- #==============================================================================
- # • Descrição:
- #------------------------------------------------------------------------------
- # Transfere um arquivo que está "linkado" numa url para outro, i.e, baixa
- # um arquivo dá internet.
- #==============================================================================
- # • Como usar:
- #------------------------------------------------------------------------------
- # URLDownloadToFile.run(url, dstfile, open)
- # url : URL do arquivo.
- # dstfile : Nome final do arquivo.
- # open : Abrir arquivo, logo após baixar? true - sim | false - não.
- #
- # Exemplo:
- #
- # url = "http://www.news2news.com/vfp/downloads/w32data.zip"
- # dstfile = "w32data.zip"
- # URLDownloadToFile.run(url, dstfile)
- #==============================================================================
- Dax.register(:urldownloadtofile, "Dax", 1.0, "21/02/15")
- module URLDownloadToFile
- #----------------------------------------------------------------------------
- # • Extensão dá função do módulo.
- # Extensão do módulo API.
- #----------------------------------------------------------------------------
- extend API
- extend self
- #----------------------------------------------------------------------------
- # • Constantes.
- #----------------------------------------------------------------------------
- DLL = "Urlmon.dll"
- DLL_SHELL32 = "Shell32.dll"
- S_OK = 0x00000000
- SW_SHOWNORMAL = 1
- #----------------------------------------------------------------------------
- # • Função dá DLL.
- #----------------------------------------------------------------------------
- @@urlDownloadToFile = int("URLDownloadToFile", [:LPCTSTR, :LPCTSTR, :LPCTSTR,
- :int, :int], DLL)
- @@shellExecute = long("ShellExecute", [:LPCTSTR, :LPCTSTR, :LPCTSTR,
- :LPCTSTR, :LPCTSTR, :LONG], DLL_SHELL32)
- #----------------------------------------------------------------------------
- # • [BooleanClass] : Baixar o arquivo dá URL para arquivo. (lol)
- # url : Link dá url.
- # dstfile : Nome do arquivo final.
- # open : Abrir arquivo automáticamente? true - sim | false - não.
- #----------------------------------------------------------------------------
- def run(url, dstfile, open=false)
- result = @@urlDownloadToFile.call(NIL, url, dstfile, 0, 0)
- if (result == S_OK)
- return TRUE unless open
- @@shellExecute.call(NIL, "open", dstfile, NIL, NIL, SW_SHOWNORMAL)
- return TRUE
- else
- raise("URLDownloadToFile call failed: %X\n", result)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement