1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2021 Dominik Reichl <dominik.reichl@t-online.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using KeePass.App;
using KeePass.Resources;
using KeePass.UI;
using KeePassLib;
using KeePassLib.Collections;
using KeePassLib.Security;
namespace KeePass.Forms
{
public partial class DuplicationForm : Form
{
// Copy data from controls to simple member variables,
// because ApplyTo must work after the dialog has been destroyed.
private bool m_bAppendCopy = true;
// public bool AppendCopyToTitles
// {
// get { return m_bAppendCopy; }
// }
private bool m_bFieldRefs = false;
// public bool ReplaceDataByFieldRefs
// {
// get { return m_bFieldRefs; }
// }
private bool m_bCopyHistory = true;
// public bool CopyHistory
// {
// get { return m_bCopyHistory; }
// }
public void ApplyTo(PwEntry peNew, PwEntry pe, PwDatabase pd)
{
if((peNew == null) || (pe == null)) { Debug.Assert(false); return; }
Debug.Assert(peNew.Strings.ReadSafe(PwDefs.UserNameField) ==
pe.Strings.ReadSafe(PwDefs.UserNameField));
Debug.Assert(peNew.Strings.ReadSafe(PwDefs.PasswordField) ==
pe.Strings.ReadSafe(PwDefs.PasswordField));
if(m_bAppendCopy && (pd != null))
{
string strTitle = peNew.Strings.ReadSafe(PwDefs.TitleField);
peNew.Strings.Set(PwDefs.TitleField, new ProtectedString(
pd.MemoryProtection.ProtectTitle, strTitle + " - " +
KPRes.CopyOfItem));
}
if(m_bFieldRefs && (pd != null))
{
string strUser = @"{REF:U@I:" + pe.Uuid.ToHexString() + @"}";
peNew.Strings.Set(PwDefs.UserNameField, new ProtectedString(
pd.MemoryProtection.ProtectUserName, strUser));
string strPw = @"{REF:P@I:" + pe.Uuid.ToHexString() + @"}";
peNew.Strings.Set(PwDefs.PasswordField, new ProtectedString(
pd.MemoryProtection.ProtectPassword, strPw));
}
if(!m_bCopyHistory)
peNew.History = new PwObjectList<PwEntry>();
}
public DuplicationForm()
{
InitializeComponent();
Program.Translation.ApplyTo(this);
}
private void OnFormLoad(object sender, EventArgs e)
{
GlobalWindowManager.AddWindow(this);
this.Icon = AppIcons.Default;
FontUtil.AssignDefaultBold(m_cbAppendCopy);
FontUtil.AssignDefaultBold(m_cbFieldRefs);
FontUtil.AssignDefaultBold(m_cbCopyHistory);
m_cbAppendCopy.Checked = m_bAppendCopy;
m_cbFieldRefs.Checked = m_bFieldRefs;
m_cbCopyHistory.Checked = m_bCopyHistory;
}
private void OnFormClosed(object sender, FormClosedEventArgs e)
{
GlobalWindowManager.RemoveWindow(this);
}
private void OnFieldRefsLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
AppHelp.ShowHelp(AppDefs.HelpTopics.FieldRefs, null);
}
private void OnBtnOK(object sender, EventArgs e)
{
m_bAppendCopy = m_cbAppendCopy.Checked;
m_bFieldRefs = m_cbFieldRefs.Checked;
m_bCopyHistory = m_cbCopyHistory.Checked;
}
}
}
|