Skip to content

Commit

Permalink
Add better content type via storage apis
Browse files Browse the repository at this point in the history
  • Loading branch information
SamChaps committed Feb 7, 2023
1 parent 4f8cf60 commit 4720f7b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Peek.Common.Models;
using Scripting;
using Windows.Foundation;
using Windows.Storage;

namespace Peek.Common.Extensions
{
Expand Down Expand Up @@ -41,12 +43,26 @@ public static ulong GetSizeInBytes(this IFileSystemItem item)
return sizeInBytes;
}

public static string GetContentType(this IFileSystemItem item)
public static async Task<string> GetContentTypeAsync(this IFileSystemItem item)
{
// TODO: find a way to get user friendly description
var propertyStore = item.PropertyStore;
var type = propertyStore.TryGetString(PropertyKey.FileType);
return type ?? string.Empty;
string contentType = string.Empty;

var storageItem = await item.GetStorageItemAsync();
switch (storageItem)
{
case StorageFile storageFile:
contentType = storageFile.DisplayType;
break;
case StorageFolder storageFolder:
contentType = storageFolder.DisplayType;
break;
default:
var propertyStore = item.PropertyStore;
contentType = propertyStore.TryGetString(PropertyKey.FileType) ?? string.Empty;
break;
}

return contentType;
}
}
}
2 changes: 1 addition & 1 deletion src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private async Task UpdateImageTooltipAsync(CancellationToken cancellationToken)
sb.Append(fileNameFormatted);

cancellationToken.ThrowIfCancellationRequested();
string fileType = await Task.Run(Item.GetContentType);
string fileType = await Task.Run(Item.GetContentTypeAsync);
string fileTypeFormatted = string.IsNullOrEmpty(fileType) ? string.Empty : "\n" + ReadableStringHelper.FormatResourceString("PreviewTooltip_FileType", fileType);
sb.Append(fileTypeFormatted);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public Task<bool> LoadDisplayInfoAsync(CancellationToken cancellationToken)
var bytes = await Task.Run(Item.GetSizeInBytes);
cancellationToken.ThrowIfCancellationRequested();
var type = await Task.Run(Item.GetContentType);
var type = await Task.Run(Item.GetContentTypeAsync);
await Dispatcher.RunOnUiThread(() =>
{
Expand Down

1 comment on commit 4720f7b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log for details.

Unrecognized words (13)
ALLVIEW
Chromakey
GETPROPERTYSTOREFLAGS
holemenu
IPalette
ipreview
pkey
ppshv
rbhid
SHCONTF
SHGDNF
SIATTRIBFLAGS
Strm
Previously acknowledged words that are now absent Asn BESTEFFORT BHIDSF Brotli clrcompression clretwrc clrgc clrjit Cng coreclr dbgshim DCompiler DELAYCREATION Dwma EXTRINSICPROPERTIESONLY FASTPROPERTIESONLY HANDLERPROPERTIESONLY hostfxr hostpolicy IIDI Imc Intrinsics IPREVIEW JSONOf Keybd LANGID mscordaccore mscordbi mscorrc msquic neighborings netstandard OPENSLOWITEM OPLOCK Pkcs PKEY PREFERQUERYPROPERTIES Previer psfi Quic rfid RTSS Shcontf Shgno Softcoded Ssl UMsg WMSDK wpfgfx WScan WVk zopfli :arrow_right:
Some files were automatically ignored

These sample patterns would exclude them:

^\Qsrc/modules/peek/Peek.Common/NativeMethods.txt\E$

You should consider adding them to:

.github/actions/spell-check/excludes.txt

File matching is via Perl regular expressions.

To check these files, more of their words need to be in the dictionary than not. You can use patterns.txt to exclude portions, add items to the dictionary (e.g. by adding them to allow.txt), or fix typos.

To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

... in a clone of the git@github.com:microsoft/PowerToys.git repository
on the sachaple/peek-folder-refactor branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.21/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/4119010019/attempts/1'
Available 📚 dictionaries could cover words not in the 📘 dictionary

This includes both expected items (2294) from .github/actions/spell-check/expect.txt and unrecognized words (13)

Dictionary Entries Covers
cspell:win32/src/win32.txt 53509 134
cspell:cpp/src/cpp.txt 30216 129
cspell:python/src/python/python-lib.txt 3873 32
cspell:php/php.txt 2597 17
cspell:node/node.txt 1768 13
cspell:typescript/typescript.txt 1211 12
cspell:python/src/python/python.txt 453 11
cspell:java/java.txt 7642 11
cspell:aws/aws.txt 218 8
cspell:python/src/common/extra.txt 741 7

Consider adding them using (in .github/workflows/spelling2.yml):

      with:
        extra_dictionaries:
          cspell:win32/src/win32.txt
          cspell:cpp/src/cpp.txt
          cspell:python/src/python/python-lib.txt
          cspell:php/php.txt
          cspell:node/node.txt
          cspell:typescript/typescript.txt
          cspell:python/src/python/python.txt
          cspell:java/java.txt
          cspell:aws/aws.txt
          cspell:python/src/common/extra.txt

To stop checking additional dictionaries, add:

      with:
        check_extra_dictionaries: ''
Warnings (1)

See the 📜action log for details.

ℹ️ Warnings Count
ℹ️ noisy-file 1

See ℹ️ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.