2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
2015-11-10 05:21:49 +00:00
|
|
|
* Project64 - A Nintendo 64 emulator. *
|
2012-12-19 09:30:18 +00:00
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2010-06-04 06:25:07 +00:00
|
|
|
#include "stdafx.h"
|
2015-10-25 10:50:28 +00:00
|
|
|
#include <io.h>
|
2015-11-12 09:15:49 +00:00
|
|
|
#include "Plugin List.h"
|
|
|
|
#include <Project64\Plugins\Plugin Base.h>
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
CPluginList::CPluginList(bool bAutoFill /* = true */) :
|
2015-11-12 08:43:32 +00:00
|
|
|
m_PluginDir(g_Settings->LoadStringVal(Directory_Plugin), "")
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
2015-11-12 08:43:32 +00:00
|
|
|
if (bAutoFill)
|
|
|
|
{
|
|
|
|
LoadList();
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CPluginList::~CPluginList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPluginList::GetPluginCount() const
|
|
|
|
{
|
2015-11-12 08:43:32 +00:00
|
|
|
return m_PluginList.size();
|
2008-11-14 20:51:06 +00:00
|
|
|
}
|
|
|
|
|
2015-11-12 08:43:32 +00:00
|
|
|
const CPluginList::PLUGIN * CPluginList::GetPluginInfo(int indx) const
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
2015-11-12 08:43:32 +00:00
|
|
|
if (indx < 0 || indx >= (int)m_PluginList.size())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return &m_PluginList[indx];
|
2008-11-14 20:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CPluginList::LoadList()
|
|
|
|
{
|
2015-11-12 08:43:32 +00:00
|
|
|
WriteTrace(TraceDebug, __FUNCTION__ ": Start");
|
|
|
|
m_PluginList.clear();
|
|
|
|
AddPluginFromDir(m_PluginDir);
|
|
|
|
WriteTrace(TraceDebug, __FUNCTION__ ": Done");
|
|
|
|
return true;
|
2008-11-14 20:51:06 +00:00
|
|
|
}
|
|
|
|
|
2015-11-12 08:43:32 +00:00
|
|
|
void CPluginList::AddPluginFromDir(CPath Dir)
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
2015-11-12 08:43:32 +00:00
|
|
|
Dir.SetNameExtension("*.*");
|
|
|
|
if (Dir.FindFirst(_A_SUBDIR))
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
AddPluginFromDir(Dir);
|
|
|
|
} while (Dir.FindNext());
|
|
|
|
Dir.UpDirectory();
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
|
2015-11-12 08:43:32 +00:00
|
|
|
Dir.SetNameExtension("*.dll");
|
|
|
|
if (Dir.FindFirst())
|
|
|
|
{
|
|
|
|
HMODULE hLib = NULL;
|
|
|
|
do {
|
|
|
|
if (hLib)
|
|
|
|
{
|
|
|
|
FreeLibrary(hLib);
|
|
|
|
hLib = NULL;
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
|
2015-11-12 08:43:32 +00:00
|
|
|
//UINT LastErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS );
|
|
|
|
WriteTraceF(TraceDebug, __FUNCTION__ ": loading %s", (LPCSTR)Dir);
|
|
|
|
hLib = LoadLibrary(Dir);
|
|
|
|
//SetErrorMode(LastErrorMode);
|
2008-11-14 20:51:06 +00:00
|
|
|
|
2015-11-12 08:43:32 +00:00
|
|
|
if (hLib == NULL)
|
|
|
|
{
|
|
|
|
DWORD LoadError = GetLastError();
|
|
|
|
WriteTraceF(TraceDebug, __FUNCTION__ ": failed to loadi %s (error: %d)", (LPCSTR)Dir, LoadError);
|
|
|
|
continue;
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
|
2015-11-12 08:43:32 +00:00
|
|
|
void(__cdecl *GetDllInfo) (PLUGIN_INFO * PluginInfo);
|
|
|
|
GetDllInfo = (void(__cdecl *)(PLUGIN_INFO *))GetProcAddress(hLib, "GetDllInfo");
|
|
|
|
if (GetDllInfo == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
|
2015-11-12 08:43:32 +00:00
|
|
|
PLUGIN Plugin = { 0 };
|
|
|
|
Plugin.Info.MemoryBswaped = true;
|
|
|
|
GetDllInfo(&Plugin.Info);
|
2015-11-12 09:15:49 +00:00
|
|
|
if (!CPlugin::ValidPluginVersion(Plugin.Info))
|
2015-11-12 08:43:32 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
|
2015-11-12 08:43:32 +00:00
|
|
|
Plugin.FullPath = Dir;
|
2015-11-12 09:15:49 +00:00
|
|
|
Plugin.FileName = stdstr((const char *)Dir).substr(strlen(m_PluginDir));
|
2008-11-14 20:51:06 +00:00
|
|
|
|
2015-11-12 08:43:32 +00:00
|
|
|
if (GetProcAddress(hLib, "DllAbout") != NULL)
|
|
|
|
{
|
|
|
|
Plugin.AboutFunction = true;
|
|
|
|
}
|
|
|
|
m_PluginList.push_back(Plugin);
|
|
|
|
} while (Dir.FindNext());
|
2008-11-14 20:51:06 +00:00
|
|
|
|
2015-11-12 08:43:32 +00:00
|
|
|
if (hLib)
|
|
|
|
{
|
|
|
|
FreeLibrary(hLib);
|
|
|
|
hLib = NULL;
|
|
|
|
}
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
}
|