forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Global.cs
160 lines (127 loc) · 4.59 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// 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; private set; }
public static bool Unix { get; private set; }
private static Dictionary<string, Image> _files;
private static Image _fileMissing, _folder, _folderMissing;
private static Dictionary<string, Xwt.Drawing.Image> _xwtFiles;
private static Xwt.Drawing.Image _xwtFileMissing, _xwtFolder, _xwtFolderMissing;
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");
_xwtFiles = new Dictionary<string, Xwt.Drawing.Image>();
_xwtFiles.Add(".", Xwt.Drawing.Image.FromResource("TreeView.File.png"));
_xwtFileMissing = Xwt.Drawing.Image.FromResource("TreeView.FileMissing.png");
_xwtFolder = Xwt.Drawing.Image.FromResource("TreeView.Folder.png");
_xwtFolderMissing = Xwt.Drawing.Image.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 void ShowOpenWithDialog(string filePath)
{
try
{
PlatformShowOpenWithDialog(filePath);
}
catch
{
MainWindow.Instance.ShowError("Error", "The current platform does not have this dialog implemented.");
}
}
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 Xwt.Drawing.Image GetXwtDirectoryIcon(bool exists)
{
return exists ? _xwtFolder : _xwtFolderMissing;
}
public static Xwt.Drawing.Image GetXwtFileIcon(string path, bool exists)
{
if (!exists)
return _xwtFileMissing;
var ext = Path.GetExtension(path);
if (_xwtFiles.ContainsKey(ext))
return _xwtFiles[ext];
Xwt.Drawing.Image icon;
try
{
icon = ToXwtImage(PlatformGetFileIcon(path));
}
catch
{
icon = _xwtFiles["."];
}
_xwtFiles.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);
}
public static Xwt.Drawing.Image GetXwtIcon(string resource)
{
#if LINUX
var nativeicon = PlatformGetIcon(resource);
if (nativeicon != null)
return ToXwtImage(nativeicon);
#endif
return Xwt.Drawing.Image.FromResource(resource);
}
}
}