Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.0, 1.0.1, and 1.0.2

shellext: use uniform unix eoln on all source

Changeset 6e5456755ad9

Parent a7dd6f210c8b

by Steve Borho

Changes to 9 files · Browse files at 6e5456755ad9 Showing diff from parent a7dd6f210c8b Diff from another changeset...

Change 1 of 1 Show Entire File win32/​shellext/​IconBitmapUtils.cpp Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
@@ -1,284 +1,284 @@
-// TortoiseSVN - a Windows shell extension for easy version control - -// Copyright (C) 2009 - TortoiseSVN - -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software Foundation, -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -// Adapted for use in TortoiseHg by Veniamin Albaev -// -#include "stdafx.h" -#include "IconBitmapUtils.h" -#include "SysInfo.h" -#include "registry.h" - -IconBitmapUtils::IconBitmapUtils() - : hUxTheme(NULL) -{ - if (SysInfo::Instance().IsVistaOrLater()) - { - hUxTheme = LoadLibrary(_T("UXTHEME.DLL")); - - if (hUxTheme) - { - pfnGetBufferedPaintBits = (FN_GetBufferedPaintBits)::GetProcAddress(hUxTheme, "GetBufferedPaintBits"); - pfnBeginBufferedPaint = (FN_BeginBufferedPaint)::GetProcAddress(hUxTheme, "BeginBufferedPaint"); - pfnEndBufferedPaint = (FN_EndBufferedPaint)::GetProcAddress(hUxTheme, "EndBufferedPaint"); - } - } -} - -IconBitmapUtils::~IconBitmapUtils() -{ - if (hUxTheme) - FreeLibrary(hUxTheme); -} - -HBITMAP IconBitmapUtils::IconToBitmap(HICON hIcon) -{ - if (!hIcon) - return NULL; - - RECT rect; - - rect.right = ::GetSystemMetrics(SM_CXMENUCHECK); - rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK); - - rect.left = rect.top = 0; - - HWND desktop = ::GetDesktopWindow(); - if (desktop == NULL) - return NULL; - - HDC screen_dev = ::GetDC(desktop); - if (screen_dev == NULL) - return NULL; - - // Create a compatible DC - HDC dst_hdc = ::CreateCompatibleDC(screen_dev); - if (dst_hdc == NULL) - { - ::ReleaseDC(desktop, screen_dev); - return NULL; - } - - // Create a new bitmap of icon size - HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom); - if (bmp == NULL) - { - ::DeleteDC(dst_hdc); - ::ReleaseDC(desktop, screen_dev); - return NULL; - } - - // Select it into the compatible DC - HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp); - if (old_dst_bmp == NULL) - return NULL; - - // Fill the background of the compatible DC with the white color - // that is taken by menu routines as transparent - ::SetBkColor(dst_hdc, RGB(255, 255, 255)); - ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL); - - // Draw the icon into the compatible DC - ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL); - - // Restore settings - ::SelectObject(dst_hdc, old_dst_bmp); - ::DeleteDC(dst_hdc); - ::ReleaseDC(desktop, screen_dev); - - return bmp; -} - -HBITMAP IconBitmapUtils::IconToBitmapPARGB32(HICON hIcon) -{ - if (!hIcon) - return NULL; - - if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL) - { - TDEBUG_TRACE(" IconBitmapUtils::IconToBitmapPARGB32: Theme functions not found, returns NULL"); - return NULL; - } - - SIZE sizIcon; - sizIcon.cx = GetSystemMetrics(SM_CXSMICON); - sizIcon.cy = GetSystemMetrics(SM_CYSMICON); - - RECT rcIcon; - SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy); - HBITMAP hBmp = NULL; - - HDC hdcDest = CreateCompatibleDC(NULL); - if (hdcDest) - { - if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp))) - { - HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp); - if (hbmpOld) - { - BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; - BP_PAINTPARAMS paintParams = {0}; - paintParams.cbSize = sizeof(paintParams); - paintParams.dwFlags = BPPF_ERASE; - paintParams.pBlendFunction = &bfAlpha; - - HDC hdcBuffer; - HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer); - if (hPaintBuffer) - { - if (DrawIconEx(hdcBuffer, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL)) - //if (FillRect(hdcBuffer, &rcIcon, (HBRUSH) (0x000000FF)) != 0) - { - // If icon did not have an alpha channel we need to convert buffer to PARGB - ConvertBufferToPARGB32(hPaintBuffer, hdcDest, hIcon, sizIcon); - } - // This will write the buffer contents to the destination bitmap - pfnEndBufferedPaint(hPaintBuffer, TRUE); - } - - SelectObject(hdcDest, hbmpOld); - } - } - - DeleteDC(hdcDest); - } - - return hBmp; -} - -HRESULT IconBitmapUtils::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp) -{ - *phBmp = NULL; - - BITMAPINFO bmi; - SecureZeroMemory(&bmi, sizeof(bmi)); - bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmi.bmiHeader.biPlanes = 1; - bmi.bmiHeader.biCompression = BI_RGB; - - bmi.bmiHeader.biWidth = psize->cx; - bmi.bmiHeader.biHeight = psize->cy; - bmi.bmiHeader.biBitCount = 32; - - HDC hdcUsed = hdc ? hdc : GetDC(NULL); - if (hdcUsed) - { - *phBmp = CreateDIBSection(hdcUsed, &bmi, DIB_RGB_COLORS, ppvBits, NULL, 0); - if (hdc != hdcUsed) - { - ReleaseDC(NULL, hdcUsed); - } - } - return (NULL == *phBmp) ? E_OUTOFMEMORY : S_OK; -} - -HRESULT IconBitmapUtils::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon) -{ - RGBQUAD *prgbQuad; - int cxRow; - HRESULT hr = pfnGetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow); - if (SUCCEEDED(hr)) - { - Gdiplus::ARGB *pargb = reinterpret_cast<Gdiplus::ARGB *>(prgbQuad); - if (!HasAlpha(pargb, sizIcon, cxRow)) - { - ICONINFO info; - if (GetIconInfo(hicon, &info)) - { - if (info.hbmMask) - { - hr = ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow); - } - - DeleteObject(info.hbmColor); - DeleteObject(info.hbmMask); - } - } - } - - return hr; -} - -bool IconBitmapUtils::HasAlpha(__in Gdiplus::ARGB *pargb, SIZE& sizImage, int cxRow) -{ - ULONG cxDelta = cxRow - sizImage.cx; - for (ULONG y = sizImage.cy; y; --y) - { - for (ULONG x = sizImage.cx; x; --x) - { - if (*pargb++ & 0xFF000000) - { - return true; - } - } - - pargb += cxDelta; - } - - return false; -} - -HRESULT IconBitmapUtils::ConvertToPARGB32(HDC hdc, __inout Gdiplus::ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow) -{ - BITMAPINFO bmi; - SecureZeroMemory(&bmi, sizeof(bmi)); - bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmi.bmiHeader.biPlanes = 1; - bmi.bmiHeader.biCompression = BI_RGB; - - bmi.bmiHeader.biWidth = sizImage.cx; - bmi.bmiHeader.biHeight = sizImage.cy; - bmi.bmiHeader.biBitCount = 32; - - HRESULT hr = E_OUTOFMEMORY; - HANDLE hHeap = GetProcessHeap(); - void *pvBits = HeapAlloc(hHeap, 0, bmi.bmiHeader.biWidth * 4 * bmi.bmiHeader.biHeight); - if (pvBits) - { - hr = E_UNEXPECTED; - if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight) - { - ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth; - Gdiplus::ARGB *pargbMask = static_cast<Gdiplus::ARGB *>(pvBits); - - for (ULONG y = bmi.bmiHeader.biHeight; y; --y) - { - for (ULONG x = bmi.bmiHeader.biWidth; x; --x) - { - if (*pargbMask++) - { - // transparent pixel - *pargb++ = 0; - } - else - { - // opaque pixel - *pargb++ |= 0xFF000000; - } - } - - pargb += cxDelta; - } - - hr = S_OK; - } - - HeapFree(hHeap, 0, pvBits); - } - - return hr; -} +// TortoiseSVN - a Windows shell extension for easy version control + +// Copyright (C) 2009 - TortoiseSVN + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +// Adapted for use in TortoiseHg by Veniamin Albaev +// +#include "stdafx.h" +#include "IconBitmapUtils.h" +#include "SysInfo.h" +#include "registry.h" + +IconBitmapUtils::IconBitmapUtils() + : hUxTheme(NULL) +{ + if (SysInfo::Instance().IsVistaOrLater()) + { + hUxTheme = LoadLibrary(_T("UXTHEME.DLL")); + + if (hUxTheme) + { + pfnGetBufferedPaintBits = (FN_GetBufferedPaintBits)::GetProcAddress(hUxTheme, "GetBufferedPaintBits"); + pfnBeginBufferedPaint = (FN_BeginBufferedPaint)::GetProcAddress(hUxTheme, "BeginBufferedPaint"); + pfnEndBufferedPaint = (FN_EndBufferedPaint)::GetProcAddress(hUxTheme, "EndBufferedPaint"); + } + } +} + +IconBitmapUtils::~IconBitmapUtils() +{ + if (hUxTheme) + FreeLibrary(hUxTheme); +} + +HBITMAP IconBitmapUtils::IconToBitmap(HICON hIcon) +{ + if (!hIcon) + return NULL; + + RECT rect; + + rect.right = ::GetSystemMetrics(SM_CXMENUCHECK); + rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK); + + rect.left = rect.top = 0; + + HWND desktop = ::GetDesktopWindow(); + if (desktop == NULL) + return NULL; + + HDC screen_dev = ::GetDC(desktop); + if (screen_dev == NULL) + return NULL; + + // Create a compatible DC + HDC dst_hdc = ::CreateCompatibleDC(screen_dev); + if (dst_hdc == NULL) + { + ::ReleaseDC(desktop, screen_dev); + return NULL; + } + + // Create a new bitmap of icon size + HBITMAP bmp = ::CreateCompatibleBitmap(screen_dev, rect.right, rect.bottom); + if (bmp == NULL) + { + ::DeleteDC(dst_hdc); + ::ReleaseDC(desktop, screen_dev); + return NULL; + } + + // Select it into the compatible DC + HBITMAP old_dst_bmp = (HBITMAP)::SelectObject(dst_hdc, bmp); + if (old_dst_bmp == NULL) + return NULL; + + // Fill the background of the compatible DC with the white color + // that is taken by menu routines as transparent + ::SetBkColor(dst_hdc, RGB(255, 255, 255)); + ::ExtTextOut(dst_hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL); + + // Draw the icon into the compatible DC + ::DrawIconEx(dst_hdc, 0, 0, hIcon, rect.right, rect.bottom, 0, NULL, DI_NORMAL); + + // Restore settings + ::SelectObject(dst_hdc, old_dst_bmp); + ::DeleteDC(dst_hdc); + ::ReleaseDC(desktop, screen_dev); + + return bmp; +} + +HBITMAP IconBitmapUtils::IconToBitmapPARGB32(HICON hIcon) +{ + if (!hIcon) + return NULL; + + if (pfnBeginBufferedPaint == NULL || pfnEndBufferedPaint == NULL || pfnGetBufferedPaintBits == NULL) + { + TDEBUG_TRACE(" IconBitmapUtils::IconToBitmapPARGB32: Theme functions not found, returns NULL"); + return NULL; + } + + SIZE sizIcon; + sizIcon.cx = GetSystemMetrics(SM_CXSMICON); + sizIcon.cy = GetSystemMetrics(SM_CYSMICON); + + RECT rcIcon; + SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy); + HBITMAP hBmp = NULL; + + HDC hdcDest = CreateCompatibleDC(NULL); + if (hdcDest) + { + if (SUCCEEDED(Create32BitHBITMAP(hdcDest, &sizIcon, NULL, &hBmp))) + { + HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDest, hBmp); + if (hbmpOld) + { + BLENDFUNCTION bfAlpha = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; + BP_PAINTPARAMS paintParams = {0}; + paintParams.cbSize = sizeof(paintParams); + paintParams.dwFlags = BPPF_ERASE; + paintParams.pBlendFunction = &bfAlpha; + + HDC hdcBuffer; + HPAINTBUFFER hPaintBuffer = pfnBeginBufferedPaint(hdcDest, &rcIcon, BPBF_DIB, &paintParams, &hdcBuffer); + if (hPaintBuffer) + { + if (DrawIconEx(hdcBuffer, 0, 0, hIcon, sizIcon.cx, sizIcon.cy, 0, NULL, DI_NORMAL)) + //if (FillRect(hdcBuffer, &rcIcon, (HBRUSH) (0x000000FF)) != 0) + { + // If icon did not have an alpha channel we need to convert buffer to PARGB + ConvertBufferToPARGB32(hPaintBuffer, hdcDest, hIcon, sizIcon); + } + // This will write the buffer contents to the destination bitmap + pfnEndBufferedPaint(hPaintBuffer, TRUE); + } + + SelectObject(hdcDest, hbmpOld); + } + } + + DeleteDC(hdcDest); + } + + return hBmp; +} + +HRESULT IconBitmapUtils::Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp) +{ + *phBmp = NULL; + + BITMAPINFO bmi; + SecureZeroMemory(&bmi, sizeof(bmi)); + bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bmi.bmiHeader.biPlanes = 1; + bmi.bmiHeader.biCompression = BI_RGB; + + bmi.bmiHeader.biWidth = psize->cx; + bmi.bmiHeader.biHeight = psize->cy; + bmi.bmiHeader.biBitCount = 32; + + HDC hdcUsed = hdc ? hdc : GetDC(NULL); + if (hdcUsed) + { + *phBmp = CreateDIBSection(hdcUsed, &bmi, DIB_RGB_COLORS, ppvBits, NULL, 0); + if (hdc != hdcUsed) + { + ReleaseDC(NULL, hdcUsed); + } + } + return (NULL == *phBmp) ? E_OUTOFMEMORY : S_OK; +} + +HRESULT IconBitmapUtils::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon) +{ + RGBQUAD *prgbQuad; + int cxRow; + HRESULT hr = pfnGetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow); + if (SUCCEEDED(hr)) + { + Gdiplus::ARGB *pargb = reinterpret_cast<Gdiplus::ARGB *>(prgbQuad); + if (!HasAlpha(pargb, sizIcon, cxRow)) + { + ICONINFO info; + if (GetIconInfo(hicon, &info)) + { + if (info.hbmMask) + { + hr = ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow); + } + + DeleteObject(info.hbmColor); + DeleteObject(info.hbmMask); + } + } + } + + return hr; +} + +bool IconBitmapUtils::HasAlpha(__in Gdiplus::ARGB *pargb, SIZE& sizImage, int cxRow) +{ + ULONG cxDelta = cxRow - sizImage.cx; + for (ULONG y = sizImage.cy; y; --y) + { + for (ULONG x = sizImage.cx; x; --x) + { + if (*pargb++ & 0xFF000000) + { + return true; + } + } + + pargb += cxDelta; + } + + return false; +} + +HRESULT IconBitmapUtils::ConvertToPARGB32(HDC hdc, __inout Gdiplus::ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow) +{ + BITMAPINFO bmi; + SecureZeroMemory(&bmi, sizeof(bmi)); + bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bmi.bmiHeader.biPlanes = 1; + bmi.bmiHeader.biCompression = BI_RGB; + + bmi.bmiHeader.biWidth = sizImage.cx; + bmi.bmiHeader.biHeight = sizImage.cy; + bmi.bmiHeader.biBitCount = 32; + + HRESULT hr = E_OUTOFMEMORY; + HANDLE hHeap = GetProcessHeap(); + void *pvBits = HeapAlloc(hHeap, 0, bmi.bmiHeader.biWidth * 4 * bmi.bmiHeader.biHeight); + if (pvBits) + { + hr = E_UNEXPECTED; + if (GetDIBits(hdc, hbmp, 0, bmi.bmiHeader.biHeight, pvBits, &bmi, DIB_RGB_COLORS) == bmi.bmiHeader.biHeight) + { + ULONG cxDelta = cxRow - bmi.bmiHeader.biWidth; + Gdiplus::ARGB *pargbMask = static_cast<Gdiplus::ARGB *>(pvBits); + + for (ULONG y = bmi.bmiHeader.biHeight; y; --y) + { + for (ULONG x = bmi.bmiHeader.biWidth; x; --x) + { + if (*pargbMask++) + { + // transparent pixel + *pargb++ = 0; + } + else + { + // opaque pixel + *pargb++ |= 0xFF000000; + } + } + + pargb += cxDelta; + } + + hr = S_OK; + } + + HeapFree(hHeap, 0, pvBits); + } + + return hr; +}
Change 1 of 1 Show Entire File win32/​shellext/​IconBitmapUtils.h Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@@ -1,56 +1,56 @@
-// TortoiseSVN - a Windows shell extension for easy version control - -// Copyright (C) 2009 - TortoiseSVN - -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software Foundation, -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// - -// Adapted for use in TortoiseHg by Veniamin Albaev -// -#pragma once -#include <Uxtheme.h> -#include <GdiPlus.h> -#include <map> - -typedef HRESULT (WINAPI *FN_GetBufferedPaintBits) (HPAINTBUFFER hBufferedPaint, RGBQUAD **ppbBuffer, int *pcxRow); -typedef HPAINTBUFFER (WINAPI *FN_BeginBufferedPaint) (HDC hdcTarget, const RECT *prcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams, HDC *phdc); -typedef HRESULT (WINAPI *FN_EndBufferedPaint) (HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget); - - -/** - * \ingroup utils - * provides helper functions for converting icons to bitmaps - */ -class IconBitmapUtils -{ -public: - IconBitmapUtils(void); - ~IconBitmapUtils(void); - - HBITMAP IconToBitmap(HICON hIcon); - HBITMAP IconToBitmapPARGB32(HICON hIcon); - HRESULT Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp); - HRESULT ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon); - bool HasAlpha(__in Gdiplus::ARGB *pargb, SIZE& sizImage, int cxRow); - HRESULT ConvertToPARGB32(HDC hdc, __inout Gdiplus::ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow); - - -private: - HMODULE hUxTheme; - - FN_GetBufferedPaintBits pfnGetBufferedPaintBits; - FN_BeginBufferedPaint pfnBeginBufferedPaint; - FN_EndBufferedPaint pfnEndBufferedPaint; -}; +// TortoiseSVN - a Windows shell extension for easy version control + +// Copyright (C) 2009 - TortoiseSVN + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// + +// Adapted for use in TortoiseHg by Veniamin Albaev +// +#pragma once +#include <Uxtheme.h> +#include <GdiPlus.h> +#include <map> + +typedef HRESULT (WINAPI *FN_GetBufferedPaintBits) (HPAINTBUFFER hBufferedPaint, RGBQUAD **ppbBuffer, int *pcxRow); +typedef HPAINTBUFFER (WINAPI *FN_BeginBufferedPaint) (HDC hdcTarget, const RECT *prcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams, HDC *phdc); +typedef HRESULT (WINAPI *FN_EndBufferedPaint) (HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget); + + +/** + * \ingroup utils + * provides helper functions for converting icons to bitmaps + */ +class IconBitmapUtils +{ +public: + IconBitmapUtils(void); + ~IconBitmapUtils(void); + + HBITMAP IconToBitmap(HICON hIcon); + HBITMAP IconToBitmapPARGB32(HICON hIcon); + HRESULT Create32BitHBITMAP(HDC hdc, const SIZE *psize, __deref_opt_out void **ppvBits, __out HBITMAP* phBmp); + HRESULT ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon); + bool HasAlpha(__in Gdiplus::ARGB *pargb, SIZE& sizImage, int cxRow); + HRESULT ConvertToPARGB32(HDC hdc, __inout Gdiplus::ARGB *pargb, HBITMAP hbmp, SIZE& sizImage, int cxRow); + + +private: + HMODULE hUxTheme; + + FN_GetBufferedPaintBits pfnGetBufferedPaintBits; + FN_BeginBufferedPaint pfnBeginBufferedPaint; + FN_EndBufferedPaint pfnEndBufferedPaint; +};
Change 1 of 1 Show Entire File win32/​shellext/​Registry.cpp Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
@@ -1,205 +1,205 @@
-// TortoiseSVN - a Windows shell extension for easy version control - -// Copyright (C) 2003-2006,2008-2009 - TortoiseSVN - -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software Foundation, -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -#include "stdafx.h" -#include "registry.h" - -////////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __CSTRINGT_H__ -CRegBase::CRegBase() -{ -} - -CRegBase::CRegBase (const CString& key, bool force, HKEY base, REGSAM sam) - : CRegBaseCommon<CString> (key, force, base, sam) -{ - m_key.TrimLeft(_T("\\")); - int backslashpos = m_key.ReverseFind('\\'); - m_path = m_key.Left(backslashpos); - m_path.TrimRight(_T("\\")); - m_key = m_key.Mid(backslashpos); - m_key.Trim(_T("\\")); -} -#endif - -////////////////////////////////////////////////////////////////////////////////////////////// - -CRegStdBase::CRegStdBase() -{ -} - -CRegStdBase::CRegStdBase (const tstring& key, bool force, HKEY base, REGSAM sam) - : CRegBaseCommon<tstring> (key, force, base, sam) -{ - tstring::size_type pos = key.find_last_of(_T('\\')); - if (pos != tstring::npos) - { - m_path = key.substr(0, pos); - m_key = key.substr(pos + 1); - } -} - -////////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __ATLTYPES_H__ // defines CRect -CRegRect::CRegRect(void) - : CRegTypedBase<CRect, CRegBase>(CRect(0,0,0,0)) -{ -} - -CRegRect::CRegRect(const CString& key, const CRect& def, bool force, HKEY base, REGSAM sam) - : CRegTypedBase<CRect, CRegBase> (key, def, force, base, sam) -{ - read(); -} - -void CRegRect::InternalRead (HKEY hKey, CRect& value) -{ - DWORD size = 0; - DWORD type = 0; - RegQueryValueEx(hKey, m_key, NULL, &type, NULL, (LPDWORD) &size); - - auto_buffer<char> buffer (size); - if ((LastError = RegQueryValueEx(hKey, m_key, NULL, &type, (BYTE*) buffer.get(), &size))==ERROR_SUCCESS) - { - ASSERT(type==REG_BINARY); - value = CRect((LPRECT)buffer.get()); - } -} - -void CRegRect::InternalWrite (HKEY hKey, const CRect& value) -{ - LastError = RegSetValueEx(hKey, m_key, 0, REG_BINARY, (BYTE *)(LPCRECT)value, sizeof(value)); -} - -#endif - -////////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef __ATLTYPES_H__ // defines CPoint -CRegPoint::CRegPoint(void) - : CRegTypedBase<CPoint, CRegBase>(CPoint(0,0)) -{ -} - -CRegPoint::CRegPoint(const CString& key, const CPoint& def, bool force, HKEY base, REGSAM sam) - : CRegTypedBase<CPoint, CRegBase> (key, def, force, base, sam) -{ - read(); -} - -void CRegPoint::InternalRead (HKEY hKey, CPoint& value) -{ - DWORD size = 0; - DWORD type = 0; - RegQueryValueEx(hKey, m_key, NULL, &type, NULL, (LPDWORD) &size); - - auto_buffer<char> buffer(size); - if ((LastError = RegQueryValueEx(hKey, m_key, NULL, &type, (BYTE*) buffer.get(), &size))==ERROR_SUCCESS) - { - ASSERT(type==REG_BINARY); - value = CPoint(*(POINT*)buffer.get()); - } -} - -void CRegPoint::InternalWrite (HKEY hKey, const CPoint& value) -{ - LastError = RegSetValueEx(hKey, m_key, 0, REG_BINARY, (BYTE *)&value, sizeof(value)); -} -#endif - -///////////////////////////////////////////////////////////////////// - -#ifdef __AFXCOLL_H__ // defines CStringList -CRegistryKey::CRegistryKey(const CString& key, HKEY base, REGSAM sam) -{ - m_base = base; - m_hKey = NULL; - m_sam = sam; - m_path = key; - m_path.TrimLeft(_T("\\")); -} - -CRegistryKey::~CRegistryKey() -{ - if (m_hKey) - RegCloseKey(m_hKey); -} - -DWORD CRegistryKey::createKey() -{ - DWORD disp; - DWORD rc = RegCreateKeyEx(m_base, m_path, 0, _T(""), REG_OPTION_NON_VOLATILE, KEY_WRITE|m_sam, NULL, &m_hKey, &disp); - if (rc != ERROR_SUCCESS) - { - return rc; - } - return RegCloseKey(m_hKey); -} - -DWORD CRegistryKey::removeKey() -{ - RegOpenKeyEx(m_base, m_path, 0, KEY_WRITE|m_sam, &m_hKey); - return SHDeleteKey(m_base, (LPCTSTR)m_path); -} - -bool CRegistryKey::getValues(CStringList& values) -{ - values.RemoveAll(); - - if (RegOpenKeyEx(m_base, m_path, 0, KEY_EXECUTE|m_sam, &m_hKey)==ERROR_SUCCESS) - { - for (int i = 0, rc = ERROR_SUCCESS; rc == ERROR_SUCCESS; i++) - { - TCHAR value[255]; - DWORD size = sizeof value / sizeof TCHAR; - rc = RegEnumValue(m_hKey, i, value, &size, NULL, NULL, NULL, NULL); - if (rc == ERROR_SUCCESS) - { - values.AddTail(value); - } - } - } - - return values.GetCount() > 0; -} - -bool CRegistryKey::getSubKeys(CStringList& subkeys) -{ - subkeys.RemoveAll(); - - if (RegOpenKeyEx(m_base, m_path, 0, KEY_EXECUTE|m_sam, &m_hKey)==ERROR_SUCCESS) - { - for (int i = 0, rc = ERROR_SUCCESS; rc == ERROR_SUCCESS; i++) - { - TCHAR value[1024]; - DWORD size = sizeof value / sizeof TCHAR; - FILETIME last_write_time; - rc = RegEnumKeyEx(m_hKey, i, value, &size, NULL, NULL, NULL, &last_write_time); - if (rc == ERROR_SUCCESS) - { - subkeys.AddTail(value); - } - } - } - - return subkeys.GetCount() > 0; -} -#endif - +// TortoiseSVN - a Windows shell extension for easy version control + +// Copyright (C) 2003-2006,2008-2009 - TortoiseSVN + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +#include "stdafx.h" +#include "registry.h" + +////////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __CSTRINGT_H__ +CRegBase::CRegBase() +{ +} + +CRegBase::CRegBase (const CString& key, bool force, HKEY base, REGSAM sam) + : CRegBaseCommon<CString> (key, force, base, sam) +{ + m_key.TrimLeft(_T("\\")); + int backslashpos = m_key.ReverseFind('\\'); + m_path = m_key.Left(backslashpos); + m_path.TrimRight(_T("\\")); + m_key = m_key.Mid(backslashpos); + m_key.Trim(_T("\\")); +} +#endif + +////////////////////////////////////////////////////////////////////////////////////////////// + +CRegStdBase::CRegStdBase() +{ +} + +CRegStdBase::CRegStdBase (const tstring& key, bool force, HKEY base, REGSAM sam) + : CRegBaseCommon<tstring> (key, force, base, sam) +{ + tstring::size_type pos = key.find_last_of(_T('\\')); + if (pos != tstring::npos) + { + m_path = key.substr(0, pos); + m_key = key.substr(pos + 1); + } +} + +////////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __ATLTYPES_H__ // defines CRect +CRegRect::CRegRect(void) + : CRegTypedBase<CRect, CRegBase>(CRect(0,0,0,0)) +{ +} + +CRegRect::CRegRect(const CString& key, const CRect& def, bool force, HKEY base, REGSAM sam) + : CRegTypedBase<CRect, CRegBase> (key, def, force, base, sam) +{ + read(); +} + +void CRegRect::InternalRead (HKEY hKey, CRect& value) +{ + DWORD size = 0; + DWORD type = 0; + RegQueryValueEx(hKey, m_key, NULL, &type, NULL, (LPDWORD) &size); + + auto_buffer<char> buffer (size); + if ((LastError = RegQueryValueEx(hKey, m_key, NULL, &type, (BYTE*) buffer.get(), &size))==ERROR_SUCCESS) + { + ASSERT(type==REG_BINARY); + value = CRect((LPRECT)buffer.get()); + } +} + +void CRegRect::InternalWrite (HKEY hKey, const CRect& value) +{ + LastError = RegSetValueEx(hKey, m_key, 0, REG_BINARY, (BYTE *)(LPCRECT)value, sizeof(value)); +} + +#endif + +////////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef __ATLTYPES_H__ // defines CPoint +CRegPoint::CRegPoint(void) + : CRegTypedBase<CPoint, CRegBase>(CPoint(0,0)) +{ +} + +CRegPoint::CRegPoint(const CString& key, const CPoint& def, bool force, HKEY base, REGSAM sam) + : CRegTypedBase<CPoint, CRegBase> (key, def, force, base, sam) +{ + read(); +} + +void CRegPoint::InternalRead (HKEY hKey, CPoint& value) +{ + DWORD size = 0; + DWORD type = 0; + RegQueryValueEx(hKey, m_key, NULL, &type, NULL, (LPDWORD) &size); + + auto_buffer<char> buffer(size); + if ((LastError = RegQueryValueEx(hKey, m_key, NULL, &type, (BYTE*) buffer.get(), &size))==ERROR_SUCCESS) + { + ASSERT(type==REG_BINARY); + value = CPoint(*(POINT*)buffer.get()); + } +} + +void CRegPoint::InternalWrite (HKEY hKey, const CPoint& value) +{ + LastError = RegSetValueEx(hKey, m_key, 0, REG_BINARY, (BYTE *)&value, sizeof(value)); +} +#endif + +///////////////////////////////////////////////////////////////////// + +#ifdef __AFXCOLL_H__ // defines CStringList +CRegistryKey::CRegistryKey(const CString& key, HKEY base, REGSAM sam) +{ + m_base = base; + m_hKey = NULL; + m_sam = sam; + m_path = key; + m_path.TrimLeft(_T("\\")); +} + +CRegistryKey::~CRegistryKey() +{ + if (m_hKey) + RegCloseKey(m_hKey); +} + +DWORD CRegistryKey::createKey() +{ + DWORD disp; + DWORD rc = RegCreateKeyEx(m_base, m_path, 0, _T(""), REG_OPTION_NON_VOLATILE, KEY_WRITE|m_sam, NULL, &m_hKey, &disp); + if (rc != ERROR_SUCCESS) + { + return rc; + } + return RegCloseKey(m_hKey); +} + +DWORD CRegistryKey::removeKey() +{ + RegOpenKeyEx(m_base, m_path, 0, KEY_WRITE|m_sam, &m_hKey); + return SHDeleteKey(m_base, (LPCTSTR)m_path); +} + +bool CRegistryKey::getValues(CStringList& values) +{ + values.RemoveAll(); + + if (RegOpenKeyEx(m_base, m_path, 0, KEY_EXECUTE|m_sam, &m_hKey)==ERROR_SUCCESS) + { + for (int i = 0, rc = ERROR_SUCCESS; rc == ERROR_SUCCESS; i++) + { + TCHAR value[255]; + DWORD size = sizeof value / sizeof TCHAR; + rc = RegEnumValue(m_hKey, i, value, &size, NULL, NULL, NULL, NULL); + if (rc == ERROR_SUCCESS) + { + values.AddTail(value); + } + } + } + + return values.GetCount() > 0; +} + +bool CRegistryKey::getSubKeys(CStringList& subkeys) +{ + subkeys.RemoveAll(); + + if (RegOpenKeyEx(m_base, m_path, 0, KEY_EXECUTE|m_sam, &m_hKey)==ERROR_SUCCESS) + { + for (int i = 0, rc = ERROR_SUCCESS; rc == ERROR_SUCCESS; i++) + { + TCHAR value[1024]; + DWORD size = sizeof value / sizeof TCHAR; + FILETIME last_write_time; + rc = RegEnumKeyEx(m_hKey, i, value, &size, NULL, NULL, NULL, &last_write_time); + if (rc == ERROR_SUCCESS) + { + subkeys.AddTail(value); + } + } + } + + return subkeys.GetCount() > 0; +} +#endif +
Change 1 of 1 Show Entire File win32/​shellext/​SysInfo.cpp Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@@ -1,40 +1,40 @@
-// TortoiseSVN - a Windows shell extension for easy version control - -// Copyright (C) 2008 - TortoiseSVN - -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software Foundation, -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -#include "StdAfx.h" -#include "SysInfo.h" - -SysInfo::SysInfo(void) -{ - SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX)); - inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - GetVersionEx((OSVERSIONINFO *)&inf); -} - -SysInfo::~SysInfo(void) -{ -} - -const SysInfo& SysInfo::Instance() -{ - static SysInfo instance; - return instance; -} - - - +// TortoiseSVN - a Windows shell extension for easy version control + +// Copyright (C) 2008 - TortoiseSVN + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +#include "StdAfx.h" +#include "SysInfo.h" + +SysInfo::SysInfo(void) +{ + SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX)); + inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + GetVersionEx((OSVERSIONINFO *)&inf); +} + +SysInfo::~SysInfo(void) +{ +} + +const SysInfo& SysInfo::Instance() +{ + static SysInfo instance; + return instance; +} + + +
Change 1 of 1 Show Entire File win32/​shellext/​SysInfo.h Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@@ -1,42 +1,42 @@
-// TortoiseSVN - a Windows shell extension for easy version control - -// Copyright (C) 2008 - TortoiseSVN - -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software Foundation, -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -#pragma once - - -/** - * \ingroup Utils - * This singleton class handles system information - */ -class SysInfo -{ -private: - SysInfo(void); - ~SysInfo(void); -public: - static const SysInfo& Instance(); - - DWORD GetFullVersion() const {return MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);} - bool IsXP() const {return (GetFullVersion() < 0x0600);} // cover Win5.1 and 5.2 alike - bool IsVista() const {return (GetFullVersion() == 0x0600);} - bool IsVistaOrLater() const {return (GetFullVersion() >= 0x0600);} - bool IsWin7() const {return (GetFullVersion() == 0x0601);} - bool IsWin7OrLater() const {return (GetFullVersion() >= 0x0601);} -private: - OSVERSIONINFOEX inf; -}; +// TortoiseSVN - a Windows shell extension for easy version control + +// Copyright (C) 2008 - TortoiseSVN + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +#pragma once + + +/** + * \ingroup Utils + * This singleton class handles system information + */ +class SysInfo +{ +private: + SysInfo(void); + ~SysInfo(void); +public: + static const SysInfo& Instance(); + + DWORD GetFullVersion() const {return MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);} + bool IsXP() const {return (GetFullVersion() < 0x0600);} // cover Win5.1 and 5.2 alike + bool IsVista() const {return (GetFullVersion() == 0x0600);} + bool IsVistaOrLater() const {return (GetFullVersion() >= 0x0600);} + bool IsWin7() const {return (GetFullVersion() == 0x0601);} + bool IsWin7OrLater() const {return (GetFullVersion() >= 0x0601);} +private: + OSVERSIONINFOEX inf; +};
Change 1 of 1 Show Entire File win32/​shellext/​auto_buffer.h Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
@@ -1,91 +1,91 @@
-// TortoiseSVN - a Windows shell extension for easy version control - -// Copyright (C) 2009 - TortoiseSVN - -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software Foundation, -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -#pragma once - -/** - * A simplified analog to std::auto_ptr<> that encapsulates - * an array allocated dynamically via new[]. - * - * Use this where you could not use a std::auto_ptr<> (works - * for single elements only) nor a std::vector<> (no guarantees - * w.r.t. to internal organization, i.e. no access to mem buffer). - */ - -template<class T> -class auto_buffer -{ -private: - - T* buffer; - - /// no copy nor assignment - - auto_buffer(const auto_buffer&); - auto_buffer& operator=(const auto_buffer&); - -public: - - explicit auto_buffer (size_t size = 0) throw() - : buffer (size == 0 ? NULL : new T[size]) - { - } - - ~auto_buffer() - { - delete[] buffer; - } - - operator T*() const throw() - { - return buffer; - } - - operator void*() const throw() - { - return buffer; - } - - operator bool() const throw() - { - return buffer != NULL; - } - - T* operator->() const throw() - { - return buffer; - } - - T *get() const throw() - { - return buffer; - } - - T* release() throw() - { - T* temp = buffer; - buffer = NULL; - return temp; - } - - void reset (size_t newSize = 0) - { - delete[] buffer; - buffer = (newSize == 0 ? NULL : new T[newSize]); - } -}; +// TortoiseSVN - a Windows shell extension for easy version control + +// Copyright (C) 2009 - TortoiseSVN + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +#pragma once + +/** + * A simplified analog to std::auto_ptr<> that encapsulates + * an array allocated dynamically via new[]. + * + * Use this where you could not use a std::auto_ptr<> (works + * for single elements only) nor a std::vector<> (no guarantees + * w.r.t. to internal organization, i.e. no access to mem buffer). + */ + +template<class T> +class auto_buffer +{ +private: + + T* buffer; + + /// no copy nor assignment + + auto_buffer(const auto_buffer&); + auto_buffer& operator=(const auto_buffer&); + +public: + + explicit auto_buffer (size_t size = 0) throw() + : buffer (size == 0 ? NULL : new T[size]) + { + } + + ~auto_buffer() + { + delete[] buffer; + } + + operator T*() const throw() + { + return buffer; + } + + operator void*() const throw() + { + return buffer; + } + + operator bool() const throw() + { + return buffer != NULL; + } + + T* operator->() const throw() + { + return buffer; + } + + T *get() const throw() + { + return buffer; + } + + T* release() throw() + { + T* temp = buffer; + buffer = NULL; + return temp; + } + + void reset (size_t newSize = 0) + { + delete[] buffer; + buffer = (newSize == 0 ? NULL : new T[newSize]); + } +};
Show Entire File win32/​shellext/​registry.h Stacked
This file's diff was not loaded because this changeset is very large. Load changes
Change 1 of 1 Show Entire File win32/​shellext/​resource.h Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@@ -1,31 +1,31 @@
-//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by shellext.rc -// - -#define IDS_APP_TITLE 103 - -#define IDR_MAINFRAME 128 -#define IDD_SHELLEXT_DIALOG 102 -#define IDD_ABOUTBOX 103 -#define IDM_ABOUT 104 -#define IDM_EXIT 105 -#define IDI_SHELLEXT 107 -#define IDI_SMALL 108 -#define IDC_SHELLEXT 109 -#define IDC_MYICON 2 -#ifndef IDC_STATIC -#define IDC_STATIC -1 -#endif -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS - -#define _APS_NO_MFC 130 -#define _APS_NEXT_RESOURCE_VALUE 129 -#define _APS_NEXT_COMMAND_VALUE 32771 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 110 -#endif -#endif +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by shellext.rc +// + +#define IDS_APP_TITLE 103 + +#define IDR_MAINFRAME 128 +#define IDD_SHELLEXT_DIALOG 102 +#define IDD_ABOUTBOX 103 +#define IDM_ABOUT 104 +#define IDM_EXIT 105 +#define IDI_SHELLEXT 107 +#define IDI_SMALL 108 +#define IDC_SHELLEXT 109 +#define IDC_MYICON 2 +#ifndef IDC_STATIC +#define IDC_STATIC -1 +#endif +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS + +#define _APS_NO_MFC 130 +#define _APS_NEXT_RESOURCE_VALUE 129 +#define _APS_NEXT_COMMAND_VALUE 32771 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 110 +#endif +#endif
Change 1 of 1 Show Entire File win32/​shellext/​tstring.h Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@@ -1,25 +1,25 @@
-// TortoiseSVN - a Windows shell extension for easy version control - -// Copyright (C) 2009 - TortoiseSVN - -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software Foundation, -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -#pragma once - -#include <string> -#include <tchar.h> - -typedef std::basic_string<TCHAR> tstring; - +// TortoiseSVN - a Windows shell extension for easy version control + +// Copyright (C) 2009 - TortoiseSVN + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +#pragma once + +#include <string> +#include <tchar.h> + +typedef std::basic_string<TCHAR> tstring; +