Exemplo n.º 1
0
        internal string ShowConfirmAssociationDialog(string key)
        {
            string id = null;

            using (var f = new ConfirmAssociationForm())
            {
                var win = HostInstance.MainWindow;
                win.Invoke((MethodInvoker) delegate
                {
                    f.Activate();
                    f.Icon  = win.Icon;
                    f.Key   = key;
                    f.Load += delegate { f.Activate(); };
                    f.ShowDialog(win);

                    if (f.KeyId != null)
                    {
                        var entry = GetConfigEntry(true);

                        bool keyNameExists = true;
                        while (keyNameExists)
                        {
                            DialogResult keyExistsResult = DialogResult.Yes;
                            if (entry.Strings.Any(x => x.Key == AssociateKeyPrefix + f.KeyId))
                            {
                                keyExistsResult = MessageBox.Show(
                                    win,
                                    "A shared encryption-key with the name \"" + f.KeyId + "\" already exists.\nDo you want to overwrite it?",
                                    "Overwrite existing key?",
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Warning,
                                    MessageBoxDefaultButton.Button1
                                    );
                            }

                            if (keyExistsResult == DialogResult.No)
                            {
                                f.ShowDialog(win);
                            }
                            else
                            {
                                keyNameExists = false;
                            }
                        }

                        if (f.KeyId != null)
                        {
                            entry.Strings.Set(AssociateKeyPrefix + f.KeyId, new ProtectedString(true, key));
                            entry.Touch(true);
                            UpdateUI(null);
                            id = f.KeyId;
                        }
                    }
                });
            }
            return(id);
        }
Exemplo n.º 2
0
        internal string ShowConfirmAssociationDialog(string key)
        {
            string id = null;

            using (var f = new ConfirmAssociationForm())
            {
                var win = HostInstance.MainWindow;
                win.Invoke((MethodInvoker) delegate
                {
                    f.Activate();
                    f.Icon  = win.Icon;
                    f.Key   = key;
                    f.Load += delegate { f.Activate(); };
                    f.ShowDialog(win);

                    if (f.KeyId != null)
                    {
                        bool keyNameExists = true;
                        var db             = GetConnectionDatabase();
                        var customKey      = DbKey + f.KeyId;

                        while (keyNameExists)
                        {
                            DialogResult keyExistsResult = DialogResult.Yes;
                            if (db.CustomData.Exists(customKey))
                            {
                                keyExistsResult = MessageBox.Show(
                                    win,
                                    "A shared encryption-key with the name \"" + f.KeyId + "\" already exists.\nDo you want to overwrite it?",
                                    "Overwrite existing key?",
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Warning,
                                    MessageBoxDefaultButton.Button1
                                    );
                            }

                            if (keyExistsResult == DialogResult.No)
                            {
                                f.ShowDialog(win);
                            }
                            else
                            {
                                keyNameExists = false;
                            }
                        }

                        if (f.KeyId != null)
                        {
                            db.CustomData.Set(customKey, key);
                            id = f.KeyId;
                            UpdateUI(null);
                        }
                    }
                });
            }
            return(id);
        }