summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/modules.cpp1
-rw-r--r--src/mir_core/db.cpp5
-rw-r--r--src/mir_core/langpack.cpp64
-rw-r--r--src/modules/database/profilemanager.cpp2
-rw-r--r--src/modules/langpack/langpack.cpp53
-rw-r--r--src/modules/langpack/langpack.h2
-rw-r--r--src/modules/langpack/lpopts.cpp4
-rw-r--r--src/modules/langpack/lpservices.cpp2
-rw-r--r--src/modules/plugins/newplugins.cpp2
9 files changed, 64 insertions, 71 deletions
diff --git a/src/core/modules.cpp b/src/core/modules.cpp
index d0fd58359e..cea9906330 100644
--- a/src/core/modules.cpp
+++ b/src/core/modules.cpp
@@ -118,7 +118,6 @@ int LoadDefaultModules(void)
if (LoadDatabaseModule()) return 1;
// database is available here
- Langpack_LoadLangpack();
if (LoadButtonModule()) return 1;
if (LoadIcoLibModule()) return 1;
if (LoadSkinIcons()) return 1;
diff --git a/src/mir_core/db.cpp b/src/mir_core/db.cpp
index f1aefcecce..e87c371898 100644
--- a/src/mir_core/db.cpp
+++ b/src/mir_core/db.cpp
@@ -354,6 +354,11 @@ MIR_CORE_DLL(MCONTACT) db_find_next(MCONTACT hContact, const char *szProto)
extern "C" MIR_CORE_DLL(void) db_setCurrent(MIDatabase *_db)
{
currDb = _db;
+
+ // try to get the langpack's name from a profile
+ ptrT langpack(db_get_tsa(NULL, "Langpack", "Current"));
+ if (langpack && langpack[0] != '\0')
+ LoadLangPack(langpack);
}
MIR_CORE_DLL(BOOL) db_set_resident(const char *szModule, const char *szService, BOOL bEnable)
diff --git a/src/mir_core/langpack.cpp b/src/mir_core/langpack.cpp
index 507eb06dc7..bebe9d6215 100644
--- a/src/mir_core/langpack.cpp
+++ b/src/mir_core/langpack.cpp
@@ -367,20 +367,39 @@ static int LoadLangDescr(LANGPACK_INFO &lpinfo, FILE *fp, char *line, int &start
return 0;
}
-MIR_CORE_DLL(int) LoadLangPack(const TCHAR *szLangPack)
+MIR_CORE_DLL(int) LoadLangPack(const TCHAR *ptszLangPack)
{
- if (!lstrcmp(szLangPack, langPack.tszFullPath))
+ if (ptszLangPack == NULL)
+ return 1;
+
+ // ensure that a lang's name is a full file name
+ TCHAR tszFullPath[MAX_PATH];
+ if (!PathIsAbsoluteT(ptszLangPack)) {
+ PathToAbsoluteT(_T("\\Languages\\"), tszFullPath);
+ _tcsncat_s(tszFullPath, SIZEOF(tszFullPath), ptszLangPack, _TRUNCATE);
+ }
+ else _tcsncpy_s(tszFullPath, SIZEOF(tszFullPath), ptszLangPack, _TRUNCATE);
+
+ // exists & not a directory?
+ DWORD dwAttrib = GetFileAttributes(tszFullPath);
+ if (dwAttrib == INVALID_FILE_ATTRIBUTES || (dwAttrib & FILE_ATTRIBUTE_DIRECTORY))
+ return 3;
+
+ // this lang is already loaded? nothing to do then
+ if (!lstrcmp(tszFullPath, langPack.tszFullPath))
return 0;
+ // ok... loading a new langpack. remove the old one if needed
if (g_entryCount)
UnloadLangPackModule();
- _tcsncpy_s(langPack.tszFullPath, SIZEOF(langPack.tszFullPath), szLangPack, _TRUNCATE);
+ // copy the full file name and extract a file name from it
+ _tcsncpy_s(langPack.tszFullPath, SIZEOF(langPack.tszFullPath), tszFullPath, _TRUNCATE);
TCHAR *p = _tcsrchr(langPack.tszFullPath, '\\');
- _tcsncpy_s(langPack.tszFileName, SIZEOF(langPack.tszFullPath), (p == NULL) ? szLangPack : p + 1, _TRUNCATE);
+ _tcsncpy_s(langPack.tszFileName, SIZEOF(langPack.tszFullPath), (p == NULL) ? tszFullPath : p + 1, _TRUNCATE);
CharLower(langPack.tszFileName);
- FILE *fp = _tfopen(szLangPack, _T("rt"));
+ FILE *fp = _tfopen(ptszLangPack, _T("rt"));
if (fp == NULL)
return 1;
@@ -403,17 +422,17 @@ MIR_CORE_DLL(int) LoadLangPack(const TCHAR *szLangPack)
return 0;
}
-MIR_CORE_DLL(int) LoadLangPackDescr(const TCHAR *szLangPack, LANGPACK_INFO *lpInfo)
+MIR_CORE_DLL(int) LoadLangPackDescr(const TCHAR *ptszLangPack, LANGPACK_INFO *lpInfo)
{
if (lpInfo == NULL)
return 1;
- _tcsncpy_s(lpInfo->tszFullPath, SIZEOF(lpInfo->tszFullPath), szLangPack, _TRUNCATE);
+ _tcsncpy_s(lpInfo->tszFullPath, SIZEOF(lpInfo->tszFullPath), ptszLangPack, _TRUNCATE);
TCHAR *p = _tcsrchr(lpInfo->tszFullPath, '\\');
- _tcsncpy_s(lpInfo->tszFileName, SIZEOF(lpInfo->tszFullPath), (p == NULL) ? szLangPack : p+1, _TRUNCATE);
+ _tcsncpy_s(lpInfo->tszFileName, SIZEOF(lpInfo->tszFullPath), (p == NULL) ? ptszLangPack : p+1, _TRUNCATE);
CharLower(lpInfo->tszFileName);
- FILE *fp = _tfopen(szLangPack, _T("rt"));
+ FILE *fp = _tfopen(ptszLangPack, _T("rt"));
if (fp == NULL)
return 1;
@@ -624,6 +643,33 @@ MIR_CORE_DLL(int) LoadLangPackModule(void)
ZeroMemory(&langPack, sizeof(langPack));
hevChanged = CreateHookableEvent(ME_LANGPACK_CHANGED);
+
+ // look into mirandaboot.ini
+ TCHAR tszDefaultLang[100], tszPath[MAX_PATH];
+ PathToAbsoluteT(_T("\\mirandaboot.ini"), tszPath);
+ if (GetPrivateProfileString(_T("Language"), _T("DefaultLanguage"), _T(""), tszDefaultLang, SIZEOF(tszDefaultLang), tszPath))
+ if (!LoadLangPack(tszDefaultLang))
+ return 0;
+
+ // finally try to load first file
+ PathToAbsoluteT(_T("\\Languages\\langpack_*.txt"), tszPath);
+
+ WIN32_FIND_DATA fd;
+ HANDLE hFind = FindFirstFile(tszPath, &fd);
+ if (hFind != INVALID_HANDLE_VALUE) {
+ do {
+ /* search first langpack that could be loaded */
+ if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ continue;
+
+ if (!LoadLangPack(fd.cFileName)) {
+ db_set_ws(NULL, "Langpack", "Current", fd.cFileName);
+ break;
+ }
+ }
+ while (FindNextFile(hFind, &fd));
+ FindClose(hFind);
+ }
return 0;
}
diff --git a/src/modules/database/profilemanager.cpp b/src/modules/database/profilemanager.cpp
index 30704d902d..ea5b7e1a3b 100644
--- a/src/modules/database/profilemanager.cpp
+++ b/src/modules/database/profilemanager.cpp
@@ -800,8 +800,6 @@ static int AddProfileManagerPage(struct DetailsPageInit *opi, OPTIONSDIALOGPAGE
int getProfileManager(PROFILEMANAGERDATA * pd)
{
- Langpack_LoadLangpack();
-
DetailsPageInit opi = { 0 };
OPTIONSDIALOGPAGE odp = { sizeof(odp) };
diff --git a/src/modules/langpack/langpack.cpp b/src/modules/langpack/langpack.cpp
index b0beb9c673..c378373e45 100644
--- a/src/modules/langpack/langpack.cpp
+++ b/src/modules/langpack/langpack.cpp
@@ -37,7 +37,7 @@ BOOL EnumLangpacks(ENUM_PACKS_CALLBACK callback, WPARAM wParam, LPARAM lParam)
ptrT langpack(db_get_tsa(NULL, "Langpack", "Current"));
LANGPACK_INFO pack;
- PathToAbsoluteT(_T("\\langpack_*.txt"), pack.tszFullPath);
+ PathToAbsoluteT(_T("\\Languages\\langpack_*.txt"), pack.tszFullPath);
BOOL fPackFound = FALSE;
WIN32_FIND_DATA wfd;
@@ -47,7 +47,7 @@ BOOL EnumLangpacks(ENUM_PACKS_CALLBACK callback, WPARAM wParam, LPARAM lParam)
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
/* get data */
TCHAR tszFullPath[MAX_PATH];
- PathToAbsoluteT(_T("\\"), tszFullPath);
+ PathToAbsoluteT(_T("\\Languages\\"), tszFullPath);
lstrcat(tszFullPath, wfd.cFileName);
ZeroMemory(&pack, sizeof(pack));
@@ -93,52 +93,3 @@ BOOL EnumLangpacks(ENUM_PACKS_CALLBACK callback, WPARAM wParam, LPARAM lParam)
return fPackFound;
}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-void Langpack_LoadLangpack(void)
-{
- TCHAR szSearch[MAX_PATH];
- PathToAbsoluteT(_T("\\"), szSearch);
-
- // try to get the langpack's name from a profile first
- ptrT langpack(db_get_tsa(NULL, "Langpack", "Current"));
- if (langpack && langpack[0] != '\0') {
- lstrcat(szSearch, langpack);
-
- DWORD dwAttrib = GetFileAttributes(szSearch);
- if (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY))
- if (!LoadLangPack(szSearch))
- return;
- }
-
- // look into mirandaboot.ini
- TCHAR tszDefaultLang[100];
- if (GetPrivateProfileString(_T("Language"), _T("DefaultLanguage"), _T(""), tszDefaultLang, SIZEOF(tszDefaultLang), mirandabootini)) {
- TCHAR tszLangPath[MAX_PATH];
- PathToAbsoluteT(tszDefaultLang, tszLangPath);
- if (!LoadLangPack(tszLangPath))
- return;
- }
-
- // finally try to load first file
- lstrcat(szSearch, _T("langpack_*.txt"));
-
- WIN32_FIND_DATA fd;
- HANDLE hFind = FindFirstFile(szSearch, &fd);
- if (hFind != INVALID_HANDLE_VALUE) {
- do {
- /* search first langpack that could be loaded */
- if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
- /* load langpack */
- PathToAbsoluteT(_T("\\"), szSearch);
- lstrcat(szSearch, fd.cFileName);
- if (!LoadLangPack(szSearch)) {
- db_set_ws(NULL, "Langpack", "Current", fd.cFileName);
- break;
- }
- }
- while (FindNextFile(hFind, &fd));
- FindClose(hFind);
- }
-}
diff --git a/src/modules/langpack/langpack.h b/src/modules/langpack/langpack.h
index 47f44de94d..9d6401c71e 100644
--- a/src/modules/langpack/langpack.h
+++ b/src/modules/langpack/langpack.h
@@ -59,5 +59,3 @@ typedef BOOL(*ENUM_PACKS_CALLBACK) (LANGPACK_INFO *pack, WPARAM wParam, LPARAM l
BOOL EnumLangpacks(ENUM_PACKS_CALLBACK callback, WPARAM wParam, LPARAM lParam);
int LangpackOptionsInit(WPARAM wParam, LPARAM);
-
-void Langpack_LoadLangpack(void);
diff --git a/src/modules/langpack/lpopts.cpp b/src/modules/langpack/lpopts.cpp
index f52254afff..376f74fcc9 100644
--- a/src/modules/langpack/lpopts.cpp
+++ b/src/modules/langpack/lpopts.cpp
@@ -152,7 +152,7 @@ INT_PTR CALLBACK DlgLangpackOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
int idx = ComboBox_GetCurSel(hwndList);
int count = ComboBox_GetCount(hwndList);
for (int i = 0; i < count; i++) {
- LANGPACK_INFO *pack = (LANGPACK_INFO*)ComboBox_GetItemData(hwndList, idx);
+ LANGPACK_INFO *pack = (LANGPACK_INFO*)ComboBox_GetItemData(hwndList, i);
if (i == idx) {
db_set_ws(NULL, "Langpack", "Current", pack->tszFileName);
lstrcpy(tszPath, pack->tszFullPath);
@@ -162,7 +162,7 @@ INT_PTR CALLBACK DlgLangpackOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
}
if (tszPath[0]) {
- CallService(MS_LANGPACK_RELOAD, 0, (LPARAM)tszPath);
+ ReloadLangpack(tszPath);
CloseWindow(GetParent(hwndDlg));
DestroyWindow(GetParent(hwndDlg));
}
diff --git a/src/modules/langpack/lpservices.cpp b/src/modules/langpack/lpservices.cpp
index c686200e91..472ba43541 100644
--- a/src/modules/langpack/lpservices.cpp
+++ b/src/modules/langpack/lpservices.cpp
@@ -97,8 +97,6 @@ static INT_PTR srvGetPluginLangpack(WPARAM wParam, LPARAM lParam)
/////////////////////////////////////////////////////////////////////////////////////////
-MIR_CORE_DLL(int)LoadLangPackModule(void);
-
int LoadLangpackModule(void)
{
LoadLangPackModule();
diff --git a/src/modules/plugins/newplugins.cpp b/src/modules/plugins/newplugins.cpp
index 5a3ea6a735..5576865477 100644
--- a/src/modules/plugins/newplugins.cpp
+++ b/src/modules/plugins/newplugins.cpp
@@ -653,8 +653,6 @@ static int LaunchServicePlugin(pluginEntry *p)
p->pclass |= PCLASS_LOADED;
}
- Langpack_LoadLangpack();
-
INT_PTR res = CallService(MS_SERVICEMODE_LAUNCH, 0, 0);
if (res != CALLSERVICE_NOTFOUND)
return res;