1 /*
2  * PROJECT:     NT Object Namespace shell extension
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     NT Object Namespace folder class header
5  * COPYRIGHT:   Copyright 2015-2017 David Quintana <gigaherz@gmail.com>
6  */
7 
8 #pragma once
9 
10 extern const GUID CLSID_NtObjectFolder;
11 
12 class CNtObjectFolderExtractIcon :
13     public CComObjectRootEx<CComMultiThreadModelNoCS>,
14     public IExtractIconW
15 {
16     PCWSTR m_NtPath;
17     PCITEMID_CHILD    m_pcidlChild;
18 
19 public:
20     CNtObjectFolderExtractIcon();
21 
22     virtual ~CNtObjectFolderExtractIcon();
23 
24     HRESULT Initialize(LPCWSTR ntPath, PCIDLIST_ABSOLUTE parent, UINT cidl, PCUITEMID_CHILD_ARRAY apidl);
25 
26     STDMETHOD(GetIconLocation)(
27         UINT uFlags,
28         LPWSTR szIconFile,
29         UINT cchMax,
30         INT *piIndex,
31         UINT *pwFlags) override;
32 
33     STDMETHOD(Extract)(
34         LPCWSTR pszFile,
35         UINT nIconIndex,
36         HICON *phiconLarge,
37         HICON *phiconSmall,
38         UINT nIconSize) override;
39 
40     DECLARE_NOT_AGGREGATABLE(CNtObjectFolderExtractIcon)
41     DECLARE_PROTECT_FINAL_CONSTRUCT()
42 
43     BEGIN_COM_MAP(CNtObjectFolderExtractIcon)
44         COM_INTERFACE_ENTRY_IID(IID_IExtractIconW, IExtractIconW)
45     END_COM_MAP()
46 
47 };
48 
49 class CNtObjectFolder :
50     public CComCoClass<CNtObjectFolder, &CLSID_NtObjectFolder>,
51     public CCommonFolder<CNtObjectFolder, NtPidlEntry, CNtObjectFolderExtractIcon>
52 {
53 public:
54     DECLARE_REGISTRY_RESOURCEID(IDR_NTOBJECTFOLDER)
55 
56     CNtObjectFolder();
57     virtual ~CNtObjectFolder();
58 
59     // IShellFolder
60 
61     STDMETHOD(EnumObjects)(
62         HWND hwndOwner,
63         SHCONTF grfFlags,
64         IEnumIDList **ppenumIDList) override;
65 
66 protected:
67     STDMETHOD(InternalBindToObject)(
68         PWSTR path,
69         const NtPidlEntry * info,
70         LPITEMIDLIST first,
71         LPCITEMIDLIST rest,
72         LPITEMIDLIST fullPidl,
73         LPBC pbcReserved,
74         IShellFolder** ppsfChild) override;
75 
76     STDMETHOD(ResolveSymLink)(
77         const NtPidlEntry * info,
78         LPITEMIDLIST * fullPidl) override;
79 
80 public:
81     STDMETHOD(GetDefaultColumnState)(
82         UINT iColumn,
83         SHCOLSTATEF *pcsFlags) override;
84 
85     STDMETHOD(GetDetailsEx)(
86         LPCITEMIDLIST pidl,
87         const SHCOLUMNID *pscid,
88         VARIANT *pv) override;
89 
90     STDMETHOD(GetDetailsOf)(
91         LPCITEMIDLIST pidl,
92         UINT iColumn,
93         SHELLDETAILS *psd) override;
94 
95     STDMETHOD(MapColumnToSCID)(
96         UINT iColumn,
97         SHCOLUMNID *pscid) override;
98 
99     // IPersistFolder
100     STDMETHOD(Initialize)(PCIDLIST_ABSOLUTE pidl) override;
101 
102     // Internal
103     HRESULT STDMETHODCALLTYPE Initialize(PCIDLIST_ABSOLUTE pidl, PCWSTR ntPath);
104 
105 protected:
106     STDMETHOD(CompareIDs)(LPARAM lParam, const NtPidlEntry * first, const NtPidlEntry * second) override;
107     STDMETHOD_(ULONG, ConvertAttributes)(const NtPidlEntry * entry, PULONG inMask) override;
108     STDMETHOD_(BOOL, IsFolder)(const NtPidlEntry * info) override;
109     STDMETHOD_(BOOL, IsSymLink)(const NtPidlEntry * info) override;
110 
111     virtual HRESULT GetInfoFromPidl(LPCITEMIDLIST pcidl, const NtPidlEntry ** pentry);
112 
113     HRESULT FormatValueData(DWORD contentType, PVOID td, DWORD contentsLength, PCWSTR * strContents);
114 
115     HRESULT FormatContentsForDisplay(const NtPidlEntry * info, HKEY rootKey, LPCWSTR ntPath, PCWSTR * strContents);
116 };
117