// (c) 2005 Electronic Arts Inc.
//

using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using System.Threading;

using System.Xml;

using System.IO.Pipes;

using EA.GameTalkMessages;

namespace EA.GameTalkViewer
{
	/// <summary>
	/// NOTE: We have one slightly risky aspect to this class
	/// 
	/// We currently process the log files with no more than a second between reads
	/// Once we realize our log files have been deleted we reset our file indices by doing the following:
	/// mConnectionsPositionInFile = 0;
	/// mTrafficPositionInFile = 0;
	/// mMiscPositionInFile = 0;
	/// 
	/// We currently have two mechanisms by which we reset our file indices.  
	/// 1. The most important is on file deletion of the misc or primary file log, we reset all of the above file indices.
	/// 2. Each time our timer goes off, if we notice any of the files don't exist, we reset the above file indices
	/// </summary>
	public class GameTalkViewer : System.Windows.Forms.Form
	{
		private Icon _IconIdle = null;
		private Icon _IconConnected = null;

		private const string mCommentStartTag = "Comment:";
		private const string mConfigurationTag = "Configuration:";
		private const string mConfigIpAddressTag = "IpAddress:";
		private const string mConfigPortNumTag = "Port:";
		private string mServerVersionStr = null;
		private List<string> mReceivedChannels = new List<string>();
		private List<string> mChannelsToIgnore = new List<string>();
		private List<ListViewItem> mListViewItems = new List<ListViewItem>();
		// Only display the last 100 messages
		private const int MAX_LIST_VIEW_ITEMS_TO_DISPLAY = 100;
		// Keep 500 in memory
		private const int MAX_LIST_VIEW_ITEMS = 500;

		private bool mServerIsAtLeast2_8_0 = false;

		// Create a UI context variable
		private static SynchronizationContext mUISynchronizationContext = null;
		private string mServerIpAddress = string.Empty;
		private string mServerPortNum = string.Empty;

		private FileIOReader mFileIOReader = null;
		private NamedPipesReader mNamedPipesReader = null;

		private System.Windows.Forms.NotifyIcon _NotifyIcon;
		private System.Windows.Forms.ContextMenu _ContextMenu;
		private System.Windows.Forms.MenuItem mMenuItemExit;
		private System.Windows.Forms.MenuItem mMenuItemShowViewer;
		private System.Windows.Forms.MenuItem mMenuItemDivider1;
		private System.Windows.Forms.MenuItem mMenuItemDivider2;
		private System.Windows.Forms.MenuItem mMenuItemGameTalkService;
		private System.Windows.Forms.MenuItem mMenuItemStart;
		private System.Windows.Forms.MenuItem mMenuItemStop;
		private System.Windows.Forms.ToolBar _ToolBar;
		private System.Windows.Forms.Panel _PanelContent;
		private System.Windows.Forms.GroupBox mGroupBoxMiscLogs;
		private System.Windows.Forms.ListView mListViewMiscellanwousLog;
		private System.Windows.Forms.ColumnHeader columnHeader1;
		private System.Windows.Forms.ColumnHeader columnHeader2;
		private System.Windows.Forms.GroupBox mGroupBoxMessageLogs;
		private System.Windows.Forms.ListView mListViewMessages;
		private System.Windows.Forms.ColumnHeader mColumnHeaderDirection;
		private System.Windows.Forms.ColumnHeader mColumnHeaderTarget;
		private System.Windows.Forms.ColumnHeader mColumnHeaderMessage;
		private System.Windows.Forms.GroupBox mGroupBoxActiveConnections;
		private System.Windows.Forms.ListView mListViewConnections;
		private System.Windows.Forms.ColumnHeader mColumnHeaderIpAddress;
		private System.Windows.Forms.ColumnHeader mColumnHeaderName;
		private System.Windows.Forms.ImageList _ImageList;
		private System.Windows.Forms.ToolBarButton _ToolBarButtonTargetManager;
		private System.Windows.Forms.ToolBarButton _ToolBarButtonClose;
		private System.Windows.Forms.ToolBarButton _ToolBarButtonRefresh;
		private System.Windows.Forms.MenuItem mMenuItemDelete;
		private System.Windows.Forms.StatusBar _StatusBar;
		private System.Windows.Forms.ToolBarButton _ToolBarButtonRefreshRate;
		private System.Windows.Forms.ContextMenu _ContextMenuRefreshRate;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem _MenuItemFast;
		private System.Windows.Forms.MenuItem _MenuItemMedium;
		private System.Windows.Forms.MenuItem _MenuItemSlow;
		private ToolBarButton _ToolBarButtonCapLogFileSize;
		private ContextMenu _CapLogFileSizeContextMenu;
		private MenuItem _DoNotCapLogFileSizeMenuItem;
		private MenuItem _CapLogFileSizeMenuItem;
		private SplitContainer splitContainer1;
		private ColumnHeader mColumnHeaderPlatform;
		private ColumnHeader mColumnHeaderVersion;
		private ToolBarButton _ToolBarButtonDisplayMessages;
		private ContextMenu _DisplayMessageDetailsContextMenu;
		private MenuItem mDoNotParseMessageMenuItem;
		private MenuItem mParseMessageMenuItem;
		private MenuItem mDoNotDisplayMessagesMenuItem;
		private MenuItem mMenuItemFileTalkService;
		private MenuItem mMenuItemDeleteFileTalk;
		private MenuItem _MenuItemNever;
		private MenuItem mMenuItemStartFileTalk;
		private MenuItem mMenuItemStopFileTalk;
		private Splitter mTopBottomSplitter;
		private ToolBarButton _ToolBarButtonClear;
		private ToolBarButton _ToolBarButtonFilterChannels;
		private ColumnHeader mColumnHeaderSender;
		private ContextMenu mContextMenuFilterChannel;
		private MenuItem menuItem1;
		private MenuItem menuItem3;
		private MenuItem menuItem4;
		private MenuItem menuItem5;
		private MenuItem menuItem6;
		private ColumnHeader mColumnHeaderChannel;
		private ToolBarButton _ToolBarButtonNetworkConnectivitySensitive;
		private ContextMenu _ContextMenuConnectivitySensitive;
		private MenuItem _MenuItemShutdownBasedOnNetwork;
		private MenuItem _MenuItemNoShutdownIfNetworkLost;
		private ToolBarButton _ToolBarButtonSwitchServer;
		private ContextMenu _ContextMenuSwitchServer;
		private MenuItem _MenuItemUse64BitServer;
		private MenuItem _MenuItemUse32BitServer;
		private ToolBarButton _ToolBarButtonLogging;
		private ContextMenu _ContextMenuGTSLogging;
		private MenuItem _MenuItemNamedPipes;
		private MenuItem _MenuItemClassicFileIO;
		private System.ComponentModel.IContainer components;

		private void UpdateWhichBitSizeServerToUse()
		{
			if (Configuration.Instance.Use32BitGameTalkServer)
			{
				_MenuItemUse64BitServer.Checked = false;
				_MenuItemUse32BitServer.Checked = true;
			}
			else
			{
				_MenuItemUse64BitServer.Checked = true;
				_MenuItemUse32BitServer.Checked = false;
			}
		}

		private void UpdateNamedPipesMenuItems()
		{
			if (Configuration.Instance.UseNamedPipes)
			{
				_MenuItemNamedPipes.Checked = true;
				_MenuItemClassicFileIO.Checked = false;
			}
			else
			{
				_MenuItemNamedPipes.Checked = false;
				_MenuItemClassicFileIO.Checked = true;
			}
		}

		public GameTalkViewer()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			// Assign a windows forms synchronization context because we do this 
			// in the creating thread, we can create a handle to this thread for 
			// the life of the UI control
			mUISynchronizationContext = WindowsFormsSynchronizationContext.Current;

			Assembly asm = Assembly.GetExecutingAssembly();
			_IconIdle = new Icon(asm.GetManifestResourceStream("GameTalkViewer.Resources.Idle.ico"), 16, 16);
			_IconConnected = new Icon(asm.GetManifestResourceStream("GameTalkViewer.Resources.Connected.ico"), 16, 16);

			// The following may be needed to make the icons look less pixelated
			/*_ImageList.Images.Clear();
			Icon icon = new Icon(asm.GetManifestResourceStream("GameTalkViewer.Resources.Target Manager.ico"), 24, 24);
			_ImageList.Images.Add(icon);
			icon = new Icon(asm.GetManifestResourceStream("GameTalkViewer.Resources.Refresh.ico"), 24, 24);
			_ImageList.Images.Add(icon);
			icon = new Icon(asm.GetManifestResourceStream("GameTalkViewer.Resources.Close.ico"), 24, 24);
			_ImageList.Images.Add(icon);
			icon = new Icon(asm.GetManifestResourceStream("GameTalkViewer.Resources.alarmclock.ico"), 24, 24);
			_ImageList.Images.Add(icon);
			icon = new Icon(asm.GetManifestResourceStream("GameTalkViewer.Resources.edit.ico"), 24, 24);
			_ImageList.Images.Add(icon);
			icon = new Icon(asm.GetManifestResourceStream("GameTalkViewer.Resources.table_sql_view.ico"), 24, 24);
			_ImageList.Images.Add(icon);*/

			TargetManager.Instance.Initialize();

			string version = string.Empty;
			try
			{
				version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
				this.Text += " " + version;
			}
			catch (Exception) { }

			// Everytime GameTalkMonitor/GameTalkViewer is restarted - we reset the settings such that:
			// - it will display messages (but only the meta data)
			// - it limits the log file size on the user's computer
			// - it makes GameTalkServer NOT shutdown just because the user's PC doesn't have network connectivity
			Configuration.Instance.SetLoggingLevel(LoggingLevel.META_DATA);
			Configuration.Instance.SetLimitOnLogFileSize(true);
			Configuration.Instance.SetCheckNetworkConnectivity(false);

			UpdateWhichBitSizeServerToUse();
			UpdateNamedPipesMenuItems();

