From eb37be750853ee7e21406100e90b96469d501d36 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 11 Apr 2021 12:01:31 +0300 Subject: =?UTF-8?q?fixes=20#2789=20(Import:=20=D0=BE=D0=BF=D1=86=D0=B8?= =?UTF-8?q?=D1=8F=20"=D0=BD=D0=B5=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B6?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D0=BF=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D1=81=D1=82=D0=B0=D1=80=D1=82=D0=B5"=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mir_app/src/db_upgrade.cpp | 2 +- src/mir_app/src/mir_app.def | 2 + src/mir_app/src/mir_app64.def | 2 + src/mir_app/src/newplugins.cpp | 79 +++++++++++++++++++++++--------------- src/mir_app/src/pluginopts.cpp | 6 +-- src/mir_app/src/plugins.h | 5 +-- src/mir_app/src/profilemanager.cpp | 2 +- src/mir_app/src/proto_opts.cpp | 2 +- 8 files changed, 58 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/mir_app/src/db_upgrade.cpp b/src/mir_app/src/db_upgrade.cpp index 9b6c83cfb5..95323a7968 100644 --- a/src/mir_app/src/db_upgrade.cpp +++ b/src/mir_app/src/db_upgrade.cpp @@ -61,7 +61,7 @@ LBL_Error: return nullptr; } - if (SetServiceModePlugin(L"import", 1) != ERROR_SUCCESS) { + if (SetServiceModePlugin("import", 1) != ERROR_SUCCESS) { if (IDYES == MessageBoxW(nullptr, TranslateT(MISSING_PLUG_MSG), L"Miranda NG", MB_YESNO)) Utils_OpenUrl("https://miranda-ng.org/p/Import"); goto LBL_Error; diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 89f5e022ce..c86156eb00 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -775,3 +775,5 @@ _Netlib_GetTlsUnique@8 @831 NONAME ?getIcon@CHAT_MANAGER@@QBGPAUHICON__@@H@Z @863 NONAME ?getSoundName@GCSessionInfoBase@@QBEPBDH@Z @864 NONAME ?Upgrade@DB@@YGPAVMDatabaseCommon@@PB_W@Z @865 NONAME +?IsPluginOnWhiteList@@YG_NPBD@Z @866 NONAME +?SetPluginOnWhiteList@@YGXPBD_N@Z @867 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 91e38bbdfc..ab19f1360a 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -775,3 +775,5 @@ Netlib_GetTlsUnique @831 NONAME ?getIcon@CHAT_MANAGER@@QEBAPEAUHICON__@@H@Z @863 NONAME ?getSoundName@GCSessionInfoBase@@QEBAPEBDH@Z @864 NONAME ?Upgrade@DB@@YAPEAVMDatabaseCommon@@PEB_W@Z @865 NONAME +?IsPluginOnWhiteList@@YA_NPEBD@Z @866 NONAME +?SetPluginOnWhiteList@@YAXPEBD_N@Z @867 NONAME diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp index 3af7efc073..12918f3426 100644 --- a/src/mir_app/src/newplugins.cpp +++ b/src/mir_app/src/newplugins.cpp @@ -30,6 +30,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "langpack.h" #include "netlib.h" +#define PLUGINDISABLELIST "PluginDisable" + bool g_bReadyToInitClist = false; void LoadExtraIconsModule(); @@ -37,7 +39,7 @@ void freePluginInstance(HINSTANCE hInst); static int sttComparePluginsByName(const pluginEntry *p1, const pluginEntry *p2) { - return mir_wstrcmpi(p1->pluginname, p2->pluginname); + return mir_strcmpi(p1->pluginname, p2->pluginname); } LIST @@ -51,8 +53,6 @@ MUUID miid_last = MIID_LAST; ///////////////////////////////////////////////////////////////////////////////////////// -#define MAX_MIR_VER ULONG_MAX - static bool bModuleInitialized = FALSE; HANDLE hevLoadModule, hevUnloadModule; @@ -61,7 +61,18 @@ static int askAboutIgnoredPlugins; pluginEntry *plugin_checker, *plugin_crshdmp, *plugin_service, *plugin_ssl, *plugin_clist; -#define PLUGINDISABLELIST "PluginDisable" +///////////////////////////////////////////////////////////////////////////////////////// + +struct CPluginName : public CMStringA +{ + CPluginName(const char *szName) : + CMStringA(szName) + { + MakeLower(); + if (Find(".dll") == -1) + Append(".dll"); + } +}; ///////////////////////////////////////////////////////////////////////////////////////// // basic functions @@ -349,7 +360,7 @@ pluginEntry* OpenPlugin(wchar_t *tszFileName, wchar_t *dir, wchar_t *path) return nullptr; pluginEntry *p = (pluginEntry*)mir_calloc(sizeof(pluginEntry)); - wcsncpy_s(p->pluginname, tszFileName, _TRUNCATE); + strncpy_s(p->pluginname, _T2A(tszFileName), _TRUNCATE); // add it to the list anyway pluginList.insert(p); @@ -408,20 +419,25 @@ pluginEntry* OpenPlugin(wchar_t *tszFileName, wchar_t *dir, wchar_t *path) return p; } -void SetPluginOnWhiteList(const wchar_t* pluginname, int allow) +MIR_APP_DLL(void) SetPluginOnWhiteList(const char* szPluginName, bool bAllow) { - db_set_b(0, PLUGINDISABLELIST, _strlwr(_T2A(pluginname)), allow == 0); + if (szPluginName != nullptr) + db_set_b(0, PLUGINDISABLELIST, CPluginName(szPluginName).c_str(), !bAllow); } // returns 1 if the plugin should be enabled within this profile, filename is always lower case -int isPluginOnWhiteList(const wchar_t* pluginname) +MIR_APP_DLL(bool) IsPluginOnWhiteList(const char *szPluginName) { - int rc = db_get_b(0, PLUGINDISABLELIST, _strlwr(_T2A(pluginname)), 0); + if (szPluginName == nullptr) + return false; + + CPluginName tmp(szPluginName); + int rc = db_get_b(0, PLUGINDISABLELIST, tmp, 0); if (rc != 0 && askAboutIgnoredPlugins) { wchar_t buf[256]; - mir_snwprintf(buf, TranslateT("'%s' is disabled, re-enable?"), pluginname); - if (MessageBox(nullptr, buf, TranslateT("Re-enable Miranda plugin?"), MB_YESNO | MB_ICONQUESTION) == IDYES) { - SetPluginOnWhiteList(pluginname, 1); + mir_snwprintf(buf, TranslateT("'%S' is disabled, re-enable?"), tmp.c_str()); + if (MessageBoxW(nullptr, buf, TranslateT("Re-enable Miranda plugin?"), MB_YESNO | MB_ICONQUESTION) == IDYES) { + SetPluginOnWhiteList(szPluginName, true); rc = 0; } } @@ -431,7 +447,7 @@ int isPluginOnWhiteList(const wchar_t* pluginname) bool TryLoadPlugin(pluginEntry *p, bool bDynamic) { - if (!bDynamic && !isPluginOnWhiteList(p->pluginname)) + if (!bDynamic && !IsPluginOnWhiteList(p->pluginname)) return false; if (p->m_pPlugin == nullptr) { @@ -442,7 +458,7 @@ bool TryLoadPlugin(pluginEntry *p, bool bDynamic) if (slice) *slice = 0; - mir_snwprintf(tszFullPath, L"%s\\%s\\%s", exe, (p->bIsCore) ? L"Core" : L"Plugins", p->pluginname); + mir_snwprintf(tszFullPath, L"%s\\%s\\%S", exe, (p->bIsCore) ? L"Core" : L"Plugins", p->pluginname); if (!p->checkAPI(tszFullPath)) return false; } @@ -453,7 +469,7 @@ bool TryLoadPlugin(pluginEntry *p, bool bDynamic) int idx = getDefaultPluginIdx(piface[i]); if (idx != -1 && pluginDefault[idx].pImpl) { if (!bDynamic) { // this place is already occupied, skip & disable - SetPluginOnWhiteList(p->pluginname, 0); + SetPluginOnWhiteList(p->pluginname, false); return false; } @@ -561,10 +577,10 @@ static pluginEntry* getCListModule(wchar_t *exe) wchar_t tszFullPath[MAX_PATH]; for (auto &p : clistPlugins) { - if (!isPluginOnWhiteList(p->pluginname)) + if (!IsPluginOnWhiteList(p->pluginname)) continue; - mir_snwprintf(tszFullPath, L"%s\\Plugins\\%s", exe, p->pluginname); + mir_snwprintf(tszFullPath, L"%s\\Plugins\\%S", exe, p->pluginname); if (loadClistModule(tszFullPath, p)) return p; } @@ -581,8 +597,9 @@ static pluginEntry* getCListModule(wchar_t *exe) int UnloadPlugin(wchar_t* buf, int bufLen) { + ptrA szShortName(mir_u2a(buf)); for (auto &it : pluginList.rev_iter()) { - if (!mir_wstrcmpi(it->pluginname, buf)) { + if (!mir_strcmpi(it->pluginname, szShortName)) { GetModuleFileName(it->m_pPlugin->getInst(), buf, bufLen); Plugin_Uninit(it); return TRUE; @@ -612,19 +629,17 @@ int LaunchServicePlugin(pluginEntry *p) if (res != CALLSERVICE_NOTFOUND) return res; - MessageBox(nullptr, TranslateT("Unable to load plugin in service mode!"), p->pluginname, MB_ICONSTOP); + MessageBox(nullptr, TranslateT("Unable to load plugin in service mode!"), _A2T(p->pluginname), MB_ICONSTOP); Plugin_Uninit(p); return SERVICE_FAILED; } -MIR_APP_DLL(int) SetServiceModePlugin(const wchar_t *wszPluginName, WPARAM wParam, LPARAM lParam) +MIR_APP_DLL(int) SetServiceModePlugin(const char *szPluginName, WPARAM wParam, LPARAM lParam) { - size_t cbLen = mir_wstrlen(wszPluginName); - if (cbLen == 0) - return 1; + CPluginName tmp(szPluginName); for (auto &p : servicePlugins) { - if (!wcsnicmp(p->pluginname, wszPluginName, cbLen)) { + if (!stricmp(tmp, p->pluginname)) { plugin_service = p; g_srvWParam = wParam; g_srvLParam = lParam; @@ -632,7 +647,7 @@ MIR_APP_DLL(int) SetServiceModePlugin(const wchar_t *wszPluginName, WPARAM wPara } } - return 2; + return 1; } ///////////////////////////////////////////////////////////////////////////////////////// @@ -684,7 +699,7 @@ int LoadProtocolPlugins(void) continue; wchar_t tszFullPath[MAX_PATH]; - mir_snwprintf(tszFullPath, L"%s\\%s\\%s", exe, L"Plugins", p->pluginname); + mir_snwprintf(tszFullPath, L"%s\\%s\\%S", exe, L"Plugins", p->pluginname); p->checkAPI(tszFullPath); } @@ -707,7 +722,7 @@ int LoadNewPluginsModule(void) askAboutIgnoredPlugins = (UINT)GetPrivateProfileInt(L"PluginLoader", L"AskAboutIgnoredPlugins", 0, mirandabootini); // if Crash Dumper is present, load it to provide Crash Reports - if (plugin_crshdmp != nullptr && isPluginOnWhiteList(plugin_crshdmp->pluginname)) + if (plugin_crshdmp != nullptr && IsPluginOnWhiteList(plugin_crshdmp->pluginname)) if (!TryLoadPlugin(plugin_crshdmp, false)) Plugin_Uninit(plugin_crshdmp); @@ -724,11 +739,11 @@ int LoadNewPluginsModule(void) return 1; } - /* enable and disable as needed */ + // enable and disable as needed for (auto &p : clistPlugins) - SetPluginOnWhiteList(p->pluginname, plugin_clist != p ? 0 : 1); + SetPluginOnWhiteList(p->pluginname, plugin_clist == p); - /* now loop thru and load all the other plugins, do this in one pass */ + // now loop thru and load all the other plugins, do this in one pass for (int i = 0; i < pluginList.getCount(); i++) { pluginEntry *p = pluginList[i]; if (!TryLoadPlugin(p, false)) { @@ -738,7 +753,7 @@ int LoadNewPluginsModule(void) } for (auto &it : servicePlugins.rev_iter()) - if (!isPluginOnWhiteList(it->pluginname)) + if (!IsPluginOnWhiteList(it->pluginname)) Plugin_Uninit(it); HookEvent(ME_OPT_INITIALISE, PluginOptionsInit); @@ -773,7 +788,7 @@ int LoadNewPluginsModuleInfos(void) if (!LoadCorePlugin(stdCrypt)) return 1; - SetServiceModePlugin(CmdLine_GetOption(L"svc")); + SetServiceModePlugin(_T2A(CmdLine_GetOption(L"svc"))); return 0; } diff --git a/src/mir_app/src/pluginopts.cpp b/src/mir_app/src/pluginopts.cpp index 3c75861424..4f63a727bd 100644 --- a/src/mir_app/src/pluginopts.cpp +++ b/src/mir_app/src/pluginopts.cpp @@ -147,7 +147,7 @@ static BOOL dialogListPlugins(WIN32_FIND_DATA *fd, wchar_t *path, WPARAM, LPARAM it.lParam = (LPARAM)dat; pCtrl->InsertItem(&it); - if (!bNoCheckbox && isPluginOnWhiteList(fd->cFileName)) + if (!bNoCheckbox && IsPluginOnWhiteList(_T2A(fd->cFileName))) dat->bWasChecked = true; if (dat->iRow != -1) { @@ -328,7 +328,7 @@ public: // set checkboxes for all loaded plugins for (auto &it : arPluginList) { - if (!isPluginOnWhiteList(it->fileName)) + if (!IsPluginOnWhiteList(_T2A(it->fileName))) continue; if (it->flags & STATIC_PLUGIN) @@ -362,7 +362,7 @@ public: wchar_t buf[1024]; m_plugList.GetItemText(iRow, 0, buf, _countof(buf)); int iState = m_plugList.GetItemState(iRow, LVIS_STATEIMAGEMASK); - SetPluginOnWhiteList(buf, (iState & 0x2000) ? 1 : 0); + SetPluginOnWhiteList(_T2A(buf), (iState & 0x2000) != 0); if (iState != 0x3000) { LVITEM lvi = { 0 }; diff --git a/src/mir_app/src/plugins.h b/src/mir_app/src/plugins.h index 9525c27417..6c6d8153b2 100644 --- a/src/mir_app/src/plugins.h +++ b/src/mir_app/src/plugins.h @@ -10,7 +10,7 @@ typedef int(__cdecl *Miranda_Plugin_Unload) (void); struct pluginEntry { - wchar_t pluginname[64]; + char pluginname[64]; struct { bool bFailed : 1; // not a valid plugin, or API is invalid, pluginname is valid @@ -58,9 +58,6 @@ extern MUUID miid_last; int PluginOptionsInit(WPARAM, LPARAM); -int isPluginOnWhiteList(const wchar_t *pluginname); -void SetPluginOnWhiteList(const wchar_t *pluginname, int allow); - int getDefaultPluginIdx(const MUUID &muuid); bool hasMuuid(const MUUID *pFirst, const MUUID&); bool isPluginBanned(const MUUID &u1); diff --git a/src/mir_app/src/profilemanager.cpp b/src/mir_app/src/profilemanager.cpp index b77880e4cf..5c4453cb45 100644 --- a/src/mir_app/src/profilemanager.cpp +++ b/src/mir_app/src/profilemanager.cpp @@ -636,7 +636,7 @@ public: else { for (int i = 0; i < servicePlugins.getCount(); i++) { pluginEntry *p = servicePlugins[i]; - m_servicePlugs.AddString(TranslateW(p->pluginname), i); + m_servicePlugs.AddStringA(p->pluginname, i); } m_servicePlugs.Disable(); diff --git a/src/mir_app/src/proto_opts.cpp b/src/mir_app/src/proto_opts.cpp index 3742a04f4a..5e5094bc1f 100644 --- a/src/mir_app/src/proto_opts.cpp +++ b/src/mir_app/src/proto_opts.cpp @@ -882,7 +882,7 @@ bool CAccountFormDlg::OnApply() if (oldProto && UnloadPlugin(szPlugin, _countof(szPlugin))) { wchar_t szNewName[MAX_PATH]; mir_snwprintf(szNewName, L"%s~", szPlugin); - MoveFile(szPlugin, szNewName); + MoveFileW(szPlugin, szNewName); } m_action = PRAC_ADDED; } -- cgit v1.2.3