diff options
author | George Hazan <george.hazan@gmail.com> | 2015-06-13 16:55:17 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-06-13 16:55:17 +0000 |
commit | cbe3cb21f5bca61a03bbd4ae811ee906e09b3f4f (patch) | |
tree | 4854fb66f4d59940efa3c1590237915851074dbf /src/modules/plugins | |
parent | 351bcbec48ed77af5f8efcc4d5198707922c5d86 (diff) |
- miranda32.exe now does nothing bug extends PATH to %miranda_root%\libs and loads mir_app.dll;
- everything that was in miranda32.exe (including resources) moved to mir_app.dll;
- exports from mir_app.dll now available for using directly, without perversions;
- src/stdplug.h deleted;
git-svn-id: http://svn.miranda-ng.org/main/trunk@14143 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/plugins')
-rw-r--r-- | src/modules/plugins/dll_sniffer.cpp | 159 | ||||
-rw-r--r-- | src/modules/plugins/newplugins.cpp | 898 | ||||
-rw-r--r-- | src/modules/plugins/pluginopts.cpp | 575 | ||||
-rw-r--r-- | src/modules/plugins/plugins.h | 84 |
4 files changed, 0 insertions, 1716 deletions
diff --git a/src/modules/plugins/dll_sniffer.cpp b/src/modules/plugins/dll_sniffer.cpp deleted file mode 100644 index 31a566346c..0000000000 --- a/src/modules/plugins/dll_sniffer.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/*
-
-Miranda NG: the free IM client for Microsoft* Windows*
-
-Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org),
-Copyright (c) 2000-12 Miranda IM project,
-all portions of this codebase are copyrighted to the people
-listed in contributors.txt.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "..\..\core\commonheaders.h"
-#include "plugins.h"
-
-static IMAGE_SECTION_HEADER *getSectionByRVA(IMAGE_SECTION_HEADER *pISH, int nSections, IMAGE_DATA_DIRECTORY *pIDD)
-{
- for (int i=0; i < nSections; i++, pISH++)
- if (pIDD->VirtualAddress >= pISH->VirtualAddress && pIDD->VirtualAddress + pIDD->Size <= pISH->VirtualAddress + pISH->SizeOfRawData )
- return pISH;
-
- return NULL;
-}
-
-MUUID* GetPluginInterfaces(const TCHAR* ptszFileName, bool& bIsPlugin)
-{
- bIsPlugin = false;
-
- HANDLE hFile = CreateFile( ptszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
- if (hFile == INVALID_HANDLE_VALUE)
- return NULL;
-
- MUUID* pResult = NULL;
- BYTE* ptr = NULL;
- HANDLE hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL );
-
- __try {
- __try {
- if (!hMap )
- __leave;
-
- DWORD dwHSize = 0, filesize = GetFileSize( hFile, &dwHSize );
- if (!filesize || filesize == INVALID_FILE_SIZE || dwHSize)
- __leave;
-
- if ( filesize < sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS) )
- __leave;
-
- ptr = (BYTE*)MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
- if (ptr == NULL)
- __leave;
-
- PIMAGE_NT_HEADERS pINTH = { 0 };
- PIMAGE_DOS_HEADER pIDH = (PIMAGE_DOS_HEADER)ptr;
- if ( pIDH->e_magic == IMAGE_DOS_SIGNATURE )
- pINTH = (PIMAGE_NT_HEADERS)(ptr + pIDH->e_lfanew);
- else
- __leave;
-
- if ((PBYTE)pINTH + sizeof(IMAGE_NT_HEADERS) >= ptr + filesize )
- __leave;
- if ( pINTH->Signature != IMAGE_NT_SIGNATURE )
- __leave;
-
- int nSections = pINTH->FileHeader.NumberOfSections;
- if (!nSections )
- __leave;
-
- INT_PTR base;
- PIMAGE_DATA_DIRECTORY pIDD;
- if ( pINTH->FileHeader.Machine == IMAGE_FILE_MACHINE_I386 &&
- pINTH->FileHeader.SizeOfOptionalHeader >= sizeof(IMAGE_OPTIONAL_HEADER32) &&
- pINTH->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
- {
- pIDD = (PIMAGE_DATA_DIRECTORY)( (PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS32, OptionalHeader.DataDirectory ));
- base = *(DWORD*)((PBYTE)pINTH + offsetof(IMAGE_NT_HEADERS32, OptionalHeader.ImageBase));
- }
- else if ( pINTH->FileHeader.Machine == IMAGE_FILE_MACHINE_AMD64 &&
- pINTH->FileHeader.SizeOfOptionalHeader >= sizeof(IMAGE_OPTIONAL_HEADER64) &&
- pINTH->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
- {
- pIDD = (PIMAGE_DATA_DIRECTORY)( (PBYTE)pINTH + offsetof( IMAGE_NT_HEADERS64, OptionalHeader.DataDirectory ));
- base = *(ULONGLONG*)((PBYTE)pINTH + offsetof(IMAGE_NT_HEADERS64, OptionalHeader.ImageBase ));
- }
- else __leave;
-
- // Export information entry
- DWORD expvaddr = pIDD[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
- DWORD expsize = pIDD[IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
- if (expsize < sizeof(IMAGE_EXPORT_DIRECTORY)) __leave;
-
- BYTE* pImage = ptr + pIDH->e_lfanew + pINTH->FileHeader.SizeOfOptionalHeader + sizeof(IMAGE_NT_HEADERS) - sizeof(IMAGE_OPTIONAL_HEADER);
- IMAGE_SECTION_HEADER *pExp = getSectionByRVA((IMAGE_SECTION_HEADER *)pImage, nSections, pIDD);
- if (!pExp) __leave;
-
- BYTE *pSecStart = ptr + pExp->PointerToRawData - pExp->VirtualAddress;
- IMAGE_EXPORT_DIRECTORY *pED = (PIMAGE_EXPORT_DIRECTORY)&pSecStart[expvaddr];
- DWORD *ptrRVA = (DWORD*)&pSecStart[pED->AddressOfNames];
- WORD *ptrOrdRVA = (WORD*)&pSecStart[pED->AddressOfNameOrdinals];
- DWORD *ptrFuncList = (DWORD*)&pSecStart[pED->AddressOfFunctions];
-
- MUUID* pIds;
- bool bHasLoad = false, bHasUnload = false, bHasInfo = false, bHasMuuids = false;
- for (size_t i=0; i < pED->NumberOfNames; i++, ptrRVA++, ptrOrdRVA++) {
- char *szName = (char*)&pSecStart[*ptrRVA];
- if (!mir_strcmp(szName, "Load"))
- bHasLoad = true;
- if (!mir_strcmp(szName, "MirandaPluginInfoEx"))
- bHasInfo = true;
- else if (!mir_strcmp(szName, "Unload"))
- bHasUnload = true;
- else if (!mir_strcmp(szName, "MirandaInterfaces")) {
- bHasMuuids = true;
- pIds = (MUUID*)&pSecStart[ ptrFuncList[*ptrOrdRVA]];
- }
- // old plugin, skip it
- else if (!mir_strcmp(szName, "MirandaPluginInterfaces"))
- __leave;
- }
-
- // a plugin might have no interfaces
- if (bHasLoad && bHasUnload && bHasInfo)
- bIsPlugin = true;
-
- if (!bHasLoad || !bHasMuuids || !bHasUnload)
- __leave;
-
- int nLength = 1; // one for MIID_LAST
- for (MUUID* p = pIds; !equalUUID(*p, miid_last); p++)
- nLength++;
-
- pResult = (MUUID*)mir_alloc( sizeof(MUUID)*nLength);
- if (pResult)
- memcpy(pResult, pIds, sizeof(MUUID)*nLength);
- }
- __except(EXCEPTION_EXECUTE_HANDLER)
- {};
- }
- __finally
- {
- if (ptr) UnmapViewOfFile(ptr);
- if (hMap) CloseHandle(hMap);
- CloseHandle(hFile);
- };
-
- return pResult;
-}
diff --git a/src/modules/plugins/newplugins.cpp b/src/modules/plugins/newplugins.cpp deleted file mode 100644 index 6eccaa8059..0000000000 --- a/src/modules/plugins/newplugins.cpp +++ /dev/null @@ -1,898 +0,0 @@ -/*
-
-Miranda NG: the free IM client for Microsoft* Windows*
-
-Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org),
-Copyright (c) 2000-12 Miranda IM project,
-all portions of this codebase are copyrighted to the people
-listed in contributors.txt.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "..\..\core\commonheaders.h"
-
-#include "plugins.h"
-#include "..\database\profilemanager.h"
-#include "..\langpack\langpack.h"
-
-void LoadExtraIconsModule();
-
-extern bool bModulesLoadedFired;
-
-static int sttComparePluginsByName(const pluginEntry* p1, const pluginEntry* p2)
-{
- return mir_tstrcmpi(p1->pluginname, p2->pluginname);
-}
-
-LIST<pluginEntry>
- pluginList(10, sttComparePluginsByName),
- servicePlugins(5, sttComparePluginsByName),
- clistPlugins(5, sttComparePluginsByName);
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-#define MAX_MIR_VER ULONG_MAX
-
-static BOOL bModuleInitialized = FALSE;
-
-TCHAR mirandabootini[MAX_PATH];
-static DWORD mirandaVersion;
-static int sttFakeID = -100;
-static HANDLE hPluginListHeap = NULL;
-static int askAboutIgnoredPlugins;
-
-static pluginEntry *plugin_freeimg, *plugin_crshdmp, *serviceModePlugin, *plugin_ssl;
-
-#define PLUGINDISABLELIST "PluginDisable"
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// basic functions
-
-int equalUUID(const MUUID& u1, const MUUID& u2)
-{
- return memcmp(&u1, &u2, sizeof(MUUID)) ? 0 : 1;
-}
-
-bool hasMuuid(const MUUID* p, const MUUID& uuid)
-{
- if (p == NULL)
- return false;
-
- for (int i = 0; !equalUUID(miid_last, p[i]); i++)
- if (equalUUID(uuid, p[i]))
- return true;
-
- return false;
-}
-
-bool hasMuuid(const BASIC_PLUGIN_INFO& bpi, const MUUID& uuid)
-{
- if (bpi.Interfaces)
- return hasMuuid(bpi.Interfaces, uuid);
-
- return false;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// banned plugins
-
-static const MUUID pluginBannedList[] =
-{
- { 0x9d6c3213, 0x02b4, 0x4fe1, { 0x92, 0xe6, 0x52, 0x6d, 0xe2, 0x4f, 0x8d, 0x65 } }, // old chat
- { 0x240a91dc, 0x9464, 0x457a, { 0x97, 0x87, 0xff, 0x1e, 0xa8, 0x8e, 0x77, 0xe3 } }, // old clist
- { 0x657fe89b, 0xd121, 0x40c2, { 0x8a, 0xc9, 0xb9, 0xfa, 0x57, 0x55, 0xb3, 0x0c } }, // old srmm
- { 0x112f7d30, 0xcd19, 0x4c74, { 0xa0, 0x3b, 0xbf, 0xbb, 0x76, 0xb7, 0x5b, 0xc4 } }, // extraicons
- { 0x72765a6f, 0xb017, 0x42f1, { 0xb3, 0x0f, 0x5e, 0x09, 0x41, 0x27, 0x3a, 0x3f } }, // flashavatars
- { 0x1394a3ab, 0x2585, 0x4196, { 0x8f, 0x72, 0x0e, 0xae, 0xc2, 0x45, 0x0e, 0x11 } }, // db3x
- { 0x28ff9b91, 0x3e4d, 0x4f1c, { 0xb4, 0x7c, 0xc6, 0x41, 0xb0, 0x37, 0xff, 0x40 } }, // dbx_mmap_sa
- { 0x28f45248, 0x8c9c, 0x4bee, { 0x93, 0x07, 0x7b, 0xcf, 0x3e, 0x12, 0xbf, 0x99 } }, // dbx_tree
- { 0x4c4a27cf, 0x5e64, 0x4242, { 0xa3, 0x32, 0xb9, 0x8b, 0x08, 0x24, 0x3e, 0x89 } }, // metacontacts
- { 0x9c448c61, 0xfc3f, 0x42f9, { 0xb9, 0xf0, 0x4a, 0x30, 0xe1, 0xcf, 0x86, 0x71 } }, // skypekit based skype
- { 0x49c2cf54, 0x7898, 0x44de, { 0xbe, 0x3a, 0x6d, 0x2e, 0x4e, 0xf9, 0x00, 0x79 } } // firstrun
-};
-
-static bool isPluginBanned(const MUUID& u1)
-{
- for (int i = 0; i < SIZEOF(pluginBannedList); i++)
- if (equalUUID(pluginBannedList[i], u1))
- return true;
-
- return false;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// default plugins
-
-static MuuidReplacement pluginDefault[] =
-{
- { MIID_UIUSERINFO, _T("stduserinfo"), NULL }, // 0
- { MIID_SRURL, _T("stdurl"), NULL }, // 1
- { MIID_SREMAIL, _T("stdemail"), NULL }, // 2
- { MIID_SRAUTH, _T("stdauth"), NULL }, // 3
- { MIID_SRFILE, _T("stdfile"), NULL }, // 4
- { MIID_UIHELP, _T("stdhelp"), NULL }, // 5
- { MIID_UIHISTORY, _T("stduihist"), NULL }, // 6
- { MIID_IDLE, _T("stdidle"), NULL }, // 7
- { MIID_AUTOAWAY, _T("stdautoaway"), NULL }, // 8
- { MIID_USERONLINE, _T("stduseronline"), NULL }, // 9
- { MIID_SRAWAY, _T("stdaway"), NULL }, // 10
- { MIID_CLIST, _T("stdclist"), NULL }, // 11
- { MIID_CHAT, _T("stdchat"), NULL }, // 12
- { MIID_SRMM, _T("stdmsg"), NULL } // 13
-};
-
-int getDefaultPluginIdx(const MUUID &muuid)
-{
- for (int i = 0; i < SIZEOF(pluginDefault); i++)
- if (equalUUID(muuid, pluginDefault[i].uuid))
- return i;
-
- return -1;
-}
-
-int LoadStdPlugins()
-{
- for (int i = 0; i < SIZEOF(pluginDefault); i++) {
- if (pluginDefault[i].pImpl)
- continue;
-
- if (!LoadCorePlugin(pluginDefault[i]))
- return 1;
- }
-
- if (pluginDefault[13].pImpl == NULL)
- MessageBox(NULL, TranslateT("No messaging plugins loaded. Please install/enable one of the messaging plugins, for instance, \"StdMsg.dll\""), _T("Miranda NG"), MB_OK | MB_ICONWARNING);
-
- return 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// global functions
-
-char* GetPluginNameByInstance(HINSTANCE hInstance)
-{
- if (pluginList.getCount() == 0)
- return NULL;
-
- for (int i = 0; i < pluginList.getCount(); i++) {
- pluginEntry *p = pluginList[i];
- if (p->bpi.pluginInfo && p->bpi.hInst == hInstance)
- return p->bpi.pluginInfo->shortName;
- }
- return NULL;
-}
-
-int GetPluginLangByInstance(HINSTANCE hInstance)
-{
- if (pluginList.getCount() == 0)
- return NULL;
-
- for (int i = 0; i < pluginList.getCount(); i++) {
- pluginEntry *p = pluginList[i];
- if (p->bpi.pluginInfo && p->bpi.hInst == hInstance)
- return p->hLangpack;
- }
- return NULL;
-}
-
-int GetPluginFakeId(const MUUID &uuid, int hLangpack)
-{
- for (int i = 0; i < pluginList.getCount(); i++) {
- pluginEntry *p = pluginList[i];
- if (!p->bpi.hInst)
- continue;
-
- if (equalUUID(p->bpi.pluginInfo->uuid, uuid))
- return p->hLangpack = (hLangpack) ? hLangpack : --sttFakeID;
- }
-
- return 0;
-}
-
-MUUID miid_last = MIID_LAST;
-MUUID miid_chat = MIID_CHAT;
-MUUID miid_srmm = MIID_SRMM;
-MUUID miid_clist = MIID_CLIST;
-MUUID miid_database = MIID_DATABASE;
-MUUID miid_protocol = MIID_PROTOCOL;
-MUUID miid_servicemode = MIID_SERVICEMODE;
-MUUID miid_crypto = MIID_CRYPTO;
-MUUID miid_ssl = MIID_SSL;
-
-static bool validInterfaceList(MUUID *piface)
-{
- if (piface == NULL)
- return true;
-
- if (equalUUID(miid_last, piface[0]))
- return false;
-
- return true;
-}
-
-static int checkPI(BASIC_PLUGIN_INFO* bpi, PLUGININFOEX* pi)
-{
- if (pi == NULL)
- return FALSE;
-
- if (bpi->InfoEx == NULL || pi->cbSize != sizeof(PLUGININFOEX))
- return FALSE;
-
- if (!validInterfaceList(bpi->Interfaces) || isPluginBanned(pi->uuid))
- return FALSE;
-
- if (pi->shortName == NULL || pi->description == NULL || pi->author == NULL ||
- pi->authorEmail == NULL || pi->copyright == NULL || pi->homepage == NULL)
- return FALSE;
-
- return TRUE;
-}
-
-int checkAPI(TCHAR* plugin, BASIC_PLUGIN_INFO* bpi, DWORD mirandaVersion, int checkTypeAPI)
-{
- HINSTANCE h = LoadLibrary(plugin);
- if (h == NULL)
- return 0;
-
- // loaded, check for exports
- bpi->Load = (Miranda_Plugin_Load)GetProcAddress(h, "Load");
- bpi->Unload = (Miranda_Plugin_Unload)GetProcAddress(h, "Unload");
- bpi->InfoEx = (Miranda_Plugin_InfoEx)GetProcAddress(h, "MirandaPluginInfoEx");
-
- // if they were present
- if (!bpi->Load || !bpi->Unload || !bpi->InfoEx) {
-LBL_Error:
- FreeLibrary(h);
- return 0;
- }
-
- bpi->Interfaces = (MUUID*)GetProcAddress(h, "MirandaInterfaces");
- if (bpi->Interfaces == NULL) {
- typedef MUUID * (__cdecl * Miranda_Plugin_Interfaces) (void);
- Miranda_Plugin_Interfaces pFunc = (Miranda_Plugin_Interfaces)GetProcAddress(h, "MirandaPluginInterfaces");
- if (pFunc)
- bpi->Interfaces = pFunc();
- }
-
- PLUGININFOEX* pi = bpi->InfoEx(mirandaVersion);
- if (!checkPI(bpi, pi))
- goto LBL_Error;
-
- bpi->pluginInfo = pi;
- // basic API is present
- if (checkTypeAPI == CHECKAPI_NONE) {
-LBL_Ok:
- bpi->hInst = h;
- return 1;
- }
- // check clist ?
- if (checkTypeAPI == CHECKAPI_CLIST) {
- bpi->clistlink = (CList_Initialise)GetProcAddress(h, "CListInitialise");
- if ((pi->flags & UNICODE_AWARE) && bpi->clistlink)
- goto LBL_Ok;
- }
- goto LBL_Error;
-}
-
-// perform any API related tasks to freeing
-void Plugin_Uninit(pluginEntry *p)
-{
- // if the basic API check had passed, call Unload if Load(void) was ever called
- if (p->pclass & PCLASS_LOADED) {
- p->bpi.Unload();
- p->pclass &= ~PCLASS_LOADED;
- }
-
- // release the library
- HINSTANCE hInst = p->bpi.hInst;
- if (hInst != NULL) {
- // we need to kill all resources which belong to that DLL before calling FreeLibrary
- KillModuleEventHooks(hInst);
- KillModuleServices(hInst);
- UnregisterModule(hInst);
-
- FreeLibrary(hInst);
- memset(&p->bpi, 0, sizeof(p->bpi));
- }
-
- if (p == plugin_crshdmp)
- plugin_crshdmp = NULL;
- pluginList.remove(p);
-}
-
-int Plugin_UnloadDyn(pluginEntry *p)
-{
- if (p->bpi.hInst) {
- if (CallPluginEventHook(p->bpi.hInst, hOkToExitEvent, 0, 0) != 0)
- return FALSE;
-
- KillModuleSubclassing(p->bpi.hInst);
-
- CallPluginEventHook(p->bpi.hInst, hPreShutdownEvent, 0, 0);
- CallPluginEventHook(p->bpi.hInst, hShutdownEvent, 0, 0);
-
- KillModuleEventHooks(p->bpi.hInst);
- KillModuleServices(p->bpi.hInst);
- }
-
- int hLangpack = p->hLangpack;
- if (hLangpack != 0) {
- KillModuleMenus(hLangpack);
- KillModuleFonts(hLangpack);
- KillModuleColours(hLangpack);
- KillModuleEffects(hLangpack);
- KillModuleIcons(hLangpack);
- KillModuleHotkeys(hLangpack);
- KillModuleSounds(hLangpack);
- KillModuleExtraIcons(hLangpack);
- KillModuleSrmmIcons(hLangpack);
- }
-
- NotifyFastHook(hevUnloadModule, (WPARAM)p->bpi.pluginInfo, (LPARAM)p->bpi.hInst);
-
- Plugin_Uninit(p);
-
- // mark default plugins to be loaded
- if (!(p->pclass & PCLASS_CORE))
- for (int i = 0; i < SIZEOF(pluginDefault); i++)
- if (pluginDefault[i].pImpl == p)
- pluginDefault[i].pImpl = NULL;
-
- return TRUE;
-}
-
-// returns true if the given file is <anything>.dll exactly
-static int valid_library_name(TCHAR *name)
-{
- TCHAR *dot = _tcsrchr(name, '.');
- if (dot != NULL && mir_tstrcmpi(dot + 1, _T("dll")) == 0)
- if (dot[4] == 0)
- return 1;
-
- return 0;
-}
-
-void enumPlugins(SCAN_PLUGINS_CALLBACK cb, WPARAM wParam, LPARAM lParam)
-{
- // get miranda's exe path
- TCHAR exe[MAX_PATH];
- GetModuleFileName(NULL, exe, SIZEOF(exe));
- TCHAR *p = _tcsrchr(exe, '\\'); if (p) *p = 0;
-
- // create the search filter
- TCHAR search[MAX_PATH];
- mir_sntprintf(search, SIZEOF(search), _T("%s\\Plugins\\*.dll"), exe);
-
- // FFFN will return filenames for things like dot dll+ or dot dllx
- WIN32_FIND_DATA ffd;
- HANDLE hFind = FindFirstFile(search, &ffd);
- if (hFind == INVALID_HANDLE_VALUE)
- return;
-
- do {
- if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && valid_library_name(ffd.cFileName))
- cb(&ffd, exe, wParam, lParam);
- } while (FindNextFile(hFind, &ffd));
- FindClose(hFind);
-}
-
-pluginEntry* OpenPlugin(TCHAR *tszFileName, TCHAR *dir, TCHAR *path)
-{
- pluginEntry *p = (pluginEntry*)HeapAlloc(hPluginListHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, sizeof(pluginEntry));
- _tcsncpy_s(p->pluginname, tszFileName, _TRUNCATE);
-
- // add it to the list anyway
- pluginList.insert(p);
-
- TCHAR tszFullPath[MAX_PATH];
- mir_sntprintf(tszFullPath, SIZEOF(tszFullPath), _T("%s\\%s\\%s"), path, dir, tszFileName);
-
- // map dll into the memory and check its exports
- bool bIsPlugin = false;
- mir_ptr<MUUID> pIds(GetPluginInterfaces(tszFullPath, bIsPlugin));
- if (!bIsPlugin) {
- p->pclass |= PCLASS_FAILED; // piece of shit
- return p;
- }
-
- // plugin declared that it's a database or a cryptor. load it asap!
- bool bIsDb = hasMuuid(pIds, miid_database);
- if (bIsDb || hasMuuid(pIds, miid_crypto)) {
- BASIC_PLUGIN_INFO bpi;
- if (checkAPI(tszFullPath, &bpi, mirandaVersion, CHECKAPI_NONE)) {
- // plugin is valid
- p->pclass |= ((bIsDb ? PCLASS_DB : PCLASS_CRYPT) | PCLASS_BASICAPI);
- // copy the dblink stuff
- p->bpi = bpi;
-
- RegisterModule(p->bpi.hInst);
- if (bpi.Load() != 0)
- p->pclass |= PCLASS_FAILED;
- else
- p->pclass |= PCLASS_LOADED;
- }
- else p->pclass |= PCLASS_FAILED;
- }
- // plugin declared that it's a contact list. mark it for the future load
- else if (hasMuuid(pIds, miid_clist)) {
- // keep a note of this plugin for later
- clistPlugins.insert(p);
- p->pclass |= PCLASS_CLIST;
- }
- // plugin declared that it's a ssl provider. mark it for the future load
- else if (hasMuuid(pIds, miid_ssl)) {
- plugin_ssl = p;
- p->pclass |= PCLASS_LAST;
- }
- // plugin declared that it's a service mode plugin.
- // load it for a profile manager's window
- else if (hasMuuid(pIds, miid_servicemode)) {
- BASIC_PLUGIN_INFO bpi;
- if (checkAPI(tszFullPath, &bpi, mirandaVersion, CHECKAPI_NONE)) {
- p->pclass |= (PCLASS_OK | PCLASS_BASICAPI);
- p->bpi = bpi;
- if (hasMuuid(bpi, miid_servicemode)) {
- p->pclass |= (PCLASS_SERVICE);
- servicePlugins.insert(p);
- }
- }
- else
- // didn't have basic APIs or DB exports - failed.
- p->pclass |= PCLASS_FAILED;
- }
- return p;
-}
-
-void SetPluginOnWhiteList(const TCHAR* pluginname, int allow)
-{
- db_set_b(NULL, PLUGINDISABLELIST, _strlwr(_T2A(pluginname)), allow == 0);
-}
-
-// returns 1 if the plugin should be enabled within this profile, filename is always lower case
-int isPluginOnWhiteList(const TCHAR* pluginname)
-{
- int rc = db_get_b(NULL, PLUGINDISABLELIST, _strlwr(_T2A(pluginname)), 0);
- if (rc != 0 && askAboutIgnoredPlugins) {
- TCHAR buf[256];
- mir_sntprintf(buf, TranslateT("'%s' is disabled, re-enable?"), pluginname);
- if (MessageBox(NULL, buf, TranslateT("Re-enable Miranda plugin?"), MB_YESNO | MB_ICONQUESTION) == IDYES) {
- SetPluginOnWhiteList(pluginname, 1);
- rc = 0;
- }
- }
-
- return rc == 0;
-}
-
-bool TryLoadPlugin(pluginEntry *p, bool bDynamic)
-{
- TCHAR exe[MAX_PATH], tszFullPath[MAX_PATH];
- GetModuleFileName(NULL, exe, SIZEOF(exe));
- TCHAR* slice = _tcsrchr(exe, '\\');
- if (slice)
- *slice = 0;
-
- if (!(p->pclass & (PCLASS_LOADED | PCLASS_DB | PCLASS_CLIST))) {
- if (!bDynamic && !isPluginOnWhiteList(p->pluginname))
- return false;
-
- if (!(p->pclass & PCLASS_BASICAPI)) {
- BASIC_PLUGIN_INFO bpi;
- mir_sntprintf(tszFullPath, SIZEOF(tszFullPath), _T("%s\\%s\\%s"), exe, (p->pclass & PCLASS_CORE) ? _T("Core") : _T("Plugins"), p->pluginname);
- if (!checkAPI(tszFullPath, &bpi, mirandaVersion, CHECKAPI_NONE)) {
- p->pclass |= PCLASS_FAILED;
- return false;
- }
-
- p->bpi = bpi;
- p->pclass |= PCLASS_OK | PCLASS_BASICAPI;
- }
-
- if (p->bpi.Interfaces) {
- MUUID *piface = p->bpi.Interfaces;
- for (int i = 0; !equalUUID(miid_last, piface[i]); i++) {
- int idx = getDefaultPluginIdx(piface[i]);
- if (idx != -1 && pluginDefault[idx].pImpl) {
- if (!bDynamic) { // this place is already occupied, skip & disable
- SetPluginOnWhiteList(p->pluginname, 0);
- return false;
- }
-
- // we're loading new implementation dynamically, let the old one die
- if (!(p->pclass & PCLASS_CORE))
- Plugin_UnloadDyn(pluginDefault[idx].pImpl);
- }
- }
- }
-
- RegisterModule(p->bpi.hInst);
- if (p->bpi.Load() != 0)
- return false;
-
- p->pclass |= PCLASS_LOADED;
- if (p->bpi.Interfaces) {
- MUUID *piface = p->bpi.Interfaces;
- for (int i = 0; !equalUUID(miid_last, piface[i]); i++) {
- int idx = getDefaultPluginIdx(piface[i]);
- if (idx != -1)
- pluginDefault[idx].pImpl = p;
- }
- }
- }
- else if (p->bpi.hInst != NULL) {
- RegisterModule(p->bpi.hInst);
- p->pclass |= PCLASS_LOADED;
- }
- return true;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Core plugins support
-
-static TCHAR tszCoreErr[] = LPGENT("Core plugin '%s' cannot be loaded or missing. Miranda will exit now");
-
-bool LoadCorePlugin(MuuidReplacement& mr)
-{
- TCHAR exe[MAX_PATH], tszPlugName[MAX_PATH];
- GetModuleFileName(NULL, exe, SIZEOF(exe));
- TCHAR *p = _tcsrchr(exe, '\\'); if (p) *p = 0;
-
- mir_sntprintf(tszPlugName, SIZEOF(tszPlugName), _T("%s.dll"), mr.stdplugname);
- pluginEntry* pPlug = OpenPlugin(tszPlugName, _T("Core"), exe);
- if (pPlug->pclass & PCLASS_FAILED) {
-LBL_Error:
- MessageBox(NULL, CMString(FORMAT, TranslateTS(tszCoreErr), mr.stdplugname), TranslateT("Fatal error"), MB_OK | MB_ICONSTOP);
-
- Plugin_UnloadDyn(pPlug);
- mr.pImpl = NULL;
- return false;
- }
-
- pPlug->pclass |= PCLASS_CORE;
-
- if (!TryLoadPlugin(pPlug, true))
- goto LBL_Error;
-
- if (bModulesLoadedFired) {
- if (CallPluginEventHook(pPlug->bpi.hInst, hModulesLoadedEvent, 0, 0) != 0)
- goto LBL_Error;
-
- NotifyEventHooks(hevLoadModule, (WPARAM)pPlug->bpi.pluginInfo, (LPARAM)pPlug->bpi.hInst);
- }
- mr.pImpl = pPlug;
- return true;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Contact list plugins support
-
-static bool loadClistModule(TCHAR* exe, pluginEntry *p)
-{
- BASIC_PLUGIN_INFO bpi;
- if (checkAPI(exe, &bpi, mirandaVersion, CHECKAPI_CLIST)) {
- p->bpi = bpi;
- p->pclass |= PCLASS_LAST | PCLASS_OK | PCLASS_BASICAPI;
- RegisterModule(p->bpi.hInst);
- if (bpi.clistlink() == 0) {
- p->bpi = bpi;
- p->pclass |= PCLASS_LOADED;
- pluginDefault[11].pImpl = p;
-
- LoadExtraIconsModule();
- return true;
- }
- Plugin_Uninit(p);
- }
- return false;
-}
-
-static pluginEntry* getCListModule(TCHAR *exe)
-{
- TCHAR tszFullPath[MAX_PATH];
-
- for (int i = 0; i < clistPlugins.getCount(); i++) {
- pluginEntry *p = clistPlugins[i];
- if (!isPluginOnWhiteList(p->pluginname))
- continue;
-
- mir_sntprintf(tszFullPath, SIZEOF(tszFullPath), _T("%s\\Plugins\\%s"), exe, p->pluginname);
- if (loadClistModule(tszFullPath, p))
- return p;
- }
-
- MuuidReplacement& stdClist = pluginDefault[11];
- if (LoadCorePlugin(stdClist)) {
- mir_sntprintf(tszFullPath, SIZEOF(tszFullPath), _T("%s\\Core\\%s.dll"), exe, stdClist.stdplugname);
- if (loadClistModule(tszFullPath, stdClist.pImpl))
- return stdClist.pImpl;
- }
-
- return NULL;
-}
-
-int UnloadPlugin(TCHAR* buf, int bufLen)
-{
- for (int i = pluginList.getCount() - 1; i >= 0; i--) {
- pluginEntry *p = pluginList[i];
- if (!mir_tstrcmpi(p->pluginname, buf)) {
- GetModuleFileName(p->bpi.hInst, buf, bufLen);
- Plugin_Uninit(p);
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Service plugins functions
-
-void SetServiceModePlugin(pluginEntry *p)
-{
- serviceModePlugin = p;
-}
-
-static int LaunchServicePlugin(pluginEntry *p)
-{
- // plugin load failed - terminating Miranda
- if (!(p->pclass & PCLASS_LOADED)) {
- if (p->bpi.Load() != ERROR_SUCCESS) {
- Plugin_Uninit(p);
- return SERVICE_FAILED;
- }
- p->pclass |= PCLASS_LOADED;
- }
-
- INT_PTR res = CallService(MS_SERVICEMODE_LAUNCH, 0, 0);
- if (res != CALLSERVICE_NOTFOUND)
- return res;
-
- MessageBox(NULL, TranslateT("Unable to load plugin in service mode!"), p->pluginname, MB_ICONSTOP);
- Plugin_Uninit(p);
- return SERVICE_FAILED;
-}
-
-int LoadDefaultServiceModePlugin()
-{
- LPCTSTR param = CmdLine_GetOption(_T("svc"));
- if (param == NULL || *param == 0)
- return SERVICE_CONTINUE;
-
- size_t cbLen = mir_tstrlen(param);
- for (int i = 0; i < servicePlugins.getCount(); i++) {
- pluginEntry *p = servicePlugins[i];
- if (!_tcsnicmp(p->pluginname, param, cbLen)) {
- int res = LaunchServicePlugin(p);
- if (res == SERVICE_ONLYDB) // load it later
- serviceModePlugin = p;
- return res;
- }
- }
-
- return SERVICE_CONTINUE;
-}
-
-int LoadServiceModePlugin()
-{
- return (serviceModePlugin == NULL) ? SERVICE_CONTINUE : LaunchServicePlugin(serviceModePlugin);
-}
-
-void EnsureCheckerLoaded(bool bEnable)
-{
- for (int i = 0; i < pluginList.getCount(); i++) {
- pluginEntry *p = pluginList[i];
- if (mir_tstrcmpi(p->pluginname, _T("dbchecker.dll")))
- continue;
-
- if (bEnable) {
- if (!(p->pclass & PCLASS_LOADED)) {
- if (p->bpi.Load() != ERROR_SUCCESS)
- Plugin_Uninit(p);
- else {
- p->pclass |= PCLASS_LOADED;
- servicePlugins.remove(p);
- }
- }
- }
- else Plugin_Uninit(p);
- break;
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-int LoadSslModule(void)
-{
- if (plugin_ssl != NULL) {
- if (!TryLoadPlugin(plugin_ssl, false)) {
- Plugin_Uninit(plugin_ssl);
- return 1;
- }
- }
- else {
- MuuidReplacement stdSsl = { MIID_SSL, _T("stdssl"), NULL };
- if (!LoadCorePlugin(stdSsl))
- return 1;
- }
-
- mir_getSI(&si);
- return 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Event hook to unload all non-core plugins
-// hooked very late, after all the internal plugins, blah
-
-void UnloadNewPlugins(void)
-{
- // unload everything but the special db/clist plugins
- for (int i = pluginList.getCount() - 1; i >= 0; i--) {
- pluginEntry *p = pluginList[i];
- if (!(p->pclass & PCLASS_LAST) && (p->pclass & PCLASS_OK))
- Plugin_Uninit(p);
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Loads all plugins
-
-int LoadNewPluginsModule(void)
-{
- int i;
-
- // make full path to the plugin
- TCHAR exe[MAX_PATH], fullPath[MAX_PATH];
- GetModuleFileName(NULL, exe, SIZEOF(exe));
- TCHAR *slice = _tcsrchr(exe, '\\');
- if (slice)
- *slice = 0;
-
- // remember some useful options
- askAboutIgnoredPlugins = (UINT)GetPrivateProfileInt(_T("PluginLoader"), _T("AskAboutIgnoredPlugins"), 0, mirandabootini);
-
- // if Crash Dumper is present, load it to provide Crash Reports
- if (plugin_crshdmp != NULL && isPluginOnWhiteList(plugin_crshdmp->pluginname))
- if (!TryLoadPlugin(plugin_crshdmp, false))
- Plugin_Uninit(plugin_crshdmp);
-
- // if freeimage is present, load it to provide the basic core functions
- if (plugin_freeimg != NULL) {
- BASIC_PLUGIN_INFO bpi;
- mir_sntprintf(fullPath, SIZEOF(fullPath), _T("%s\\Plugins\\%s"), exe, plugin_freeimg->pluginname);
- if (checkAPI(fullPath, &bpi, mirandaVersion, CHECKAPI_NONE)) {
- plugin_freeimg->bpi = bpi;
- plugin_freeimg->pclass |= PCLASS_OK | PCLASS_BASICAPI;
- if (bpi.Load() == 0)
- plugin_freeimg->pclass |= PCLASS_LOADED;
- else
- Plugin_Uninit(plugin_freeimg);
- }
- }
-
- // first load the clist cos alot of plugins need that to be present at Load(void)
- pluginEntry* clist = getCListModule(exe);
-
- /* the loop above will try and get one clist DLL to work, if all fail then just bail now */
- if (clist == NULL) {
- // result = 0, no clist_* can be found
- if (clistPlugins.getCount())
- MessageBox(NULL, TranslateT("Unable to start any of the installed contact list plugins, I even ignored your preferences for which contact list couldn't load any."), _T("Miranda NG"), MB_OK | MB_ICONERROR);
- else
- MessageBox(NULL, TranslateT("Can't find a contact list plugin! You need StdClist or any other contact list plugin."), _T("Miranda NG"), MB_OK | MB_ICONERROR);
- return 1;
- }
-
- /* enable and disable as needed */
- for (i = 0; i < clistPlugins.getCount(); i++)
- SetPluginOnWhiteList(clistPlugins[i]->pluginname, clist != clistPlugins[i] ? 0 : 1);
-
- /* now loop thru and load all the other plugins, do this in one pass */
- for (i = 0; i < pluginList.getCount(); i++) {
- pluginEntry *p = pluginList[i];
- if (!TryLoadPlugin(p, false)) {
- Plugin_Uninit(p);
- i--;
- }
- }
-
- HookEvent(ME_OPT_INITIALISE, PluginOptionsInit);
- return 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Plugins module initialization
-// called before anything real is loaded, incl. database
-
-static BOOL scanPluginsDir(WIN32_FIND_DATA *fd, TCHAR *path, WPARAM, LPARAM)
-{
- pluginEntry *p = OpenPlugin(fd->cFileName, _T("Plugins"), path);
- if (!(p->pclass & PCLASS_FAILED)) {
- if (plugin_freeimg == NULL && mir_tstrcmpi(fd->cFileName, _T("advaimg.dll")) == 0) {
- plugin_freeimg = p;
- p->pclass |= PCLASS_LAST;
- }
-
- if (plugin_crshdmp == NULL && mir_tstrcmpi(fd->cFileName, _T("crashdumper.dll")) == 0) {
- plugin_crshdmp = p;
- p->pclass |= PCLASS_LAST;
- }
- }
-
- return TRUE;
-}
-
-int LoadNewPluginsModuleInfos(void)
-{
- bModuleInitialized = TRUE;
-
- LoadPluginOptions();
-
- hPluginListHeap = HeapCreate(HEAP_NO_SERIALIZE, 0, 0);
- mirandaVersion = (DWORD)CallService(MS_SYSTEM_GETVERSION, 0, 0);
-
- // remember where the mirandaboot.ini goes
- PathToAbsoluteT(_T("mirandaboot.ini"), mirandabootini);
-
- // look for all *.dll's
- enumPlugins(scanPluginsDir, 0, 0);
-
- MuuidReplacement stdCrypt = { MIID_CRYPTO, _T("stdcrypt"), NULL };
- return !LoadCorePlugin(stdCrypt);
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Plugins module unloading
-// called at the end of module chain unloading, just modular engine left at this point
-
-void UnloadDatabase(void)
-{
- if (currDb != NULL) {
- db_setCurrent(NULL);
- currDblink->Unload(currDb);
- currDb = NULL;
- currDblink = NULL;
- }
-
- UninitIni();
-}
-
-void UnloadNewPluginsModule(void)
-{
- if (!bModuleInitialized)
- return;
-
- UnloadPluginOptions();
-
- // unload everything but the DB
- for (int i = pluginList.getCount() - 1; i >= 0; i--) {
- pluginEntry *p = pluginList[i];
- if (!(p->pclass & (PCLASS_DB | PCLASS_CRYPT)) && p != plugin_crshdmp)
- Plugin_Uninit(p);
- }
-
- if (plugin_crshdmp)
- Plugin_Uninit(plugin_crshdmp);
-
- UnloadDatabase();
-
- for (int k = pluginList.getCount() - 1; k >= 0; k--) {
- pluginEntry *p = pluginList[k];
- Plugin_Uninit(p);
- }
-
- if (hPluginListHeap) HeapDestroy(hPluginListHeap);
- hPluginListHeap = 0;
-}
diff --git a/src/modules/plugins/pluginopts.cpp b/src/modules/plugins/pluginopts.cpp deleted file mode 100644 index 9200d04bd1..0000000000 --- a/src/modules/plugins/pluginopts.cpp +++ /dev/null @@ -1,575 +0,0 @@ -/*
-
-Miranda NG: the free IM client for Microsoft* Windows*
-
-Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org),
-Copyright (c) 2000-12 Miranda IM project,
-all portions of this codebase are copyrighted to the people
-listed in contributors.txt.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#include "..\..\core\commonheaders.h"
-
-#include <m_version.h>
-
-#include "plugins.h"
-
-extern MUUID miid_clist, miid_database, miid_protocol;
-HANDLE hevLoadModule, hevUnloadModule;
-
-static bool bOldMode = false;
-static CMString szFilter;
-static UINT_PTR timerID;
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Plugins options page dialog
-
-struct PluginListItemData
-{
- TCHAR fileName[MAX_PATH];
- HINSTANCE hInst;
- int flags, stdPlugin;
- char* author;
- char* authorEmail;
- char* description;
- char* copyright;
- char* homepage;
- MUUID uuid;
-};
-
-static int sttSortPlugins(const PluginListItemData *p1, const PluginListItemData *p2)
-{
- return mir_tstrcmp(p1->fileName, p2->fileName);
-}
-
-static LIST<PluginListItemData> arPluginList(10, sttSortPlugins);
-
-static BOOL dialogListPlugins(WIN32_FIND_DATA *fd, TCHAR *path, WPARAM, LPARAM lParam)
-{
- TCHAR buf[MAX_PATH];
- mir_sntprintf(buf, _T("%s\\Plugins\\%s"), path, fd->cFileName);
- HINSTANCE hInst = GetModuleHandle(buf);
-
- BASIC_PLUGIN_INFO pi;
- if (checkAPI(buf, &pi, MIRANDA_VERSION_CORE, CHECKAPI_NONE) == 0)
- return TRUE;
-
- PluginListItemData *dat = (PluginListItemData*)mir_alloc(sizeof(PluginListItemData));
- dat->hInst = hInst;
- dat->flags = pi.pluginInfo->flags;
-
- dat->stdPlugin = 0;
- if (pi.Interfaces) {
- MUUID *piface = pi.Interfaces;
- for (int i=0; !equalUUID(miid_last, piface[i]); i++) {
- int idx = getDefaultPluginIdx( piface[i] );
- if (idx != -1 ) {
- dat->stdPlugin |= (1 << idx);
- break;
- }
- }
- }
-
- CharLower(fd->cFileName);
- _tcsncpy_s(dat->fileName, fd->cFileName, _TRUNCATE);
-
- HWND hwndList = (HWND)lParam;
-
- LVITEM it = { 0 };
- // column 1: Checkbox + Enable/disabled icons
- it.mask = LVIF_PARAM | LVIF_IMAGE;
- it.iImage = (hInst != NULL) ? 2 : 3;
- bool bNoCheckbox = (dat->flags & STATIC_PLUGIN) != 0;
- if (bNoCheckbox|| hasMuuid(pi, miid_clist) || hasMuuid(pi, miid_protocol))
- it.iImage += 2;
- it.lParam = (LPARAM)dat;
- int iRow = ListView_InsertItem(hwndList, &it);
-
- if (isPluginOnWhiteList(fd->cFileName))
- ListView_SetItemState(hwndList, iRow, bNoCheckbox ? 0x3000 : 0x2000, LVIS_STATEIMAGEMASK);
-
- if (iRow != -1) {
- // column 2: Unicode/ANSI icon + filename
- it.mask = LVIF_IMAGE | LVIF_TEXT;
- it.iItem = iRow;
- it.iSubItem = 1;
- it.iImage = (dat->flags & UNICODE_AWARE) ? 0 : 1;
- it.pszText = fd->cFileName;
- ListView_SetItem(hwndList, &it);
-
- dat->author = mir_strdup(pi.pluginInfo->author);
- dat->authorEmail = mir_strdup(pi.pluginInfo->authorEmail);
- dat->copyright = mir_strdup(pi.pluginInfo->copyright);
- dat->description = mir_strdup(pi.pluginInfo->description);
- dat->homepage = mir_strdup(pi.pluginInfo->homepage);
- if (pi.pluginInfo->cbSize == sizeof(PLUGININFOEX))
- dat->uuid = pi.pluginInfo->uuid;
- else
- memset(&dat->uuid, 0, sizeof(dat->uuid));
-
- TCHAR *shortNameT = mir_a2t(pi.pluginInfo->shortName);
- // column 3: plugin short name
- if (shortNameT) {
- ListView_SetItemText(hwndList, iRow, 2, shortNameT);
- mir_free(shortNameT);
- }
-
- // column4: version number
- DWORD unused, verInfoSize = GetFileVersionInfoSize(buf, &unused);
- if (verInfoSize != 0) {
- UINT blockSize;
- VS_FIXEDFILEINFO *fi;
- void *pVerInfo = mir_alloc(verInfoSize);
- GetFileVersionInfo(buf, 0, verInfoSize, pVerInfo);
- VerQueryValue(pVerInfo, _T("\\"), (LPVOID*)&fi, &blockSize);
- mir_sntprintf(buf, _T("%d.%d.%d.%d"), HIWORD(fi->dwProductVersionMS),
- LOWORD(fi->dwProductVersionMS), HIWORD(fi->dwProductVersionLS), LOWORD(fi->dwProductVersionLS));
- mir_free(pVerInfo);
- }
- else
- mir_sntprintf(buf, _T("%d.%d.%d.%d"), HIBYTE(HIWORD(pi.pluginInfo->version)),
- LOBYTE(HIWORD(pi.pluginInfo->version)), HIBYTE(LOWORD(pi.pluginInfo->version)),
- LOBYTE(LOWORD(pi.pluginInfo->version)));
-
- ListView_SetItemText(hwndList, iRow, 3, buf);
- arPluginList.insert(dat);
- }
- else
- mir_free(dat);
- FreeLibrary(pi.hInst);
- return TRUE;
-}
-
-static int uuidToString(const MUUID uuid, char *szStr, int cbLen)
-{
- if (cbLen < 1 || !szStr)
- return 0;
-
- mir_snprintf(szStr, cbLen, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
- uuid.a, uuid.b, uuid.c, uuid.d[0], uuid.d[1], uuid.d[2], uuid.d[3], uuid.d[4], uuid.d[5], uuid.d[6], uuid.d[7]);
- return 1;
-}
-
-static void RemoveAllItems(HWND hwnd)
-{
- LVITEM lvi;
- lvi.mask = LVIF_PARAM;
- lvi.iItem = 0;
- while (ListView_GetItem(hwnd, &lvi)) {
- PluginListItemData *dat = (PluginListItemData*)lvi.lParam;
- mir_free(dat->author);
- mir_free(dat->authorEmail);
- mir_free(dat->copyright);
- mir_free(dat->description);
- mir_free(dat->homepage);
- mir_free(dat);
- lvi.iItem ++;
- }
-}
-
-static bool LoadPluginDynamically(PluginListItemData *dat)
-{
- TCHAR exe[MAX_PATH];
- GetModuleFileName(NULL, exe, SIZEOF(exe));
- TCHAR *p = _tcsrchr(exe, '\\'); if (p) *p = 0;
-
- pluginEntry* pPlug = OpenPlugin(dat->fileName, _T("Plugins"), exe);
- if (pPlug->pclass & PCLASS_FAILED) {
-LBL_Error:
- Plugin_UnloadDyn(pPlug);
- return false;
- }
-
- if (!TryLoadPlugin(pPlug, true))
- goto LBL_Error;
-
- if (CallPluginEventHook(pPlug->bpi.hInst, hModulesLoadedEvent, 0, 0) != 0)
- goto LBL_Error;
-
- dat->hInst = pPlug->bpi.hInst;
- NotifyFastHook(hevLoadModule, (WPARAM)pPlug->bpi.pluginInfo, (LPARAM)pPlug->bpi.hInst);
- return true;
-}
-
-static bool UnloadPluginDynamically(PluginListItemData *dat)
-{
- pluginEntry *p = pluginList.find((pluginEntry*)dat->fileName);
- if (p) {
- if (!Plugin_UnloadDyn(p))
- return false;
-
- dat->hInst = NULL;
- }
- return true;
-}
-
-static LRESULT CALLBACK PluginListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch(msg) {
- case WM_CHAR:
- if (wParam == '\b') {
- if (szFilter.GetLength() > 0)
- szFilter.Truncate(szFilter.GetLength() - 1);
- }
- else {
- szFilter.AppendChar(wParam);
-
- for (int i = 0; i < arPluginList.getCount(); i++) {
- PluginListItemData *p = arPluginList[i];
- if (!_tcsnicmp(szFilter, p->fileName, szFilter.GetLength())) {
- LVFINDINFO lvfi;
- lvfi.flags = LVFI_PARAM;
- lvfi.lParam = (LPARAM)p;
- int idx = ListView_FindItem(hwnd, 0, &lvfi);
- if (idx != -1) {
- ListView_SetItemState(hwnd, idx, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
- ListView_EnsureVisible(hwnd, idx, FALSE);
- if (timerID != 0)
- KillTimer(hwnd, timerID);
- timerID = SetTimer(hwnd, 1, 1500, 0);
- return TRUE;
- }
- }
- }
-
- szFilter.Truncate(szFilter.GetLength() - 1);
- MessageBeep((UINT)-1);
- }
- return TRUE;
-
- case WM_TIMER:
- if (wParam == 1) {
- KillTimer(hwnd, timerID);
- timerID = 0;
- szFilter.Empty();
- }
- break;
-
- case WM_LBUTTONDOWN:
- LVHITTESTINFO hi;
- hi.pt.x = LOWORD(lParam);
- hi.pt.y = HIWORD(lParam);
- ListView_SubItemHitTest(hwnd, &hi);
- // Dynamically load/unload a plugin
- if ((hi.iSubItem == 0) && (hi.flags & LVHT_ONITEMICON)) {
- LVITEM lvi = {0};
- lvi.mask = LVIF_IMAGE | LVIF_PARAM;
- lvi.stateMask = -1;
- lvi.iItem = hi.iItem;
- lvi.iSubItem = 0;
- if (ListView_GetItem(hwnd, &lvi)) {
- lvi.mask = LVIF_IMAGE;
- PluginListItemData *dat = (PluginListItemData*)lvi.lParam;
- if (lvi.iImage == 3) {
- // load plugin
- if (LoadPluginDynamically(dat)) {
- lvi.iImage = 2;
- ListView_SetItem(hwnd, &lvi);
- }
- }
- else if (lvi.iImage == 2) {
- // unload plugin
- if (UnloadPluginDynamically(dat)) {
- lvi.iImage = 3;
- ListView_SetItem(hwnd, &lvi);
- }
- }
- LoadStdPlugins();
- }
- }
- }
-
- return mir_callNextSubclass(hwnd, PluginListWndProc, msg, wParam, lParam);
-}
-
-static int CALLBACK SortPlugins(WPARAM i1, LPARAM i2, LPARAM)
-{
- PluginListItemData *p1 = (PluginListItemData*)i1, *p2 = (PluginListItemData*)i2;
- return mir_tstrcmp(p1->fileName, p2->fileName);
-}
-
-static TCHAR *latin2t(const char *p)
-{
- if (p == NULL)
- return mir_tstrdup( _T(""));
-
- return mir_a2t_cp(p, 1250);
-}
-
-INT_PTR CALLBACK DlgPluginOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- timerID = 0;
- {
- HWND hwndList = GetDlgItem(hwndDlg, IDC_PLUGLIST);
- mir_subclassWindow(hwndList, PluginListWndProc);
-
- HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 4, 0);
- ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_UNICODE);
- ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_ANSI);
- ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_LOADED);
- ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_NOTLOADED);
- ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_LOADEDGRAY);
- ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_NOTLOADEDGRAY);
- ListView_SetImageList(hwndList, hIml, LVSIL_SMALL);
-
- LVCOLUMN col;
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.pszText = _T("");
- col.cx = 40;
- ListView_InsertColumn(hwndList, 0, &col);
-
- col.pszText = TranslateT("Plugin");
- col.cx = 180;
- ListView_InsertColumn(hwndList, 1, &col);
-
- col.pszText = TranslateT("Name");
- col.cx = 180;//max = 220;
- ListView_InsertColumn(hwndList, 2, &col);
-
- col.pszText = TranslateT("Version");
- col.cx = 75;
- ListView_InsertColumn(hwndList, 3, &col);
-
- ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_SUBITEMIMAGES | LVS_EX_CHECKBOXES | LVS_EX_LABELTIP | LVS_EX_FULLROWSELECT);
- // scan the plugin dir for plugins, cos
- arPluginList.destroy();
- szFilter.Empty();
- enumPlugins(dialogListPlugins, (WPARAM)hwndDlg, (LPARAM)hwndList);
- // sort out the headers
-
- ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); // dll name
- int w = ListView_GetColumnWidth(hwndList, 1);
- if (w > 110) {
- ListView_SetColumnWidth(hwndList, 1, w = 110);
- }
- int max = w < 110 ? 189 + 110 - w : 189;
- ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); // short name
- w = ListView_GetColumnWidth(hwndList, 2);
- if (w > max)
- ListView_SetColumnWidth(hwndList, 2, max);
-
- ListView_SortItems(hwndList, SortPlugins, (LPARAM)hwndDlg);
- }
- return TRUE;
-
- case WM_NOTIFY:
- if (lParam) {
- NMLISTVIEW *hdr = (NMLISTVIEW *)lParam;
- if (hdr->hdr.code == LVN_ITEMCHANGED && IsWindowVisible(hdr->hdr.hwndFrom)) {
- if (hdr->uOldState != 0 && (hdr->uNewState == 0x1000 || hdr->uNewState == 0x2000)) {
- HWND hwndList = GetDlgItem(hwndDlg, IDC_PLUGLIST);
-
- LVITEM it;
- it.mask = LVIF_PARAM | LVIF_STATE;
- it.iItem = hdr->iItem;
- if (!ListView_GetItem(hwndList, &it))
- break;
-
- PluginListItemData *dat = (PluginListItemData*)it.lParam;
- if (dat->flags & STATIC_PLUGIN) {
- ListView_SetItemState(hwndList, hdr->iItem, 0x3000, LVIS_STATEIMAGEMASK);
- return FALSE;
- }
- // find all another standard plugins by mask and disable them
- if ((hdr->uNewState == 0x2000) && dat->stdPlugin != 0) {
- for (int iRow = 0; iRow != -1; iRow = ListView_GetNextItem(hwndList, iRow, LVNI_ALL)) {
- if (iRow != hdr->iItem) { // skip the plugin we're standing on
- LVITEM dt;
- dt.mask = LVIF_PARAM;
- dt.iItem = iRow;
- if (ListView_GetItem(hwndList, &dt)) {
- PluginListItemData *dat2 = (PluginListItemData*)dt.lParam;
- if (dat2->stdPlugin & dat->stdPlugin) {// mask differs
- // the lParam is unset, so when the check is unset the clist block doesnt trigger
- int lParam = dat2->stdPlugin;
- dat2->stdPlugin = 0;
- ListView_SetItemState(hwndList, iRow, 0x1000, LVIS_STATEIMAGEMASK);
- dat2->stdPlugin = lParam;
- }
- }
- }
- }
- }
-
- if (bOldMode)
- ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), TRUE); // this here only in "ghazan mode"
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
- }
-
- if (hdr->iItem != -1) {
- int sel = hdr->uNewState & LVIS_SELECTED;
- HWND hwndList = GetDlgItem(hwndDlg, IDC_PLUGLIST);
- LVITEM lvi = { 0 };
- lvi.mask = LVIF_PARAM;
- lvi.iItem = hdr->iItem;
- if (ListView_GetItem(hwndList, &lvi)) {
- PluginListItemData *dat = (PluginListItemData*)lvi.lParam;
-
- TCHAR buf[1024];
- ListView_GetItemText(hwndList, hdr->iItem, 2, buf, SIZEOF(buf));
- SetDlgItemText(hwndDlg, IDC_PLUGININFOFRAME, sel ? buf : _T(""));
-
- ptrT tszAuthor(latin2t(sel ? dat->author : NULL));
- SetDlgItemText(hwndDlg, IDC_PLUGINAUTHOR, tszAuthor);
-
- ptrT tszEmail(latin2t(sel ? dat->authorEmail : NULL));
- SetDlgItemText(hwndDlg, IDC_PLUGINEMAIL, tszEmail);
-
- ptrT p(Langpack_PcharToTchar(dat->description));
- SetDlgItemText(hwndDlg, IDC_PLUGINLONGINFO, sel ? p : _T(""));
-
- ptrT tszCopyright(latin2t(sel ? dat->copyright : NULL));
- SetDlgItemText(hwndDlg, IDC_PLUGINCPYR, tszCopyright);
-
- ptrT tszUrl(latin2t(sel ? dat->homepage : NULL));
- SetDlgItemText(hwndDlg, IDC_PLUGINURL, tszUrl);
-
- if (!equalUUID(miid_last, dat->uuid)) {
- char szUID[128];
- uuidToString(dat->uuid, szUID, sizeof(szUID));
- SetDlgItemTextA(hwndDlg, IDC_PLUGINPID, sel ? szUID : "");
- }
- else
- SetDlgItemText(hwndDlg, IDC_PLUGINPID, sel ? TranslateT("<none>") : _T(""));
- }
- }
- }
-
- if (hdr->hdr.code == PSN_APPLY) {
- bool needRestart = false;
- TCHAR bufRestart[1024];
- int bufLen = mir_sntprintf(bufRestart, SIZEOF(bufRestart), _T("%s\n"), TranslateT("Miranda NG must be restarted to apply changes for these plugins:"));
-
- HWND hwndList = GetDlgItem(hwndDlg, IDC_PLUGLIST);
- for (int iRow = 0; iRow != -1;) {
- TCHAR buf[1024];
- ListView_GetItemText(hwndList, iRow, 1, buf, SIZEOF(buf));
- int iState = ListView_GetItemState(hwndList, iRow, LVIS_STATEIMAGEMASK);
- SetPluginOnWhiteList(buf, (iState & 0x2000) ? 1 : 0);
-
- if (!bOldMode && iState != 0x3000) {
- LVITEM lvi = { 0 };
- lvi.mask = LVIF_IMAGE | LVIF_PARAM;
- lvi.stateMask = -1;
- lvi.iItem = iRow;
- lvi.iSubItem = 0;
- if (ListView_GetItem(hwndList, &lvi)) {
- lvi.mask = LVIF_IMAGE;
-
- PluginListItemData *dat = (PluginListItemData*)lvi.lParam;
- if (iState == 0x2000) {
- // enabling plugin
- if (lvi.iImage == 3 || lvi.iImage == 5) {
- if (lvi.iImage == 3 && LoadPluginDynamically(dat)) {
- lvi.iImage = 2;
- ListView_SetItem(hwndList, &lvi);
- }
- else {
- bufLen += mir_sntprintf(bufRestart + bufLen, SIZEOF(bufRestart) - bufLen, _T(" - %s\n"), buf);
- needRestart = true;
- }
- }
- }
- else {
- // disabling plugin
- if (lvi.iImage == 2 || lvi.iImage == 4) {
- if (lvi.iImage == 2 && UnloadPluginDynamically(dat)) {
- lvi.iImage = 3;
- ListView_SetItem(hwndList, &lvi);
- }
- else {
- bufLen += mir_sntprintf(bufRestart + bufLen, SIZEOF(bufRestart) - bufLen, _T(" - %s\n"), buf);
- needRestart = true;
- }
- }
- }
- }
- }
-
- iRow = ListView_GetNextItem(hwndList, iRow, LVNI_ALL);
- }
- LoadStdPlugins();
-
- ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), needRestart);
- if (needRestart) {
- mir_sntprintf(bufRestart + bufLen, SIZEOF(bufRestart) - bufLen, _T("\n%s"), TranslateT("Do you want to restart it now?"));
- if (MessageBox(NULL, bufRestart, _T("Miranda NG"), MB_ICONWARNING | MB_YESNO) == IDYES)
- CallService(MS_SYSTEM_RESTART, 1, 0);
- }
- }
- }
- break;
-
- case WM_COMMAND:
- if (HIWORD(wParam) == STN_CLICKED) {
- switch (LOWORD(wParam)) {
- case IDC_GETMOREPLUGINS:
- CallService(MS_UTILS_OPENURL, 0, (LPARAM) "http://miranda-ng.org/downloads/");
- break;
-
- case IDC_PLUGINEMAIL:
- case IDC_PLUGINURL:
- char buf[512];
- char *p = &buf[7];
- mir_strcpy(buf, "mailto:");
- if (GetDlgItemTextA(hwndDlg, LOWORD(wParam), p, SIZEOF(buf) - 7))
- CallService(MS_UTILS_OPENURL, 0, (LPARAM)(LOWORD(wParam) == IDC_PLUGINEMAIL ? buf : p));
- break;
- }
- }
- break;
-
- case WM_DESTROY:
- arPluginList.destroy();
- RemoveAllItems(GetDlgItem(hwndDlg, IDC_PLUGLIST));
- break;
- }
- return FALSE;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-int PluginOptionsInit(WPARAM wParam, LPARAM)
-{
- OPTIONSDIALOGPAGE odp = { 0 };
- odp.hInstance = hInst;
- odp.pfnDlgProc = DlgPluginOpt;
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_PLUGINS);
- odp.position = 1300000000;
- odp.pszTitle = LPGEN("Plugins");
- odp.flags = ODPF_BOLDGROUPS;
- Options_AddPage(wParam, &odp);
- return 0;
-}
-
-void LoadPluginOptions()
-{
- bOldMode = db_get_b(NULL, "Options", "OldPluginSettings", false) != 0;
-
- hevLoadModule = CreateHookableEvent(ME_SYSTEM_MODULELOAD);
- hevUnloadModule = CreateHookableEvent(ME_SYSTEM_MODULEUNLOAD);
-}
-
-void UnloadPluginOptions()
-{
- DestroyHookableEvent(hevLoadModule);
- DestroyHookableEvent(hevUnloadModule);
-}
diff --git a/src/modules/plugins/plugins.h b/src/modules/plugins/plugins.h deleted file mode 100644 index 35ae742b60..0000000000 --- a/src/modules/plugins/plugins.h +++ /dev/null @@ -1,84 +0,0 @@ -
-// returns true if the API exports were good, otherwise, passed in data is returned
-#define CHECKAPI_NONE 0
-#define CHECKAPI_CLIST 1
-
-// block these plugins
-#define DEFMOD_REMOVED_UIPLUGINOPTS 21
-#define DEFMOD_REMOVED_PROTOCOLNETLIB 22
-
-// basic export prototypes
-typedef int (__cdecl * Miranda_Plugin_Load) (void);
-typedef int (__cdecl * Miranda_Plugin_Unload) (void);
-// version control
-typedef PLUGININFOEX * (__cdecl * Miranda_Plugin_InfoEx) (DWORD mirandaVersion);
-// prototype for clists
-typedef int (__cdecl * CList_Initialise) (void);
-
-// can all be NULL
-struct BASIC_PLUGIN_INFO
-{
- HINSTANCE hInst;
- Miranda_Plugin_Load Load;
- Miranda_Plugin_Unload Unload;
- Miranda_Plugin_InfoEx InfoEx;
- CList_Initialise clistlink;
- PLUGININFOEX * pluginInfo; // must be freed if hInst = = NULL then its a copy
- MUUID *Interfaces; // array of supported interfaces
-};
-
-#define PCLASS_FAILED 0x1 // not a valid plugin, or API is invalid, pluginname is valid
-#define PCLASS_BASICAPI 0x2 // has Load, Unload, MirandaPluginInfo() -> PLUGININFO seems valid, this dll is in memory.
-#define PCLASS_DB 0x4 // has DatabasePluginInfo() and is valid as can be, and PCLASS_BASICAPI has to be set too
-#define PCLASS_LAST 0x8 // this plugin should be unloaded after everything else
-#define PCLASS_OK 0x10 // plugin should be loaded, if DB means nothing
-#define PCLASS_LOADED 0x20 // Load(void) has been called, Unload() should be called.
-#define PCLASS_STOPPED 0x40 // wasn't loaded cos plugin name not on white list
-#define PCLASS_CLIST 0x80 // a CList implementation
-#define PCLASS_SERVICE 0x100 // has Service Mode implementation
-#define PCLASS_CORE 0x200 // a plugin from the /Core directory
-#define PCLASS_CRYPT 0x400 // crypto provider
-
-struct pluginEntry
-{
- TCHAR pluginname[64];
- unsigned int pclass; // PCLASS_*
- int hLangpack;
- BASIC_PLUGIN_INFO bpi;
-};
-
-extern LIST<pluginEntry> pluginList, servicePlugins, clistPlugins;
-extern MUUID miid_last;
-
-int PluginOptionsInit(WPARAM, LPARAM);
-void LoadPluginOptions();
-void UnloadPluginOptions();
-
-int isPluginOnWhiteList(const TCHAR* pluginname);
-void SetPluginOnWhiteList(const TCHAR* pluginname, int allow);
-
-int getDefaultPluginIdx(const MUUID& muuid);
-bool hasMuuid(const BASIC_PLUGIN_INFO&, const MUUID&);
-bool hasMuuid(const MUUID* pFirst, const MUUID&);
-int equalUUID(const MUUID& u1, const MUUID& u2);
-int checkAPI(TCHAR* plugin, BASIC_PLUGIN_INFO* bpi, DWORD mirandaVersion, int checkTypeAPI);
-
-pluginEntry* OpenPlugin(TCHAR *tszFileName, TCHAR *dir, TCHAR *path);
-
-bool TryLoadPlugin(pluginEntry *p, bool bDynamic);
-void Plugin_Uninit(pluginEntry *p);
-int Plugin_UnloadDyn(pluginEntry *p);
-
-typedef BOOL (*SCAN_PLUGINS_CALLBACK) (WIN32_FIND_DATA * fd, TCHAR *path, WPARAM wParam, LPARAM lParam);
-void enumPlugins(SCAN_PLUGINS_CALLBACK cb, WPARAM wParam, LPARAM lParam);
-
-struct MuuidReplacement
-{
- MUUID uuid; // default interface plugin
- TCHAR* stdplugname;
- pluginEntry* pImpl; // replacement plugin
-};
-
-bool LoadCorePlugin( MuuidReplacement& );
-
-MUUID* GetPluginInterfaces(const TCHAR* ptszFileName, bool& bIsPlugin);
\ No newline at end of file |