From c2bb7727483b9b5620e8cc0ce6adae35ee78d0a4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 28 Mar 2018 15:41:21 +0300 Subject: fix for proper initialization of partially loaded plugins --- src/mir_app/src/newplugins.cpp | 65 +++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 35 deletions(-) (limited to 'src/mir_app') diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp index 3978b14dd8..1710e71a3d 100644 --- a/src/mir_app/src/newplugins.cpp +++ b/src/mir_app/src/newplugins.cpp @@ -523,47 +523,42 @@ int isPluginOnWhiteList(const wchar_t* pluginname) bool TryLoadPlugin(pluginEntry *p, bool bDynamic) { - // if plugin is already loaded, don't ask questions, just mark it as loaded - if (p->bpi.hInst != nullptr) { - RegisterModule(p->bpi.hInst); - p->bLoaded = true; - return true; - } + if (p->bpi.hInst == nullptr) { + if (!bDynamic && !isPluginOnWhiteList(p->pluginname)) + return false; - if (!bDynamic && !isPluginOnWhiteList(p->pluginname)) - return false; + if (!p->bHasBasicApi) { + wchar_t exe[MAX_PATH], tszFullPath[MAX_PATH]; + GetModuleFileName(nullptr, exe, _countof(exe)); + wchar_t* slice = wcsrchr(exe, '\\'); + if (slice) + *slice = 0; - if (!p->bHasBasicApi) { - wchar_t exe[MAX_PATH], tszFullPath[MAX_PATH]; - GetModuleFileName(nullptr, exe, _countof(exe)); - wchar_t* slice = wcsrchr(exe, '\\'); - if (slice) - *slice = 0; + BASIC_PLUGIN_INFO bpi; + mir_snwprintf(tszFullPath, L"%s\\%s\\%s", exe, (p->bIsCore) ? L"Core" : L"Plugins", p->pluginname); + if (!checkAPI(tszFullPath, &bpi, mirandaVersion, CHECKAPI_NONE)) { + p->bFailed = true; + return false; + } - BASIC_PLUGIN_INFO bpi; - mir_snwprintf(tszFullPath, L"%s\\%s\\%s", exe, (p->bIsCore) ? L"Core" : L"Plugins", p->pluginname); - if (!checkAPI(tszFullPath, &bpi, mirandaVersion, CHECKAPI_NONE)) { - p->bFailed = true; - return false; + p->bpi = bpi; + p->bOk = p->bHasBasicApi = true; } - p->bpi = bpi; - p->bOk = p->bHasBasicApi = true; - } - - if (p->bpi.Interfaces) { - MUUID *piface = p->bpi.Interfaces; - for (int i = 0; piface[i] != miid_last; 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; + if (p->bpi.Interfaces) { + MUUID *piface = p->bpi.Interfaces; + for (int i = 0; piface[i] != miid_last; 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->bIsCore) + Plugin_UnloadDyn(pluginDefault[idx].pImpl); } - - // we're loading new implementation dynamically, let the old one die - if (!p->bIsCore) - Plugin_UnloadDyn(pluginDefault[idx].pImpl); } } } -- cgit v1.2.3