コード例 #1
0
		private void Help_DownloadLatest_Click(object sender, RoutedEventArgs e)
		{
			if (!_Settings.UpdateAvailable)
				return;

			Assembly a = Assembly.GetExecutingAssembly();
			String tempPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(a.Location), "update");

			// Blow away any existing files
			if (System.IO.Directory.Exists(tempPath))
				System.IO.Directory.Delete(tempPath, true);
			System.IO.Directory.CreateDirectory(tempPath);

			// Copy all DLLs to the temp Update directory -- these are the only ones that can't be overwritten
			foreach (String file in System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(a.Location), "*", System.IO.SearchOption.TopDirectoryOnly))
			{
				if (file.ToLower().EndsWith(".dll") || file == a.Location)
					System.IO.File.Copy(file, System.IO.Path.Combine(tempPath, System.IO.Path.GetFileName(file)));
			}

			String tempFile = System.IO.Path.Combine(tempPath, System.IO.Path.GetFileName(a.Location));
			if (this.latestVersionInfo == null)
				this.latestVersionInfo = VersionChecker.GetLatestVersion();
			System.Diagnostics.Process.Start(tempFile, String.Format("-u \"{0}\"", this.latestVersionInfo.FileUrl));
			this.Close();
		}
コード例 #2
0
		public static VersionInfo GetLatestVersion()
		{
			VersionInfo latestVersion = new VersionInfo();
			String xmlURL = "http://dominion.technowall.net/files/version.xml";
			try
			{
				XmlDocument xDoc = new XmlDocument();
				xDoc.Load(xmlURL);

				XmlNode xnHead = xDoc.SelectSingleNode("Dominion.NET");
				if (xnHead != null)
				{
					XmlNode xnVersion = xnHead.SelectSingleNode("version");
					if (xnVersion != null)
					{
						latestVersion.Version = new Version(xnVersion.InnerText);
						latestVersion.IsVersionValid = true;
					}

					XmlNode xnUrl = xnHead.SelectSingleNode("url");
					if (xnUrl != null)
						latestVersion.Url = new Uri(xnUrl.InnerText);

					XmlNode xnFileUrl = xnHead.SelectSingleNode("fileurl");
					if (xnFileUrl != null)
						latestVersion.FileUrl = new Uri(xnFileUrl.InnerText);
				}
			}
			catch (System.Net.WebException wex)
			{
				// We'll just silently ignore these errors
			}
			catch (Exception ex)
			{
				DominionBase.Utilities.Logging.LogError(ex);
			}
			return latestVersion;
		}
コード例 #3
0
		private void CheckForUpdates(Boolean forceCheck)
		{
			Assembly a = Assembly.GetExecutingAssembly();

			// If this isn't null, we're trying to update to a version
			if (!forceCheck && System.Windows.Application.Current.Properties["Update"] != null)
			{
				System.Net.WebClient wClient = new System.Net.WebClient();
				wClient.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(wClient_DownloadFileCompleted);
				wClient.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(wClient_DownloadProgressChanged);
				wClient.DownloadFileAsync(new Uri(System.Windows.Application.Current.Properties["Update"].ToString()), System.IO.Path.Combine(System.IO.Path.GetDirectoryName(a.Location), "update.zip"));
			}
			else
			{
				if (System.Windows.Application.Current.Properties["Updated"] != null && (Boolean)System.Windows.Application.Current.Properties["Updated"])
				{
					wMessageBox.Show(String.Format("Successfully updated to latest version {0}!", a.GetName().Version), "Update complete!", MessageBoxButton.OK, MessageBoxImage.Information);
					_Settings.UpdateAvailable = false;
					_Settings.Save();
				}

				String tempPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(a.Location), "update");
				// Blow away any existing files
				if (System.IO.Directory.Exists(tempPath))
					System.IO.Directory.Delete(tempPath, true);

				iUpdate.Dispatcher.BeginInvoke((Action)(() => iUpdate.Visibility = miDownload.Visibility = System.Windows.Visibility.Collapsed));

				// Only check for an update if we haven't checked in the last 24 hours
				// Or if we're forcing a check
				if (forceCheck || DateTime.Now - TimeSpan.FromHours(24) > _Settings.LastUpdateCheck)
				{
					this.latestVersionInfo = VersionChecker.GetLatestVersion();
					_Settings.LastUpdateCheck = DateTime.Now;

					Version currentVersion = a.GetName().Version;
					if (latestVersionInfo.IsVersionValid && latestVersionInfo.IsNewerThan(currentVersion))
						_Settings.UpdateAvailable = true;

					if (forceCheck)
						wMessageBox.Show(String.Format("Your version: {0}{2}Latest version: {1}", currentVersion, latestVersionInfo.Version, System.Environment.NewLine), "Version info", MessageBoxButton.OK, MessageBoxImage.Information);

					_Settings.Save();
				}

				if (_Settings.UpdateAvailable)
				{
					iUpdate.Dispatcher.BeginInvoke((Action)(() => iUpdate.Visibility = miDownload.Visibility = System.Windows.Visibility.Visible));
					iUpdate.Dispatcher.BeginInvoke((Action)(() => iUpdate.ToolTip = miDownload.ToolTip = "Update available"));
				}
			}
		}