From 580cd5b276abd96032f64eb472b3bee592471ab8 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 8 Nov 2023 21:16:37 +0300 Subject: =?UTF-8?q?fixes=20#3882=20(tabSRMM:=20=D0=BF=D1=80=D0=BE=D0=BF?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=20?= =?UTF-8?q?=D1=83=20=D0=BF=D1=83=D0=BD=D0=BA=D1=82=D0=B0=20=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=8E=20"=D0=97=D0=B0=D0=BA=D1=80=D1=8B=D1=82=D1=8C=20?= =?UTF-8?q?=D0=B2=D0=BA=D0=BB=D0=B0=D0=B4=D0=BA=D1=83")?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/m_langpack.h | 2 - libs/win32/mir_core.lib | Bin 494254 -> 493994 bytes libs/win64/mir_core.lib | Bin 499484 -> 499242 bytes src/mir_app/src/modules.cpp | 2 - src/mir_core/src/Windows/langpack.cpp | 130 ++++++++-------------------------- src/mir_core/src/mir_core.def | 1 - src/mir_core/src/mir_core64.def | 1 - src/mir_core/src/stdafx.h | 2 + 8 files changed, 32 insertions(+), 106 deletions(-) diff --git a/include/m_langpack.h b/include/m_langpack.h index 0eb2a0a677..aff4601c43 100644 --- a/include/m_langpack.h +++ b/include/m_langpack.h @@ -39,8 +39,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define LANG_UNICODE 0x1000 -EXTERN_C MIR_CORE_DLL(void) Langpack_SortDuplicates(void); - EXTERN_C MIR_CORE_DLL(int) LoadLangPackModule(void); EXTERN_C MIR_CORE_DLL(int) LoadLangPack(const wchar_t *szLangPack); EXTERN_C MIR_CORE_DLL(void) ReloadLangpack(wchar_t *pszStr); diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib index 15c5ec2121..2cb9ff7b28 100644 Binary files a/libs/win32/mir_core.lib and b/libs/win32/mir_core.lib differ diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib index 6845ee9eda..7b77de4141 100644 Binary files a/libs/win64/mir_core.lib and b/libs/win64/mir_core.lib differ diff --git a/src/mir_app/src/modules.cpp b/src/mir_app/src/modules.cpp index d1bbdedf90..199188a835 100644 --- a/src/mir_app/src/modules.cpp +++ b/src/mir_app/src/modules.cpp @@ -139,8 +139,6 @@ int LoadDefaultModules(void) if (LoadHelpModule()) return 1; if (LoadStdPlugins()) return 1; - Langpack_SortDuplicates(); - if (LoadAccountsModule()) return 1; // order becomes less important below here diff --git a/src/mir_core/src/Windows/langpack.cpp b/src/mir_core/src/Windows/langpack.cpp index 912e8feb7c..0e8ab01532 100644 --- a/src/mir_core/src/Windows/langpack.cpp +++ b/src/mir_core/src/Windows/langpack.cpp @@ -41,15 +41,22 @@ static HANDLE hevChanged = nullptr; static BOOL bModuleInitialized = FALSE; -struct LangPackEntry +struct LangPackEntry : public MZeroedObject { - uint32_t englishHash; char *szLocal; char *utfLocal; wchar_t *wszLocal; MUUID *pMuuid; LangPackEntry* pNext; // for langpack items with the same hash value + ~LangPackEntry() + { + mir_free(szLocal); + mir_free(utfLocal); + mir_free(wszLocal); + delete pNext; + } + LangPackEntry* findNearest(const MUUID *pUuid) { if (pUuid) @@ -68,8 +75,7 @@ struct LangPackEntry static LANGPACK_INFO langPack; static wchar_t g_tszRoot[MAX_PATH]; -static LangPackEntry *g_pEntries; -static int g_entryCount, g_entriesAlloced; +static std::map g_entries; static int IsEmpty(const char *str) { @@ -177,14 +183,6 @@ static const MUUID* GetMuid(HPLUGIN pPlugin) } } -static int SortLangPackHashesProc(LangPackEntry *arg1, LangPackEntry *arg2) -{ - if (arg1->englishHash < arg2->englishHash) return -1; - if (arg1->englishHash > arg2->englishHash) return 1; - - return (arg1->pMuuid < arg2->pMuuid) ? -1 : 1; -} - static void swapBytes(void *p, size_t iSize) { char *head = (char*)p; // here @@ -287,34 +285,28 @@ static void LoadLangPackFile(FILE *fp, char *line) } char cFirst = line[0]; + uint32_t hash; ConvertBackslashes(line, CP_UTF8); size_t cbLen = strlen(line) - 1; if (cFirst == '[' && line[cbLen] == ']') { - if (g_entryCount && g_pEntries[g_entryCount-1].wszLocal == nullptr) - g_entryCount--; - char *pszLine = line + 1; line[cbLen] = '\0'; - if (++g_entryCount > g_entriesAlloced) { - g_entriesAlloced += 128; - g_pEntries = (LangPackEntry*)mir_realloc(g_pEntries, sizeof(LangPackEntry)*g_entriesAlloced); - } - LangPackEntry *E = &g_pEntries[g_entryCount - 1]; - E->englishHash = mir_hashstr(pszLine); - E->szLocal = E->utfLocal = nullptr; - E->wszLocal = nullptr; - E->pMuuid = pCurrentMuuid; - E->pNext = nullptr; + hash = mir_hashstr(pszLine); continue; } - if (!g_entryCount) - continue; + LangPackEntry *E = new LangPackEntry(); + E->pMuuid = pCurrentMuuid; + + auto p = g_entries.find(hash); + if (p == g_entries.end()) + g_entries[hash] = E; + else + (*p).second->pNext = E; - LangPackEntry *E = &g_pEntries[g_entryCount - 1]; int iNeeded = MultiByteToWideChar(CP_UTF8, 0, line, -1, nullptr, 0), iOldLen; if (E->wszLocal == nullptr) { iOldLen = 0; @@ -421,11 +413,11 @@ MIR_CORE_DLL(int) LoadLangPack(const wchar_t *ptszLangPack) wcsncpy_s(tszFullPath, ptszLangPack, _TRUNCATE); // this lang is already loaded? nothing to do then - if (!mir_wstrcmp(tszFullPath, langPack.tszFullPath)) + if (!mir_wstrcmpi(tszFullPath, langPack.tszFullPath)) return 0; // ok... loading a new langpack. remove the old one if needed - if (g_entryCount) + if (g_entries.size()) UnloadLangPackModule(); langPack.Locale = 0; @@ -460,8 +452,6 @@ MIR_CORE_DLL(int) LoadLangPack(const wchar_t *ptszLangPack) LoadLangPackFile(fp, line); fclose(fp); pCurrentMuuid = nullptr; - - qsort(g_pEntries, g_entryCount, sizeof(LangPackEntry), (int(*)(const void*, const void*))SortLangPackHashesProc); return 0; } @@ -488,25 +478,17 @@ MIR_CORE_DLL(int) LoadLangPackDescr(const wchar_t *ptszLangPack, LANGPACK_INFO * ///////////////////////////////////////////////////////////////////////////////////////// -static int SortLangPackHashesProc2(LangPackEntry *arg1, LangPackEntry *arg2) -{ - if (arg1->englishHash < arg2->englishHash) return -1; - if (arg1->englishHash > arg2->englishHash) return 1; - return 0; -} - char* LangPackTranslateString(const MUUID *pUuid, const char *szEnglish, const int W) { - if (g_entryCount == 0 || szEnglish == nullptr) + if (g_entries.size() == 0 || szEnglish == nullptr) return (char*)szEnglish; - LangPackEntry key, *entry; - key.englishHash = (W == 1) ? hashstrW(szEnglish) : mir_hashstr(szEnglish); - entry = (LangPackEntry*)bsearch(&key, g_pEntries, g_entryCount, sizeof(LangPackEntry), (int(*)(const void*, const void*))SortLangPackHashesProc2); - if (entry == nullptr) + uint32_t englishHash = (W == 1) ? hashstrW(szEnglish) : mir_hashstr(szEnglish); + auto p = g_entries.find(englishHash); + if (p == g_entries.end()) return (char*)szEnglish; - entry = entry->findNearest(pUuid); + auto *entry = (*p).second->findNearest(pUuid); if (entry == nullptr) return (char *)szEnglish; @@ -634,40 +616,6 @@ MIR_CORE_DLL(void) TranslateDialog_LP(HWND hDlg, HPLUGIN pPlugin) ///////////////////////////////////////////////////////////////////////////////////////// -MIR_CORE_DLL(void) Langpack_SortDuplicates(void) -{ - if (g_entryCount == 0) - return; - - LangPackEntry *s = g_pEntries + 1, *d = s, *pLast = g_pEntries; - uint32_t dwSavedHash = g_pEntries->englishHash; - bool bSortNeeded = false; - - for (int i = 1; i < g_entryCount; i++, s++) { - if (s->englishHash != dwSavedHash) { - pLast = d; - if (s != d) - *d++ = *s; - else - d++; - dwSavedHash = s->englishHash; - } - else { - bSortNeeded = true; - LangPackEntry *p = (LangPackEntry*)mir_alloc(sizeof(LangPackEntry)); - *p = *s; - pLast->pNext = p; pLast = p; - } - } - - if (bSortNeeded) { - g_entryCount = (int)(d - g_pEntries); - qsort(g_pEntries, g_entryCount, sizeof(LangPackEntry), (int(*)(const void*, const void*))SortLangPackHashesProc); - } -} - -///////////////////////////////////////////////////////////////////////////////////////// - void GetDefaultLang() { // calculate the langpacks' root @@ -729,7 +677,6 @@ MIR_CORE_DLL(void) ReloadLangpack(wchar_t *pszStr) UnloadLangPackModule(); LoadLangPack(pszStr); - Langpack_SortDuplicates(); NotifyEventHooks(hevChanged, 0, 0); } @@ -759,26 +706,9 @@ void UnloadLangPackModule() mir_free(it); lMuuids.destroy(); - LangPackEntry *p = g_pEntries; - for (int i = 0; i < g_entryCount; i++, p++) { - if (p->pNext != nullptr) { - for (LangPackEntry *p1 = p->pNext; p1 != nullptr;) { - LangPackEntry *p2 = p1; p1 = p1->pNext; - mir_free(p2->szLocal); - mir_free(p2->wszLocal); - mir_free(p2); - } - } - - mir_free(p->szLocal); - mir_free(p->wszLocal); - } - - if (g_entryCount) { - mir_free(g_pEntries); - g_pEntries = nullptr; - g_entryCount = g_entriesAlloced = 0; - } + for (auto &it : g_entries) + delete it.second; + g_entries.clear(); langPack.tszFileName[0] = langPack.tszFullPath[0] = 0; } diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index d243278ac2..3b80e61e94 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -33,7 +33,6 @@ KillModuleServices @29 KillObjectEventHooks @30 KillObjectServices @31 KillObjectThreads @32 -Langpack_SortDuplicates @33 Langpack_GetDefaultCodePage @34 Langpack_GetDefaultLocale @35 Langpack_PcharToTchar @36 diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index efa7ecff00..837f49d092 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -33,7 +33,6 @@ KillModuleServices @29 KillObjectEventHooks @30 KillObjectServices @31 KillObjectThreads @32 -Langpack_SortDuplicates @33 Langpack_GetDefaultCodePage @34 Langpack_GetDefaultLocale @35 Langpack_PcharToTchar @36 diff --git a/src/mir_core/src/stdafx.h b/src/mir_core/src/stdafx.h index dd6d93d679..fb6e5e14c9 100644 --- a/src/mir_core/src/stdafx.h +++ b/src/mir_core/src/stdafx.h @@ -43,6 +43,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include + #include + #ifdef _DEBUG #include #endif -- cgit v1.2.3