示例#1
0
        private void OtpInformation_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == DialogResult.Cancel)
            {
                return;
            }
            try
            {
                this.data = readData();

                this.entry.CreateBackup(this.host.Database);

                if (this.data.loadedFields != null && !string.IsNullOrEmpty(OtpAuthUtils.getOtpString(this.data)))
                {
                    OtpAuthUtils.purgeLoadedFields(this.data, this.entry);
                }

                if (this.data.KeeOtp1Mode)
                {
                    OtpAuthUtils.migrateToKeeOtp1String(this.data, this.entry);
                }
                else
                {
                    OtpAuthUtils.migrateToBuiltInOtp(this.data, this.entry);
                }


                this.entry.Touch(true);
                this.host.MainWindow.ActiveDatabase.Modified = true;
                this.host.MainWindow.UpdateUI(false, null, false, null, false, null, true);
            }
            catch (InvalidBase32FormatException ex)
            {
                MessageBox.Show(ex.Message, KeeOtp2Statics.InvalidBase32Format, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            catch (InvalidBase64FormatException ex)
            {
                MessageBox.Show(ex.Message, KeeOtp2Statics.InvalidBase64Format, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            catch (InvalidHexFormatException ex)
            {
                MessageBox.Show(ex.Message, KeeOtp2Statics.InvalidHexFormat, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            catch (InvalidUriFormat ex)
            {
                MessageBox.Show(ex.Message, KeeOtp2Statics.InvalidUriFormat, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                e.Cancel = true;
                return;
            }
            catch (InvalidOtpConfiguration ex)
            {
                MessageBox.Show(ex.Message, KeeOtp2Statics.InvalidOtpConfiguration, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                e.Cancel = true;
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format(KeeOtp2Statics.MessageBoxException, ex.Message), KeeOtp2Statics.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.Cancel = true;
                return;
            }
        }