Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # • Ligni Download URL by cmd
- #==============================================================================
- # Author: Dax
- # Version: 1.0
- # Site: www.dax-soft.weebly.com
- # Requeriments: ldufcmd.exe (download at my website, just there)
- #==============================================================================
- # • Desc:
- #------------------------------------------------------------------------------
- # Allow you download files from web, direct by your rpg maker project.
- #==============================================================================
- # • How to Use:
- #------------------------------------------------------------------------------
- # lducmd(url, filename, ext, path)
- # url : your web link url
- # filename : For default is '-f', that is mean: original filename from link.
- # ext : For default is '-e', that is mean: original extension file from link.
- # If are you gonna change, don't put on a '.'... example: 'jpg'
- # path : For default is '-p', that is mean: original directory where the
- # app is.
- #------------------------------------------------------------------------------
- # url = "http://dax-soft.weebly.com/uploads/1/5/7/2/15724724/plugin.exe"
- # lducmd(url)
- #==============================================================================
- class << Kernel
- #----------------------------------------------------------------------------
- # • Method:
- # Return to boolean status
- #----------------------------------------------------------------------------
- def lducmd(url, filename="-f", ext="-e", path="-p")
- # setup
- path = "-p" if path.nil? or path.empty?
- filename = "-f" if filename.nil? or filename.empty?
- ext = "-e" if ext.nil? or ext.empty?
- filename = filename.gsub(" ", "_") unless filename == "-f"
- # call the program
- system("start ./ldufcmd.exe -s #{url} #{path} #{filename} #{ext}")
- # loop while downloading
- loop {
- # if runnig
- status = `tasklist | find "ldufcmd.exe"`
- # end?
- if status.empty?
- break if filename == "-f"
- # get the recent file add
- _file = Dir.glob("*").sort {|a,b| File.ctime(a) <=> File.ctime(b)}.last
- # get the path
- _path = ->(file) {
- x = File.absolute_path(file).split("/")
- ext = File.extname(x.last)
- x.delete_at(x.size.pred)
- str = ""
- x.each { |i| str += i + "/" }
- return [str, ext]
- }
- # filename change
- filename = filename.gsub("_", " ") + _path[_file][1]
- # change the name to filename origal
- File.rename(_path[_file][0] + _file, _path[_file][0] + filename) rescue break
- break # bye
- end
- }
- return true
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement