Click here to Skip to main content
15,885,309 members
Articles / Desktop Programming / MFC

dotNetInstaller - Setup Bootstrapper for .NET Application

Rate me:
Please Sign up or sign in to vote.
4.96/5 (87 votes)
4 Jan 2004MIT22 min read 1M   2.2K   310  
With this tool the developer can define the application prerequisites and install the correct version of these components in the correct order based on the user operating system type and language, allow the user to download these components from the web or install these components directly.
using System;
using System.Xml;
using System.ComponentModel;

namespace InstallerEditor
{
	/// <summary>
	/// Summary description for Download.
	/// </summary>
	public class Download : IXmlClass
	{
		public Download():this("APP_TEMP_DOWNLOADPATH")
		{
		}
		public Download(string p_DownloadPath)
		{
			m_componentname = "New Component";
			m_sourceurl = "http://www.yourwebsite.com/SetupX/Setup.exe";
			m_destinationpath = "#TEMPPATH\\" + p_DownloadPath;
			m_destinationfilename = "";
		}

		private string m_componentname;
		[Description("The description of the file to download. (REQUIRED)")]
		public string componentname
		{
			get{return m_componentname;}
			set{m_componentname = value;OnComponentNameChanged(EventArgs.Empty);}
		}

		private string m_sourceurl;
		[Description("The complete source path of the file to download. For example 'http://www.yourwebsite.com/SetupX/Setup.exe' . Must be URL with http:// or ftp:// protocol (REQUIRED)")]
		public string sourceurl
		{
			get{return m_sourceurl;}
			set{m_sourceurl = value;}
		}

		private string m_destinationpath;
		[Description("The complete destination path where the application copy the sourceurl file. Is recommended to use the TEMP path for destination like this: '#TEMPPATH\\APPLICATION_NAME' . Can contains path constant (see Help->Path Constant). (REQUIRED)")]
		public string destinationpath
		{
			get{return m_destinationpath;}
			set{m_destinationpath = value;}
		}

		private string m_destinationfilename;
		[Description("New name of the downloaded file. Leave this value empty to use the same filename of the original filename. (OPTIONAL)")]
		public string destinationfilename
		{
			get{return m_destinationfilename;}
			set{m_destinationfilename = value;}
		}


		#region IXmlClass Members

		public void ToXml(XmlWriter p_Writer)
		{
			p_Writer.WriteStartElement("download");

			OnXmlWriteTagDownload(new XmlWriterEventArgs(p_Writer));

			p_Writer.WriteEndElement();
		}

		public void FromXml(XmlElement p_Element)
		{
			OnXmlReadTagDownload(new XmlElementEventArgs(p_Element));
		}
		#endregion


		protected virtual void OnXmlWriteTagDownload(XmlWriterEventArgs e)
		{
			e.XmlWriter.WriteAttributeString("componentname",m_componentname);
			e.XmlWriter.WriteAttributeString("sourceurl",m_sourceurl);
			e.XmlWriter.WriteAttributeString("destinationpath",m_destinationpath);
			e.XmlWriter.WriteAttributeString("destinationfilename",m_destinationfilename);
		}
		protected virtual void OnXmlReadTagDownload(XmlElementEventArgs e)
		{
			if (e.XmlElement.Attributes["componentname"] != null)
				m_componentname = e.XmlElement.Attributes["componentname"].InnerText;

			if (e.XmlElement.Attributes["destinationfilename"] != null)
				m_destinationfilename = e.XmlElement.Attributes["destinationfilename"].InnerText;

			if (e.XmlElement.Attributes["destinationpath"] != null)
				m_destinationpath = e.XmlElement.Attributes["destinationpath"].InnerText;

			if (e.XmlElement.Attributes["sourceurl"] != null)
				m_sourceurl = e.XmlElement.Attributes["sourceurl"].InnerText;
		}

		protected virtual void OnComponentNameChanged(EventArgs e)
		{
			if (ComponentNameChanged!=null)
				ComponentNameChanged(this, e);
		}

		public event EventHandler ComponentNameChanged;
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions