Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 113 additions & 111 deletions Tewl/FileExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,113 +1,115 @@
using System.Linq;
using JetBrains.Annotations;

namespace Tewl {
/// <summary>
/// String constants for the content types for common file types.
/// Includes the period prefix.
/// </summary>
[ PublicAPI ]
public class FileExtensions {
/// <summary>
/// An APK file.
/// </summary>
public const string Apk = ".apk";

/// <summary>
/// A CSS file.
/// </summary>
public const string Css = ".css";

/// <summary>
/// A CSV file.
/// </summary>
public const string Csv = ".csv";

/// <summary>
/// An older Excel file.
/// </summary>
public const string ExcelXls = ".xls";

/// <summary>
/// A current Excel file.
/// </summary>
public const string ExcelXlsx = ".xlsx";

/// <summary>
/// A JPG file.
/// </summary>
public static readonly string[] Jpeg = { ".jpg", ".jpeg" };

/// <summary>
/// A GIF file.
/// </summary>
public const string Gif = ".gif";

/// <summary>
/// A JavaScript file.
/// </summary>
public const string JavaScript = ".js";

/// <summary>
/// A PDF file.
/// </summary>
public const string Pdf = ".pdf";

/// <summary>
/// A PNG file.
/// </summary>
public const string Png = ".png";

/// <summary>
/// A Scalable Vector Graphics image.
/// </summary>
public const string Svg = ".svg";

/// <summary>
/// A text document.
/// </summary>
public const string Txt = ".txt";

/// <summary>
/// An Excel file.
/// </summary>
public static readonly string[] Excel = { ExcelXls, ExcelXlsx };

/// <summary>
/// A pre-docx Word Document.
/// </summary>
public const string WordDoc = ".doc";

/// <summary>
/// A Word document.
/// </summary>
public const string WordDocx = ".docx";

/// <summary>
/// A Word file.
/// </summary>
public static readonly string[] Word = { WordDoc, WordDocx };

/// <summary>
/// An XML file.
/// </summary>
public const string Xml = ".xml";

/// <summary>
/// An XML Schema file.
/// </summary>
public const string Xsd = ".xsd";

/// <summary>
/// A ZIP file.
/// </summary>
public const string Zip = ".zip";

/// <summary>
/// Returns true if the file name has one of the given extensions.
/// </summary>
public static bool MatchesAGivenExtension( string fileName, params string[] allowableExtensions ) {
return allowableExtensions.Any( ext => fileName.ToLower().EndsWith( ext.ToLower() ) );
}
namespace Tewl;

/// <summary>
/// String constants for the content types for common file types.
/// Includes the period prefix.
/// </summary>
[ PublicAPI ]
public class FileExtensions {
/// <summary>
/// An APK file.
/// </summary>
public const string Apk = ".apk";

/// <summary>
/// A CSS file.
/// </summary>
public const string Css = ".css";

/// <summary>
/// A CSV file.
/// </summary>
public const string Csv = ".csv";

/// <summary>
/// An older Excel file.
/// </summary>
public const string ExcelXls = ".xls";

/// <summary>
/// A current Excel file.
/// </summary>
public const string ExcelXlsx = ".xlsx";

/// <summary>
/// A JPG file.
/// </summary>
public static readonly string[] Jpeg = [ ".jpg", ".jpeg" ];

/// <summary>
/// A GIF file.
/// </summary>
public const string Gif = ".gif";

/// <summary>
/// A JavaScript file.
/// </summary>
public const string JavaScript = ".js";

/// <summary>
/// A PDF file.
/// </summary>
public const string Pdf = ".pdf";

/// <summary>
/// A PNG file.
/// </summary>
public const string Png = ".png";

/// <summary>
/// A Scalable Vector Graphics image.
/// </summary>
public const string Svg = ".svg";

/// <summary>
/// A text document.
/// </summary>
public const string Txt = ".txt";

/// <summary>
/// Markdown.
/// </summary>
public const string Markdown = ".md";

/// <summary>
/// An Excel file.
/// </summary>
public static readonly string[] Excel = [ ExcelXls, ExcelXlsx ];

/// <summary>
/// A pre-docx Word Document.
/// </summary>
public const string WordDoc = ".doc";

/// <summary>
/// A Word document.
/// </summary>
public const string WordDocx = ".docx";

/// <summary>
/// A Word file.
/// </summary>
public static readonly string[] Word = [ WordDoc, WordDocx ];

/// <summary>
/// An XML file.
/// </summary>
public const string Xml = ".xml";

/// <summary>
/// An XML Schema file.
/// </summary>
public const string Xsd = ".xsd";

/// <summary>
/// A ZIP file.
/// </summary>
public const string Zip = ".zip";

/// <summary>
/// Returns true if the file name has one of the given extensions.
/// </summary>
public static bool MatchesAGivenExtension( string fileName, params string[] allowableExtensions ) {
return allowableExtensions.Any( ext => fileName.ToLower().EndsWith( ext.ToLower() ) );
}
}
8 changes: 7 additions & 1 deletion Tewl/Tools/ContentTypes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Net.Mime;
using JetBrains.Annotations;

namespace Tewl.Tools;

Expand Down Expand Up @@ -53,6 +52,11 @@ public static class ContentTypes {
/// </summary>
public const string PlainText = MediaTypeNames.Text.Plain;

/// <summary>
/// Content type to be used by Markdown files.
/// </summary>
public const string Markdown = MediaTypeNames.Text.Markdown;

/// <summary>
/// Content type to be used for tab-separated values files.
/// </summary>
Expand Down Expand Up @@ -118,6 +122,8 @@ public static string GetContentType( string fileName ) {

var fileExtension = fileName.Substring( beginExtensionIndex );
switch( fileExtension ) {
case FileExtensions.Markdown:
return Markdown;
case FileExtensions.Apk:
return ApplicationPackageFile;
case FileExtensions.Css:
Expand Down