summaryrefslogtreecommitdiff
path: root/src/modules/langpack/langpack.cpp
blob: f6110cbbdf38b3f368748f0172a08841c522d293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*

Miranda NG: the free IM client for Microsoft* Windows*

Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org),
Copyright (c) 2000-12 Miranda IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "..\..\core\commonheaders.h"
#include "langpack.h"

MIR_CORE_DLL(int) LoadLangPackDescr(const TCHAR *szLangPack, LANGPACK_INFO *lpInfo);

BOOL EnumLangpacks(ENUM_PACKS_CALLBACK callback, WPARAM wParam, LPARAM lParam)
{
	if (callback == NULL) return FALSE;

	BOOL res = FALSE;

	/* language folder */
	ptrT langpack(db_get_tsa(NULL, "Langpack", "Current"));
	
	TCHAR tszFullPath[MAX_PATH];
	PathToAbsoluteT(_T("\\Languages\\langpack_*.txt"), tszFullPath);

	BOOL fPackFound = FALSE;
	WIN32_FIND_DATA wfd;
	HANDLE hFind = FindFirstFile(tszFullPath, &wfd);
	if (hFind != INVALID_HANDLE_VALUE) {
		do {
			if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
			/* get data */
			PathToAbsoluteT(_T("\\Languages\\"), tszFullPath);
			mir_tstrcat(tszFullPath, wfd.cFileName);

			LANGPACK_INFO pack;
			if (!LoadLangPackDescr(tszFullPath, &pack)) {
				pack.ftFileDate = wfd.ftLastWriteTime;
				/* enabled? */
				if (langpack && !lstrcmpi(langpack, wfd.cFileName)) {
					if (!fPackFound) pack.flags |= LPF_ENABLED;
					fPackFound = TRUE;
				}
				/* callback */
				res = callback(&pack, wParam, lParam);
				if (!res) { FindClose(hFind); return FALSE; }
			}
		} while (FindNextFile(hFind, &wfd));
		FindClose(hFind);
	}

	/* default langpack: English */
	if (callback != NULL) {
		LANGPACK_INFO pack;
		pack.Locale = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
		mir_tstrcpy(pack.tszLanguage, _T("English"));
		pack.szAuthors = "Miranda NG Development Team";
		pack.szAuthorEmail = "project-info@miranda-ng.org";
		DWORD v = CallService(MS_SYSTEM_GETVERSION, 0, 0);
		pack.szLastModifiedUsing.Format("%d.%d.%d", ((v >> 24) & 0xFF), ((v >> 16) & 0xFF), ((v >> 8) & 0xFF));
		/* file date */
		if (GetModuleFileName(NULL, pack.tszFullPath, SIZEOF(pack.tszFullPath))) {
			mir_tstrcpy(pack.tszFileName, _T("default"));
			HANDLE hFile = CreateFile(pack.tszFileName, 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_DEFAULT;
		
		if (!fPackFound) pack.flags |= LPF_ENABLED;
		/* callback */
		if (!callback(&pack, wParam, lParam)) return FALSE;
	}

	return fPackFound;
}