|
6 | 6 | using PureOtp; |
7 | 7 |
|
8 | 8 | using KeePassLib; |
| 9 | +using KeePassLib.Interfaces; |
9 | 10 |
|
10 | 11 | namespace PassXYZLib |
11 | 12 | { |
12 | | - public class PxEntry : PwEntry |
| 13 | + public class PxEntry : PwEntry, IDeepCloneable<PxEntry> |
13 | 14 | { |
14 | 15 | public PxEntry() : base() |
15 | 16 | { } |
16 | 17 |
|
| 18 | + /// <summary> |
| 19 | + /// Construct a new, empty password entry. Member variables will be initialized |
| 20 | + /// to their default values. |
| 21 | + /// </summary> |
| 22 | + /// <param name="bCreateNewUuid">If <c>true</c>, a new UUID will be created |
| 23 | + /// for this entry. If <c>false</c>, the UUID is zero and you must set it |
| 24 | + /// manually later.</param> |
| 25 | + /// <param name="bSetTimes">If <c>true</c>, the creation, last modification |
| 26 | + /// and last access times will be set to the current system time.</param> |
| 27 | + public PxEntry(bool bCreateNewUuid, bool bSetTimes) : base(bCreateNewUuid, bSetTimes) { } |
| 28 | + |
| 29 | + public PxEntry(PwEntry entry) |
| 30 | + { |
| 31 | + Uuid = entry.Uuid; // PwUuid is immutable |
| 32 | + ParentGroup = entry.ParentGroup; |
| 33 | + LocationChanged = entry.LocationChanged; |
| 34 | + |
| 35 | + Strings = entry.Strings.CloneDeep(); |
| 36 | + Binaries = entry.Binaries.CloneDeep(); |
| 37 | + AutoType = entry.AutoType.CloneDeep(); |
| 38 | + History = entry.History.CloneDeep(); |
| 39 | + |
| 40 | + IconId = entry.IconId; |
| 41 | + CustomIconUuid = entry.CustomIconUuid; |
| 42 | + |
| 43 | + ForegroundColor = entry.ForegroundColor; |
| 44 | + BackgroundColor = entry.BackgroundColor; |
| 45 | + |
| 46 | + CreationTime = entry.CreationTime; |
| 47 | + LastModificationTime = entry.LastModificationTime; |
| 48 | + LastAccessTime = entry.LastAccessTime; |
| 49 | + ExpiryTime = entry.ExpiryTime; |
| 50 | + Expires = entry.Expires; |
| 51 | + UsageCount = entry.UsageCount; |
| 52 | + |
| 53 | + OverrideUrl = entry.OverrideUrl; |
| 54 | + |
| 55 | + Tags = new List<string>(entry.Tags); |
| 56 | + |
| 57 | + CustomData = entry.CustomData.CloneDeep(); |
| 58 | + } |
| 59 | + |
| 60 | +#if DEBUG |
| 61 | + // For display in debugger |
| 62 | + public override string ToString() |
| 63 | + { |
| 64 | + return ("PxEntry '" + Strings.ReadSafe(PwDefs.TitleField) + "'"); |
| 65 | + } |
| 66 | +#endif |
| 67 | + |
| 68 | + /// <summary> |
| 69 | + /// Clone the current entry. The returned entry is an exact value copy |
| 70 | + /// of the current entry (including UUID and parent group reference). |
| 71 | + /// All mutable members are cloned. |
| 72 | + /// </summary> |
| 73 | + /// <returns>Exact value clone. All references to mutable values changed.</returns> |
| 74 | + public new PxEntry CloneDeep() |
| 75 | + { |
| 76 | + PxEntry peNew = new PxEntry(false, false); |
| 77 | + |
| 78 | + peNew.Uuid = Uuid; // PwUuid is immutable |
| 79 | + peNew.ParentGroup = ParentGroup; |
| 80 | + peNew.LocationChanged = LocationChanged; |
| 81 | + |
| 82 | + peNew.Strings = Strings.CloneDeep(); |
| 83 | + peNew.Binaries = Binaries.CloneDeep(); |
| 84 | + peNew.AutoType = AutoType.CloneDeep(); |
| 85 | + peNew.History = History.CloneDeep(); |
| 86 | + |
| 87 | + peNew.IconId = IconId; |
| 88 | + peNew.CustomIconUuid = CustomIconUuid; |
| 89 | + |
| 90 | + peNew.ForegroundColor = ForegroundColor; |
| 91 | + peNew.BackgroundColor = BackgroundColor; |
| 92 | + |
| 93 | + peNew.CreationTime = CreationTime; |
| 94 | + peNew.LastModificationTime = LastModificationTime; |
| 95 | + peNew.LastAccessTime = LastAccessTime; |
| 96 | + peNew.ExpiryTime = ExpiryTime; |
| 97 | + peNew.Expires = Expires; |
| 98 | + peNew.UsageCount = UsageCount; |
| 99 | + |
| 100 | + peNew.OverrideUrl = OverrideUrl; |
| 101 | + |
| 102 | + peNew.Tags = new List<string>(Tags); |
| 103 | + |
| 104 | + peNew.CustomData = CustomData.CloneDeep(); |
| 105 | + |
| 106 | + return peNew; |
| 107 | + } |
| 108 | + |
17 | 109 | #region PxEntrySupportOTP |
18 | 110 | // Update progress every 3 seconds |
19 | 111 | public const int TimerStep = 3; |
|
0 commit comments