From bea9ca96330b7391df275dcaa0597623458a54f3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 28 Mar 2018 00:02:18 +0300 Subject: fix for plugin loader: it shall not unload already loaded plugins --- src/mir_app/src/newplugins.cpp | 72 ++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp index 80bc8897c0..fe84b8e321 100644 --- a/src/mir_app/src/newplugins.cpp +++ b/src/mir_app/src/newplugins.cpp @@ -523,45 +523,52 @@ int isPluginOnWhiteList(const wchar_t* pluginname) bool TryLoadPlugin(pluginEntry *p, bool bDynamic) { - wchar_t exe[MAX_PATH], tszFullPath[MAX_PATH]; - GetModuleFileName(nullptr, exe, _countof(exe)); - wchar_t* slice = wcsrchr(exe, '\\'); - if (slice) - *slice = 0; + // 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->bLoaded && !p->bIsDatabase && !p->bIsClist) { - if (!bDynamic && !isPluginOnWhiteList(p->pluginname)) - return false; + if (!bDynamic && !isPluginOnWhiteList(p->pluginname)) + return false; - if (!p->bHasBasicApi) { - 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; - } + 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; - p->bpi = bpi; - p->bOk = p->bHasBasicApi = true; + 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; } - 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); + 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; } + + // we're loading new implementation dynamically, let the old one die + if (!p->bIsCore) + Plugin_UnloadDyn(pluginDefault[idx].pImpl); } } + } + if (!p->bLoaded) { RegisterModule(p->bpi.hInst); if (p->bpi.Load() != 0) return false; @@ -576,10 +583,7 @@ bool TryLoadPlugin(pluginEntry *p, bool bDynamic) } } } - else if (p->bpi.hInst != nullptr) { - RegisterModule(p->bpi.hInst); - p->bLoaded = true; - } + return true; } -- cgit v1.2.3