This source file includes following definitions.
- GetPluginsDir
- LoadRealPlugin
- UnloadRealPlugin
#include <vector>
#include "xp.h"
#include "logger.h"
extern Logger * logger;
DWORD GetPluginsDir(char * path, DWORD maxsize)
{
if(!path)
return 0;
path[0] = '\0';
#ifdef XP_WIN
DWORD res = GetModuleFileName(NULL, path, maxsize);
if(res == 0)
return 0;
if(path[strlen(path) - 1] == '\\')
path[lstrlen(path) - 1] = '\0';
char *p = strrchr(path, '\\');
if(p)
*p = '\0';
strcat(path, "\\plugins");
#endif
#ifdef XP_UNIX
#endif
#ifdef XP_MAC
#endif
res = strlen(path);
return res;
}
XP_HLIB LoadRealPlugin(char * mimetype)
{
if(!mimetype || !strlen(mimetype))
return NULL;
#ifdef XP_WIN
BOOL bDone = FALSE;
WIN32_FIND_DATA ffdataStruct;
char szPath[_MAX_PATH];
char szFileName[_MAX_PATH];
GetPluginsDir(szPath, _MAX_PATH);
if(logger) {
char msg[512];
sprintf(msg, "LoadRealPlugin Path: %s\r\n", szPath);
logger->logMessage(msg);
}
strcpy(szFileName, szPath);
std::vector<std::string> directories;
directories.push_back(szFileName);
directories.push_back("C:\\Windows\\System32\\Macromed\\Flash");
directories.push_back("C:\\Windows\\SysWOW64\\Macromed\\Flash");
for (size_t i = 0; i < directories.size(); ++i) {
std::string search_path = directories[i];
search_path = search_path.append("\\np*.dll");
HANDLE handle = FindFirstFile(search_path.c_str(), &ffdataStruct);
if(handle == INVALID_HANDLE_VALUE)
{
FindClose(handle);
continue;
}
DWORD versize = 0L;
DWORD zero = 0L;
char * verbuf = NULL;
do
{
std::string cur_file = directories[i];
cur_file = cur_file.append("\\");
cur_file = cur_file.append(ffdataStruct.cFileName);
if(!(ffdataStruct. dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
strstr(cur_file.c_str(), "npspy.dll") == NULL)
{
versize = GetFileVersionInfoSize(cur_file.c_str(), &zero);
if (versize > 0)
verbuf = new char[versize];
else
continue;
if(!verbuf)
continue;
GetFileVersionInfo(cur_file.c_str(), NULL, versize, verbuf);
char *mimetypes = NULL;
UINT len = 0;
if(!VerQueryValue(verbuf, "\\StringFileInfo\\040904E4\\MIMEType", (void **)&mimetypes, &len)
|| !mimetypes || !len)
{
delete [] verbuf;
continue;
}
mimetypes[len] = '\0';
char * type = mimetypes;
BOOL more = TRUE;
while(more)
{
char * p = strchr(type, '|');
if(p)
*p = '\0';
else
more = FALSE;
if(0 == _stricmp(mimetype, type))
{
delete [] verbuf;
FindClose(handle);
HINSTANCE hLib = LoadLibrary(cur_file.c_str());
return hLib;
}
type = p;
type++;
}
delete [] verbuf;
}
} while(FindNextFile(handle, &ffdataStruct));
FindClose(handle);
}
#endif
#ifdef XP_UNIX
#endif
#ifdef XP_MAC
#endif
return NULL;
}
void UnloadRealPlugin(XP_HLIB hLib)
{
#ifdef XP_WIN
if(!hLib)
FreeLibrary(hLib);
#endif
#ifdef XP_UNIX
#endif
#ifdef XP_MAC
#endif
}