Skip to content

Listen to size and date meta changes #5992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Files/Filesystem/ListedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,19 @@ public string ItemType
}

public string FileExtension { get; set; }
public string FileSize { get; set; }

private string fileSize;

public string FileSize
{
get => fileSize;
set
{
SetProperty(ref fileSize, value);
OnPropertyChanged(nameof(FileSizeDisplay));
}
}

public string FileSizeDisplay => string.IsNullOrEmpty(FileSize) ? "ItemSizeNotCalcluated".GetLocalized() : FileSize;
public long FileSizeBytes { get; set; }
public string ItemDateModified { get; private set; }
Expand All @@ -235,6 +247,7 @@ public DateTimeOffset ItemDateModifiedReal
{
ItemDateModified = value.GetFriendlyDateFromFormat(DateReturnFormat);
itemDateModifiedReal = value;
OnPropertyChanged(nameof(ItemDateModified));
}
}

Expand All @@ -247,6 +260,7 @@ public DateTimeOffset ItemDateCreatedReal
{
ItemDateCreated = value.GetFriendlyDateFromFormat(DateReturnFormat);
itemDateCreatedReal = value;
OnPropertyChanged(nameof(ItemDateCreated));
}
}

Expand All @@ -259,6 +273,7 @@ public DateTimeOffset ItemDateAccessedReal
{
ItemDateAccessed = value.GetFriendlyDateFromFormat(DateReturnFormat);
itemDateAccessedReal = value;
OnPropertyChanged(nameof(ItemDateAccessed));
}
}

Expand Down
5 changes: 5 additions & 0 deletions Files/Helpers/NativeDirectoryChangesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public struct OffsetPair { public uint Offset; public uint OffsetHigh; }
public const int FILE_NOTIFY_CHANGE_FILE_NAME = 1;
public const int FILE_NOTIFY_CHANGE_DIR_NAME = 2;
public const int FILE_NOTIFY_CHANGE_ATTRIBUTES = 4;
public const int FILE_NOTIFY_CHANGE_SIZE = 8;
public const int FILE_NOTIFY_CHANGE_LAST_WRITE = 16;
public const int FILE_NOTIFY_CHANGE_LAST_ACCESS = 32;
public const int FILE_NOTIFY_CHANGE_CREATION = 64;
public const int FILE_NOTIFY_CHANGE_SECURITY = 256;

public unsafe struct FILE_NOTIFY_INFORMATION
{
Expand Down
19 changes: 17 additions & 2 deletions Files/ViewModels/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ private void WatchForDirectoryChanges(string path, CloudDriveSyncStatus syncStat
byte[] buff = new byte[4096];
var rand = Guid.NewGuid();
buff = new byte[4096];
int notifyFilters = FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_FILE_NAME;
int notifyFilters = FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE;

if (syncStatus != CloudDriveSyncStatus.NotSynced && syncStatus != CloudDriveSyncStatus.Unknown)
{
Expand Down Expand Up @@ -2028,9 +2028,24 @@ private async Task UpdateFileOrFolderAsync(ListedItem item)
if (storageItem != null)
{
var syncStatus = await CheckCloudDriveSyncStatusAsync(storageItem);
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() =>
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
{
item.SyncStatusUI = CloudDriveSyncStatusUI.FromCloudDriveSyncStatus(syncStatus);

if (storageItem.IsOfType(StorageItemTypes.File))
{
var properties = await storageItem.AsBaseStorageFile().GetBasicPropertiesAsync();
item.FileSizeBytes = (long)properties.Size;
item.FileSize = ByteSizeLib.ByteSize.FromBytes(item.FileSizeBytes).ToBinaryString().ConvertSizeAbbreviation();
item.ItemDateModifiedReal = properties.DateModified;
item.ItemDateCreatedReal = properties.ItemDate;
}
else if (storageItem.IsOfType(StorageItemTypes.Folder))
{
var properties = await storageItem.AsBaseStorageFolder().GetBasicPropertiesAsync();
item.ItemDateModifiedReal = properties.DateModified;
item.ItemDateCreatedReal = properties.ItemDate;
}
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion Files/Views/LayoutModes/GridViewBrowser.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
HorizontalAlignment="Left"
Opacity="0.6"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind FileSize}"
Text="{x:Bind FileSize, Mode=OneWay}"
TextAlignment="Left"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap" />
Expand Down