view Main.cs @ 34:c3c64e139e5f default tip

Re #245: Create unit tab implementation * Create layout for unit tab widget * Start to populate values WARNING: Qyoto/Qt# seems unstable now and segfaults when new units are added!
author IBBoard <dev@ibboard.co.uk>
date Sat, 07 Aug 2010 16:02:53 +0000
parents 55d4f16c982b
children
line wrap: on
line source

// This file (Main.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
// 
// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
using System;
using System.IO;
using System.Collections.Generic;
using Qyoto;
using log4net;
using IBBoard;
using IBBoard.WarFoundry.API;
using IBBoard.WarFoundry.API.Factories.Xml;
using IBBoard.WarFoundry.API.Savers;

namespace IBBoard.WarFoundry.GUI.QtSharp
{
	class MainClass
	{
		private static ILog logger = LogManager.GetLogger(typeof(MainClass));
		static QApplication app;
		
		public static void Main(string[] args)
		{
			try
			{
				logger.InfoFormat("Starting application with args: {0}", args.ToString());
				app = new QApplication(args, true);
				app.QuitOnLastWindowClosed = true;
				logger.Debug("Starting exec");
				QApplication.Invoke(delegate
				{
					SetUpWarFoundryEnvironment();
				
					MainWindow win = new MainWindow();
					win.Show();
					QApplication.SetActiveWindow(win);
				});
				int result = QApplication.Exec();
				logger.InfoFormat("Closing application - exit code {0}", result);
			}
			catch(Exception ex)
			{
				logger.Fatal(ex);
				QMessageBox.Critical(null, "Unhandled exception", ex.Message+"\n\nPlease see log for more details");
			}
				
		}
		
		private static void SetUpWarFoundryEnvironment()
		{
			logger.Debug("Creating application environment");
			//FIXME: Temporary hack to add paths and factories before we get preferences and plugins
			WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Path.Combine(Constants.ExecutablePath, "data")));
			WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
			WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished;
			WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver());
		}		

		private static void FileLoadingFinished(List<FileLoadFailure> failures)
		{
			foreach(FileLoadFailure failure in failures)
			{
				logger.Warn("Failed to load " + failure.FailedFile.FullName + ": " + failure.Message);
			}
		}
	}
}