From 06e87a6376180f34cf8a4cef89e98a4940ad9d08 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 3 Nov 2023 16:38:27 +0300 Subject: =?UTF-8?q?fixes=20#3777=20(Langpack:=20=D0=B5=D1=81=D0=BB=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=BA=D0=B8=20=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81?= =?UTF-8?q?=D1=82=D0=B2=D1=83=D0=B5=D1=82=20=D0=B2=20=D1=82=D0=B5=D0=BA?= =?UTF-8?q?=D1=83=D1=89=D0=B5=D0=BC=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B5?= =?UTF-8?q?,=20=D0=BD=D0=B5=20=D0=B8=D1=81=D0=BA=D0=B0=D1=82=D1=8C=20?= =?UTF-8?q?=D0=B5=D0=B3=D0=BE=20=D0=B2=20=D0=B4=D1=80=D1=83=D0=B3=D0=B8?= =?UTF-8?q?=D1=85=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=D1=85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mir_core/src/Windows/langpack.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/mir_core/src/Windows/langpack.cpp b/src/mir_core/src/Windows/langpack.cpp index 010b1311ca..a71d3dabb2 100644 --- a/src/mir_core/src/Windows/langpack.cpp +++ b/src/mir_core/src/Windows/langpack.cpp @@ -28,6 +28,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define LANGPACK_BUF_SIZE 4000 +static MUUID emptyMuid = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } }; + static int CompareMuuids(const MUUID *p1, const MUUID *p2) { return memcmp(p1, p2, sizeof(MUUID)); @@ -47,6 +49,20 @@ struct LangPackEntry wchar_t *wszLocal; MUUID *pMuuid; LangPackEntry* pNext; // for langpack items with the same hash value + + LangPackEntry* findNearest(const MUUID *pUuid) + { + if (pUuid) + for (auto *p = this; p != nullptr; p = p->pNext) + if (p->pMuuid && *p->pMuuid == *pUuid) + return p; + + for (auto *p = this; p != nullptr; p = p->pNext) + if (p->pMuuid == nullptr) + return p; + + return nullptr; + } }; static LANGPACK_INFO langPack; @@ -149,7 +165,11 @@ static const MUUID* GetMuid(HPLUGIN pPlugin) return nullptr; __try { - return &pPlugin->getInfo().uuid; + auto &pMuuid = pPlugin->getInfo().uuid; + if (pMuuid == emptyMuid) + return nullptr; + + return &pMuuid; } __except (EXCEPTION_EXECUTE_HANDLER) { @@ -486,15 +506,9 @@ char* LangPackTranslateString(const MUUID *pUuid, const char *szEnglish, const i if (entry == nullptr) return (char*)szEnglish; - // try to find the exact match, otherwise the first entry will be returned - if (pUuid) { - for (LangPackEntry *p = entry->pNext; p != nullptr; p = p->pNext) { - if (p->pMuuid && *p->pMuuid == *pUuid) { - entry = p; - break; - } - } - } + entry = entry->findNearest(pUuid); + if (entry == nullptr) + return (char *)szEnglish; switch (W) { case 0: -- cgit v1.2.3