www.pudn.com > OracleServiceManager.zip > AboutDialog.cs


using System; 
using System.Diagnostics; 
using System.Drawing; 
using System.Collections; 
using System.ComponentModel; 
using System.IO; 
using System.Windows.Forms; 
using System.Reflection; 
using Microsoft.Win32; 
 
namespace kae.OracleServiceManager 
{ 
	///  
	/// Summary description for AboutDialog. 
	///  
	public class AboutDialog : System.Windows.Forms.Form 
	{ 
		private System.Collections.Hashtable assemblyAttributes; 
		private System.Windows.Forms.Label appTitle; 
		private System.Windows.Forms.Label productVersion; 
		private System.Windows.Forms.Label copyrightInfo; 
		private System.Windows.Forms.Button okButton; 
		private System.Windows.Forms.Button systemInfoButton; 
		private System.Windows.Forms.PictureBox appImage; 
		private OsmResources _resources; 
 
		///  
		/// Required designer variable. 
		///  
		private System.ComponentModel.Container components = null; 
 
		public AboutDialog() 
		{ 
			_resources = OracleServiceManager.Instance.Resources; 
 
			InitializeComponent(); 
 
			LoadAssemblyAttributes(); 
			 
			AssemblyTitleAttribute title = (AssemblyTitleAttribute) assemblyAttributes[ typeof(AssemblyTitleAttribute)]; 
			string format = this.GetStringFromResource( "Title"); 
			this.Text = String.Format( format, title.Title); 
			 
			appTitle.Text = String.Format( "{0} by {1}", title.Title, Application.CompanyName); 
			AssemblyInformationalVersionAttribute version = (AssemblyInformationalVersionAttribute) assemblyAttributes[ typeof(AssemblyInformationalVersionAttribute)]; 
			format = GetStringFromResource( "Version"); 
			productVersion.Text = String.Format( format, version.InformationalVersion); 
			AssemblyCopyrightAttribute copyright = (AssemblyCopyrightAttribute) assemblyAttributes[ typeof(AssemblyCopyrightAttribute)]; 
			copyrightInfo.Text = copyright.Copyright; 
 
			this.Icon = this.GetAppIcon(); 
 
			MemoryStream memStream = new MemoryStream(); 
			this.GetAppIcon().Save( memStream); 
			appImage.Image = Image.FromStream( memStream); 
 
			FileInfo msInfoFile = GetMsInfoFileInfo(); 
			if (msInfoFile != null && msInfoFile.Exists) 
			{ 
				systemInfoButton.Enabled = true; 
				systemInfoButton.Tag = msInfoFile; 
			} 
		} 
 
		///  
		/// Clean up any resources being used. 
		///  
		protected override void Dispose( bool disposing ) 
		{ 
			if( disposing ) 
			{ 
				if(components != null) 
				{ 
					components.Dispose(); 
				} 
			} 
			base.Dispose( disposing ); 
		} 
 
		private void LoadAssemblyAttributes() 
		{ 
			Assembly asm = Assembly.GetExecutingAssembly(); 
			object[] attributes = asm.GetCustomAttributes( false); 
			assemblyAttributes = new Hashtable( attributes.Length); 
 
			foreach (object attribute in attributes) 
			{ 
				assemblyAttributes.Add( attribute.GetType(), attribute); 
			} 
		} 
 
