Skip to content

Commit 11e6488

Browse files
committed
Refactoring: Reduce indention
Signed-off-by: Sven Strickroth <[email protected]>
1 parent b3b8b55 commit 11e6488

File tree

3 files changed

+247
-274
lines changed

3 files changed

+247
-274
lines changed

src/Utils/LangDll.cpp

Lines changed: 61 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// TortoiseGit - a Windows shell extension for easy version control
22

3+
// Copyright (C) 2016 - TortoiseGit
34
// Copyright (C) 2003-2006, 2008, 2013-2015 - TortoiseSVN
45

56
// This program is free software; you can redistribute it and/or
@@ -42,50 +43,49 @@ HINSTANCE CLangDll::Init(LPCTSTR appname, unsigned long langID)
4243
_tcscpy_s(sVer, MAX_PATH, _T(STRPRODUCTVER));
4344
GetModuleFileName(NULL, langpath, MAX_PATH);
4445
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
4658
{
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))
5064
{
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;
7767
}
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+
7979
return m_hInstance;
8080
}
8181

8282
void CLangDll::Close()
8383
{
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;
8989
}
9090

9191
bool CLangDll::DoVersionStringsMatch(LPCTSTR sVer, LPCTSTR langDll) const
@@ -96,48 +96,34 @@ bool CLangDll::DoVersionStringsMatch(LPCTSTR sVer, LPCTSTR langDll) const
9696
WORD wCharacterSet;
9797
};
9898

99-
bool bReturn = false;
10099
DWORD dwReserved = 0;
101100
DWORD dwBufferSize = GetFileVersionInfoSize((LPTSTR)langDll,&dwReserved);
102101

103-
if (dwBufferSize > 0)
104-
{
105-
auto pBuffer = std::make_unique<BYTE[]>(dwBufferSize);
102+
if (dwBufferSize <= 0)
103+
return false;
106104

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);
140106

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;
143118

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+
}

src/Utils/ShellUpdater.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// TortoiseGit - a Windows shell extension for easy version control
22

3-
// Copyright (C) 2012-2013, 2015 - TortoiseGit
3+
// Copyright (C) 2012-2013, 2015-2016 - TortoiseGit
44
// Copyright (C) 2003-2008,2011,2014 - TortoiseSVN
55

66
// This program is free software; you can redistribute it and/or
@@ -69,13 +69,13 @@ void CShellUpdater::AddPathsForUpdate(const CTGitPathList& pathList)
6969

7070
void CShellUpdater::Flush()
7171
{
72-
if (!m_pathsForUpdating.IsEmpty())
73-
{
74-
CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Flushing shell update list\n");
72+
if (m_pathsForUpdating.IsEmpty())
73+
return;
7574

76-
UpdateShell();
77-
m_pathsForUpdating.Clear();
78-
}
75+
CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Flushing shell update list\n");
76+
77+
UpdateShell();
78+
m_pathsForUpdating.Clear();
7979
}
8080

8181
void CShellUpdater::UpdateShell()
@@ -164,18 +164,18 @@ bool CShellUpdater::RebuildIcons()
164164
{
165165
const int BUFFER_SIZE = 1024;
166166
TCHAR buf[BUFFER_SIZE] = { 0 };
167-
HKEY hRegKey = 0;
167+
HKEY hRegKey = nullptr;
168168
DWORD dwRegValue;
169169
DWORD dwRegValueTemp;
170170
DWORD dwSize;
171171
DWORD_PTR dwResult;
172172
LONG lRegResult;
173-
bool bResult = false;
174173

175174
lRegResult = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Control Panel\\Desktop\\WindowMetrics"),
176175
0, KEY_READ | KEY_WRITE, &hRegKey);
177176
if (lRegResult != ERROR_SUCCESS)
178-
goto Cleanup;
177+
return false;
178+
SCOPE_EXIT { RegCloseKey(hRegKey); };
179179

180180
// we're going to change the Shell Icon Size value
181181
const TCHAR* sRegValueName = _T("Shell Icon Size");
@@ -193,7 +193,7 @@ bool CShellUpdater::RebuildIcons()
193193
_sntprintf_s(buf, BUFFER_SIZE, BUFFER_SIZE, _T("%d"), iDefaultIconSize);
194194
}
195195
else if (lRegResult != ERROR_SUCCESS)
196-
goto Cleanup;
196+
return false;
197197

198198
// Change registry value
199199
dwRegValue = _ttoi(buf);
@@ -203,8 +203,7 @@ bool CShellUpdater::RebuildIcons()
203203
lRegResult = RegSetValueEx(hRegKey, sRegValueName, 0, REG_SZ,
204204
(LPBYTE) buf, dwSize);
205205
if (lRegResult != ERROR_SUCCESS)
206-
goto Cleanup;
207-
206+
return false;
208207

209208
// Update all windows
210209
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS,
@@ -214,19 +213,12 @@ bool CShellUpdater::RebuildIcons()
214213
dwSize = _sntprintf_s(buf, BUFFER_SIZE, BUFFER_SIZE, _T("%lu"), dwRegValue) + sizeof(TCHAR);
215214
lRegResult = RegSetValueEx(hRegKey, sRegValueName, 0, REG_SZ,
216215
(LPBYTE) buf, dwSize);
217-
if(lRegResult != ERROR_SUCCESS)
218-
goto Cleanup;
216+
if (lRegResult != ERROR_SUCCESS)
217+
return false;
219218

220219
// Update all windows
221220
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS,
222221
0, SMTO_ABORTIFHUNG, 5000, &dwResult);
223222

224-
bResult = true;
225-
226-
Cleanup:
227-
if (hRegKey != 0)
228-
{
229-
RegCloseKey(hRegKey);
230-
}
231-
return bResult;
223+
return true;
232224
}

0 commit comments

Comments
 (0)