From e50e6771832d838f0b339318fe49115b0101c619 Mon Sep 17 00:00:00 2001
From: Lamparter <71598437+Lamparter@users.noreply.github.com>
Date: Sun, 11 Jan 2026 19:20:24 +0000
Subject: [PATCH 1/8] Unify extension helpers
---
Directory.Packages.props | 3 +-
.../Helpers/Layout/AdaptiveLayoutHelpers.cs | 2 +-
.../UserControls/InfoPaneViewModel.cs | 10 +-
.../Previews/CodePreviewViewModel.cs | 45 +----
.../Previews/HtmlPreviewViewModel.cs | 5 +-
.../Previews/ImagePreviewViewModel.cs | 6 +-
.../Previews/MarkdownPreviewViewModel.cs | 2 +-
.../Previews/PDFPreviewViewModel.cs | 5 +-
.../Previews/RichTextPreviewViewModel.cs | 2 +-
.../Previews/TextPreviewViewModel.cs | 2 +-
src/Files.Shared/Files.Shared.csproj | 1 +
.../Helpers/FileExtensionHelpers.cs | 174 +++++++++++++-----
12 files changed, 151 insertions(+), 106 deletions(-)
diff --git a/Directory.Packages.props b/Directory.Packages.props
index 8f93ac00c6da..48315f9a0030 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -1,10 +1,11 @@
-
+
true
+
diff --git a/src/Files.App/Helpers/Layout/AdaptiveLayoutHelpers.cs b/src/Files.App/Helpers/Layout/AdaptiveLayoutHelpers.cs
index ffc58fabc491..ab142931a291 100644
--- a/src/Files.App/Helpers/Layout/AdaptiveLayoutHelpers.cs
+++ b/src/Files.App/Helpers/Layout/AdaptiveLayoutHelpers.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Files Community
+// Copyright (c) Files Community
// Licensed under the MIT License.
using Files.App.ViewModels.Previews;
diff --git a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs
index 40eaf90c9bec..971959c8c36a 100644
--- a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs
+++ b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Files Community
+// Copyright (c) Files Community
// Licensed under the MIT License.
using Files.App.UserControls.FilePreviews;
@@ -319,7 +319,7 @@ private async Task GetBuiltInPreviewControlAsync(ListedItem item, b
return new MarkdownPreview(model);
}
- if (ImagePreviewViewModel.ContainsExtension(ext))
+ if (FileExtensionHelpers.IsImageFile(ext))
{
var model = new ImagePreviewViewModel(item);
await model.LoadAsync();
@@ -335,7 +335,7 @@ private async Task GetBuiltInPreviewControlAsync(ListedItem item, b
return new TextPreview(model);
}
- /*if (PDFPreviewViewModel.ContainsExtension(ext))
+ /*if (FileExtensionHelpers.IsPdfFile(ext))
{
var model = new PDFPreviewViewModel(item);
await model.LoadAsync();
@@ -343,7 +343,7 @@ private async Task GetBuiltInPreviewControlAsync(ListedItem item, b
return new PDFPreview(model);
}*/
- /*if (HtmlPreviewViewModel.ContainsExtension(ext))
+ /*if (FileExtensionHelpers.IsHtmlFile(ext))
{
var model = new HtmlPreviewViewModel(item);
await model.LoadAsync();
@@ -359,7 +359,7 @@ private async Task GetBuiltInPreviewControlAsync(ListedItem item, b
return new RichTextPreview(model);
}
- if (CodePreviewViewModel.ContainsExtension(ext))
+ if (FileExtensionHelpers.IsCodeFile(ext))
{
var model = new CodePreviewViewModel(item);
await model.LoadAsync();
diff --git a/src/Files.App/ViewModels/UserControls/Previews/CodePreviewViewModel.cs b/src/Files.App/ViewModels/UserControls/Previews/CodePreviewViewModel.cs
index 4ad8d1f71f26..1191cd2fb97b 100644
--- a/src/Files.App/ViewModels/UserControls/Previews/CodePreviewViewModel.cs
+++ b/src/Files.App/ViewModels/UserControls/Previews/CodePreviewViewModel.cs
@@ -1,16 +1,15 @@
-// Copyright (c) Files Community
+// Copyright (c) Files Community
// Licensed under the MIT License.
using ColorCode;
using Files.App.ViewModels.Properties;
+using Files.Shared.Helpers;
using System.Collections.Frozen;
namespace Files.App.ViewModels.Previews
{
public sealed partial class CodePreviewViewModel : BasePreviewModel
{
- private static readonly FrozenDictionary extensions = GetDictionary();
-
private string textValue;
public string TextValue
{
@@ -30,9 +29,6 @@ public CodePreviewViewModel(ListedItem item)
{
}
- public static bool ContainsExtension(string extension)
- => extensions.ContainsKey(extension);
-
public async override Task> LoadPreviewAndDetailsAsync()
{
var details = new List();
@@ -42,7 +38,7 @@ public async override Task> LoadPreviewAndDetailsAsync()
var text = TextValue ?? await ReadFileAsTextAsync(Item.ItemFile);
details.Add(GetFileProperty("PropertyLineCount", text.Split('\n').Length));
- CodeLanguage = extensions[Item.FileExtension.ToLowerInvariant()];
+ CodeLanguage = FileExtensionHelpers.CodeFileExtensions[Item.FileExtension.ToLowerInvariant()];
TextValue = text.Left(Constants.PreviewPane.TextCharacterLimit);
}
catch (Exception e)
@@ -52,40 +48,5 @@ public async override Task> LoadPreviewAndDetailsAsync()
return details;
}
-
- private static FrozenDictionary GetDictionary()
- {
- var items = new Dictionary
- {
- [Languages.Aspx] = "aspx",
- [Languages.AspxCs] = "acsx",
- [Languages.Cpp] = "cpp,c++,cc,cp,cxx,h,h++,hh,hpp,hxx,inc,inl,ino,ipp,re,tcc,tpp",
- [Languages.CSharp] = "cs,cake,csx,linq",
- [Languages.Css] = "css,scss",
- [Languages.FSharp] = "fs,fsi,fsx",
- [Languages.Haskell] = "hs",
- [Languages.Html] = "razor,cshtml,vbhtml,svelte",
- [Languages.Java] = "java",
- [Languages.JavaScript] = "js,jsx",
- [Languages.Php] = "php",
- [Languages.PowerShell] = "pwsh,ps1,psd1,psm1",
- [Languages.Typescript] = "ts,tsx",
- [Languages.VbDotNet] = "vb,vbs",
- [Languages.Xml] = "xml,axml,xaml,xsd,xsl,xslt,xlf",
- };
-
- var dictionary = new Dictionary();
-
- foreach (var item in items)
- {
- var extensions = item.Value.Split(',').Select(ext => $".{ext}");
- foreach (var extension in extensions)
- {
- dictionary.Add(extension, item.Key);
- }
- }
-
- return dictionary.ToFrozenDictionary();
- }
}
}
diff --git a/src/Files.App/ViewModels/UserControls/Previews/HtmlPreviewViewModel.cs b/src/Files.App/ViewModels/UserControls/Previews/HtmlPreviewViewModel.cs
index 934e4789785b..0835066cea58 100644
--- a/src/Files.App/ViewModels/UserControls/Previews/HtmlPreviewViewModel.cs
+++ b/src/Files.App/ViewModels/UserControls/Previews/HtmlPreviewViewModel.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Files Community
+// Copyright (c) Files Community
// Licensed under the MIT License.
using Files.App.ViewModels.Properties;
@@ -12,9 +12,6 @@ public HtmlPreviewViewModel(ListedItem item)
{
}
- public static bool ContainsExtension(string extension)
- => extension is ".htm" or ".html" or ".svg";
-
public async override Task> LoadPreviewAndDetailsAsync()
=> [];
}
diff --git a/src/Files.App/ViewModels/UserControls/Previews/ImagePreviewViewModel.cs b/src/Files.App/ViewModels/UserControls/Previews/ImagePreviewViewModel.cs
index 6a323b90e1d6..94149178ea11 100644
--- a/src/Files.App/ViewModels/UserControls/Previews/ImagePreviewViewModel.cs
+++ b/src/Files.App/ViewModels/UserControls/Previews/ImagePreviewViewModel.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Files Community
+// Copyright (c) Files Community
// Licensed under the MIT License.
using Files.App.ViewModels.Properties;
@@ -23,10 +23,6 @@ public ImagePreviewViewModel(ListedItem item)
{
}
- // TODO: Use existing helper mothods
- public static bool ContainsExtension(string extension)
- => extension is ".png" or ".jpg" or ".jpeg" or ".bmp" or ".gif" or ".tiff" or ".ico" or ".webp" or ".jxr";
-
public override async Task> LoadPreviewAndDetailsAsync()
{
using IRandomAccessStream stream = await Item.ItemFile.OpenAsync(FileAccessMode.Read);
diff --git a/src/Files.App/ViewModels/UserControls/Previews/MarkdownPreviewViewModel.cs b/src/Files.App/ViewModels/UserControls/Previews/MarkdownPreviewViewModel.cs
index 699d06a211e5..a347cefdae16 100644
--- a/src/Files.App/ViewModels/UserControls/Previews/MarkdownPreviewViewModel.cs
+++ b/src/Files.App/ViewModels/UserControls/Previews/MarkdownPreviewViewModel.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Files Community
+// Copyright (c) Files Community
// Licensed under the MIT License.
using Files.App.ViewModels.Properties;
diff --git a/src/Files.App/ViewModels/UserControls/Previews/PDFPreviewViewModel.cs b/src/Files.App/ViewModels/UserControls/Previews/PDFPreviewViewModel.cs
index fa1d08dc7698..c64acc029af5 100644
--- a/src/Files.App/ViewModels/UserControls/Previews/PDFPreviewViewModel.cs
+++ b/src/Files.App/ViewModels/UserControls/Previews/PDFPreviewViewModel.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Files Community
+// Copyright (c) Files Community
// Licensed under the MIT License.
using Files.App.ViewModels.Properties;
@@ -34,9 +34,6 @@ public PDFPreviewViewModel(ListedItem item)
{
}
- public static bool ContainsExtension(string extension)
- => extension is ".pdf";
-
public async override Task> LoadPreviewAndDetailsAsync()
{
var fileStream = await Item.ItemFile.OpenReadAsync();
diff --git a/src/Files.App/ViewModels/UserControls/Previews/RichTextPreviewViewModel.cs b/src/Files.App/ViewModels/UserControls/Previews/RichTextPreviewViewModel.cs
index 18d55829a526..ed59883760a8 100644
--- a/src/Files.App/ViewModels/UserControls/Previews/RichTextPreviewViewModel.cs
+++ b/src/Files.App/ViewModels/UserControls/Previews/RichTextPreviewViewModel.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Files Community
+// Copyright (c) Files Community
// Licensed under the MIT License.
using Files.App.ViewModels.Properties;
diff --git a/src/Files.App/ViewModels/UserControls/Previews/TextPreviewViewModel.cs b/src/Files.App/ViewModels/UserControls/Previews/TextPreviewViewModel.cs
index 0fa858db2077..8264a2601272 100644
--- a/src/Files.App/ViewModels/UserControls/Previews/TextPreviewViewModel.cs
+++ b/src/Files.App/ViewModels/UserControls/Previews/TextPreviewViewModel.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Files Community
+// Copyright (c) Files Community
// Licensed under the MIT License.
using Files.App.UserControls.FilePreviews;
diff --git a/src/Files.Shared/Files.Shared.csproj b/src/Files.Shared/Files.Shared.csproj
index a4941310287b..a4f552c33a9e 100644
--- a/src/Files.Shared/Files.Shared.csproj
+++ b/src/Files.Shared/Files.Shared.csproj
@@ -16,6 +16,7 @@
+
diff --git a/src/Files.Shared/Helpers/FileExtensionHelpers.cs b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
index 67277c5ca60b..32b1e8f4a6cf 100644
--- a/src/Files.Shared/Helpers/FileExtensionHelpers.cs
+++ b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
@@ -1,6 +1,7 @@
-// Copyright (c) Files Community
+// Copyright (c) Files Community
// Licensed under the MIT License.
+using ColorCode;
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
@@ -14,6 +15,8 @@ namespace Files.Shared.Helpers
///
public static class FileExtensionHelpers
{
+ public static readonly FrozenDictionary CodeFileExtensions = CodeFileExtensions_GetDictionary();
+
private static readonly FrozenSet _signableTypes = new HashSet(StringComparer.OrdinalIgnoreCase)
{
".aab", ".apk", ".application", ".appx", ".appxbundle", ".arx", ".cab", ".cat", ".cbx",
@@ -26,6 +29,41 @@ public static class FileExtensionHelpers
".xltm", ".xlsm", ".xsn"
}.ToFrozenSet(StringComparer.OrdinalIgnoreCase);
+ private static FrozenDictionary CodeFileExtensions_GetDictionary()
+ {
+ var items = new Dictionary
+ {
+ [Languages.Aspx] = "aspx",
+ [Languages.AspxCs] = "acsx",
+ [Languages.Cpp] = "cpp,c++,cc,cp,cxx,h,h++,hh,hpp,hxx,inc,inl,ino,ipp,re,tcc,tpp",
+ [Languages.CSharp] = "cs,cake,csx,linq",
+ [Languages.Css] = "css,scss",
+ [Languages.FSharp] = "fs,fsi,fsx",
+ [Languages.Haskell] = "hs",
+ [Languages.Html] = "razor,cshtml,vbhtml,svelte",
+ [Languages.Java] = "java",
+ [Languages.JavaScript] = "js,jsx",
+ [Languages.Php] = "php",
+ [Languages.PowerShell] = "pwsh,ps1,psd1,psm1",
+ [Languages.Typescript] = "ts,tsx",
+ [Languages.VbDotNet] = "vb,vbs",
+ [Languages.Xml] = "xml,axml,xaml,xsd,xsl,xslt,xlf",
+ };
+
+ var dictionary = new Dictionary();
+
+ foreach (var item in items)
+ {
+ var extensions = item.Value.Split(',').Select(ext => $".{ext}");
+ foreach (var extension in extensions)
+ {
+ dictionary.Add(extension, item.Key);
+ }
+ }
+
+ return dictionary.ToFrozenDictionary();
+ }
+
///
/// Check if the file extension matches one of the specified extensions.
///
@@ -51,7 +89,7 @@ public static bool HasExtension(string? filePathToCheck, params ReadOnlySpan
- /// Check if the file extension is an image file.
+ /// Checks if the file extension represents an image file.
///
/// The file extension to check.
/// true if the fileExtensionToCheck is an image; otherwise, false.
@@ -71,7 +109,7 @@ public static bool IsCompatibleToSetAsWindowsWallpaper(string? fileExtensionToCh
}
///
- /// Check if the file extension is an audio file.
+ /// Checks if the file extension represents an audio file.
///
/// The file extension to check.
/// true if the fileExtensionToCheck is an audio file; otherwise, false.
@@ -81,7 +119,7 @@ public static bool IsAudioFile(string? fileExtensionToCheck)
}
///
- /// Check if the file extension is a video file.
+ /// Checks if the file extension represents a video file.
///
/// The file extension to check.
/// true if the fileExtensionToCheck is a video file; otherwise, false.
@@ -91,7 +129,7 @@ public static bool IsVideoFile(string? fileExtensionToCheck)
}
///
- /// Check if the file extension is a PowerShell script.
+ /// Checks if the file extension represents a PowerShell script.
///
/// The file extension to check.
/// true if the fileExtensionToCheck is a PowerShell script; otherwise, false.
@@ -101,7 +139,7 @@ public static bool IsPowerShellFile(string fileExtensionToCheck)
}
///
- /// Check if the file extension is a Batch file.
+ /// Checks if the file extension represents a Batch file.
///
/// The file extension to check.
/// true if the fileExtensionToCheck is a Batch file; otherwise, false.
@@ -111,7 +149,7 @@ public static bool IsBatchFile(string fileExtensionToCheck)
}
///
- /// Check if the file extension is a zip file.
+ /// Checks if the file extension represents a zip file.
///
/// The file extension to check.
/// true if the fileExtensionToCheck is a zip bundle file; otherwise, false.
@@ -137,43 +175,40 @@ public static bool IsBrowsableZipFile(string? filePath, out string? ext)
}
///
- /// Check if the file extension is a driver inf file.
+ /// Checks if the file extension represents a driver inf file.
///
/// The file extension to check.
- /// true if the fileExtensionToCheck is an inf file; otherwise false.
+ /// true if the filePathToCheck is an inf file; otherwise false.
public static bool IsInfFile(string? fileExtensionToCheck)
{
return HasExtension(fileExtensionToCheck, ".inf");
}
///
- /// Check if the file extension is a font file.
+ /// Checks if the file extension represents a font file.
///
/// The file extension to check.
- /// true if the fileExtensionToCheck is a font file; otherwise false.
- /// Font file types are; fon, otf, ttc, ttf
+ /// true if the filePathToCheck is a font file; otherwise false.
public static bool IsFontFile(string? fileExtensionToCheck)
{
return HasExtension(fileExtensionToCheck, ".fon", ".otf", ".ttc", ".ttf");
}
///
- /// Check if the file path is a shortcut file.
+ /// Checks if the file extension represents a shortcut file.
///
/// The file path to check.
- /// true if the filePathToCheck is a shortcut file; otherwise, false.
- /// Shortcut file type is .lnk
+ /// true if the filePathToCheck is a shortcut file; otherwise, false.
public static bool IsShortcutFile(string? filePathToCheck)
{
return HasExtension(filePathToCheck, ".lnk");
}
///
- /// Check if the file path is a web link file.
+ /// Checks if the file extension represents a web link file.
///
/// The file path to check.
- /// true if the filePathToCheck is a web link file; otherwise, false.
- /// Web link file type is .url
+ /// true if the filePathToCheck is a web link file; otherwise, false.
public static bool IsWebLinkFile(string? filePathToCheck)
{
return HasExtension(filePathToCheck, ".url");
@@ -185,11 +220,10 @@ public static bool IsShortcutOrUrlFile(string? filePathToCheck)
}
///
- /// Check if the file path is an executable file.
+ /// Checks if the file extension represents an executable file.
///
/// The file path to check.
- /// true if the filePathToCheck is an executable file; otherwise, false.
- /// /// Executable file types are; exe, bat, cmd
+ /// true if the filePathToCheck is an executable file; otherwise, false.
public static bool IsExecutableFile(string? filePathToCheck, bool exeOnly = false)
{
return
@@ -199,62 +233,60 @@ public static bool IsExecutableFile(string? filePathToCheck, bool exeOnly = fals
}
///
- /// Check if the file path is an Auto Hot Key file.
+ /// Checks if the file extension represents an Auto Hot Key file.
///
/// The file path to check.
- /// true if the filePathToCheck is an Auto Hot Key file; otherwise, false.
+ /// true if the filePathToCheck is an Auto Hot Key file; otherwise, false.
public static bool IsAhkFile(string? filePathToCheck)
{
return HasExtension(filePathToCheck, ".ahk");
}
///
- /// Check if the file path is a cmd file.
+ /// Checks if the file extension represents a CMD file.
///
/// The file path to check.
- /// true if the filePathToCheck is a cmd file; otherwise, false.
+ /// true if the filePathToCheck is a CMD file; otherwise, false.
public static bool IsCmdFile(string? filePathToCheck)
{
return HasExtension(filePathToCheck, ".cmd");
}
///
- /// Check if the file path is an msi installer file.
+ /// Checks if the file extension represents an MSI installer file.
///
/// The file path to check.
- /// true if the filePathToCheck is an msi installer file; otherwise, false.
+ /// true if the filePathToCheck is an MSI installer file; otherwise, false.
public static bool IsMsiFile(string? filePathToCheck)
{
return HasExtension(filePathToCheck, ".msi");
}
///
- /// Check if the file extension is a vhd disk file.
+ /// Checks if the file extension represents a vhd disk file.
///
/// The file extension to check.
- /// true if the fileExtensionToCheck is a vhd disk file; otherwise, false.
- /// Vhd disk file types are; vhd, vhdx
+ /// true if the filePathToCheck is a vhd disk file; otherwise, false.
public static bool IsVhdFile(string? fileExtensionToCheck)
{
return HasExtension(fileExtensionToCheck, ".vhd", ".vhdx");
}
///
- /// Check if the file extension is a screen saver file.
+ /// Checks if the file extension represents a screen saver file.
///
/// The file extension to check.
- /// true if the fileExtensionToCheck is a screen saver file; otherwise, false.
- /// Screen saver file types are; scr
+ /// true if the filePathToCheck is a screen saver file; otherwise, false.
public static bool IsScreenSaverFile(string? fileExtensionToCheck)
{
return HasExtension(fileExtensionToCheck, ".scr");
}
///
- /// Check if the file extension is a media (audio/video) file.
+ /// Checks if the file extension represents a media (audio/video) file.
///
/// The file extension to check.
- /// true if the filePathToCheck is a media file; otherwise, false.
+ /// true if the filePathToCheck is a media file; otherwise, false.
public static bool IsMediaFile(string? filePathToCheck)
{
return HasExtension(
@@ -263,35 +295,95 @@ public static bool IsMediaFile(string? filePathToCheck)
}
///
- /// Check if the file extension is a certificate file.
+ /// Checks if the file extension represents a certificate file.
///
///
- /// true if the filePathToCheck is a certificate file; otherwise, false.
+ /// true if the filePathToCheck is a certificate file; otherwise, false.
public static bool IsCertificateFile(string? filePathToCheck)
{
return HasExtension(filePathToCheck, ".cer", ".crt", ".der", ".pfx");
}
///
- /// Check if the file extension is a Script file.
+ /// Checks if the file extension represents a script file.
///
///
- /// true if the filePathToCheck is a script file; otherwise, false.
+ /// true if the filePathToCheck is a script file; otherwise, false.
public static bool IsScriptFile(string? filePathToCheck)
{
return HasExtension(filePathToCheck, ".py", ".ahk", ".bat", ".cmd", ".ps1");
}
///
- /// Check if the file extension is a system file.
+ /// Checks if the file extension represents a system file.
///
///
- /// true if the filePathToCheck is a system file; otherwise, false.
+ /// true if the filePathToCheck is a system file; otherwise, false.
public static bool IsSystemFile(string? filePathToCheck)
{
return HasExtension(filePathToCheck, ".dll", ".exe", ".sys", ".inf");
}
+ ///
+ /// Checks if the file extension matches a recognised code file extension.
+ ///
+ /// The file extension to check.
+ /// true if the filePathToCheck is a code file; otherwise, false.
+ public static bool IsCodeFile(string? filePathToCheck)
+ {
+ return HasExtension(filePathToCheck, CodeFileExtensions.Keys.ToArray());
+ }
+
+ ///
+ /// Checks if the file extension represents an Adobe Acrobat PDF file.
+ ///
+ /// The file extension to check
+ /// true if the filePathToCheck is a PDF file; otherwise, false.
+ public static bool IsPdfFile(string? fileExtensionToCheck)
+ {
+ return HasExtension(fileExtensionToCheck, ".pdf");
+ }
+
+ ///
+ /// Checks if the file extension represents an HTML file.
+ ///
+ /// The file extension to check
+ /// true if the filePathToCheck is an HTML file; otherwise, false.
+ public static bool IsHtmlFile(string? fileExtensionToCheck)
+ {
+ return HasExtension(fileExtensionToCheck, ".html", ".htm", ".xhtml", ".svg");
+ }
+
+ ///
+ /// Checks if the file extension represents a markdown file.
+ ///
+ /// The file extension to check
+ /// true if the filePathToCheck is a markdown file; otherwise, false.
+ public static bool IsMarkdownFile(string? fileExtensionToCheck)
+ {
+ return HasExtension(fileExtensionToCheck, ".md", ".markdown", ".mdx");
+ }
+
+ ///
+ /// Checks if the file extension represents a rich text file.
+ ///
+ /// The file extension to check
+ /// true if the filePathToCheck is a rich text file; otherwise, false.
+ public static bool IsRichTextFile(string? fileExtensionToCheck)
+ {
+ return HasExtension(fileExtensionToCheck, ".rtf");
+ }
+
+ ///
+ /// Checks if the file extension represents a plain text file.
+ ///
+ /// The file extension to check
+ /// true if the filePathToCheck is a text file; otherwise, false.
+ public static bool IsTextFile(string? fileExtensionToCheck)
+ {
+ return HasExtension(fileExtensionToCheck, ".txt");
+ }
+
///
/// Check if the file is signable.
///
From 2825aeaf5d029b9e560c4b84197f4c73a4ffaec6 Mon Sep 17 00:00:00 2001
From: Lamparter <71598437+Lamparter@users.noreply.github.com>
Date: Sun, 11 Jan 2026 21:30:58 +0000
Subject: [PATCH 2/8] Do what Copilot says
---
src/Files.Shared/Helpers/FileExtensionHelpers.cs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/Files.Shared/Helpers/FileExtensionHelpers.cs b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
index 32b1e8f4a6cf..c9585f65f11b 100644
--- a/src/Files.Shared/Helpers/FileExtensionHelpers.cs
+++ b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
@@ -17,6 +17,8 @@ public static class FileExtensionHelpers
{
public static readonly FrozenDictionary CodeFileExtensions = CodeFileExtensions_GetDictionary();
+ private static readonly string[] CodeFileExtensionKeys = [.. CodeFileExtensions.Keys];
+
private static readonly FrozenSet _signableTypes = new HashSet(StringComparer.OrdinalIgnoreCase)
{
".aab", ".apk", ".application", ".appx", ".appxbundle", ".arx", ".cab", ".cat", ".cbx",
@@ -331,7 +333,7 @@ public static bool IsSystemFile(string? filePathToCheck)
/// true if the filePathToCheck is a code file; otherwise, false.
public static bool IsCodeFile(string? filePathToCheck)
{
- return HasExtension(filePathToCheck, CodeFileExtensions.Keys.ToArray());
+ return HasExtension(filePathToCheck, CodeFileExtensionKeys);
}
///
From e335d608dac6373825e2691973f1c7bc3c9053b1 Mon Sep 17 00:00:00 2001
From: Lamparter <71598437+Lamparter@users.noreply.github.com>
Date: Mon, 12 Jan 2026 07:47:25 +0000
Subject: [PATCH 3/8] Remove `.mdx`
---
src/Files.Shared/Helpers/FileExtensionHelpers.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Files.Shared/Helpers/FileExtensionHelpers.cs b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
index c9585f65f11b..0135132f014e 100644
--- a/src/Files.Shared/Helpers/FileExtensionHelpers.cs
+++ b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Files Community
+// Copyright (c) Files Community
// Licensed under the MIT License.
using ColorCode;
@@ -363,7 +363,7 @@ public static bool IsHtmlFile(string? fileExtensionToCheck)
/// true if the filePathToCheck is a markdown file; otherwise, false.
public static bool IsMarkdownFile(string? fileExtensionToCheck)
{
- return HasExtension(fileExtensionToCheck, ".md", ".markdown", ".mdx");
+ return HasExtension(fileExtensionToCheck, ".md", ".markdown");
}
///
From 204fc32edd6006fe20c1b561d9332f566d395b8a Mon Sep 17 00:00:00 2001
From: Lamparter <71598437+Lamparter@users.noreply.github.com>
Date: Mon, 12 Jan 2026 07:47:41 +0000
Subject: [PATCH 4/8] Add back image types
---
src/Files.Shared/Helpers/FileExtensionHelpers.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Files.Shared/Helpers/FileExtensionHelpers.cs b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
index 0135132f014e..420af2d5cca8 100644
--- a/src/Files.Shared/Helpers/FileExtensionHelpers.cs
+++ b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Files Community
+// Copyright (c) Files Community
// Licensed under the MIT License.
using ColorCode;
@@ -107,7 +107,7 @@ public static bool IsImageFile(string? fileExtensionToCheck)
/// true if the fileExtensionToCheck is an image; otherwise, false.
public static bool IsCompatibleToSetAsWindowsWallpaper(string? fileExtensionToCheck)
{
- return HasExtension(fileExtensionToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif", ".jxr");
+ return HasExtension(fileExtensionToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif", ".jxr", ".ico", ".webp");
}
///
From da4dc3d93898a4a79b4946bab9dc76c839248437 Mon Sep 17 00:00:00 2001
From: Lamparter <71598437+Lamparter@users.noreply.github.com>
Date: Mon, 12 Jan 2026 07:50:04 +0000
Subject: [PATCH 5/8] Add svg file check method
---
src/Files.Shared/Helpers/FileExtensionHelpers.cs | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/Files.Shared/Helpers/FileExtensionHelpers.cs b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
index 420af2d5cca8..8c730aea6423 100644
--- a/src/Files.Shared/Helpers/FileExtensionHelpers.cs
+++ b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
@@ -353,7 +353,7 @@ public static bool IsPdfFile(string? fileExtensionToCheck)
/// true if the filePathToCheck is an HTML file; otherwise, false.
public static bool IsHtmlFile(string? fileExtensionToCheck)
{
- return HasExtension(fileExtensionToCheck, ".html", ".htm", ".xhtml", ".svg");
+ return HasExtension(fileExtensionToCheck, ".html", ".htm", ".xhtml");
}
///
@@ -386,6 +386,16 @@ public static bool IsTextFile(string? fileExtensionToCheck)
return HasExtension(fileExtensionToCheck, ".txt");
}
+ ///
+ /// Checks if the file extension represents an SVG file.
+ ///
+ /// The file extension to check
+ /// true if the filePathToCheck is an SVG file; otherwise, false.
+ public static bool IsSvgFile(string? fileExtensionToCheck)
+ {
+ return HasExtension(fileExtensionToCheck, ".svg");
+ }
+
///
/// Check if the file is signable.
///
From 18ff30734b0bf30a7a05df0a95619d7dd163a5ca Mon Sep 17 00:00:00 2001
From: Lamparter <71598437+Lamparter@users.noreply.github.com>
Date: Mon, 12 Jan 2026 08:30:28 +0000
Subject: [PATCH 6/8] Fix
---
src/Files.Shared/Helpers/FileExtensionHelpers.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Files.Shared/Helpers/FileExtensionHelpers.cs b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
index 8c730aea6423..fd97e923c22c 100644
--- a/src/Files.Shared/Helpers/FileExtensionHelpers.cs
+++ b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
@@ -97,7 +97,7 @@ public static bool HasExtension(string? filePathToCheck, params ReadOnlySpantrue if the fileExtensionToCheck is an image; otherwise, false.
public static bool IsImageFile(string? fileExtensionToCheck)
{
- return HasExtension(fileExtensionToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif", ".webp", ".jxr");
+ return HasExtension(fileExtensionToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif", ".jxr", ".webp", ".ico");
}
///
@@ -107,7 +107,7 @@ public static bool IsImageFile(string? fileExtensionToCheck)
/// true if the fileExtensionToCheck is an image; otherwise, false.
public static bool IsCompatibleToSetAsWindowsWallpaper(string? fileExtensionToCheck)
{
- return HasExtension(fileExtensionToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif", ".jxr", ".ico", ".webp");
+ return HasExtension(fileExtensionToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif", ".jxr");
}
///
From 53bc1186841bf18ffa0faf65e1c7a0da4e780fa7 Mon Sep 17 00:00:00 2001
From: Lamparter <71598437+Lamparter@users.noreply.github.com>
Date: Sun, 25 Jan 2026 09:43:03 +0000
Subject: [PATCH 7/8] Make variable names consistent
---
.../Helpers/FileExtensionHelpers.cs | 118 +++++++++---------
1 file changed, 59 insertions(+), 59 deletions(-)
diff --git a/src/Files.Shared/Helpers/FileExtensionHelpers.cs b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
index fd97e923c22c..779bb1402d6b 100644
--- a/src/Files.Shared/Helpers/FileExtensionHelpers.cs
+++ b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
@@ -71,7 +71,7 @@ private static FrozenDictionary CodeFileExtensions_GetDiction
///
/// Path or name or extension of the file to check.
/// List of the extensions to check.
- /// true if the filePathToCheck has one of the specified extensions; otherwise, false.
+ /// true if the filePathToCheck has one of the specified extensions; otherwise, false.
public static bool HasExtension(string? filePathToCheck, params ReadOnlySpan extensions)
{
if (string.IsNullOrWhiteSpace(filePathToCheck))
@@ -93,71 +93,71 @@ public static bool HasExtension(string? filePathToCheck, params ReadOnlySpan
/// Checks if the file extension represents an image file.
///
- /// The file extension to check.
- /// true if the fileExtensionToCheck is an image; otherwise, false.
- public static bool IsImageFile(string? fileExtensionToCheck)
+ /// The file extension to check.
+ /// true if the filePathToCheck is an image; otherwise, false.
+ public static bool IsImageFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif", ".jxr", ".webp", ".ico");
+ return HasExtension(filePathToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif", ".jxr", ".webp", ".ico");
}
///
/// Checks if the file can be set as wallpaper.
///
- /// The file extension to check.
- /// true if the fileExtensionToCheck is an image; otherwise, false.
- public static bool IsCompatibleToSetAsWindowsWallpaper(string? fileExtensionToCheck)
+ /// The file extension to check.
+ /// true if the filePathToCheck is an image; otherwise, false.
+ public static bool IsCompatibleToSetAsWindowsWallpaper(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif", ".jxr");
+ return HasExtension(filePathToCheck, ".png", ".bmp", ".jpg", ".jpeg", ".jfif", ".gif", ".tiff", ".tif", ".jxr");
}
///
/// Checks if the file extension represents an audio file.
///
- /// The file extension to check.
- /// true if the fileExtensionToCheck is an audio file; otherwise, false.
- public static bool IsAudioFile(string? fileExtensionToCheck)
+ /// The file extension to check.
+ /// true if the filePathToCheck is an audio file; otherwise, false.
+ public static bool IsAudioFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".mp3", ".m4a", ".ogg", ".oga", ".wav", ".wma", ".aac", ".adt", ".adts", ".cda", ".flac");
+ return HasExtension(filePathToCheck, ".mp3", ".m4a", ".ogg", ".oga", ".wav", ".wma", ".aac", ".adt", ".adts", ".cda", ".flac");
}
///
/// Checks if the file extension represents a video file.
///
- /// The file extension to check.
- /// true if the fileExtensionToCheck is a video file; otherwise, false.
- public static bool IsVideoFile(string? fileExtensionToCheck)
+ /// The file extension to check.
+ /// true if the filePathToCheck is a video file; otherwise, false.
+ public static bool IsVideoFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".avi", ".mp4", ".webm", ".ogg", ".mov", ".qt", ".m4v", ".mp4v", ".3g2", ".3gp2", ".3gp", ".3gpp", ".mkv");
+ return HasExtension(filePathToCheck, ".avi", ".mp4", ".webm", ".ogg", ".mov", ".qt", ".m4v", ".mp4v", ".3g2", ".3gp2", ".3gp", ".3gpp", ".mkv");
}
///
/// Checks if the file extension represents a PowerShell script.
///
- /// The file extension to check.
- /// true if the fileExtensionToCheck is a PowerShell script; otherwise, false.
- public static bool IsPowerShellFile(string fileExtensionToCheck)
+ /// The file extension to check.
+ /// true if the filePathToCheck is a PowerShell script; otherwise, false.
+ public static bool IsPowerShellFile(string filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".ps1");
+ return HasExtension(filePathToCheck, ".ps1");
}
///
/// Checks if the file extension represents a Batch file.
///
- /// The file extension to check.
- /// true if the fileExtensionToCheck is a Batch file; otherwise, false.
- public static bool IsBatchFile(string fileExtensionToCheck)
+ /// The file extension to check.
+ /// true if the filePathToCheck is a Batch file; otherwise, false.
+ public static bool IsBatchFile(string filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".bat");
+ return HasExtension(filePathToCheck, ".bat");
}
///
/// Checks if the file extension represents a zip file.
///
- /// The file extension to check.
- /// true if the fileExtensionToCheck is a zip bundle file; otherwise, false.
- public static bool IsZipFile(string? fileExtensionToCheck)
+ /// The file extension to check.
+ /// true if the filePathToCheck is a zip bundle file; otherwise, false.
+ public static bool IsZipFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".zip", ".msix", ".appx", ".msixbundle", ".appxbundle", ".7z", ".rar", ".tar", ".mcpack", ".mcworld", ".mrpack", ".jar", ".gz", ".lzh");
+ return HasExtension(filePathToCheck, ".zip", ".msix", ".appx", ".msixbundle", ".appxbundle", ".7z", ".rar", ".tar", ".mcpack", ".mcworld", ".mrpack", ".jar", ".gz", ".lzh");
}
public static bool IsBrowsableZipFile(string? filePath, out string? ext)
@@ -179,21 +179,21 @@ public static bool IsBrowsableZipFile(string? filePath, out string? ext)
///
/// Checks if the file extension represents a driver inf file.
///
- /// The file extension to check.
+ /// The file extension to check.
/// true if the filePathToCheck is an inf file; otherwise false.
- public static bool IsInfFile(string? fileExtensionToCheck)
+ public static bool IsInfFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".inf");
+ return HasExtension(filePathToCheck, ".inf");
}
///
/// Checks if the file extension represents a font file.
///
- /// The file extension to check.
+ /// The file extension to check.
/// true if the filePathToCheck is a font file; otherwise false.
- public static bool IsFontFile(string? fileExtensionToCheck)
+ public static bool IsFontFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".fon", ".otf", ".ttc", ".ttf");
+ return HasExtension(filePathToCheck, ".fon", ".otf", ".ttc", ".ttf");
}
///
@@ -267,21 +267,21 @@ public static bool IsMsiFile(string? filePathToCheck)
///
/// Checks if the file extension represents a vhd disk file.
///
- /// The file extension to check.
+ /// The file extension to check.
/// true if the filePathToCheck is a vhd disk file; otherwise, false.
- public static bool IsVhdFile(string? fileExtensionToCheck)
+ public static bool IsVhdFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".vhd", ".vhdx");
+ return HasExtension(filePathToCheck, ".vhd", ".vhdx");
}
///
/// Checks if the file extension represents a screen saver file.
///
- /// The file extension to check.
+ /// The file extension to check.
/// true if the filePathToCheck is a screen saver file; otherwise, false.
- public static bool IsScreenSaverFile(string? fileExtensionToCheck)
+ public static bool IsScreenSaverFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".scr");
+ return HasExtension(filePathToCheck, ".scr");
}
///
@@ -339,61 +339,61 @@ public static bool IsCodeFile(string? filePathToCheck)
///
/// Checks if the file extension represents an Adobe Acrobat PDF file.
///
- /// The file extension to check
+ /// The file extension to check
/// true if the filePathToCheck is a PDF file; otherwise, false.
- public static bool IsPdfFile(string? fileExtensionToCheck)
+ public static bool IsPdfFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".pdf");
+ return HasExtension(filePathToCheck, ".pdf");
}
///
/// Checks if the file extension represents an HTML file.
///
- /// The file extension to check
+ /// The file extension to check
/// true if the filePathToCheck is an HTML file; otherwise, false.
- public static bool IsHtmlFile(string? fileExtensionToCheck)
+ public static bool IsHtmlFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".html", ".htm", ".xhtml");
+ return HasExtension(filePathToCheck, ".html", ".htm", ".xhtml");
}
///
/// Checks if the file extension represents a markdown file.
///
- /// The file extension to check
+ /// The file extension to check
/// true if the filePathToCheck is a markdown file; otherwise, false.
- public static bool IsMarkdownFile(string? fileExtensionToCheck)
+ public static bool IsMarkdownFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".md", ".markdown");
+ return HasExtension(filePathToCheck, ".md", ".markdown");
}
///
/// Checks if the file extension represents a rich text file.
///
- /// The file extension to check
+ /// The file extension to check
/// true if the filePathToCheck is a rich text file; otherwise, false.
- public static bool IsRichTextFile(string? fileExtensionToCheck)
+ public static bool IsRichTextFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".rtf");
+ return HasExtension(filePathToCheck, ".rtf");
}
///
/// Checks if the file extension represents a plain text file.
///
- /// The file extension to check
+ /// The file extension to check
/// true if the filePathToCheck is a text file; otherwise, false.
- public static bool IsTextFile(string? fileExtensionToCheck)
+ public static bool IsTextFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".txt");
+ return HasExtension(filePathToCheck, ".txt");
}
///
/// Checks if the file extension represents an SVG file.
///
- /// The file extension to check
+ /// The file extension to check
/// true if the filePathToCheck is an SVG file; otherwise, false.
- public static bool IsSvgFile(string? fileExtensionToCheck)
+ public static bool IsSvgFile(string? filePathToCheck)
{
- return HasExtension(fileExtensionToCheck, ".svg");
+ return HasExtension(filePathToCheck, ".svg");
}
///
From e04df89f4f1db4371c2e89d3b97d01c48bcfdc79 Mon Sep 17 00:00:00 2001
From: Lamparter <71598437+Lamparter@users.noreply.github.com>
Date: Mon, 27 Apr 2026 23:43:16 +0100
Subject: [PATCH 8/8] Remove duplicated methods
---
.../Helpers/FileExtensionHelpers.cs | 30 -------------------
1 file changed, 30 deletions(-)
diff --git a/src/Files.Shared/Helpers/FileExtensionHelpers.cs b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
index 779bb1402d6b..88172e1492d7 100644
--- a/src/Files.Shared/Helpers/FileExtensionHelpers.cs
+++ b/src/Files.Shared/Helpers/FileExtensionHelpers.cs
@@ -411,35 +411,5 @@ public static bool IsSignableFile(string? filePathToCheck, bool isExtension = fa
return _signableTypes.Contains(filePathToCheck);
}
-
- ///
- /// Check if the file extension is a markdown file.
- ///
- ///
- /// true if the fileExtensionToCheck is a markdown file; otherwise, false.
- public static bool IsMarkdownFile(string? fileExtensionToCheck)
- {
- return HasExtension(fileExtensionToCheck, ".md", ".markdown");
- }
-
- ///
- /// Check if the file extension is a text file.
- ///
- ///
- /// true if the fileExtensionToCheck is a text file; otherwise, false.
- public static bool IsTextFile(string? fileExtensionToCheck)
- {
- return HasExtension(fileExtensionToCheck, ".txt");
- }
-
- ///
- /// Check if the file extension is a rich text file.
- ///
- ///
- /// true if the fileExtensionToCheck is a rich text file; otherwise, false.
- public static bool IsRichTextFile(string? fileExtensionToCheck)
- {
- return HasExtension(fileExtensionToCheck, ".rtf");
- }
}
}