DaxSoft

URLDownloadToFile[USA]

Feb 21st, 2015
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.93 KB | None | 0 0
  1. #==============================================================================
  2. # • URLDownloadToFile
  3. #==============================================================================
  4. # Author: Dax
  5. # Version: 1.0
  6. # Site: www.dax-soft.weebly.com
  7. # Required: Dax Core
  8. #==============================================================================
  9. # • Description:
  10. #------------------------------------------------------------------------------
  11. #  Transfer an file that is "linked" in the url to another file, i.e,
  12. # make download an file of internet.
  13. #==============================================================================
  14. # • How to use:
  15. #------------------------------------------------------------------------------
  16. # URLDownloadToFile.run(url, dstfile, open)
  17. #   url : URL of file.
  18. #   dstfile : Final name of the file
  19. #   open : Open file, after downloading? true - yes | false - no.
  20. #
  21. # Example:
  22. #
  23. # url = "http://www.news2news.com/vfp/downloads/w32data.zip"
  24. # dstfile = "w32data.zip"
  25. # URLDownloadToFile.run(url, dstfile)
  26. #==============================================================================
  27. Dax.register(:urldownloadtofile, "Dax", 1.0) {
  28. module URLDownloadToFile
  29.   #----------------------------------------------------------------------------
  30.   # • Extensão dá função do módulo.
  31.   #   Extensão do módulo API.
  32.   #----------------------------------------------------------------------------
  33.   extend API
  34.   extend self
  35.   #----------------------------------------------------------------------------
  36.   # • Constantes.
  37.   #----------------------------------------------------------------------------
  38.   DLL = "Urlmon.dll"
  39.   DLL_SHELL32 = "Shell32.dll"
  40.   S_OK = 0x00000000
  41.   SW_SHOWNORMAL = 1
  42.   #----------------------------------------------------------------------------
  43.   # • Função dá DLL.
  44.   #----------------------------------------------------------------------------
  45.   @@urlDownloadToFile = int("URLDownloadToFile", [:LPCTSTR, :LPCTSTR, :LPCTSTR,
  46.                                                 :int, :int], DLL)
  47.   @@shellExecute = long("ShellExecute", [:LPCTSTR, :LPCTSTR, :LPCTSTR,
  48.                                       :LPCTSTR, :LPCTSTR, :LONG], DLL_SHELL32)
  49.   #----------------------------------------------------------------------------
  50.   # • [BooleanClass] : Baixar o arquivo dá URL para arquivo. (lol)
  51.   #     url : Link dá url.
  52.   #     dstfile : Nome do arquivo final.
  53.   #     open : Abrir arquivo automáticamente? true - sim | false - não.
  54.   #----------------------------------------------------------------------------
  55.   def run(url, dstfile, open=false)
  56.     result = @@urlDownloadToFile.call(NIL, url, dstfile, 0, 0)
  57.     if (result == S_OK)
  58.       return TRUE unless open
  59.       @@shellExecute.call(NIL, "open", dstfile, NIL, NIL, SW_SHOWNORMAL)
  60.       return TRUE
  61.     else
  62.       raise("URLDownloadToFile call failed: %X\n", result)
  63.     end                      
  64.   end
  65. end
  66. }
Add Comment
Please, Sign In to add comment