From dd73f92c55cb026b52c8b04cb1dc50d621822a95 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 28 Mar 2022 21:06:44 +0300 Subject: =?UTF-8?q?fixes=20#3061=20(StdMsg:=20=D0=BF=D1=80=D0=BE=D0=B1?= =?UTF-8?q?=D0=BB=D0=B5=D0=BC=D1=8B=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=B8=D0=BD=D0=B0=D0=BC=D0=B8=D1=87=D0=B5=D1=81=D0=BA?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=BF=D0=BE=D0=B4=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mir_app/src/newplugins.cpp | 48 ++++++++++++++++++++++++++++-------------- src/mir_app/src/plugins.h | 1 + 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp index 3e83b9523d..7e90950040 100644 --- a/src/mir_app/src/newplugins.cpp +++ b/src/mir_app/src/newplugins.cpp @@ -168,34 +168,42 @@ int getDefaultPluginIdx(const MUUID &muuid) return -1; } -bool MuuidReplacement::Load() +bool MuuidReplacement::Preload() { - wchar_t exe[MAX_PATH], tszPlugName[MAX_PATH]; - GetModuleFileName(nullptr, exe, _countof(exe)); - wchar_t *p = wcsrchr(exe, '\\'); if (p) *p = 0; - + wchar_t tszPlugName[MAX_PATH]; mir_snwprintf(tszPlugName, L"%s.dll", stdplugname); - pluginEntry *ppe = OpenPlugin(tszPlugName, L"Core", exe); + + pluginEntry *ppe = OpenPlugin(tszPlugName, L"Core", VARSW(L"%miranda_path%")); if (ppe == nullptr) { -LBL_Error: - Plugin_UnloadDyn(ppe); pImpl = nullptr; return false; } ppe->bIsCore = true; + pImpl = ppe; + return true; +} - if (!TryLoadPlugin(ppe, true)) - goto LBL_Error; +bool MuuidReplacement::Load() +{ + if (pImpl == nullptr) + if (!Preload()) + return false; + + if (!TryLoadPlugin(pImpl, true)) { +LBL_Error: + Plugin_UnloadDyn(pImpl); + pImpl = nullptr; + return false; + } - CMPluginBase *ppb = ppe->m_pPlugin; + CMPluginBase *ppb = pImpl->m_pPlugin; if (g_bModulesLoadedFired) { if (CallPluginEventHook(ppb->getInst(), hModulesLoadedEvent, 0, 0) != 0) goto LBL_Error; NotifyEventHooks(hevLoadModule, (WPARAM)ppb, (LPARAM)ppb->getInst()); } - pImpl = ppe; return true; } @@ -299,18 +307,23 @@ bool Plugin_UnloadDyn(pluginEntry *p) if (p == nullptr) return true; + MuuidReplacement *stdPlugin = nullptr; + // mark default plugins to be loaded if (!p->bIsCore) for (auto &it : pluginDefault) - if (it.pImpl == p) - if (!it.Load()) { - MessageBoxW(nullptr, - CMStringW(FORMAT, TranslateT("Plugin %S cannot be unloaded because the core plugin is missing"), p->pluginname), + if (it.pImpl == p) { + if (!it.Preload()) { + MessageBoxW(nullptr, + CMStringW(FORMAT, TranslateT("Plugin %S cannot be unloaded because the core plugin is missing"), p->pluginname), L"Miranda", MB_ICONERROR | MB_OK); it.pImpl = p; return false; } + stdPlugin = ⁢ + } + // if plugin has active resources, kill them forcibly CMPluginBase *ppb = p->m_pPlugin; if (ppb != nullptr) { @@ -334,6 +347,9 @@ bool Plugin_UnloadDyn(pluginEntry *p) } Plugin_Uninit(p); + + if (stdPlugin) + stdPlugin->Load(); return true; } diff --git a/src/mir_app/src/plugins.h b/src/mir_app/src/plugins.h index d845bf7d4d..aad6d35a9a 100644 --- a/src/mir_app/src/plugins.h +++ b/src/mir_app/src/plugins.h @@ -77,6 +77,7 @@ struct MuuidReplacement wchar_t* stdplugname; pluginEntry* pImpl; // replacement plugin + bool Preload(); bool Load(); }; -- cgit v1.2.3