Advertisement
Guest User

Untitled

a guest
May 5th, 2012
1,468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. private void AutoUpdate()
  2. {
  3. // Get a local pointer to the UpdateManager instance
  4. UpdateManager updManager = UpdateManager.Instance;
  5.  
  6. // Only check for updates if we haven't done so already
  7. if (updManager.State != UpdateManager.UpdateProcessState.NotChecked)
  8. {
  9. //Update has already begun
  10. if (updManager.State == UpdateManager.UpdateProcessState.RollbackRequired)
  11. {
  12. //If rollback is required carry it out
  13. updManager.RollbackUpdates();
  14. }
  15. else
  16. {
  17. return;
  18. }
  19. }
  20.  
  21. try
  22. {
  23. // Check for updates - returns true if relevant updates are found (after processing all the tasks and
  24. // conditions)
  25. // Throws exceptions in case of bad arguments or unexpected results
  26. AppLog.LogEvent("NAppUpdate: Checking for updates");
  27. if (updManager.CheckForUpdates())
  28. {
  29. notifyIcon1.ShowBalloonTip(5000, "Updates Downloading", "Downloading new updates, please wait", ToolTipIcon.Info);
  30. if (!updManager.PrepareUpdates())
  31. {
  32. //MessageBox.Show("Updates preperation failed. Check the feed and try again.");
  33. AppLog.LogEvent("NAppUpdate update preperation failed. Possibly feed down.");
  34. }
  35. else
  36. {
  37. AppLog.LogEvent("NAppUpdate: Updates ready to install.");
  38. AppLog.LogEvent("NAppUpdate: Attempting to install updates");
  39. if (!updManager.ApplyUpdates())
  40. {
  41. MessageBox.Show(this, "Error while trying to install software updates. Please contact support.", "Update Error");
  42. AppLog.LogEvent("NAppUpdate: Error while trying to install updates.");
  43. }
  44. else
  45. {
  46. AppLog.LogEvent("NAppUpdate: Updates successfully installed");
  47. }
  48. }
  49. }
  50. }
  51. catch (Exception ex)
  52. {
  53. string exceptionLocation = "Exception in AutoUpdate()";
  54.  
  55. // This indicates a feed or network error; ex will contain all the info necessary
  56. // to deal with that
  57. if (ex is NAppUpdateException)
  58. exceptionLocation = "NAppUpdate: Update failed";
  59.  
  60. AppLog.LogEvent((string.Format("{0} message: {1} stack trace: \n{2}", exceptionLocation, ex.Message, ex.StackTrace)));
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement