Skip to content

Commit c4425f9

Browse files
committed
Built-in plugin manager
1 parent c815412 commit c4425f9

File tree

141 files changed

+38297
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+38297
-0
lines changed

.vs/QuickLibrary/v16/.suo

10.5 KB
Binary file not shown.
40 KB
Binary file not shown.
32 KB
Binary file not shown.
3.29 MB
Binary file not shown.

QuickLibrary/PluginInfo.cs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using Utf8Json;
2+
3+
namespace QuickLibrary
4+
{
5+
public class PluginInfo
6+
{
7+
#region STRUCTS
8+
9+
public struct Author
10+
{
11+
public string name;
12+
public string link;
13+
}
14+
15+
public struct Target
16+
{
17+
public string name;
18+
public string minVersion;
19+
public string maxVersion;
20+
}
21+
22+
public struct Hotkey
23+
{
24+
public bool ctrl;
25+
public bool shift;
26+
public int key;
27+
}
28+
29+
public struct MultilangString
30+
{
31+
public string en;
32+
public string ru;
33+
public string es;
34+
35+
public string Get(string langCode)
36+
{
37+
string value;
38+
switch (langCode)
39+
{
40+
case "ru":
41+
value = ru;
42+
break;
43+
case "es":
44+
value = es;
45+
break;
46+
default:
47+
value = en;
48+
break;
49+
}
50+
return value;
51+
}
52+
}
53+
54+
public struct Function
55+
{
56+
public string name;
57+
public MultilangString title;
58+
public Hotkey hotkey;
59+
public bool configurable; // for pluginType = effect
60+
public bool inputRequired;
61+
public bool source;
62+
}
63+
64+
#endregion
65+
66+
#region VARIABLES
67+
68+
public string name;
69+
public string version;
70+
public string title;
71+
public MultilangString description;
72+
public string link;
73+
public Author[] authors;
74+
public int apiVer; // 2
75+
public string pluginType; // tool, effect
76+
public string inputType; // bitmap
77+
public string dllType; // csharp, cpp
78+
public Function[] functions;
79+
80+
#endregion
81+
82+
#region STATIC METHODS
83+
84+
public static PluginInfo FromJson(string json)
85+
{
86+
return JsonSerializer.Deserialize<PluginInfo>(json);
87+
}
88+
89+
#endregion
90+
91+
#region CONSTRUCTOR
92+
93+
public PluginInfo()
94+
{
95+
96+
}
97+
98+
#endregion
99+
}
100+
}

QuickLibrary/PluginMan.cs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Drawing;
4+
using System.IO;
5+
using System.Runtime.InteropServices;
6+
7+
namespace QuickLibrary
8+
{
9+
public class PluginMan
10+
{
11+
public static string pluginsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins");
12+
public static int apiVer = 2;
13+
14+
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
15+
public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName);
16+
17+
[DllImport("kernel32", SetLastError = true, EntryPoint = "GetProcAddress")]
18+
public static extern IntPtr GetProcAddressOrdinal(IntPtr hModule, string procName);
19+
20+
public delegate Bitmap RunFunction(
21+
Bitmap bmp = null,
22+
string path = null,
23+
string[] args = null
24+
);
25+
26+
public delegate string[] ConfFunction(
27+
Bitmap bmp = null,
28+
string path = null,
29+
bool darkMode = false,
30+
string language = "en",
31+
bool alwaysOnTop = false
32+
);
33+
34+
public delegate void PluginOutput(object sender, PluginOutputEventArgs poea);
35+
36+
public class PluginOutputEventArgs : EventArgs
37+
{
38+
public object subject { get; set; }
39+
}
40+
41+
public static PluginInfo[] GetPlugins(bool onlyAvailable, string pluginType)
42+
{
43+
List<PluginInfo> plugins = new List<PluginInfo>();
44+
DirectoryInfo di = new DirectoryInfo(pluginsFolder);
45+
if (di.Exists)
46+
{
47+
List<FileInfo> files = new List<FileInfo>();
48+
DirectoryInfo[] dirs = di.GetDirectories();
49+
for (int i = 0; i < dirs.Length; i++)
50+
{
51+
files.AddRange(dirs[i].GetFiles());
52+
dirs[i] = null;
53+
}
54+
for (int i = 0; i < files.Count; i++)
55+
{
56+
if (Path.GetExtension(files[i].Name) == ".json")
57+
{
58+
PluginInfo pi = PluginInfo.FromJson(File.ReadAllText(Path.Combine(di.FullName, files[i].DirectoryName, files[i].Name)));
59+
60+
if (onlyAvailable)
61+
{
62+
if (pi.apiVer == apiVer && pi.pluginType == pluginType)
63+
{
64+
plugins.Add(pi);
65+
}
66+
}
67+
else
68+
{
69+
plugins.Add(pi);
70+
}
71+
}
72+
files[i] = null;
73+
}
74+
}
75+
return plugins.ToArray();
76+
}
77+
78+
public static Image GetPluginIcon(string pluginName, string funcName, bool darkMode)
79+
{
80+
if (darkMode)
81+
{
82+
string path = Path.Combine(pluginsFolder, pluginName, funcName + ".dark.png");
83+
if (File.Exists(path))
84+
{
85+
return Bitmap.FromFile(path);
86+
}
87+
88+
path = Path.Combine(pluginsFolder, pluginName, funcName + ".png");
89+
if (File.Exists(path))
90+
{
91+
return Bitmap.FromFile(path);
92+
}
93+
94+
return null;
95+
}
96+
else
97+
{
98+
string path = Path.Combine(pluginsFolder, pluginName, funcName + ".light.png");
99+
if (File.Exists(path))
100+
{
101+
return Bitmap.FromFile(path);
102+
}
103+
104+
path = Path.Combine(pluginsFolder, pluginName, funcName + ".png");
105+
if (File.Exists(path))
106+
{
107+
return Bitmap.FromFile(path);
108+
}
109+
110+
return null;
111+
}
112+
}
113+
}
114+
}

QuickLibrary/QuickLibrary.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
</Reference>
3636
<Reference Include="System" />
3737
<Reference Include="System.Core" />
38+
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
39+
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.4.0\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
40+
</Reference>
41+
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
42+
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net47\System.ValueTuple.dll</HintPath>
43+
</Reference>
3844
<Reference Include="System.Xml.Linq" />
3945
<Reference Include="System.Data.DataSetExtensions" />
4046
<Reference Include="Microsoft.CSharp" />
@@ -43,6 +49,9 @@
4349
<Reference Include="System.Net.Http" />
4450
<Reference Include="System.Windows.Forms" />
4551
<Reference Include="System.Xml" />
52+
<Reference Include="Utf8Json, Version=1.3.7.0, Culture=neutral, PublicKeyToken=8a73d3ba7e392e27, processorArchitecture=MSIL">
53+
<HintPath>..\packages\Utf8Json.1.3.7\lib\net47\Utf8Json.dll</HintPath>
54+
</Reference>
4655
</ItemGroup>
4756
<ItemGroup>
4857
<Compile Include="DialogMan.cs" />
@@ -56,6 +65,8 @@
5665
<Compile Include="Dwm.cs" />
5766
<Compile Include="FileAssociation.cs" />
5867
<Compile Include="NativeMan.cs" />
68+
<Compile Include="PluginInfo.cs" />
69+
<Compile Include="PluginMan.cs" />
5970
<Compile Include="Properties\Resources.Designer.cs">
6071
<AutoGen>True</AutoGen>
6172
<DesignTime>True</DesignTime>
3 KB
Binary file not shown.
6 KB
Binary file not shown.
25.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)