CommitDlg: Update empty file list message
[TortoiseGit.git] / src / Utils / LangDll.cpp
blobeaad117cec6a71102e60eac780ca1921622cc375
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.
19 #include "stdafx.h"
20 #include <assert.h>
21 #include "LangDll.h"
22 #include "..\version.h"
24 #pragma comment(lib, "Version.lib")
26 CLangDll::CLangDll()
28 m_hInstance = NULL;
31 CLangDll::~CLangDll()
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, '\\');
44 if (pSlash)
46 *pSlash = 0;
47 pSlash = _tcsrchr(langpath, '\\');
48 if (pSlash)
50 *pSlash = 0;
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);
62 m_hInstance = NULL;
64 if (m_hInstance == NULL)
66 DWORD lid = SUBLANGID(langID);
67 lid--;
68 if (lid > 0)
70 langID = MAKELANGID(PRIMARYLANGID(langID), lid);
72 else
73 langID = 0;
75 } while ((m_hInstance == NULL) && (langID != 0));
78 return m_hInstance;
81 void CLangDll::Close()
83 if (m_hInstance)
85 FreeLibrary(m_hInstance);
86 m_hInstance = NULL;
90 bool CLangDll::DoVersionStringsMatch(LPCTSTR sVer, LPCTSTR langDll) const
92 struct TRANSARRAY
94 WORD wLanguageID;
95 WORD wCharacterSet;
98 bool bReturn = false;
99 DWORD dwReserved = 0;
100 DWORD dwBufferSize = GetFileVersionInfoSize((LPTSTR)langDll,&dwReserved);
102 if (dwBufferSize > 0)
104 LPVOID pBuffer = (void*) malloc(dwBufferSize);
106 if (pBuffer != (void*) NULL)
108 UINT nInfoSize = 0,
109 nFixedLength = 0;
110 LPSTR lpVersion = NULL;
111 VOID* lpFixedPointer;
112 TRANSARRAY* lpTransArray;
113 TCHAR strLangProductVersion[MAX_PATH] = {0};
115 GetFileVersionInfo((LPTSTR)langDll,
116 dwReserved,
117 dwBufferSize,
118 pBuffer);
120 VerQueryValue( pBuffer,
121 _T("\\VarFileInfo\\Translation"),
122 &lpFixedPointer,
123 &nFixedLength);
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,
134 &nInfoSize);
135 if (lpVersion && nInfoSize)
136 bReturn = (_tcscmp(sVer, (LPCTSTR)lpVersion)==0);
137 free(pBuffer);
141 return bReturn;