1
1
// TortoiseGit - a Windows shell extension for easy version control
2
2
3
+ // Copyright (C) 2016 - TortoiseGit
3
4
// Copyright (C) 2003-2006, 2008, 2013-2015 - TortoiseSVN
4
5
5
6
// This program is free software; you can redistribute it and/or
@@ -42,50 +43,49 @@ HINSTANCE CLangDll::Init(LPCTSTR appname, unsigned long langID)
42
43
_tcscpy_s (sVer , MAX_PATH, _T (STRPRODUCTVER));
43
44
GetModuleFileName (NULL , langpath, MAX_PATH);
44
45
TCHAR * pSlash = _tcsrchr (langpath, ' \\ ' );
45
- if (pSlash)
46
+ if (!pSlash)
47
+ return m_hInstance;
48
+
49
+ *pSlash = 0 ;
50
+ pSlash = _tcsrchr (langpath, ' \\ ' );
51
+ if (!pSlash)
52
+ return m_hInstance;
53
+
54
+ *pSlash = 0 ;
55
+ _tcscat_s (langpath, MAX_PATH, _T (" \\ Languages\\ " ));
56
+ assert (m_hInstance == nullptr );
57
+ do
46
58
{
47
- *pSlash = 0 ;
48
- pSlash = _tcsrchr (langpath, ' \\ ' );
49
- if (pSlash)
59
+ _stprintf_s (langdllpath, MAX_PATH, _T (" %s%s%lu.dll" ), langpath, appname, langID);
60
+
61
+ m_hInstance = LoadLibrary (langdllpath);
62
+
63
+ if (!DoVersionStringsMatch (sVer , langdllpath))
50
64
{
51
- *pSlash = 0 ;
52
- _tcscat_s (langpath, MAX_PATH, _T (" \\ Languages\\ " ));
53
- assert (m_hInstance == NULL );
54
- do
55
- {
56
- _stprintf_s (langdllpath, MAX_PATH, _T (" %s%s%lu.dll" ), langpath, appname, langID);
57
-
58
- m_hInstance = LoadLibrary (langdllpath);
59
-
60
- if (!DoVersionStringsMatch (sVer , langdllpath))
61
- {
62
- FreeLibrary (m_hInstance);
63
- m_hInstance = NULL ;
64
- }
65
- if (m_hInstance == NULL )
66
- {
67
- DWORD lid = SUBLANGID (langID);
68
- lid--;
69
- if (lid > 0 )
70
- {
71
- langID = MAKELANGID (PRIMARYLANGID (langID), lid);
72
- }
73
- else
74
- langID = 0 ;
75
- }
76
- } while ((m_hInstance == NULL ) && (langID != 0 ));
65
+ FreeLibrary (m_hInstance);
66
+ m_hInstance = nullptr ;
77
67
}
78
- }
68
+ if (!m_hInstance)
69
+ {
70
+ DWORD lid = SUBLANGID (langID);
71
+ lid--;
72
+ if (lid > 0 )
73
+ langID = MAKELANGID (PRIMARYLANGID (langID), lid);
74
+ else
75
+ langID = 0 ;
76
+ }
77
+ } while (!m_hInstance && (langID != 0 ));
78
+
79
79
return m_hInstance;
80
80
}
81
81
82
82
void CLangDll::Close ()
83
83
{
84
- if (m_hInstance)
85
- {
86
- FreeLibrary (m_hInstance);
87
- m_hInstance = NULL ;
88
- }
84
+ if (! m_hInstance)
85
+ return ;
86
+
87
+ FreeLibrary ( m_hInstance) ;
88
+ m_hInstance = nullptr ;
89
89
}
90
90
91
91
bool CLangDll::DoVersionStringsMatch (LPCTSTR sVer , LPCTSTR langDll) const
@@ -96,48 +96,34 @@ bool CLangDll::DoVersionStringsMatch(LPCTSTR sVer, LPCTSTR langDll) const
96
96
WORD wCharacterSet;
97
97
};
98
98
99
- bool bReturn = false ;
100
99
DWORD dwReserved = 0 ;
101
100
DWORD dwBufferSize = GetFileVersionInfoSize ((LPTSTR)langDll,&dwReserved);
102
101
103
- if (dwBufferSize > 0 )
104
- {
105
- auto pBuffer = std::make_unique<BYTE[]>(dwBufferSize);
102
+ if (dwBufferSize <= 0 )
103
+ return false ;
106
104
107
- if (pBuffer)
108
- {
109
- UINT nInfoSize = 0 ,
110
- nFixedLength = 0 ;
111
- LPSTR lpVersion = NULL ;
112
- VOID* lpFixedPointer;
113
- TRANSARRAY* lpTransArray;
114
- TCHAR strLangProductVersion[MAX_PATH] = {0 };
115
-
116
- GetFileVersionInfo ((LPTSTR)langDll,
117
- dwReserved,
118
- dwBufferSize,
119
- pBuffer.get ());
120
-
121
- VerQueryValue (pBuffer.get (),
122
- _T (" \\ VarFileInfo\\ Translation" ),
123
- &lpFixedPointer,
124
- &nFixedLength);
125
- lpTransArray = (TRANSARRAY*) lpFixedPointer;
126
-
127
- _stprintf_s (strLangProductVersion, MAX_PATH,
128
- _T (" \\ StringFileInfo\\ %04x%04x\\ ProductVersion" ),
129
- lpTransArray[0 ].wLanguageID ,
130
- lpTransArray[0 ].wCharacterSet );
131
-
132
- VerQueryValue (pBuffer.get (),
133
- (LPTSTR)strLangProductVersion,
134
- (LPVOID *)&lpVersion,
135
- &nInfoSize);
136
- if (lpVersion && nInfoSize)
137
- bReturn = (_tcscmp (sVer , (LPCTSTR)lpVersion)==0 );
138
- }
139
- }
105
+ auto pBuffer = std::make_unique<BYTE[]>(dwBufferSize);
140
106
141
- return bReturn;
142
- }
107
+ if (!pBuffer)
108
+ return false ;
109
+
110
+ UINT nInfoSize = 0 , nFixedLength = 0 ;
111
+ LPSTR lpVersion = nullptr ;
112
+ VOID* lpFixedPointer;
113
+ TRANSARRAY* lpTransArray;
114
+ TCHAR strLangProductVersion[MAX_PATH] = { 0 };
115
+
116
+ if (!GetFileVersionInfo ((LPTSTR)langDll, dwReserved, dwBufferSize, pBuffer.get ()))
117
+ return false ;
143
118
119
+ VerQueryValue (pBuffer.get (), _T (" \\ VarFileInfo\\ Translation" ), &lpFixedPointer, &nFixedLength);
120
+ lpTransArray = (TRANSARRAY*)lpFixedPointer;
121
+
122
+ _stprintf_s (strLangProductVersion, MAX_PATH, _T (" \\ StringFileInfo\\ %04x%04x\\ ProductVersion" ), lpTransArray[0 ].wLanguageID , lpTransArray[0 ].wCharacterSet );
123
+
124
+ VerQueryValue (pBuffer.get (), (LPTSTR)strLangProductVersion, (LPVOID*)&lpVersion, &nInfoSize);
125
+ if (lpVersion && nInfoSize)
126
+ return (_tcscmp (sVer , (LPCTSTR)lpVersion) == 0 );
127
+
128
+ return false ;
129
+ }
0 commit comments