Click here to Skip to main content
15,892,537 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;

namespace InstallerEditor
{
	/// <summary>
	/// Summary description for ConfigFile.
	/// </summary>
	public class ConfigFile
	{
		public ConfigFile()
		{
		}

		private string m_FileName = null;
		public string FileName
		{
			get{return m_FileName;}
			set{m_FileName = value;}
		}

		public void Save()
		{
			if (m_FileName==null)
				throw new ApplicationException("Invalid save filename");

			SaveAs(m_FileName);
		}

		public void SaveAs(string p_FileName)
		{
			XmlTextWriter l_XmlWriter = new XmlTextWriter(p_FileName, System.Text.Encoding.ASCII);
			try
			{
				l_XmlWriter.Formatting = Formatting.Indented;
				
				l_XmlWriter.WriteStartElement("configurations");
				foreach (Configuration c in Configurations)
				{
					c.ToXml(l_XmlWriter);
				}
				l_XmlWriter.WriteEndElement();

				m_FileName = p_FileName;
			}
			finally
			{
				l_XmlWriter.Close();
			}
		}

		public void Create(string p_FileName)
		{
			m_FileName = p_FileName;
		}


		public void Load(string p_FileName)
		{
			XmlDocument l_XmlElement = new XmlDocument();
			l_XmlElement.Load(p_FileName);

			XmlNodeList l_List = l_XmlElement.SelectNodes("//configurations/configuration");
			foreach(XmlElement l_Element in l_List)
			{
				string l_Type = l_Element.Attributes["type"].InnerText.ToLower();
				Configuration l_Config;
				if (l_Type == "install")
					l_Config = new SetupConfiguration();
				else if (l_Type == "reference")
					l_Config = new WebConfiguration();
				else
					throw new ApplicationException("Invalid type");

				l_Config.FromXml(l_Element);

				Configurations.Add(l_Config);
			}
			
			m_FileName = p_FileName;
		}

		private ConfigurationCollection m_Configurations = new ConfigurationCollection();

		[System.ComponentModel.Browsable(false)]
		public ConfigurationCollection Configurations
		{
			get{return m_Configurations;}
			set{m_Configurations = value;}
		}
	}

	public interface IXmlClass
	{
		void ToXml(XmlWriter p_Writer);
		void FromXml(XmlElement p_Element);
	}

	public class XmlWriterEventArgs : EventArgs
	{
		public XmlWriterEventArgs(XmlWriter p_Writer)
		{
			m_Writer = p_Writer;
		}
		private XmlWriter m_Writer;
		public XmlWriter XmlWriter
		{
			get{return m_Writer;}
		}
	}

	public delegate void XmlWriterEventHandler(object sender, XmlWriterEventArgs e);

	public class XmlElementEventArgs : EventArgs
	{
		public XmlElementEventArgs(XmlElement p_XmlElement)
		{
			m_XmlElement = p_XmlElement;
		}
		private XmlElement m_XmlElement;
		public XmlElement XmlElement
		{
			get{return m_XmlElement;}
		}
	}

	public delegate void XmlElementEventHandler(object sender, XmlElementEventArgs e);

	public class ConfigFileEventArgs : EventArgs
	{
		public ConfigFileEventArgs(ConfigFile p_Config)
		{
			m_ConfigFile = p_Config;
		}

		private ConfigFile m_ConfigFile;
		public ConfigFile ConfigFile
		{
			get{return m_ConfigFile;}
			set{m_ConfigFile = value;}
		}
	}

	public delegate void ConfigFileEventHandler(object sender, ConfigFileEventArgs e);

	public class ConfigFileFileEventArgs : ConfigFileEventArgs
	{
		public ConfigFileFileEventArgs(string p_FileName, ConfigFile p_Config):base(p_Config)
		{
			m_FileName = p_FileName;
		}

		private string m_FileName;
		public string FileName
		{
			get{return m_FileName;}
			set{m_FileName = value;}
		}
	}

	public delegate void ConfigFileFileEventHandler(object sender, ConfigFileFileEventArgs e);

	public class ConfigFileXmlWriterEventArgs : ConfigFileFileEventArgs
	{
		public ConfigFileXmlWriterEventArgs(XmlWriter p_XmlWriter, string p_FileName, ConfigFile p_Config):base(p_FileName, p_Config)
		{
			m_XmlWriter = p_XmlWriter;
		}

		private XmlWriter m_XmlWriter;
		public XmlWriter XmlWriter
		{
			get{return m_XmlWriter;}
			set{m_XmlWriter = value;}
		}
	}

	public delegate void ConfigFileXmlWriterEventHandler(object sender, ConfigFileXmlWriterEventArgs e);

	public class ConfigFileXmlElementEventArgs : ConfigFileFileEventArgs
	{
		public ConfigFileXmlElementEventArgs(XmlElement p_XmlElement, string p_FileName, ConfigFile p_Config):base(p_FileName, p_Config)
		{
			m_XmlElement = p_XmlElement;
		}

		private XmlElement m_XmlElement;
		public XmlElement XmlElement
		{
			get{return m_XmlElement;}
			set{m_XmlElement = value;}
		}
	}

	public delegate void ConfigFileXmlElementEventHandler(object sender, ConfigFileXmlElementEventArgs e);

}

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