Skip to content

Commit b48e04f

Browse files
authored
Listen to size and date meta changes (#5992)
1 parent 4c363db commit b48e04f

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

Files/Filesystem/ListedItem.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,19 @@ public string ItemType
221221
}
222222

223223
public string FileExtension { get; set; }
224-
public string FileSize { get; set; }
224+
225+
private string fileSize;
226+
227+
public string FileSize
228+
{
229+
get => fileSize;
230+
set
231+
{
232+
SetProperty(ref fileSize, value);
233+
OnPropertyChanged(nameof(FileSizeDisplay));
234+
}
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(ItemDateCreated));
250264
}
251265
}
252266

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

Files/Helpers/NativeDirectoryChangesHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ 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;
5762

5863
public unsafe struct FILE_NOTIFY_INFORMATION
5964
{

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.IsOfType(StorageItemTypes.File))
2036+
{
2037+
var properties = await storageItem.AsBaseStorageFile().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.IsOfType(StorageItemTypes.Folder))
2044+
{
2045+
var properties = await storageItem.AsBaseStorageFolder().GetBasicPropertiesAsync();
2046+
item.ItemDateModifiedReal = properties.DateModified;
2047+
item.ItemDateCreatedReal = properties.ItemDate;
2048+
}
20342049
});
20352050
}
20362051
}

Files/Views/LayoutModes/GridViewBrowser.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@
357357
HorizontalAlignment="Left"
358358
Opacity="0.6"
359359
Style="{StaticResource CaptionTextBlockStyle}"
360-
Text="{x:Bind FileSize}"
360+
Text="{x:Bind FileSize, Mode=OneWay}"
361361
TextAlignment="Left"
362362
TextTrimming="CharacterEllipsis"
363363
TextWrapping="NoWrap" />

0 commit comments

Comments
 (0)