forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Global.Windows.cs
executable file
·103 lines (84 loc) · 3.2 KB
/
Global.Windows.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
// 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 Eto.Drawing;
using Eto.Forms;
using Eto.Wpf.Drawing;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Windows.Media.Imaging;
using System.Windows.Media;
namespace MonoGame.Tools.Pipeline
{
static partial class Global
{
public static bool IsWindows10 { get; set; }
[DllImport("Shell32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
private static extern int ExtractIconExW(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons);
private static void PlatformInit()
{
var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
IsWindows10 = (reg.GetValue("ProductName") as string).StartsWith("Windows 10");
}
public static System.Drawing.Icon ExtractIcon(int number)
{
IntPtr large;
IntPtr small;
ExtractIconExW("shell32.dll", number, out large, out small, 1);
return System.Drawing.Icon.FromHandle(large);
}
private static BitmapSource Convert(System.Drawing.Bitmap bitmap)
{
var ret = new BitmapImage();
using (MemoryStream memory = new MemoryStream())
{
bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
memory.Position = 0;
ret.BeginInit();
ret.StreamSource = memory;
ret.CacheOption = BitmapCacheOption.OnLoad;
ret.EndInit();
}
return ret;
}
private static Image PlatformGetDirectoryIcon(bool exists)
{
System.Drawing.Bitmap icon;
if (exists)
icon = ExtractIcon(4).ToBitmap();
else
icon = ExtractIcon(234).ToBitmap();
return new Bitmap(new BitmapHandler(Convert(icon)));
}
private static Image PlatformGetFileIcon(string path, bool exists)
{
System.Drawing.Bitmap icon;
if (exists)
{
try
{
icon = System.Drawing.Icon.ExtractAssociatedIcon(path).ToBitmap();
}
catch
{
icon = ExtractIcon(0).ToBitmap();
}
}
else
icon = ExtractIcon(271).ToBitmap();
return new Bitmap(new BitmapHandler(Convert(icon)));
}
private static void PlatformShowOpenWithDialog(string filePath)
{
var args = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "shell32.dll");
Process.Start("rundll32.exe", args + ",OpenAs_RunDLL " + filePath);
}
private static bool PlatformSetIcon(Command cmd)
{
return false;
}
}
}