mc_repack_core/ext.rs
1
2/// An enum containing all "known" file formats that can be processed by this library
3#[derive(Clone, Copy, PartialEq, Eq)]
4pub enum KnownFmt {
5 /// JavaScript Object Notation, also known as JSON
6 Json,
7 /// Tom's Obvious Minimal Language, also known as TOML
8 Toml,
9 /// Portable Network Graphics, also known as PNG
10 Png,
11 /// Ogg Vorbis (it may not be an audio file)
12 Ogg,
13 /// Named Binary Tag, also known as NBT
14 Nbt,
15 /// Configuration file
16 Cfg,
17 /// Wavefront .obj file
18 Obj,
19 /// Wavefront .mtl file
20 Mtl,
21 /// GLSL fragment shader
22 Fsh,
23 /// GLSL vertex shader
24 Vsh,
25 /// JavaScript
26 Js,
27 /// ZenScript (ZS), format used by CraftTweaker
28 Zs,
29 /// JAR archive
30 Jar,
31 /// Java Manifest file
32 Mf,
33 /// Any type format with maximum length of 3 (unused bytes are marked as zeroes)
34 Other([u8; 3])
35}
36impl KnownFmt {
37 /// Return a `KnownFmt` based on file extension.
38 #[must_use]
39 pub fn by_extension(ftype: &str) -> Option<Self> {
40 Some(match ftype.to_ascii_lowercase().as_str() {
41 "json" | "mcmeta" => Self::Json,
42 "toml" => Self::Toml,
43 "png" => Self::Png,
44 "ogg" => Self::Ogg,
45 "nbt" | "blueprint" => Self::Nbt,
46 "cfg" => Self::Cfg,
47 "obj" => Self::Obj,
48 "mtl" => Self::Mtl,
49 "fsh" => Self::Fsh,
50 "vsh" => Self::Vsh,
51 "js" => Self::Js,
52 "zs" => Self::Zs,
53 "jar" => Self::Jar,
54 "mf" => Self::Mf,
55 x => match x.as_bytes() {
56 [a] => Self::Other([*a, 0, 0]),
57 [a, b] => Self::Other([*a, *b, 0]),
58 [a, b, c] => Self::Other([*a, *b, *c]),
59 _ => return None
60 }
61 })
62 }
63}