using System;
using System.Collections.Generic;
using System.Text;
using EA.GameTalk;
using EA.FileTalk;

namespace FileTalkInstaller
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.Out.WriteLine("FileTalk Installer started");
			GameTalkManager.Instance.Initialize("FileTalk.Installer", System.Net.Dns.GetHostName(), "PC");
			Console.Out.WriteLine("GameTalk initialized");
			FileTalkManager.Instance.Initialize(GameTalkManager.Instance);
			Console.Out.WriteLine("FileTalk initialized");

			bool clientRootPathSet = false;
			for (int i = 0; i < args.Length; i++)
			{
				if (args[i] == "-ClientRoot")
				{
					if (args.Length >= (i + 3))
					{
						string clientName = args[i + 1];
						string filePathRoot = args[i + 2];
						GameTalkManager.Instance.StartBuffering(clientName, 1, false);
						FileTalkManager.Instance.SetFileRootForClient(clientName, filePathRoot);
						Console.Out.WriteLine("Set file path root " + filePathRoot + " for client " + clientName + " with FileTalkServer");
						i += 2;
						clientRootPathSet = true;
					}
				}
				else
				{
					Console.Out.WriteLine("Usage: FileTalkInstaller -ClientRoot \"<client name>\" \"<file path root>\"");
				}
			}

			if (clientRootPathSet)
			{
				Console.Out.WriteLine("All client file path roots have been registered with the FileTalkServer");
				Console.Out.WriteLine("Client file path roots will remain set in FileTalkServer until either:");
				Console.Out.WriteLine("A) The FileTalkServer is reset, OR");
				Console.Out.WriteLine("B) A client invokes FileTalkManager.RemoveFileRootForClient");
				Console.Out.WriteLine("C) A client invokes FileTalkManager.SetFileRootForClient and overrides the existing file path root");
			}

			FileTalkManager.Instance.ReleaseInstance();
			GameTalkManager.Instance.Shutdown();

			Environment.Exit(0);
		}
	}
}
