summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-11-08 21:16:37 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-11-08 21:16:43 +0300
commit580cd5b276abd96032f64eb472b3bee592471ab8 (patch)
treee6395f34b14ef8bb67e9dd514285c71e3f35e05d
parent86c456502ff42f8f3a56e04a95ce97ea70ab0ea8 (diff)
fixes #3882 (tabSRMM: пропал перевод у пункта меню "Закрыть вкладку")
-rw-r--r--include/m_langpack.h2
-rw-r--r--libs/win32/mir_core.libbin494254 -> 493994 bytes
-rw-r--r--libs/win64/mir_core.libbin499484 -> 499242 bytes
-rw-r--r--src/mir_app/src/modules.cpp2
-rw-r--r--src/mir_core/src/Windows/langpack.cpp130
-rw-r--r--src/mir_core/src/mir_core.def1
-rw-r--r--src/mir_core/src/mir_core64.def1
-rw-r--r--src/mir_core/src/stdafx.h2
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
--- a/libs/win32/mir_core.lib
+++ b/libs/win32/mir_core.lib
Binary files differ
diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib
index 6845ee9eda..7b77de4141 100644
--- a/libs/win64/mir_core.lib
+++ b/libs/win64/mir_core.lib
Binary files 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<uint32_t, LangPackEntry *> 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 <io.h>
#include <direct.h>
+ #include <map>
+
#ifdef _DEBUG
#include <crtdbg.h>
#endif