OSQ: Download/install update in-game

Hello all,

This summer I’m taking on a large game development project, and to start it off I’m doing several mini-projects, of which this is the first. I’ve created here a “mock-up operating system” called OSQ (Q was a my nickname at one point in time). Though partly to experiment with UI controls and responsive buttons etc, the main purpose is to implement an update system in-game.

While this is made to look like an operating system’s update, the more general idea is that when you startup your game, it checks online to see if you (the creator) has posted an updated version, ie adding new textures or new levels, etc. It then, while still running the game, will download the relevant parts of the update of the main game while holding the user in a temporary “update” scene, while everything is downloaded and moved to the right location.

This is my attempt at doing this :slight_smile:

Downloads below, do me a favor and test the updater! –and (if you don’t mind) post a comment with your system setup and whether it succeeded or failed

Links:

Download for Windows x64
Download for Mac x64
Download for Mac x32
Download raw blend

(Sorry no win x32, but the blend file will do on its own)

EDIT4: I believe finally that everything is fixed, so everyone test it out – see if you can successfully update/revert in-game without ever leaving the player! At this point, as I say in a later post, the download can only fail to my knowledge in two circumstances:

  • If MediaFire changes their page layout, since the most stable way to retrieve the actual file URL location is to extract it from the fancy interface page knowing that it is the “Nth” url to appear
  • At least once I have seen the “spam blocker” page come up instead of the actual download page, which I suppose is actually designed to prevent scripts/programs like this from downloading as I am having it do :smiley:

Screen Shot of OSQv1.0:


Screen Shot of OSQv1.1:


In a nutshell, I am using the urllib.request module. OSQ will check this webpage to see if there is an updated version of itself by shifting through the html text it downloads to make a list of the below data, of the version numbers and the corresponding URL’s. The biggest problem is that I am using an external hosting service, mediafire, so the exact file locations have the potential to change. At this point, the only thing that can go wrong and prevent the download is a user-side configuration problem or some change to the website where the file is posted. Please, please do not make a comment containing the exact phrase of four or more ‘/’ in a row. Thank-you :slight_smile:

////OSQv1.0////http://www.mediafire.com/?o23ar0ame79gcgz////OSQv1.1////http://www.mediafire.com/?lvgd1khoovjffc2////

I probably will go to the lengths of creating a sort of library or systematic way of incorporating this into your game. If I do, it will be around the time that I’m redoing it for myself in my upcoming more major game project, later this summer.

If anyone else found that the game/mock OS got stuck somewhere, especially during the update, please respond so I can look into it and know what to improve!

Sounds really interesting. I’d like to see how easy this is, and how it works.

In concept, it’s quite easy. Using urllib.request module you can download files from servers, the tough part is getting your game to figure out where the most updated file URL is :wink:

As of a couple hours ago, I actually got the whole thing working… minus the seemingly trivial problem of recursive unzipping the downloaded .zip file (any help on this? I’m not finding straightforward solutions for python 3). Assuming I get that figured out, just a couple things to make pwetty and I’ll have it up.

I suppose on a more general note, you have to be very careful in the way you setup everything. In an actual game, which is what I’ll ultimately end up tackling in my later more major project, you need to split up the game download into pieces and have it somehow cross check the version number and download only the needed assest (eg if from v3 to v4 don’t download characters.zip because no changes were made between that version, but you did make a change so in updating v3 to v5 it should download it, etc)

I’ll do a proper walkthrough of the setup later once it’s entirely working :slight_smile:

Wouldn’t it be easy to use the, if I recall correctly, which I don’t think I do, os module to check the date modified stamp of the file? If there is no similar file in the game folder, or if the date modified is after the existing file’s last modified date, then it should download / replace the existing file with the updated version.

EDIT: And the zipfile module can unzip files, though I’m not sure of what you meant by ‘recursively unzip’.

That’s a good point, I’ll have a look into that later…

I’m actually having a ridiculous time with this silly unzipping problem. Just unzip, that’s all…

If you or someone else wouldn’t mind, I’m having some sort of encoding error. I’ve written an “unzip” script that works without any problems through the python IDLE, but when I run it through blender it raises:

