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