Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # • URLDownloadToFile
- #==============================================================================
- # Author: Dax
- # Version: 1.0
- # Site: www.dax-soft.weebly.com
- # Required: Dax Core
- #==============================================================================
- # • Description:
- #------------------------------------------------------------------------------
- # Transfer an file that is "linked" in the url to another file, i.e,
- # make download an file of internet.
- #==============================================================================
- # • How to use:
- #------------------------------------------------------------------------------
- # URLDownloadToFile.run(url, dstfile, open)
- # url : URL of file.
- # dstfile : Final name of the file
- # open : Open file, after downloading? true - yes | false - no.
- #
- # Example:
- #
- # url = "http://www.news2news.com/vfp/downloads/w32data.zip"
- # dstfile = "w32data.zip"
- # URLDownloadToFile.run(url, dstfile)
- #==============================================================================
- Dax.register(:urldownloadtofile, "Dax", 1.0) {
- 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
- }
Add Comment
Please, Sign In to add comment