Skip to content

Commit 5a59be5

Browse files
committed
Context
1 parent a08ccba commit 5a59be5

File tree

4 files changed

+68
-48
lines changed

4 files changed

+68
-48
lines changed

src/Files.App/Data/Items/ListedItem.cs

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using FluentFTP;
77
using Microsoft.UI.Xaml;
88
using Microsoft.UI.Xaml.Media.Imaging;
9-
using System.Drawing;
109
using System.IO;
1110
using System.Text;
1211
using Windows.Storage;
@@ -47,8 +46,8 @@ public string ItemTooltipText
4746
tooltipBuilder.Append($"{"ToolTipDescriptionDate".GetLocalizedResource()} {ItemDateModified}");
4847
if (!string.IsNullOrWhiteSpace(FileSize))
4948
tooltipBuilder.Append($"{Environment.NewLine}{"SizeLabel".GetLocalizedResource()} {FileSize}");
50-
if (SyncStatusUI.SyncStatus is not CloudDriveSyncStatus.FileOnline and not CloudDriveSyncStatus.FolderOnline && !string.IsNullOrWhiteSpace(DimensionsDisplay))
51-
tooltipBuilder.Append($"{Environment.NewLine}{"PropertyDimensionsColon".GetLocalizedResource()} {DimensionsDisplay}");
49+
if (!string.IsNullOrWhiteSpace(ImageDimensions))
50+
tooltipBuilder.Append($"{Environment.NewLine}{"PropertyDimensionsColon".GetLocalizedResource()} {ImageDimensions}");
5251
if (SyncStatusUI.LoadSyncStatus)
5352
tooltipBuilder.Append($"{Environment.NewLine}{"StatusWithColon".GetLocalizedResource()} {syncStatusUI.SyncStatusString}");
5453

@@ -330,57 +329,36 @@ public ObservableCollection<FileProperty> ItemProperties
330329
set => SetProperty(ref itemProperties, value);
331330
}
332331

333-
public string DimensionsDisplay
332+
private string imageDimensions;
333+
public string ImageDimensions
334334
{
335-
get
336-
{
337-
int imageHeight = 0;
338-
int imageWidth = 0;
339-
340-
var isImageFile = FileExtensionHelpers.IsImageFile(FileExtension);
341-
if (isImageFile)
342-
{
343-
try
344-
{
345-
// TODO: Switch to use 'System.Kind' instead.
346-
using FileStream fileStream = new(ItemPath, FileMode.Open, FileAccess.Read, FileShare.Read);
347-
using Image image = Image.FromStream(fileStream, false, false);
348-
349-
if (image is not null)
350-
{
351-
imageHeight = image.Height;
352-
imageWidth = image.Width;
353-
}
354-
}
355-
catch { }
356-
}
335+
get => imageDimensions;
336+
set => SetProperty(ref imageDimensions, value);
337+
}
357338

339+
private string fileVersion;
340+
public string FileVersion
341+
{
342+
get => fileVersion;
343+
set => SetProperty(ref fileVersion, value);
344+
}
358345

359-
return
360-
isImageFile &&
361-
imageWidth > 0 &&
362-
imageHeight > 0
363-
? $"{imageWidth} \u00D7 {imageHeight}"
364-
: string.Empty;
365-
}
346+
private string mediaDuration;
347+
public string MediaDuration
348+
{
349+
get => mediaDuration;
350+
set => SetProperty(ref mediaDuration, value);
366351
}
367352

368353
/// <summary>
369-
/// Contextual property that changes based on the item type
354+
/// Contextual property that changes based on the item type.
370355
/// </summary>
371-
public string ContextualPropertyString => FileExtension switch
372-
{
373-
// Image files are on hold until DimensionsDisplay switches to 'System.Kind', otherwise it causes OneDrive files to be downloaded.
374-
// Images
375-
//_ when FileExtensionHelpers.IsImageFile(FileExtension) => !string.IsNullOrEmpty(DimensionsDisplay)
376-
// ? $"{Strings.PropertyDimensions.GetLocalizedResource()}: {DimensionsDisplay}"
377-
// : string.Empty,
378-
379-
// Other file formats
380-
_ => !string.IsNullOrEmpty(ItemDateModified)
381-
? $"{Strings.Modified.GetLocalizedResource()}: {ItemDateModified}"
382-
: string.Empty
383-
};
356+
private string contextualProperty;
357+
public string ContextualProperty
358+
{
359+
get => contextualProperty;
360+
set => SetProperty(ref contextualProperty, value);
361+
}
384362

385363
/// <summary>
386364
/// Initializes a new instance of the <see cref="ListedItem" /> class.

src/Files.App/ViewModels/ShellViewModel.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ public async Task LoadExtendedItemPropertiesAsync(ListedItem item)
11411141
var fileFRN = await FileTagsHelper.GetFileFRN(matchingStorageFile);
11421142
var fileTag = FileTagsHelper.ReadFileTag(item.ItemPath);
11431143
var itemType = (item.ItemType == "Folder".GetLocalizedResource()) ? item.ItemType : matchingStorageFile.DisplayType;
1144+
var extraProperties = await GetExtraProperties(matchingStorageFile);
11441145

