1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016 - TortoiseGit
4 // Copyright (C) 2003-2006, 2008, 2013-2015 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "..\version.h"
26 #pragma comment(lib, "Version.lib")
29 : m_hInstance(nullptr)
37 HINSTANCE
CLangDll::Init(LPCTSTR appname
, unsigned long langID
)
39 TCHAR langpath
[MAX_PATH
] = {0};
40 TCHAR langdllpath
[MAX_PATH
] = {0};
41 TCHAR sVer
[MAX_PATH
] = {0};
42 wcscpy_s(sVer
, _T(STRPRODUCTVER
));
43 GetModuleFileName(nullptr, langpath
, _countof(langpath
));
44 TCHAR
* pSlash
= wcsrchr(langpath
, L
'\\');
49 pSlash
= wcsrchr(langpath
, L
'\\');
54 wcscat_s(langpath
, L
"\\Languages\\");
55 assert(m_hInstance
== nullptr);
58 swprintf_s(langdllpath
, L
"%s%s%lu.dll", langpath
, appname
, langID
);
60 m_hInstance
= LoadLibrary(langdllpath
);
62 if (!DoVersionStringsMatch(sVer
, langdllpath
))
64 FreeLibrary(m_hInstance
);
65 m_hInstance
= nullptr;
69 DWORD lid
= SUBLANGID(langID
);
72 langID
= MAKELANGID(PRIMARYLANGID(langID
), lid
);
76 } while (!m_hInstance
&& (langID
!= 0));
81 void CLangDll::Close()
86 FreeLibrary(m_hInstance
);
87 m_hInstance
= nullptr;
90 bool CLangDll::DoVersionStringsMatch(LPCTSTR sVer
, LPCTSTR langDll
) const
99 DWORD dwBufferSize
= GetFileVersionInfoSize((LPTSTR
)langDll
,&dwReserved
);
101 if (dwBufferSize
== 0)
104 auto pBuffer
= std::make_unique
<BYTE
[]>(dwBufferSize
);
109 UINT nInfoSize
= 0, nFixedLength
= 0;
110 LPSTR lpVersion
= nullptr;
111 VOID
* lpFixedPointer
;
112 TRANSARRAY
* lpTransArray
;
113 TCHAR strLangProductVersion
[MAX_PATH
] = { 0 };
115 if (!GetFileVersionInfo((LPTSTR
)langDll
, dwReserved
, dwBufferSize
, pBuffer
.get()))
118 VerQueryValue(pBuffer
.get(), L
"\\VarFileInfo\\Translation", &lpFixedPointer
, &nFixedLength
);
119 lpTransArray
= (TRANSARRAY
*)lpFixedPointer
;
121 swprintf_s(strLangProductVersion
, L
"\\StringFileInfo\\%04x%04x\\ProductVersion", lpTransArray
[0].wLanguageID
, lpTransArray
[0].wCharacterSet
);
123 VerQueryValue(pBuffer
.get(), (LPTSTR
)strLangProductVersion
, (LPVOID
*)&lpVersion
, &nInfoSize
);
124 if (lpVersion
&& nInfoSize
)
125 return (wcscmp(sVer
, (LPCTSTR
)lpVersion
) == 0);