Unity Standalone Auto-updater/Launcher Issue

After countless searches, I am unable to find an answer to my issue.

I have created a Standalone client launcher, which is self-updating and also checks for newer client files. It checks for newer client files by comparing the file size of the local client file to the client file data hosted on the server. If the file size is different, the launcher will download the new file and install it.

However, this does not always work. Sometimes files that were updated share the exact same file size… preventing the launcher from downloading the newer file.

The problem is that Unity will delete, and recreate, the folder and all of it’s contents; for the Standalone client. I can not check against creation or modified dates, since Unity creates all new files on every build.

My question: Does anyone know how to solve this problem?

You need to use a hash to represent the file and check against that. Typically MD5 hashes are used. MD5 hashes can take a while to generate, so you only want to generate them if the modification date has changed. Cache your MD5 hashes along with file name and modification date to a file. If the hash doesn’t match what the server has, download the new file to a temporary directory, and record the new hash (from the server don’t regenerate) in a temporary cache file. When all updated files are downloaded move the changes over to the proper locations. Using the temp directory prevents the updater from breaking the game if the update is interrupted.

You may also need the game client to move updated Client Loader files into place, as Windows won’t allow you to over write a currently running application. In such a case, you would update the new loader to the temp directory first. Execute the game client with a command line argument to tell it it needs to update the loader and to run in headless mode, then quit the loader. From the game client, check for command line arguments, if the update argument is found, move the updated loader files into place, then start the loader, and quit the game client. Finally download the latest game files as above.

You could also go fancy, and use the Dropbox API. It creates hash files for you, and if you attempt to push a file through the DB API that ends up having the same hash as the previous file, it will simply not send it.

You’d then need to incorporate DB API calls in your launcher to compare local hashes, to the ones stored on Dropbox. You can even check hashes on folder levels, instead of looping through all files, and comparing hashes that way.

Another option, is to keep the standalone data folder under version control, and let SVN/GIT tell you which files actually changed. All you’d have to do then, is perform an update call to your master repository (from within your launcher / updater), and let version control handle the rest.

Best of luck.