			_NotifyIcon.Icon = _IconIdle;
			// Useful for debugging - without the following the Trace output won't be sent anywhere.
			//Trace.Listeners.Add(new LogManager());

			if (Configuration.Instance.UseNamedPipes)
				mNamedPipesReader = new NamedPipesReader(mUISynchronizationContext, ProcessMiscOnUiThread, ProcessConnectionsOnUiThread, ProcessTrafficOnUiThread);
			else
				mFileIOReader = new FileIOReader(this, SuspendLayoutOfPanels, ResumeLayoutOfPanels, HaveConnections, ShowNoClientsConnected, ProcessMisc, ProcessConnections, ProcessTraffic);
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GameTalkViewer));
			this._NotifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
			this._ContextMenu = new System.Windows.Forms.ContextMenu();
			this.mMenuItemShowViewer = new System.Windows.Forms.MenuItem();
			this.mMenuItemDivider1 = new System.Windows.Forms.MenuItem();
			this.mMenuItemGameTalkService = new System.Windows.Forms.MenuItem();
			this.mMenuItemStart = new System.Windows.Forms.MenuItem();
			this.mMenuItemStop = new System.Windows.Forms.MenuItem();
			this.mMenuItemDelete = new System.Windows.Forms.MenuItem();
			this.mMenuItemFileTalkService = new System.Windows.Forms.MenuItem();
			this.mMenuItemStartFileTalk = new System.Windows.Forms.MenuItem();
			this.mMenuItemStopFileTalk = new System.Windows.Forms.MenuItem();
			this.mMenuItemDeleteFileTalk = new System.Windows.Forms.MenuItem();
			this.mMenuItemDivider2 = new System.Windows.Forms.MenuItem();
			this.mMenuItemExit = new System.Windows.Forms.MenuItem();
			this._ToolBar = new System.Windows.Forms.ToolBar();
			this._ToolBarButtonTargetManager = new System.Windows.Forms.ToolBarButton();
			this._ToolBarButtonRefresh = new System.Windows.Forms.ToolBarButton();
			this._ToolBarButtonRefreshRate = new System.Windows.Forms.ToolBarButton();
			this._ContextMenuRefreshRate = new System.Windows.Forms.ContextMenu();
			this._MenuItemFast = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this._MenuItemMedium = new System.Windows.Forms.MenuItem();
			this._MenuItemSlow = new System.Windows.Forms.MenuItem();
			this._MenuItemNever = new System.Windows.Forms.MenuItem();
			this._ToolBarButtonCapLogFileSize = new System.Windows.Forms.ToolBarButton();
			this._CapLogFileSizeContextMenu = new System.Windows.Forms.ContextMenu();
			this._DoNotCapLogFileSizeMenuItem = new System.Windows.Forms.MenuItem();
			this._CapLogFileSizeMenuItem = new System.Windows.Forms.MenuItem();
			this._ToolBarButtonDisplayMessages = new System.Windows.Forms.ToolBarButton();
			this._DisplayMessageDetailsContextMenu = new System.Windows.Forms.ContextMenu();
			this.mParseMessageMenuItem = new System.Windows.Forms.MenuItem();
			this.mDoNotParseMessageMenuItem = new System.Windows.Forms.MenuItem();
			this.mDoNotDisplayMessagesMenuItem = new System.Windows.Forms.MenuItem();
			this._ToolBarButtonClear = new System.Windows.Forms.ToolBarButton();
			this._ToolBarButtonFilterChannels = new System.Windows.Forms.ToolBarButton();
			this.mContextMenuFilterChannel = new System.Windows.Forms.ContextMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.menuItem4 = new System.Windows.Forms.MenuItem();
			this.menuItem5 = new System.Windows.Forms.MenuItem();
			this.menuItem6 = new System.Windows.Forms.MenuItem();
			this._ToolBarButtonNetworkConnectivitySensitive = new System.Windows.Forms.ToolBarButton();
			this._ContextMenuConnectivitySensitive = new System.Windows.Forms.ContextMenu();
			this._MenuItemShutdownBasedOnNetwork = new System.Windows.Forms.MenuItem();
			this._MenuItemNoShutdownIfNetworkLost = new System.Windows.Forms.MenuItem();
			this._ToolBarButtonSwitchServer = new System.Windows.Forms.ToolBarButton();
			this._ContextMenuSwitchServer = new System.Windows.Forms.ContextMenu();
			this._MenuItemUse64BitServer = new System.Windows.Forms.MenuItem();
			this._MenuItemUse32BitServer = new System.Windows.Forms.MenuItem();
			this._ToolBarButtonLogging = new System.Windows.Forms.ToolBarButton();
			this._ContextMenuGTSLogging = new System.Windows.Forms.ContextMenu();
			this._MenuItemNamedPipes = new System.Windows.Forms.MenuItem();
			this._MenuItemClassicFileIO = new System.Windows.Forms.MenuItem();
			this._ToolBarButtonClose = new System.Windows.Forms.ToolBarButton();
			this._ImageList = new System.Windows.Forms.ImageList(this.components);
			this._PanelContent = new System.Windows.Forms.Panel();
			this.mTopBottomSplitter = new System.Windows.Forms.Splitter();
			this.splitContainer1 = new System.Windows.Forms.SplitContainer();
			this.mGroupBoxActiveConnections = new System.Windows.Forms.GroupBox();
			this.mListViewConnections = new System.Windows.Forms.ListView();
			this.mColumnHeaderIpAddress = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
			this.mColumnHeaderName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
			this.mColumnHeaderPlatform = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
			this.mColumnHeaderVersion = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
			this.mGroupBoxMessageLogs = new System.Windows.Forms.GroupBox();
			this.mListViewMessages = new System.Windows.Forms.ListView();
			this.mColumnHeaderDirection = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
			this.mColumnHeaderSender = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
			this.mColumnHeaderTarget = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
			this.mColumnHeaderChannel = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
			this.mColumnHeaderMessage = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
			this.mGroupBoxMiscLogs = new System.Windows.Forms.GroupBox();
			this.mListViewMiscellanwousLog = new System.Windows.Forms.ListView();
			this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
			this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
			this._StatusBar = new System.Windows.Forms.StatusBar();
			this._PanelContent.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
			this.splitContainer1.Panel1.SuspendLayout();
			this.splitContainer1.Panel2.SuspendLayout();
			this.splitContainer1.SuspendLayout();
			this.mGroupBoxActiveConnections.SuspendLayout();
			this.mGroupBoxMessageLogs.SuspendLayout();
			this.mGroupBoxMiscLogs.SuspendLayout();
			this.SuspendLayout();
			// 
			// _NotifyIcon
			// 
			this._NotifyIcon.ContextMenu = this._ContextMenu;
			this._NotifyIcon.Text = "EA Game Talk Server";
			this._NotifyIcon.Visible = true;
			this._NotifyIcon.DoubleClick += new System.EventHandler(this.NotifyIcon_DoubleClick);
			// 
			// _ContextMenu
			// 
			this._ContextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.mMenuItemShowViewer,
            this.mMenuItemDivider1,
            this.mMenuItemGameTalkService,
            this.mMenuItemFileTalkService,
            this.mMenuItemDivider2,
            this.mMenuItemExit});
			// 
			// mMenuItemShowViewer
			// 
			this.mMenuItemShowViewer.Index = 0;
			this.mMenuItemShowViewer.Text = "Game Talk &Monitor ...";
			this.mMenuItemShowViewer.Click += new System.EventHandler(this.MenuItemShowViewer_Click);
			// 
			// mMenuItemDivider1
			// 
			this.mMenuItemDivider1.Index = 1;
			this.mMenuItemDivider1.Text = "-";
			// 
			// mMenuItemGameTalkService
			// 
			this.mMenuItemGameTalkService.Index = 2;
			this.mMenuItemGameTalkService.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.mMenuItemStart,
            this.mMenuItemStop,
            this.mMenuItemDelete});
			this.mMenuItemGameTalkService.Text = "GameTalk Service";
			// 
			// mMenuItemStart
			// 
			this.mMenuItemStart.Index = 0;
			this.mMenuItemStart.Text = "Start";
			this.mMenuItemStart.Click += new System.EventHandler(this.MenuItemStart_Click);
			// 
			// mMenuItemStop
			// 
			this.mMenuItemStop.Index = 1;
			this.mMenuItemStop.Text = "Stop";
			this.mMenuItemStop.Click += new System.EventHandler(this.MenuItemStop_Click);
			// 
			// mMenuItemDelete
			// 
			this.mMenuItemDelete.Index = 2;
			this.mMenuItemDelete.Text = "Delete";
			this.mMenuItemDelete.Click += new System.EventHandler(this.MenuItemDelete_Click);
			// 
			// mMenuItemFileTalkService
			// 
			this.mMenuItemFileTalkService.Index = 3;
			this.mMenuItemFileTalkService.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.mMenuItemStartFileTalk,
            this.mMenuItemStopFileTalk,
            this.mMenuItemDeleteFileTalk});
			this.mMenuItemFileTalkService.Text = "FileTalk Service";
			// 
			// mMenuItemStartFileTalk
			// 
			this.mMenuItemStartFileTalk.Index = 0;
			this.mMenuItemStartFileTalk.Text = "Start";
			this.mMenuItemStartFileTalk.Click += new System.EventHandler(this.mMenuItemStartFileTalk_Click);
			// 
			// mMenuItemStopFileTalk
			// 
			this.mMenuItemStopFileTalk.Index = 1;
			this.mMenuItemStopFileTalk.Text = "Stop";
			this.mMenuItemStopFileTalk.Click += new System.EventHandler(this.mMenuItemStopFileTalk_Click);
			// 
			// mMenuItemDeleteFileTalk
			// 
			this.mMenuItemDeleteFileTalk.Index = 2;
			this.mMenuItemDeleteFileTalk.Text = "Delete";
			this.mMenuItemDeleteFileTalk.Click += new System.EventHandler(this.mMenuItemDeleteFileTalk_Click);
			// 
			// mMenuItemDivider2
			// 
			this.mMenuItemDivider2.Index = 4;
			this.mMenuItemDivider2.Text = "-";
			// 
			// mMenuItemExit
			// 
			this.mMenuItemExit.Index = 5;
			this.mMenuItemExit.Text = "E&xit";
			this.mMenuItemExit.Click += new System.EventHandler(this.MenuItemExit_Click);
			// 
			// _ToolBar
			// 
			this._ToolBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
			this._ToolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
            this._ToolBarButtonTargetManager,
            this._ToolBarButtonRefresh,
            this._ToolBarButtonRefreshRate,
            this._ToolBarButtonCapLogFileSize,
            this._ToolBarButtonDisplayMessages,
            this._ToolBarButtonClear,
            this._ToolBarButtonFilterChannels,
            this._ToolBarButtonNetworkConnectivitySensitive,
            this._ToolBarButtonSwitchServer,
            this._ToolBarButtonLogging,
            this._ToolBarButtonClose});
			this._ToolBar.DropDownArrows = true;
			this._ToolBar.ImageList = this._ImageList;
			this._ToolBar.Location = new System.Drawing.Point(0, 0);
			this._ToolBar.Name = "_ToolBar";
			this._ToolBar.ShowToolTips = true;
			this._ToolBar.Size = new System.Drawing.Size(1282, 44);
			this._ToolBar.TabIndex = 5;
			this._ToolBar.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right;
			this._ToolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.ToolBar_ButtonClick);
			// 
			// _ToolBarButtonTargetManager
			// 
			this._ToolBarButtonTargetManager.ImageIndex = 0;
			this._ToolBarButtonTargetManager.Name = "_ToolBarButtonTargetManager";
			this._ToolBarButtonTargetManager.Text = "Target Manager";
			// 
			// _ToolBarButtonRefresh
			// 
			this._ToolBarButtonRefresh.ImageIndex = 1;
			this._ToolBarButtonRefresh.Name = "_ToolBarButtonRefresh";
			this._ToolBarButtonRefresh.Text = "Refresh";
			// 
			// _ToolBarButtonRefreshRate
			// 
			this._ToolBarButtonRefreshRate.DropDownMenu = this._ContextMenuRefreshRate;
			this._ToolBarButtonRefreshRate.ImageIndex = 3;
			this._ToolBarButtonRefreshRate.Name = "_ToolBarButtonRefreshRate";
			this._ToolBarButtonRefreshRate.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this._ToolBarButtonRefreshRate.Text = "Refresh Rate";
			this._ToolBarButtonRefreshRate.ToolTipText = "Select refresh time";
			// 
			// _ContextMenuRefreshRate
			// 
			this._ContextMenuRefreshRate.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this._MenuItemFast,
            this.menuItem2,
            this._MenuItemMedium,
            this._MenuItemSlow,
            this._MenuItemNever});
			// 
			// _MenuItemFast
			// 
			this._MenuItemFast.Checked = true;
			this._MenuItemFast.Index = 0;
			this._MenuItemFast.Text = "Fast";
			this._MenuItemFast.Click += new System.EventHandler(this.RefreshMenuItem_Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 1;
			this.menuItem2.Text = "-";
			// 
			// _MenuItemMedium
			// 
			this._MenuItemMedium.Index = 2;
			this._MenuItemMedium.Text = "Medium";
			this._MenuItemMedium.Click += new System.EventHandler(this.RefreshMenuItem_Click);
			// 
			// _MenuItemSlow
			// 
			this._MenuItemSlow.Index = 3;
			this._MenuItemSlow.Text = "Slow";
			this._MenuItemSlow.Click += new System.EventHandler(this.RefreshMenuItem_Click);
			// 
			// _MenuItemNever
			// 
			this._MenuItemNever.Index = 4;
			this._MenuItemNever.Text = "Never";
			this._MenuItemNever.Click += new System.EventHandler(this.RefreshMenuItem_Click);
			// 
			// _ToolBarButtonCapLogFileSize
			// 
			this._ToolBarButtonCapLogFileSize.DropDownMenu = this._CapLogFileSizeContextMenu;
			this._ToolBarButtonCapLogFileSize.ImageIndex = 4;
			this._ToolBarButtonCapLogFileSize.Name = "_ToolBarButtonCapLogFileSize";
			this._ToolBarButtonCapLogFileSize.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this._ToolBarButtonCapLogFileSize.Text = "Log File Size";
			// 
			// _CapLogFileSizeContextMenu
			// 
			this._CapLogFileSizeContextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this._DoNotCapLogFileSizeMenuItem,
            this._CapLogFileSizeMenuItem});
			// 
			// _DoNotCapLogFileSizeMenuItem
			// 
			this._DoNotCapLogFileSizeMenuItem.Index = 0;
			this._DoNotCapLogFileSizeMenuItem.Text = "Allow Log File to Grow Without Limit";
			this._DoNotCapLogFileSizeMenuItem.Click += new System.EventHandler(this._DoNotCapLogFileSizeMenuItem_Click);
			// 
			// _CapLogFileSizeMenuItem
			// 
			this._CapLogFileSizeMenuItem.Checked = true;
			this._CapLogFileSizeMenuItem.Index = 1;
			this._CapLogFileSizeMenuItem.Text = "Cap Log File Size";
			this._CapLogFileSizeMenuItem.Click += new System.EventHandler(this._CapLogFileSizeMenuItem_Click);
			// 
			// _ToolBarButtonDisplayMessages
			// 
			this._ToolBarButtonDisplayMessages.DropDownMenu = this._DisplayMessageDetailsContextMenu;
			this._ToolBarButtonDisplayMessages.ImageIndex = 5;
			this._ToolBarButtonDisplayMessages.Name = "_ToolBarButtonDisplayMessages";
			this._ToolBarButtonDisplayMessages.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this._ToolBarButtonDisplayMessages.Text = "Message Details";
			// 
			// _DisplayMessageDetailsContextMenu
			// 
			this._DisplayMessageDetailsContextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.mParseMessageMenuItem,
            this.mDoNotParseMessageMenuItem,
            this.mDoNotDisplayMessagesMenuItem});
			// 
			// mParseMessageMenuItem
			// 
			this.mParseMessageMenuItem.Index = 0;
			this.mParseMessageMenuItem.Text = "Parse Message Details";
			this.mParseMessageMenuItem.Click += new System.EventHandler(this.mParseMessageMenuItem_Click);
			// 
			// mDoNotParseMessageMenuItem
			// 
			this.mDoNotParseMessageMenuItem.Checked = true;
			this.mDoNotParseMessageMenuItem.Index = 1;
			this.mDoNotParseMessageMenuItem.Text = "Don\'t Parse Message Details";
			this.mDoNotParseMessageMenuItem.Click += new System.EventHandler(this.mDoNotParseMessageMenuItem_Click);
			// 
			// mDoNotDisplayMessagesMenuItem
			// 
			this.mDoNotDisplayMessagesMenuItem.Index = 2;
			this.mDoNotDisplayMessagesMenuItem.Text = "Don\'t Display Messages";
			this.mDoNotDisplayMessagesMenuItem.Click += new System.EventHandler(this.mDoNotDisplayMessagesMenuItem_Click);
			// 
			// _ToolBarButtonClear
			// 
			this._ToolBarButtonClear.ImageIndex = 6;
			this._ToolBarButtonClear.Name = "_ToolBarButtonClear";
			this._ToolBarButtonClear.Text = "Clear Logs";
			// 
			// _ToolBarButtonFilterChannels
			// 
			this._ToolBarButtonFilterChannels.DropDownMenu = this.mContextMenuFilterChannel;
			this._ToolBarButtonFilterChannels.ImageIndex = 8;
			this._ToolBarButtonFilterChannels.Name = "_ToolBarButtonFilterChannels";
			this._ToolBarButtonFilterChannels.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this._ToolBarButtonFilterChannels.Text = "Filter Channels";
			// 
			// mContextMenuFilterChannel
			// 
			this.mContextMenuFilterChannel.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem1,
            this.menuItem3,
            this.menuItem4,
            this.menuItem5,
            this.menuItem6});
			this.mContextMenuFilterChannel.Popup += new System.EventHandler(this.mContextMenuFilterChannel_Popup);
			// 
			// menuItem1
			// 
			this.menuItem1.Checked = true;
			this.menuItem1.Index = 0;
			this.menuItem1.Text = "Fast";
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 1;
			this.menuItem3.Text = "-";
			// 
			// menuItem4
			// 
			this.menuItem4.Index = 2;
			this.menuItem4.Text = "Medium";
			// 
			// menuItem5
			// 
			this.menuItem5.Index = 3;
			this.menuItem5.Text = "Slow";
			// 
			// menuItem6
			// 
			this.menuItem6.Index = 4;
			this.menuItem6.Text = "Never";
			// 
			// _ToolBarButtonNetworkConnectivitySensitive
			// 
			this._ToolBarButtonNetworkConnectivitySensitive.DropDownMenu = this._ContextMenuConnectivitySensitive;
			this._ToolBarButtonNetworkConnectivitySensitive.ImageIndex = 9;
			this._ToolBarButtonNetworkConnectivitySensitive.Name = "_ToolBarButtonNetworkConnectivitySensitive";
			this._ToolBarButtonNetworkConnectivitySensitive.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this._ToolBarButtonNetworkConnectivitySensitive.Text = "Networking";
			this._ToolBarButtonNetworkConnectivitySensitive.ToolTipText = "Connectivity Sensitive: Should GameTalkServer shutdown if PC loses network connec" +
				"tion";
			// 
			// _ContextMenuConnectivitySensitive
			// 
			this._ContextMenuConnectivitySensitive.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this._MenuItemShutdownBasedOnNetwork,
            this._MenuItemNoShutdownIfNetworkLost});
			// 
			// _MenuItemShutdownBasedOnNetwork
			// 
			this._MenuItemShutdownBasedOnNetwork.Index = 0;
			this._MenuItemShutdownBasedOnNetwork.Text = "Shutdown if network connection lost";
			this._MenuItemShutdownBasedOnNetwork.Click += new System.EventHandler(this._MenuItemShutdownBasedOnNetwork_Click);
			// 
			// _MenuItemNoShutdownIfNetworkLost
			// 
			this._MenuItemNoShutdownIfNetworkLost.Checked = true;
			this._MenuItemNoShutdownIfNetworkLost.Index = 1;
			this._MenuItemNoShutdownIfNetworkLost.Text = "Do not shutdown if network connection lost";
			this._MenuItemNoShutdownIfNetworkLost.Click += new System.EventHandler(this._MenuItemNoShutdownIfNetworkLost_Click);
			// 
			// _ToolBarButtonSwitchServer
			// 
			this._ToolBarButtonSwitchServer.DropDownMenu = this._ContextMenuSwitchServer;
			this._ToolBarButtonSwitchServer.ImageIndex = 10;
			this._ToolBarButtonSwitchServer.Name = "_ToolBarButtonSwitchServer";
			this._ToolBarButtonSwitchServer.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this._ToolBarButtonSwitchServer.Text = "Switch Server";
			this._ToolBarButtonSwitchServer.ToolTipText = "Switch between 32 and 64 bit server";
			// 
			// _ContextMenuSwitchServer
			// 
			this._ContextMenuSwitchServer.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this._MenuItemUse64BitServer,
            this._MenuItemUse32BitServer});
			// 
			// _MenuItemUse64BitServer
			// 
			this._MenuItemUse64BitServer.Checked = true;
			this._MenuItemUse64BitServer.Index = 0;
			this._MenuItemUse64BitServer.Text = "64 bit GameTalkServer";
			this._MenuItemUse64BitServer.Click += new System.EventHandler(this._MenuItemUse64BitServer_Click);
			// 
			// _MenuItemUse32BitServer
			// 
			this._MenuItemUse32BitServer.Index = 1;
			this._MenuItemUse32BitServer.Text = "32 bit GameTalkServer";
			this._MenuItemUse32BitServer.Click += new System.EventHandler(this._MenuItemUse32BitServer_Click);
			// 
			// _ToolBarButtonLogging
			// 
			this._ToolBarButtonLogging.DropDownMenu = this._ContextMenuGTSLogging;
			this._ToolBarButtonLogging.ImageIndex = 11;
			this._ToolBarButtonLogging.Name = "_ToolBarButtonLogging";
			this._ToolBarButtonLogging.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this._ToolBarButtonLogging.Text = "Logging";
			this._ToolBarButtonLogging.ToolTipText = "In the past the GameTalkServer has logged messages using files - now named pipes " +
	"can be used";
			// 
			// _ContextMenuGTSLogging
			// 
			this._ContextMenuGTSLogging.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this._MenuItemNamedPipes,
            this._MenuItemClassicFileIO});
			// 
			// _MenuItemNamedPipes
			// 
			this._MenuItemNamedPipes.Checked = true;
			this._MenuItemNamedPipes.Index = 0;
			this._MenuItemNamedPipes.Text = "Named Pipes";
			this._MenuItemNamedPipes.Click += new System.EventHandler(this._MenuItemNamedPipes_Click);
			// 
			// _MenuItemClassicFileIO
			// 
			this._MenuItemClassicFileIO.Index = 1;
			this._MenuItemClassicFileIO.Text = "Classic File I/O";
			this._MenuItemClassicFileIO.Click += new System.EventHandler(this._MenuItemClassicFileIO_Click);
			// 
			// _ToolBarButtonClose
			// 
			this._ToolBarButtonClose.ImageIndex = 2;
			this._ToolBarButtonClose.Name = "_ToolBarButtonClose";
			this._ToolBarButtonClose.Text = "Close";
			// 
			// _ImageList
			// 
			this._ImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("_ImageList.ImageStream")));
			this._ImageList.TransparentColor = System.Drawing.Color.Transparent;
			this._ImageList.Images.SetKeyName(0, "");
			this._ImageList.Images.SetKeyName(1, "");
			this._ImageList.Images.SetKeyName(2, "");
			this._ImageList.Images.SetKeyName(3, "");
			this._ImageList.Images.SetKeyName(4, "edit.ico");
			this._ImageList.Images.SetKeyName(5, "table_sql_view.ico");
			this._ImageList.Images.SetKeyName(6, "window_new.ico");
			this._ImageList.Images.SetKeyName(7, "document_plain_new.ico");
			this._ImageList.Images.SetKeyName(8, "funnel_delete.ico");
			this._ImageList.Images.SetKeyName(9, "trafficlight_red.ico");
			this._ImageList.Images.SetKeyName(10, "Connected.ico");
			this._ImageList.Images.SetKeyName(11, "server_to_client.ico");
			// 
			// _PanelContent
			// 
			this._PanelContent.Controls.Add(this.mTopBottomSplitter);
			this._PanelContent.Controls.Add(this.splitContainer1);
			this._PanelContent.Controls.Add(this.mGroupBoxMiscLogs);
			this._PanelContent.Dock = System.Windows.Forms.DockStyle.Fill;
			this._PanelContent.Location = new System.Drawing.Point(0, 44);
			this._PanelContent.Name = "_PanelContent";
			this._PanelContent.Size = new System.Drawing.Size(1282, 362);
			this._PanelContent.TabIndex = 6;
			// 
			// mTopBottomSplitter
			// 
			this.mTopBottomSplitter.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.mTopBottomSplitter.Location = new System.Drawing.Point(0, 230);
			this.mTopBottomSplitter.Name = "mTopBottomSplitter";
			this.mTopBottomSplitter.Size = new System.Drawing.Size(1282, 3);
			this.mTopBottomSplitter.TabIndex = 8;
			this.mTopBottomSplitter.TabStop = false;
			// 
			// splitContainer1
			// 
			this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.splitContainer1.Location = new System.Drawing.Point(0, 0);
			this.splitContainer1.Name = "splitContainer1";
			// 
			// splitContainer1.Panel1
			// 
			this.splitContainer1.Panel1.Controls.Add(this.mGroupBoxActiveConnections);
			// 
			// splitContainer1.Panel2
			// 
			this.splitContainer1.Panel2.Controls.Add(this.mGroupBoxMessageLogs);
			this.splitContainer1.Size = new System.Drawing.Size(1282, 233);
			this.splitContainer1.SplitterDistance = 403;
			this.splitContainer1.TabIndex = 7;
			// 
			// mGroupBoxActiveConnections
			// 
			this.mGroupBoxActiveConnections.Controls.Add(this.mListViewConnections);
			this.mGroupBoxActiveConnections.Dock = System.Windows.Forms.DockStyle.Fill;
			this.mGroupBoxActiveConnections.ForeColor = System.Drawing.Color.Blue;
			this.mGroupBoxActiveConnections.Location = new System.Drawing.Point(0, 0);
			this.mGroupBoxActiveConnections.Name = "mGroupBoxActiveConnections";
			this.mGroupBoxActiveConnections.Size = new System.Drawing.Size(403, 233);
			this.mGroupBoxActiveConnections.TabIndex = 4;
			this.mGroupBoxActiveConnections.TabStop = false;
			this.mGroupBoxActiveConnections.Text = "Active Connections";
			// 
			// mListViewConnections
			// 
			this.mListViewConnections.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.mColumnHeaderIpAddress,
            this.mColumnHeaderName,
            this.mColumnHeaderPlatform,
            this.mColumnHeaderVersion});
			this.mListViewConnections.Dock = System.Windows.Forms.DockStyle.Fill;
			this.mListViewConnections.FullRowSelect = true;
			this.mListViewConnections.GridLines = true;
			this.mListViewConnections.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
			this.mListViewConnections.LabelWrap = false;
			this.mListViewConnections.Location = new System.Drawing.Point(3, 17);
			this.mListViewConnections.Name = "mListViewConnections";
			this.mListViewConnections.Size = new System.Drawing.Size(397, 213);
			this.mListViewConnections.TabIndex = 0;
			this.mListViewConnections.UseCompatibleStateImageBehavior = false;
			this.mListViewConnections.View = System.Windows.Forms.View.Details;
			// 
			// mColumnHeaderIpAddress
			// 
			this.mColumnHeaderIpAddress.Text = "Ip Address";
			this.mColumnHeaderIpAddress.Width = 123;
			// 
			// mColumnHeaderName
			// 
			this.mColumnHeaderName.Text = "Name";
			this.mColumnHeaderName.Width = 110;
			// 
			// mColumnHeaderPlatform
			// 
			this.mColumnHeaderPlatform.Text = "Platform";
			this.mColumnHeaderPlatform.Width = 66;
			// 
			// mColumnHeaderVersion
			// 
			this.mColumnHeaderVersion.Text = "Version";
			// 
			// mGroupBoxMessageLogs
			// 
			this.mGroupBoxMessageLogs.Controls.Add(this.mListViewMessages);
			this.mGroupBoxMessageLogs.Dock = System.Windows.Forms.DockStyle.Fill;
			this.mGroupBoxMessageLogs.ForeColor = System.Drawing.Color.Blue;
			this.mGroupBoxMessageLogs.Location = new System.Drawing.Point(0, 0);
			this.mGroupBoxMessageLogs.Name = "mGroupBoxMessageLogs";
			this.mGroupBoxMessageLogs.Size = new System.Drawing.Size(875, 233);
			this.mGroupBoxMessageLogs.TabIndex = 5;
			this.mGroupBoxMessageLogs.TabStop = false;
			this.mGroupBoxMessageLogs.Text = "Messages Logs";
			// 
			// mListViewMessages
			// 
			this.mListViewMessages.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.mColumnHeaderDirection,
            this.mColumnHeaderSender,
            this.mColumnHeaderTarget,
            this.mColumnHeaderChannel,
            this.mColumnHeaderMessage});
			this.mListViewMessages.Dock = System.Windows.Forms.DockStyle.Fill;
			this.mListViewMessages.FullRowSelect = true;
			this.mListViewMessages.GridLines = true;
			this.mListViewMessages.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
			this.mListViewMessages.LabelWrap = false;
			this.mListViewMessages.Location = new System.Drawing.Point(3, 17);
			this.mListViewMessages.Name = "mListViewMessages";
			this.mListViewMessages.Size = new System.Drawing.Size(869, 213);
			this.mListViewMessages.TabIndex = 0;
			this.mListViewMessages.UseCompatibleStateImageBehavior = false;
			this.mListViewMessages.View = System.Windows.Forms.View.Details;
			this.mListViewMessages.RegionChanged += new System.EventHandler(this.mListViewMessages_RegionChanged);
			this.mListViewMessages.KeyDown += new System.Windows.Forms.KeyEventHandler(this.mListViewMessages_KeyDown);
			// 
			// mColumnHeaderDirection
			// 
			this.mColumnHeaderDirection.Text = "Direction";
			this.mColumnHeaderDirection.Width = 67;
			// 
			// mColumnHeaderSender
			// 
			this.mColumnHeaderSender.Text = "Sender";
			this.mColumnHeaderSender.Width = 89;
			// 
			// mColumnHeaderTarget
			// 
			this.mColumnHeaderTarget.Text = "Target";
			this.mColumnHeaderTarget.Width = 105;
			// 
			// mColumnHeaderChannel
			// 
			this.mColumnHeaderChannel.Text = "Channel";
			this.mColumnHeaderChannel.Width = 102;
			// 
			// mColumnHeaderMessage
			// 
			this.mColumnHeaderMessage.Text = "Message";
			this.mColumnHeaderMessage.Width = 432;
			// 
			// mGroupBoxMiscLogs
			// 
			this.mGroupBoxMiscLogs.Controls.Add(this.mListViewMiscellanwousLog);
			this.mGroupBoxMiscLogs.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.mGroupBoxMiscLogs.ForeColor = System.Drawing.Color.Blue;
			this.mGroupBoxMiscLogs.Location = new System.Drawing.Point(0, 233);
			this.mGroupBoxMiscLogs.Name = "mGroupBoxMiscLogs";
			this.mGroupBoxMiscLogs.Size = new System.Drawing.Size(1282, 129);
			this.mGroupBoxMiscLogs.TabIndex = 6;
			this.mGroupBoxMiscLogs.TabStop = false;
			this.mGroupBoxMiscLogs.Text = "Miscellaneous Logs";
			// 
			// mListViewMiscellanwousLog
			// 
			this.mListViewMiscellanwousLog.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.columnHeader1,
            this.columnHeader2});
			this.mListViewMiscellanwousLog.Dock = System.Windows.Forms.DockStyle.Fill;
			this.mListViewMiscellanwousLog.FullRowSelect = true;
			this.mListViewMiscellanwousLog.GridLines = true;
			this.mListViewMiscellanwousLog.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
			this.mListViewMiscellanwousLog.LabelWrap = false;
			this.mListViewMiscellanwousLog.Location = new System.Drawing.Point(3, 17);
			this.mListViewMiscellanwousLog.Name = "mListViewMiscellanwousLog";
			this.mListViewMiscellanwousLog.Size = new System.Drawing.Size(1276, 109);
			this.mListViewMiscellanwousLog.TabIndex = 0;
			this.mListViewMiscellanwousLog.UseCompatibleStateImageBehavior = false;
			this.mListViewMiscellanwousLog.View = System.Windows.Forms.View.Details;
			this.mListViewMiscellanwousLog.KeyDown += new System.Windows.Forms.KeyEventHandler(this.mListViewMiscellanwousLog_KeyDown);
			// 
			// columnHeader1
			// 
			this.columnHeader1.Text = "Type";
			this.columnHeader1.Width = 98;
			// 
			// columnHeader2
			// 
			this.columnHeader2.Text = "Message";
			this.columnHeader2.Width = 1069;
			// 
			// _StatusBar
			// 
			this._StatusBar.Location = new System.Drawing.Point(0, 406);
			this._StatusBar.Name = "_StatusBar";
			this._StatusBar.Size = new System.Drawing.Size(1282, 22);
			this._StatusBar.TabIndex = 7;
			this._StatusBar.Text = "Running Server *.*.*.*";
			// 
			// GameTalkViewer
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
			this.ClientSize = new System.Drawing.Size(1282, 428);
			this.ControlBox = false;
			this.Controls.Add(this._PanelContent);
			this.Controls.Add(this._ToolBar);
			this.Controls.Add(this._StatusBar);
			this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.MinimumSize = new System.Drawing.Size(622, 314);
			this.Name = "GameTalkViewer";
			this.ShowInTaskbar = false;
			this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
			this.Text = "Game Talk Monitor";
			this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
			this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.GameTalkViewer_FormClosing);
			this.Load += new System.EventHandler(this.GameTalkViewer_Load);
			this.VisibleChanged += new System.EventHandler(this.GameTalkViewer_VisibleChanged);
			this._PanelContent.ResumeLayout(false);
			this.splitContainer1.Panel1.ResumeLayout(false);
			this.splitContainer1.Panel2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
			this.splitContainer1.ResumeLayout(false);
			this.mGroupBoxActiveConnections.ResumeLayout(false);
			this.mGroupBoxMessageLogs.ResumeLayout(false);
			this.mGroupBoxMiscLogs.ResumeLayout(false);
			this.ResumeLayout(false);
			this.PerformLayout();

		}
		#endregion

		private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
		{
			// Get DLL base name = assembly (full) name up to first comma.
			string desired = args.Name;
			string desiredWithCommaDelimiter = args.Name + ",";
			int indexOfComma = args.Name.IndexOf(',');
			if (indexOfComma != -1)
			{
				desired = args.Name.Substring(0, indexOfComma);
				desiredWithCommaDelimiter = args.Name.Substring(0, indexOfComma + 1);
			}
			// First see if we've already loaded a version of this assembly.
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				if (assemblies[i].FullName.StartsWith(desiredWithCommaDelimiter))
				{
					return assemblies[i];
				}
			}

			// Now try and load DLL embedded as a resource.
			Assembly mainAssembly = System.Reflection.Assembly.GetExecutingAssembly();
			string[] resources = mainAssembly.GetManifestResourceNames();
			Stream stream = mainAssembly.GetManifestResourceStream("GameTalkViewer.Assemblies." + desired + ".dll");
			if (stream == null) // There is a chance the requested dll is mixed-case, but that we've just put a lower case version of it in the embedded resources
				stream = mainAssembly.GetManifestResourceStream("GameTalkViewer.Assemblies." + desired.ToLower() + ".dll");
			if (stream != null)
			{
				byte[] bytes = new byte[stream.Length];
				stream.Read(bytes, 0, (int)stream.Length);
				stream.Close();
				return Assembly.Load(bytes);
			}

			// Try in the Microsoft.Net directory for primary interop
			string drive = Path.GetPathRoot(Environment.SystemDirectory);
			string path = drive + @"Program Files\Microsoft.NET\Primary Interop Assemblies\";
			if (File.Exists(path + desired + ".dll"))
			{
				return Assembly.LoadFile(path + desired + ".dll");
			}

			// No dice.
			return null;
		}

		private static void HandleCommandLineArguments(string[] args)
		{
			if (args.Length > 0)
			{
				if (args[0] == EA.GameTalkMessages.Configuration.RunServerAsAppCommandLineArgs)
					EA.GameTalkMessages.RegistrySettings.SetRegistryKeyAreaToCurrentUser();
			}
		}

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

			// Critical you don't invoke any GameTalkMessages methods in this method - as it will result in an immediate crash because .NET won't let the assumbly resolve (above) be registered
			HandleCommandLineArguments(args);

			// Run the application
			Application.EnableVisualStyles();
			Application.DoEvents();
			Application.Run(new GameTalkViewer());
		}

		#region Form Events

		private void GameTalkViewer_Load(object sender, System.EventArgs e)
		{
			this.Hide();
		}

		#endregion

		#region Notify Events

		private void UpdateChannelToIgnoreList()
		{
			mContextMenuFilterChannel.MenuItems.Clear();
			lock (mReceivedChannels)
			{
				for (int i = mReceivedChannels.Count - 1; (i >= 0) && (i >= (mReceivedChannels.Count - 10)); --i)
				{
					string channel = mReceivedChannels[i];
					EventHandler updateFilteredChannelsEventHandler = new EventHandler(UpdateFilteredChannels);
					MenuItem menuItem = new MenuItem(channel, updateFilteredChannelsEventHandler);
					menuItem.Checked = this.mChannelsToIgnore.Contains(channel);
					mContextMenuFilterChannel.MenuItems.Add(menuItem);
				}
			}
		}

		private void NotifyIcon_DoubleClick(object sender, System.EventArgs e)
		{
			// Show the window. Must be done first.
			this.Show();
			// When I double click on the GameTalkMonitor in the system tray - I want it to come to the front (regardless of whether it is already maximized)
			this.Activate();
			this.WindowState = FormWindowState.Normal;
			this.ShowInTaskbar = true;
		}

		#endregion

		#region Context Menu Events

		private void MenuItemShowViewer_Click(object sender, System.EventArgs e)
		{
			// Show the window. Must be done first.
			this.Show();

			this.WindowState = FormWindowState.Normal;
			this.ShowInTaskbar = true;
		}

		private void MenuItemStart_Click(object sender, System.EventArgs e)
		{
			PerfomServiceAction("start", "GameServer");
		}

		private void MenuItemStop_Click(object sender, System.EventArgs e)
		{
			PerfomServiceAction("stop", "GameServer");
		}

		private void RemoveGameTalkServer()
		{
			PerfomServiceAction("stop", "GameServer");
			PerfomServiceAction("delete", "GameServer");
		}

		private void MenuItemDelete_Click(object sender, System.EventArgs e)
		{
			string message = "Are you sure you want to delete the GameServer service?";
			DialogResult result = MessageBox.Show(message, "GameTalk Monitor", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
			if (DialogResult.Yes == result)
			{
				RemoveGameTalkServer();
				message = "GameServer service deleted.";
				MessageBox.Show(message, "GameTalk Monitor", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
		}

		private void MenuItemExit_Click(object sender, System.EventArgs e)
		{
			if (mNamedPipesReader != null)
				mNamedPipesReader.Active = false;
			else if (mFileIOReader != null)
				mFileIOReader.TimerEnabled = false;
			_NotifyIcon.Visible = false;
			this.Close();

			if ((mNamedPipesReader != null) && mNamedPipesReader.ThreadsAlive) // If the threads that are run by the NamedPipesReader aren't shut-down gracefully - this ensures the process is actually killed.  Once the code in the NamedPipesReader is a bit more asynchronous - we can remove this
				Environment.Exit(0);
		}

		private void PerfomServiceAction(string action, string serviceName)
		{
			try
			{
				ProcessStartInfo info = null;
				Process p = null;

				// Stop service if running
				info = new ProcessStartInfo();
				info.FileName = "sc.exe";
				info.Arguments = action + " " + serviceName;
				info.WorkingDirectory = Application.LocalUserAppDataPath;
				info.WindowStyle = ProcessWindowStyle.Hidden;
				p = Process.Start(info);
				p.WaitForExit();
			}
			catch { }
		}

		#endregion

		private void SuspendLayoutOfPanels()
		{
			mListViewConnections.SuspendLayout();
			mListViewMessages.SuspendLayout();
			mListViewMiscellanwousLog.SuspendLayout();
		}

		private void ResumeLayoutOfPanels()
		{
			mListViewMiscellanwousLog.ResumeLayout();
			mListViewConnections.ResumeLayout();
			mListViewMessages.ResumeLayout();
		}

		private bool HaveConnections()
		{
			if (mListViewConnections.Items.Count > 0)
			{
				// If necessary - switch the icon to show it as connected
				ShowSystemTrayIconAsConnected();
				return true;
			}
			else
			{
				// This will likely never happen - since as soon as the number of clients reaches zero, the server
				// will delete the files - in which case this will be caught at a higher level
				ShowNoClientsConnected(false);
				return false;
			}
		}

		public void ParseConfigurationLog(string line)
		{
			int startOfIpAddressTag = line.IndexOf(mConfigIpAddressTag);
			if (startOfIpAddressTag > -1)
			{
				int endOfIpAddressTag = startOfIpAddressTag + mConfigIpAddressTag.Length;
				if (endOfIpAddressTag < line.Length)
				{
					int startOfPortNumTag = line.IndexOf(mConfigPortNumTag);
					if (startOfPortNumTag > endOfIpAddressTag)
					{
						int endOfPortNumTag = startOfPortNumTag + mConfigPortNumTag.Length;
						if (endOfPortNumTag < line.Length)
						{
							mServerIpAddress = line.Substring(endOfIpAddressTag, startOfPortNumTag - endOfIpAddressTag).Trim();
							mServerPortNum = line.Substring(endOfPortNumTag).Trim();
						}
					}
				}
			}
		}

		private void ProcessMisc(string text)
		{
			string[] lines = text.Split('\n');
			foreach (string line in lines)
			{
				if (line.StartsWith(mCommentStartTag))
				{
					// Add to the message list
					ListViewItem item = new ListViewItem();
					item.Text = "Comment";
					item.SubItems.Add(line.Substring(mCommentStartTag.Length).Trim());
					mListViewMiscellanwousLog.Items.Add(item);
				}
				else if (line.StartsWith(mConfigurationTag))
					ParseConfigurationLog(line.Trim());
			}
		}

		private void ProcessMiscOnUiThread(string text)
		{
			mUISynchronizationContext.Send(new SendOrPostCallback(
				delegate(object state)
				{
					mListViewConnections.SuspendLayout();
					ProcessMisc(text);
					mListViewConnections.ResumeLayout();
				}
			), null);
		}

		private void ProcessMisc(byte[] miscBuffer)
		{
			if ((miscBuffer == null) || (miscBuffer.Length == 0))
				return;

			try
			{
				if (mListViewMiscellanwousLog.Items.Count > 500)
					mListViewMiscellanwousLog.Items.Clear();

				string text = System.Text.ASCIIEncoding.ASCII.GetString(miscBuffer);
				ProcessMisc(text);
			}
			catch
			{
				//MessageBox.Show("Error parsing log !!!" + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace);
			}
		}

		private void ProcessConnections(string text)
		{
			string[] lines = text.Split('\n');
			foreach (string line in lines)
			{
				if (line.StartsWith("Connection:"))
				{
					string[] s = line.Split(':');

					// Add to connection list
					ListViewItem item = new ListViewItem();
					item.Text = s[1].Trim() + ":" + s[2].Trim();
					item.SubItems.Add("<name>");
					item.SubItems.Add("<platform>");
					item.SubItems.Add("<version>");

					mListViewConnections.Items.Add(item);
				}
				else if (line.StartsWith("Disconnection:"))
				{
					string[] s = line.Split(':');
					string ipAddress = s[1].Trim() + ":" + s[2].Trim();

					// Removed from connection list
					ArrayList toDelete = new ArrayList();
					foreach (ListViewItem item in mListViewConnections.Items)
					{
						if (item.Text.Equals(ipAddress))
						{
							// Mark for deletion
							mListViewConnections.Items.Remove(item);
						}
					}
				}
				else if (line.StartsWith("TargetName:"))
				{
					string[] s = line.Split(':');
					string ipAddress = s[1].Trim() + ":" + s[2].Trim();

					// Update name
					foreach (ListViewItem item in mListViewConnections.Items)
					{
						if (item.Text.Equals(ipAddress))
						{
							item.SubItems[1].Text = s[3].Trim();
							// The greater than is added in case extra colon has been inserted somehow
							if (s.Length >= 6)
							{
								item.SubItems[2].Text = s[4].Trim();
								item.SubItems[3].Text = s[5].Trim();
							}
						}
					}
				}
			}
		}

		private void ProcessConnectionsOnUiThread(string text)
		{
			mUISynchronizationContext.Send(new SendOrPostCallback(
				delegate(object state)
				{
					mListViewConnections.SuspendLayout();
					ProcessConnections(text);
					if (mListViewConnections.Items.Count == 0)
						ShowNoClientsConnected(true);
					else if (mListViewConnections.Items.Count > 0)
						ShowSystemTrayIconAsConnected();
					mListViewConnections.ResumeLayout();
				}
			), null);
		}

		private void ProcessConnections(byte[] connectionsBuffer)
		{
			if ((connectionsBuffer == null) || (connectionsBuffer.Length == 0))
				return;

			try
			{
				string text = System.Text.ASCIIEncoding.ASCII.GetString(connectionsBuffer);
				ProcessConnections(text);
			}
			catch (Exception e)
			{
				MessageBox.Show("Error parsing log !!!" + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace);
			}
		}

		private void RegisterChannelInUi(string channelName)
		{
			lock (mReceivedChannels)
			{
				if (!mReceivedChannels.Contains(channelName))
					mReceivedChannels.Add(channelName);
			}
		}

		private void AddListViewItemToUi(ListViewItem item, string channel)
		{
			lock (mChannelsToIgnore)
			{
				if (!mChannelsToIgnore.Contains(channel))
					mListViewMessages.Items.Add(item);
			}
		}

		private void AddTrafficMessageToUi(ListViewItem item, string channel)
		{
			if (channel != null)
				AddListViewItemToUi(item, channel);
			else
				mListViewMessages.Items.Add(item);

			// I believe this is only being done so memory doesn't get over-inflated (i.e. endlessly keeping track of a huge list)
			if (mListViewItems.Count > MAX_LIST_VIEW_ITEMS) 
				mListViewItems.RemoveAt(0);

			mListViewItems.Add(item);
		}

		// Possible optimization (for bulk adds)
		//private ListViewItem AddMessageContent(ListViewItem item, string entireMessage, string[] messageData)
		private void AddMessageContent(ListViewItem item, string entireMessage, string[] messageData)
		{
			//ListViewItem listViewItemToReturn = null;
			// We want to preserve any colons in the message
			int startPosOfMessageContent = 0;
			string channel = null;
			// Should be at least four separators:
			// <direction>:<sender>:<target>:<channel>:<message>
			if ((mServerIsAtLeast2_8_0) && (messageData.Length >= 4) &&
				(!messageData[3].EndsWith("Full Message Bytes"))) // The last condition is to prevent coincidental parsing of the previous format
			{
				item.SubItems.Add(messageData[1].Trim()); // Sender
				item.SubItems.Add(messageData[2]); // Target
				channel = messageData[3]; // Channel

				RegisterChannelInUi(channel);

				item.SubItems.Add(channel);
				// The server is at least 2.8.0.0 - which means it logs sender and channel as well
				startPosOfMessageContent = messageData[0].Length + 1 + messageData[1].Length + 1 + messageData[2].Length + 1 + messageData[3].Length + 1;
			}
			else
			{
				// We're apparently using a new GameTalkMonitor with an old GameTalkServer - fill in a blank for the sender
				item.SubItems.Add(""); // Sender
				item.SubItems.Add(messageData[1].Trim()); // Target
				item.SubItems.Add(""); // Channel
				startPosOfMessageContent = messageData[0].Length + 1 + messageData[1].Length + 1;
			}

			if (startPosOfMessageContent < entireMessage.Length)
				item.SubItems.Add(entireMessage.Substring(startPosOfMessageContent).Trim());

			AddTrafficMessageToUi(item, channel);

			// Possible optimization (for bulk adds)
			/*
			if (channel != null)
			{
				lock (mChannelsToIgnore)
				{
					if (!mChannelsToIgnore.Contains(channel))
						listViewItemToReturn = item;
				}
			}
			else
				listViewItemToReturn = item;

			mListViewItems.Add(item);

			return listViewItemToReturn;*/
		}

		private bool ProcessTraffic(string text)
		{
			bool readLargeAmountOfData = false;
			string[] lines = text.Split('\n');
			int lineIndex = 0;
			if (lines.Length > MAX_LIST_VIEW_ITEMS_TO_DISPLAY)
			{
				// we just read a large amount of data into our trafficBuffer - we only want the last 100 messages
				readLargeAmountOfData = true;
				lineIndex = lines.Length - MAX_LIST_VIEW_ITEMS_TO_DISPLAY;
			}

			// Possible optimization (for bulk adds)
			//List<ListViewItem> listViewItems = new List<ListViewItem>();
			for (; lineIndex < lines.Length; lineIndex++)
			{
				string line = lines[lineIndex];
				string[] messageData = line.Split(':');
				// Don't try filtering out messages based on their channel here - they will have to be added to mListViewItems regardless
				if (line.StartsWith("MessageReceived:"))
				{
					// Add to the message list
					ListViewItem item = new ListViewItem();
					item.Text = "Received";
					// Possible optimization (for bulk adds)
					/*ListViewItem validItem = AddMessageContent(item, line, messageData);
					if (validItem != null)
						listViewItems.Add(validItem);*/
					AddMessageContent(item, line, messageData);
				}
				else if (line.StartsWith("MessageSent:"))
				{
					// Add to the message list
					ListViewItem item = new ListViewItem();
					item.Text = "Sent";
					// Possible optimization (for bulk adds)
					/*ListViewItem validItem = AddMessageContent(item, line, messageData);
					if (validItem != null)
						listViewItems.Add(validItem);*/
					AddMessageContent(item, line, messageData);
				}
			}

			// Possible optimization (for bulk adds)
			//mListViewMessages.Items.AddRange(listViewItems.ToArray());

			// This ensures the number of items never grows past 100
			int numItemsToRemove = mListViewMessages.Items.Count - MAX_LIST_VIEW_ITEMS_TO_DISPLAY;
			for (int i = 0; i < numItemsToRemove; i++)
				mListViewMessages.Items.RemoveAt(0);

			return readLargeAmountOfData;
		}

		private bool ProcessTrafficOnUiThread(string text)
		{
			bool readLargeAmountOfData = false;
			mUISynchronizationContext.Send(new SendOrPostCallback(
				delegate(object state)
				{
					mListViewConnections.SuspendLayout();
					readLargeAmountOfData = ProcessTraffic(text);
					mListViewConnections.ResumeLayout();
				}
			), null);

			return readLargeAmountOfData;
		}

		private bool ProcessTraffic(byte[] trafficBuffer)
		{
			bool readLargeAmountOfData = false;
			if ((trafficBuffer == null) || (trafficBuffer.Length == 0))
				return readLargeAmountOfData;

			try
			{
				string text = System.Text.ASCIIEncoding.ASCII.GetString(trafficBuffer);
				readLargeAmountOfData = ProcessTraffic(text);
			}
			catch
			{
				//MessageBox.Show("Error parsing log !!!" + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace);
			}

			return readLargeAmountOfData;
		}

		private void ShowNoClientsConnected(bool clearMiscListBox)
		{
			mListViewConnections.Items.Clear();
			mListViewMessages.Items.Clear();
			if (clearMiscListBox)
				mListViewMiscellanwousLog.Items.Clear();
			// If necessary - switch the icon to show it as disconnected
			if (_NotifyIcon.Icon != _IconIdle)
			{
				_NotifyIcon.Icon = _IconIdle;
				this.Invalidate(true);
			}
		}

		private void ShowSystemTrayIconAsConnected()
		{
			if (_NotifyIcon.Icon != _IconConnected)
			{
				_NotifyIcon.Icon = _IconConnected;
				this.Invalidate(true);
			}
		}


		#region Assembly Management

		/// <summary>
		/// Create a file from the resource speficied
		/// </summary>
		/// <param name="resourceName">The resource name to use</param>
		/// <param name="fileName">The file name to write the resource to file</param>
		static private void CreateFileFromResource(string resourceName, string fileName)
		{
			try
			{
				// Create path if it doesn't exists
				string path = Path.GetDirectoryName(fileName);
				if (!Directory.Exists(path))
				{
					Directory.CreateDirectory(path);
				}

				Assembly asm = Assembly.GetExecutingAssembly();
				Stream stream = asm.GetManifestResourceStream(resourceName);
				BinaryReader reader = new BinaryReader(stream);

				FileStream fileStream = null;
				try
				{
					fileStream = File.Open(fileName, FileMode.Create, FileAccess.Write);
					BinaryWriter writer = new BinaryWriter(fileStream);

					try
					{
						writer.Write(reader.ReadBytes((int)stream.Length));
						writer.Flush();
					}
					catch (Exception e)
					{
						Trace.WriteLine(e.Message);
					}
				}
				catch (Exception e)
				{
					Trace.WriteLine(e.Message);
				}
				finally
				{
					if (fileStream != null)
					{
						fileStream.Close();
					}
				}
			}
			catch (Exception e)
			{
				Trace.WriteLine(e.Message);
			}
		}

		#endregion

		#region Toolbar Events

		private void UpdateFilteredChannels(object sender, EventArgs eventArgs)
		{
			if (!(sender is MenuItem))
				return;

			MenuItem clickedMenuItem = (MenuItem)sender;
			clickedMenuItem.Checked = !clickedMenuItem.Checked;
			if (clickedMenuItem.Checked)
			{
				lock (mChannelsToIgnore)
					mChannelsToIgnore.Add(clickedMenuItem.Text);
			}
			else
			{
				lock (mChannelsToIgnore)
					mChannelsToIgnore.Remove(clickedMenuItem.Text);
			}

			mListViewMessages.Items.Clear();
			foreach (ListViewItem listViewItem in mListViewItems)
			{
				AddListViewItemToUi(listViewItem, listViewItem.SubItems[3].Text);
				if (mListViewMessages.Items.Count >= MAX_LIST_VIEW_ITEMS_TO_DISPLAY)
					break;
			}
		}

		private void ToolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			switch (e.Button.Text)
			{
				case "Target Manager":
					TargetManagerDialog dialog = new TargetManagerDialog();
					dialog.ShowDialog();
					break;
				case "Refresh":
					if (!Configuration.Instance.UseNamedPipes)
					{
						if (mFileIOReader != null)
							mFileIOReader.ProcessFileContent();
					}
					break;
				case "Close":
					// Hide the window
					this.ShowInTaskbar = false;
					this.Hide();
					break;
				case "Clear":
				case "Clear Logs":
					mListViewMessages.Items.Clear();

					if (mListViewMiscellanwousLog.Items.Count > 500)
						mListViewMiscellanwousLog.Items.Clear();
					break;
				case "Filter Channels":
				case "Remove Messages on Channel":
					break;
			}
		}

		#endregion

		#region Form Events
		private static bool IsRequiredGreaterOrEqualToRequestedVersion(string requiredVersionStr, string currentVersionStr)
		{
			bool currentVersionIsGreater = false;
			if (currentVersionStr == null)
				return currentVersionIsGreater;

			try
			{
				string[] currentVersion = currentVersionStr.Split('.');
				string[] requiredVersion = requiredVersionStr.Split('.');
				int currentMajor = int.Parse(currentVersion[0]);
				int requiredMajor = int.Parse(requiredVersion[0]);
				int currentMinor = int.Parse(currentVersion[1]);
				int requiredMinor = int.Parse(requiredVersion[1]);

				int currentRevision = int.Parse(currentVersion[2]);
				int requiredRevision = int.Parse(requiredVersion[2]);
				// In case we want to make greater than decisions based on build
				/*int currentBuild = int.Parse(currentVersion[3]);
				int requiredBuild = int.Parse(requiredVersion[3]);*/
				if (!currentVersionIsGreater)
				{
					currentVersionIsGreater = (currentMajor > requiredMajor);
					if (!currentVersionIsGreater)
					{
						currentVersionIsGreater = (currentMajor == requiredMajor) && (currentMinor > requiredMinor);
						if (!currentVersionIsGreater)
							currentVersionIsGreater = (currentMajor == requiredMajor) && (currentMinor == requiredMinor)
	&& (currentRevision >= requiredRevision);
					}
				}
			}
			catch { }

			return currentVersionIsGreater;
		}

		private void GameTalkViewer_VisibleChanged(object sender, System.EventArgs e)
		{
			try
			{
				string installedVersion = Configuration.Instance.GetInstalledGameTalkVersion();
				if (installedVersion != null)
				{
					mServerVersionStr = installedVersion;
					if ((mServerVersionStr != null) &&
						(GameTalkViewer.IsRequiredGreaterOrEqualToRequestedVersion("2.8.0.0", mServerVersionStr)))
						mServerIsAtLeast2_8_0 = true;
					else
						mServerIsAtLeast2_8_0 = false;

					this._StatusBar.Text = "Running Server " + mServerVersionStr;
					if ((!string.IsNullOrEmpty(mServerIpAddress)) && (!string.IsNullOrEmpty(mServerPortNum)))
						_StatusBar.Text += " [" + mServerIpAddress + ":" + mServerPortNum + "]";
					if ((!string.IsNullOrEmpty(mServerPortNum)) && (mServerPortNum != "9876")) // Alert the user that their GameTalkServer is on a port other than 9876
						this.BackColor = Color.Salmon;
					else
						this.BackColor = Color.FromName("Control");
				}
			}
			catch { }
		}

		#endregion

		#region Refresh Rate Menu Events

		private void SetTimer(MenuItem menuItem)
		{
			foreach (MenuItem m in _ContextMenuRefreshRate.MenuItems)
			{
				m.Checked = false;
			}
			menuItem.Checked = true;

			switch (menuItem.Text)
			{
				case "Fast":
					if (mFileIOReader != null)
						mFileIOReader.TimerInterval = 100;
					break;
				case "Medium":
					if (mFileIOReader != null)
						mFileIOReader.TimerInterval = 500;
					break;
				case "Slow":
					if (mFileIOReader != null)
						mFileIOReader.TimerInterval = 1000;
					break;
				default: // This handles the "Never" case
					if (mFileIOReader != null)
						mFileIOReader.TimerEnabled = false;
					break;
			}
		}

		#endregion

		private void RefreshMenuItem_Click(object sender, System.EventArgs e)
		{
			SetTimer(sender as MenuItem);
		}

		private void _CapLogFileSizeMenuItem_Click(object sender, EventArgs e)
		{
			_DoNotCapLogFileSizeMenuItem.Checked = false;
			_CapLogFileSizeMenuItem.Checked = true;
			Configuration.Instance.SetLimitOnLogFileSize(true);
		}

		private void _DoNotCapLogFileSizeMenuItem_Click(object sender, EventArgs e)
		{
			_DoNotCapLogFileSizeMenuItem.Checked = true;
			_CapLogFileSizeMenuItem.Checked = false;
			Configuration.Instance.SetLimitOnLogFileSize(false);
		}

		private void mDoNotParseMessageMenuItem_Click(object sender, EventArgs e)
		{
			mParseMessageMenuItem.Checked = false;
			mDoNotParseMessageMenuItem.Checked = true;
			mDoNotDisplayMessagesMenuItem.Checked = false;
			Configuration.Instance.SetLoggingLevel(LoggingLevel.META_DATA);
		}

		private void mParseMessageMenuItem_Click(object sender, EventArgs e)
		{
			mParseMessageMenuItem.Checked = true;
			mDoNotParseMessageMenuItem.Checked = false;
			mDoNotDisplayMessagesMenuItem.Checked = false;
			Configuration.Instance.SetLoggingLevel(LoggingLevel.FULL_LOGGING);
		}

		private void mDoNotDisplayMessagesMenuItem_Click(object sender, EventArgs e)
		{
			mParseMessageMenuItem.Checked = false;
			mDoNotParseMessageMenuItem.Checked = false;
			mDoNotDisplayMessagesMenuItem.Checked = true;
			Configuration.Instance.SetLoggingLevel(LoggingLevel.NO_MESSAGE_LOGGING);
		}

		private void mMenuItemDeleteFileTalk_Click(object sender, EventArgs e)
		{
			string message = "Are you sure you want to delete the FileTalk service?";
			DialogResult result = MessageBox.Show(message, "GameTalk Monitor", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
			if (DialogResult.Yes == result)
			{
				PerfomServiceAction("stop", "FileTalkServer");
				PerfomServiceAction("delete", "FileTalkServer");

				message = "FileTalk service deleted.";
				MessageBox.Show(message, "GameTalk Monitor", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
		}

		/// <summary>
		/// If we can find a "nice" way to shut-down the GameTalkMonitor (other than Process.Kill)
		/// this method should set the icon in the system tray to not visible
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void GameTalkViewer_FormClosing(object sender, FormClosingEventArgs e)
		{
			// To address MS bug or "feature":
			// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=98317
			_NotifyIcon.Visible = false;
		}

		private void mMenuItemStartFileTalk_Click(object sender, EventArgs e)
		{
			PerfomServiceAction("start", "FileTalkServer");
		}

		private void mMenuItemStopFileTalk_Click(object sender, EventArgs e)
		{
			PerfomServiceAction("stop", "FileTalkServer");
		}

		private void mContextMenuFilterChannel_Popup(object sender, EventArgs e)
		{
			this.UpdateChannelToIgnoreList();
		}

		private void mListViewMessages_RegionChanged(object sender, EventArgs e)
		{
			Trace.WriteLine("mListViewMessages_RegionChanged");
		}

		private void mListViewMessages_DrawItem(object sender, DrawListViewItemEventArgs e)
		{
			Trace.WriteLine("mListViewMessages_DrawItem");
		}

		private void CopyTextFromListViewIntoClipboard(ListView listView)
		{
			if (listView.SelectedItems.Count == 0)
				return;

			if (listView.SelectedItems[0].SubItems.Count == 0)
				return;

			int numSubItems = listView.SelectedItems[0].SubItems.Count;
			int[] longestStringByColumn = new int[numSubItems];
			int subItemIndex = 0;
			// Determine the longest string in each column (across all rows) - each element of longestStringByColumn will contain the length of the longest string for that column
			foreach (ListViewItem listViewItem in listView.SelectedItems)
			{
				subItemIndex = 0;
				foreach (ListViewItem.ListViewSubItem listViewSubItem in listViewItem.SubItems)
				{
					if ((longestStringByColumn.Length > subItemIndex) &&
						(longestStringByColumn[subItemIndex] < listViewSubItem.Text.Length))
						longestStringByColumn[subItemIndex] = listViewSubItem.Text.Length;

					++subItemIndex;
				}
			}
			StringBuilder listViewText = new StringBuilder();
			// Generate a line of text for each row - adding spaces to line up each column of text
			foreach (ListViewItem listViewItem in listView.SelectedItems)
			{
				subItemIndex = 0;
				foreach (ListViewItem.ListViewSubItem listViewSubItem in listViewItem.SubItems)
				{
					listViewText.Append(listViewSubItem.Text);
					int numSpaces = longestStringByColumn[subItemIndex] - listViewSubItem.Text.Length;
					if (numSpaces > 0)
						listViewText.Append(' ', numSpaces);
					listViewText.Append("|");

					++subItemIndex;
				}
				listViewText.Append(Environment.NewLine);
			}
			Clipboard.SetText(listViewText.ToString());
		}

		private void mListViewMessages_KeyDown(object sender, KeyEventArgs e)
		{
			if ((e.KeyCode == Keys.C) && (e.Control))
			{
				CopyTextFromListViewIntoClipboard(mListViewMessages);
				e.Handled = true;
			}
		}

		private void mListViewMiscellanwousLog_KeyDown(object sender, KeyEventArgs e)
		{
			if ((e.KeyCode == Keys.C) && (e.Control))
			{
				CopyTextFromListViewIntoClipboard(mListViewMiscellanwousLog);
				e.Handled = true;
			}

		}

		private void _MenuItemShutdownBasedOnNetwork_Click(object sender, EventArgs e)
		{
			_MenuItemShutdownBasedOnNetwork.Checked = true;
			_MenuItemNoShutdownIfNetworkLost.Checked = false;
			Configuration.Instance.SetCheckNetworkConnectivity(true);
		}

		private void _MenuItemNoShutdownIfNetworkLost_Click(object sender, EventArgs e)
		{
			_MenuItemShutdownBasedOnNetwork.Checked = false;
			_MenuItemNoShutdownIfNetworkLost.Checked = true;
			Configuration.Instance.SetCheckNetworkConnectivity(false);
		}

		private void RemoveServerAndNotifyUser()
		{
			// If we wanted to try a more dangerous approach - instead of completely uninstalling and reinstalling the GameTalkServer - we could just stop it and then update this key:
			// HKLM\System\CurrentControlSet\Services\GameServer\ImagePath
			// and then start the GameTalkServer again.  I'm just worried that this is akin to hacking a Windows service.. so not sure if it is safe
			RemoveGameTalkServer();
			// If the GameTalkServer is running as an application - we'll need to kill the process (instead of just stopping the service) - the crappy thing about this is that the Server isn't given a chance to clear the logs
			// In some future update - we'll want to change the following into signalling to the GameTalkServer (running as an application) that it should shut-down gracefully (possibilities include - writing a file, updating a RegistryKey, etc)
			try
			{
				Process gameTalkServerProcess = Configuration.Instance.GameTalkServerRunningAsApplication();
				if ((gameTalkServerProcess != null) && (!gameTalkServerProcess.HasExited))
					gameTalkServerProcess.Kill();
			}
			catch { }

			string message = "GameTalk configuration updated!  You'll need to start a GameTalk enabled application for the changes to take effect.";
			MessageBox.Show(message, "GameTalk Monitor", MessageBoxButtons.OK, MessageBoxIcon.Information);
		}

		private void ChangeGameTalkServerExecutableTo32Bit(bool use32Bit)
		{
			Configuration.Instance.Use32BitGameTalkServer = use32Bit;
			UpdateWhichBitSizeServerToUse();

			RemoveServerAndNotifyUser();
		}

		private void _MenuItemUse64BitServer_Click(object sender, EventArgs e)
		{
			ChangeGameTalkServerExecutableTo32Bit(false);
		}

		private void _MenuItemUse32BitServer_Click(object sender, EventArgs e)
		{
			ChangeGameTalkServerExecutableTo32Bit(true);
		}

		private void UpdateLogging(bool useNamedPipes)
		{
			Configuration.Instance.UseNamedPipes = useNamedPipes;
			UpdateNamedPipesMenuItems();
			RemoveServerAndNotifyUser();
		}

		private void _MenuItemClassicFileIO_Click(object sender, EventArgs e)
		{
			UpdateLogging(false);
		}

		private void _MenuItemNamedPipes_Click(object sender, EventArgs e)
		{
			UpdateLogging(true);
		}

		#region LogManager - strictly intended for debugging
		public class LogManager : TraceListener
		{
			private XmlTextWriter mWriter = null;
			//Format date such that it is acceptable to the windows file system
			private string mLoggingFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"GameTalkServer") + "\\" + DateTime.Now.ToString("[dd-MMMM-yyyy]hh-mm-ss") + ".log";

			public override void WriteLine(string text)
			{
				try
				{
					// Since this is called so frequently we may want to consider allowing multiple concurrent
					// writes to the log files instead of potentially blocking at this point
					if (mWriter == null)
					{
						String dateStringFormatted = DateTime.Now.ToString("[dd-MMMM-yyyy]hh-mm-ss");
						try
						{
							FileStream fileStream = new FileStream(mLoggingFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
							// Create the writer
							mWriter = new XmlTextWriter(fileStream, System.Text.Encoding.UTF8);

							mWriter.Formatting = Formatting.Indented;
							mWriter.IndentChar = '\t';
							mWriter.Indentation = 1;

							// Begin the document
							mWriter.WriteStartDocument();
							mWriter.WriteStartElement("Logging");
						}
						catch
						{
						}
					}
					else
					{
						mWriter.WriteStartElement("LogEntry");
						mWriter.WriteAttributeString("time", DateTime.Now.ToString());
						mWriter.WriteString(text);
						mWriter.WriteEndElement();
					}
				}
				catch { }
			}

			public override void Write(string text)
			{
				//DebugConsoleControl.Write(text);
			}
		}
		#endregion
	}
}
