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 #include <windows.h>
20 #include "factory.h"
21 #include "iconoverlay.h"
22 #include "contextmenu.h"
23 #include "propsheet.h"
24 #include "volpropsheet.h"
25
QueryInterface(const IID & iid,void ** ppv)26 HRESULT __stdcall Factory::QueryInterface(const IID& iid, void** ppv) {
27 if (iid == IID_IUnknown || iid == IID_IClassFactory) {
28 *ppv = static_cast<IClassFactory*>(this);
29 } else {
30 *ppv = nullptr;
31 return E_NOINTERFACE;
32 }
33
34 reinterpret_cast<IUnknown*>(*ppv)->AddRef();
35
36 return S_OK;
37 }
38
LockServer(BOOL bLock)39 HRESULT __stdcall Factory::LockServer(BOOL bLock) {
40 return E_NOTIMPL;
41 }
42
CreateInstance(IUnknown * pUnknownOuter,const IID & iid,void ** ppv)43 HRESULT __stdcall Factory::CreateInstance(IUnknown* pUnknownOuter, const IID& iid, void** ppv) {
44 if (pUnknownOuter)
45 return CLASS_E_NOAGGREGATION;
46
47 switch (type) {
48 case FactoryIconHandler:
49 if (iid == IID_IUnknown || iid == IID_IShellIconOverlayIdentifier) {
50 BtrfsIconOverlay* bio = new BtrfsIconOverlay;
51 if (!bio)
52 return E_OUTOFMEMORY;
53
54 return bio->QueryInterface(iid, ppv);
55 }
56 break;
57
58 case FactoryContextMenu:
59 if (iid == IID_IUnknown || iid == IID_IContextMenu || iid == IID_IShellExtInit) {
60 BtrfsContextMenu* bcm = new BtrfsContextMenu;
61 if (!bcm)
62 return E_OUTOFMEMORY;
63
64 return bcm->QueryInterface(iid, ppv);
65 }
66 break;
67
68 case FactoryPropSheet:
69 if (iid == IID_IUnknown || iid == IID_IShellPropSheetExt || iid == IID_IShellExtInit) {
70 BtrfsPropSheet* bps = new BtrfsPropSheet;
71 if (!bps)
72 return E_OUTOFMEMORY;
73
74 return bps->QueryInterface(iid, ppv);
75 }
76 break;
77
78 case FactoryVolPropSheet:
79 if (iid == IID_IUnknown || iid == IID_IShellPropSheetExt || iid == IID_IShellExtInit) {
80 BtrfsVolPropSheet* bps = new BtrfsVolPropSheet;
81 if (!bps)
82 return E_OUTOFMEMORY;
83
84 return bps->QueryInterface(iid, ppv);
85 }
86 break;
87
88 default:
89 break;
90 }
91
92 *ppv = nullptr;
93 return E_NOINTERFACE;
94 }
95