boskee / Minecraft

Simple Minecraft-inspired program using Python and Pyglet
MIT License
207 stars 33 forks source link

Create update mechanism #93

Closed r58Playz closed 5 years ago

r58Playz commented 5 years ago

This updates the game using requests.

EDIT: The git function has been removed in commit 947bfad

Closes #71

Nebual commented 5 years ago

Good idea, but I'm not sure this is an ideal approach...

  1. At this stage of development, 99% of people running this are going to be using the git version anyway, in which case updating is a simple git pull + relaunch. Once the game is meaningful to users who wouldn't use git directly, we'd probably produce packaged Releases (including pyglet/dependencies), possibly as a self-contained .exe. Travis/Appveyer can automate this.
  2. The sorts of users who can't be served by a git pull likely don't have git installed to be able to run git clone. Replacing the git clone with something like (untested)
    r = urllib.request.urlopen('https://github.com/boskee/Minecraft/archive/master.zip')
    with zipfile.ZipFile(BytesIO(r.read())) as z:
    z.extractall()

    is more portable (non-Windows), is much more efficient/fast than a git clone, doesn't involve temporary files, and avoids run() in favour of pure python.

  3. You still need to manually relaunch the game, hot-reloading would be sweet for development (and useful for this)... you might also be able to get away with replacing python main.py with python update_and_run_main.py which checks for + updates first, prior to import'ing/exec'ing the rest of the game, though that would prevent you from having a nice pyglet Update button.
r58Playz commented 5 years ago

That's fixed...

r58Playz commented 5 years ago

Replacing the git clone with something like (untested)

r = urllib.request.urlopen('https://github.com/boskee/Minecraft/archive/master.zip')
with zipfile.ZipFile(BytesIO(r.read())) as z:
    z.extractall()

That works, but there's a catch: It updates update.py.

r58Playz commented 5 years ago

So, we need to use temporary files so that while updating, the updater does not update itself(the updater overwrites the file it is in).

r58Playz commented 5 years ago

Oh, in the imports the urllif.request needs to be changed to urllib.request. Also, append this after all the imports:from io import BytesIO