Skip to content

How do updates work?

Brendan Forster edited this page Oct 26, 2013 · 16 revisions

So we know how to get started and create an installer but once your app is out there in the wild, how can we get it to update?

Updates using Squirrel

Let's run through how you use the Squirrel UpdateManager.

A note about Reactive Extensions

Squirrel uses Reactive Extensions (Rx) heavily as the process necessary to retrieve, download and apply updates is best done asynchronously. If you are using the Microsoft.Bcl.Async package (which Squirrel also uses) you can combine the Rx APIs with the TPL async/await keywords, for maximum simplicity.

Check yourself

First, check the location where your application updates are hosted:

var updateManager = new UpdateManager(@"C:\Users\brendanforster\Desktop\TestApp", 
                                      "TestApp", 
                                      FrameworkVersion.Net40);

var updateInfo = await updateManager.CheckForUpdate();

if (updateInfo == null) {
    Console.WriteLine("No updates found");
} else if (!updateInfo.ReleasesToApply.Any()) {
    Console.WriteLine("You're up to date!"); 
} else {
    var latest = updateInfo.ReleasesToApply.MaxBy(x => x.Version).First();
    Console.WriteLine("You can update to {0}", latest.Version);
}

Depending on the result you get from this operation, you might:

  • not detect any updates
  • be on the latest version
  • have one or more versions to apply

Fetch all the Updates

The result from CheckForUpdates will contain a list of releases to apply to your current application.

That result becomes the input to DownloadReleases:

var releases = updateInfo.ReleasesToApply;

await updateManager.DownloadReleases(releases)

Apply dem Updates

And lastly, once those updates have been downloaded, tell Squirrel to apply them:

var results = await updateManager.ApplyReleases(updateInfo);
updateManager.Dispose(); // don't forget to tidy up after yourself

TODO: do we care about these results? I don't think so.

Clone this wiki locally