Ejemplo n.º 1
0
		internal static async void CheckForUpdates(bool silent)
		{
			var hc = new HttpClient();
			try
			{
				var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
				var uri = new Uri("http://wordslive.org/version.xml"); 
				var str = await hc.GetStringAsync(uri);
				var reader = new StringReader(str);
				var doc = XDocument.Load(reader);
				var latestVersion = new Version(doc.Root.Element("version").Value);
				var noUpdateVersion = new Version(Properties.Settings.Default.NoUpdateVersion);
				var latestUri = new Uri(doc.Root.Element("url").Value);

				if (currentVersion >= latestVersion)
				{
					if (!silent)
					{
						MessageBox.Show(instance.window, Resource.updMsgUpToDate, "");
					}
				}
				else if (!silent || noUpdateVersion < latestVersion)
				{
					var result = MessageBox.Show(instance.window, String.Format(Resource.updMsgNewVersion, latestVersion.SimplifyVersion().ToString()), "", MessageBoxButton.YesNoCancel);

					if (result == MessageBoxResult.Yes)
					{
						// open download in browser and don't show update alert again
						latestUri.OpenInBrowser();
						Properties.Settings.Default.NoUpdateVersion = latestVersion.ToString();
					}
					else if (result == MessageBoxResult.No)
					{
						// don't show update alert again (until newer version is available)
						Properties.Settings.Default.NoUpdateVersion = latestVersion.ToString();
					}
				}
			}
			catch (Exception)
			{
				if (!silent)
				{
					MessageBox.Show(instance.window, Resource.updMsgFailed, "", MessageBoxButton.OK, MessageBoxImage.Error);
				}
			}
		}