forked from JeremyDurnell/locbaml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryFileType.cs
More file actions
54 lines (52 loc) · 1.64 KB
/
BinaryFileType.cs
File metadata and controls
54 lines (52 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Collections.Generic;
using System.Globalization;
namespace BamlLocalization
{
internal enum BinaryFileType
{
NONE = 0,
BAML,
RESOURCES,
DLL,
EXE,
}
static class BinaryFileTypeHelper
{
static readonly Dictionary<BinaryFileType, string> InputFileTypeExtensions = new Dictionary<BinaryFileType, string>()
{
{ BinaryFileType.BAML, "baml" },
{ BinaryFileType.DLL, "dll" },
{ BinaryFileType.EXE, "exe" },
{ BinaryFileType.RESOURCES, "resources" }
};
internal static string GetExtension(this BinaryFileType fileType, bool includeDot = true)
{
string extension;
InputFileTypeExtensions.TryGetValue(fileType, out extension);
if ((extension != null) && includeDot)
{
return "." + extension;
}
else
{
// Don't need to prepend a dot or we don't know the extension
return extension;
}
}
internal static BinaryFileType GetBinaryFileTypeFromExtension(string extension)
{
if (extension.StartsWith("."))
{
extension = extension.Substring(1);
}
foreach (var pair in InputFileTypeExtensions)
{
if (string.Compare(extension, pair.Value, true, CultureInfo.InvariantCulture) == 0)
{
return pair.Key;
}
}
return BinaryFileType.NONE;
}
}
}