using System;

namespace baoge.Admin
{
	/// <summary>
	/// FTP 的摘要说明。
	/// </summary>
	public class FTP
	{
		public FTP()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		public static string getParentDirectory()
		{	
			// this function works for /main/db/test/ as well as /main/db/test.aspx
			System.Web.HttpContext context = System.Web.HttpContext.Current;
			string path = context.Session["Path"].ToString();
			if(path == "./")
				return("../");	// trivial, no string manipulation required
			else if(path == "/")
				return("/");	// can't go higher than root
			else
			{
				// remove trailing "/" at end of path
				if(path.LastIndexOf("/") == path.Length-1)
				{	
					path = path.Remove(path.LastIndexOf("/"), (path.Length - path.LastIndexOf("/")));
				}
				try
				{
					// remove the characters after the last occurence of / in the string. => parent directory
					path = path.Remove(path.LastIndexOf("/"), (path.Length - path.LastIndexOf("/")));
					return(path + "/");
				}
				catch(ArgumentOutOfRangeException ex)
				{
					return("/");	// default to root;
				}
			}
		}
		public static void ReportError(string problem, string tech, string suggestion)
		{
			// outputs error, in english, and in tech, and with any suggestions.
			System.Web.HttpContext context = System.Web.HttpContext.Current;
			string output = "<font color=red><BIG>Problem:</BIG> " + problem + "</font><hr>";
			output += "Suggestion: " + suggestion + "<hr>";
			output += "<small>Technical details: " + tech + "</small><hr>";
			context.Response.Write(output);
		}
	}
}
