Skip to content

Commit 5153af0

Browse files
working on plugin system & type console
1 parent 414aad5 commit 5153af0

34 files changed

+840
-61
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ FlipnoteDesktop/obj/
55
FlipnoteDesktop/Properties/VersionCounter.cs
66
FlipnoteDesktop/FlipnoteDesktop.csproj.user
77
G_TypeConsole/bin/
8-
G_TypeConsole/obj/
8+
G_TypeConsole/obj/
9+
Test/bin/
10+
Test/obj

FlipnoteDesktop.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{668E
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "G_TypeConsole", "G_TypeConsole\G_TypeConsole.csproj", "{6C6B6EBE-0CE4-4EBE-9FF6-12631A5BC0BF}"
1111
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{B8F65948-DD38-4559-BAC1-BFC68FE86D64}"
13+
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1416
Debug|Any CPU = Debug|Any CPU
@@ -23,12 +25,17 @@ Global
2325
{6C6B6EBE-0CE4-4EBE-9FF6-12631A5BC0BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
2426
{6C6B6EBE-0CE4-4EBE-9FF6-12631A5BC0BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
2527
{6C6B6EBE-0CE4-4EBE-9FF6-12631A5BC0BF}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{B8F65948-DD38-4559-BAC1-BFC68FE86D64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{B8F65948-DD38-4559-BAC1-BFC68FE86D64}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{B8F65948-DD38-4559-BAC1-BFC68FE86D64}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{B8F65948-DD38-4559-BAC1-BFC68FE86D64}.Release|Any CPU.Build.0 = Release|Any CPU
2632
EndGlobalSection
2733
GlobalSection(SolutionProperties) = preSolution
2834
HideSolutionNode = FALSE
2935
EndGlobalSection
3036
GlobalSection(NestedProjects) = preSolution
3137
{6C6B6EBE-0CE4-4EBE-9FF6-12631A5BC0BF} = {668EC33D-F7E1-4F5C-8614-EFB8FE82553F}
38+
{B8F65948-DD38-4559-BAC1-BFC68FE86D64} = {668EC33D-F7E1-4F5C-8614-EFB8FE82553F}
3239
EndGlobalSection
3340
GlobalSection(ExtensibilityGlobals) = postSolution
3441
SolutionGuid = {3D063199-4222-4D97-9059-BCE39666CE39}

FlipnoteDesktop/App.xaml.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ private void Application_Startup(object sender, StartupEventArgs e)
7474
{
7575

7676
}
77-
}
78-
79-
public static void ImportPlugin(string dllpath)
80-
{
81-
Assembly myassembly = Assembly.LoadFrom(dllpath);
82-
Type type = myassembly.GetType("FDHeader.Metadata");
83-
string plugin_name = type.GetField("PluginName").GetValue(null) as string;
84-
///
85-
}
77+
}
8678
}
8779
}

FlipnoteDesktop/Drawable/BrushPatternSample.xaml.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ public BrushPatternSample()
2626
InitializeComponent();
2727
Image.Source = new WriteableBitmap(12, 12, 96, 96, PixelFormats.Indexed2,
2828
new BitmapPalette(new List<Color> { Colors.White, Colors.Black }));
29-
}
30-
31-
public bool IsPen;
29+
}
3230

3331
internal static DependencyProperty PatternNameProperty = DependencyProperty.Register("PatternName", typeof(string), typeof(BrushPatternSample),
3432
new PropertyMetadata("Default", new PropertyChangedCallback(PatternNamePropertyChanged)));

FlipnoteDesktop/Drawable/PenPatternSample.xaml.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public PenPatternSample()
2828
InitializeComponent();
2929
Image.Source = new WriteableBitmap(32, 32, 96, 96, PixelFormats.Indexed2,
3030
new BitmapPalette(new List<Color> { Colors.White, Colors.Black }));
31-
}
32-
33-
public bool IsPen;
31+
}
3432

