forked from Radfordhound/HedgeLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Addon.cs
50 lines (42 loc) · 1.38 KB
/
Addon.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
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;
namespace HedgeArchiveEditor
{
public class Addon
{
public static List<Addon> Addons = new List<Addon>();
public List<ArchiveAddon> Archives = new List<ArchiveAddon>();
public static void LoadAddons(string addonsDir)
{
foreach (var filePath in Directory.GetFiles(addonsDir))
{
try
{
var lib = Assembly.LoadFile(filePath);
var addonType = lib.GetExportedTypes().ToList()
.Find(t => t.IsSubclassOf(typeof(Addon)));
if (addonType == null)
continue;
var addon = Activator.CreateInstance(addonType) as Addon;
if (addon.OnLoad())
Addons.Add(addon);
}
catch(Exception e)
{ MessageBox.Show(e.ToString()); continue; }
}
}
public virtual bool OnLoad() { return false; }
public class ArchiveAddon
{
public Type ArchiveType;
public string ArchiveName;
public List<string> FileExtensions = new List<string>();
}
}
}