Skip to content

Commit

Permalink
Juliata/filetypes (#22538)
Browse files Browse the repository at this point in the history
* Using the same list of file extensions as Lightbox's AppxManifest, and ensuring we convert file extension to lowercase

* Add IsFileTypeSupported to IPreviewer

* respond to PR comments
  • Loading branch information
jth-ms authored Dec 7, 2022
1 parent 7392588 commit 6295ed8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/modules/peek/Peek.Common/Models/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public File(string path)

public string Path { get; init; }

public string Extension => System.IO.Path.GetExtension(Path);
public string Extension => System.IO.Path.GetExtension(Path).ToLower();

public async Task<StorageFile> GetStorageFileAsync()
{
Expand Down
3 changes: 3 additions & 0 deletions src/modules/peek/Peek.FilePreviewer/Previewers/IPreviewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Peek.FilePreviewer.Previewers
{
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Windows.Foundation;
Expand All @@ -12,6 +13,8 @@ public interface IPreviewer : INotifyPropertyChanged
{
bool IsPreviewLoaded { get; }

public static bool IsFileTypeSupported(string fileExt) => throw new NotImplementedException();

public Task<Size> GetPreviewSizeAsync();

Task LoadPreviewAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Peek.FilePreviewer.Previewers
{
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Threading;
Expand Down Expand Up @@ -174,5 +175,75 @@ private static async Task<BitmapSource> GetBitmapFromHBitmapAsync(IntPtr hbitmap
NativeMethods.DeleteObject(hbitmap);
}
}

public static bool IsFileTypeSupported(string fileExt)
{
return _supportedFileTypes.Contains(fileExt);
}

private static readonly HashSet<string> _supportedFileTypes = new HashSet<string>
{
// Image types
".bmp",
".gif",
".jpg",
".jfif",
".jfi",
".jif",
".jpeg",
".jpe",
".png",
".tif",
".tiff",
".dib",

// ".heic", // Error in System.Drawing.Image.FromHbitmap(hbitmap);
".heif",
".hif",
".avif",
".jxr",
".wdp",
".ico",
".thumb",

// Raw types
".arw",
".cr2",

// ".crw", // Error in WICImageFactory.CreateDecoderFromFilename
// ".erf", // Error in WICImageFactory.CreateDecoderFromFilename
".kdc",
".mrw",
".nef",
".nrw",
".orf",
".pef",
".raf",
".raw",
".rw2",
".rwl",
".sr2",
".srw",
".srf",
".dcs",
".dcr",
".drf",
".k25",
".3fr",
".ari",
".bay",
".cap",
".iiq",
".eip",
".fff",
".mef",
".mdc",
".mos",
".R3D",
".rwz",
".x3f",
".ori",
".cr3",
};
}
}
21 changes: 5 additions & 16 deletions src/modules/peek/Peek.FilePreviewer/Previewers/PreviewerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,13 @@ public class PreviewerFactory
{
public IPreviewer? Create(File file)
{
// TODO: investigate performance of reflection to resolve previewer type
switch (file.Extension)
if (ImagePreviewer.IsFileTypeSupported(file.Extension))
{
case ".bmp":
case ".gif":
case ".jpg":
case ".jfif":
case ".jfi":
case ".jif":
case ".jpeg":
case ".jpe":
case ".png":
case ".tif":
case ".tiff":
return new ImagePreviewer(file);
default:
return null;
return new ImagePreviewer(file);
}

// Other previewer types check their supported file types here
return null;
}
}
}

1 comment on commit 6295ed8

@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 (127)
apidl
ari
arw
BESTEFFORT
BHIDSF
BVal
calpwstr
CARRAY
CElems
Chromakey
cidl
crw
CVal
DANGEROUSLYCOMMITMERELYTODISKCACHE
dcr
dcs
Dct
Dds
DELAYCREATION
drf
Dwma
eip
Excep
EXCEPINFO
EXTRINSICPROPERTIES
EXTRINSICPROPERTIESONLY
FASTPROPERTIESONLY
filetime
HANDLERPROPERTIESONLY
HDR
hicon
hif
HVal
IBitmap
IBlock
IColor
icolumn
IContext
IDecoder
IEncoder
IEnum
IIDI
iiq
IMetadata
IPalette
IQuery
IReader
ISource
ISurface
ithumbnail
jfi
jif
kdc
Keybd
Lcid
LOCKBYTES
LOCKTYPE
LVal
mdc
mef
mrw
neighborings
NOOPEN
nrw
ONLYIFCURRENT
ONLYONCE
OPENSLOWITEM
OPLOCK
ori
overriden
pbgra
PBlob
pcch
pcelt
pcs
pef
PElems
pkey
ppenum
pprop
PREFERQUERYPROPERTIES
PRGBA
PROPERTYNOTFOUND
PROPVARIANT
pscid
psfi
pstatstg
pstm
pui
pvar
raf
retunred
rfid
RGBE
rgelt
rgf
rwl
rwz
sachaple
SAFEARRAY
SCID
Scode
Shcontf
SHELLDETAILS
Shgno
Softcoded
srf
SRGB
STGC
STGTY
Stroe
Strret
titlebar
tlbimp
toogle
UMsg
UOffset
USERDEFINED
UType
VARTYPE
VERSIONED
windowsapp
WMSDK
WReserved
WScan
WVk
YQuantized
Previously acknowledged words that are now absent brucelindbloom chromaticities companding DCR Eqn ffaa FILETIME HICON ITHUMBNAIL Pbgra PKEY Windowsapp :arrow_right:
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 [email protected]:microsoft/PowerToys.git repository
on the peek 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/3634949471/attempts/1'
Available 📚 dictionaries could cover words not in the 📘 dictionary

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

Dictionary Entries Covers
cspell:win32/src/win32.txt 53509 133
cspell:cpp/src/cpp.txt 30216 129
cspell:python/src/python/python-lib.txt 3873 31
cspell:php/php.txt 2597 17
cspell:node/node.txt 1768 14
cspell:typescript/typescript.txt 1211 12
cspell:java/java.txt 7642 11
cspell:python/src/python/python.txt 453 10
cspell:aws/aws.txt 218 8
cspell:r/src/r.txt 808 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:java/java.txt
          cspell:python/src/python/python.txt
          cspell:aws/aws.txt
          cspell:r/src/r.txt

To stop checking additional dictionaries, add:

      with:
        check_extra_dictionaries: ''
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.