コード例 #1
0
        void LoadParam(AXMLNode N)
        {
            bool Protected = N[sProtected] == "1";
            Func <string, string> F;

            if (Protected)
            {
                F = (x) => { string s = N[x]; if (s.StartsWith(sProtected + "!"))
                             {
                                 s = Unprotect(s.Substring(sProtected.Length + 1));
                             }
                             ; return(s); };
            }
            else
            {
                F = (x) => N[x];
            }
            CurrentVpn         = new VpnItem();
            CurrentVpn.vpnName = N["vpnName"];
            CurrentVpn.vpnUser = N["vpnUser"];
            CurrentVpn.vpnPwd  = F("vpnPwd");
            CurrentVpn.ipMask  = N["ipMask"];
            CurrentVpn.Routes  = N["Routes"];

            if (!Protected)
            {
                SettingsChanged = true;
            }
        }
コード例 #2
0
        public bool LoadSettings(string s1 = "")
        { // Чтение настроечных параметров
            SettingsChanged = false;
            string s, s2;

            if (s1 == "")
            {
                s = Application.StartupPath; s += @"\Settings.xml";
            }
            else
            {
                s = s1;
            }
            SettingsPath = s;
            if (!File.Exists(s))
            {
                return(false);
            }
            XmlDocument D = new XmlDocument();

            try
            {
                D.Load(s);
                XmlNodeList Ns = D.DocumentElement.ChildNodes;
                if (Ns.Count > 0)
                {
                    var AC = Ns[0].Attributes;
                    var A  = AC[@"Path"];
                    if (A != null)
                    {
                        s2 = A.Value;
                    }
                    else
                    {
                        s2 = "";
                    }
                    if ((s1 == "") && (s2 != ""))
                    {
                        LoadSettings(s2);
                    }
                    else
                    {
                        XmlNode vpnNode = D.DocumentElement.SelectSingleNode("vpnConnect");
                        if (vpnNode != null)
                        {
                            XmlNodeList items = vpnNode.SelectNodes("item");
                            if (items.Count == 0)
                            {
                                vpnNode = null;
                            }
                        }
                        if (vpnNode == null)
                        {
                            LoadParam(new AXMLNode(Ns[0]));
                            SettingsChanged = true;
                            Connect.VpnDict.Clear();
                            Connect.VpnDict.Add(CurrentVpn.vpnName, CurrentVpn);
                        }
                        else
                        {
                            XmlNodeList items = vpnNode.SelectNodes("item");
                            Connect.VpnDict.Clear();
                            VpnItem first = null;
                            foreach (XmlNode item in items)
                            {
                                var aitem = new AXMLNode(item);
                                LoadParam(aitem);
                                if (first == null)
                                {
                                    first = CurrentVpn;
                                }
                                try
                                {
                                    Connect.VpnDict.Add(CurrentVpn.vpnName, CurrentVpn);
                                }
                                catch { }
                            }
                            if (first != null)
                            {
                                CurrentVpn = first;
                            }
                            try
                            {
                                string current = (string)vpnNode.Attributes["Current"].Value;
                                if (Connect.VpnDict.TryGetValue(current, out first))
                                {
                                    CurrentVpn = first;
                                }
                                Connect.CurrentVpn = CurrentVpn;
                            }
                            catch { }
                        }
                    }
                }
            }
            catch (Exception e) { MessageBox.Show(e.Message); }
            D = null;
            if (SettingsChanged)
            {
                SaveSettings();
            }
            return(true);
        }