Skip to content

Commit 9fcf21e

Browse files
committed
v2.3.2
1 parent af4d607 commit 9fcf21e

25 files changed

+247
-36
lines changed

.vs/QuickLibrary/v16/.suo

-11 KB
Binary file not shown.
0 Bytes
Binary file not shown.
32 KB
Binary file not shown.
3.96 MB
Binary file not shown.

QuickLibrary/NativeMan.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ public struct MARGINS
7272
public int Bottom;
7373
}
7474

75+
// KERNEL32 METHODS
76+
77+
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
78+
public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName);
79+
80+
[DllImport("kernel32", SetLastError = true, EntryPoint = "GetProcAddress")]
81+
public static extern IntPtr GetProcAddressOrdinal(IntPtr hModule, string procName);
82+
7583
// USER32 METHODS
7684

7785
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]

QuickLibrary/PluginInfo.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ public struct Author
1212
public string link;
1313
}
1414

15-
public struct Hotkey
16-
{
17-
public bool ctrl;
18-
public bool shift;
19-
public int key;
20-
}
21-
2215
public struct MultilangString
2316
{
2417
public string en;
@@ -48,10 +41,9 @@ public struct Function
4841
{
4942
public string name;
5043
public MultilangString title;
51-
public Hotkey hotkey;
52-
public bool configurable; // for pluginType = effect
53-
public bool inputRequired;
54-
public bool source;
44+
public string type; // tool, effect
45+
public bool configurable;
46+
public bool inputRequired; // for type = tool
5547
}
5648

5749
#endregion
@@ -65,7 +57,6 @@ public struct Function
6557
public string link;
6658
public Author[] authors;
6759
public int apiVer; // 2
68-
public string pluginType; // tool, effect
6960
public string inputType; // bitmap
7061
public string dllType; // csharp, cpp
7162
public Function[] functions;

QuickLibrary/PluginMan.cs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,18 @@ namespace QuickLibrary
88
{
99
public class PluginMan
1010
{
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);
11+
public static string pluginsFolder = null;
12+
public static int apiVer = 0;
13+
public static string inputType = null;
1914

2015
public delegate Bitmap RunFunction(
21-
Bitmap bmp = null,
16+
Object input = null,
2217
string path = null,
2318
string[] args = null
2419
);
2520

2621
public delegate string[] ConfFunction(
27-
Bitmap bmp = null,
22+
Object input = null,
2823
string path = null,
2924
bool darkMode = false,
3025
string language = "en",
@@ -38,28 +33,22 @@ public class PluginOutputEventArgs : EventArgs
3833
public object subject { get; set; }
3934
}
4035

41-
public static PluginInfo[] GetPlugins(bool onlyAvailable, string pluginType)
36+
public static PluginInfo[] GetPlugins(bool onlyAvailable)
4237
{
4338
List<PluginInfo> plugins = new List<PluginInfo>();
4439
DirectoryInfo di = new DirectoryInfo(pluginsFolder);
4540
if (di.Exists)
4641
{
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++)
42+
FileInfo[] files = di.GetFiles();
43+
for (int i = 0; i < files.Length; i++)
5544
{
5645
if (Path.GetExtension(files[i].Name) == ".json")
5746
{
58-
PluginInfo pi = PluginInfo.FromJson(File.ReadAllText(Path.Combine(di.FullName, files[i].DirectoryName, files[i].Name)));
47+
PluginInfo pi = PluginInfo.FromJson(File.ReadAllText(Path.Combine(di.FullName, files[i].Name)));
5948

6049
if (onlyAvailable)
6150
{
62-
if (pi.apiVer == apiVer && pi.pluginType == pluginType)
51+
if (pi.apiVer == apiVer && pi.inputType == inputType)
6352
{
6453
plugins.Add(pi);
6554
}

QuickLibrary/PluginMenuItem.cs

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
using System;
2+
using System.IO;
3+
using System.Reflection;
4+
using System.Runtime.InteropServices;
5+
using System.Windows.Forms;
6+
7+
namespace QuickLibrary
8+
{
9+
public class PluginMenuItem : ToolStripMenuItem
10+
{
11+
private string dllPath;
12+
13+
public PluginMenuItem(
14+
object input, // bitmap
15+
string path,
16+
bool darkMode,
17+
PluginInfo pi,
18+
PluginInfo.Function func,
19+
string applyText,
20+
string configureText,
21+
bool alwaysOnTop,
22+
string langCode
23+
)
24+
{
25+
Text = func.title.Get(langCode);
26+
dllPath = Path.Combine(PluginMan.pluginsFolder, pi.name, pi.name + ".dll");
27+
28+
if (func.inputRequired)
29+
{
30+
Enabled = input != null;
31+
}
32+
33+
if (func.type == "effect")
34+
{
35+
ToolStripMenuItem apply = new ToolStripMenuItem(applyText);
36+
apply.Click += (s, e) =>
37+
{
38+
Object res;
39+
if (pi.dllType == "cpp")
40+
{
41+
IntPtr pluginPtr = NativeMan.LoadLibrary(dllPath);
42+
IntPtr funcPtr = NativeMan.GetProcAddressOrdinal(pluginPtr, func.name);
43+
var callback = Marshal.GetDelegateForFunctionPointer<PluginMan.RunFunction>(funcPtr);
44+
res = callback(input, path);
45+
}
46+
else if (pi.dllType == "csharp")
47+
{
48+
Assembly assembly = Assembly.LoadFrom(dllPath);
49+
Type type = assembly.GetType(Path.GetFileNameWithoutExtension(dllPath).Replace("-", "_") + ".Main");
50+
object instance = Activator.CreateInstance(type);
51+
res = type.GetMethod(func.name).Invoke(instance, new object[] {
52+
input,
53+
path
54+
}) as Object;
55+
56+
OutputEventArgs oea = new OutputEventArgs
57+
{
58+
input = res
59+
};
60+
OnOutput(oea);
61+
}
62+
};
63+
DropDownItems.Add(apply);
64+
65+
if (func.configurable)
66+
{
67+
ToolStripMenuItem conf = new ToolStripMenuItem(configureText + " ...");
68+
conf.Click += (s, e) =>
69+
{
70+
if (pi.dllType == "cpp")
71+
{
72+
IntPtr pluginPtr = NativeMan.LoadLibrary(dllPath);
73+
IntPtr funcPtr = NativeMan.GetProcAddressOrdinal(pluginPtr, func.name + "_conf");
74+
var callback = Marshal.GetDelegateForFunctionPointer<PluginMan.ConfFunction>(funcPtr);
75+
callback(input, path, darkMode, langCode, alwaysOnTop);
76+
}
77+
else if (pi.dllType == "csharp")
78+
{
79+
Assembly assembly = Assembly.LoadFrom(dllPath);
80+
Type type = assembly.GetType(Path.GetFileNameWithoutExtension(dllPath).Replace("-", "_") + ".Main");
81+
object instance = Activator.CreateInstance(type);
82+
type.GetMethod(func.name + "_conf").Invoke(instance, new object[] {
83+
input,
84+
path,
85+
darkMode,
86+
langCode,
87+
alwaysOnTop
88+
});
89+
}
90+
};
91+
if (darkMode)
92+
{
93+
conf.Image = Properties.Resources.white_options;
94+
}
95+
else
96+
{
97+
conf.Image = Properties.Resources.black_options;
98+
}
99+
DropDownItems.Add(conf);
100+
}
101+
102+
Image = PluginMan.GetPluginIcon(pi.name, func.name, darkMode);
103+
if (darkMode)
104+
{
105+
DropDown.BackColor = ThemeManager.DarkSecondColor;
106+
apply.Image = Properties.Resources.white_check;
107+
}
108+
else
109+
{
110+
DropDown.BackColor = ThemeManager.LightSecondColor;
111+
apply.Image = Properties.Resources.black_check;
112+
}
113+
}
114+
else if (func.type == "tool")
115+
{
116+
Text += " ...";
117+
Click += (s, e) =>
118+
{
119+
if (pi.dllType == "cpp")
120+
{
121+
IntPtr pluginPtr = NativeMan.LoadLibrary(dllPath);
122+
IntPtr funcPtr = NativeMan.GetProcAddressOrdinal(pluginPtr, func.name + "_tool");
123+
var callback = Marshal.GetDelegateForFunctionPointer<PluginMan.ConfFunction>(funcPtr);
124+
callback(input, path, darkMode, langCode, alwaysOnTop);
125+
}
126+
else if (pi.dllType == "csharp")
127+
{
128+
Assembly assembly = Assembly.LoadFrom(dllPath);
129+
Type type = assembly.GetType(Path.GetFileNameWithoutExtension(dllPath).Replace("-", "_") + ".Main");
130+
object instance = Activator.CreateInstance(type);
131+
type.GetMethod(func.name + "_tool").Invoke(instance, new object[] {
132+
input,
133+
path,
134+
darkMode,
135+
langCode,
136+
alwaysOnTop
137+
});
138+
}
139+
};
140+
Image = PluginMan.GetPluginIcon(pi.name, func.name, darkMode);
141+
}
142+
}
143+
144+
protected virtual void OnOutput(OutputEventArgs e)
145+
{
146+
Output?.Invoke(this, e);
147+
}
148+
public event EventHandler<OutputEventArgs> Output;
149+
}
150+
151+
public class OutputEventArgs : EventArgs
152+
{
153+
public Object input { get; set; }
154+
}
155+
}

QuickLibrary/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// set of attributes. Change these attribute values to modify the information
77
// associated with an assembly.
88
[assembly: AssemblyTitle("QuickLibrary")]
9-
[assembly: AssemblyDescription("WinForms Control class library for \"Quick\" apps and Tinote Sticky Notes (.NET Framework).")]
9+
[assembly: AssemblyDescription("WinForms/C# library for \"Quick\" apps (.NET Framework)")]
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("Module Art")]
1212
[assembly: AssemblyProduct("QuickLibrary")]
@@ -32,6 +32,6 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.3.1")]
36-
[assembly: AssemblyFileVersion("2.3.1")]
35+
[assembly: AssemblyVersion("2.3.2")]
36+
[assembly: AssemblyFileVersion("2.3.2")]
3737
[assembly: NeutralResourcesLanguage("en")]

QuickLibrary/Properties/Resources.Designer.cs

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)