This solution lab provides a working example of an application that can download
and apply a series of updates (an update “chain”) automatically. This is in contrast
to an application that can only discover and apply a single update at once.
AppLife Update allows you to choose which versions of your application can apply
any given update, and combined with the new Patch File action, this feature
can allow you to keep updates very small. However, using small updates that apply
to specific versions can be inconvenient for users who just installed an older version,
or who update infrequently. These users will need to update their software over
and over again until they finally have the latest version. Using a chained update
system, we can automate that process and make the multiple updates transparent.
This solution lab presents the first part of a chained update system, showing how
to implement chained update logic into your application so that all the updates
needed to move to the latest version of your application are downloaded at once
and applied automatically. Part two will extend this example with a custom updating
user interface that unifies the user interface as the updates are applied.
The first step of a chained update solution is finding all the updates in a chain.
Using the information provided by the UpdateController, this is easy. An
update chain is simply composed of all the updates that would normally be applied
separately, so in order to find the chain, we can follow these steps:
- Set the UpdateController’s version to the current
version—when we begin making an update chain, this is the version of the application
that’s running now.
- Find the highest version update that can be applied
to the current version.
- Change our current version to the version of the update
we found, effectively “simulating” having that update applied.
- Go back to step 1.
We then repeat these steps until there is no update to be found. With previous versions
of AppLife Update, these steps would require multiple update checks, but with the
new AllUpdates collection, the UpdateController makes this process extremely
simple by caching the updates it finds. All we have to do is check for updates once.
After that, just changing the Version property of the UpdateController
will refresh its list of AvailableUpdates, allowing us to see instantly whether
another update is in the chain.
Once an update chain is found, downloading the updates is simple—just set the CurrentUpdate
property on your UpdateController, and call one of the DownloadUpdate
methods. The controller does the rest. Since you might have a long list of updates
to download, it’s helpful to allow them to download in the background. The example
project shows one way of doing this. The built-in download resume features of AppLife
Update mean that even if your application shuts down in the middle of a download
session, it can pick up right where it left off the next time.
The last step of a chained update process goes back to the beginning of your application.
Once all of your updates have been downloaded, it’s time to apply them—but each
update can only be applied once the previous update has finished. Fortunately, we
can use the automatic restart feature of AppLife Update to make sure all the updates
we downloaded get applied before our application really restarts.
To do so, we modify our application’s start-up code to determine whether an update
chain is in progress. In the example solution, this is done by creating an UpdateController
with the same settings we use to check for updates, and then checking the IsFirstRun
property. This property is only true for the first UpdateController that has these
settings after an update has been applied. Since we set up an UpdateController with
these settings every time the application starts, we know that if the property returns
true, the application was just restarted after an update, and may be in the middle
of an update chain.
If we know that the application was just restarted after an update, we then check
to see if there is another update in a chain ready to be applied. To do so, we first
need to check for an update—if no update is available, then the chain must be finished.
Even if an update is found, it may have been published after the chain started,
so we also make sure that the update is already downloaded. If so, we apply the
next update in the chain and shut down the application before it gets a chance to
really start up.
Chaining updates can provide a way for you to keep update sizes down by issuing
small patches that can only be applied to specific versions, while still providing
a pleasant and convenient user interface. The downside of chained updates is that
the user will see a series of “Updating” dialogs as each update is applied. In part
2 of our chained updater solution lab, we present a way to show a single, unified
UI that represents all updates in the chain as part of a single process.
For answers to questions about this example, please contact Kinetic Jump tech support.
techsupport@kineticjump.com
Download AppLife Update Here