-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugins.cpp
53 lines (48 loc) · 1.09 KB
/
Plugins.cpp
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
51
52
53
#include "Plugins.h"
#include <Windows.h>
Plugin *Plugins::plugins;
Plugin::Plugin(char *path)
{
this->module = LoadLibrary(path);
this->prev = nullptr;
}
Plugin::~Plugin()
{
FreeLibrary(this->module);
}
void Plugins::LoadPlugins()
{
WIN32_FIND_DATA FindFileData;
memset(&FindFileData, 0, sizeof(WIN32_FIND_DATA));
HANDLE hFind = FindFirstFile("stats\\*.stats", &FindFileData);
Plugins::plugins = nullptr;
if (hFind != INVALID_HANDLE_VALUE) {
do {
if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
char filename[MAX_PATH];
strcpy_s(filename, "stats\\");
strcat_s(filename, FindFileData.cFileName);
Plugin *plugin = new Plugin(filename);
if (plugin) {
if (!plugin->module) {
delete plugin;
} else {
plugin->prev = Plugins::plugins;
Plugins::plugins = plugin;
}
}
}
} while (FindNextFile(hFind, &FindFileData));
FindClose(hFind);
}
}
void Plugins::UnloadPlugins()
{
Plugin *plugin = Plugins::plugins;
while (plugin) {
Plugin *prev = plugin->prev;
delete plugin;
plugin = prev;
}
Plugins::plugins = nullptr;
}