Skip to content

Commit 0130af0

Browse files
committed
v2.5.6 (1)
1 parent e0be8ed commit 0130af0

24 files changed

+391
-214
lines changed

.vs/QuickLibrary/v16/.suo

12.5 KB
Binary file not shown.

QuickLibrary/OkForm.Designer.cs

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

QuickLibrary/PluginInfo.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,44 @@
1-
using Utf8Json;
1+
using System;
2+
using Utf8Json;
23

34
namespace QuickLibrary
45
{
6+
[Serializable]
57
public class PluginInfo
68
{
79
#region STRUCTS
810

11+
[Serializable]
912
public struct Author
1013
{
1114
public string name;
1215
public string link;
1316
}
1417

18+
[Serializable]
1519
public struct MultilangString
1620
{
1721
public string en;
22+
public string cn;
23+
public string fr;
24+
public string hu;
1825
public string ru;
1926
public string es;
20-
27+
2128
public string Get(string langCode)
2229
{
2330
string value;
2431
switch (langCode)
2532
{
33+
case "cn":
34+
value = cn;
35+
break;
36+
case "fr":
37+
value = fr;
38+
break;
39+
case "hu":
40+
value = hu;
41+
break;
2642
case "ru":
2743
value = ru;
2844
break;
@@ -37,6 +53,16 @@ public string Get(string langCode)
3753
}
3854
}
3955

56+
[Serializable]
57+
public struct Hotkey
58+
{
59+
public bool ctrl;
60+
public bool shift;
61+
public bool alt;
62+
public int key;
63+
}
64+
65+
[Serializable]
4066
public struct Function
4167
{
4268
public string name;
@@ -45,6 +71,7 @@ public struct Function
4571
public bool inputRequired;
4672
public bool dialog;
4773
public bool hideMainForm;
74+
public Hotkey hotkey;
4875
}
4976

5077
#endregion

QuickLibrary/PluginMan.cs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,18 @@ public class OutputEventArgs : EventArgs
2727
public object input { get; set; }
2828
}
2929

30-
public static PluginInfo[] GetPlugins(bool onlyAvailable)
30+
public static string GenerateCacheStr()
31+
{
32+
return Convert.ToBase64String(SerializeMan.ObjectToByteArray(GetPlugins()));
33+
}
34+
35+
public static PluginInfo[] GetPluginsCache(string cacheStr)
36+
{
37+
if (cacheStr.Length > 0) return SerializeMan.ByteArrayToObject(Convert.FromBase64String(cacheStr)) as PluginInfo[];
38+
else return new PluginInfo[] { };
39+
}
40+
41+
private static PluginInfo[] GetPlugins()
3142
{
3243
List<PluginInfo> plugins = new List<PluginInfo>();
3344
DirectoryInfo di = new DirectoryInfo(pluginsFolder);
@@ -39,18 +50,7 @@ public static PluginInfo[] GetPlugins(bool onlyAvailable)
3950
if (Path.GetExtension(files[i].Name) == ".json")
4051
{
4152
PluginInfo pi = PluginInfo.FromJson(File.ReadAllText(Path.Combine(di.FullName, files[i].Name)));
42-
43-
if (onlyAvailable)
44-
{
45-
if (pi.apiVer == apiVer && pi.inputType == inputType)
46-
{
47-
plugins.Add(pi);
48-
}
49-
}
50-
else
51-
{
52-
plugins.Add(pi);
53-
}
53+
if (pi.apiVer == apiVer && pi.inputType == inputType) plugins.Add(pi);
5454
}
5555
files[i] = null;
5656
}
@@ -63,32 +63,20 @@ public static Image GetPluginIcon(string pluginName, string funcName, bool darkM
6363
if (darkMode)
6464
{
6565
string path = Path.Combine(pluginsFolder, pluginName, funcName + ".dark.png");
66-
if (File.Exists(path))
67-
{
68-
return Bitmap.FromFile(path);
69-
}
66+
if (File.Exists(path)) return Bitmap.FromFile(path);
7067

7168
path = Path.Combine(pluginsFolder, pluginName, funcName + ".png");
72-
if (File.Exists(path))
73-
{
74-
return Bitmap.FromFile(path);
75-
}
69+
if (File.Exists(path)) return Bitmap.FromFile(path);
7670

7771
return null;
7872
}
7973
else
8074
{
8175
string path = Path.Combine(pluginsFolder, pluginName, funcName + ".light.png");
82-
if (File.Exists(path))
83-
{
84-
return Bitmap.FromFile(path);
85-
}
76+
if (File.Exists(path)) return Bitmap.FromFile(path);
8677

8778
path = Path.Combine(pluginsFolder, pluginName, funcName + ".png");
88-
if (File.Exists(path))
89-
{
90-
return Bitmap.FromFile(path);
91-
}
79+
if (File.Exists(path)) return Bitmap.FromFile(path);
9280

9381
return null;
9482
}

QuickLibrary/PluginMenuItem.cs

Lines changed: 78 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,70 +9,104 @@ namespace QuickLibrary
99
public class PluginMenuItem : ToolStripMenuItem
1010
{
1111
private string dllPath;
12+
private PluginInfo pi;
13+
private PluginInfo.Function func;
14+
private bool darkMode;
15+
private string langCode;
1216

1317
public PluginMenuItem(
14-
object input,
15-
string path,
16-
bool darkMode,
1718
PluginInfo pi,
1819
PluginInfo.Function func,
19-
bool alwaysOnTop,
2020
string langCode,
21-
Form mainForm,
22-
object secondaryArg
21+
bool darkMode
2322
)
2423
{
24+
this.pi = pi;
25+
this.func = func;
26+
this.darkMode = darkMode;
27+
this.langCode = langCode;
28+
2529
Text = func.title.Get(langCode);
2630
dllPath = Path.Combine(PluginMan.pluginsFolder, pi.name, pi.name + ".dll");
2731

32+
if (func.hotkey.ctrl)
33+
{
34+
if (func.hotkey.shift)
35+
{
36+
if (func.hotkey.alt) ShortcutKeys = Keys.Control | Keys.Shift | Keys.Alt | (Keys)func.hotkey.key;
37+
else ShortcutKeys = Keys.Control | Keys.Shift | (Keys)func.hotkey.key;
38+
}
39+
else
40+
{
41+
if (func.hotkey.alt) ShortcutKeys = Keys.Control | Keys.Alt | (Keys)func.hotkey.key;
42+
else ShortcutKeys = Keys.Control | (Keys)func.hotkey.key;
43+
}
44+
}
45+
else if (func.hotkey.shift)
46+
{
47+
if (func.hotkey.alt) ShortcutKeys = Keys.Shift | Keys.Alt | (Keys)func.hotkey.key;
48+
else ShortcutKeys = Keys.Shift | (Keys)func.hotkey.key;
49+
}
50+
else if (func.hotkey.alt)
51+
{
52+
ShortcutKeys = Keys.Alt | (Keys)func.hotkey.key;
53+
}
54+
else
55+
{
56+
ShortcutKeys = (Keys)func.hotkey.key;
57+
}
58+
2859
if (func.dialog)
2960
{
3061
Text += " ...";
3162
}
3263

33-
if (func.inputRequired)
64+
Image = PluginMan.GetPluginIcon(pi.name, func.name, darkMode);
65+
}
66+
67+
public void ProcessPlugin(
68+
object input,
69+
string path,
70+
bool alwaysOnTop,
71+
object secondaryArg,
72+
Form mainForm
73+
)
74+
{
75+
if (func.inputRequired && input == null) return;
76+
77+
if (mainForm != null && func.hideMainForm) mainForm.Hide();
78+
79+
object res = null;
80+
if (pi.dllType == "cpp")
3481
{
35-
Enabled = input != null;
82+
IntPtr pluginPtr = NativeMan.LoadLibrary(dllPath);
83+
IntPtr funcPtr = NativeMan.GetProcAddressOrdinal(pluginPtr, func.name);
84+
var callback = Marshal.GetDelegateForFunctionPointer<PluginMan.RunFunction>(funcPtr);
85+
res = callback(input, path, darkMode, langCode, alwaysOnTop, secondaryArg);
3686
}
37-
38-
Click += (s, e) =>
87+
else if (pi.dllType == "csharp")
3988
{
40-
if (mainForm != null && func.hideMainForm)
41-
{
42-
mainForm.Hide();
43-
}
89+
Assembly assembly = Assembly.LoadFrom(dllPath);
90+
Type type = assembly.GetType(Path.GetFileNameWithoutExtension(dllPath).Replace("-", "_") + ".Main");
91+
object instance = Activator.CreateInstance(type);
92+
res = type.GetMethod(func.name).Invoke(instance, new object[] {
93+
input,
94+
path,
95+
darkMode,
96+
langCode,
97+
alwaysOnTop,
98+
secondaryArg
99+
}) as object;
100+
}
44101

45-
Object res;
46-
if (pi.dllType == "cpp")
47-
{
48-
IntPtr pluginPtr = NativeMan.LoadLibrary(dllPath);
49-
IntPtr funcPtr = NativeMan.GetProcAddressOrdinal(pluginPtr, func.name);
50-
var callback = Marshal.GetDelegateForFunctionPointer<PluginMan.RunFunction>(funcPtr);
51-
res = callback(input, path, darkMode, langCode, alwaysOnTop, secondaryArg);
52-
}
53-
else if (pi.dllType == "csharp")
102+
if (res != null)
103+
{
104+
PluginMan.OutputEventArgs oea = new PluginMan.OutputEventArgs
54105
{
55-
Assembly assembly = Assembly.LoadFrom(dllPath);
56-
Type type = assembly.GetType(Path.GetFileNameWithoutExtension(dllPath).Replace("-", "_") + ".Main");
57-
object instance = Activator.CreateInstance(type);
58-
res = type.GetMethod(func.name).Invoke(instance, new object[] {
59-
input,
60-
path,
61-
darkMode,
62-
langCode,
63-
alwaysOnTop,
64-
secondaryArg
65-
}) as Object;
66-
67-
PluginMan.OutputEventArgs oea = new PluginMan.OutputEventArgs
68-
{
69-
input = res
70-
};
71-
OnOutput(oea);
72-
}
73-
};
74-
75-
Image = PluginMan.GetPluginIcon(pi.name, func.name, darkMode);
106+
input = res
107+
};
108+
OnOutput(oea);
109+
}
76110
}
77111

78112
protected virtual void OnOutput(PluginMan.OutputEventArgs e)

0 commit comments

Comments
 (0)