[ADVAPI32] SEH-protext the calls to service control handlers
[reactos.git] / dll / shellext / shellbtrfs / iconoverlay.cpp
1 /* Copyright (c) Mark Harmstone 2016-17
2 *
3 * This file is part of WinBtrfs.
4 *
5 * WinBtrfs is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public Licence as published by
7 * the Free Software Foundation, either version 3 of the Licence, or
8 * (at your option) any later version.
9 *
10 * WinBtrfs is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public Licence for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public Licence
16 * along with WinBtrfs. If not, see <http://www.gnu.org/licenses/>. */
17
18 #include "shellext.h"
19 #ifndef __REACTOS__
20 #include <windows.h>
21 #include <winternl.h>
22 #else
23 #define WIN32_NO_STATUS
24 #include <windef.h>
25 #include <winbase.h>
26 #include <ndk/iofuncs.h>
27 #endif
28 #include "iconoverlay.h"
29 #ifndef __REACTOS__
30 #include "../btrfsioctl.h"
31 #else
32 #include "btrfsioctl.h"
33 #endif
34
35 HRESULT __stdcall BtrfsIconOverlay::QueryInterface(REFIID riid, void **ppObj) {
36 if (riid == IID_IUnknown || riid == IID_IShellIconOverlayIdentifier) {
37 *ppObj = static_cast<IShellIconOverlayIdentifier*>(this);
38 AddRef();
39 return S_OK;
40 }
41
42 *ppObj = NULL;
43 return E_NOINTERFACE;
44 }
45
46 HRESULT __stdcall BtrfsIconOverlay::GetOverlayInfo(PWSTR pwszIconFile, int cchMax, int* pIndex, DWORD* pdwFlags) {
47 WCHAR dllpath[MAX_PATH];
48
49 GetModuleFileNameW(module, dllpath, sizeof(dllpath));
50
51 if ((size_t)cchMax < wcslen(dllpath))
52 return E_INVALIDARG;
53
54 if (!pIndex)
55 return E_INVALIDARG;
56
57 if (!pdwFlags)
58 return E_INVALIDARG;
59
60 wcscpy(pwszIconFile, dllpath);
61 *pIndex = 0;
62 *pdwFlags = ISIOI_ICONFILE | ISIOI_ICONINDEX;
63
64 return S_OK;
65 }
66
67 HRESULT __stdcall BtrfsIconOverlay::GetPriority(int *pPriority) {
68 if (!pPriority)
69 return E_INVALIDARG;
70
71 *pPriority = 0;
72
73 return S_OK;
74 }
75
76 HRESULT __stdcall BtrfsIconOverlay::IsMemberOf(PCWSTR pwszPath, DWORD dwAttrib) {
77 HANDLE h;
78 NTSTATUS Status;
79 IO_STATUS_BLOCK iosb;
80 btrfs_get_file_ids bgfi;
81
82 h = CreateFileW(pwszPath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL);
83
84 if (h == INVALID_HANDLE_VALUE)
85 return S_FALSE;
86
87 Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_GET_FILE_IDS, NULL, 0, &bgfi, sizeof(btrfs_get_file_ids));
88
89 if (!NT_SUCCESS(Status)) {
90 CloseHandle(h);
91 return S_FALSE;
92 }
93
94 CloseHandle(h);
95
96 return (bgfi.inode == 0x100 && !bgfi.top) ? S_OK : S_FALSE;
97 }