Click here to Skip to main content
15,892,298 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 Configuration.
	/// </summary>
	public abstract class Component : IXmlClass
	{
		public Component(string p_type):this(p_type, "COMPONENT_NAME")
		{
		}
		public Component(string p_type, string p_ComponentName)
		{
			m_type = p_type;

			m_mustreboot = false;
			m_os_filter_greater = "";
			m_os_filter_lcid = "";
			m_os_filter_smaller = "";
			if (LanguageUI.Language == SupportedLanguage.Italian)
			{
				m_description = p_ComponentName;
				m_installcompletemessage = "";
				m_installmessage = "Premi avanti per installare " + p_ComponentName;
			}
			else //english
			{
				m_description = p_ComponentName;
				m_installcompletemessage = "";
				m_installmessage = "Click Next to install " + p_ComponentName;
			}
		}

		#region Attributi
		private string m_type; //can be cmd or msi or openfile
		[Description("The type of the component; can be 'cmd' for executing generic command line installation or 'msi' for installing Windows Installer MSI package or 'openfile' to open a file. (REQUIRED)")]
		public string type
		{
			get{return m_type;}
		}

		private string m_os_filter_greater;
		[Description("A filter to install this component only on all operating system id greater than the id specified (see Help->Operating System Table). For example to install a component only in Windows 2000 or later write '44'. (OPTIONAL)")]
		public string os_filter_greater
		{
			get{return m_os_filter_greater;}
			set{m_os_filter_greater = value;}
		}

		private string m_os_filter_smaller;
		[Description("A filter to install this component only on all operating system id smaller than the id specified (see operating system table). For example to install a component preceding Windows 2000 write '45'. (OPTIONAL)")]
		public string os_filter_smaller
		{
			get{return m_os_filter_smaller;}
			set{m_os_filter_smaller = value;}
		}

		private string m_os_filter_lcid;
		[Description("A filter to install this component only on all operating system language equals or not equals than the LCID specified (see Help->LCID table). Separate multiple LCID with comma (',') and use not symbol ('!') for NOT logic (es. '1044,1033,!1038' ). You can also filter all the configuration element. (OPTIONAL)")]
		public string os_filter_lcid
		{
			get{return m_os_filter_lcid;}
			set{m_os_filter_lcid = value;}
		}

		private string m_installcompletemessage; //se vuoto non viene visualizzato nessun messagio al termine del download
		[Description("The message used when a component is successfully installed. To disable this message leave this property empty. (OPTIONAL)")]
		public string installcompletemessage
		{
			get{return m_installcompletemessage;}
			set{m_installcompletemessage = value;}
		}

		private bool m_mustreboot;
		[Description("Indicates if ask to reboot after this component is installed successfully (True/False). Normally if the system must be restarted is automatically the component that tells this setup (with special return code) to stop and restart the system, but in special circumstances (for example in Windows 98) we must force a reboot to install correctly some components (for example the .NET Framework). (REQUIRED)")]
		public bool mustreboot
		{
			get{return m_mustreboot;}
			set{m_mustreboot = value;}
		}

		private string m_description;
		[Description("Description of this component. This value is used also in some message to replace the %s string. (REQUIRED)")]
		public string description
		{
			get{return m_description;}
			set{m_description = value;OnDescriptionChanged();}
		}

		private string m_installmessage;
		[Description("The message used to confirm the installation of this component. (REQUIRED)")]
		public string installmessage
		{
			get{return m_installmessage;}
			set{m_installmessage = value;}
		}

		private string m_note;
		[Description("Note, not used by the setup. (OPTIONAL)")]
		public string note
		{
			get{return m_note;}
			set{m_note = value;}
		}
		#endregion

		protected void OnDescriptionChanged()
		{
			if (DescriptionChanged!=null)
				DescriptionChanged(this,EventArgs.Empty);
		}

		public event EventHandler DescriptionChanged;

		#region IXmlClass Members

		public void ToXml(XmlWriter p_Writer)
		{
			p_Writer.WriteStartElement("component");
				OnXmlWriteTagcomponent(new XmlWriterEventArgs(p_Writer));

				if (m_DownloadDialog!=null)
				{
					m_DownloadDialog.ToXml(p_Writer);
				}

				foreach(installedcheck i in installchecks)
				{
					i.ToXml(p_Writer);
				}

			p_Writer.WriteEndElement();
		}

		public void FromXml(XmlElement p_Element)
		{
			if (p_Element.Attributes["type"] == null ||
				p_Element.Attributes["type"].InnerText != m_type)
				throw new ApplicationException("Invalid type");

			OnXmlReadTagcomponent(new XmlElementEventArgs(p_Element));

			XmlElement l_ElementDownloadDialog = (XmlElement)p_Element.SelectSingleNode("downloaddialog");
			if (l_ElementDownloadDialog != null)
			{
				DownloadDialog l_dialog = new DownloadDialog();
				l_dialog.FromXml(l_ElementDownloadDialog);
				m_DownloadDialog = l_dialog;
			}

			XmlNodeList l_List = p_Element.SelectNodes("installedcheck");
			foreach(XmlElement l_XmlCheck in l_List)
			{
				if (l_XmlCheck.Attributes["type"] != null)
				{
					installedcheck l_check;
					if (l_XmlCheck.Attributes["type"].InnerText == "check_file")
						l_check = new installedcheck_file();
					else if (l_XmlCheck.Attributes["type"].InnerText == "check_registry_value")
						l_check = new installedcheck_registry();
					else
						throw new ApplicationException("Invalid type");

					l_check.FromXml(l_XmlCheck);

					installchecks.Add(l_check);
				}
			}
		}
		#endregion

		protected virtual void OnXmlWriteTagcomponent(XmlWriterEventArgs e)
		{
			e.XmlWriter.WriteAttributeString("os_filter_greater",m_os_filter_greater);
			e.XmlWriter.WriteAttributeString("os_filter_smaller",m_os_filter_smaller);
			e.XmlWriter.WriteAttributeString("os_filter_lcid",m_os_filter_lcid);
			e.XmlWriter.WriteAttributeString("type",m_type);
			e.XmlWriter.WriteAttributeString("installcompletemessage",m_installcompletemessage);
			e.XmlWriter.WriteAttributeString("mustreboot",m_mustreboot.ToString());
			e.XmlWriter.WriteAttributeString("description",m_description);
			e.XmlWriter.WriteAttributeString("installmessage",m_installmessage);
			e.XmlWriter.WriteAttributeString("note",m_note);
		}
		protected virtual void OnXmlReadTagcomponent(XmlElementEventArgs e)
		{
			if (e.XmlElement.Attributes["description"]!=null)
				m_description = e.XmlElement.Attributes["description"].InnerText;

			if (e.XmlElement.Attributes["installcompletemessage"]!=null)
				m_installcompletemessage = e.XmlElement.Attributes["installcompletemessage"].InnerText;

			if (e.XmlElement.Attributes["installmessage"]!=null)
				m_installmessage = e.XmlElement.Attributes["installmessage"].InnerText;

			if (e.XmlElement.Attributes["mustreboot"]!=null)
				m_mustreboot = bool.Parse(e.XmlElement.Attributes["mustreboot"].InnerText);

			if (e.XmlElement.Attributes["os_filter_greater"]!=null)
				m_os_filter_greater = e.XmlElement.Attributes["os_filter_greater"].InnerText;

			if (e.XmlElement.Attributes["os_filter_lcid"]!=null)
				m_os_filter_lcid = e.XmlElement.Attributes["os_filter_lcid"].InnerText;

			if (e.XmlElement.Attributes["os_filter_smaller"]!=null)
				m_os_filter_smaller = e.XmlElement.Attributes["os_filter_smaller"].InnerText;

			if (e.XmlElement.Attributes["note"]!=null)
				m_note = e.XmlElement.Attributes["note"].InnerText;

//			if (e.XmlElement.Attributes["type"]!=null)
//				m_type = e.XmlElement.Attributes["type"].InnerText;
		}

		private installedcheckCollection m_installchecks = new installedcheckCollection();
		[System.ComponentModel.Browsable(false)]
		public installedcheckCollection installchecks
		{
			get{return m_installchecks;}
			set{m_installchecks = value;}
		}

		private DownloadDialog m_DownloadDialog = null; //di default non � presente
		[System.ComponentModel.Browsable(false)]
		public DownloadDialog DownloadDialog
		{
			get{return m_DownloadDialog;}
			set{m_DownloadDialog = value;}
		}
	}

}

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