diff options
author | George Hazan <george.hazan@gmail.com> | 2014-03-25 14:19:43 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-03-25 14:19:43 +0000 |
commit | 88f6179361e5b378c2938c77674d28cd1dc9a4ed (patch) | |
tree | 8ad248bd753a5e7643057a43c5a8bd78d3789017 /src/mir_core/langpack.cpp | |
parent | 86e8851bf37227b9f70f88e1788c7355422ee3b0 (diff) |
- language packs' directory is now %miranda_path%\Languages
- lang pack loading code restructurization
git-svn-id: http://svn.miranda-ng.org/main/trunk@8738 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/mir_core/langpack.cpp')
-rw-r--r-- | src/mir_core/langpack.cpp | 64 |
1 files changed, 55 insertions, 9 deletions
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;
}
|