forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Global.cs
134 lines (109 loc) · 3.77 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
// MonoGame - Copyright (C) MonoGame Foundation, Inc
// 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
{
return "/?<>\\:*|\"";
}
}
public static bool Linux { get; private set; }
public static bool UseHeaderBar { get; set; }
public static bool Unix { get; private set; }
public static bool IsGtk { get; private set; }
private static Dictionary<string, Bitmap> _files;
private static Image _folder;
private static Bitmap _link;
static Global()
{
Unix = Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX;
_link = Bitmap.FromResource("TreeView.Link.png");
_files = new Dictionary<string, Bitmap>();
_files.Add("0.", Bitmap.FromResource("TreeView.File.png"));
_folder = Bitmap.FromResource("TreeView.Folder.png");
PlatformInit();
// Generate default link file image
var linkfile = new Bitmap(_files["0."]);
var g = new Graphics(linkfile);
g.DrawImage(_link, Point.Empty);
g.Flush();
_files.Add("1.", linkfile);
}
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()
{
return _folder;
}
public static Image GetEtoFileIcon(string path, bool link)
{
var key = (link ? '1' : '0') + (File.Exists(path) ? Path.GetExtension(path) : ".");
if (_files.ContainsKey(key))
return _files[key];
try
{
if (File.Exists(path))
{
var platformicon = PlatformGetFileIcon(path);
if (platformicon != null)
{
var icon = ToEtoImage(platformicon);
if (icon != null)
{
if (link)
{
var g = new Graphics(icon);
g.DrawImage(_link, Point.Empty);
g.Flush();
}
_files.Add(key, icon);
return icon;
}
}
}
}
catch { }
return _files[(link) ? "1." : "0."];
}
public static Image GetEtoIcon(string resource)
{
#if GTK
var nativeicon = PlatformGetIcon(resource);
if (nativeicon != null)
return ToEtoImage(nativeicon);
#endif
return Icon.FromResource(resource);
}
public static T Show<T>(this Eto.Forms.Dialog<T> dialog, Eto.Forms.Control parent)
{
#if IDE
return dialog.ShowModal(null);
#else
return dialog.ShowModal(parent);
#endif
}
public static Eto.Forms.DialogResult Show(this Eto.Forms.CommonDialog dialog, Eto.Forms.Control parent)
{
#if IDE
return dialog.ShowDialog(null);
#else
return dialog.ShowDialog(parent);
#endif
}
}
}