mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
[Peek]Fix preview for folders with dot in the name(#32085)
This commit is contained in:
committed by
GitHub
parent
0110d7d244
commit
0a316370d8
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using ManagedCommon;
|
||||
using Windows.Storage;
|
||||
@@ -25,6 +26,8 @@ namespace Peek.Common.Models
|
||||
|
||||
public string Path { get; init; }
|
||||
|
||||
public string Extension => System.IO.Path.GetExtension(Path).ToLower(CultureInfo.InvariantCulture);
|
||||
|
||||
public async Task<IStorageItem?> GetStorageItemAsync()
|
||||
{
|
||||
return await GetStorageFileAsync();
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace Peek.Common.Models
|
||||
|
||||
public string Path { get; init; }
|
||||
|
||||
public string Extension => string.Empty;
|
||||
|
||||
public async Task<IStorageItem?> GetStorageItemAsync()
|
||||
{
|
||||
return await GetStorageFolderAsync();
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using Peek.Common.Helpers;
|
||||
using Windows.Storage;
|
||||
@@ -32,7 +31,7 @@ namespace Peek.Common.Models
|
||||
}
|
||||
}
|
||||
|
||||
public string Extension => System.IO.Path.GetExtension(Path).ToLower(CultureInfo.InvariantCulture);
|
||||
public string Extension { get; }
|
||||
|
||||
public string Name { get; init; }
|
||||
|
||||
|
||||
@@ -111,9 +111,9 @@ namespace Peek.FilePreviewer.Previewers.Archives
|
||||
State = PreviewState.Loaded;
|
||||
}
|
||||
|
||||
public static bool IsFileTypeSupported(string fileExt)
|
||||
public static bool IsItemSupported(IFileSystemItem item)
|
||||
{
|
||||
return _supportedFileTypes.Contains(fileExt);
|
||||
return _supportedFileTypes.Contains(item.Extension);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -89,9 +89,9 @@ namespace Peek.FilePreviewer.Previewers.Drive
|
||||
State = PreviewState.Loaded;
|
||||
}
|
||||
|
||||
public static bool IsPathSupported(string path)
|
||||
public static bool IsItemSupported(IFileSystemItem item)
|
||||
{
|
||||
return DriveInfo.GetDrives().Any(d => d.Name == path);
|
||||
return DriveInfo.GetDrives().Any(d => d.Name == item.Path);
|
||||
}
|
||||
|
||||
private string GetDriveTypeDescription(DriveType driveType) => driveType switch
|
||||
|
||||
@@ -8,7 +8,7 @@ using Peek.FilePreviewer.Previewers.Archives.Models;
|
||||
|
||||
namespace Peek.FilePreviewer.Previewers.Interfaces
|
||||
{
|
||||
public interface IArchivePreviewer : IPreviewer, IDisposable
|
||||
public interface IArchivePreviewer : IPreviewer, IPreviewTarget, IDisposable
|
||||
{
|
||||
ObservableCollection<ArchiveItem> Tree { get; }
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using Peek.FilePreviewer.Previewers.MediaPreviewer.Models;
|
||||
|
||||
namespace Peek.FilePreviewer.Previewers.Interfaces
|
||||
{
|
||||
public interface IAudioPreviewer : IPreviewer
|
||||
public interface IAudioPreviewer : IPreviewer, IPreviewTarget
|
||||
{
|
||||
public AudioPreviewData? Preview { get; }
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace Peek.FilePreviewer.Previewers
|
||||
namespace Peek.FilePreviewer.Previewers.Interfaces
|
||||
{
|
||||
public interface IBrowserPreviewer : IPreviewer
|
||||
public interface IBrowserPreviewer : IPreviewer, IPreviewTarget
|
||||
{
|
||||
public Uri? Preview { get; }
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using Peek.FilePreviewer.Previewers.Drive.Models;
|
||||
|
||||
namespace Peek.FilePreviewer.Previewers.Interfaces
|
||||
{
|
||||
public interface IDrivePreviewer : IPreviewer
|
||||
public interface IDrivePreviewer : IPreviewer, IPreviewTarget
|
||||
{
|
||||
public DrivePreviewData? Preview { get; }
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using Windows.Foundation;
|
||||
|
||||
namespace Peek.FilePreviewer.Previewers.Interfaces
|
||||
{
|
||||
public interface IImagePreviewer : IPreviewer
|
||||
public interface IImagePreviewer : IPreviewer, IPreviewTarget
|
||||
{
|
||||
public ImageSource? Preview { get; }
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// 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 Peek.Common.Models;
|
||||
|
||||
namespace Peek.FilePreviewer.Previewers.Interfaces
|
||||
{
|
||||
public interface IPreviewTarget
|
||||
{
|
||||
static abstract bool IsItemSupported(IFileSystemItem item);
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,10 @@
|
||||
// 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.ComponentModel;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Peek.FilePreviewer.Models;
|
||||
using Windows.Foundation;
|
||||
|
||||
namespace Peek.FilePreviewer.Previewers
|
||||
{
|
||||
@@ -15,8 +13,6 @@ namespace Peek.FilePreviewer.Previewers
|
||||
{
|
||||
PreviewState State { get; set; }
|
||||
|
||||
public static bool IsFileTypeSupported(string fileExt) => throw new NotImplementedException();
|
||||
|
||||
public Task<PreviewSize> GetPreviewSizeAsync(CancellationToken cancellationToken);
|
||||
|
||||
Task LoadPreviewAsync(CancellationToken cancellationToken);
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
using Windows.Win32.UI.Shell;
|
||||
|
||||
namespace Peek.FilePreviewer.Previewers
|
||||
namespace Peek.FilePreviewer.Previewers.Interfaces
|
||||
{
|
||||
public interface IShellPreviewHandlerPreviewer : IPreviewer
|
||||
public interface IShellPreviewHandlerPreviewer : IPreviewer, IPreviewTarget
|
||||
{
|
||||
public IPreviewHandler? Preview { get; }
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using Windows.Media.Core;
|
||||
|
||||
namespace Peek.FilePreviewer.Previewers.Interfaces
|
||||
{
|
||||
public interface IVideoPreviewer : IPreviewer
|
||||
public interface IVideoPreviewer : IPreviewer, IPreviewTarget
|
||||
{
|
||||
public MediaSource? Preview { get; }
|
||||
}
|
||||
|
||||
@@ -154,9 +154,9 @@ namespace Peek.FilePreviewer.Previewers.MediaPreviewer
|
||||
});
|
||||
}
|
||||
|
||||
public static bool IsFileTypeSupported(string fileExt)
|
||||
public static bool IsItemSupported(IFileSystemItem item)
|
||||
{
|
||||
return _supportedFileTypes.Contains(fileExt);
|
||||
return _supportedFileTypes.Contains(item.Extension);
|
||||
}
|
||||
|
||||
private static readonly HashSet<string> _supportedFileTypes = new()
|
||||
|
||||
@@ -70,9 +70,9 @@ namespace Peek.FilePreviewer.Previewers
|
||||
|
||||
private ImageSource? highQualityThumbnailPreview;
|
||||
|
||||
public static bool IsFileTypeSupported(string fileExt)
|
||||
public static bool IsItemSupported(IFileSystemItem item)
|
||||
{
|
||||
return _supportedFileTypes.Contains(fileExt);
|
||||
return _supportedFileTypes.Contains(item.Extension);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -42,9 +42,9 @@ namespace Peek.FilePreviewer.Previewers
|
||||
|
||||
private Task<bool>? VideoTask { get; set; }
|
||||
|
||||
public static bool IsFileTypeSupported(string fileExt)
|
||||
public static bool IsItemSupported(IFileSystemItem item)
|
||||
{
|
||||
return _supportedFileTypes.Contains(fileExt);
|
||||
return _supportedFileTypes.Contains(item.Extension);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -23,39 +23,39 @@ namespace Peek.FilePreviewer.Previewers
|
||||
_previewSettings = Application.Current.GetService<IPreviewSettings>();
|
||||
}
|
||||
|
||||
public IPreviewer Create(IFileSystemItem file)
|
||||
public IPreviewer Create(IFileSystemItem item)
|
||||
{
|
||||
if (ImagePreviewer.IsFileTypeSupported(file.Extension))
|
||||
if (ImagePreviewer.IsItemSupported(item))
|
||||
{
|
||||
return new ImagePreviewer(file);
|
||||
return new ImagePreviewer(item);
|
||||
}
|
||||
else if (VideoPreviewer.IsFileTypeSupported(file.Extension))
|
||||
else if (VideoPreviewer.IsItemSupported(item))
|
||||
{
|
||||
return new VideoPreviewer(file);
|
||||
return new VideoPreviewer(item);
|
||||
}
|
||||
else if (AudioPreviewer.IsFileTypeSupported(file.Extension))
|
||||
else if (AudioPreviewer.IsItemSupported(item))
|
||||
{
|
||||
return new AudioPreviewer(file);
|
||||
return new AudioPreviewer(item);
|
||||
}
|
||||
else if (WebBrowserPreviewer.IsFileTypeSupported(file.Extension))
|
||||
else if (WebBrowserPreviewer.IsItemSupported(item))
|
||||
{
|
||||
return new WebBrowserPreviewer(file, _previewSettings);
|
||||
return new WebBrowserPreviewer(item, _previewSettings);
|
||||
}
|
||||
else if (ArchivePreviewer.IsFileTypeSupported(file.Extension))
|
||||
else if (ArchivePreviewer.IsItemSupported(item))
|
||||
{
|
||||
return new ArchivePreviewer(file);
|
||||
return new ArchivePreviewer(item);
|
||||
}
|
||||
else if (ShellPreviewHandlerPreviewer.IsFileTypeSupported(file.Extension))
|
||||
else if (ShellPreviewHandlerPreviewer.IsItemSupported(item))
|
||||
{
|
||||
return new ShellPreviewHandlerPreviewer(file);
|
||||
return new ShellPreviewHandlerPreviewer(item);
|
||||
}
|
||||
else if (DrivePreviewer.IsPathSupported(file.Path))
|
||||
else if (DrivePreviewer.IsItemSupported(item))
|
||||
{
|
||||
return new DrivePreviewer(file);
|
||||
return new DrivePreviewer(item);
|
||||
}
|
||||
|
||||
// Other previewer types check their supported file types here
|
||||
return CreateDefaultPreviewer(file);
|
||||
return CreateDefaultPreviewer(item);
|
||||
}
|
||||
|
||||
public IPreviewer CreateDefaultPreviewer(IFileSystemItem file)
|
||||
|
||||
@@ -16,6 +16,7 @@ using Peek.Common.Helpers;
|
||||
using Peek.Common.Models;
|
||||
using Peek.FilePreviewer.Models;
|
||||
using Peek.FilePreviewer.Previewers.Helpers;
|
||||
using Peek.FilePreviewer.Previewers.Interfaces;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.System.Com;
|
||||
using Windows.Win32.UI.Shell;
|
||||
@@ -205,9 +206,9 @@ namespace Peek.FilePreviewer.Previewers
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsFileTypeSupported(string fileExt)
|
||||
public static bool IsItemSupported(IFileSystemItem item)
|
||||
{
|
||||
return !string.IsNullOrEmpty(GetPreviewHandlerGuid(fileExt));
|
||||
return !string.IsNullOrEmpty(GetPreviewHandlerGuid(item.Extension));
|
||||
}
|
||||
|
||||
private static string? GetPreviewHandlerGuid(string fileExt)
|
||||
|
||||
@@ -13,6 +13,7 @@ using Peek.Common.Extensions;
|
||||
using Peek.Common.Helpers;
|
||||
using Peek.Common.Models;
|
||||
using Peek.FilePreviewer.Models;
|
||||
using Peek.FilePreviewer.Previewers.Interfaces;
|
||||
|
||||
namespace Peek.FilePreviewer.Previewers
|
||||
{
|
||||
@@ -137,9 +138,9 @@ namespace Peek.FilePreviewer.Previewers
|
||||
});
|
||||
}
|
||||
|
||||
public static bool IsFileTypeSupported(string fileExt)
|
||||
public static bool IsItemSupported(IFileSystemItem item)
|
||||
{
|
||||
return _supportedFileTypes.Contains(fileExt) || MonacoHelper.SupportedMonacoFileTypes.Contains(fileExt);
|
||||
return _supportedFileTypes.Contains(item.Extension) || MonacoHelper.SupportedMonacoFileTypes.Contains(item.Extension);
|
||||
}
|
||||
|
||||
private bool HasFailedLoadingPreview()
|
||||
|
||||
Reference in New Issue
Block a user