fb4cd44b396318145672430265fb28d732af4ebf
[reactos.git] / reactos / dll / shellext / acppage / CLayerUIPropPage.cpp
1 /*
2 * Copyright 2015-2017 Mark Jansen (mark.jansen@reactos.org)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include "precomp.h"
20
21 #include <shlwapi.h>
22 #include <shellapi.h>
23 #include <shellutils.h>
24 #include <strsafe.h>
25 #include <apphelp.h>
26 #include <windowsx.h>
27 #include <sfc.h>
28
29 const GUID CLSID_CLayerUIPropPage = { 0x513D916F, 0x2A8E, 0x4F51, { 0xAE, 0xAB, 0x0C, 0xBC, 0x76, 0xFB, 0x1A, 0xF8 } };
30 #define ACP_WNDPROP L"{513D916F-2A8E-4F51-AEAB-0CBC76FB1AF8}.Prop"
31
32 #define GPLK_USER 1
33 #define GPLK_MACHINE 2
34 #define MAX_LAYER_LENGTH 256
35
36 static struct {
37 const PCWSTR Display;
38 const PCWSTR Name;
39 } g_CompatModes[] = {
40 { L"Windows 95", L"WIN95" },
41 { L"Windows 98/ME", L"WIN98" },
42 { L"Windows NT 4.0 (SP5)", L"NT4SP5" },
43 { L"Windows 2000", L"WIN2000" },
44 { L"Windows XP (SP2)", L"WINXPSP2" },
45 { L"Windows XP (SP3)", L"WINXPSP3" },
46 { L"Windows Server 2003 (SP1)", L"WINSRV03SP1" },
47 #if 0
48 { L"Windows Server 2008 (SP1)", L"WINSRV08SP1" },
49 { L"Windows Vista", L"VISTARTM" },
50 { L"Windows Vista (SP1)", L"VISTASP1" },
51 { L"Windows Vista (SP2)", L"VISTASP2" },
52 { L"Windows 7", L"WIN7RTM" },
53 #endif
54 { NULL, NULL }
55 };
56
57 static struct {
58 const PCWSTR Name;
59 DWORD Id;
60 } g_Layers[] = {
61 { L"256COLOR", IDC_CHKRUNIN256COLORS },
62 { L"640X480", IDC_CHKRUNIN640480RES },
63 { L"DISABLETHEMES", IDC_CHKDISABLEVISUALTHEMES },
64 #if 0
65 { L"DISABLEDWM", IDC_??, TRUE },
66 { L"HIGHDPIAWARE", IDC_??, TRUE },
67 { L"RUNASADMIN", IDC_??, TRUE },
68 #endif
69 { NULL, 0 }
70 };
71
72 static const WCHAR* g_AllowedExtensions[] = {
73 L".exe",
74 L".msi",
75 L".pif",
76 L".bat",
77 L".cmd",
78 0
79 };
80
81
82 void ACDBG_FN(PCSTR FunctionName, PCWSTR Format, ...)
83 {
84 WCHAR Buffer[512];
85 WCHAR* Current = Buffer;
86 size_t Length = _countof(Buffer);
87
88 StringCchPrintfExW(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, L"[%-20S] ", FunctionName);
89 va_list ArgList;
90 va_start(ArgList, Format);
91 StringCchVPrintfExW(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, Format, ArgList);
92 va_end(ArgList);
93 OutputDebugStringW(Buffer);
94 }
95
96 #define ACDBG(fmt, ...) ACDBG_FN(__FUNCTION__, fmt, ##__VA_ARGS__ )
97
98
99
100 CLayerUIPropPage::CLayerUIPropPage()
101 : m_IsSfcProtected(FALSE)
102 , m_AllowPermLayer(FALSE)
103 , m_LayerQueryFlags(GPLK_USER) /* TODO: When do we read from HKLM? */
104 , m_RegistryOSMode(0)
105 , m_OSMode(0)
106 , m_RegistryEnabledLayers(0)
107 , m_EnabledLayers(0)
108 {
109 }
110
111 CLayerUIPropPage::~CLayerUIPropPage()
112 {
113 }
114
115 HRESULT CLayerUIPropPage::InitFile(PCWSTR Filename)
116 {
117 CString ExpandedFilename;
118 DWORD dwRequired = ExpandEnvironmentStringsW(Filename, NULL, 0);
119 if (dwRequired > 0)
120 {
121 LPWSTR Buffer = ExpandedFilename.GetBuffer(dwRequired);
122 DWORD dwReturned = ExpandEnvironmentStringsW(Filename, Buffer, dwRequired);
123 if (dwRequired == dwReturned)
124 {
125 ExpandedFilename.ReleaseBufferSetLength(dwReturned - 1);
126 ACDBG(L"Expanded '%s' => '%s'\r\n", Filename, (PCWSTR)ExpandedFilename);
127 }
128 else
129 {
130 ExpandedFilename.ReleaseBufferSetLength(0);
131 ExpandedFilename = Filename;
132 ACDBG(L"Failed during expansion '%s'\r\n", Filename);
133 }
134 }
135 else
136 {
137 ACDBG(L"Failed to expand '%s'\r\n", Filename);
138 ExpandedFilename = Filename;
139 }
140 PCWSTR pwszExt = PathFindExtensionW(ExpandedFilename);
141 if (!pwszExt)
142 {
143 ACDBG(L"Failed to find an extension: '%s'\r\n", (PCWSTR)ExpandedFilename);
144 return E_FAIL;
145 }
146 if (!wcsicmp(pwszExt, L".lnk"))
147 {
148 WCHAR Buffer[MAX_PATH];
149 if (!GetExeFromLnk(ExpandedFilename, Buffer, _countof(Buffer)))
150 {
151 ACDBG(L"Failed to read link target from: '%s'\r\n", (PCWSTR)ExpandedFilename);
152 return E_FAIL;
153 }
154 if (!wcsicmp(Buffer, ExpandedFilename))
155 {
156 ACDBG(L"Link redirects to itself: '%s'\r\n", (PCWSTR)ExpandedFilename);
157 return E_FAIL;
158 }
159 return InitFile(Buffer);
160 }
161 for (size_t n = 0; g_AllowedExtensions[n]; ++n)
162 {
163 if (!wcsicmp(g_AllowedExtensions[n], pwszExt))
164 {
165 m_Filename = ExpandedFilename;
166 ACDBG(L"Got: %s\r\n", (PCWSTR)ExpandedFilename);
167 m_IsSfcProtected = SfcIsFileProtected(NULL, m_Filename);
168 m_AllowPermLayer = AllowPermLayer(ExpandedFilename);
169 return S_OK;
170 }
171 }
172 ACDBG(L"Extension not included: '%s'\r\n", pwszExt);
173 return E_FAIL;
174 }
175
176 static BOOL GetLayerInfo(PCWSTR Filename, DWORD QueryFlags, PDWORD OSMode, PDWORD Enabledlayers, CSimpleArray<CString>& customLayers)
177 {
178 WCHAR wszLayers[MAX_LAYER_LENGTH] = { 0 };
179 DWORD dwBytes = sizeof(wszLayers);
180
181 *OSMode = *Enabledlayers = 0;
182 customLayers.RemoveAll();
183 if (!SdbGetPermLayerKeys(Filename, wszLayers, &dwBytes, QueryFlags))
184 return FALSE;
185
186 for (PWCHAR Layer = wcstok(wszLayers, L" "); Layer; Layer = wcstok(NULL, L" "))
187 {
188 size_t n;
189 for (n = 0; g_Layers[n].Name; ++n)
190 {
191 if (!wcsicmp(g_Layers[n].Name, Layer))
192 {
193 *Enabledlayers |= (1<<n);
194 break;
195 }
196 }
197 /* Did we find it? */
198 if (g_Layers[n].Name)
199 continue;
200
201 for (n = 0; g_CompatModes[n].Name; ++n)
202 {
203 if (!wcsicmp(g_CompatModes[n].Name, Layer))
204 {
205 *OSMode = n+1;
206 break;
207 }
208 }
209 /* Did we find it? */
210 if (g_CompatModes[n].Name)
211 continue;
212
213 /* Must be a 'custom' layer */
214 customLayers.Add(Layer);
215 }
216 return TRUE;
217 }
218
219 void CLayerUIPropPage::OnRefresh(HWND hWnd)
220 {
221 if (!GetLayerInfo(m_Filename, m_LayerQueryFlags, &m_RegistryOSMode, &m_RegistryEnabledLayers, m_RegistryCustomLayers))
222 m_RegistryOSMode = m_RegistryEnabledLayers = 0;
223
224 for (size_t n = 0; g_Layers[n].Name; ++n)
225 CheckDlgButton(hWnd, g_Layers[n].Id, (m_RegistryEnabledLayers & (1<<n)) ? BST_CHECKED : BST_UNCHECKED);
226
227 CheckDlgButton(hWnd, IDC_CHKRUNCOMPATIBILITY, m_RegistryOSMode ? BST_CHECKED : BST_UNCHECKED);
228
229 if (m_RegistryOSMode)
230 ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_COMPATIBILITYMODE), m_RegistryOSMode-1);
231
232 m_CustomLayers = m_RegistryCustomLayers;
233
234 /* TODO: visualize 'custom' layers! */
235
236 UpdateControls(hWnd);
237 }
238
239
240 static BOOL ArrayEquals(const CSimpleArray<CString>& lhs, const CSimpleArray<CString>& rhs)
241 {
242 if (lhs.GetSize() != rhs.GetSize())
243 return FALSE;
244
245 for (int n = 0; n < lhs.GetSize(); ++n)
246 {
247 if (lhs[n] != rhs[n])
248 return FALSE;
249 }
250 return TRUE;
251 }
252
253 BOOL CLayerUIPropPage::HasChanges() const
254 {
255 if (m_RegistryEnabledLayers != m_EnabledLayers)
256 return TRUE;
257
258 if (m_RegistryOSMode != m_OSMode)
259 return TRUE;
260
261 if (!ArrayEquals(m_RegistryCustomLayers, m_CustomLayers))
262 return TRUE;
263
264 return FALSE;
265 }
266
267 void CLayerUIPropPage::OnApply(HWND hWnd)
268 {
269 if (HasChanges())
270 {
271 BOOL bMachine = m_LayerQueryFlags == GPLK_MACHINE;
272
273 for (size_t n = 0; g_CompatModes[n].Name; ++n)
274 SetPermLayerState(m_Filename, g_CompatModes[n].Name, 0, bMachine, (n+1) == m_OSMode);
275
276 for (size_t n = 0; g_Layers[n].Name; ++n)
277 {
278 SetPermLayerState(m_Filename, g_Layers[n].Name, 0, bMachine, ((1<<n) & m_EnabledLayers) != 0);
279 }
280
281 /* Disable all old values */
282 for (int j = 0; j < m_RegistryCustomLayers.GetSize(); j++)
283 {
284 SetPermLayerState(m_Filename, m_RegistryCustomLayers[j].GetString(), 0, bMachine, FALSE);
285 }
286
287 /* Enable all new values */
288 for (int j = 0; j < m_CustomLayers.GetSize(); j++)
289 {
290 SetPermLayerState(m_Filename, m_CustomLayers[j].GetString(), 0, bMachine, TRUE);
291 }
292
293 SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATHW, (PCWSTR)m_Filename, NULL);
294 }
295 }
296
297 INT_PTR CLayerUIPropPage::InitDialog(HWND hWnd)
298 {
299 HWND cboMode = GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
300 for (size_t n = 0; g_CompatModes[n].Display; ++n)
301 ComboBox_AddString(cboMode, g_CompatModes[n].Display);
302 ComboBox_SetCurSel(cboMode, 5);
303
304 CComBSTR explanation;
305 if (!m_AllowPermLayer)
306 {
307 explanation.LoadString(g_hModule, IDS_FAILED_NETWORK);
308 DisableControls(hWnd);
309 ACDBG(L"AllowPermLayer returned FALSE\r\n");
310 }
311 else if (m_IsSfcProtected)
312 {
313 explanation.LoadString(g_hModule, IDS_FAILED_PROTECTED);
314 DisableControls(hWnd);
315 ACDBG(L"Protected OS file\r\n");
316 }
317 else
318 {
319 return TRUE;
320 }
321 SetDlgItemTextW(hWnd, IDC_EXPLANATION, explanation);
322 return TRUE;
323 }
324
325 INT_PTR CLayerUIPropPage::DisableControls(HWND hWnd)
326 {
327 EnableWindow(GetDlgItem(hWnd, IDC_COMPATIBILITYMODE), 0);
328 EnableWindow(GetDlgItem(hWnd, IDC_CHKRUNCOMPATIBILITY), 0);
329 for (size_t n = 0; g_Layers[n].Name; ++n)
330 EnableWindow(GetDlgItem(hWnd, g_Layers[n].Id), 0);
331 EnableWindow(GetDlgItem(hWnd, IDC_EDITCOMPATIBILITYMODES), 0);
332 return TRUE;
333 }
334
335 void CLayerUIPropPage::UpdateControls(HWND hWnd)
336 {
337 m_OSMode = 0, m_EnabledLayers = 0;
338 BOOL ModeEnabled = IsDlgButtonChecked(hWnd, IDC_CHKRUNCOMPATIBILITY);
339 if (ModeEnabled)
340 m_OSMode = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_COMPATIBILITYMODE))+1;
341 EnableWindow(GetDlgItem(hWnd, IDC_COMPATIBILITYMODE), ModeEnabled);
342
343 for (size_t n = 0; g_Layers[n].Name; ++n)
344 {
345 m_EnabledLayers |= IsDlgButtonChecked(hWnd, g_Layers[n].Id) ? (1<<n) : 0;
346 ShowWindow(GetDlgItem(hWnd, g_Layers[n].Id), SW_SHOW);
347 }
348
349 if (HasChanges())
350 {
351 PropSheet_Changed(GetParent(hWnd), hWnd);
352 }
353 else
354 {
355 PropSheet_UnChanged(GetParent(hWnd), hWnd);
356 }
357 }
358
359 INT_PTR CLayerUIPropPage::OnCommand(HWND hWnd, WORD id)
360 {
361 switch (id)
362 {
363 case IDC_CHKRUNCOMPATIBILITY:
364 UpdateControls(hWnd);
365 break;
366 case IDC_COMPATIBILITYMODE:
367 UpdateControls(hWnd);
368 break;
369 case IDC_CHKRUNIN256COLORS:
370 case IDC_CHKRUNIN640480RES:
371 case IDC_CHKDISABLEVISUALTHEMES:
372 UpdateControls(hWnd);
373 break;
374 case IDC_EDITCOMPATIBILITYMODES:
375 if (DialogBoxParam(g_hModule, MAKEINTRESOURCE(IDD_EDITCOMPATIBILITYMODES), hWnd, EditModesProc, (LPARAM)this) == IDOK)
376 {
377 UpdateControls(hWnd);
378 }
379 break;
380 }
381 return FALSE;
382 }
383
384 INT_PTR CALLBACK CLayerUIPropPage::PropDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
385 {
386 CLayerUIPropPage* page = NULL;
387
388 switch (uMsg)
389 {
390 case WM_INITDIALOG:
391 page = (CLayerUIPropPage*)((LPPROPSHEETPAGE)lParam)->lParam;
392 SetProp(hWnd, ACP_WNDPROP, page);
393 return page->InitDialog(hWnd);
394
395 case WM_ENDSESSION:
396 case WM_DESTROY:
397 page = (CLayerUIPropPage*)GetProp(hWnd, ACP_WNDPROP);
398 RemoveProp(hWnd, ACP_WNDPROP);
399 page->Release();
400 break;
401
402 case WM_COMMAND:
403 page = (CLayerUIPropPage*)GetProp(hWnd, ACP_WNDPROP);
404 return page->OnCommand(hWnd, LOWORD(wParam));
405 case WM_NOTIFY:
406 switch (((LPNMHDR)lParam)->code)
407 {
408 case PSN_SETACTIVE:
409 if (((LPNMHDR)lParam)->hwndFrom == GetParent(hWnd))
410 {
411 page = (CLayerUIPropPage*)GetProp(hWnd, ACP_WNDPROP);
412 page->OnRefresh(hWnd);
413 }
414 break;
415 case PSN_APPLY:
416 if (((LPNMHDR)lParam)->hwndFrom == GetParent(hWnd))
417 {
418 page = (CLayerUIPropPage*)GetProp(hWnd, ACP_WNDPROP);
419 page->OnApply(hWnd);
420 }
421 break;
422 case NM_CLICK:
423 case NM_RETURN:
424 if (((LPNMHDR)lParam)->idFrom == IDC_INFOLINK)
425 {
426 ShellExecute(NULL, L"open", L"https://www.reactos.org/forum/viewforum.php?f=4", NULL, NULL, SW_SHOW);
427 }
428 break;
429 default:
430 break;
431 }
432 break;
433 }
434
435 return FALSE;
436 }
437
438 static void ListboxChanged(HWND hWnd)
439 {
440 int Sel = ListBox_GetCurSel(GetDlgItem(hWnd, IDC_COMPATIBILITYMODE));
441 EnableWindow(GetDlgItem(hWnd, IDC_EDIT), Sel >= 0);
442 EnableWindow(GetDlgItem(hWnd, IDC_DELETE), Sel >= 0);
443 }
444
445 static void OnAdd(HWND hWnd)
446 {
447 HWND Combo = GetDlgItem(hWnd, IDC_NEWCOMPATIBILITYMODE);
448
449 int Length = ComboBox_GetTextLength(Combo);
450 CComBSTR Str(Length);
451 ComboBox_GetText(Combo, Str, Length+1);
452 HWND List = GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
453 int Index = ListBox_FindStringExact(List, -1, Str);
454 if (Index == LB_ERR)
455 Index = ListBox_AddString(List, Str);
456 ListBox_SetCurSel(List, Index);
457 ListboxChanged(hWnd);
458 ComboBox_SetText(Combo, TEXT(""));
459 SetFocus(Combo);
460 }
461
462 static BOOL ComboHasData(HWND hWnd)
463 {
464 HWND Combo = GetDlgItem(hWnd, IDC_NEWCOMPATIBILITYMODE);
465 if (ComboBox_GetCurSel(Combo) >= 0)
466 return TRUE;
467 ULONG Len = ComboBox_GetTextLength(Combo);
468 return Len > 0;
469 }
470
471 INT_PTR CALLBACK CLayerUIPropPage::EditModesProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
472 {
473 CLayerUIPropPage* page = NULL;
474
475 switch (uMsg)
476 {
477 case WM_INITDIALOG:
478 page = (CLayerUIPropPage*)lParam;
479 page->AddRef();
480 SetProp(hWnd, ACP_WNDPROP, page);
481 {
482 HWND Combo = GetDlgItem(hWnd, IDC_NEWCOMPATIBILITYMODE);
483 CComObject<CLayerStringList> pList;
484
485 while (TRUE)
486 {
487 CComBSTR str;
488 HRESULT hr = pList.Next(1, &str, NULL);
489 if (hr != S_OK)
490 break;
491 ComboBox_AddString(Combo, str);
492 }
493
494 HWND List = GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
495 for (int n = 0; n < page->m_CustomLayers.GetSize(); ++n)
496 {
497 const WCHAR* Str = page->m_CustomLayers[n].GetString();
498 int Index = ListBox_FindStringExact(List, -1, Str);
499 if (Index == LB_ERR)
500 Index = ListBox_AddString(List, Str);
501 }
502 }
503 break;
504 case WM_ENDSESSION:
505 case WM_DESTROY:
506 page = (CLayerUIPropPage*)GetProp(hWnd, ACP_WNDPROP);
507 RemoveProp(hWnd, ACP_WNDPROP);
508 page->Release();
509 break;
510
511 case WM_COMMAND:
512 switch(LOWORD(wParam))
513 {
514 case IDC_ADD:
515 OnAdd(hWnd);
516 break;
517 case IDC_EDIT:
518 {
519 HWND List = GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
520 int Cur = ListBox_GetCurSel(List);
521 int Length = ListBox_GetTextLen(List, Cur);
522 CComBSTR Str(Length);
523 ListBox_GetText(List, Cur, Str);
524 ListBox_DeleteString(List, Cur);
525 HWND Combo = GetDlgItem(hWnd, IDC_NEWCOMPATIBILITYMODE);
526 ComboBox_SetText(Combo, Str);
527 ListboxChanged(hWnd);
528 ComboBox_SetEditSel(Combo, 30000, 30000);
529 SetFocus(Combo);
530 }
531 break;
532 case IDC_DELETE:
533 {
534 HWND List = GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
535 ListBox_DeleteString(List, ListBox_GetCurSel(List));
536 ListboxChanged(hWnd);
537 }
538 break;
539 case IDC_COMPATIBILITYMODE:
540 ListboxChanged(hWnd);
541 break;
542 case IDC_NEWCOMPATIBILITYMODE:
543 {
544 EnableWindow(GetDlgItem(hWnd, IDC_ADD), ComboHasData(hWnd));
545 }
546 break;
547 case IDOK:
548 /* Copy from list! */
549 {
550 if (ComboHasData(hWnd))
551 {
552 CComBSTR question, title;
553 title.LoadString(g_hModule, IDS_TABTITLE);
554 question.LoadString(g_hModule, IDS_YOU_DID_NOT_ADD);
555 int result = MessageBoxW(hWnd, question, title, MB_YESNOCANCEL | MB_ICONQUESTION);
556 switch (result)
557 {
558 case IDYES:
559 OnAdd(hWnd);
560 break;
561 case IDNO:
562 break;
563 case IDCANCEL:
564 return FALSE;
565 }
566 }
567
568 page = (CLayerUIPropPage*)GetProp(hWnd, ACP_WNDPROP);
569
570 HWND List = GetDlgItem(hWnd, IDC_COMPATIBILITYMODE);
571 int Count = ListBox_GetCount(List);
572 page->m_CustomLayers.RemoveAll();
573 for (int Cur = 0; Cur < Count; ++Cur)
574 {
575 int Length = ListBox_GetTextLen(List, Cur);
576 CString Str;
577 LPWSTR Buffer = Str.GetBuffer(Length + 1);
578 ListBox_GetText(List, Cur, Buffer);
579 Str.ReleaseBuffer(Length);
580 page->m_CustomLayers.Add(Str);
581 }
582 }
583 /* Fall trough */
584 case IDCANCEL:
585 EndDialog(hWnd, LOWORD(wParam));
586 break;
587 }
588 break;
589 case WM_CLOSE:
590 EndDialog(hWnd, IDCANCEL);
591 break;
592 }
593 return FALSE;
594 }
595
596 static BOOL DisableShellext()
597 {
598 HKEY hkey;
599 LSTATUS ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Policies\\Microsoft\\Windows\\AppCompat", 0, KEY_QUERY_VALUE, &hkey);
600 BOOL Disable = FALSE;
601 if (ret == ERROR_SUCCESS)
602 {
603 DWORD dwValue = 0;
604 DWORD type, size = sizeof(dwValue);
605 ret = RegQueryValueExW(hkey, L"DisableEngine", NULL, &type, (PBYTE)&dwValue, &size);
606 if (ret == ERROR_SUCCESS && type == REG_DWORD)
607 {
608 Disable = !!dwValue;
609 }
610 if (!Disable)
611 {
612 size = sizeof(dwValue);
613 ret = RegQueryValueExW(hkey, L"DisablePropPage", NULL, &type, (PBYTE)&dwValue, &size);
614 if (ret == ERROR_SUCCESS && type == REG_DWORD)
615 {
616 Disable = !!dwValue;
617 }
618 }
619
620 RegCloseKey(hkey);
621 }
622 return Disable;
623 }
624
625 STDMETHODIMP CLayerUIPropPage::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hkeyProgID)
626 {
627 FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
628 STGMEDIUM stg;
629
630 if (DisableShellext())
631 return E_ACCESSDENIED;
632
633 HRESULT hr = pDataObj->GetData(&etc, &stg);
634 if (FAILED(hr))
635 {
636 ACDBG(L"Failed to retrieve Data from pDataObj.\r\n");
637 return E_INVALIDARG;
638 }
639 hr = E_FAIL;
640 HDROP hdrop = (HDROP)GlobalLock(stg.hGlobal);
641 if (hdrop)
642 {
643 UINT uNumFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, NULL, 0);
644 if (uNumFiles == 1)
645 {
646 WCHAR szFile[MAX_PATH * 2];
647 if (DragQueryFileW(hdrop, 0, szFile, _countof(szFile)))
648 {
649 this->AddRef();
650 hr = InitFile(szFile);
651 }
652 else
653 {
654 ACDBG(L"Failed to query the file.\r\n");
655 }
656 }
657 else
658 {
659 ACDBG(L"Invalid number of files: %d\r\n", uNumFiles);
660 }
661 GlobalUnlock(stg.hGlobal);
662 }
663 else
664 {
665 ACDBG(L"Could not lock stg.hGlobal\r\n");
666 }
667 ReleaseStgMedium(&stg);
668 return hr;
669 }
670
671 STDMETHODIMP CLayerUIPropPage::AddPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam)
672 {
673 PROPSHEETPAGEW psp = { 0 };
674 psp.dwSize = sizeof(psp);
675 psp.dwFlags = PSP_USEREFPARENT | PSP_USETITLE;
676 psp.hInstance = g_hModule;
677 psp.pszTemplate = MAKEINTRESOURCE(IDD_ACPPAGESHEET);
678 psp.pszTitle = MAKEINTRESOURCE(IDS_TABTITLE);
679 psp.pfnDlgProc = PropDlgProc;
680 psp.lParam = (LPARAM)this;
681 psp.pcRefParent = (PUINT)&g_ModuleRefCnt;
682 HPROPSHEETPAGE hPage = CreatePropertySheetPageW(&psp);
683 if (hPage && !pfnAddPage(hPage, lParam))
684 DestroyPropertySheetPage(hPage);
685
686 return S_OK;
687 }