File "blender.app/Contents/MacOS/2.62/python/lib/python3.2/zipfile.py", line 804, in _RealGetContents
LookupError: unknown encoding: cp437

I just included the last error file of a few that occurred in zipfile. Below is what I’ve tried so far, and no luck

  • looking to see if blender’s packaged python has cp437.py in lib/python3.2/encoding - it does
  • I noticed, however, that the sizes of my full python3 package and blenders package version of this encoding library folder were different sizes - replacing it with mine still resulted in the same error
  • In a last desperate attempt, I replaced the entire python library of blender and the blenderplayer with the one from my computer, which still didn’t work (each time I ‘replaced’ some part of the python libraries, I kept backups so I at least reverted to the original state in between each step)

Below I’ve posted my unzip code, just supply any zip file (‘path/file.zip’) and the (’./output/folder’) you want it to be unzipped to.


def unzip(file, dir):
    if os.path.isdir(dir):
        shutil.rmtree(dir)
    os.mkdir(dir)
    zfobj = zipfile.ZipFile(file)
    for name in zfobj.namelist():
        if name[0] in ['_','/','.']:
            pass
        elif name.endswith('/'):
            os.mkdir(os.path.join(dir, name))
        
        else:
            outfile = open(os.path.join(dir, name), 'wb')
            outfile.write(zfobj.read(name))
            outfile.close()

Again, I got this to work fine on my machine separate to blender, but not running from within it. Worse comes to worse, I can try to look into other compression formats…

I tested it, and it works fine for me - unzipped fine into the directory that I specified. I zipped the file with 7-zip in .zip format, if that matters. Here’s the line that I used to call your function:

unzip(logic.expandPath('//test.zip'), logic.expandPath('//TestFolder'))

EDIT: Oh, and try looking for the >first< error - sometimes early errors will cause other problems later on, thereby causing unrelated errors. The first error is the real problem.

I’ll definitely try this later. It sounds like an awesome idea.

If a lot of BGE users were able to use this in-game updating system, I reckon it would make the whole development process more efficient.

It’s done! I’m still working on creating a short video on it, of course you can download the “operating system” below to test it out yourself!

[Links in the first post]

[Edit: this was my 100th post!] :wink:

hey the Duckcow, your logo is way better now!!! also congratulations this system that you created look very cool!

Fix posted! For those that already tried it out, though it may look mostly the same there were a number of changes to the updater. The problem with “changing servers” has been circumvented, the main thing that can go wrong now is MediaFire catching the program in the spam filter (you know, when you post too much/download too much the box that comes up saying “type in the letters of this image to continue” which then would actually redirect you to the real download page).

Pleas, please try out the downloaded (and comment below if there was an issue)! It should only take a couple minutes to try it out and if I confirm it works on a wide range of machines, it confirms that this can be actually a fairly stable feature people can add to a game!

For me it worked out very fine, I didnt let the updating loading end, but it worked, very well done man!

I’m surprised more people haven’t been curious about this, but oh well :slight_smile:

I’ve finally finished the demonstration video. After about the midway point I go into a little bit of the programming, enough that if there is anyone who is curious it would certainly be a good starting place to do something similar in the bge.

Downloaded on my Mac OS X 10.58 and got an error, (automatically quit).
http://www.pasteall.org/pic/show.php?id=32949
It’s a great idea, so congratulations on it working for anyone else. :slight_smile:

I should have considered this before, but I was exporting 64-bit blender players (and OSX didn’t support x64 until 10.6). I’ve added a 32 bit version that I tried on my old laptop… do you normally have any trouble with blender games on that machine? I just tested this 32 bit version on my 10.58 laptop and it ran at 0.25 fps, but the same (32 bit) player ran fine on my newer computer, version 10.6. It also could just be the result of using that old laptop as a render slave :slight_smile:

So hey, try it again if you get around to it! On a side note, the .blend will work so long as you have a 2.6 version of blender installed :wink:

Nice to know this can be done. Now can we have minecraft in blender?