82 lines
1.3 KiB
C
82 lines
1.3 KiB
C
![]() |
#include "plugin.h"
|
||
|
|
||
|
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
|
||
|
|
||
|
typedef struct _loaded_plugin
|
||
|
{
|
||
|
struct _loaded_plugin* next;
|
||
|
NSISPLUGINCALLBACK proc;
|
||
|
HMODULE dll;
|
||
|
}
|
||
|
loaded_plugin;
|
||
|
|
||
|
static loaded_plugin* g_plugins = 0; // not thread safe!
|
||
|
|
||
|
void NSISCALL Plugins_SendMsgToAllPlugins(int msg)
|
||
|
{
|
||
|
loaded_plugin* p;
|
||
|
|
||
|
for (p = g_plugins; p; p = p->next)
|
||
|
{
|
||
|
p->proc(msg);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void NSISCALL Plugins_UnloadAll()
|
||
|
{
|
||
|
loaded_plugin* p = g_plugins;
|
||
|
|
||
|
Plugins_SendMsgToAllPlugins(NSPIM_UNLOAD);
|
||
|
|
||
|
while (p)
|
||
|
{
|
||
|
loaded_plugin* oldp = p;
|
||
|
p = oldp->next;
|
||
|
FreeLibrary(oldp->dll);
|
||
|
GlobalFree(oldp);
|
||
|
}
|
||
|
|
||
|
g_plugins = NULL;
|
||
|
}
|
||
|
|
||
|
BOOL NSISCALL Plugins_CanUnload(HANDLE pluginHandle)
|
||
|
{
|
||
|
loaded_plugin* p;
|
||
|
|
||
|
for (p = g_plugins; p; p = p->next)
|
||
|
{
|
||
|
if (p->dll == pluginHandle)
|
||
|
{
|
||
|
return FALSE;
|
||
|
}
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
BOOL NSISCALL RegisterPluginCallback(HMODULE pluginHandle, NSISPLUGINCALLBACK proc)
|
||
|
{
|
||
|
loaded_plugin* p;
|
||
|
|
||
|
if (!Plugins_CanUnload(pluginHandle))
|
||
|
{
|
||
|
// already registered
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
p = (loaded_plugin*) GlobalAlloc(LPTR, sizeof(loaded_plugin));
|
||
|
if (p)
|
||
|
{
|
||
|
p->proc = proc;
|
||
|
p->dll = pluginHandle;
|
||
|
p->next = g_plugins;
|
||
|
|
||
|
g_plugins = p;
|
||
|
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
#endif /* #ifdef NSIS_CONFIG_PLUGIN_SUPPORT */
|