3533
public static DependencyProperty PatternNameProperty = DependencyProperty.Register("PatternName", typeof(string), typeof(PenPatternSample),
3634
new PropertyMetadata("Default", new PropertyChangedCallback(PatternNamePropertyChanged)));
@@ -63,7 +61,7 @@ private static void PatternNamePropertyChanged(DependencyObject d, DependencyPro
6361
for (int t = 3; t < 29; t++)
6462
{
6563
double a = (t * 0.0625 - 1);
66-
int y = (int)(25 * a * a * a - a) + 16;
64+
int y = (int)(25 * a * a * a + a) + 16;
6765
var pts = LineTool.GetLinePixels(x0, y0, t, y);
6866
if (o.Pattern.ContinuousDraw)
6967
{

FlipnoteDesktop/Environment/Canvas/Generator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public Generator(bool usesBothLayers = false)
1717
UsesBothLayers = usesBothLayers;
1818
}
1919

20+
public abstract string Name { get; }
2021
public bool UsesBothLayers { get; }
2122

2223
/// <summary>

FlipnoteDesktop/Environment/Canvas/Generators/ExampleGenerator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class ExampleGenerator : Generator
1111
{
1212
public ExampleGenerator() { }
1313

14+
public override string Name { get => "Example"; }
15+
1416
public override List<DecodedFrame> GenerateFrames()
1517
{
1618
var res = new List<DecodedFrame>();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using FlipnoteDesktop.Environment.Canvas;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace FlipnoteDesktop.External.Plugins
9+
{
10+
internal class PluginData
11+
{
12+
public PluginData(string asmname, string classname, PluginTypes type, Type _class)
13+
{
14+
AssemblyName = asmname;
15+
ClassName = classname;
16+
PluginType = type;
17+
Class = _class;
18+
if (PluginType == PluginTypes.Generator)
19+
{
20+
PluginName = (Activator.CreateInstance(Class) as Generator).Name;
21+
}
22+
}
23+
24+
public static PluginData Failed(string asmname, string pluginname)
25+
=> new PluginData(asmname, pluginname, PluginTypes.Failed, null);
26+
27+
public string AssemblyName { get; }
28+
public string ClassName { get; }
29+
public string PluginName { get; }
30+
public PluginTypes PluginType { get; }
31+
public Type Class { get; }
32+
}
33+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using FlipnoteDesktop.Environment.Canvas;
2+
using FlipnoteDesktop.Windows;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Controls;
10+
11+
namespace FlipnoteDesktop.External.Plugins
12+
{
13+
internal static class PluginManager
14+
{
15+
public static void ImportPlugins(string dllpath)
16+
{
17+
try
18+
{
19+
Assembly assembly = Assembly.LoadFrom(dllpath);
20+
Type type = assembly.GetType("FDHeader.Metadata");
21+
var asm_name = type.GetField("PluginName").GetValue(null) as string;
22+
var exports = type.GetField("Exports").GetValue(null) as List<string>;
23+
for (int i = 0, cnt = exports.Count; i < cnt; i++)
24+
{
25+
try
26+
{
27+
var _class = assembly.GetType(exports[i]);
28+
if(_class.IsSubclassOf(typeof(Generator)))
29+
{
30+
Plugins.Add(new PluginData(asm_name, exports[i], PluginTypes.Generator, _class));
31+
}
32+
}
33+
catch(TypeLoadException)
34+
{
35+
Plugins.Add(PluginData.Failed(asm_name, exports[i]));
36+
}
37+
}
38+
}
39+
catch(Exception)
40+
{
41+
}
42+
}
43+
44+
public static List<PluginData> Plugins = new List<PluginData>();
45+
46+
public static void Populate(MainWindow wnd)
47+
{
48+
for (int i = 0, cnt = Plugins.Count; i < cnt; i++)
49+
{
50+
if(Plugins[i].PluginType==PluginTypes.Generator)
51+
{
52+
var item = new MenuItem();
53+
item.Header = Plugins[i].PluginName;
54+
item.Tag = Plugins[i].Class;
55+
item.Click += wnd.GeneratorMenuItem_Click;
56+
wnd.GeneratorsMenuItem.Items.Add(item);
57+
}
58+
}
59+
}
60+
}
61+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace FlipnoteDesktop.External.Plugins
8+
{
9+
internal enum PluginTypes
10+
{
11+
Failed,
12+
Generator
13+
}
14+
}

0 commit comments

Comments
 (0)