2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* Project 64 - A Nintendo 64 emulator. *
|
|
|
|
* 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>
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
CPluginList::CPluginList(bool bAutoFill /* = true */) :
|
2015-10-25 10:50:28 +00:00
|
|
|
m_PluginDir(g_Settings->LoadStringVal(Directory_Plugin),"")
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
|
|
|
if (bAutoFill)
|
|
|
|
{
|
|
|
|
LoadList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CPluginList::~CPluginList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPluginList::GetPluginCount() const
|
|
|
|
{
|
|
|
|
return m_PluginList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const CPluginList::PLUGIN * CPluginList::GetPluginInfo ( int indx ) const
|
|
|
|
{
|
2010-10-23 18:53:01 +00:00
|
|
|
if (indx < 0 || indx >= (int)m_PluginList.size())
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return &m_PluginList[indx];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPluginList::LoadList()
|
|
|
|
{
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceDebug,__FUNCTION__ ": Start");
|
2008-11-14 20:51:06 +00:00
|
|
|
m_PluginList.clear();
|
|
|
|
AddPluginFromDir(m_PluginDir);
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceDebug,__FUNCTION__ ": Done");
|
2008-11-14 20:51:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPluginList::AddPluginFromDir ( CPath Dir)
|
|
|
|
{
|
|
|
|
Dir.SetNameExtension("*.*");
|
|
|
|
if (Dir.FindFirst(_A_SUBDIR))
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
AddPluginFromDir(Dir);
|
|
|
|
} while (Dir.FindNext());
|
|
|
|
Dir.UpDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
Dir.SetNameExtension("*.dll");
|
|
|
|
if (Dir.FindFirst())
|
|
|
|
{
|
|
|
|
HMODULE hLib = NULL;
|
|
|
|
do {
|
|
|
|
if (hLib)
|
|
|
|
{
|
|
|
|
FreeLibrary(hLib);
|
|
|
|
hLib = NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-16 00:55:23 +00:00
|
|
|
//UINT LastErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS );
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTraceF(TraceDebug,__FUNCTION__ ": loading %s",(LPCSTR)Dir);
|
2015-05-16 00:55:23 +00:00
|
|
|
hLib = LoadLibrary(Dir);
|
|
|
|
//SetErrorMode(LastErrorMode);
|
2008-11-14 20:51:06 +00:00
|
|
|
|
|
|
|
if (hLib == NULL)
|
|
|
|
{
|
2015-05-16 00:55:23 +00:00
|
|
|
DWORD LoadError = GetLastError();
|
|
|
|
WriteTraceF(TraceDebug, __FUNCTION__ ": failed to loadi %s (error: %d)", (LPCSTR)Dir, LoadError);
|
2008-11-14 20:51:06 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void (__cdecl *GetDllInfo) ( PLUGIN_INFO * PluginInfo );
|
|
|
|
GetDllInfo = (void (__cdecl *)(PLUGIN_INFO *))GetProcAddress( hLib, "GetDllInfo" );
|
|
|
|
if (GetDllInfo == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-01-30 21:01:21 +00:00
|
|
|
PLUGIN Plugin = { 0 };
|
2010-11-30 18:10:16 +00:00
|
|
|
Plugin.Info.MemoryBswaped = true;
|
2008-11-14 20:51:06 +00:00
|
|
|
GetDllInfo(&Plugin.Info);
|
|
|
|
if (!ValidPluginVersion(Plugin.Info))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plugin.FullPath = Dir;
|
2015-10-29 23:58:26 +00:00
|
|
|
std::string& fullPath = Dir;
|
|
|
|
std::string& pluginPath = m_PluginDir;
|
|
|
|
Plugin.FileName = fullPath.substr(pluginPath.length());
|
2008-11-14 20:51:06 +00:00
|
|
|
|
|
|
|
if (GetProcAddress(hLib,"DllAbout") != NULL)
|
|
|
|
{
|
|
|
|
Plugin.AboutFunction = true;
|
|
|
|
}
|
|
|
|
m_PluginList.push_back(Plugin);
|
|
|
|
} while (Dir.FindNext());
|
|
|
|
|
|
|
|
if (hLib)
|
|
|
|
{
|
|
|
|
FreeLibrary(hLib);
|
|
|
|
hLib = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPluginList::ValidPluginVersion ( PLUGIN_INFO & PluginInfo ) {
|
|
|
|
switch (PluginInfo.Type)
|
|
|
|
{
|
|
|
|
case PLUGIN_TYPE_RSP:
|
2012-10-06 13:57:18 +00:00
|
|
|
if (!PluginInfo.MemoryBswaped) { return false; }
|
|
|
|
if (PluginInfo.Version == 0x0001) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0100) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0101) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0102) { return true; }
|
2008-11-14 20:51:06 +00:00
|
|
|
break;
|
|
|
|
case PLUGIN_TYPE_GFX:
|
2012-10-06 13:57:18 +00:00
|
|
|
if (!PluginInfo.MemoryBswaped) { return false; }
|
|
|
|
if (PluginInfo.Version == 0x0102) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0103) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0104) { return true; }
|
2008-11-14 20:51:06 +00:00
|
|
|
break;
|
|
|
|
case PLUGIN_TYPE_AUDIO:
|
2012-10-06 13:57:18 +00:00
|
|
|
if (!PluginInfo.MemoryBswaped) { return false; }
|
|
|
|
if (PluginInfo.Version == 0x0101) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0102) { return true; }
|
2008-11-14 20:51:06 +00:00
|
|
|
break;
|
|
|
|
case PLUGIN_TYPE_CONTROLLER:
|
|
|
|
if (PluginInfo.Version == 0x0100) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0101) { return true; }
|
|
|
|
if (PluginInfo.Version == 0x0102) { return true; }
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|