Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void AutoUpdate()
- {
- // Get a local pointer to the UpdateManager instance
- UpdateManager updManager = UpdateManager.Instance;
- // Only check for updates if we haven't done so already
- if (updManager.State != UpdateManager.UpdateProcessState.NotChecked)
- {
- //Update has already begun
- if (updManager.State == UpdateManager.UpdateProcessState.RollbackRequired)
- {
- //If rollback is required carry it out
- updManager.RollbackUpdates();
- }
- else
- {
- return;
- }
- }
- try
- {
- // Check for updates - returns true if relevant updates are found (after processing all the tasks and
- // conditions)
- // Throws exceptions in case of bad arguments or unexpected results
- AppLog.LogEvent("NAppUpdate: Checking for updates");
- if (updManager.CheckForUpdates())
- {
- notifyIcon1.ShowBalloonTip(5000, "Updates Downloading", "Downloading new updates, please wait", ToolTipIcon.Info);
- if (!updManager.PrepareUpdates())
- {
- //MessageBox.Show("Updates preperation failed. Check the feed and try again.");
- AppLog.LogEvent("NAppUpdate update preperation failed. Possibly feed down.");
- }
- else
- {
- AppLog.LogEvent("NAppUpdate: Updates ready to install.");
- AppLog.LogEvent("NAppUpdate: Attempting to install updates");
- if (!updManager.ApplyUpdates())
- {
- MessageBox.Show(this, "Error while trying to install software updates. Please contact support.", "Update Error");
- AppLog.LogEvent("NAppUpdate: Error while trying to install updates.");
- }
- else
- {
- AppLog.LogEvent("NAppUpdate: Updates successfully installed");
- }
- }
- }
- }
- catch (Exception ex)
- {
- string exceptionLocation = "Exception in AutoUpdate()";
- // This indicates a feed or network error; ex will contain all the info necessary
- // to deal with that
- if (ex is NAppUpdateException)
- exceptionLocation = "NAppUpdate: Update failed";
- AppLog.LogEvent((string.Format("{0} message: {1} stack trace: \n{2}", exceptionLocation, ex.Message, ex.StackTrace)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement