[Nasa-exp-checkins] WorldWind/WorldWind/PluginEngine PluginInstallDialog.cs,NONE,1.1 PluginInstallDi
Brought to you by:
baker99-bull,
vigilant
From: Bjorn R. \(B. Reppen\) <mas...@us...> - 2005-05-31 09:31:14
|
Update of /cvsroot/nasa-exp/WorldWind/WorldWind/PluginEngine In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23831/WorldWind/PluginEngine Added Files: PluginInstallDialog.cs PluginInstallDialog.resx Log Message: WW-106: Add plugin install/uninstall buttons --- NEW FILE: PluginInstallDialog.cs --- using System; using WorldWind.Net; using WorldWind.PluginEngine; using System.IO; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; namespace WorldWind.PluginEngine { /// <summary> /// Ask user for plugin file path/url, then download and install. /// </summary> public class PluginInstallDialog : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Button buttonInstall; private System.Windows.Forms.Button buttonCancel; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox url; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; private System.Windows.Forms.Button buttonBrowse; private System.Windows.Forms.OpenFileDialog openFileDialog; private PluginCompiler m_compiler; public PluginInstallDialog(PluginCompiler compiler) { // // Required for Windows Form Designer support // InitializeComponent(); m_compiler = compiler; } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.url = new System.Windows.Forms.TextBox(); this.buttonInstall = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.label2 = new System.Windows.Forms.Label(); this.buttonBrowse = new System.Windows.Forms.Button(); this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.SuspendLayout(); // // label1 // this.label1.Location = new System.Drawing.Point(11, 65); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(163, 14); this.label1.TabIndex = 1; this.label1.Text = "Plugin File / URL:"; // // url // this.url.Location = new System.Drawing.Point(11, 83); this.url.Name = "url"; this.url.Size = new System.Drawing.Size(333, 20); this.url.TabIndex = 2; this.url.Text = ""; // // buttonInstall // this.buttonInstall.Location = new System.Drawing.Point(214, 115); this.buttonInstall.Name = "buttonInstall"; this.buttonInstall.TabIndex = 4; this.buttonInstall.Text = "&Install"; this.buttonInstall.Click += new System.EventHandler(this.buttonInstall_Click); // // buttonCancel // this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.buttonCancel.Location = new System.Drawing.Point(297, 115); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.TabIndex = 5; this.buttonCancel.Text = "&Cancel"; // // label2 // this.label2.Location = new System.Drawing.Point(12, 14); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(345, 42); this.label2.TabIndex = 0; this.label2.Text = "To install a plugin, either copy the URL pointing to the plugin from a web page a" + "nd paste it in the field below or paste/browse for a local file. Then press ins" + "tall."; // // buttonBrowse // this.buttonBrowse.Location = new System.Drawing.Point(345, 81); this.buttonBrowse.Name = "buttonBrowse"; this.buttonBrowse.Size = new System.Drawing.Size(30, 23); this.buttonBrowse.TabIndex = 3; this.buttonBrowse.Text = "&..."; this.buttonBrowse.Click += new System.EventHandler(this.buttonBrowse_Click); // // openFileDialog // this.openFileDialog.AddExtension = false; this.openFileDialog.RestoreDirectory = true; // // PluginInstallDialog // this.AcceptButton = this.buttonInstall; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.CancelButton = this.buttonCancel; this.ClientSize = new System.Drawing.Size(383, 148); this.Controls.Add(this.buttonBrowse); this.Controls.Add(this.label2); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonInstall); this.Controls.Add(this.url); this.Controls.Add(this.label1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Name = "PluginInstallDialog"; this.Text = "Plugin Installation"; this.ResumeLayout(false); } #endregion /// <summary> /// Install plugin /// </summary> private void buttonInstall_Click(object sender, System.EventArgs e) { try { // Trim off any whitespace the user may have added url.Text = url.Text.Trim(); if(IsWeb) InstallFromUrl(new Uri(url.Text)); else if(IsFile) InstallFromFile(url.Text); else { MessageBox.Show("Please specify an existing filename or a web url starting with 'http://'.", "Not found", MessageBoxButtons.OK, MessageBoxIcon.Error ); url.Focus(); return; } // Success, close this dialog Close(); } catch(ApplicationException) { // User aborted } } /// <summary> /// Determine if user points to a file. /// </summary> bool IsFile { get { return File.Exists(url.Text); } } /// <summary> /// Determine if user points to a web URL. /// </summary> bool IsWeb { get { return url.Text.ToLower().StartsWith("http://"); } } /// <summary> /// Install plugin from local file. /// </summary> /// <param name="pluginPath">Plugin path/filename.</param> void InstallFromFile( string pluginPath ) { string fileName = Path.GetFileName( pluginPath ); string destPath = GetDestinationPath( fileName ); if(destPath == null) return; File.Copy(pluginPath, destPath); ShowSuccessMessage( fileName ); } /// <summary> /// Install plugin from web (url). /// </summary> /// <param name="pluginUrl">http:// URL</param> void InstallFromUrl( Uri uri ) { string fileName = Path.GetFileName( uri.LocalPath ); string destPath = GetDestinationPath( fileName ); if(destPath == null) return; using(WebDownload dl = new WebDownload(uri.ToString())) dl.DownloadFile(destPath); ShowSuccessMessage( fileName ); } /// <summary> /// Calculates plugin destination directory based on name, and prepares it. /// </summary> /// <param name="fileName">Plugin filename only (no path).</param> string GetDestinationPath( string fileName ) { string directory = Path.Combine(m_compiler.PluginRootDirectory, Path.GetFileNameWithoutExtension(fileName)); Directory.CreateDirectory(directory); string fullPath = Path.Combine(directory, fileName); if(File.Exists(fullPath)) { // Show overwrite warning string msg = string.Format("You already have {0} installed. Do you wish to overwrite it?", Path.GetFileNameWithoutExtension(fileName) ); if( MessageBox.Show(msg, "Overwrite?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes) throw new ApplicationException("Install aborted."); } return fullPath; } /// <summary> /// Display a message box with successful installation message. /// </summary> void ShowSuccessMessage( string fileName ) { string msg = string.Format("{0} was successfully installed.", Path.GetFileNameWithoutExtension(fileName) ); MessageBox.Show(msg, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } /// <summary> /// Browse for local file /// </summary> private void buttonBrowse_Click(object sender, System.EventArgs e) { OpenFileDialog of = new OpenFileDialog(); if(IsFile) of.FileName = url.Text; if(of.ShowDialog()!=DialogResult.OK) return; url.Text = of.FileName; } } } --- NEW FILE: PluginInstallDialog.resx --- <?xml version="1.0" encoding="utf-8"?> <root> <!-- Microsoft ResX Schema Version 1.3 The primary goals of this format is to allow a simple XML format that is mostly human readable. The generation and parsing of the various data types are done through the TypeConverter classes associated with the data types. Example: ... ado.net/XML headers & schema ... <resheader name="resmimetype">text/microsoft-resx</resheader> <resheader name="version">1.3</resheader> <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> <data name="Name1">this is my long string</data> <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> [base64 mime encoded serialized .NET Framework object] </data> <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> [base64 mime encoded string representing a byte array form of the .NET Framework object] </data> There are any number of "resheader" rows that contain simple name/value pairs. Each data row contains a name, and value. The row also contains a type or mimetype. Type corresponds to a .NET class that support text/value conversion through the TypeConverter architecture. Classes that don't support this are serialized and stored with the mimetype set. The mimetype is used forserialized objects, and tells the ResXResourceReader how to depersist the object. This is currently not extensible. For a given mimetype the value must be set accordingly: Note - application/x-microsoft.net.object.binary.base64 is the format that the ResXResourceWriter will generate, however the reader can read any of the formats listed below. mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with : System.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 value : The object must be serialized with : System.Runtime.Serialization.Formatters.Soap.SoapFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.bytearray.base64 value : The object must be serialized into a byte array : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:element name="root" msdata:IsDataSet="true"> <xsd:complexType> <xsd:choice maxOccurs="unbounded"> <xsd:element name="data"> <xsd:complexType> <xsd:sequence> <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> </xsd:sequence> <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" /> <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> </xsd:complexType> </xsd:element> <xsd:element name="resheader"> <xsd:complexType> <xsd:sequence> <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> </xsd:sequence> <xsd:attribute name="name" type="xsd:string" use="required" /> </xsd:complexType> </xsd:element> </xsd:choice> </xsd:complexType> </xsd:element> </xsd:schema> <resheader name="resmimetype"> <value>text/microsoft-resx</value> </resheader> <resheader name="version"> <value>1.3</value> </resheader> <resheader name="reader"> <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> <resheader name="writer"> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> <data name="label1.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>False</value> </data> <data name="label1.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="label1.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="url.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="url.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>False</value> </data> <data name="url.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="buttonInstall.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>False</value> </data> <data name="buttonInstall.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="buttonInstall.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="buttonCancel.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>False</value> </data> <data name="buttonCancel.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="buttonCancel.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="label2.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>False</value> </data> <data name="label2.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="label2.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="buttonBrowse.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>False</value> </data> <data name="buttonBrowse.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="buttonBrowse.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="openFileDialog.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="openFileDialog.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> <data name="openFileDialog.Location" type="System.Drawing.Point, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>17, 17</value> </data> <data name="$this.Name"> <value>PluginInstallDialog</value> </data> <data name="$this.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>False</value> </data> <data name="$this.Language" type="System.Globalization.CultureInfo, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>(Default)</value> </data> <data name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>False</value> </data> <data name="$this.Localizable" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>False</value> </data> <data name="$this.GridSize" type="System.Drawing.Size, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>8, 8</value> </data> <data name="$this.DrawGrid" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>False</value> </data> <data name="$this.TrayHeight" type="System.Int32, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>80</value> </data> <data name="$this.SnapToGrid" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>False</value> </data> <data name="$this.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>Private</value> </data> </root> |