4b69f282f7bf0f695487b9cd0f72b09f1f0c1d1e
[reactos.git] / dll / win32 / inseng / inseng_main.c
1 /*
2 * INSENG Implementation
3 *
4 * Copyright 2006 Mike McCormack
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 #define COBJMACROS
26
27 #include <config.h>
28
29 #include <stdarg.h>
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "ole2.h"
35 #include "rpcproxy.h"
36 #include "initguid.h"
37 #include "inseng.h"
38
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(inseng);
42
43 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc(size_t size)
44 {
45 return HeapAlloc(GetProcessHeap(), 0, size);
46 }
47
48 static inline BOOL heap_free(void *mem)
49 {
50 return HeapFree(GetProcessHeap(), 0, mem);
51 }
52
53 static HINSTANCE instance;
54
55 struct InstallEngine {
56 IInstallEngine2 IInstallEngine2_iface;
57 LONG ref;
58 };
59
60 static inline InstallEngine *impl_from_IInstallEngine2(IInstallEngine2 *iface)
61 {
62 return CONTAINING_RECORD(iface, InstallEngine, IInstallEngine2_iface);
63 }
64
65 static HRESULT WINAPI InstallEngine_QueryInterface(IInstallEngine2 *iface, REFIID riid, void **ppv)
66 {
67 InstallEngine *This = impl_from_IInstallEngine2(iface);
68
69 if(IsEqualGUID(&IID_IUnknown, riid)) {
70 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
71 *ppv = &This->IInstallEngine2_iface;
72 }else if(IsEqualGUID(&IID_IInstallEngine, riid)) {
73 TRACE("(%p)->(IID_IInstallEngine %p)\n", This, ppv);
74 *ppv = &This->IInstallEngine2_iface;
75 }else if(IsEqualGUID(&IID_IInstallEngine2, riid)) {
76 TRACE("(%p)->(IID_IInstallEngine2 %p)\n", This, ppv);
77 *ppv = &This->IInstallEngine2_iface;
78 }else {
79 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
80 *ppv = NULL;
81 return E_NOINTERFACE;
82 }
83
84 IUnknown_AddRef((IUnknown*)*ppv);
85 return S_OK;
86 }
87
88 static ULONG WINAPI InstallEngine_AddRef(IInstallEngine2 *iface)
89 {
90 InstallEngine *This = impl_from_IInstallEngine2(iface);
91 LONG ref = InterlockedIncrement(&This->ref);
92
93 TRACE("(%p) ref=%d\n", This, ref);
94
95 return ref;
96 }
97
98 static ULONG WINAPI InstallEngine_Release(IInstallEngine2 *iface)
99 {
100 InstallEngine *This = impl_from_IInstallEngine2(iface);
101 LONG ref = InterlockedDecrement(&This->ref);
102
103 TRACE("(%p) ref=%d\n", This, ref);
104
105 if(!ref)
106 heap_free(This);
107
108 return ref;
109 }
110
111 static HRESULT WINAPI InstallEngine_GetEngineStatus(IInstallEngine2 *iface, DWORD *status)
112 {
113 InstallEngine *This = impl_from_IInstallEngine2(iface);
114 FIXME("(%p)->(%p)\n", This, status);
115 return E_NOTIMPL;
116 }
117
118 static HRESULT WINAPI InstallEngine_SetCifFile(IInstallEngine2 *iface, const char *cab_name, const char *cif_name)
119 {
120 InstallEngine *This = impl_from_IInstallEngine2(iface);
121 FIXME("(%p)->(%s %s)\n", This, debugstr_a(cab_name), debugstr_a(cif_name));
122 return E_NOTIMPL;
123 }
124
125 static HRESULT WINAPI InstallEngine_DownloadComponents(IInstallEngine2 *iface, DWORD flags)
126 {
127 InstallEngine *This = impl_from_IInstallEngine2(iface);
128 FIXME("(%p)->(%x)\n", This, flags);
129 return E_NOTIMPL;
130 }
131
132 static HRESULT WINAPI InstallEngine_InstallComponents(IInstallEngine2 *iface, DWORD flags)
133 {
134 InstallEngine *This = impl_from_IInstallEngine2(iface);
135 FIXME("(%p)->(%x)\n", This, flags);
136 return E_NOTIMPL;
137 }
138
139 static HRESULT WINAPI InstallEngine_EnumInstallIDs(IInstallEngine2 *iface, UINT index, char **id)
140 {
141 InstallEngine *This = impl_from_IInstallEngine2(iface);
142 FIXME("(%p)->(%d %p)\n", This, index, id);
143 return E_NOTIMPL;
144 }
145
146 static HRESULT WINAPI InstallEngine_EnumDownloadIDs(IInstallEngine2 *iface, UINT index, char **id)
147 {
148 InstallEngine *This = impl_from_IInstallEngine2(iface);
149 FIXME("(%p)->(%d %p)\n", This, index, id);
150 return E_NOTIMPL;
151 }
152
153 static HRESULT WINAPI InstallEngine_IsComponentInstalled(IInstallEngine2 *iface, const char *id, DWORD *status)
154 {
155 InstallEngine *This = impl_from_IInstallEngine2(iface);
156 FIXME("(%p)->(%s %p)\n", This, debugstr_a(id), status);
157 return E_NOTIMPL;
158 }
159
160 static HRESULT WINAPI InstallEngine_RegisterInstallEngineCallback(IInstallEngine2 *iface, IInstallEngineCallback *callback)
161 {
162 InstallEngine *This = impl_from_IInstallEngine2(iface);
163 FIXME("(%p)->(%p)\n", This, callback);
164 return E_NOTIMPL;
165 }
166
167 static HRESULT WINAPI InstallEngine_UnregisterInstallEngineCallback(IInstallEngine2 *iface)
168 {
169 InstallEngine *This = impl_from_IInstallEngine2(iface);
170 FIXME("(%p)\n", This);
171 return E_NOTIMPL;
172 }
173
174 static HRESULT WINAPI InstallEngine_SetAction(IInstallEngine2 *iface, const char *id, DWORD action, DWORD priority)
175 {
176 InstallEngine *This = impl_from_IInstallEngine2(iface);
177 FIXME("(%p)->(%s %d %d)\n", This, debugstr_a(id), action, priority);
178 return E_NOTIMPL;
179 }
180
181 static HRESULT WINAPI InstallEngine_GetSizes(IInstallEngine2 *iface, const char *id, COMPONENT_SIZES *sizes)
182 {
183 InstallEngine *This = impl_from_IInstallEngine2(iface);
184 FIXME("(%p)->(%s %p)\n", This, debugstr_a(id), sizes);
185 return E_NOTIMPL;
186 }
187
188 static HRESULT WINAPI InstallEngine_LaunchExtraCommand(IInstallEngine2 *iface, const char *inf_name, const char *section)
189 {
190 InstallEngine *This = impl_from_IInstallEngine2(iface);
191 FIXME("(%p)->(%s %s)\n", This, debugstr_a(inf_name), debugstr_a(section));
192 return E_NOTIMPL;
193 }
194
195 static HRESULT WINAPI InstallEngine_GetDisplayName(IInstallEngine2 *iface, const char *id, const char *name)
196 {
197 InstallEngine *This = impl_from_IInstallEngine2(iface);
198 FIXME("(%p)->(%s %s)\n", This, debugstr_a(id), debugstr_a(name));
199 return E_NOTIMPL;
200 }
201
202 static HRESULT WINAPI InstallEngine_SetBaseUrl(IInstallEngine2 *iface, const char *base_name)
203 {
204 InstallEngine *This = impl_from_IInstallEngine2(iface);
205 FIXME("(%p)->(%s)\n", This, debugstr_a(base_name));
206 return E_NOTIMPL;
207 }
208
209 static HRESULT WINAPI InstallEngine_SetDownloadDir(IInstallEngine2 *iface, const char *download_dir)
210 {
211 InstallEngine *This = impl_from_IInstallEngine2(iface);
212 FIXME("(%p)->(%s)\n", This, debugstr_a(download_dir));
213 return E_NOTIMPL;
214 }
215
216 static HRESULT WINAPI InstallEngine_SetInstallDrive(IInstallEngine2 *iface, char drive)
217 {
218 InstallEngine *This = impl_from_IInstallEngine2(iface);
219 FIXME("(%p)->(%c)\n", This, drive);
220 return E_NOTIMPL;
221 }
222
223 static HRESULT WINAPI InstallEngine_SetInstallOptions(IInstallEngine2 *iface, DWORD flags)
224 {
225 InstallEngine *This = impl_from_IInstallEngine2(iface);
226 FIXME("(%p)->(%x)\n", This, flags);
227 return E_NOTIMPL;
228 }
229
230 static HRESULT WINAPI InstallEngine_SetHWND(IInstallEngine2 *iface, HWND hwnd)
231 {
232 InstallEngine *This = impl_from_IInstallEngine2(iface);
233 FIXME("(%p)->(%p)\n", This, hwnd);
234 return E_NOTIMPL;
235 }
236
237 static HRESULT WINAPI InstallEngine_SetIStream(IInstallEngine2 *iface, IStream *stream)
238 {
239 InstallEngine *This = impl_from_IInstallEngine2(iface);
240 FIXME("(%p)->(%p)\n", This, stream);
241 return E_NOTIMPL;
242 }
243
244 static HRESULT WINAPI InstallEngine_Abort(IInstallEngine2 *iface, DWORD flags)
245 {
246 InstallEngine *This = impl_from_IInstallEngine2(iface);
247 FIXME("(%p)->(%x)\n", This, flags);
248 return E_NOTIMPL;
249 }
250
251 static HRESULT WINAPI InstallEngine_Suspend(IInstallEngine2 *iface)
252 {
253 InstallEngine *This = impl_from_IInstallEngine2(iface);
254 FIXME("(%p)\n", This);
255 return E_NOTIMPL;
256 }
257
258 static HRESULT WINAPI InstallEngine_Resume(IInstallEngine2 *iface)
259 {
260 InstallEngine *This = impl_from_IInstallEngine2(iface);
261 FIXME("(%p)\n", This);
262 return E_NOTIMPL;
263 }
264
265 static HRESULT WINAPI InstallEngine2_SetLocalCif(IInstallEngine2 *iface, const char *cif)
266 {
267 InstallEngine *This = impl_from_IInstallEngine2(iface);
268 FIXME("(%p)->(%s)\n", This, debugstr_a(cif));
269 return E_NOTIMPL;
270 }
271
272 static HRESULT WINAPI InstallEngine2_GetICifFile(IInstallEngine2 *iface, ICifFile **cif_file)
273 {
274 InstallEngine *This = impl_from_IInstallEngine2(iface);
275 FIXME("(%p)->(%p)\n", This, cif_file);
276 return E_NOTIMPL;
277 }
278
279 static const IInstallEngine2Vtbl InstallEngine2Vtbl = {
280 InstallEngine_QueryInterface,
281 InstallEngine_AddRef,
282 InstallEngine_Release,
283 InstallEngine_GetEngineStatus,
284 InstallEngine_SetCifFile,
285 InstallEngine_DownloadComponents,
286 InstallEngine_InstallComponents,
287 InstallEngine_EnumInstallIDs,
288 InstallEngine_EnumDownloadIDs,
289 InstallEngine_IsComponentInstalled,
290 InstallEngine_RegisterInstallEngineCallback,
291 InstallEngine_UnregisterInstallEngineCallback,
292 InstallEngine_SetAction,
293 InstallEngine_GetSizes,
294 InstallEngine_LaunchExtraCommand,
295 InstallEngine_GetDisplayName,
296 InstallEngine_SetBaseUrl,
297 InstallEngine_SetDownloadDir,
298 InstallEngine_SetInstallDrive,
299 InstallEngine_SetInstallOptions,
300 InstallEngine_SetHWND,
301 InstallEngine_SetIStream,
302 InstallEngine_Abort,
303 InstallEngine_Suspend,
304 InstallEngine_Resume,
305 InstallEngine2_SetLocalCif,
306 InstallEngine2_GetICifFile
307 };
308
309 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
310 {
311 *ppv = NULL;
312
313 if(IsEqualGUID(&IID_IUnknown, riid)) {
314 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
315 *ppv = iface;
316 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
317 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
318 *ppv = iface;
319 }
320
321 if(*ppv) {
322 IUnknown_AddRef((IUnknown*)*ppv);
323 return S_OK;
324 }
325
326 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
327 return E_NOINTERFACE;
328 }
329
330 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
331 {
332 return 2;
333 }
334
335 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
336 {
337 return 1;
338 }
339
340 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
341 {
342 return S_OK;
343 }
344
345 static HRESULT WINAPI InstallEngineCF_CreateInstance(IClassFactory *iface, IUnknown *outer,
346 REFIID riid, void **ppv)
347 {
348 InstallEngine *engine;
349 HRESULT hres;
350
351 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
352
353 engine = heap_alloc(sizeof(*engine));
354 if(!engine)
355 return E_OUTOFMEMORY;
356
357 engine->IInstallEngine2_iface.lpVtbl = &InstallEngine2Vtbl;
358 engine->ref = 1;
359
360 hres = IInstallEngine2_QueryInterface(&engine->IInstallEngine2_iface, riid, ppv);
361 IInstallEngine2_Release(&engine->IInstallEngine2_iface);
362 return hres;
363 }
364
365 static const IClassFactoryVtbl InstallEngineCFVtbl = {
366 ClassFactory_QueryInterface,
367 ClassFactory_AddRef,
368 ClassFactory_Release,
369 InstallEngineCF_CreateInstance,
370 ClassFactory_LockServer
371 };
372
373 static IClassFactory InstallEngineCF = { &InstallEngineCFVtbl };
374
375 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
376 {
377 switch(fdwReason)
378 {
379 case DLL_WINE_PREATTACH:
380 return FALSE; /* prefer native version */
381 case DLL_PROCESS_ATTACH:
382 instance = hInstDLL;
383 DisableThreadLibraryCalls(hInstDLL);
384 break;
385 }
386 return TRUE;
387 }
388
389 /***********************************************************************
390 * DllGetClassObject (INSENG.@)
391 */
392 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
393 {
394 if(IsEqualGUID(rclsid, &CLSID_InstallEngine)) {
395 TRACE("(CLSID_InstallEngine %s %p)\n", debugstr_guid(iid), ppv);
396 return IClassFactory_QueryInterface(&InstallEngineCF, iid, ppv);
397 }
398
399 FIXME("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
400 return CLASS_E_CLASSNOTAVAILABLE;
401 }
402
403 /***********************************************************************
404 * DllCanUnloadNow (INSENG.@)
405 */
406 HRESULT WINAPI DllCanUnloadNow(void)
407 {
408 return S_FALSE;
409 }
410
411 /***********************************************************************
412 * DllRegisterServer (INSENG.@)
413 */
414 HRESULT WINAPI DllRegisterServer(void)
415 {
416 return __wine_register_resources( instance );
417 }
418
419 /***********************************************************************
420 * DllUnregisterServer (INSENG.@)
421 */
422 HRESULT WINAPI DllUnregisterServer(void)
423 {
424 return __wine_unregister_resources( instance );
425 }
426
427 BOOL WINAPI CheckTrustEx( LPVOID a, LPVOID b, LPVOID c, LPVOID d, LPVOID e )
428 {
429 FIXME("%p %p %p %p %p\n", a, b, c, d, e );
430 return TRUE;
431 }
432
433 /***********************************************************************
434 * DllInstall (INSENG.@)
435 */
436 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
437 {
438 FIXME("(%s, %s): stub\n", bInstall ? "TRUE" : "FALSE", debugstr_w(cmdline));
439 return S_OK;
440 }