From a25f1165d67181ddf83d087bb5f7fcc6646dbaef Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 24 Mar 2022 13:24:13 +0300 Subject: =?UTF-8?q?fixes=20#3048=20(=D0=9F=D1=80=D0=BE=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BC=D0=B0=20=D0=B3=D1=80=D0=BE=D0=B7=D0=B8=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D0=B7=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B8=D1=82=D1=8C?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=83=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81=D1=82=D0=B2=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B5=D0=B9=20=D1=8F=D0=B4=D1=80?= =?UTF-8?q?=D0=B0,=20=D0=BD=D0=BE=20=D0=BD=D0=B5=20=D0=B7=D0=B0=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=88=D0=B0=D0=B5=D1=82)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mir_app/mir_app.vcxproj.filters | 6 +- src/mir_app/src/newplugins.cpp | 119 +++++++++++++++++++----------------- src/mir_app/src/pluginopts.cpp | 8 ++- src/mir_app/src/plugins.h | 4 +- 4 files changed, 73 insertions(+), 64 deletions(-) diff --git a/src/mir_app/mir_app.vcxproj.filters b/src/mir_app/mir_app.vcxproj.filters index 0b29744b8c..0a5e9fb1c5 100644 --- a/src/mir_app/mir_app.vcxproj.filters +++ b/src/mir_app/mir_app.vcxproj.filters @@ -86,9 +86,6 @@ Source Files - - Source Files - Source Files @@ -398,6 +395,9 @@ Source Files\Plugins + + Source Files\Plugins + diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp index 12ffdb230d..3e83b9523d 100644 --- a/src/mir_app/src/newplugins.cpp +++ b/src/mir_app/src/newplugins.cpp @@ -168,17 +168,35 @@ int getDefaultPluginIdx(const MUUID &muuid) return -1; } -int LoadStdPlugins() +bool MuuidReplacement::Load() { - for (auto &it : pluginDefault) { - if (it.pImpl) - continue; + wchar_t exe[MAX_PATH], tszPlugName[MAX_PATH]; + GetModuleFileName(nullptr, exe, _countof(exe)); + wchar_t *p = wcsrchr(exe, '\\'); if (p) *p = 0; - if (!LoadCorePlugin(it)) - return 1; + mir_snwprintf(tszPlugName, L"%s.dll", stdplugname); + pluginEntry *ppe = OpenPlugin(tszPlugName, L"Core", exe); + if (ppe == nullptr) { +LBL_Error: + Plugin_UnloadDyn(ppe); + pImpl = nullptr; + return false; } - return 0; + ppe->bIsCore = true; + + if (!TryLoadPlugin(ppe, true)) + goto LBL_Error; + + CMPluginBase *ppb = ppe->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; } ///////////////////////////////////////////////////////////////////////////////////////// @@ -281,6 +299,19 @@ bool Plugin_UnloadDyn(pluginEntry *p) if (p == nullptr) return true; + // 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), + L"Miranda", MB_ICONERROR | MB_OK); + it.pImpl = p; + return false; + } + + // if plugin has active resources, kill them forcibly CMPluginBase *ppb = p->m_pPlugin; if (ppb != nullptr) { if (HINSTANCE hInst = ppb->getInst()) { @@ -302,12 +333,6 @@ bool Plugin_UnloadDyn(pluginEntry *p) NotifyFastHook(hevUnloadModule, (WPARAM)&ppb, (LPARAM)ppb->getInst()); } - // mark default plugins to be loaded - if (!p->bIsCore) - for (auto &it : pluginDefault) - if (it.pImpl == p) - it.pImpl = nullptr; - Plugin_Uninit(p); return true; } @@ -501,44 +526,6 @@ bool TryLoadPlugin(pluginEntry *p, bool bDynamic) return true; } -///////////////////////////////////////////////////////////////////////////////////////// -// Core plugins support - -static wchar_t tszCoreErr[] = LPGENW("Core plugin '%s' cannot be loaded or missing. Miranda will exit now"); - -bool LoadCorePlugin(MuuidReplacement &mr) -{ - wchar_t exe[MAX_PATH], tszPlugName[MAX_PATH]; - GetModuleFileName(nullptr, exe, _countof(exe)); - wchar_t *p = wcsrchr(exe, '\\'); if (p) *p = 0; - - mir_snwprintf(tszPlugName, L"%s.dll", mr.stdplugname); - pluginEntry* ppe = OpenPlugin(tszPlugName, L"Core", exe); - if (ppe == nullptr) { -LBL_Error: - MessageBox(nullptr, CMStringW(FORMAT, TranslateW(tszCoreErr), mr.stdplugname), TranslateT("Fatal error"), MB_OK | MB_ICONSTOP); - - Plugin_UnloadDyn(ppe); - mr.pImpl = nullptr; - return false; - } - - ppe->bIsCore = true; - - if (!TryLoadPlugin(ppe, true)) - goto LBL_Error; - - CMPluginBase *ppb = ppe->m_pPlugin; - if (g_bModulesLoadedFired) { - if (CallPluginEventHook(ppb->getInst(), hModulesLoadedEvent, 0, 0) != 0) - goto LBL_Error; - - NotifyEventHooks(hevLoadModule, (WPARAM)ppb, (LPARAM)ppb->getInst()); - } - mr.pImpl = ppe; - return true; -} - ///////////////////////////////////////////////////////////////////////////////////////// // Contact list plugins support @@ -586,7 +573,7 @@ static pluginEntry* getCListModule(wchar_t *exe) } MuuidReplacement &stdClist = pluginDefault[0]; - if (LoadCorePlugin(stdClist)) { + if (stdClist.Load()) { mir_snwprintf(tszFullPath, L"%s\\Core\\%s.dll", exe, stdClist.stdplugname); if (loadClistModule(tszFullPath, stdClist.pImpl)) return stdClist.pImpl; @@ -629,7 +616,7 @@ int LaunchServicePlugin(pluginEntry *p) if (res != CALLSERVICE_NOTFOUND) return res; - MessageBox(nullptr, TranslateT("Unable to load plugin in service mode!"), _A2T(p->pluginname), MB_ICONSTOP); + MessageBoxW(nullptr, TranslateT("Unable to load plugin in service mode!"), _A2T(p->pluginname), MB_ICONSTOP); Plugin_Uninit(p); return SERVICE_FAILED; } @@ -711,9 +698,9 @@ int LoadNewPluginsModule(void) if (plugin_clist == nullptr) { // result = 0, no clist_* can be found if (clistPlugins.getCount()) - MessageBox(nullptr, TranslateT("Unable to start any of the installed contact list plugins, I even ignored your preferences for which contact list couldn't load any."), L"Miranda NG", MB_OK | MB_ICONERROR); + MessageBoxW(nullptr, TranslateT("Unable to start any of the installed contact list plugins, I even ignored your preferences for which contact list couldn't load any."), L"Miranda NG", MB_OK | MB_ICONERROR); else - MessageBox(nullptr, TranslateT("Can't find a contact list plugin! You need StdClist or any other contact list plugin."), L"Miranda NG", MB_OK | MB_ICONERROR); + MessageBoxW(nullptr, TranslateT("Can't find a contact list plugin! You need StdClist or any other contact list plugin."), L"Miranda NG", MB_OK | MB_ICONERROR); return 1; } @@ -738,6 +725,26 @@ int LoadNewPluginsModule(void) return 0; } +///////////////////////////////////////////////////////////////////////////////////////// +// loads all standard plugins. + +int LoadStdPlugins() +{ + for (auto &it : pluginDefault) { + if (it.pImpl) + continue; + + if (!it.Load()) { + MessageBoxW(nullptr, + CMStringW(FORMAT, LPGENW("Core plugin '%s' cannot be loaded or missing. Miranda will exit now"), it.stdplugname), + TranslateT("Fatal error"), MB_OK | MB_ICONSTOP); + return 1; + } + } + + return 0; +} + ///////////////////////////////////////////////////////////////////////////////////////// // Plugins module initialization // called before anything real is loaded, incl. database @@ -763,7 +770,7 @@ int LoadNewPluginsModuleInfos(void) enumPlugins(scanPluginsDir, 0, 0); MuuidReplacement stdCrypt = { MIID_CRYPTO, L"stdcrypt", nullptr }; - if (!LoadCorePlugin(stdCrypt)) + if (!stdCrypt.Load()) return 1; SetServiceModePlugin(_T2A(CmdLine_GetOption(L"svc"))); diff --git a/src/mir_app/src/pluginopts.cpp b/src/mir_app/src/pluginopts.cpp index f3f1094366..4f7160d2be 100644 --- a/src/mir_app/src/pluginopts.cpp +++ b/src/mir_app/src/pluginopts.cpp @@ -394,8 +394,10 @@ public: } else { // disabling plugin if (dat->bWasLoaded) { - if (!dat->bRequiresRestart) - UnloadPluginDynamically(dat); + if (!dat->bRequiresRestart) { + if (!UnloadPluginDynamically(dat)) + m_plugList.SetItemState(iRow, 0x2000, LVIS_STATEIMAGEMASK); + } else { bufRestart.AppendFormat(L" - %s\n", buf); needRestart = true; @@ -413,7 +415,7 @@ public: if (needRestart) { bufRestart.AppendChar('\n'); bufRestart.Append(TranslateT("Do you want to restart it now?")); - if (MessageBox(m_hwnd, bufRestart, L"Miranda NG", MB_ICONWARNING | MB_YESNO) == IDYES) + if (MessageBoxW(m_hwnd, bufRestart, L"Miranda NG", MB_ICONWARNING | MB_YESNO) == IDYES) CallService(MS_SYSTEM_RESTART, 1, 0); } return true; diff --git a/src/mir_app/src/plugins.h b/src/mir_app/src/plugins.h index 6b686265ab..d845bf7d4d 100644 --- a/src/mir_app/src/plugins.h +++ b/src/mir_app/src/plugins.h @@ -76,8 +76,8 @@ struct MuuidReplacement MUUID uuid; // default interface plugin wchar_t* stdplugname; pluginEntry* pImpl; // replacement plugin -}; -bool LoadCorePlugin(MuuidReplacement&); + bool Load(); +}; MUUID* GetPluginInterfaces(const wchar_t *ptszFileName, bool &bIsPlugin); -- cgit v1.2.3