/***********************************************************************
 * 
 *  Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; version 2.1
 *  of the License.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, Novell, Inc.
 * 
 *  To contact Novell about this file by physical or electronic mail, 
 *  you may find current contact information at www.novell.com.
 * 
 ***********************************************************************/

//
// copyright 2003 Don Kackman - mailto:dkackman_2000@yahoo.com
//
// no warranty expressed or implied
// use however you'd like
//
using System;

namespace VersionVDProj
{
	/// <summary>
	/// This is the class that has the Main method. This class is responsible for parsing command line
	/// arguments and dispatching them to the correct classes
	/// </summary>
	class App
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static int Main(string[] args)
		{
			if ( args.Length != 0 )
			{
				try
				{
					ArgumentParser arguments = new ArgumentParser( args );
					VDProjectVersioner versioner = null;

					switch ( arguments.Command )
					{
						case "msi":
							versioner = new MSIProjectVersioner( arguments.ProjectFile );
							break;
						case "msm":
							versioner = new MSMProjectVersioner( arguments.ProjectFile );
							break;
						default:
							throw new Exception( string.Format( "Unrecognized command {0}", arguments.Command ) );
					}

					versioner.UpdateFile( arguments.Options );
					return 0;
				}
				catch ( Exception e )
				{
					Console.WriteLine( "ERROR" );
					Console.WriteLine( e.Message );
					return 1;
				}
			}
			
			// with no arguments show the usage
			ShowUsage();
			return 0;
		}

		private static void ShowUsage()
		{
			Console.WriteLine( "VersionVDProj -msi <PATH> version=<VERSION> [package=<PACKAGECODE>]" );
			Console.WriteLine( "\t[product=<PRODUCTCODE>] [upgrade=<UPGRADECODE>]" );
			Console.WriteLine( "The -msi switch is used for updating MSI installer projects" );
			Console.WriteLine( "" );
			Console.WriteLine( "<PATH> is the path to the vdproj file (without braces)" );
			Console.WriteLine( "<VERSION> is the version to use in format #.#.# (without braces)" );
			Console.WriteLine( "<PACKAGECODE> Optional package guid (if not specified will be auto-generated)" );
			Console.WriteLine( "<PRODUCTCODE> Optional product guid (if not specified will be set to the" );
			Console.WriteLine( "\tsame value used to set the package guid)" );
			Console.WriteLine( "<UPGRADECODE> Optional upgrade guid (if not specified the upgrade code will" );
			Console.WriteLine( "\tnot be modified)" );
			Console.WriteLine( "" );
			Console.WriteLine( "VersionVDProj -msm <PATH> version=<VERSION> [signature=<SIGNATURE>]" );
			Console.WriteLine( "The -msm switch is used for updating merge module projects" );
			Console.WriteLine( "" );
			Console.WriteLine( "<PATH> is the path to the vdproj file (without braces)" );
			Console.WriteLine( "<VERSION> is the version to use in format #.#.# (without braces)" );
			Console.WriteLine( "<SIGNATURE> Optional unique id for the merge module (if not specified a guid" );
			Console.WriteLine( "\tbased signature will be auto-generated)" );
			Console.WriteLine( "" );
			Console.WriteLine( "Named arguments can be specified in any order" );
		}
	}
}
