diff --git a/KeePassNatMsg/KeePassNatMsgExt.cs b/KeePassNatMsg/KeePassNatMsgExt.cs index 4236db4..1d32916 100644 --- a/KeePassNatMsg/KeePassNatMsgExt.cs +++ b/KeePassNatMsg/KeePassNatMsgExt.cs @@ -624,7 +624,7 @@ internal void MoveConfig(PwDatabase db, bool fromKpnm) } else { - dupeKeys.Add(cd.Key); + dupeKeys.Add(id); } } @@ -644,6 +644,40 @@ internal void MoveConfig(PwDatabase db, bool fromKpnm) } } + if (dupeKeys.Count > 0 || dupeEntries.Count > 0) + { + var lines = new List(); + + if (dupeKeys.Count > 0) + { + lines.AddRange(new[] { string.Empty, "Duplicate Keys:", string.Empty }); + lines.AddRange(dupeKeys); + lines.Add(string.Empty); + } + + if (dupeEntries.Count > 0) + { + lines.AddRange(new[] { string.Empty, "Duplicate Entry Configs:", string.Empty }); + lines.AddRange(dupeEntries.Select(x => x.Strings.ReadSafe(PwDefs.TitleField))); + lines.Add(string.Empty); + } + + var file = Path.Combine(Path.GetTempPath(), string.Format("KeePassNatMsg-Migration-{0}.log", DateTime.Now)); + + File.WriteAllLines(file, lines, new System.Text.UTF8Encoding(false)); + + var title = dupeKeys.Count > 0 && dupeEntries.Count > 0 ? "Duplicate Keys/Entries Found" : dupeKeys.Count > 0 ? "Duplicate Keys Found" : "Duplicate Entries Found"; + var result = MessageBox.Show("There were duplicates found. Please check the log file for more information:\r\n\r\n" + file + "\r\n\r\nDo you want to open the log file now?", title, MessageBoxButtons.YesNo); + + if (result == DialogResult.Yes) + { + var psi = new System.Diagnostics.ProcessStartInfo(file); + psi.UseShellExecute = true; + psi.Verb = "open"; + System.Diagnostics.Process.Start(psi); + } + } + // set db modified HostInstance.MainWindow.UpdateUI(false, null, false, null, false, null, true); } diff --git a/KeePassNatMsg/Options/OptionsForm.cs b/KeePassNatMsg/Options/OptionsForm.cs index 8b30904..805d2dd 100644 --- a/KeePassNatMsg/Options/OptionsForm.cs +++ b/KeePassNatMsg/Options/OptionsForm.cs @@ -305,7 +305,7 @@ private void LoadDatabaseKeys(PwDatabase db) if (db.IsOpen) { var keys = new List(); - var dbKey = KeePassNatMsgExt.GetDbKey(chkUseKpxcSettingsKey.Checked); + var dbKey = KeePassNatMsgExt.GetDbKey(_config.UseKeePassXcSettings); foreach (var cd in db.CustomData) { @@ -334,11 +334,11 @@ private void btnRemoveSelectedKeys_Click(object sender, EventArgs e) if (db.IsOpen) { - var dbKey = KeePassNatMsgExt.GetDbKey(chkUseKpxcSettingsKey.Checked); + var dbKey = KeePassNatMsgExt.GetDbKey(_config.UseKeePassXcSettings); var items = dgvKeys.SelectedRows .OfType() - .Select(x => dbKey + (x.DataBoundItem as DatabaseKeyItem) == null ? null : (x.DataBoundItem as DatabaseKeyItem).Name); + .Select(x => dbKey + ((x.DataBoundItem as DatabaseKeyItem) == null ? string.Empty : (x.DataBoundItem as DatabaseKeyItem).Name)); var deleteKeys = db.CustomData .Where(x => items.Contains(x.Key)) @@ -354,7 +354,7 @@ private void btnRemoveAllKeys_Click(object sender, EventArgs e) if (db.IsOpen) { - var dbKey = KeePassNatMsgExt.GetDbKey(chkUseKpxcSettingsKey.Checked); + var dbKey = KeePassNatMsgExt.GetDbKey(_config.UseKeePassXcSettings); var deleteKeys = db.CustomData .Where(x => x.Key.StartsWith(dbKey))