2016-01-27 09:11:59 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include <io.h>
|
|
|
|
#include "PluginList.h"
|
|
|
|
#include <Project64-core/Plugins/PluginBase.h>
|
|
|
|
|
|
|
|
CPluginList::CPluginList(bool bAutoFill /* = true */) :
|
|
|
|
m_PluginDir(g_Settings->LoadStringVal(Directory_Plugin), "")
|
|
|
|
{
|
|
|
|
if (bAutoFill)
|
|
|
|
{
|
|
|
|
LoadList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CPluginList::~CPluginList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPluginList::GetPluginCount() const
|
|
|
|
{
|
|
|
|
return m_PluginList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const CPluginList::PLUGIN * CPluginList::GetPluginInfo(int indx) const
|
|
|
|
{
|
|
|
|
if (indx < 0 || indx >= (int)m_PluginList.size())
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
return nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
return &m_PluginList[indx];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPluginList::LoadList()
|
|
|
|
{
|
|
|
|
WriteTrace(TraceUserInterface, TraceDebug, "Start");
|
|
|
|
m_PluginList.clear();
|
|
|
|
AddPluginFromDir(m_PluginDir);
|
|
|
|
WriteTrace(TraceUserInterface, TraceDebug, "Done");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPluginList::AddPluginFromDir(CPath Dir)
|
|
|
|
{
|
2016-04-12 07:53:40 +00:00
|
|
|
Dir.SetNameExtension("*");
|
|
|
|
if (Dir.FindFirst(CPath::FIND_ATTRIBUTE_SUBDIR))
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
AddPluginFromDir(Dir);
|
|
|
|
} while (Dir.FindNext());
|
|
|
|
Dir.UpDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
Dir.SetNameExtension("*.dll");
|
|
|
|
if (Dir.FindFirst())
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
HMODULE hLib = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (hLib)
|
|
|
|
{
|
|
|
|
FreeLibrary(hLib);
|
2021-04-12 11:35:39 +00:00
|
|
|
hLib = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//UINT LastErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS );
|
|
|
|
WriteTrace(TraceUserInterface, TraceDebug, "loading %s", (LPCSTR)Dir);
|
2020-05-12 12:19:05 +00:00
|
|
|
hLib = LoadLibrary(stdstr((LPCSTR)Dir).ToUTF16().c_str());
|
2016-01-27 09:11:59 +00:00
|
|
|
//SetErrorMode(LastErrorMode);
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
if (hLib == nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
DWORD LoadError = GetLastError();
|
2016-02-01 06:10:43 +00:00
|
|
|
WriteTrace(TraceUserInterface, TraceDebug, "failed to load %s (error: %d)", (LPCSTR)Dir, LoadError);
|
2016-01-27 09:11:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void(CALL *GetDllInfo) (PLUGIN_INFO * PluginInfo);
|
|
|
|
GetDllInfo = (void(CALL *)(PLUGIN_INFO *))GetProcAddress(hLib, "GetDllInfo");
|
2021-04-12 11:35:39 +00:00
|
|
|
if (GetDllInfo == nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLUGIN Plugin = { 0 };
|
|
|
|
Plugin.Info.MemoryBswaped = true;
|
|
|
|
GetDllInfo(&Plugin.Info);
|
|
|
|
if (!CPlugin::ValidPluginVersion(Plugin.Info))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plugin.FullPath = Dir;
|
|
|
|
Plugin.FileName = stdstr((const char *)Dir).substr(strlen(m_PluginDir));
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
if (GetProcAddress(hLib, "DllAbout") != nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
Plugin.AboutFunction = true;
|
|
|
|
}
|
|
|
|
m_PluginList.push_back(Plugin);
|
|
|
|
} while (Dir.FindNext());
|
|
|
|
|
|
|
|
if (hLib)
|
|
|
|
{
|
|
|
|
FreeLibrary(hLib);
|
2021-04-12 11:35:39 +00:00
|
|
|
hLib = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-10 09:37:35 +00:00
|
|
|
}
|