diff --git a/Directory.Packages.props b/Directory.Packages.props index 61755484ea0f..4f7f3403cd98 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 83c5ebe14eaa..7f671d95c265 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; @@ -89,7 +89,7 @@ static bool IsFolder(ListedItem item) static bool IsImage(ListedItem item) => !string.IsNullOrEmpty(item.FileExtension) - && ImagePreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant()); + && FileExtensionHelpers.IsImageFile(item.FileExtension.ToLowerInvariant()); static bool IsMedia(ListedItem item) => !string.IsNullOrEmpty(item.FileExtension) diff --git a/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs b/src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs index fc119b6efc82..639f89968760 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; @@ -284,7 +284,7 @@ private async Task GetBuiltInPreviewControlAsync(ListedItem item, b return new MediaPreview(model); } - if (MarkdownPreviewViewModel.ContainsExtension(ext)) + if (FileExtensionHelpers.IsMarkdownFile(ext)) { var model = new MarkdownPreviewViewModel(item); await model.LoadAsync(); @@ -292,7 +292,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(); @@ -300,7 +300,7 @@ private async Task GetBuiltInPreviewControlAsync(ListedItem item, b return new ImagePreview(model); } - if (TextPreviewViewModel.ContainsExtension(ext)) + if (FileExtensionHelpers.IsTextFile(ext)) { var model = new TextPreviewViewModel(item); await model.LoadAsync(); @@ -308,7 +308,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(); @@ -316,7 +316,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(); @@ -324,7 +324,7 @@ private async Task GetBuiltInPreviewControlAsync(ListedItem item, b return new HtmlPreview(model); }*/ - if (RichTextPreviewViewModel.ContainsExtension(ext)) + if (FileExtensionHelpers.IsRichTextFile(ext)) { var model = new RichTextPreviewViewModel(item); await model.LoadAsync(); @@ -332,7 +332,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 313b2648204f..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; @@ -19,9 +19,6 @@ public MarkdownPreviewViewModel(ListedItem item) { } - public static bool ContainsExtension(string extension) - => extension is ".md" or ".markdown"; - public override async Task> LoadPreviewAndDetailsAsync() { var text = await ReadFileAsTextAsync(Item.ItemFile); 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 da16faf85385..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; @@ -12,9 +12,6 @@ public sealed partial class RichTextPreviewViewModel : BasePreviewModel public RichTextPreviewViewModel(ListedItem item) : base(item) { } - public static bool ContainsExtension(string extension) - => extension is ".rtf"; - public async override Task> LoadPreviewAndDetailsAsync() { Stream = await Item.ItemFile.OpenReadAsync(); diff --git a/src/Files.App/ViewModels/UserControls/Previews/TextPreviewViewModel.cs b/src/Files.App/ViewModels/UserControls/Previews/TextPreviewViewModel.cs index b5fc658ba793..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; @@ -20,9 +20,6 @@ public TextPreviewViewModel(ListedItem item) { } - public static bool ContainsExtension(string extension) - => extension is ".txt"; - public async override Task> LoadPreviewAndDetailsAsync() { var details = new List(); 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 e4d8f9e5ecc7..83b5461ff45f 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,10 @@ namespace Files.Shared.Helpers /// 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", @@ -26,12 +31,47 @@ 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. /// /// 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)) @@ -51,73 +91,73 @@ 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. - 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", ".webp", ".jxr"); + 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"); } /// - /// 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. - 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", ".wav", ".wma", ".aac", ".adt", ".adts", ".cda", ".flac"); + return HasExtension(filePathToCheck, ".mp3", ".m4a", ".wav", ".wma", ".aac", ".adt", ".adts", ".cda", ".flac"); } /// - /// 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. - 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, ".mp4", ".webm", ".ogg", ".mov", ".qt", ".m4v", ".mp4v", ".3g2", ".3gp2", ".3gp", ".3gpp", ".mkv"); + return HasExtension(filePathToCheck, ".mp4", ".webm", ".ogg", ".mov", ".qt", ".m4v", ".mp4v", ".3g2", ".3gp2", ".3gp", ".3gpp", ".mkv"); } /// - /// 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. - 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"); } /// - /// 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. - 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"); } /// - /// 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. - 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) @@ -137,43 +177,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. - public static bool IsInfFile(string? fileExtensionToCheck) + /// The file extension to check. + /// true if the filePathToCheck is an inf file; otherwise false. + public static bool IsInfFile(string? filePathToCheck) { - return HasExtension(fileExtensionToCheck, ".inf"); + return HasExtension(filePathToCheck, ".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 - public static bool IsFontFile(string? fileExtensionToCheck) + /// The file extension to check. + /// true if the filePathToCheck is a font file; otherwise false. + public static bool IsFontFile(string? filePathToCheck) { - return HasExtension(fileExtensionToCheck, ".fon", ".otf", ".ttc", ".ttf"); + return HasExtension(filePathToCheck, ".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 +222,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 +235,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 - public static bool IsVhdFile(string? fileExtensionToCheck) + /// The file extension to check. + /// true if the filePathToCheck is a vhd disk file; otherwise, false. + public static bool IsVhdFile(string? filePathToCheck) { - return HasExtension(fileExtensionToCheck, ".vhd", ".vhdx"); + return HasExtension(filePathToCheck, ".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 - public static bool IsScreenSaverFile(string? fileExtensionToCheck) + /// The file extension to check. + /// true if the filePathToCheck is a screen saver file; otherwise, false. + public static bool IsScreenSaverFile(string? filePathToCheck) { - return HasExtension(fileExtensionToCheck, ".scr"); + return HasExtension(filePathToCheck, ".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 +297,105 @@ 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, CodeFileExtensionKeys); + } + + /// + /// 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? filePathToCheck) + { + return HasExtension(filePathToCheck, ".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? filePathToCheck) + { + return HasExtension(filePathToCheck, ".html", ".htm", ".xhtml"); + } + + /// + /// 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? filePathToCheck) + { + return HasExtension(filePathToCheck, ".md", ".markdown"); + } + + /// + /// 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? filePathToCheck) + { + return HasExtension(filePathToCheck, ".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? filePathToCheck) + { + return HasExtension(filePathToCheck, ".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? filePathToCheck) + { + return HasExtension(filePathToCheck, ".svg"); + } + /// /// Check if the file is signable. ///