//public AddWindow()
 //{
 //    InitializeComponent();
 //}
 public AddWindow(Tree tree)
 {
     InitializeComponent();
     this.tree = tree;
 }
        /// <summary>
        /// Parses a tree.cfg file into a Tree class
        /// </summary>
        /// <param name="path">Full path to tree.cfg</param>
        /// <returns>A Tree class with Nodes corresponding the tree.cfg data</returns>
        private Tree Load(string path)
        {
            var treeString = "";
            using (var reader = new StreamReader(path))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    treeString = treeString + line + Environment.NewLine;
                }
            }

            var tree = new Tree(path);
            var nodes = tree.Nodes;
            var n = 0;
            var b = false;
            foreach (var str in Regex.Split(treeString, Environment.NewLine))
            {
                switch (str.Trim())
                {
                    case "{":
                        n += 1;
                        b = true;
                        break;
                    case "}":
                        n -= 1;
                        break;
                }

                switch (n)
                {
                    case 1:
                        if (b) { nodes.Add(new Node()); nodes.Last().Parts = new List<Attribute>(); }
                        if (str.Contains('=') == false)
                            break;

                        var ss = new Attribute(str.Trim());
                        switch (ss.Item)
                        {
                            case "name":
                                nodes.Last().Name.Value = ss.Value;
                                break;
                            case "techID":
                                nodes.Last().TechId.Value = ss.Value;
                                break;
                            case "pos":
                                nodes.Last().Pos.Value = ss.Value;
                                break;
                            case "icon":
                                nodes.Last().Icon.Value = ss.Value;
                                break;
                            case "cost":
                                nodes.Last().Cost.Value = ss.Value;
                                break;
                            case "title":
                                nodes.Last().Title.Value = ss.Value;
                                break;
                            case "description":
                                nodes.Last().Description.Value = ss.Value;
                                break;
                            case "anyParent":
                                nodes.Last().AnyParent.Value = ss.Value;
                                break;
                            case "hideIfEmpty":
                                nodes.Last().HideIfEmpty.Value = ss.Value;
                                break;
                            case "parents":
                                nodes.Last().Parents.Value = ss.Value;
                                break;
                        }
                        break;
                    case 2:
                        if (str.Contains('=') == false)
                            break;

                        nodes.Last().Parts.Add(new Attribute(str.Trim()));
                        break;
                }
                b = false;
            }
            return tree;
        }
 public void Restore(string backupFile)
 {
     Tree = Load(backupFile);
     Tree.FilePath = Path;
     Save();
 }
 private void InitialiseTree()
 {
     _tp = new TreeParser(_treeFile);
     _tree = _tp.Tree;
 }