
using System.Collections.Specialized;
using System.Web.Configuration;
namespace Sex
{
    public partial class Sex : System.Web.UI.Page
    {
        public class State
        {
            public bool UseLogin = true;
            public string Password = "SEXy";
            public bool DynamicLoadTree = false;
            public bool AutocloseTree = true;
            public int ThumbDimension = 200;
            public int ThumbCols = 3;
            public int MaxLineLength = 27;
            public int MaxLineCount = 10;
            public string RelativePath = "../";
            public string UrlJsHighlight = "http://alexgorbatchev.com/pub/sh/current/";
            public string[] IpsAllowed = new string[]
            {
                "127.0.0.1",  // localhost
                "192.168.0.107", // host in private network
                "86.59.41.251" // public host
            };

            public string OwnFile = "";
            public string RootDirFullName = "";
            public string CurrentPathRel = "";
            public string CurrentPathAbs = "";
            public E_ObjectType CurrentItemType = E_ObjectType.DIRECTORY;
            public string CurrentIcon = "";
            public string CurrentBrush = "";
            public FileGroup.Type CurrentType = FileGroup.Type.OTHER;
            public string CurrentFile = "";
            public string CurrentServer = "";
            public bool UserAccepted = false;
            public int CurrentTemplate = -1;
            public string[] RelativePathComponents = new string[] { };
            public string ApplicationPath = "/";

            public State()
            {
                // from web.config
                NameValueCollection nvc = WebConfigurationManager.AppSettings;
                UseLogin = bool.Parse(nvc["UseLogin"]);
                Password = nvc["Password"];
                DynamicLoadTree = bool.Parse(nvc["DynamicLoadTree"]);
                AutocloseTree = bool.Parse(nvc["AutocloseTree"]);
                ThumbDimension = int.Parse(nvc["ThumbDimension"]);
                ThumbCols = int.Parse(nvc["ThumbCols"]);
                MaxLineLength = int.Parse(nvc["MaxLineLength"]);
                MaxLineCount = int.Parse(nvc["MaxLineCount"]);
                RelativePath = nvc["RelativePath"];
                UrlJsHighlight = nvc["UrlJsHighlight"];
                IpsAllowed = nvc["IpsAllowed"].Split(new char[] { ',' });
            }
 
            public State(System.Web.UI.StateBag v)
            {
                UseLogin = (bool)v["UseLogin"];
                Password = (string)v["Password"];
                DynamicLoadTree = (bool)v["DynamicLoadTree"];
                AutocloseTree = (bool)v["AutocloseTree"];
                ThumbDimension = (int)v["ThumbDimension"];
                ThumbCols = (int)v["ThumbCols"];
                MaxLineLength = (int)v["MaxLineLength"];
                MaxLineCount = (int)v["MaxLineCount"];
                RelativePath = (string)v["RelativePath"];
                UrlJsHighlight = (string)v["UrlJsHighlight"];
                IpsAllowed = (string[])v["IpsAllowed"];
                // 
                OwnFile = (string)v["OwnFile"];
                RootDirFullName = (string)v["RootDirFullName"];
                CurrentPathRel = (string)v["CurrentPathRel"];
                CurrentPathAbs = (string)v["CurrentPathAbs"];
                CurrentItemType = (E_ObjectType)v["CurrentItemType"];
                CurrentIcon = (string)v["CurrentIcon"];
                CurrentBrush = (string)v["CurrentBrush"];
                CurrentType = (FileGroup.Type)v["CurrentType"];
                CurrentFile = (string)v["CurrentFile"];
                CurrentServer = (string)v["CurrentServer"];
                UserAccepted = (bool)v["UserAccepted"];
                CurrentTemplate = (int)v["CurrentTemplate"];
                RelativePathComponents = (string[])v["RelativePathComponents"];
                ApplicationPath = (string)v["ApplicationPath"];
            }
            public void SaveState(System.Web.UI.StateBag v)
            {
                v.Add("UseLogin", UseLogin);
                v.Add("Password", Password);
                v.Add("DynamicLoadTree", DynamicLoadTree);
                v.Add("AutocloseTree", AutocloseTree);
                v.Add("ThumbDimension", ThumbDimension);
                v.Add("ThumbCols", ThumbCols);
                v.Add("MaxLineLength", MaxLineLength);
                v.Add("MaxLineCount", MaxLineCount);
                v.Add("UrlJsHighlight", UrlJsHighlight);
                v.Add("RelativePath", RelativePath);
                v.Add("IpsAllowed", IpsAllowed);

                v.Add("OwnFile", OwnFile);
                v.Add("RootDirFullName", RootDirFullName);
                v.Add("CurrentPathRel", CurrentPathRel);
                v.Add("CurrentPathAbs", CurrentPathAbs);
                v.Add("CurrentItemType", CurrentItemType);
                v.Add("CurrentIcon", CurrentIcon);
                v.Add("CurrentBrush", CurrentBrush);
                v.Add("CurrentType", CurrentType);
                v.Add("CurrentFile", CurrentFile);
                v.Add("CurrentServer", CurrentServer);
                v.Add("UserAccepted", UserAccepted);
                v.Add("CurrentTemplate", CurrentTemplate);
                v.Add("RelativePathComponents", RelativePathComponents);
                v.Add("ApplicationPath", ApplicationPath);
            }
        }
    }
}