1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006, 2008, 2013-2014 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "..\version.h"
24 #pragma comment(lib, "Version.lib")
36 HINSTANCE
CLangDll::Init(LPCTSTR appname
, unsigned long langID
)
38 TCHAR langpath
[MAX_PATH
] = {0};
39 TCHAR langdllpath
[MAX_PATH
] = {0};
40 TCHAR sVer
[MAX_PATH
] = {0};
41 _tcscpy_s(sVer
, MAX_PATH
, _T(STRPRODUCTVER
));
42 GetModuleFileName(NULL
, langpath
, MAX_PATH
);
43 TCHAR
* pSlash
= _tcsrchr(langpath
, '\\');
47 pSlash
= _tcsrchr(langpath
, '\\');
51 _tcscat_s(langpath
, MAX_PATH
, _T("\\Languages\\"));
52 assert(m_hInstance
== NULL
);
55 _stprintf_s(langdllpath
, MAX_PATH
, _T("%s%s%lu.dll"), langpath
, appname
, langID
);
57 m_hInstance
= LoadLibrary(langdllpath
);
59 if (!DoVersionStringsMatch(sVer
, langdllpath
))
61 FreeLibrary(m_hInstance
);
64 if (m_hInstance
== NULL
)
66 DWORD lid
= SUBLANGID(langID
);
70 langID
= MAKELANGID(PRIMARYLANGID(langID
), lid
);
75 } while ((m_hInstance
== NULL
) && (langID
!= 0));
81 void CLangDll::Close()
85 FreeLibrary(m_hInstance
);
90 bool CLangDll::DoVersionStringsMatch(LPCTSTR sVer
, LPCTSTR langDll
) const
100 DWORD dwBufferSize
= GetFileVersionInfoSize((LPTSTR
)langDll
,&dwReserved
);
102 if (dwBufferSize
> 0)
104 LPVOID pBuffer
= (void*) malloc(dwBufferSize
);
106 if (pBuffer
!= (void*) NULL
)
110 LPSTR lpVersion
= NULL
;
111 VOID
* lpFixedPointer
;
112 TRANSARRAY
* lpTransArray
;
113 TCHAR strLangProductVersion
[MAX_PATH
] = {0};
115 GetFileVersionInfo((LPTSTR
)langDll
,
120 VerQueryValue( pBuffer
,
121 _T("\\VarFileInfo\\Translation"),
124 lpTransArray
= (TRANSARRAY
*) lpFixedPointer
;
126 _stprintf_s(strLangProductVersion
, MAX_PATH
,
127 _T("\\StringFileInfo\\%04x%04x\\ProductVersion"),
128 lpTransArray
[0].wLanguageID
,
129 lpTransArray
[0].wCharacterSet
);
131 VerQueryValue(pBuffer
,
132 (LPTSTR
)strLangProductVersion
,
133 (LPVOID
*)&lpVersion
,
135 if (lpVersion
&& nInfoSize
)
136 bReturn
= (_tcscmp(sVer
, (LPCTSTR
)lpVersion
)==0);