Files
Moonlight/Moonlight/Features/FileManager/Helpers/EditorModeDetector.cs
Marcel Baumgartner 0eabe27196 Reimplementing file manager and code editor (untested)
TODO: Add ftp auth back
2024-02-05 22:40:15 +01:00

210 lines
9.1 KiB
C#

namespace Moonlight.Features.FileManager.Helpers;
public static class EditorModeDetector
{
// We probably will never need every of this modes ;)
private static readonly Dictionary<string, string[]> ExtensionIndex = new()
{
{ "abap", new[] { "abap" } },
{ "abc", new[] { "abc" } },
{ "actionscript", new[] { "as" } },
{ "ada", new[] { "ada", "adb" } },
{ "alda", new[] { "alda" } },
{ "apache_conf", new[] { "htaccess", "htgroups", "htpasswd", "conf", "htaccess", "htgroups", "htpasswd" } },
{ "apex", new[] { "apex", "cls", "trigger", "tgr" } },
{ "aql", new[] { "aql" } },
{ "asciidoc", new[] { "asciidoc", "adoc" } },
{ "asl", new[] { "dsl", "asl", "asl.json" } },
{ "assembly_x86", new[] { "asm", "a" } },
{ "astro", new[] { "astro" } },
{ "autohotkey", new[] { "ahk" } },
{ "batchfile", new[] { "bat", "cmd" } },
{ "bibtex", new[] { "bib" } },
{ "c_cpp", new[] { "cpp", "c", "cc", "cxx", "h", "hh", "hpp", "ino" } },
{ "c9search", new[] { "c9search_results" } },
{ "cirru", new[] { "cirru", "cr" } },
{ "clojure", new[] { "clj", "cljs" } },
{ "cobol", new[] { "cbl", "cob" } },
{ "coffee", new[] { "coffee", "cf", "cson", "cakefile" } },
{ "coldfusion", new[] { "cfm", "cfc" } },
{ "crystal", new[] { "cr" } },
{ "csharp", new[] { "cs" } },
{ "csound_document", new[] { "csd" } },
{ "csound_orchestra", new[] { "orc" } },
{ "csound_score", new[] { "sco" } },
{ "css", new[] { "css" } },
{ "curly", new[] { "curly" } },
{ "cuttlefish", new[] { "conf" } },
{ "d", new[] { "d", "di" } },
{ "dart", new[] { "dart" } },
{ "diff", new[] { "diff", "patch" } },
{ "django", new[] { "djt", "html.djt", "dj.html", "djhtml" } },
{ "dockerfile", new[] { "dockerfile" } },
{ "dot", new[] { "dot" } },
{ "drools", new[] { "drl" } },
{ "edifact", new[] { "edi" } },
{ "eiffel", new[] { "e", "ge" } },
{ "ejs", new[] { "ejs" } },
{ "elixir", new[] { "ex", "exs" } },
{ "elm", new[] { "elm" } },
{ "erlang", new[] { "erl", "hrl" } },
{ "flix", new[] { "flix" } },
{ "forth", new[] { "frt", "fs", "ldr", "fth", "4th" } },
{ "fortran", new[] { "f", "f90" } },
{ "fsharp", new[] { "fsi", "fs", "ml", "mli", "fsx", "fsscript" } },
{ "fsl", new[] { "fsl" } },
{ "ftl", new[] { "ftl" } },
{ "gcode", new[] { "gcode" } },
{ "gherkin", new[] { "feature" } },
{ "gitignore", new[] { ".gitignore" } },
{ "glsl", new[] { "glsl", "frag", "vert" } },
{ "gobstones", new[] { "gbs" } },
{ "golang", new[] { "go" } },
{ "graphqlschema", new[] { "gql" } },
{ "groovy", new[] { "groovy" } },
{ "haml", new[] { "haml" } },
{ "handlebars", new[] { "hbs", "handlebars", "tpl", "mustache" } },
{ "haskell", new[] { "hs" } },
{ "haskell_cabal", new[] { "cabal" } },
{ "haxe", new[] { "hx" } },
{ "hjson", new[] { "hjson" } },
{ "html", new[] { "html", "htm", "xhtml", "vue", "we", "wpy" } },
{ "html_elixir", new[] { "eex", "html.eex" } },
{ "html_ruby", new[] { "erb", "rhtml", "html.erb" } },
{ "ini", new[] { "ini", "conf", "cfg", "prefs" } },
{ "io", new[] { "io" } },
{ "ion", new[] { "ion" } },
{ "jack", new[] { "jack" } },
{ "jade", new[] { "jade", "pug" } },
{ "java", new[] { "java" } },
{ "javascript", new[] { "js", "jsm", "jsx", "cjs", "mjs" } },
{ "jexl", new[] { "jexl" } },
{ "json", new[] { "json" } },
{ "json5", new[] { "json5" } },
{ "jsoniq", new[] { "jq" } },
{ "jsp", new[] { "jsp" } },
{ "jssm", new[] { "jssm", "jssm_state" } },
{ "jsx", new[] { "jsx" } },
{ "julia", new[] { "jl" } },
{ "kotlin", new[] { "kt", "kts" } },
{ "latex", new[] { "tex", "latex", "ltx", "bib" } },
{ "latte", new[] { "latte" } },
{ "less", new[] { "less" } },
{ "liquid", new[] { "liquid" } },
{ "lisp", new[] { "lisp" } },
{ "livescript", new[] { "ls" } },
{ "log", new[] { "log" } },
{ "logiql", new[] { "logic", "lql" } },
{ "logtalk", new[] { "lgt" } },
{ "lsl", new[] { "lsl" } },
{ "lua", new[] { "lua" } },
{ "luapage", new[] { "lp" } },
{ "lucene", new[] { "lucene" } },
{ "makefile", new[] { "makefile", "gnumakefile", "makefile", "ocamlmakefile", "make" } },
{ "markdown", new[] { "md", "markdown" } },
{ "mask", new[] { "mask" } },
{ "matlab", new[] { "matlab" } },
{ "maze", new[] { "mz" } },
{ "mediawiki", new[] { "wiki", "mediawiki" } },
{ "mel", new[] { "mel" } },
{ "mips", new[] { "s", "asm" } },
{ "mixal", new[] { "mixal" } },
{ "mushcode", new[] { "mc", "mush" } },
{ "mysql", new[] { "mysql" } },
{ "nasal", new[] { "nas" } },
{ "nginx", new[] { "nginx", "conf" } },
{ "nim", new[] { "nim" } },
{ "nix", new[] { "nix" } },
{ "nsis", new[] { "nsi", "nsh" } },
{ "nunjucks", new[] { "nunjucks", "nunjs", "nj", "njk" } },
{ "objectivec", new[] { "m", "mm" } },
{ "ocaml", new[] { "ml", "mli" } },
{ "odin", new[] { "odin" } },
{ "partiql", new[] { "partiql", "pql" } },
{ "pascal", new[] { "pas", "p" } },
{ "perl", new[] { "pl", "pm" } },
{ "pgsql", new[] { "pgsql" } },
{ "php", new[] { "php", "inc", "phtml", "shtml", "php3", "php4", "php5", "phps", "phpt", "aw", "ctp", "module" } },
{ "php_laravel_blade", new[] { "blade.php" } },
{ "pig", new[] { "pig" } },
{ "plsql", new[] { "plsql" } },
{ "powershell", new[] { "ps1" } },
{ "praat", new[] { "praat", "praatscript", "psc", "proc" } },
{ "prisma", new[] { "prisma" } },
{ "prolog", new[] { "plg", "prolog" } },
{ "properties", new[] { "properties" } },
{ "protobuf", new[] { "proto" } },
{ "prql", new[] { "prql" } },
{ "puppet", new[] { "epp", "pp" } },
{ "python", new[] { "py" } },
{ "qml", new[] { "qml" } },
{ "r", new[] { "r" } },
{ "raku", new[] { "raku", "rakumod", "rakutest", "p6", "pl6", "pm6" } },
{ "razor", new[] { "cshtml", "asp" } },
{ "rdoc", new[] { "rd" } },
{ "red", new[] { "red", "reds" } },
{ "rhtml", new[] { "rhtml" } },
{ "robot", new[] { "robot", "resource" } },
{ "rst", new[] { "rst" } },
{ "ruby", new[] { "rb", "ru", "gemspec", "rake", "guardfile", "rakefile", "gemfile" } },
{ "rust", new[] { "rs" } },
{ "sac", new[] { "sac" } },
{ "sass", new[] { "sass" } },
{ "scad", new[] { "scad" } },
{ "scala", new[] { "scala", "sbt" } },
{ "scheme", new[] { "scm", "sm", "rkt", "oak", "scheme" } },
{ "scrypt", new[] { "scrypt" } },
{ "scss", new[] { "scss" } },
{ "sh", new[] { "sh", "bash", ".bashrc" } },
{ "sjs", new[] { "sjs" } },
{ "slim", new[] { "slim", "skim" } },
{ "smarty", new[] { "smarty", "tpl" } },
{ "smithy", new[] { "smithy" } },
{ "snippets", new[] { "snippets" } },
{ "soy_template", new[] { "soy" } },
{ "space", new[] { "space" } },
{ "sparql", new[] { "rq" } },
{ "sql", new[] { "sql" } },
{ "sqlserver", new[] { "sqlserver" } },
{ "stylus", new[] { "styl", "stylus" } },
{ "svg", new[] { "svg" } },
{ "swift", new[] { "swift" } },
{ "tcl", new[] { "tcl" } },
{ "terraform", new[] { "tf", "tfvars", "terragrunt" } },
{ "tex", new[] { "tex" } },
{ "text", new[] { "txt" } },
{ "textile", new[] { "textile" } },
{ "toml", new[] { "toml" } },
{ "tsx", new[] { "tsx" } },
{ "turtle", new[] { "ttl" } },
{ "twig", new[] { "twig", "swig" } },
{ "typescript", new[] { "ts", "mts", "cts", "typescript", "str" } },
{ "vala", new[] { "vala" } },
{ "vbscript", new[] { "vbs", "vb" } },
{ "velocity", new[] { "vm" } },
{ "verilog", new[] { "v", "vh", "sv", "svh" } },
{ "vhdl", new[] { "vhd", "vhdl" } },
{ "visualforce", new[] { "vfp", "component", "page" } },
{ "wollok", new[] { "wlk", "wpgm", "wtest" } },
{ "xml", new[] { "xml", "rdf", "rss", "wsdl", "xslt", "atom", "mathml", "mml", "xul", "xbl", "xaml" } },
{ "xquery", new[] { "xq" } },
{ "yaml", new[] { "yaml", "yml" } },
{ "zeek", new[] { "zeek", "bro" } }
};
public static string GetModeFromFile(string fileName)
{
var extension = Path.GetExtension(fileName).Replace(".", "");
if (string.IsNullOrEmpty(extension))
return "text";
foreach (var entry in ExtensionIndex)
{
if (entry.Value.Any(x => string.Equals(x, extension, StringComparison.InvariantCultureIgnoreCase)))
return entry.Key;
}
return "text";
}
}