-
Notifications
You must be signed in to change notification settings - Fork 55
How do updates work?
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?
Let's run through how you use the Squirrel UpdateManager
.
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.
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
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)
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.