Skip to content

Commit ece725f

Browse files
committed
Added Description to Item.
1 parent c71d628 commit ece725f

File tree

8 files changed

+141
-3
lines changed

8 files changed

+141
-3
lines changed

KPCLib.xunit/PassXYZLibTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ public void IsOpenDbTest()
6262
Assert.True((passxyz.PxDb.IsOpen));
6363
}
6464

65+
[Fact]
66+
public void ListItemsTests()
67+
{
68+
PwGroup pg = passxyz.PxDb.RootGroup;
69+
foreach (var item in pg.Items)
70+
{
71+
Debug.WriteLine($"{item.Description}\t{item.Name}");
72+
if(!item.IsGroup)
73+
{
74+
if(PxDefs.IsPxEntry((PwEntry)item))
75+
{
76+
var entry = new PxEntry((PwEntry)item);
77+
if (entry.Totp == null)
78+
{
79+
entry.UpdateOtpUrl("otpauth://totp/Google%3Apxentry_test%40gmail.com?secret=JBSWY3DPEHPK3PXP&issuer=Google");
80+
var Totp = entry.Totp;
81+
Debug.WriteLine($"Token={entry.Token}");
82+
Assert.NotNull(Totp);
83+
}
84+
}
85+
}
86+
}
87+
}
88+
6589
[Fact]
6690
public void CurrentGroupTests()
6791
{

KPCLib.xunit/PxDatabaseTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void ListGroupsTests()
6767
}
6868
}
6969

70+
7071
[Fact]
7172
public void ListEntriesTests()
7273
{

KPCLib/KPCLib.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535
</PropertyGroup>
3636

3737
<ItemGroup>
38+
<PackageReference Include="PureOtp" Version="1.0.0.8" />
3839
<PackageReference Include="SkiaSharp" Version="1.68.0" />
3940
</ItemGroup>
4041

42+
<ItemGroup>
43+
<Folder Include="PassXYZLib\" />
44+
</ItemGroup>
45+
4146
</Project>

KPCLib/PassXYZLib/Item.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public abstract class Item : INotifyPropertyChanged
1717

1818
public abstract string Name { get; set; }
1919

20+
public abstract string Description { get;}
21+
2022
public abstract bool IsGroup { get; }
2123

2224
/// <summary>

KPCLib/PassXYZLib/PxEntry.cs

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,106 @@
66
using PureOtp;
77

88
using KeePassLib;
9+
using KeePassLib.Interfaces;
910

1011
namespace PassXYZLib
1112
{
12-
public class PxEntry : PwEntry
13+
public class PxEntry : PwEntry, IDeepCloneable<PxEntry>
1314
{
1415
public PxEntry() : base()
1516
{ }
1617

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+
17109
#region PxEntrySupportOTP
18110
// Update progress every 3 seconds
19111
public const int TimerStep = 3;

KPCLib/PwEntry.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ internal set
283283
public EventHandler<ObjectTouchedEventArgs> Touched;
284284

285285
#if KPCLib
286+
public override string Description
287+
{
288+
get {
289+
return $"PwEntry\t{LastModificationTime.ToString("yyyy'-'MM'-'dd")}";
290+
}
291+
}
292+
286293
public override bool IsGroup => false;
287294

288295
/// <summary>

KPCLib/PwGroup.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,15 @@ public override string Name
8686
}
8787

8888
#if KPCLib
89-
public override bool IsGroup => true;
89+
public override string Description
90+
{
91+
get {
92+
return $"PwGroup\t{LastModificationTime.ToString("yyyy'-'MM'-'dd")}";
93+
}
94+
}
95+
96+
97+
public override bool IsGroup => true;
9098

9199
/// <summary>
92100
/// Get a list of items in this group.

PassXYZLib/PassXYZLib.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="PassXYZ" Version="2.1.4.8" />
22-
<PackageReference Include="PureOtp" Version="1.0.0.8" />
2322
</ItemGroup>
2423

2524
<ItemGroup>

0 commit comments

Comments
 (0)