Client library
The ZeroInstall.Client namespace allows you to invoke Zero Install commands from within other applications.
Use Detect to automatically discover the locations of the 0install
and/or 0install-win
executables. This gives you an instance of IZeroInstallClient, which enables easy programmatic access to a subset of the Command-line interface.
Samples
Detect 0install
location and the feed URI used to launch the app:
var zeroInstall = ZeroInstallClient.Detect;
var feedUri = ZeroInstallEnvironment.FeedUri ?? new FeedUri("https://example.com/your-feed.xml");
Download updates if available:
if (await zeroInstall.UpdateAsync(feedUri))
NotifyUpdateAvailable();
Restart the app to run the latest version:
zeroInstall.Run(feedUri);
Environment.Exit(0);
Toggle the app's auto start desktop integration:
bool isAutoStartEnabled = (await zeroInstall.GetIntegrationAsync(feedUri)).Contains("auto-start");
if (isAutoStartEnabled)
await zeroInstall.IntegrateAsync(feedUri, remove: new[] {"auto-start"});
else
await zeroInstall.IntegrateAsync(feedUri, add: new[] {"auto-start"});
Error handling
The client library maps 0install
's exit codes to exceptions. Your code should be ready to catch:
- IOException:
0install
could not be launched or there was a problem accessing the filesystem. - WebException: There was a problem downloading a file.
- OperationCanceledException: The user canceled the operation.
- ExitCodeException: Any other kind of error.