Beispiel #1
0
        private void SaveConfig()
        {
            Settings   s  = instance.GlobalSettings;
            SavedLogin sl = new SavedLogin();

            string username = cbxUsername.Text;

            if (cbxUsername.SelectedIndex > 0 && cbxUsername.SelectedItem is SavedLogin)
            {
                username = ((SavedLogin)cbxUsername.SelectedItem).Username;
            }

            if (cbxGrid.SelectedIndex == cbxGrid.Items.Count - 1) // custom login uri
            {
                sl.GridID    = "custom_login_uri";
                sl.CustomURI = txtCustomLoginUri.Text;
            }
            else
            {
                sl.GridID    = (cbxGrid.SelectedItem as Grid).ID;
                sl.CustomURI = string.Empty;
            }

            string savedLoginsKey = string.Format("{0}%{1}", username, sl.GridID);

            if (!(s["saved_logins"] is OSDMap))
            {
                s["saved_logins"] = new OSDMap();
            }

            if (cbRemember.Checked)
            {
                sl.Username = s["username"] = username;

                if (LoginOptions.IsPasswordMD5(txtPassword.Text))
                {
                    sl.Password   = txtPassword.Text;
                    s["password"] = txtPassword.Text;
                }
                else
                {
                    sl.Password   = Utils.MD5(txtPassword.Text);
                    s["password"] = Utils.MD5(txtPassword.Text);
                }
                if (cbxLocation.SelectedIndex == -1)
                {
                    sl.CustomStartLocation = cbxLocation.Text;
                }
                else
                {
                    sl.CustomStartLocation = string.Empty;
                }
                sl.StartLocationType = cbxLocation.SelectedIndex;
                ((OSDMap)s["saved_logins"])[savedLoginsKey] = sl.ToOSD();
            }
            else if (((OSDMap)s["saved_logins"]).ContainsKey(savedLoginsKey))
            {
                ((OSDMap)s["saved_logins"]).Remove(savedLoginsKey);
            }

            s["login_location_type"] = OSD.FromInteger(cbxLocation.SelectedIndex);
            s["login_location"]      = OSD.FromString(cbxLocation.Text);

            s["login_grid"]     = OSD.FromInteger(cbxGrid.SelectedIndex);
            s["login_uri"]      = OSD.FromString(txtCustomLoginUri.Text);
            s["remember_login"] = cbRemember.Checked;
        }