示例#1
0
    public void Add(string account, string password)
    {
        if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
        {
            return;
        }
        SecurityElement se;

        if (FileUtils.Exist(PathUtils.AccountInfo) == false)
        {
            se = MonoXmlUtils.Create();
        }
        else
        {
            se = MonoXmlUtils.LoadXmlSE(PathUtils.AccountInfo);
        }

        SecurityElement item;
        bool            found = false;

        if (se.Children != null)
        {
            int index = 0;
            for (int i = 0, count = se.Children.Count; i < count; ++i)
            {
                item = se.Children[i] as SecurityElement;
                if (string.IsNullOrEmpty(item.Text) == false && item.Text.CompareTo(account) == 0)
                {
                    found = true;
                    index = i;
                    item.SetAttribute("pwd", password);
                }
            }

            if (index != 0)
            {
                ///将本次登录的账号置于第一位,下次登录默认就是这个账号了
                string median = (se.Children[0] as SecurityElement).Text;
                (se.Children[0] as SecurityElement).Text     = (se.Children[index] as SecurityElement).Text;
                (se.Children[index] as SecurityElement).Text = median;
                median = (se.Children[0] as SecurityElement).Attributes["pwd"] as string;
                (se.Children[0] as SecurityElement).SetAttribute("pwd", (se.Children[index] as SecurityElement).Attributes["pwd"] as string);
                (se.Children[index] as SecurityElement).SetAttribute("pwd", median);
            }
        }

        if (found == false)
        {
            MonoXmlUtils.AddAttr(se, account, password);
        }
        MonoXmlUtils.SaveXml(PathUtils.AccountInfo, se);
    }