OSDN Git Service

Add swtich fetch branch tag command at ContextMenu.cpp
[tortoisegit/TortoiseGitJp.git] / src / Utils / LangDll.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2006,2008 - TortoiseSVN\r
4 \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
9 \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
14 \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
18 //\r
19 #include "stdafx.h"\r
20 #include <assert.h>\r
21 #include "LangDll.h"\r
22 #include "..\version.h"\r
23 \r
24 #pragma comment(lib, "Version.lib")\r
25 \r
26 CLangDll::CLangDll()\r
27 {\r
28         m_hInstance = NULL;\r
29 }\r
30 \r
31 CLangDll::~CLangDll()\r
32 {\r
33 \r
34 }\r
35 \r
36 HINSTANCE CLangDll::Init(LPCTSTR appname, unsigned long langID)\r
37 {\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
44         if (pSlash)\r
45         {\r
46                 *pSlash = 0;\r
47                 pSlash = _tcsrchr(langpath, '\\');\r
48                 if (pSlash)\r
49                 {\r
50                         *pSlash = 0;\r
51                         _tcscat_s(langpath, MAX_PATH, _T("\\Languages\\"));\r
52                         assert(m_hInstance == NULL);\r
53                         do\r
54                         {\r
55                                 _stprintf_s(langdllpath, MAX_PATH, _T("%s%s%d.dll"), langpath, appname, langID);\r
56 \r
57                                 m_hInstance = LoadLibrary(langdllpath);\r
58 \r
59                                 if (!DoVersionStringsMatch(sVer, langdllpath))\r
60                                 {\r
61                                         FreeLibrary(m_hInstance);\r
62                                         m_hInstance = NULL;\r
63                                 }\r
64                                 if (m_hInstance == NULL)\r
65                                 {\r
66                                         DWORD lid = SUBLANGID(langID);\r
67                                         lid--;\r
68                                         if (lid > 0)\r
69                                         {\r
70                                                 langID = MAKELANGID(PRIMARYLANGID(langID), lid);\r
71                                         }\r
72                                         else\r
73                                                 langID = 0;\r
74                                 }\r
75                         } while ((m_hInstance == NULL) && (langID != 0));\r
76                 }\r
77         }\r
78         return m_hInstance;\r
79 }\r
80 \r
81 void CLangDll::Close()\r
82 {\r
83         if (m_hInstance)\r
84         {\r
85                 FreeLibrary(m_hInstance);\r
86                 m_hInstance = NULL;\r
87         }\r
88 }\r
89 \r
90 bool CLangDll::DoVersionStringsMatch(LPCTSTR sVer, LPCTSTR langDll)\r
91 {\r
92         struct TRANSARRAY\r
93         {\r
94                 WORD wLanguageID;\r
95                 WORD wCharacterSet;\r
96         };\r
97 \r
98         bool bReturn = false;\r
99         DWORD dwReserved,dwBufferSize;\r
100         dwBufferSize = GetFileVersionInfoSize((LPTSTR)langDll,&dwReserved);\r
101 \r
102         if (dwBufferSize > 0)\r
103         {\r
104                 LPVOID pBuffer = (void*) malloc(dwBufferSize);\r
105 \r
106                 if (pBuffer != (void*) NULL)\r
107                 {\r
108                         UINT        nInfoSize = 0,\r
109                                 nFixedLength = 0;\r
110                         LPSTR       lpVersion = NULL;\r
111                         VOID*       lpFixedPointer;\r
112                         TRANSARRAY* lpTransArray;\r
113                         TCHAR       strLangProduktVersion[MAX_PATH];\r
114 \r
115                         GetFileVersionInfo((LPTSTR)langDll,\r
116                                 dwReserved,\r
117                                 dwBufferSize,\r
118                                 pBuffer);\r
119 \r
120                         VerQueryValue(  pBuffer,\r
121                                 _T("\\VarFileInfo\\Translation"),\r
122                                 &lpFixedPointer,\r
123                                 &nFixedLength);\r
124                         lpTransArray = (TRANSARRAY*) lpFixedPointer;\r
125 \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
130 \r
131                         VerQueryValue(pBuffer,\r
132                                 (LPTSTR)strLangProduktVersion,\r
133                                 (LPVOID *)&lpVersion,\r
134                                 &nInfoSize);\r
135 \r
136                         bReturn = (_tcscmp(sVer, (LPCTSTR)lpVersion)==0);\r
137                         free(pBuffer);\r
138                 }\r
139         } \r
140 \r
141         return bReturn;\r
142 }\r
143 \r