Skip to content

Commit d382309

Browse files
committed
Added INotifyPropertyChanged to class User
1 parent ea705d0 commit d382309

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

PassXYZLib/User.cs

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.Diagnostics;
45
using System.IO;
6+
using System.Runtime.CompilerServices;
57

68
namespace PassXYZLib
79
{
@@ -112,6 +114,22 @@ public static string BakFilePath
112114
}
113115
}
114116

117+
/// <summary>
118+
/// The icon file path.
119+
/// </summary>
120+
public static string IconFilePath
121+
{
122+
get
123+
{
124+
string iconPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "icons");
125+
if (!Directory.Exists(iconPath))
126+
{
127+
_ = Directory.CreateDirectory(iconPath);
128+
}
129+
return iconPath;
130+
}
131+
}
132+
115133
/// <summary>
116134
/// Decode the username from filename
117135
/// </summary>
@@ -151,7 +169,7 @@ public static string GetUserName(string fileName)
151169

152170
}
153171

154-
public class User
172+
public class User : INotifyPropertyChanged
155173
{
156174
private string _username = string.Empty;
157175
/// <summary>
@@ -254,10 +272,7 @@ public bool IsKeyFileExist
254272
/// <summary>
255273
/// The date/time when this user was last accessed (read).
256274
/// </summary>
257-
public DateTime LastAccessTime
258-
{
259-
get { return File.GetLastAccessTime(this.Path); }
260-
}
275+
public DateTime LastAccessTime => File.GetLastWriteTime(this.Path);
261276

262277
/// <summary>
263278
/// Data file name. Converted Username to file name
@@ -321,10 +336,10 @@ public string KeyFilePath
321336
/// <summary>
322337
/// Delete the current user
323338
/// </summary>
324-
public void Delete()
339+
public void Delete()
325340
{
326341
File.Delete(Path);
327-
if (IsDeviceLockEnabled)
342+
if (IsDeviceLockEnabled)
328343
{
329344
File.Delete(KeyFilePath);
330345
}
@@ -378,5 +393,30 @@ public User()
378393
{
379394
IsDeviceLockEnabled = false;
380395
}
396+
397+
#region INotifyPropertyChanged
398+
protected bool SetProperty<T>(ref T backingStore, T value,
399+
[CallerMemberName] string propertyName = "",
400+
Action onChanged = null)
401+
{
402+
if (EqualityComparer<T>.Default.Equals(backingStore, value))
403+
return false;
404+
405+
backingStore = value;
406+
onChanged?.Invoke();
407+
OnPropertyChanged(propertyName);
408+
return true;
409+
}
410+
411+
public event PropertyChangedEventHandler PropertyChanged;
412+
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
413+
{
414+
var changed = PropertyChanged;
415+
if (changed == null)
416+
return;
417+
418+
changed.Invoke(this, new PropertyChangedEventArgs(propertyName));
419+
}
420+
#endregion
381421
}
382422
}

0 commit comments

Comments
 (0)