Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
How to download multiples files with UrlLoader? - Gideros Forum

How to download multiples files with UrlLoader?

I'm trying to adapt UrlLoader example to download multiple files.

My problem is that when I try to download next file it interrupts the previous one.

I tried to start next downloads from onComplete handler but I'm making some sily mistske because it is not working.

As I failed to fix it I duplicated the sampke code 3 timed to download all files I wanted to.

Any advice id very much appreciated.

Thanks.

Comments

  • rrraptorrrraptor Member
    edited December 2019 Accepted Answer
    FilesLoader = Core.class(UrlLoader, function(url,method,headers,body) return nil end)
     
    function FilesLoader:init(url, files)
    	self.url = url
    	self.files = files
    	self.currentFileInd = 1
    	self.currentFile = ""
    	self.maxFiles = #self.files
     
    	self:addEventListener(Event.ERROR, self.error, self)
    	self:addEventListener(Event.COMPLETE, self.complete, self)
    end
     
    function FilesLoader:message(str, ...)
    	print(("[FilesLoader]: "..str):format(...))
    end
     
    function FilesLoader:error()
    	self:message("Error while loading file \"%s\"", self.currentFile)
    end
     
    function FilesLoader:complete(event)
    	local out = io.open("|D|"..self.currentFile, "wb")
    	out:write(event.data)
    	out:close()
    	self:message("Finished loading \"%s\"", self.currentFile)
    	if (self.currentFileInd <= self.maxFiles) then 
    		self:start()
    	else
    		self:message("All downloads finished.")
    	end
    end
     
    function FilesLoader:start()
    	self.currentFile = self.files[self.currentFileInd]
    	self:message("Loading file \"%s\"...", self.currentFile)
    	self:load(self.url .. self.currentFile)
    	self.currentFileInd += 1
    end
     
    local url = "<a href="https://raw.githubusercontent.com/MultiPain/Gideros_BluredShape/master/&quot" target="_blank" rel="nofollow">https://raw.githubusercontent.com/MultiPain/Gideros_BluredShape/master/&quot</a>;
    local file_list = { "main.lua", "GShape.lua", "ShapeRender.lua", "init.lua" }
     
    local loader = FilesLoader.new(url, file_list)
    loader:start()


    P.S. For some reason forum engine adds "< a >" tag to url :smile: Safe to remove it.
    image.png
    897 x 155 - 36K
    +1 -1 (+4 / -0 ) Share on Facebook
  • @rrraptor super cool man :)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • @rrraptor Thank you so much. That's what I wanted.
  • @rrraptor can I put it in the wiki? :)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • @MoKaLux you can, but I think its not needed. Existing 2 examples is more than enough to understand how it works. Also, this line can be a bit confusing for newbies:
    FilesLoader = Core.class(UrlLoader, function(url,method,headers,body) return nil end)
    Personally I dont like big examples, they must be small.

    Likes: oleg, MoKaLux

    +1 -1 (+2 / -0 ) Share on Facebook
  • rrraptor said:

    @MoKaLux you can, but I think its not needed. Existing 2 examples is more than enough to understand how it works. Also, this line can be a bit confusing for newbies:

    FilesLoader = Core.class(UrlLoader, function(url,method,headers,body) return nil end)
    Personally I dont like big examples, they must be small.
    I agree, the examples should be short.

    But you can make a link under the examples-
    For more advanced examples.

    Likes: MoKaLux, plicatibu

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+2 / -0 ) Share on Facebook
  • MoKaLuxMoKaLux Member
    edited December 2019
    @rrraptor @oleg I understand your point. I like short examples too but I also like fully fledged classes :) that make our life so much easy.
    I can add it where @oleg mentioned (advanced example) if I can make it work on my side first :) .
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • plicatibuplicatibu Member
    edited December 2019
    @rrraptor I made a project using your code.

    For some reason, when I try to download files from unsafe URLs (http) everything works fine, but for https URLs it always failed.

    I tried 5 different https URLs. When I try to access them directly in my browser I see the file but when I put the URL in script, it doesn't.

    For example:
    -- XPTO://www.mozilla.org/media/protocol/img/logos/firefox/browser/logo-sm.f2523d97cbe0.png
    local url = "XPTO://www.mozilla.org/media/protocol/img/logos/firefox/browser/";
    local file_list = { "logo-sm.f2523d97cbe0.png"}

    Any idea what may be the problem? I'm using Gideros Player in Windows 10.

    Thanks

    PS: I replaced https by XPTO to avoid the anchor tag.

    Likes: MoKaLux

    +1 -1 (+1 / -0 ) Share on Facebook
  • It seems UrlLoader dos not handle HTTPS protocol. :/
  • Are you using windows and ssl isn't working in the player? If so, copy the contents of this rar file to your install folder:

    https://www.dropbox.com/s/y8ixf3d03ygf29t/extra_ssl.rar?dl=0
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+3 / -0 ) Share on Facebook
  • Now it worked like a charm.

    Thank you.
    +1 -1 (+2 / -0 ) Share on Facebook
  • I don't think we can distribute those files officially with the main build. Not sure exactly why.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
Sign In or Register to comment.