-
Notifications
You must be signed in to change notification settings - Fork 2
/
OSGiExtensions.cpp
204 lines (177 loc) · 6.59 KB
/
OSGiExtensions.cpp
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
#include "stdafx.h"
#include "Bundle.h"
#include "BundleColumn.h"
#include "BundleTypeColumn.h"
#include "AliasColumn.h"
#ifndef PSFMTID_VERSION
DEFINE_GUID(PSFMTID_VERSION, 0x0CEF7D53, 0xFA64, 0x11D1, 0xA2, 0x03, 0x00, 0x00, 0xF8, 0x1F, 0xED, 0xEE);
#define PIDVSI_FileDescription 3
#define PIDVSI_FileVersion 4
#define PIDVSI_ProductName 7
#endif
class ATL_NO_VTABLE
DECLSPEC_UUID("d480098c-c50d-430e-bdec-aaab424078e5")
OSGiExtensions :
public ATL::CComObjectRootEx<ATL::CComSingleThreadModel>,
public ATL::CComCoClass<OSGiExtensions, &__uuidof(OSGiExtensions)>,
//public IStreamInit,
//public IQueryInfo,
//public IShellIconOverlayIdentifier
public IExtractIcon,
public IColumnProvider,
#ifdef IPropertyStore
public IPropertyStore,
public IInitWithStream,
public IInitWithFile,
#endif
public IPersistFile {
public:
BEGIN_COM_MAP(OSGiExtensions)
COM_INTERFACE_ENTRY(IPersistFile)
//COM_INTERFACE_ENTRY_IID(IID_IQueryInfo, IQueryInfo)
COM_INTERFACE_ENTRY_IID(IID_IColumnProvider, IColumnProvider)
COM_INTERFACE_ENTRY_IID(IID_IExtractIcon, IExtractIcon)
//COM_INTERFACE_ENTRY_IID(IID_IShellIconOverlayIdentifier, IShellIconOverlayIdentifier)
END_COM_MAP()
STDMETHODIMP GetClassID(LPCLSID) { ATLTRACENOTIMPL2(); }
STDMETHODIMP IsDirty() { ATLTRACENOTIMPL2(); }
/**
Called for before IQueryInfo methods.
*/
STDMETHODIMP Load(LPCOLESTR filename, DWORD) {
this->filename = filename;
return S_OK;
}
STDMETHODIMP Save(LPCOLESTR, BOOL) { ATLTRACENOTIMPL2(); }
STDMETHODIMP SaveCompleted(LPCOLESTR) { ATLTRACENOTIMPL2(); }
STDMETHODIMP GetCurFile(LPOLESTR*) { ATLTRACENOTIMPL2(); }
//
// IQueryInfo
//
STDMETHODIMP GetInfoFlags(DWORD*) { ATLTRACENOTIMPL2(); }
STDMETHODIMP GetInfoTip(DWORD flags, LPWSTR* text) {
ATLASSERT(!::IsBadWritePtr(text, sizeof(text)));
*text = 0;
return S_OK;
}
// IColumnProvider
STDMETHODIMP Initialize(LPCSHCOLUMNINIT psci) { return S_OK; }
Column* getColumn(int index) {
static BundleTypeColumn type;
static BundleColumn version("Bundle-Version", PSFMTID_VERSION, PIDVSI_FileVersion);
static BundleColumn author("Bundle-Author", FMTID_SummaryInformation, PIDSI_AUTHOR);
static BundleColumn name("Bundle-Name", PSFMTID_VERSION, PIDVSI_ProductName);
static AliasColumn name2(name, FMTID_SummaryInformation, PIDSI_TITLE);
static BundleColumn vendor("Bundle-Vendor", FMTID_DocSummaryInformation, PIDDSI_COMPANY);
static BundleColumn category("Bundle-Category", FMTID_DocSummaryInformation, PIDDSI_CATEGORY);
static BundleColumn contact("Bundle-ContactAddress", FMTID_DocSummaryInformation, PIDDSI_MANAGER);
static BundleColumn copyright("Bundle-Copyright", FMTID_MediaFileSummaryInformation, PIDMSI_COPYRIGHT);
static BundleColumn desc("Bundle-Description", PSFMTID_VERSION, PIDVSI_FileDescription);
// Add new columns here...
static Column* columns[] = {
&type, &version, &author, &name, &name2, &vendor, &category, &contact, ©right, &desc,
// ... and here.
};
static const int count = sizeof(columns) / sizeof(columns[0]);
if (index >= count) {
return 0;
}
return columns[index];
}
STDMETHODIMP GetColumnInfo(DWORD dwIndex, SHCOLUMNINFO* psci) {
ATLTRACEMETHOD();
Column* column = getColumn(dwIndex);
if (column) {
CopyMemory(psci, &column->getInfo(), sizeof(*psci));;
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP GetItemData(LPCSHCOLUMNID pscid, LPCSHCOLUMNDATA pscd, VARIANT* pvarData) {
ATLTRACEMETHOD();
if (pscd->dwFileAttributes & (/*FILE_ATTRIBUTE_DIRECTORY|*/FILE_ATTRIBUTE_OFFLINE)) {
return S_FALSE;
}
bool isManifest = lstrcmpW(pscd->pwszExt, L".MF") == 0;
if (lstrcmpiW(pscd->pwszExt, L".jar") != 0 && !isManifest && !(pscd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
return S_FALSE;
}
const org::osgi::framework::Bundle* bundle = cacheBundle(pscd->wszFile);
if (!bundle->isValid()) {
return S_FALSE;
}
ATL::CComVariant variant;
Column* column = getColumn(0);
int i=0;
while (column) {
if (column->equals(*pscid)) {
column->visit(*bundle, variant);
return variant.Detach(pvarData);
}
column = getColumn(++i);
}
return S_FALSE;
}
STDMETHODIMP GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags) {
GetModuleFileName(ATL::_pModule->GetResourceInstance(), pwszIconFile, cchMax);
*pIndex = 0;
*pdwFlags = ISIOI_ICONFILE | ISIOI_ICONINDEX;
return S_OK;
}
STDMETHODIMP GetPriority(int *pPriority) {
*pPriority = 0;
return S_OK;
}
STDMETHODIMP IsMemberOf(LPCWSTR pwszPath, DWORD dwAttrib) {
if (wcsstr(pwszPath, L".jar") != 0 ||
((dwAttrib & FILE_ATTRIBUTE_DIRECTORY) && (GetFileAttributes(ATL::CStringW(pwszPath) + L"/META-INF/MANIFEST.MF") != -1))) {
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP GetIconLocation(UINT uFlags, LPTSTR szIconFile, UINT cchMax,
int* piIndex, UINT* pwFlags) {
GetModuleFileName(ATL::_pModule->GetResourceInstance(), szIconFile, cchMax);
const org::osgi::framework::Bundle* bundle = cacheBundle(filename);
if (bundle->isValid()) {
if (bundle->isFragment()) {
*piIndex = 2;
} else if (bundle->hasServiceComponents()) {
*piIndex = 0;
} else {
*piIndex = 1;
}
*pwFlags = 0;
} else {
return S_FALSE;
}
return S_OK;
}
STDMETHODIMP Extract(LPCWSTR,UINT,HICON *,HICON *,UINT) {
return S_FALSE;
}
DECLARE_PROTECT_FINAL_CONSTRUCT()
DECLARE_REGISTRY_RESOURCEID(IDR_OSGI_BUNDLE);
private:
const org::osgi::framework::Bundle* cacheBundle(LPCWSTR path) {
const int index = bundleCache.FindKey(path);
if (index != -1) {
return bundleCache.GetValueAt(index);
}
org::osgi::framework::Bundle* bundle = new org::osgi::framework::Bundle(path);
if (!bundle->isValid()) {
delete bundle;
bundle = &invalidBundleCacheEntry;
}
bundleCache.Add(path, bundle);
return bundle;
}
class InvalidBundleCacheEntry : public org::osgi::framework::Bundle {
public:
InvalidBundleCacheEntry() : org::osgi::framework::Bundle(L"") {
}
}invalidBundleCacheEntry;
ATL::CSimpleMap<ATL::CStringW, org::osgi::framework::Bundle*> bundleCache;
ATL::CStringW filename;
};
OBJECT_ENTRY_AUTO(__uuidof(OSGiExtensions), OSGiExtensions)