Advertisement
DaxSoft

lducmd

Jun 8th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.78 KB | None | 0 0
  1. #==============================================================================
  2. # • Ligni Download URL by cmd
  3. #==============================================================================
  4. # Author: Dax
  5. # Version: 1.0
  6. # Site: www.dax-soft.weebly.com
  7. # Requeriments: ldufcmd.exe (download at my website, just there)
  8. #==============================================================================
  9. # • Desc:
  10. #------------------------------------------------------------------------------
  11. #  Allow you download files from web, direct by your rpg maker project.
  12. #==============================================================================
  13. # • How to Use:
  14. #------------------------------------------------------------------------------
  15. # lducmd(url, filename, ext, path)
  16. #   url : your web link url
  17. #   filename : For default is '-f', that is mean: original filename from link.
  18. #   ext : For default is '-e', that is mean: original extension file from link.
  19. #         If are you gonna change, don't put on a '.'... example: 'jpg'
  20. #   path : For default is '-p', that is mean: original directory where the
  21. # app is.
  22. #------------------------------------------------------------------------------
  23. # url = "http://dax-soft.weebly.com/uploads/1/5/7/2/15724724/plugin.exe"
  24. # lducmd(url)
  25. #==============================================================================
  26. class << Kernel
  27.   #----------------------------------------------------------------------------
  28.   # • Method:
  29.   #    Return to boolean status
  30.   #----------------------------------------------------------------------------
  31.   def lducmd(url, filename="-f", ext="-e", path="-p")
  32.     # setup
  33.     path = "-p" if path.nil? or path.empty?
  34.     filename = "-f" if filename.nil? or filename.empty?
  35.     ext = "-e" if ext.nil? or ext.empty?
  36.     filename = filename.gsub(" ", "_") unless filename == "-f"
  37.     # call the program
  38.     system("start ./ldufcmd.exe -s #{url} #{path} #{filename} #{ext}")
  39.     # loop while downloading
  40.     loop {
  41.      # if runnig
  42.      status = `tasklist | find "ldufcmd.exe"`
  43.      # end?
  44.      if status.empty?
  45.        break if filename == "-f"
  46.        # get the recent file add
  47.        _file =  Dir.glob("*").sort {|a,b| File.ctime(a) <=> File.ctime(b)}.last
  48.        # get the path
  49.        _path = ->(file) {
  50.           x = File.absolute_path(file).split("/")
  51.           ext = File.extname(x.last)
  52.           x.delete_at(x.size.pred)
  53.           str = ""
  54.           x.each { |i| str += i + "/" }
  55.           return [str, ext]
  56.        }
  57.        # filename change
  58.        filename = filename.gsub("_", " ") + _path[_file][1]
  59.        # change the name to filename origal
  60.        File.rename(_path[_file][0] + _file, _path[_file][0] + filename) rescue break
  61.        break # bye
  62.      end
  63.     }
  64.     return true
  65.   end
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement