Question

Title. It's only allowed to save to a certain directory, but is there a way of making an executable made with it update itself? I've got the code to check if it's out of date (HttpGet), but not sure how to intall the newer update.

Main reason is people are complaining about having to repeatedly redownload my RPG. Would it be easier to package it with a C# auto-Updater they can run?

Was it helpful?

Solution

You can not make the .love file "update itself". That is not possible, unless you use the operative system's package manager or something similar (apt-get in Ubuntu, the app store on mac, and whatever microsoft uses, if it has it).

If you don't want to do that, then the second best way to make that work would be making your love2d executable a "shell"; an "empty game" that simply downloads stuff from the internet, and later on it executes some function that initializes everything, including the proper game.

As jpjacobs says, you can download stuff from the web using LuaSocket (which is already included in LÖVE 0.7). For example, this is how you download a png (I've copied the code from here):

if not love.filesystem.exists("expo.png") then
  local http = require("socket.http")
  local b, c, h = http.request("http://love2d.org/w/images/e/e3/Resource-AnalExplosion.png")
  love.filesystem.write("expo.png", b)
end

There's also a way to uncompress data using the GNU unzip algorithm using pure lua. It's implemented by the /AdvTiledLoader/external/gunzip.lua file in Kadoba's Advanced TileLoader.

So I guess you can make a game that:

  1. Starts by reading a file called version.lua, and comparing it to a file in your server (http://www.your-server.com/latest-version-number). That file simply contains a number, like "48".
  2. If no file and server could not be contacted, then error "could not download game".
  3. If no file, or current version < latest version from the server, download zip file from server (http://www.your-server.com/latest.zip)
  4. If latest.zip downloaded successfully, erase everything inside the /latest directory and uncompress latest.zip on the new latest. Update version.lua with the new version (return 48)
  5. Detect when you are working offline - If could not download latest.zip or version, but there's already a version.lua and latest folder, give just a warning, not an error.
  6. Require the file that contains the real game; probably something like require 'latest.main'

Notes:

  • I'm not familiar with luasocket. It is possible that there's a way to get the 'last updated' date from http://www.your-server.com/latest.zip, so you can simply get rid of the latest-version-number stuff.
  • I haven't used gunzip.lua myself. I don't know how it handles multiple files, or directories.

OTHER TIPS

My first guess would be using LuaSocket. You can have a small file containing the current version number, have that downloaded on startup, and then decide whether an upgrade is necesarry or not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top