using System;
using System.IO;
using Microsoft.Win32;
using Server;

namespace Server.Misc
{
	public class DataPath
	{
		private static string CustomPath = "Data/Files";

		public static void Configure()
		{
			if ( CustomPath != null ) 
				Core.DataDirectories.Add( CustomPath ); 

			if ( Core.DataDirectories.Count == 0 && !Core.Service )
			{
				Console.WriteLine( "Enter the Ultima Online directory:" );
				Console.Write( "> " );

				Core.DataDirectories.Add( Console.ReadLine() );
			}
		}

		private static string GetPath( string subName, string keyName )
		{
			try
			{
				string keyString;

				if( Core.Is64Bit )
					keyString = @"SOFTWARE\Wow6432Node\{0}";
				else
					keyString = @"SOFTWARE\{0}";

				using( RegistryKey key = Registry.LocalMachine.OpenSubKey( String.Format( keyString, subName ) ) )
				{
					if( key == null )
						return null;

					string v = key.GetValue( keyName ) as string;

					if( String.IsNullOrEmpty( v ) )
						return null;

					if ( keyName == "InstallDir" )
						v = v + @"\";

					v = Path.GetDirectoryName( v );

					if ( String.IsNullOrEmpty( v ) )
						return null;

					return v;
				}
			}
			catch
			{
				return null;
			}
		}
	}
}
