From e0bb11dee76db814a37ecfb155076169d8780878 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 22 May 2025 16:49:26 +0300 Subject: fixes #1907 (PluginUpdater: move deleting/renaming file rules from plugin to server side) --- plugins/PluginUpdater/src/DlgUpdate.cpp | 121 ++------------------------------ plugins/PluginUpdater/src/Utils.cpp | 20 +++++- plugins/PluginUpdater/src/stdafx.h | 30 +++++--- 3 files changed, 48 insertions(+), 123 deletions(-) (limited to 'plugins/PluginUpdater/src') diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp index dc823ad35d..e04c3561e2 100644 --- a/plugins/PluginUpdater/src/DlgUpdate.cpp +++ b/plugins/PluginUpdater/src/DlgUpdate.cpp @@ -466,114 +466,7 @@ LBL_Error: ///////////////////////////////////////////////////////////////////////////////////////// // building file list in the separate thread -struct -{ - wchar_t *oldName, *newName; -} -static renameTable[] = -{ - { L"svc_dbepp.dll", L"Plugins\\dbeditorpp.dll" }, - { L"svc_crshdmp.dll", L"Plugins\\crashdumper.dll" }, - { L"crashdmp.dll", L"Plugins\\crashdumper.dll" }, - { L"crashrpt.dll", L"Plugins\\crashdumper.dll" }, - { L"attache.dll", L"Plugins\\crashdumper.dll" }, - { L"svc_vi.dll", L"Plugins\\crashdumper.dll" }, - { L"crashrpt.dll", L"Plugins\\crashdumper.dll" }, - { L"versioninfo.dll", L"Plugins\\crashdumper.dll" }, - { L"advsplashscreen.dll", L"Plugins\\splashscreen.dll" }, - { L"import_sa.dll", L"Plugins\\import.dll" }, - { L"newnr.dll", L"Plugins\\notesreminders.dll" }, - { L"dbtool.exe", nullptr }, - { L"dbtool_sa.exe", nullptr }, - { L"dbchecker.bat", nullptr }, - { L"fixme.cmd", nullptr }, - { L"mdbx_chk.exe", nullptr }, - { L"mdbx_dump.exe", nullptr }, - { L"mdbx_load.exe", nullptr }, - { L"clist_mw.dll", L"Plugins\\clist_nicer.dll" }, - { L"bclist.dll", L"Plugins\\clist_blind.dll" }, - { L"otr.dll", L"Plugins\\mirotr.dll" }, - { L"ttnotify.dll", L"Plugins\\tooltipnotify.dll" }, - { L"newstatusnotify.dll", L"Plugins\\newxstatusnotify.dll" }, - { L"rss.dll", L"Plugins\\newsaggregator.dll" }, - { L"dbx_3x.dll", L"Plugins\\dbx_mmap.dll" }, - { L"actman30.dll", L"Plugins\\actman.dll" }, - { L"skype.dll", L"Plugins\\skypeweb.dll" }, - { L"skypeclassic.dll", L"Plugins\\skypeweb.dll" }, - { L"historysweeper.dll", L"Plugins\\historysweeperlight.dll" }, - { L"advancedautoaway.dll", L"Plugins\\statusmanager.dll" }, - { L"keepstatus.dll", L"Plugins\\statusmanager.dll" }, - { L"startupstatus.dll", L"Plugins\\statusmanager.dll" }, - { L"dropbox.dll", L"Plugins\\cloudfile.dll" }, - { L"popup.dll", L"Plugins\\popupplus.dll" }, - { L"libaxolotl.mir", L"Libs\\libsignal.mir" }, - - { L"dbx_mmap_sa.dll", L"Plugins\\dbx_mmap.dll" }, - { L"dbx_tree.dll", L"Plugins\\dbx_mmap.dll" }, - { L"rc4.dll", nullptr }, - { L"athena.dll", nullptr }, - { L"skypekit.exe", nullptr }, - { L"mir_app.dll", nullptr }, - { L"mir_core.dll", nullptr }, - { L"zlib.dll", nullptr }, - - { L"quotes.dll", L"Plugins\\currencyrates.dll" }, - { L"proto_quotes.dll", L"Icons\\proto_currencyrates.dll" }, - - { L"proto_newsaggr.dll", L"Icons\\proto_newsaggregator.dll" }, - { L"clienticons_*.dll", L"Icons\\fp_icons.dll" }, - { L"fp_*.dll", L"Icons\\fp_icons.dll" }, - { L"xstatus_icq.dll", nullptr }, - - { L"langpack_*.txt", L"Languages\\*" }, - - { L"pcre16.dll", nullptr }, - { L"clist_classic.dll", nullptr }, - { L"chat.dll", nullptr }, - { L"srmm.dll", nullptr }, - { L"stdchat.dll", nullptr }, - { L"stdurl.dll", nullptr }, - { L"stdidle.dll", nullptr }, - { L"stdfile.dll", nullptr }, - { L"stdhelp.dll", nullptr }, - { L"stdauth.dll", nullptr }, - { L"stdssl.dll", nullptr }, - - { L"advaimg.dll", nullptr }, - { L"aim.dll", nullptr }, - { L"extraicons.dll", nullptr }, - { L"firstrun.dll", nullptr }, - { L"flashavatars.dll", nullptr }, - { L"gender.dll", nullptr }, - { L"gtalkext.dll", nullptr }, - { L"icq.dll", nullptr }, - { L"importtxt.dll", nullptr }, - { L"langman.dll", nullptr }, - { L"libcrypto-1_1.mir", nullptr }, - { L"libssl-1_1.mir", nullptr }, - { L"libtox.dll", nullptr }, - { L"lua53.dll", nullptr }, - { L"metacontacts.dll", nullptr }, - { L"mra.dll", nullptr }, - { L"modernopt.dll", nullptr }, - { L"msn.dll", nullptr }, - { L"msvcp100.dll", nullptr }, - { L"msvcr100.dll", nullptr }, - { L"mtextcontrol.dll", nullptr }, - { L"omegle.dll", nullptr }, - { L"openssl.dll", nullptr }, - { L"rate.dll", nullptr }, - { L"skypestatuschange.dll", nullptr }, - { L"skypeweb.dll", nullptr }, - { L"spamotron.dll", nullptr }, - { L"sms.dll", nullptr }, - { L"tlen.dll", nullptr }, - { L"xfire.dll", nullptr }, - { L"yahoo.dll", nullptr }, - { L"yahoogroups.dll", nullptr }, - { L"yapp.dll", nullptr }, - { L"WART-*.exe", nullptr }, -}; +RENAMETABLE g_arRename(50); // Checks if file needs to be renamed and copies it in pNewName // Returns true if smth. was copied @@ -582,13 +475,13 @@ static bool CheckFileRename(const wchar_t *pwszFolder, const wchar_t *pwszOldNam MFilePath fullOldPath; fullOldPath.Format(L"%s\\%s", pwszFolder, pwszOldName); - for (auto &it : renameTable) { - if (wildcmpiw(pwszOldName, it.oldName)) { - if (it.newName == nullptr) + for (auto &it : g_arRename) { + if (wildcmpiw(pwszOldName, it->wszSearch)) { + if (it->wszReplace == nullptr) *pNewName = 0; else { - wcsncpy_s(pNewName, MAX_PATH, it.newName, _TRUNCATE); - size_t cbLen = wcslen(it.newName) - 1; + wcsncpy_s(pNewName, MAX_PATH, it->wszReplace, _TRUNCATE); + size_t cbLen = wcslen(it->wszReplace) - 1; if (pNewName[cbLen] == '*') wcsncpy_s(pNewName + cbLen, MAX_PATH - cbLen, pwszOldName, _TRUNCATE); @@ -789,7 +682,7 @@ static void CheckUpdates(void *) ptrW updateUrl(GetDefaultUrl()), baseUrl; SERVLIST hashes(50, CompareHashes); - bool success = ParseHashes(updateUrl, baseUrl, hashes); + bool success = ParseHashes(updateUrl, baseUrl, hashes, &g_arRename); if (success) { if (hashes.getCount()) { FILELIST *UpdateFiles = new FILELIST(20); diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index 5fbf66192d..ecab59c7a0 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -29,7 +29,7 @@ int CompareHashes(const ServListEntry *p1, const ServListEntry *p2) return _wcsicmp(p1->m_name, p2->m_name); } -bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes) +bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes, RENAMETABLE *arRename) { REPLACEVARSARRAY vars[2]; vars[0].key.w = L"platform"; @@ -42,6 +42,9 @@ bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes) baseUrl = Utils_ReplaceVarsW(pwszUrl, 0, vars); + if (arRename) + arRename->destroy(); + // Download version info FILEURL pFileUrl; mir_snwprintf(pFileUrl.wszDownloadURL, L"%s/hashes.zip", baseUrl.get()); @@ -113,6 +116,21 @@ bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes) fclose(fp); DeleteFileW(wszTmpIni); + // building table of rules + mir_snwprintf(wszTmpIni, L"%s\\rules.txt", g_wszTempPath); + if (arRename) { + JSONNode root; + if (file2json(wszTmpIni, root)) + for (auto &it : root["rules"]) { + Utf2T wszName(it.name()); + if (it.isnull()) + arRename->insert(new RenameTableItem(wszName, nullptr)); + else + arRename->insert(new RenameTableItem(wszName, it.as_mstring())); + } + } + DeleteFileW(wszTmpIni); + if (bDoNotSwitchToStable) { g_plugin.setByte(DB_SETTING_DONT_SWITCH_TO_STABLE, 1); // Reset setting if needed diff --git a/plugins/PluginUpdater/src/stdafx.h b/plugins/PluginUpdater/src/stdafx.h index 7053769c59..ca76ba0763 100644 --- a/plugins/PluginUpdater/src/stdafx.h +++ b/plugins/PluginUpdater/src/stdafx.h @@ -30,17 +30,17 @@ Boston, MA 02111-1307, USA. // Miranda header files #include +#include #include -#include +#include +#include +#include +#include #include +#include #include -#include #include -#include -#include -#include -#include -#include +#include #include @@ -233,6 +233,20 @@ typedef OBJLIST SERVLIST; /////////////////////////////////////////////////////////////////////////////// +struct RenameTableItem +{ + RenameTableItem(const wchar_t *_1, const wchar_t *_2) : + wszSearch(mir_wstrdup(_1)), + wszReplace(mir_wstrdup(_2)) + {} + + ptrW wszSearch, wszReplace; +}; + +typedef OBJLIST RENAMETABLE; + +/////////////////////////////////////////////////////////////////////////////// + void InitPopupList(); void InitEvents(); @@ -249,7 +263,7 @@ void CALLBACK CheckUpdateOnStartup(void); int BackupFile(wchar_t *pwszSrcFileName, wchar_t *pwszBackFileName); -bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes); +bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes, RENAMETABLE *arRename = nullptr); int CompareHashes(const ServListEntry *p1, const ServListEntry *p2); wchar_t* GetDefaultUrl(); -- cgit v1.2.3