-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathProjectType.cs
102 lines (87 loc) · 3.75 KB
/
ProjectType.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
using System;
using System.Text.RegularExpressions;
namespace PdnCodeLab
{
public enum ProjectType
{
PlainText,
ClassicEffect,
GpuImageEffect,
GpuDrawEffect,
BitmapEffect,
FileType,
Reference,
Shape,
Default = GpuImageEffect
}
internal static class ProjectTypeExtensions
{
internal static bool IsCSharp(this ProjectType projectType)
{
return
projectType == ProjectType.ClassicEffect ||
projectType == ProjectType.GpuImageEffect ||
projectType == ProjectType.GpuDrawEffect ||
projectType == ProjectType.BitmapEffect ||
projectType == ProjectType.FileType;
}
internal static bool IsEffect(this ProjectType projectType)
{
return
projectType == ProjectType.ClassicEffect ||
projectType == ProjectType.GpuImageEffect ||
projectType == ProjectType.GpuDrawEffect ||
projectType == ProjectType.BitmapEffect;
}
internal static bool Is5Effect(this ProjectType projectType)
{
return
projectType == ProjectType.GpuImageEffect ||
projectType == ProjectType.GpuDrawEffect ||
projectType == ProjectType.BitmapEffect;
}
}
internal static class ProjectTypeUtil
{
internal static ProjectType FromContents(string textContents, string fileExtension)
{
ProjectType projectType = FromContentImpl(textContents);
if (fileExtension is null ||
projectType == ProjectType.PlainText ||
(fileExtension.Equals(".cs", StringComparison.OrdinalIgnoreCase) && projectType.IsCSharp()) ||
(fileExtension.Equals(".xaml", StringComparison.OrdinalIgnoreCase) && projectType == ProjectType.Shape))
{
return projectType;
}
return ProjectType.PlainText;
}
private static ProjectType FromContentImpl(string textContents)
{
if (Regex.IsMatch(textContents, @"void\s+Render\s*\(\s*Surface\s+\w+\s*,\s*Surface\s+\w+\s*,\s*Rectangle\s+\w+\s*\)\s*{(.|\s)*}", RegexOptions.Singleline))
{
return ProjectType.ClassicEffect;
}
if (Regex.IsMatch(textContents, @"protected\s+override\s+void\s+OnRender\s*\(\s*IBitmapEffectOutput\s+\w+\s*\)\s*{(.|\s)*}", RegexOptions.Singleline))
{
return ProjectType.BitmapEffect;
}
if (Regex.IsMatch(textContents, @"protected\s+override\s+IDeviceImage\s+OnCreateOutput\(IDeviceContext\s+\w+\s*\)\s*{(.|\s)*}", RegexOptions.Singleline))
{
return ProjectType.GpuImageEffect;
}
if (Regex.IsMatch(textContents, @"protected\s+override\s+unsafe\s+void\s+OnDraw\(IDeviceContext\s+\w+\s*\)\s*{(.|\s)*}", RegexOptions.Singleline))
{
return ProjectType.GpuDrawEffect;
}
if (Regex.IsMatch(textContents, @"void\s+SaveImage\s*\(\s*Document\s+\w+\s*,\s*Stream\s+\w+\s*,\s*PropertyBasedSaveConfigToken\s+\w+\s*,\s*Surface\s+\w+\s*,\s*ProgressEventHandler\s+\w+\s*\)\s*{(.|\s)*}", RegexOptions.Singleline))
{
return ProjectType.FileType;
}
if (Regex.IsMatch(textContents, @"<ps:SimpleGeometryShape\s+xmlns=""clr-namespace:PaintDotNet\.UI\.Media;assembly=PaintDotNet\.Framework""\s+xmlns:ps=""clr-namespace:PaintDotNet\.Shapes;assembly=PaintDotNet\.Framework""", RegexOptions.Singleline))
{
return ProjectType.Shape;
}
return ProjectType.PlainText;
}
}
}