Skip to content

Commit 4e67757

Browse files
committed
Listen to size and date meta changes
1 parent 649cb3e commit 4e67757

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

Files/Filesystem/ListedItem.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,20 @@ public string ItemType
220220
}
221221
}
222222

223-
public string FileExtension { get; set; }
224-
public string FileSize { get; set; }
223+
public string FileExtension
224+
{
225+
get => fileExtension;
226+
set => SetProperty(ref fileExtension, value);
227+
}
228+
public string FileSize
229+
{
230+
get => fileSize;
231+
set
232+
{
233+
SetProperty(ref fileSize, value);
234+
OnPropertyChanged(nameof(FileSizeDisplay));
235+
}
236+
}
225237
public string FileSizeDisplay => string.IsNullOrEmpty(FileSize) ? "ItemSizeNotCalcluated".GetLocalized() : FileSize;
226238
public long FileSizeBytes { get; set; }
227239
public string ItemDateModified { get; private set; }
@@ -235,6 +247,7 @@ public DateTimeOffset ItemDateModifiedReal
235247
{
236248
ItemDateModified = value.GetFriendlyDateFromFormat(DateReturnFormat);
237249
itemDateModifiedReal = value;
250+
OnPropertyChanged(nameof(ItemDateModified));
238251
}
239252
}
240253

@@ -247,6 +260,7 @@ public DateTimeOffset ItemDateCreatedReal
247260
{
248261
ItemDateCreated = value.GetFriendlyDateFromFormat(DateReturnFormat);
249262
itemDateCreatedReal = value;
263+
OnPropertyChanged(nameof(ItemDateCreatedReal));
250264
}
251265
}
252266

@@ -259,6 +273,7 @@ public DateTimeOffset ItemDateAccessedReal
259273
{
260274
ItemDateAccessed = value.GetFriendlyDateFromFormat(DateReturnFormat);
261275
itemDateAccessedReal = value;
276+
OnPropertyChanged(nameof(ItemDateAccessedReal));
262277
}
263278
}
264279

@@ -340,6 +355,8 @@ public override string ToString()
340355
public bool IsPinned => App.SidebarPinnedController.Model.FavoriteItems.Contains(itemPath);
341356

342357
private BaseStorageFile itemFile;
358+
private string fileExtension;
359+
private string fileSize;
343360

344361
public BaseStorageFile ItemFile
345362
{

Files/Helpers/NativeDirectoryChangesHelper.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public struct OffsetPair { public uint Offset; public uint OffsetHigh; }
5454
public const int FILE_NOTIFY_CHANGE_FILE_NAME = 1;
5555
public const int FILE_NOTIFY_CHANGE_DIR_NAME = 2;
5656
public const int FILE_NOTIFY_CHANGE_ATTRIBUTES = 4;
57+
public const int FILE_NOTIFY_CHANGE_SIZE = 8;
58+
public const int FILE_NOTIFY_CHANGE_LAST_WRITE = 16;
59+
public const int FILE_NOTIFY_CHANGE_LAST_ACCESS = 32;
60+
public const int FILE_NOTIFY_CHANGE_CREATION = 64;
61+
public const int FILE_NOTIFY_CHANGE_SECURITY = 256;
62+
5763

5864
public unsafe struct FILE_NOTIFY_INFORMATION
5965
{

Files/ViewModels/ItemViewModel.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,7 @@ private void WatchForDirectoryChanges(string path, CloudDriveSyncStatus syncStat
17151715
byte[] buff = new byte[4096];
17161716
var rand = Guid.NewGuid();
17171717
buff = new byte[4096];
1718-
int notifyFilters = FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_FILE_NAME;
1718+
int notifyFilters = FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE;
17191719

17201720
if (syncStatus != CloudDriveSyncStatus.NotSynced && syncStatus != CloudDriveSyncStatus.Unknown)
17211721
{
@@ -2028,9 +2028,24 @@ private async Task UpdateFileOrFolderAsync(ListedItem item)
20282028
if (storageItem != null)
20292029
{
20302030
var syncStatus = await CheckCloudDriveSyncStatusAsync(storageItem);
2031-
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() =>
2031+
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
20322032
{
20332033
item.SyncStatusUI = CloudDriveSyncStatusUI.FromCloudDriveSyncStatus(syncStatus);
2034+
2035+
if (storageItem is IStorageFile file)
2036+
{
2037+
var properties = await file.GetBasicPropertiesAsync();
2038+
item.FileSizeBytes = (long)properties.Size;
2039+
item.FileSize = ByteSizeLib.ByteSize.FromBytes(item.FileSizeBytes).ToBinaryString().ConvertSizeAbbreviation();
2040+
item.ItemDateModifiedReal = properties.DateModified;
2041+
item.ItemDateCreatedReal = properties.ItemDate;
2042+
}
2043+
else if (storageItem is IStorageFolder folder)
2044+
{
2045+
var properties = await folder.GetBasicPropertiesAsync();
2046+
item.ItemDateModifiedReal = properties.DateModified;
2047+
item.ItemDateCreatedReal = properties.ItemDate;
2048+
}
20342049
});
20352050
}
20362051
}

0 commit comments

Comments
 (0)