11451146
cts.Token.ThrowIfCancellationRequested();
11461147

@@ -1152,6 +1153,27 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() =>
11521153
item.FileFRN = fileFRN;
11531154
item.FileTags = fileTag;
11541155
item.IsElevationRequired = CheckElevationRights(item);
1156+
item.ImageDimensions = extraProperties?.Result["System.Image.Dimensions"]?.ToString() ?? string.Empty;
1157+
item.FileVersion = extraProperties?.Result["System.FileVersion"]?.ToString() ?? string.Empty;
1158+
item.MediaDuration = ulong.TryParse(extraProperties?.Result["System.Media.Duration"]?.ToString(), out ulong duration)
1159+
? TimeSpan.FromTicks((long)duration).ToString(@"hh\:mm\:ss")
1160+
: string.Empty;
1161+
1162+
switch (true)
1163+
{
1164+
case var _ when !string.IsNullOrEmpty(item.ImageDimensions):
1165+
item.ContextualProperty = $"{Strings.PropertyDimensions.GetLocalizedResource()}: {item.ImageDimensions}";
1166+
break;
1167+
case var _ when !string.IsNullOrEmpty(item.MediaDuration):
1168+
item.ContextualProperty = $"{Strings.PropertyDuration.GetLocalizedResource()}: {item.MediaDuration}";
1169+
break;
1170+
case var _ when !string.IsNullOrEmpty(item.FileVersion):
1171+
item.ContextualProperty = $"{Strings.PropertyVersion.GetLocalizedResource()}: {item.FileVersion}";
1172+
break;
1173+
default:
1174+
item.ContextualProperty = $"{Strings.Modified.GetLocalizedResource()}: {item.ItemDateModified}";
1175+
break;
1176+
}
11551177
},
11561178
Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
11571179

@@ -1187,6 +1209,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() =>
11871209
var fileFRN = await FileTagsHelper.GetFileFRN(matchingStorageFolder);
11881210
var fileTag = FileTagsHelper.ReadFileTag(item.ItemPath);
11891211
var itemType = (item.ItemType == "Folder".GetLocalizedResource()) ? item.ItemType : matchingStorageFolder.DisplayType;
1212+
11901213
cts.Token.ThrowIfCancellationRequested();
11911214

11921215
await dispatcherQueue.EnqueueOrInvokeAsync(() =>
@@ -1196,6 +1219,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() =>
11961219
item.SyncStatusUI = CloudDriveSyncStatusUI.FromCloudDriveSyncStatus(syncStatus);
11971220
item.FileFRN = fileFRN;
11981221
item.FileTags = fileTag;
1222+
item.ContextualProperty = $"{Strings.Modified.GetLocalizedResource()}: {item.ItemDateModified}";
11991223
},
12001224
Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
12011225

@@ -1908,6 +1932,14 @@ public async Task<CloudDriveSyncStatus> CheckCloudDriveSyncStatusAsync(IStorageI
19081932
return (CloudDriveSyncStatus)syncStatus;
19091933
}
19101934

1935+
private async Task<FilesystemResult<IDictionary<string, object>>?> GetExtraProperties(IStorageItem matchingStorageItem)
1936+
{
1937+
if (matchingStorageItem is BaseStorageFile file && file.Properties != null)
1938+
return await FilesystemTasks.Wrap(() => file.Properties.RetrievePropertiesAsync(["System.Image.Dimensions", "System.Media.Duration", "System.FileVersion"]).AsTask());
1939+
1940+
return null;
1941+
}
1942+
19111943
private async Task WatchForStorageFolderChangesAsync(BaseStorageFolder? rootFolder)
19121944
{
19131945
if (rootFolder is null)

src/Files.App/Views/Layouts/GridLayoutPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@
607607
<TextBlock
608608
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
609609
Style="{ThemeResource CaptionTextBlockStyle}"
610-
Text="{x:Bind ContextualPropertyString, Mode=OneWay}"
610+
Text="{x:Bind ContextualProperty, Mode=OneWay}"
611611
TextTrimming="CharacterEllipsis"
612612
TextWrapping="NoWrap"
613613
Visibility="{Binding ElementName=PageRoot, Path=CardsViewShowContextualProperty, Mode=OneWay}" />

src/Files.Shared/Helpers/FileExtensionHelpers.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ public static bool IsScriptFile(string? filePathToCheck)
256256
{
257257
return HasExtension(filePathToCheck, ".py", ".ahk");
258258
}
259+
260+
/// <summary>
261+
/// Check if the file extension is a system file.
262+
/// </summary>
263+
/// <param name="filePathToCheck"></param>
264+
/// <returns><c>true</c> if the filePathToCheck is a system file; otherwise, <c>false</c>.</returns>
265+
public static bool IsSystemFile(string? filePathToCheck)
266+
{
267+
return HasExtension(filePathToCheck, ".dll", ".exe", ".sys", ".inf");
268+
}
259269

260270
}
261271
}

0 commit comments

Comments
 (0)