From 68f067fecf589ad0637229ce4a2e1185f140465a Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Fri, 14 Mar 2014 21:31:42 +0000 Subject: LangMan: - all langpacks stored in Languages folders - langpacks from root will be moved in Languages folders - added langpack changing at runtime - added langpack loading on miranda start git-svn-id: http://svn.miranda-ng.org/main/trunk@8607 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/LangMan/src/langpack.cpp | 177 +++++++++++++-------------------------- 1 file changed, 58 insertions(+), 119 deletions(-) (limited to 'plugins/LangMan/src/langpack.cpp') diff --git a/plugins/LangMan/src/langpack.cpp b/plugins/LangMan/src/langpack.cpp index 1fb31928de..cab1a6d116 100644 --- a/plugins/LangMan/src/langpack.cpp +++ b/plugins/LangMan/src/langpack.cpp @@ -128,8 +128,8 @@ static void CleanupLastModifiedUsing(char *szLastModifiedUsing, int nSize) if (p!=NULL) MoveMemory(p+1, p+2, lstrlenA(p+2)+1); /* default if empty */ if (!szLastModifiedUsing[0]) { - lstrcpynA(szLastModifiedUsing, MIRANDANAME" ", nSize); - CallService(MS_SYSTEM_GETVERSIONTEXT, nSize-lstrlenA(szLastModifiedUsing), (LPARAM)szLastModifiedUsing+lstrlenA(szLastModifiedUsing)); + DWORD v = CallService(MS_SYSTEM_GETVERSION, 0, 0); + mir_snprintf(szLastModifiedUsing, nSize, "%d.%d.%d.%d", ((v >> 24) & 0xFF), ((v >> 16) & 0xFF), ((v >> 8) & 0xFF), (v & 0xFF)); } } @@ -246,7 +246,7 @@ BOOL GetPackPath(TCHAR *pszPath, int nSize, BOOL fEnabledPacks, const TCHAR *psz /* subdirectory */ if (!fEnabledPacks) { if (nSize<(lstrlen(pszPath)+10)) return FALSE; - lstrcat(pszPath, _T("Plugins\\Language\\")); + lstrcat(pszPath, _T("Languages\\")); } /* file name */ if (pszFile!=NULL) { @@ -258,7 +258,7 @@ BOOL GetPackPath(TCHAR *pszPath, int nSize, BOOL fEnabledPacks, const TCHAR *psz // callback is allowed to be NULL // returns TRUE if any pack exists except default -BOOL EnumPacks(ENUM_PACKS_CALLBACK callback, const TCHAR *pszFilePattern, const char *pszFileVersionHeader, BOOL fEnglishDefault, WPARAM wParam, LPARAM lParam) +BOOL EnumPacks(ENUM_PACKS_CALLBACK callback, const TCHAR *pszFilePattern, const char *pszFileVersionHeader, WPARAM wParam, LPARAM lParam) { BOOL fPackFound = FALSE; BOOL res = FALSE; @@ -266,6 +266,8 @@ BOOL EnumPacks(ENUM_PACKS_CALLBACK callback, const TCHAR *pszFilePattern, const WIN32_FIND_DATA wfd; HANDLE hFind; + mir_ptr langpack(db_get_tsa(NULL, "LangMan", "Langpack")); + /* enabled packs */ if (GetPackPath(pack.szFileName, SIZEOF(pack.szFileName), TRUE, pszFilePattern)) { hFind = FindFirstFile(pack.szFileName, &wfd); @@ -279,8 +281,10 @@ BOOL EnumPacks(ENUM_PACKS_CALLBACK callback, const TCHAR *pszFilePattern, const if (LoadPackData(&pack, TRUE, pszFileVersionHeader)) { pack.ftFileDate = wfd.ftLastWriteTime; /* enabled? */ - if (!fPackFound) pack.flags |= LPF_ENABLED; - fPackFound = TRUE; + if (!langpack) { + if (!fPackFound) pack.flags |= LPF_ENABLED; + fPackFound = TRUE; + } /* callback */ if (callback!=NULL) res = callback(&pack, wParam, lParam); if (!res) { FindClose(hFind); return FALSE; } @@ -290,30 +294,6 @@ BOOL EnumPacks(ENUM_PACKS_CALLBACK callback, const TCHAR *pszFilePattern, const } } - /* default: English (GB) */ - if (fEnglishDefault && callback!=NULL) { - ZeroMemory(&pack, sizeof(pack)); - pack.Locale = LOCALE_USER_DEFAULT; /* miranda uses default locale in this case */ - lstrcpy(pack.szLanguage, _T("English (default)")); /* buffer safe */ - lstrcpyA(pack.szAuthors, "Miranda NG Development Team"); /* buffer safe */ - lstrcpyA(pack.szAuthorEmail, "project-info at miranda-ng.org"); /* buffer safe */ - CleanupEmail(pack.szAuthorEmail); /* correct " at " */ - CleanupLastModifiedUsing(pack.szLastModifiedUsing, sizeof(pack.szLastModifiedUsing)); - /* file date */ - if (GetModuleFileName(NULL, pack.szFileName, SIZEOF(pack.szFileName))) { - HANDLE hFile; - hFile = CreateFile(pack.szFileName, 0, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); - if (hFile!=INVALID_HANDLE_VALUE) { - GetFileTime(hFile, NULL, NULL, &pack.ftFileDate); - CloseHandle(hFile); - } - } - pack.flags = LPF_NOLOCALE|LPF_DEFAULT; - if (!fPackFound) pack.flags |= LPF_ENABLED; - /* callback */ - if (!callback(&pack, wParam, lParam)) return FALSE; - } - /* disabled packs */ if (GetPackPath(pack.szFileName, SIZEOF(pack.szFileName), FALSE, pszFilePattern)) { hFind = FindFirstFile(pack.szFileName, &wfd); @@ -326,7 +306,13 @@ BOOL EnumPacks(ENUM_PACKS_CALLBACK callback, const TCHAR *pszFilePattern, const lstrcpy(pack.szFileName, CharLower(wfd.cFileName)); /* buffer safe */ if (LoadPackData(&pack, FALSE, pszFileVersionHeader)) { pack.ftFileDate = wfd.ftLastWriteTime; - fPackFound = TRUE; + /* enabled? */ + if (langpack) { + if (!_tcscmp(pack.szFileName, langpack)) { + if (!fPackFound) pack.flags |= LPF_ENABLED; + fPackFound = TRUE; + } + } /* callback */ if (callback!=NULL) res = callback(&pack, wParam, lParam); if (!res) { FindClose(hFind); return FALSE; } @@ -335,65 +321,36 @@ BOOL EnumPacks(ENUM_PACKS_CALLBACK callback, const TCHAR *pszFilePattern, const FindClose(hFind); } } - return fPackFound; -} - -BOOL IsPluginIncluded(const LANGPACK_INFO *pack, char *pszFileBaseName) -{ - char *p; - if (!lstrcmpiA(pszFileBaseName, "png2dib") || !lstrcmpiA(pszFileBaseName, "loadavatars")) - return TRUE; /* workaround: does not need no translation */ - for(p = (char*)pack->szPluginsIncluded;;) { - p = strstr(p, CharLowerA(pszFileBaseName)); - if (p == NULL) return FALSE; - if (p == pack->szPluginsIncluded || *(p-1) == ' ' || *(p-1) == ',') { - p+=lstrlenA(pszFileBaseName)+1; - if (*p == ',' || *p == ' ' || *p == 0) return TRUE; - } - else p+=lstrlenA(pszFileBaseName)+1; - } -} - -/************************* Switch *************************************/ -BOOL EnablePack(const LANGPACK_INFO *pack, const TCHAR *pszFilePattern) -{ - TCHAR szFrom[MAX_PATH], szDest[MAX_PATH]; - HANDLE hFind; - WIN32_FIND_DATA wfd; - - /* disable previous pack */ - if (GetPackPath(szFrom, SIZEOF(szFrom), TRUE, pszFilePattern)) { - hFind = FindFirstFile(szFrom, &wfd); - if (hFind!=INVALID_HANDLE_VALUE) { - do { - if (wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) continue; - if (lstrlen(wfd.cFileName)<4 || wfd.cFileName[lstrlen(wfd.cFileName)-4]!=_T('.')) continue; - /* ensure dir exists */ - if (GetPackPath(szFrom, SIZEOF(szFrom), FALSE, NULL)) - CreateDirectory(szFrom, NULL); - /* move file */ - if (GetPackPath(szFrom, SIZEOF(szFrom), TRUE, wfd.cFileName)) - if (GetPackPath(szDest, SIZEOF(szDest), FALSE, wfd.cFileName)) - if (!MoveFile(szFrom, szDest) && GetLastError() == ERROR_ALREADY_EXISTS) { - DeleteFile(szDest); - MoveFile(szFrom, szDest); - } - break; - } while(FindNextFile(hFind, &wfd)); - FindClose(hFind); + /* default: English (GB) */ + if (callback!=NULL) { + ZeroMemory(&pack, sizeof(pack)); + pack.Locale = LOCALE_USER_DEFAULT; /* miranda uses default locale in this case */ + lstrcpy(pack.szLanguage, _T("English (default)")); /* buffer safe */ + lstrcpyA(pack.szAuthors, "Miranda NG Development Team"); /* buffer safe */ + lstrcpyA(pack.szAuthorEmail, "project-info at miranda-ng.org"); /* buffer safe */ + CleanupEmail(pack.szAuthorEmail); /* correct " at " */ + CleanupLastModifiedUsing(pack.szLastModifiedUsing, sizeof(pack.szLastModifiedUsing)); + /* file date */ + if (GetModuleFileName(NULL, pack.szFileName, SIZEOF(pack.szFileName))) { + HANDLE hFile; + hFile = CreateFile(pack.szFileName, 0, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + if (hFile!=INVALID_HANDLE_VALUE) { + GetFileTime(hFile, NULL, NULL, &pack.ftFileDate); + CloseHandle(hFile); + } } + pack.flags = LPF_NOLOCALE|LPF_DEFAULT; + pack.Locale = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT); + if (!fPackFound) pack.flags |= LPF_ENABLED; + /* callback */ + if (!callback(&pack, wParam, lParam)) return FALSE; } - /* enable current pack */ - if (pack->flags&LPF_DEFAULT) return TRUE; - if (GetPackPath(szFrom, SIZEOF(szFrom), FALSE, pack->szFileName)) - if (GetPackPath(szDest, SIZEOF(szDest), TRUE, pack->szFileName)) - return MoveFile(szFrom, szDest); - return FALSE; + return fPackFound; } -void CorrectPacks(const TCHAR *pszFilePattern, BOOL fDisableAll) +void MovePacks(const TCHAR *pszFilePattern) { TCHAR szFrom[MAX_PATH], szDest[MAX_PATH], szDir[MAX_PATH], *pszFile; BOOL fDirCreated = FALSE; @@ -403,52 +360,34 @@ void CorrectPacks(const TCHAR *pszFilePattern, BOOL fDisableAll) /* main path */ if (!GetModuleFileName(NULL, szDir, SIZEOF(szDir))) return; pszFile = _tcsrchr(szDir, _T('\\')); - if (pszFile!=NULL) *pszFile = _T('\0'); + if (pszFile != NULL) *pszFile = _T('\0'); - /* move wrongly placed packs from 'Plugins' to 'Language' */ - mir_sntprintf(szFrom, SIZEOF(szFrom), _T("%s\\Plugins\\%s"), szDir, pszFilePattern); + if (!GetPackPath(szDest, SIZEOF(szDest), FALSE, _T(""))) return; + + /* move wrongly placed packs from 'root' to 'Language' */ + mir_sntprintf(szFrom, SIZEOF(szFrom), _T("%s\\%s"), szDir, pszFilePattern); hFind = FindFirstFile(szFrom, &wfd); - if (hFind!=INVALID_HANDLE_VALUE) { + if (hFind != INVALID_HANDLE_VALUE) { do { if (wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) continue; - if (lstrlen(wfd.cFileName)<4 || wfd.cFileName[lstrlen(wfd.cFileName)-4]!=_T('.')) continue; + if (lstrlen(wfd.cFileName)<4 || wfd.cFileName[lstrlen(wfd.cFileName) - 4] != _T('.')) continue; + /* set first lp ad default */ + mir_ptr langpack(db_get_tsa(NULL, "LangMan", "Langpack")); + if (!langpack) + db_set_ws(NULL, "LangMan", "Langpack", wfd.cFileName); /* ensure dir exists */ - if (!fDirCreated && GetPackPath(szFrom, SIZEOF(szFrom), FALSE, NULL)) - fDirCreated = CreateDirectory(szFrom, NULL); + if (!fDirCreated) + fDirCreated = CreateDirectory(szDest, NULL); /* move file */ - if (GetPackPath(szDest, SIZEOF(szDest), FALSE, wfd.cFileName)) { - mir_sntprintf(szFrom, SIZEOF(szFrom), _T("%s\\Plugins\\%s"), szDir, wfd.cFileName); + if (GetPackPath(szDest, SIZEOF(szDest), FALSE, wfd.cFileName)) + { + mir_sntprintf(szFrom, SIZEOF(szFrom), _T("%s\\%s"), szDir, wfd.cFileName); if (!MoveFile(szFrom, szDest) && GetLastError() == ERROR_ALREADY_EXISTS) { DeleteFile(szDest); MoveFile(szFrom, szDest); } } - } while(FindNextFile(hFind, &wfd)); + } while (FindNextFile(hFind, &wfd)); FindClose(hFind); } - - /* disable all packs except one */ - if (GetPackPath(szFrom, SIZEOF(szFrom), TRUE, pszFilePattern)) { - hFind = FindFirstFile(szFrom, &wfd); - if (hFind!=INVALID_HANDLE_VALUE) { - do { - if (wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) continue; - if (lstrlen(wfd.cFileName)<4 || wfd.cFileName[lstrlen(wfd.cFileName)-4]!=_T('.')) continue; - /* skip first file */ - if (!fDisableAll) { fDisableAll = TRUE; continue; } - /* ensure dir exists */ - if (!fDirCreated && GetPackPath(szFrom, SIZEOF(szFrom), FALSE, NULL)) - fDirCreated = CreateDirectory(szFrom, NULL); - /* move file */ - if (GetPackPath(szFrom, SIZEOF(szFrom), TRUE, wfd.cFileName)) - if (GetPackPath(szDest, SIZEOF(szDest), FALSE, wfd.cFileName)) { - if (!MoveFile(szFrom, szDest) && GetLastError() == ERROR_ALREADY_EXISTS) { - DeleteFile(szDest); - MoveFile(szFrom, szDest); - } - } - } while(FindNextFile(hFind, &wfd)); - FindClose(hFind); - } - } } \ No newline at end of file -- cgit v1.2.3