-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Peek] Refactoring of file system models, removal of PngPreviewer, re…
…trieving of folder size via Scripting com reference and other fixes (#23955) * Refactor icon retrieval, refactor hbitmap to bitmap conversion, add icon fallback * Add svg to assets in installer * - Refactor File class into IFileSystemItem, FileItem & FolderItem - Display size for folders using Scripting namespace - Remove default app buttons for files or folders not supporting it * Add better content type via storage apis * Add check for storagefile in PngPreviewer * Fix png stretching * Remove png previewer * Rename ThumbnailOptions.None to ThumbnailOptions.ResizeToFit
- Loading branch information
Showing
42 changed files
with
456 additions
and
488 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/modules/peek/Peek.Common/Extensions/IFileSystemItemExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// 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 | ||
{ | ||
public static class IFileSystemItemExtensions | ||
{ | ||
public static Size GetImageSize(this IFileSystemItem item) | ||
{ | ||
var propertyStore = item.PropertyStore; | ||
var width = propertyStore.TryGetUInt(PropertyKey.ImageHorizontalSize) ?? 0; | ||
var height = propertyStore.TryGetUInt(PropertyKey.ImageVerticalSize) ?? 0; | ||
|
||
var size = new Size((int)width, (int)height); | ||
|
||
return size; | ||
} | ||
|
||
public static ulong GetSizeInBytes(this IFileSystemItem item) | ||
{ | ||
ulong sizeInBytes = 0; | ||
|
||
switch (item) | ||
{ | ||
case FolderItem _: | ||
FileSystemObject fileSystemObject = new FileSystemObject(); | ||
Folder folder = fileSystemObject.GetFolder(item.Path); | ||
sizeInBytes = (ulong)folder.Size; | ||
break; | ||
case FileItem _: | ||
var propertyStore = item.PropertyStore; | ||
sizeInBytes = propertyStore.TryGetULong(PropertyKey.FileSizeBytes) ?? 0; | ||
break; | ||
} | ||
|
||
return sizeInBytes; | ||
} | ||
|
||
public static async Task<string> GetContentTypeAsync(this IFileSystemItem item) | ||
{ | ||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Windows.ApplicationModel.DataTransfer; | ||
using Windows.Storage; | ||
using Windows.Storage.Streams; | ||
|
||
namespace Peek.Common.Helpers | ||
{ | ||
public static class ClipboardHelper | ||
{ | ||
public static void SaveToClipboard(IStorageItem? storageItem) | ||
{ | ||
if (storageItem == null) | ||
{ | ||
return; | ||
} | ||
|
||
var dataPackage = new DataPackage(); | ||
dataPackage.SetStorageItems(new IStorageItem[1] { storageItem }, false); | ||
|
||
if (storageItem is StorageFile storageFile) | ||
{ | ||
RandomAccessStreamReference imageStreamRef = RandomAccessStreamReference.CreateFromFile(storageFile); | ||
dataPackage.Properties.Thumbnail = imageStreamRef; | ||
dataPackage.SetBitmap(imageStreamRef); | ||
} | ||
|
||
Clipboard.SetContent(dataPackage); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// 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; | ||
using System.Threading.Tasks; | ||
using Peek.Common.Helpers; | ||
using Windows.Storage; | ||
|
||
#nullable enable | ||
|
||
namespace Peek.Common.Models | ||
{ | ||
public class FileItem : IFileSystemItem | ||
{ | ||
private StorageFile? storageFile; | ||
|
||
private Lazy<IPropertyStore> _propertyStore; | ||
|
||
public FileItem(string path) | ||
{ | ||
Path = path; | ||
_propertyStore = new(() => PropertyStoreHelper.GetPropertyStoreFromPath(Path)); | ||
} | ||
|
||
public string Path { get; init; } | ||
|
||
public IPropertyStore PropertyStore => _propertyStore.Value; | ||
|
||
public async Task<IStorageItem?> GetStorageItemAsync() | ||
{ | ||
return await GetStorageFileAsync(); | ||
} | ||
|
||
public async Task<StorageFile?> GetStorageFileAsync() | ||
{ | ||
if (storageFile == null) | ||
{ | ||
try | ||
{ | ||
storageFile = await StorageFile.GetFileFromPathAsync(Path); | ||
} | ||
catch (Exception) | ||
{ | ||
storageFile = null; | ||
} | ||
} | ||
|
||
return storageFile; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// 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; | ||
using System.Threading.Tasks; | ||
using Peek.Common.Helpers; | ||
using Windows.Storage; | ||
|
||
#nullable enable | ||
|
||
namespace Peek.Common.Models | ||
{ | ||
public class FolderItem : IFileSystemItem | ||
{ | ||
private StorageFolder? storageFolder; | ||
|
||
private Lazy<IPropertyStore> _propertyStore; | ||
|
||
public FolderItem(string path) | ||
{ | ||
Path = path; | ||
_propertyStore = new(() => PropertyStoreHelper.GetPropertyStoreFromPath(Path)); | ||
} | ||
|
||
public string Path { get; init; } | ||
|
||
public IPropertyStore PropertyStore => _propertyStore.Value; | ||
|
||
public async Task<IStorageItem?> GetStorageItemAsync() | ||
{ | ||
return await GetStorageFolderAsync(); | ||
} | ||
|
||
public async Task<StorageFolder?> GetStorageFolderAsync() | ||
{ | ||
if (storageFolder == null) | ||
{ | ||
try | ||
{ | ||
storageFolder = await StorageFolder.GetFolderFromPathAsync(Path); | ||
} | ||
catch (Exception) | ||
{ | ||
storageFolder = null; | ||
} | ||
} | ||
|
||
return storageFolder; | ||
} | ||
} | ||
} |
Oops, something went wrong.
e7b62a5
There was a problem hiding this comment.
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)
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:
You should consider adding them to:
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 toallow.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
peek
branch (ℹ️ how do I use this?):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)
Consider adding them using (in
.github/workflows/spelling2.yml
):To stop checking additional dictionaries, add:
Warnings (1)
See the 📜action log for details.
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.