forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Global.cs
98 lines (77 loc) · 2.63 KB
/
Global.cs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.Collections.Generic;
using System.IO;
using Eto.Drawing;
namespace MonoGame.Tools.Pipeline
{
static partial class Global
{
public static string NotAllowedCharacters
{
get
{
if (Unix)
return Linux ? "/" : ":";
return "/?<>\\:*|\"";
}
}
public static bool Linux { get; private set; }
public static bool UseHeaderBar { get; set; }
public static bool Unix { get; private set; }
private static Dictionary<string, Image> _files;
private static Image _fileMissing, _folder, _folderMissing;
static Global()
{
Unix = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX;
_files = new Dictionary<string, Image>();
_files.Add(".", Bitmap.FromResource("TreeView.File.png"));
_fileMissing = Bitmap.FromResource("TreeView.FileMissing.png");
_folder = Bitmap.FromResource("TreeView.Folder.png");
_folderMissing = Bitmap.FromResource("TreeView.FolderMissing.png");
PlatformInit();
}
public static bool CheckString(string s)
{
var notAllowed = Path.GetInvalidFileNameChars();
for (int i = 0; i < notAllowed.Length; i++)
if (s.Contains(notAllowed[i].ToString()))
return false;
return true;
}
public static Image GetEtoDirectoryIcon(bool exists)
{
return exists ? _folder : _folderMissing;
}
public static Image GetEtoFileIcon(string path, bool exists)
{
if (!exists)
return _fileMissing;
var ext = Path.GetExtension(path);
if (_files.ContainsKey(ext))
return _files[ext];
Image icon;
try
{
icon = ToEtoImage(PlatformGetFileIcon(path));
}
catch
{
icon = _files["."];
}
_files.Add(ext, icon);
return icon;
}
public static Image GetEtoIcon(string resource)
{
#if LINUX
var nativeicon = PlatformGetIcon(resource);
if (nativeicon != null)
return ToEtoImage(nativeicon);
#endif
return Icon.FromResource(resource);
}
}
}