8

In the company I am I was asked to write an autoupdate function a la chrome. I.e. It should check periodically whether a new version is available, download the new version and apply it silently the next time the application starts.

I already have something up and running but it is more like a dirty hack than something I feel happy about it. So, I would like to know how to design and implement such a solution. My horrible hack works as this:

  1. Have a mechanism to check whether a new version exists (a database query or a web service)

  2. Download a full zip with the whole new version.

  3. Check file signature. If everything went alright, set a registry value: must update to true.

  4. When the application restarts, if the must update value is true, launch an update program and exist.

  5. The update deletes the contents of the application folder, unzips the update and replaces the old contents, launches the application and exits.

Now, I would like to change it, so it works cleaner. I am planning to send the update as a bsdiff file. It gets downloaded. But the question is, what happens next?

When do apply the update? Who is in charge of applying the patch? is it the program itself or is it a third program, as I did, which is in charge of applying the patch and relaunch the application?

Sambatyon
  • 3,316
  • 10
  • 48
  • 65

4 Answers4

3

If your going down the C++ route you can go to chromium and download the Chrome source code and dig around to see how the update is done, this might give you a better idea on how to approach it. Here's an article that might help.

If your familiar with .NET the recently release nuget also has an auto update feature that might be useful to look at, you can get the source code from here. David Ebbo has a blog about how its done here.

I'm not up to date on Delphi but you might be able to use either of the above options.

lancscoder
  • 8,658
  • 8
  • 48
  • 68
2

You could literally use the Google Chrome update workflow by using the Google Chrome updater:

http://code.google.com/p/omaha/

They open sourced it Feb 2009.

Chris Moschini
  • 36,764
  • 19
  • 160
  • 190
2

So, after giving it a lot of though, this is what I came with (for active directory I will refer to the directory where the main program lies, active program is the main program and update program is the one that replaces the active program and its resource files):

  • The active program checks if there is a new version every certain amount of time. If so, download it
  • Prepare new version in a separate folder (this can be done by copying the contents of the directory with the program to a subdirectory and applying a binary patch, or simply unziping the new version).
  • Set a flag that indicates that a new version is ready.

When a program is exiting (and one has to control for different interrupts here):

  • The active program checks the new version ready flag. Launch the update program and exit.
  • The update program checks if it can write in the active directory. If so, replaces the contents with the prepared version.
  • The update program has to recheck links and update them accordingly.

So guys, if you have a better workflow, please tell me.

Sambatyon
  • 3,316
  • 10
  • 48
  • 65
2

The workflow you proposed is more or less like it should work, but there's no need to re-invent the wheel - there are plenty libraries out there that will do this for you. Using a 3rd party library has the benefit of keeping your code cleaner while making sure the dirty process of auto-update is contained and working flawlessly.

Trust me, I know. I'm the author of NAppUpdate, an app update framework for .NET (which you might want to try out or learn from).

synhershko
  • 4,472
  • 1
  • 30
  • 37
  • Although it started as a problem at work, now I am just interested on the topic and doing research on my own. I was also thinking on writing a library for it. – Sambatyon May 31 '11 at 08:43
  • Take a look at NAppUpdate and tell me if another library is needed at all :) – synhershko May 31 '11 at 09:45