Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Player to reload last project on device — Gideros Forum

Player to reload last project on device

grotlygrotly Member
edited March 2012 in Suggestions & requests
Hi Gideros team!

I noticed that the code for the projects run on the device stays in a folder even after the player is closed. I was wondering if it's possible to make the player run the latest run project when launched on the device. It would be nice to show the progress to my friends for getting feedback without having to be near my computer.

Thanks!

Comments

  • atilimatilim Maintainer
    Yes this feature is requested a couple of times. But I haven't put it to the roadmap yet. Here it is: http://bugs.giderosmobile.com/issues/73
    +1 -1 (+3 / -0 )Share on Facebook
  • MagnusviriMagnusviri Member
    edited March 2012
    Put this in your main.lua file. I haven't tried to handle file dependencies. But this will download the latest code from a webserver. This is how I'm able to code on my iPad and run it on my iPhone.
    function exists(fname)
    	local f = io.open(fname, "r")
    	if (f and f:read()) then return true end
    end
     
    fileLoader = Core.class()
    function fileLoader:onComplete()
    	local out = io.open("|D|"..self.currentFilename, "wb")
        out:write(self.loader.data)
        out:close()
    	self.info:setText(self.currentFilename.." downloaded")
    	print(self.currentURL.." downloaded")
    	self:step()
    end
    function fileLoader:onError()
    	self.info:setText("error downloading "..self.currentFilename)
    	print("error downloading "..self.currentURL)
    end
    function fileLoader:onProgress(event)
    	self.info:setText("progress: " .. event.bytesLoaded .. " of " .. event.bytesTotal)
    	print("progress: " .. event.bytesLoaded .. " of " .. event.bytesTotal)
    end
    function fileLoader:step()
    	if ( table.getn(self.urls) > 0 ) then
    		self.currentURL = table.remove(self.urls)
    		self.currentFilename = string.match(self.currentURL, ".*/(.*)" )
    		local download = not exists("|D|"..self.currentFilename)
    		if self.currentFilename == "main.lua" then
    			self.currentFilename = "main2.lua"
    			download = true
    		end
    		download = true -- I'm just always downloading because if a 404 occurs then the file is corrupt and needs to be replaced, eventually I should find out if it is a 404 and just not save it.
    		if download then
    			self.info:setText("loading "..self.currentFilename)
    			print("loading "..self.currentURL)
    			self.loader = URLLoader.new(self.currentURL)
    			self.loader:addEventListener(Event.COMPLETE, self.onComplete, self)
    			self.loader:addEventListener(Event.ERROR, self.onError, self)
    			self.loader:addEventListener(Event.PROGRESS, self.onProgress, self)
    		else
    			self.info:setText(self.currentFilename.." exists")
    			self:step()
    		end
    	else
    		--stage:removeChild(self.info)
    		self.completionHandler()
    	end
    end
    function fileLoader:init(urls, completionHandler)
    	self.completionHandler = completionHandler
    	self.urls = urls
    	self.info = TextField.new(nil, "loading files...")
    	self.info:setPosition(10, 10)
    	stage:addChild(self.info)
    	self:step()
    end
    Texture.oldNew = Texture.new
    function Texture.new(filename, filtering, options)
    	if exists(filename) then
    		return Texture.oldNew(filename, filtering, options)
    	elseif exists("|D|"..filename) then
    		return Texture.oldNew("|D|"..filename, filtering, options)
    	else
    		return nil
    	end
    end
     
    local downloadURLs = {
    	'<a href="http://dl.dropbox.com/u/path/to/file.lua'" rel="nofollow">http://dl.dropbox.com/u/path/to/file.lua'</a>,
    	'<a href="http://dl.dropbox.com/u/path/to/image.png'" rel="nofollow">http://dl.dropbox.com/u/path/to/image.png'</a>,
    }
     
    function start()
    	dofile("|D|file.lua")
    end
    fileLoader.new(downloadURLs, start)

    Likes: gorkem, atilim, ndoss

    +1 -1 (+3 / -0 )Share on Facebook
  • Thanks, I'll try it today.
Sign In or Register to comment.