Esempio n. 1
0
 private List <string> FindPath(SavedRouteItem route, SavedRouteGroup rootNode = null)
 {
     if (rootNode == null)
     {
         rootNode = (SavedRouteGroup)Nodes[0];
     }
     foreach (SavedRouteNode node in rootNode.Nodes)
     {
         if (node is SavedRouteItem)
         {
             SavedRouteItem item = (SavedRouteItem)node;
             if (item.IPVersion == route.IPVersion)
             {
                 if (item.Destination == route.Destination)
                 {
                     if (item.Prefix == route.Prefix)
                     {
                         if (item.Gateway == route.Gateway)
                         {
                             if (item.InterfaceGuid == route.InterfaceGuid)
                             {
                                 return(new List <string>(new string[] { rootNode.Name, item.Name }));
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             SavedRouteGroup group        = (SavedRouteGroup)node;
             List <string>   relativePath = FindPath(route, group);
             if (relativePath != null)
             {
                 return(new List <string>(new string[] { rootNode.Name }).Concat(relativePath).ToList());
             }
         }
     }
     return(null);
 }
Esempio n. 2
0
 private List<string> FindPath(SavedRouteItem route, SavedRouteGroup rootNode = null)
 {
     if (rootNode == null)
         rootNode = (SavedRouteGroup)Nodes[0];
     foreach (SavedRouteNode node in rootNode.Nodes)
     {
         if (node is SavedRouteItem)
         {
             SavedRouteItem item = (SavedRouteItem)node;
             if (item.IPVersion == route.IPVersion)
                 if (item.Destination == route.Destination)
                     if (item.Prefix == route.Prefix)
                         if (item.Gateway == route.Gateway)
                             if (item.InterfaceGuid == route.InterfaceGuid)
                                 return new List<string>(new string[] { rootNode.Name, item.Name });
         }
         else
         {
             SavedRouteGroup group = (SavedRouteGroup)node;
             List<string> relativePath = FindPath(route, group);
             if (relativePath != null)
                 return new List<string>(new string[] { rootNode.Name }).Concat(relativePath).ToList();
         }
     }
     return null;
 }
Esempio n. 3
0
        public static void Load()
        {
            Config currentConfig;
            if (File.Exists("Network_Manager.xml"))
            {
                try
                {
                    XmlSerializer reader = new XmlSerializer(typeof(Config));
                    using (StreamReader file = new StreamReader("Network_Manager.xml"))
                    {
                        currentConfig = (Config)reader.Deserialize(file);
                        //Config defaultConfig = new Config();
                        //currentConfig = (Config)CheckIfNull(typeof(Config), currentConfig, defaultConfig); // not needed, XML does a nice job
                    }
                }
                catch
                {
                    DialogResult result = MessageBox.Show("Configuration file was corrupted.\n\nDo you want to reset it to default and lose all configurations?", "Config File Corrupted", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.ServiceNotification);
                    if (result == DialogResult.No)
                        Global.Exit();
                    currentConfig = new Config();
                    File.Delete("Network_Manager.xml");
                }
            }
            else
                currentConfig = new Config();
            // load defaults if null
            if (currentConfig.SavedRoutes.Nodes.Count == 0)
            {
                currentConfig.SavedRoutes.Nodes.Add(new SavedRouteGroup());
                currentConfig.SavedRoutes.Nodes[0].Name = "<Root Group>";
            }
            if (currentConfig.InterfaceProfiles.Count == 0)
            {
                InterfaceProfile profile = new InterfaceProfile();
                profile.Name = "Google DNS";
                profile.IPv4DnsAddresses.Add("8.8.8.8");
                profile.IPv4DnsAddresses.Add("8.8.4.4");
                profile.IPv6DnsAddresses.Add("2001:4860:4860::8888");
                profile.IPv6DnsAddresses.Add("2001:4860:4860::8844");
                currentConfig.InterfaceProfiles.Add(profile);
                profile = new InterfaceProfile();
                profile.Name = "Comodo Secure DNS";
                profile.IPv4DnsAddresses.Add("8.26.56.26");
                profile.IPv4DnsAddresses.Add("8.20.247.20");
                currentConfig.InterfaceProfiles.Add(profile);
                profile = new InterfaceProfile();
                profile.Name = "OpenDNS";
                profile.IPv4DnsAddresses.Add("208.67.222.222");
                profile.IPv4DnsAddresses.Add("208.67.220.220");
                profile.IPv6DnsAddresses.Add("2620:0:ccc::2");
                profile.IPv6DnsAddresses.Add("2620:0:ccd::2");
                currentConfig.InterfaceProfiles.Add(profile);
            }
            if (currentConfig.LoadBalancer.IPv4LocalAddresses.Count == 0)
                currentConfig.LoadBalancer.IPv4LocalAddresses.Add(new NetworkInterface.IPHostAddress("192.168.200.2", "255.255.255.0"));
            if (currentConfig.LoadBalancer.IPv4GatewayAddresses.Count == 0)
                currentConfig.LoadBalancer.IPv4GatewayAddresses.Add(new NetworkInterface.IPGatewayAddress("192.168.200.1", 1));
            if (currentConfig.LoadBalancer.IPv4DnsAddresses.Count == 0)
                currentConfig.LoadBalancer.IPv4DnsAddresses.Add("8.8.8.8");
            // legacy upgrade support
            if (File.Exists("Network_Manager.ini"))
            {
                // recover Gadget settings
                string gadgetX = Kernel32.IniReadValue("Gadget", "GadgetX", "Network_Manager.ini");
                string gadgetY = Kernel32.IniReadValue("Gadget", "GadgetY", "Network_Manager.ini");
                string alwaysOnTop = Kernel32.IniReadValue("Gadget", "AlwaysOnTop", "Network_Manager.ini");
                string checkForUpdates = Kernel32.IniReadValue("Gadget", "CheckForUpdates", "Network_Manager.ini");
                string maxVerticalSlots = Kernel32.IniReadValue("Gadget", "MaxVerticalSlots", "Network_Manager.ini");
                string maxHorizontalSlots = Kernel32.IniReadValue("Gadget", "MaxHorizontalSlots", "Network_Manager.ini");
                if (Regex.IsMatch(gadgetX, @"^\d+$") &&
                    Regex.IsMatch(gadgetY, @"^\d+$"))
                    currentConfig.Gadget.Location = new Point(int.Parse(gadgetX), int.Parse(gadgetY));
                if (Regex.IsMatch(alwaysOnTop, @"^(0|1)$"))
                    currentConfig.Gadget.AlwaysOnTop = alwaysOnTop == "1";
                if (Regex.IsMatch(checkForUpdates, @"^(0|1)$"))
                    currentConfig.Gadget.CheckForUpdates = checkForUpdates == "1";
                if (Regex.IsMatch(maxVerticalSlots, @"^\d$"))
                    currentConfig.Gadget.MaxVerticalSlots = int.Parse(maxVerticalSlots);
                if (Regex.IsMatch(maxHorizontalSlots, @"^\d$"))
                    currentConfig.Gadget.MaxHorizontalSlots = int.Parse(maxHorizontalSlots);
                // recover routes
                string routeNames = Kernel32.IniReadValue("Routes", "RouteNames", "Network_Manager.ini");
                if (routeNames.Contains('#'))
                {
                    SavedRouteGroup group = new SavedRouteGroup();
                    group.Name = "Legacy recovered routes";

                    foreach (string routeName in routeNames.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        string[] sRoute = Kernel32.IniReadValue("Routes", routeName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                        SavedRouteItem route = new SavedRouteItem();
                        route.Name = routeName;
                        try
                        {
                            route.Destination = sRoute[0];
                            route.Prefix = sRoute[1];
                            route.Gateway = sRoute[2];
                            route.InterfaceGuid = Guid.Empty;
                            route.Metric = ushort.Parse(sRoute[4]);
                            route.IPVersion = 4;
                            group.Nodes.Add(route);
                        }
                        catch { }
                    }
                    ((SavedRouteGroup)currentConfig.SavedRoutes.Nodes[0]).Nodes.Add(group);
                }
                // recover interface profiles
                // complete profiles
                string completeProfileNames = Kernel32.IniReadValue("ConfigInterfaceProfiles", "CompleteProfileNames", "Network_Manager.ini");
                foreach (string profileName in completeProfileNames.Split(new [] {'#'}, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (currentConfig.InterfaceProfiles.Any(i => i.Name == profileName))
                        continue;
                    string[] sProfile = Kernel32.IniReadValue("ConfigInterfaceProfiles", profileName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    InterfaceProfile profile = new InterfaceProfile();
                    profile.Name = profileName;
                    try
                    {
                        profile.IPv4LocalAddresses.Add(new NetworkInterface.IPHostAddress(sProfile[0], sProfile[1]));
                        profile.IPv4GatewayAddresses.Add(new NetworkInterface.IPGatewayAddress(sProfile[2], ushort.Parse(sProfile[3])));
                        profile.IPv4DnsAddresses.Add(sProfile[5]);
                        //profile.DhcpEnabled = (NetworkInterface.Dhcp)(int.Parse(sProfile[4]) + int.Parse(sProfile[6]));
                        profile.InterfaceMetric = int.Parse(sProfile[7]);
                        profile.NetbiosEnabled = (NetworkInterface.Netbios)(int.Parse(sProfile[7]) == 1 ? 1 : 2);
                        currentConfig.InterfaceProfiles.Add(profile);
                    }
                    catch { }
                }
                // IP profiles
                string ipProfileNames = Kernel32.IniReadValue("ConfigInterfaceProfiles", "IpProfileNames", "Network_Manager.ini");
                foreach (string profileName in ipProfileNames.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (currentConfig.InterfaceProfiles.Any(i => i.Name == profileName))
                        continue;
                    string[] sProfile = Kernel32.IniReadValue("ConfigInterfaceProfiles", profileName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    InterfaceProfile profile = new InterfaceProfile();
                    profile.Name = profileName;
                    try
                    {
                        profile.IPv4LocalAddresses.Add(new NetworkInterface.IPHostAddress(sProfile[0], sProfile[1]));
                        profile.IPv4GatewayAddresses.Add(new NetworkInterface.IPGatewayAddress(sProfile[2], ushort.Parse(sProfile[3])));
                        currentConfig.InterfaceProfiles.Add(profile);
                    }
                    catch { }
                }
                // DNS profiles
                string dnsProfileNames = Kernel32.IniReadValue("ConfigInterfaceProfiles", "DnsProfileNames", "Network_Manager.ini");
                foreach (string profileName in dnsProfileNames.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (currentConfig.InterfaceProfiles.Any(i => i.Name == profileName))
                        continue;
                    string[] sProfile = Kernel32.IniReadValue("ConfigInterfaceProfiles", profileName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    InterfaceProfile profile = new InterfaceProfile();
                    profile.Name = profileName;
                    try
                    {
                        profile.IPv4DnsAddresses.Add(sProfile[0]);
                        currentConfig.InterfaceProfiles.Add(profile);
                    }
                    catch { }
                }
                // Settings profiles
                string settingsProfileNames = Kernel32.IniReadValue("ConfigInterfaceProfiles", "SettingsProfileNames", "Network_Manager.ini");
                foreach (string profileName in settingsProfileNames.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (currentConfig.InterfaceProfiles.Any(i => i.Name == profileName))
                        continue;
                    string[] sProfile = Kernel32.IniReadValue("ConfigInterfaceProfiles", profileName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    InterfaceProfile profile = new InterfaceProfile();
                    profile.Name = profileName;
                    try
                    {
                        profile.InterfaceMetric = int.Parse(sProfile[7]);
                        profile.NetbiosEnabled = (NetworkInterface.Netbios)(int.Parse(sProfile[7]) == 1 ? 2 : 0);
                        currentConfig.InterfaceProfiles.Add(profile);
                    }
                    catch { }
                }
                try
                {
                    File.Move("Network_Manager.ini", "Network_Manager.old.ini");
                }
                catch { }
            }
            Global.Config = currentConfig;
        }
Esempio n. 4
0
        public static void Load()
        {
            Config currentConfig;

            if (!File.Exists("Network_Manager.xml") && File.Exists("Network_Manager.xml.tmp"))
            {
                File.Move("Network_Manager.xml.tmp", "Network_Manager.xml");
            }
            if (File.Exists("Network_Manager.xml"))
            {
                try
                {
                    XmlSerializer reader = new XmlSerializer(typeof(Config));
                    using (StreamReader file = new StreamReader("Network_Manager.xml"))
                    {
                        XmlReader xmlReader = XmlReader.Create(file);
                        currentConfig = (Config)reader.Deserialize(xmlReader);
                        //Config defaultConfig = new Config();
                        //currentConfig = (Config)CheckIfNull(typeof(Config), currentConfig, defaultConfig); // not needed, XML does a nice job
                    }
                }
                catch
                {
                    DialogResult result = MessageBox.Show("Configuration file was corrupted.\n\nDo you want to reset it to default and lose all configurations?", "Config File Corrupted", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.ServiceNotification);
                    if (result == DialogResult.No)
                    {
                        Global.Exit();
                    }
                    currentConfig = new Config();
                    File.Delete("Network_Manager.xml");
                }
            }
            else
            {
                currentConfig = new Config();
            }
            // load defaults if null
            if (currentConfig.SavedRoutes.Nodes.Count == 0)
            {
                currentConfig.SavedRoutes.Nodes.Add(new SavedRouteGroup());
                currentConfig.SavedRoutes.Nodes[0].Name = "<Root Group>";
            }
            if (currentConfig.InterfaceProfiles.Count == 0)
            {
                InterfaceProfile profile = new InterfaceProfile();
                profile.Name = "Google DNS";
                profile.IPv4DnsAddresses.Add("8.8.8.8");
                profile.IPv4DnsAddresses.Add("8.8.4.4");
                profile.IPv6DnsAddresses.Add("2001:4860:4860::8888");
                profile.IPv6DnsAddresses.Add("2001:4860:4860::8844");
                currentConfig.InterfaceProfiles.Add(profile);
                profile      = new InterfaceProfile();
                profile.Name = "Comodo Secure DNS";
                profile.IPv4DnsAddresses.Add("8.26.56.26");
                profile.IPv4DnsAddresses.Add("8.20.247.20");
                currentConfig.InterfaceProfiles.Add(profile);
                profile      = new InterfaceProfile();
                profile.Name = "OpenDNS";
                profile.IPv4DnsAddresses.Add("208.67.222.222");
                profile.IPv4DnsAddresses.Add("208.67.220.220");
                profile.IPv6DnsAddresses.Add("2620:0:ccc::2");
                profile.IPv6DnsAddresses.Add("2620:0:ccd::2");
                currentConfig.InterfaceProfiles.Add(profile);
            }
            if (currentConfig.LoadBalancer.IPv4LocalAddresses.Count == 0)
            {
                currentConfig.LoadBalancer.IPv4LocalAddresses.Add(new NetworkInterface.IPHostAddress("192.168.200.2", "255.255.255.0"));
            }
            if (currentConfig.LoadBalancer.IPv4GatewayAddresses.Count == 0)
            {
                currentConfig.LoadBalancer.IPv4GatewayAddresses.Add(new NetworkInterface.IPGatewayAddress("192.168.200.1", 1));
            }
            if (currentConfig.LoadBalancer.IPv4DnsAddresses.Count == 0)
            {
                currentConfig.LoadBalancer.IPv4DnsAddresses.Add("8.8.8.8");
            }
            // legacy upgrade support
            if (File.Exists("Network_Manager.ini"))
            {
                // recover Gadget settings
                string gadgetX            = Kernel32.IniReadValue("Gadget", "GadgetX", "Network_Manager.ini");
                string gadgetY            = Kernel32.IniReadValue("Gadget", "GadgetY", "Network_Manager.ini");
                string alwaysOnTop        = Kernel32.IniReadValue("Gadget", "AlwaysOnTop", "Network_Manager.ini");
                string checkForUpdates    = Kernel32.IniReadValue("Gadget", "CheckForUpdates", "Network_Manager.ini");
                string maxVerticalSlots   = Kernel32.IniReadValue("Gadget", "MaxVerticalSlots", "Network_Manager.ini");
                string maxHorizontalSlots = Kernel32.IniReadValue("Gadget", "MaxHorizontalSlots", "Network_Manager.ini");
                if (Regex.IsMatch(gadgetX, @"^\d+$") &&
                    Regex.IsMatch(gadgetY, @"^\d+$"))
                {
                    currentConfig.Gadget.Location = new Point(int.Parse(gadgetX), int.Parse(gadgetY));
                }
                if (Regex.IsMatch(alwaysOnTop, @"^(0|1)$"))
                {
                    currentConfig.Gadget.AlwaysOnTop = alwaysOnTop == "1";
                }
                if (Regex.IsMatch(checkForUpdates, @"^(0|1)$"))
                {
                    currentConfig.Gadget.CheckForUpdates = checkForUpdates == "1";
                }
                if (Regex.IsMatch(maxVerticalSlots, @"^\d$"))
                {
                    currentConfig.Gadget.MaxVerticalSlots = int.Parse(maxVerticalSlots);
                }
                if (Regex.IsMatch(maxHorizontalSlots, @"^\d$"))
                {
                    currentConfig.Gadget.MaxHorizontalSlots = int.Parse(maxHorizontalSlots);
                }
                // recover routes
                string routeNames = Kernel32.IniReadValue("Routes", "RouteNames", "Network_Manager.ini");
                if (routeNames.Contains('#'))
                {
                    SavedRouteGroup group = new SavedRouteGroup();
                    group.Name = "Legacy recovered routes";

                    foreach (string routeName in routeNames.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        string[]       sRoute = Kernel32.IniReadValue("Routes", routeName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                        SavedRouteItem route  = new SavedRouteItem();
                        route.Name = routeName;
                        try
                        {
                            route.Destination   = sRoute[0];
                            route.Prefix        = sRoute[1];
                            route.Gateway       = sRoute[2];
                            route.InterfaceGuid = Guid.Empty;
                            route.Metric        = ushort.Parse(sRoute[4]);
                            route.IPVersion     = 4;
                            group.Nodes.Add(route);
                        }
                        catch { }
                    }
                    ((SavedRouteGroup)currentConfig.SavedRoutes.Nodes[0]).Nodes.Add(group);
                }
                // recover interface profiles
                // complete profiles
                string completeProfileNames = Kernel32.IniReadValue("ConfigInterfaceProfiles", "CompleteProfileNames", "Network_Manager.ini");
                foreach (string profileName in completeProfileNames.Split(new [] { '#' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (currentConfig.InterfaceProfiles.Any(i => i.Name == profileName))
                    {
                        continue;
                    }
                    string[]         sProfile = Kernel32.IniReadValue("ConfigInterfaceProfiles", profileName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    InterfaceProfile profile  = new InterfaceProfile();
                    profile.Name = profileName;
                    try
                    {
                        profile.IPv4LocalAddresses.Add(new NetworkInterface.IPHostAddress(sProfile[0], sProfile[1]));
                        profile.IPv4GatewayAddresses.Add(new NetworkInterface.IPGatewayAddress(sProfile[2], ushort.Parse(sProfile[3])));
                        profile.IPv4DnsAddresses.Add(sProfile[5]);
                        //profile.DhcpEnabled = (NetworkInterface.Dhcp)(int.Parse(sProfile[4]) + int.Parse(sProfile[6]));
                        profile.InterfaceMetric = int.Parse(sProfile[7]);
                        profile.NetbiosEnabled  = (NetworkInterface.Netbios)(int.Parse(sProfile[7]) == 1 ? 1 : 2);
                        currentConfig.InterfaceProfiles.Add(profile);
                    }
                    catch { }
                }
                // IP profiles
                string ipProfileNames = Kernel32.IniReadValue("ConfigInterfaceProfiles", "IpProfileNames", "Network_Manager.ini");
                foreach (string profileName in ipProfileNames.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (currentConfig.InterfaceProfiles.Any(i => i.Name == profileName))
                    {
                        continue;
                    }
                    string[]         sProfile = Kernel32.IniReadValue("ConfigInterfaceProfiles", profileName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    InterfaceProfile profile  = new InterfaceProfile();
                    profile.Name = profileName;
                    try
                    {
                        profile.IPv4LocalAddresses.Add(new NetworkInterface.IPHostAddress(sProfile[0], sProfile[1]));
                        profile.IPv4GatewayAddresses.Add(new NetworkInterface.IPGatewayAddress(sProfile[2], ushort.Parse(sProfile[3])));
                        currentConfig.InterfaceProfiles.Add(profile);
                    }
                    catch { }
                }
                // DNS profiles
                string dnsProfileNames = Kernel32.IniReadValue("ConfigInterfaceProfiles", "DnsProfileNames", "Network_Manager.ini");
                foreach (string profileName in dnsProfileNames.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (currentConfig.InterfaceProfiles.Any(i => i.Name == profileName))
                    {
                        continue;
                    }
                    string[]         sProfile = Kernel32.IniReadValue("ConfigInterfaceProfiles", profileName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    InterfaceProfile profile  = new InterfaceProfile();
                    profile.Name = profileName;
                    try
                    {
                        profile.IPv4DnsAddresses.Add(sProfile[0]);
                        currentConfig.InterfaceProfiles.Add(profile);
                    }
                    catch { }
                }
                // Settings profiles
                string settingsProfileNames = Kernel32.IniReadValue("ConfigInterfaceProfiles", "SettingsProfileNames", "Network_Manager.ini");
                foreach (string profileName in settingsProfileNames.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (currentConfig.InterfaceProfiles.Any(i => i.Name == profileName))
                    {
                        continue;
                    }
                    string[]         sProfile = Kernel32.IniReadValue("ConfigInterfaceProfiles", profileName, "Network_Manager.ini").Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    InterfaceProfile profile  = new InterfaceProfile();
                    profile.Name = profileName;
                    try
                    {
                        profile.InterfaceMetric = int.Parse(sProfile[7]);
                        profile.NetbiosEnabled  = (NetworkInterface.Netbios)(int.Parse(sProfile[7]) == 1 ? 2 : 0);
                        currentConfig.InterfaceProfiles.Add(profile);
                    }
                    catch { }
                }
                try
                {
                    File.Move("Network_Manager.ini", "Network_Manager.old.ini");
                }
                catch { }
            }
            Global.Config = currentConfig;
        }
Esempio n. 5
0
            /// <summary>
            /// For rename = true, if node already exists and source is a group it renames it without changing its subnodes,
            /// and if it's an item it replaces it.<para/>
            /// Returns:<para/>
            /// 0: success<para/>
            /// 1: invlid destination<para/>
            /// 2: name already exists
            /// </summary>
            /// <param name="treeView"></param>
            /// <param name="name"></param>
            /// <param name="rename">Rename group/edit item</param>
            /// <returns></returns>
            public int AddNode(TreeView treeView, SavedRouteNode node, bool rename = false)
            {
                TreeNode selectedNode = treeView.SelectedNode;

                if (selectedNode == null)
                {
                    return(1);
                }
                // get TV selection path
                List <string> path   = new List <string>();
                TreeNode      tvNode = selectedNode;

                while (tvNode.Parent != null)
                {
                    path.Insert(0, tvNode.Parent.Text);
                    tvNode = tvNode.Parent;
                }
                if (selectedNode.ImageIndex == 0)
                {
                    path.Add(selectedNode.Text);
                }
                // find equivalent node in config
                List <SavedRouteNode> destination = this.Nodes;

                foreach (string pathNode in path.Take(path.Count - Convert.ToInt32(rename) + selectedNode.ImageIndex))
                {
                    destination = ((SavedRouteGroup)destination.Find((i) => i.Name == pathNode && i is SavedRouteGroup)).Nodes;
                }
                // find if name already used at destination
                if (destination.Find((i) => i.Name == node.Name && i.GetType() == node.GetType()) != null &&
                    (!rename || node.Name != selectedNode.Text))
                {
                    return(2);
                }
                if (rename)
                {
                    if (selectedNode.ImageIndex == 0)
                    {
                        if (destination.Find((i) => i.Name == selectedNode.Text && i.GetType() == node.GetType()) != null)
                        {
                            SavedRouteGroup group = (SavedRouteGroup)destination.Find((i) => i.Name == selectedNode.Text && i.GetType() == node.GetType());
                            group.Name = node.Name;
                            group.AutoLoadOnStartup = ((SavedRouteGroup)node).AutoLoadOnStartup;
                        }
                        path.Remove(path.Last());
                    }
                    else
                    {
                        destination.Remove(destination.Find((i) => i.Name == selectedNode.Text && i.GetType() == node.GetType()));
                        destination.Add(node);
                    }
                }
                else
                {
                    destination.Add(node);
                }
                path.Add(node.Name);
                // update TV
                Global.Config.Save();
                Global.Config.SavedRoutes.Populate(treeView, path);
                // raise event
                if (NodesChanged != null)
                {
                    NodesChanged(this, new EventArgs());
                }
                return(0);
            }