コード例 #1
0
        private void linkLabelMigrate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (MessageBox.Show(String.Format(KeeOtp2Statics.MessageBoxMigrationReplacePlaceholder, KeeOtp2Ext.KeeOtp1PlaceHolder, string.Format("{0}/{1}", KeeOtp2Ext.BuiltInTotpPlaceHolder, KeeOtp2Ext.BuiltInHotpPlaceHolder)), KeeOtp2Statics.Migration, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if (data.Type == OtpType.Totp)
                {
                    OtpAuthUtils.replacePlaceholder(this.entry, KeeOtp2Ext.KeeOtp1PlaceHolder, KeeOtp2Ext.BuiltInTotpPlaceHolder);
                }
                else if (data.Type == OtpType.Hotp)
                {
                    OtpAuthUtils.replacePlaceholder(this.entry, KeeOtp2Ext.KeeOtp1PlaceHolder, KeeOtp2Ext.BuiltInHotpPlaceHolder);
                }
            }

            checkboxOldKeeOtp.Checked = false;
            this.DialogResult         = DialogResult.OK;
        }
コード例 #2
0
ファイル: Settings.cs プロジェクト: tiuub/KeeOtp2
        private void backgroundWorkerMigrate_DoWork(object sender, DoWorkEventArgs e)
        {
            PwUuid RecycleBinUuid = this.host.Database.RecycleBinUuid;

            List <PwEntry> entries = new List <PwEntry>();

            entries = this.host.MainWindow.ActiveDatabase.RootGroup.GetEntries(true).ToList();

            int count     = entries.Count;
            int counter   = 0;
            int succeeded = 0;

            labelStatus.Text = String.Format(KeeOtp2Statics.SettingsLoadedNEntries, count);

            foreach (PwEntry entry in entries)
            {
                if (entry.ParentGroup.Uuid != RecycleBinUuid)
                {
                    if (checkEntryMigratable(entry, currentMigrationProfile.migrationMode))
                    {
                        OtpAuthData data = OtpAuthUtils.loadData(entry);
                        if (data != null)
                        {
                            entry.CreateBackup(this.host.Database);
                            switch (currentMigrationProfile.migrationMode)
                            {
                            case MigrationMode.KeeOtp1ToBuiltIn:
                                if (!data.isForcedKeeOtp1Mode())
                                {
                                    OtpAuthUtils.migrateToBuiltInOtp(data, entry);
                                    if (OtpAuthUtils.loadDataFromKeeOtp1String(entry) != null)
                                    {
                                        if (removeAfterMigration)
                                        {
                                            OtpAuthUtils.purgeLoadedFields(data, entry);
                                        }
                                    }
                                }
                                else
                                {
                                    encounteredForcedKeeOtp1Entries = true;
                                }
                                break;

                            case MigrationMode.BuiltInToKeeOtp1:
                                OtpAuthUtils.migrateToKeeOtp1String(data, entry);
                                if (OtpAuthUtils.loadDataFromKeeOtp1String(entry) != null)
                                {
                                    if (removeAfterMigration)
                                    {
                                        OtpAuthUtils.purgeLoadedFields(data, entry);
                                    }
                                }
                                break;

                            default:
                                break;
                            }

                            if (migrateAutoType)
                            {
                                foreach (string currentPlaceholder in currentMigrationProfile.findPlaceholder.Values)
                                {
                                    OtpAuthUtils.replacePlaceholder(entry, currentPlaceholder, currentMigrationProfile.replacePlaceholder[data.Type]);
                                }
                            }
                            entry.Touch(true);
                            succeeded++;
                        }
                        else
                        {
                            this.Invoke((Action)(() =>
                            {
                                if (MessageBox.Show(String.Format(KeeOtp2Statics.MessageBoxCantParseEntry, entry.ParentGroup.Name, entry.Strings.ReadSafe(PwDefs.TitleField), entry.Strings.ReadSafe(PwDefs.UserNameField)), KeeOtp2Statics.Migration, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
                                {
                                    backgroundWorkerMigrate.CancelAsync();
                                }
                            }));
                        }
                    }
                }
                counter++;
                labelStatus.Text = String.Format(KeeOtp2Statics.SettingsDoneNofNEntries, counter, count);
            }

            if (succeeded > 0)
            {
                this.host.MainWindow.ActiveDatabase.Modified = true;
                this.host.MainWindow.UpdateUI(false, null, false, null, false, null, true);
            }
        }