|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
| 3 | +using System.ComponentModel; |
3 | 4 | using System.Diagnostics; |
4 | 5 | using System.IO; |
| 6 | +using System.Runtime.CompilerServices; |
5 | 7 |
|
6 | 8 | namespace PassXYZLib |
7 | 9 | { |
@@ -112,6 +114,22 @@ public static string BakFilePath |
112 | 114 | } |
113 | 115 | } |
114 | 116 |
|
| 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 | + |
115 | 133 | /// <summary> |
116 | 134 | /// Decode the username from filename |
117 | 135 | /// </summary> |
@@ -151,7 +169,7 @@ public static string GetUserName(string fileName) |
151 | 169 |
|
152 | 170 | } |
153 | 171 |
|
154 | | - public class User |
| 172 | + public class User : INotifyPropertyChanged |
155 | 173 | { |
156 | 174 | private string _username = string.Empty; |
157 | 175 | /// <summary> |
@@ -254,10 +272,7 @@ public bool IsKeyFileExist |
254 | 272 | /// <summary> |
255 | 273 | /// The date/time when this user was last accessed (read). |
256 | 274 | /// </summary> |
257 | | - public DateTime LastAccessTime |
258 | | - { |
259 | | - get { return File.GetLastAccessTime(this.Path); } |
260 | | - } |
| 275 | + public DateTime LastAccessTime => File.GetLastWriteTime(this.Path); |
261 | 276 |
|
262 | 277 | /// <summary> |
263 | 278 | /// Data file name. Converted Username to file name |
@@ -321,10 +336,10 @@ public string KeyFilePath |
321 | 336 | /// <summary> |
322 | 337 | /// Delete the current user |
323 | 338 | /// </summary> |
324 | | - public void Delete() |
| 339 | + public void Delete() |
325 | 340 | { |
326 | 341 | File.Delete(Path); |
327 | | - if (IsDeviceLockEnabled) |
| 342 | + if (IsDeviceLockEnabled) |
328 | 343 | { |
329 | 344 | File.Delete(KeyFilePath); |
330 | 345 | } |
@@ -378,5 +393,30 @@ public User() |
378 | 393 | { |
379 | 394 | IsDeviceLockEnabled = false; |
380 | 395 | } |
| 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 |
381 | 421 | } |
382 | 422 | } |
0 commit comments