		#region Windows Form Designer generated code 
		///  
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor. 
		///  
		private void InitializeComponent() 
		{ 
			this.appTitle = new System.Windows.Forms.Label(); 
			this.productVersion = new System.Windows.Forms.Label(); 
			this.copyrightInfo = new System.Windows.Forms.Label(); 
			this.okButton = new System.Windows.Forms.Button(); 
			this.systemInfoButton = new System.Windows.Forms.Button(); 
			this.appImage = new System.Windows.Forms.PictureBox(); 
			this.SuspendLayout(); 
			//  
			// appTitle 
			//  
			this.appTitle.Location = new System.Drawing.Point(88, 16); 
			this.appTitle.Name = "appTitle"; 
			this.appTitle.Size = new System.Drawing.Size(284, 16); 
			this.appTitle.TabIndex = 0; 
			this.appTitle.Text = "Application Title by Producer Placeholder"; 
			//  
			// productVersion 
			//  
			this.productVersion.Location = new System.Drawing.Point(88, 44); 
			this.productVersion.Name = "productVersion"; 
			this.productVersion.Size = new System.Drawing.Size(284, 16); 
			this.productVersion.TabIndex = 1; 
			this.productVersion.Text = "Product Version Placeholder"; 
			//  
			// copyrightInfo 
			//  
			this.copyrightInfo.Location = new System.Drawing.Point(88, 72); 
			this.copyrightInfo.Name = "copyrightInfo"; 
			this.copyrightInfo.Size = new System.Drawing.Size(284, 16); 
			this.copyrightInfo.TabIndex = 2; 
			this.copyrightInfo.Text = "Copyright Information Placeholder"; 
			//  
			// okButton 
			//  
			this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; 
			this.okButton.Location = new System.Drawing.Point(188, 112); 
			this.okButton.Name = "okButton"; 
			this.okButton.TabIndex = 3; 
			this.okButton.Text = this.GetAppString( "OK"); 
			//  
			// systemInfoButton 
			//  
			this.systemInfoButton.Enabled = false; 
			this.systemInfoButton.Location = new System.Drawing.Point(276, 112); 
			this.systemInfoButton.Name = "systemInfoButton"; 
			this.systemInfoButton.Size = new System.Drawing.Size(92, 23); 
			this.systemInfoButton.TabIndex = 4; 
			this.systemInfoButton.Text = this.GetStringFromResource( "SystemInfo"); 
			this.systemInfoButton.Click += new System.EventHandler(this.OnSystemInfoClick); 
			//  
			// appImage 
			//  
			this.appImage.Location = new System.Drawing.Point(16, 16); 
			this.appImage.Name = "appImage"; 
			this.appImage.Size = new System.Drawing.Size(48, 48); 
			this.appImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 
			this.appImage.TabIndex = 5; 
			this.appImage.TabStop = false; 
			//  
			// AboutDialog 
			//  
			this.AcceptButton = this.okButton; 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); 
			this.ClientSize = new System.Drawing.Size(386, 146); 
			this.Controls.AddRange(new System.Windows.Forms.Control[] { 
																		  this.appImage, 
																		  this.systemInfoButton, 
																		  this.okButton, 
																		  this.copyrightInfo, 
																		  this.productVersion, 
																		  this.appTitle}); 
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 
			this.MaximizeBox = false; 
			this.MinimizeBox = false; 
			this.Name = "AboutDialog"; 
			this.ShowInTaskbar = false; 
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 
			this.Text = "About Title"; 
			this.ResumeLayout(false); 
 
		} 
		#endregion 
 
		private string GetStringFromResource( string resourceName) 
		{ 
			return _resources.GetString( typeof(AboutDialog), resourceName); 
		} 
 
		private string GetAppString( string resourceName) 
		{ 
			return _resources.GetAppString( resourceName); 
		} 
 
		private Icon GetAppIcon() 
		{ 
			return _resources.GetApplicationImage(); 
		} 
 
		private FileInfo GetMsInfoFileInfo() 
		{ 
			string SHARED_TOOLS = @"SOFTWARE\Microsoft\Shared Tools\MsInfo"; 
			FileInfo fileInfo = null; 
 
			RegistryKey key = Registry.LocalMachine.OpenSubKey( SHARED_TOOLS); 
			try 
			{ 
				object path = key.GetValue( "Path"); 
				if (path != null) 
					fileInfo = new FileInfo( path.ToString()); 
			} 
			catch {} 
 
			return fileInfo; 
		} 
 
		private void OnSystemInfoClick( object sender, EventArgs e) 
		{ 
			FileInfo fileInfo = (FileInfo) systemInfoButton.Tag; 
			Process.Start( fileInfo.FullName); 
		} 
	} 
}