I participate in the development of a certain game and are finally tired of uploading a new copy of the game each time, considering that it already weighs 3+ gigs. We decided to do the cool thing in advance and make either a launcher for the game right away, but then quickly retreated from this idea and decided to make at least a clean update.

Task:

The essence of the update should be that somewhere on the server / hosting (including virtual) are all these 3+ gigs of the game, when a new version comes out - it is uploaded there via FTP with the replacement of files. When a new version comes out, players can simply run the update and they will check all the game files with those on the hosting and replace the old ones with the new ones (but they will not upload the same ones).

How do I guess this should work?

I don't know for sure about that. I suppose it is necessary to make a byte check of each file to know for sure that it is old or new, but then it will be long and there will be a large load on the server (probably, after all, hundreds of people will download the game, and moreover they will download it almost on the day of release updates all at once).

Another option is to compare the sizes of SHA1 or something like that. But what if only 1 character is changed in the file, is there any chance that this method will miss any change?

Tools for this:

I have not worked with the files yet as detailed as necessary here. I mainly worked with web technologies: PHP, JS, and everything related to them or lies side by side. I read them, they can be used with for example WinJS, PHP-GTK or I really liked PHP Desktop with its capabilities. But it sounds like some way through the back seat. I am not very familiar with C ++ and I think to try to implement something like this in C #.

But I’m almost sure that you don’t need to think of anything, where there may already be a ready-made solution, so that you can create a regular update.exe which will go through all the files and replace the necessary ones. I found some kind of electron-builder who might do something like that, but first I would like to hear the opinion of more experienced people on this topic.

  • Winjs only supports Win8 + and to access the files, the user must confirm the selection of the desired folder. Node.js is a normal option for writing a console application, Electron and NW.js, which are not needed for the GUI. - Alex78191

1 answer 1

  1. To update the game files, the game must be stopped so that there are no problems with access to the file.
  2. The game weighs quite a lot, you still need to know the maximum file size, it will also affect the file comparison operation.

The above two points will most likely not allow you to use some kind of ready-made solution (for example, lftp), especially the first one. You need to write your game loader, which will check for updates and perform this update, after stopping the game.

As for the file comparison, I would start the register of versions (hashes) of files - text document. According to it, it would be possible to judge what needs to be updated and what is already there. Those. one text file lies with the user, the other is on the server, both versions of the files are already counted, there is no need to calculate anything each time. When replacing a file, edit the local text file by inserting the current versions of the hashes.

The only drawback with this approach is that if the user manually deletes a part of the files, then your updater will not notice this, since he relies on a text file. On the other hand, it is possible to add another utility to complete the scan of files, which will read the hash of the amount of files and check them with data from the local text file.

The structure is approximately as follows:

/data/ /sounds/ /sound1.mp3 {sdfu9r72fv83r7wehfsed} /sound2.mp3 {df82j0380dusoisdfsdfs} 

What is the game, on that, probably better and write a utility to update.

I do not think that it is worth thinking about the collisions of file hashes (different files have one hash), this is probable.

  • Yes, at the expense of hashes, I already found while doing a more detailed search. The question is how to make a hash? Is it just encoded byte file size or is it something else? Files will not be very large, but they will be quite a lot, which will lead to the size of 3GB. The only problem here is to look for reliable hosting that would distribute it for cheap. At the expense of manual deletion of files by the user, nothing can be done, in terms of it is in the interest of the player not to delete anything :) But I understand what you are talking about, it’s in plans for future versions if it will be useful. - Telion
  • @Telion You need to create hashes using ready-made functions. They are calculated for all sites of the file. - Alex78191
  • You can compare files by date of change. - Alex78191
  • There are ready-made libraries for comparing folders via FTP by size or date. Winscp.net/eng/docs/library_session_synchronizedirectories - Alex78191
  • @Telion, the hash is made on the basis of the entire content of the file, the only way. Everything else may not give the desired result. No date, no size. - Dima G.