Click here to Skip to main content
15,886,137 members
Articles / Programming Languages / C#

A Windows Installer Database Diff Tool

Rate me:
Please Sign up or sign in to vote.
4.68/5 (17 votes)
21 Dec 2004CPOL2 min read 70.3K   899   29  
A command line tool that generates XML and/or HTML Diff reports of two Windows installer databases.
using System;
using System.IO;
using System.Collections;

namespace MSIDiff
{
	/// <summary>
	/// Summary description for ArgumentParser.
	/// </summary>
	public class ArgumentParser
	{
		private Hashtable m_options;
		private ArrayList m_flags;
		private ArrayList m_fileNames;

		public ArgumentParser( string[] args )
		{
			m_options = new Hashtable();
			m_flags = new ArrayList();
			m_fileNames = new ArrayList();

			for ( int i = 0; i < args.Length; i++ )
				ParseArgument( args[i].ToLower() );
		}		

		public bool HasArgument( string name )
		{
			return m_options.Contains( name );
		}

		public string GetArgument( string name )
		{
			return (string)m_options[name];
		}

		public bool CheckFlag( string name )
		{
			return m_flags.Contains( name );
		}

		public FileInfo GetFile( int index )
		{
			return (FileInfo)m_fileNames[index];
		}

		public int FileNameCount
		{
			get
			{
				return m_fileNames.Count;
			}
		}

		private void ParseArgument( string arg )
		{
			int eqPos = arg.IndexOf( '=', 0 );

			if ( eqPos != -1 )
				m_options.Add( arg.Substring( 0, eqPos ), arg.Substring( eqPos + 1 ) );

			else if ( arg.Substring( 0, 1 ) == "-" )
				m_flags.Add( arg.Substring( 1 ) );

			else
				ParseFileName( arg );
		}

		private void ParseFileName( string path )
		{
			FileInfo file = new FileInfo( path );
			if ( !file.Exists )
				throw new ArgumentException( string.Format( "The file {0} could not be found", path ) );

			m_fileNames.Add( file );
		}
	}
}

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 Code Project Open License (CPOL)


Written By
Team Leader Starkey Laboratories
United States United States
The first computer program I ever wrote was in BASIC on a TRS-80 Model I and it looked something like:
10 PRINT "Don is cool"
20 GOTO 10

It only went downhill from there.

Hey look, I've got a blog

Comments and Discussions