e57d1be164fdcae6355cd8d14ca6fad6d5b89cd6
[reactos.git] / reactos / dll / win32 / msi / classes.c
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
3 *
4 * Copyright 2005 Aric Stewart for CodeWeavers
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 /* Actions handled in this module:
22 *
23 * RegisterClassInfo
24 * RegisterProgIdInfo
25 * RegisterExtensionInfo
26 * RegisterMIMEInfo
27 * UnregisterClassInfo
28 * UnregisterProgIdInfo
29 * UnregisterExtensionInfo
30 * UnregisterMIMEInfo
31 */
32
33 #define WIN32_NO_STATUS
34 #define _INC_WINDOWS
35 #define COM_NO_WINDOWS_H
36
37 //#include <stdarg.h>
38
39 #include <windef.h>
40 //#include "winbase.h"
41 //#include "winerror.h"
42 #include <winreg.h>
43 #include <wine/debug.h>
44 #include "msipriv.h"
45 //#include "winuser.h"
46 #include <wine/unicode.h>
47
48 WINE_DEFAULT_DEBUG_CHANNEL(msi);
49
50 static MSIAPPID *load_appid( MSIPACKAGE* package, MSIRECORD *row )
51 {
52 LPCWSTR buffer;
53 MSIAPPID *appid;
54
55 /* fill in the data */
56
57 appid = msi_alloc_zero( sizeof(MSIAPPID) );
58 if (!appid)
59 return NULL;
60
61 appid->AppID = msi_dup_record_field( row, 1 );
62 TRACE("loading appid %s\n", debugstr_w( appid->AppID ));
63
64 buffer = MSI_RecordGetString(row,2);
65 deformat_string( package, buffer, &appid->RemoteServerName );
66
67 appid->LocalServer = msi_dup_record_field(row,3);
68 appid->ServiceParameters = msi_dup_record_field(row,4);
69 appid->DllSurrogate = msi_dup_record_field(row,5);
70
71 appid->ActivateAtStorage = !MSI_RecordIsNull(row,6);
72 appid->RunAsInteractiveUser = !MSI_RecordIsNull(row,7);
73
74 list_add_tail( &package->appids, &appid->entry );
75
76 return appid;
77 }
78
79 static MSIAPPID *load_given_appid( MSIPACKAGE *package, LPCWSTR name )
80 {
81 static const WCHAR query[] = {
82 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
83 '`','A','p','p','I','d','`',' ','W','H','E','R','E',' ',
84 '`','A','p','p','I','d','`',' ','=',' ','\'','%','s','\'',0};
85 MSIRECORD *row;
86 MSIAPPID *appid;
87
88 if (!name)
89 return NULL;
90
91 /* check for appids already loaded */
92 LIST_FOR_EACH_ENTRY( appid, &package->appids, MSIAPPID, entry )
93 {
94 if (!strcmpiW( appid->AppID, name ))
95 {
96 TRACE("found appid %s %p\n", debugstr_w(name), appid);
97 return appid;
98 }
99 }
100
101 row = MSI_QueryGetRecord(package->db, query, name);
102 if (!row)
103 return NULL;
104
105 appid = load_appid(package, row);
106 msiobj_release(&row->hdr);
107 return appid;
108 }
109
110 static MSIPROGID *load_given_progid(MSIPACKAGE *package, LPCWSTR progid);
111 static MSICLASS *load_given_class( MSIPACKAGE *package, LPCWSTR classid );
112
113 static MSIPROGID *load_progid( MSIPACKAGE* package, MSIRECORD *row )
114 {
115 MSIPROGID *progid;
116 LPCWSTR buffer;
117
118 /* fill in the data */
119
120 progid = msi_alloc_zero( sizeof(MSIPROGID) );
121 if (!progid)
122 return NULL;
123
124 list_add_tail( &package->progids, &progid->entry );
125
126 progid->ProgID = msi_dup_record_field(row,1);
127 TRACE("loading progid %s\n",debugstr_w(progid->ProgID));
128
129 buffer = MSI_RecordGetString(row,2);
130 progid->Parent = load_given_progid(package,buffer);
131 if (progid->Parent == NULL && buffer)
132 FIXME("Unknown parent ProgID %s\n",debugstr_w(buffer));
133
134 buffer = MSI_RecordGetString(row,3);
135 progid->Class = load_given_class(package,buffer);
136 if (progid->Class == NULL && buffer)
137 FIXME("Unknown class %s\n",debugstr_w(buffer));
138
139 progid->Description = msi_dup_record_field(row,4);
140
141 if (!MSI_RecordIsNull(row,6))
142 {
143 INT icon_index = MSI_RecordGetInteger(row,6);
144 LPCWSTR FileName = MSI_RecordGetString(row,5);
145 LPWSTR FilePath;
146 static const WCHAR fmt[] = {'%','s',',','%','i',0};
147
148 FilePath = msi_build_icon_path(package, FileName);
149
150 progid->IconPath = msi_alloc( (strlenW(FilePath)+10)* sizeof(WCHAR) );
151
152 sprintfW(progid->IconPath,fmt,FilePath,icon_index);
153
154 msi_free(FilePath);
155 }
156 else
157 {
158 buffer = MSI_RecordGetString(row,5);
159 if (buffer)
160 progid->IconPath = msi_build_icon_path(package, buffer);
161 }
162
163 progid->CurVer = NULL;
164 progid->VersionInd = NULL;
165
166 /* if we have a parent then we may be that parents CurVer */
167 if (progid->Parent && progid->Parent != progid)
168 {
169 MSIPROGID *parent = progid->Parent;
170
171 while (parent->Parent && parent->Parent != parent)
172 parent = parent->Parent;
173
174 /* FIXME: need to determine if we are really the CurVer */
175
176 progid->CurVer = parent;
177 parent->VersionInd = progid;
178 }
179
180 return progid;
181 }
182
183 static MSIPROGID *load_given_progid(MSIPACKAGE *package, LPCWSTR name)
184 {
185 static const WCHAR query[] = {
186 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
187 '`','P','r','o','g','I','d','`',' ','W','H','E','R','E',' ',
188 '`','P','r','o','g','I','d','`',' ','=',' ','\'','%','s','\'',0};
189 MSIPROGID *progid;
190 MSIRECORD *row;
191
192 if (!name)
193 return NULL;
194
195 /* check for progids already loaded */
196 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
197 {
198 if (!strcmpiW( progid->ProgID, name ))
199 {
200 TRACE("found progid %s (%p)\n",debugstr_w(name), progid );
201 return progid;
202 }
203 }
204
205 row = MSI_QueryGetRecord( package->db, query, name );
206 if (!row)
207 return NULL;
208
209 progid = load_progid(package, row);
210 msiobj_release(&row->hdr);
211 return progid;
212 }
213
214 static MSICLASS *load_class( MSIPACKAGE* package, MSIRECORD *row )
215 {
216 MSICLASS *cls;
217 DWORD i;
218 LPCWSTR buffer;
219
220 /* fill in the data */
221
222 cls = msi_alloc_zero( sizeof(MSICLASS) );
223 if (!cls)
224 return NULL;
225
226 list_add_tail( &package->classes, &cls->entry );
227
228 cls->clsid = msi_dup_record_field( row, 1 );
229 TRACE("loading class %s\n",debugstr_w(cls->clsid));
230 cls->Context = msi_dup_record_field( row, 2 );
231 buffer = MSI_RecordGetString(row,3);
232 cls->Component = msi_get_loaded_component( package, buffer );
233
234 cls->ProgIDText = msi_dup_record_field(row,4);
235 cls->ProgID = load_given_progid(package, cls->ProgIDText);
236
237 cls->Description = msi_dup_record_field(row,5);
238
239 buffer = MSI_RecordGetString(row,6);
240 if (buffer)
241 cls->AppID = load_given_appid(package, buffer);
242
243 cls->FileTypeMask = msi_dup_record_field(row,7);
244
245 if (!MSI_RecordIsNull(row,9))
246 {
247
248 INT icon_index = MSI_RecordGetInteger(row,9);
249 LPCWSTR FileName = MSI_RecordGetString(row,8);
250 LPWSTR FilePath;
251 static const WCHAR fmt[] = {'%','s',',','%','i',0};
252
253 FilePath = msi_build_icon_path(package, FileName);
254
255 cls->IconPath = msi_alloc( (strlenW(FilePath)+5)* sizeof(WCHAR) );
256
257 sprintfW(cls->IconPath,fmt,FilePath,icon_index);
258
259 msi_free(FilePath);
260 }
261 else
262 {
263 buffer = MSI_RecordGetString(row,8);
264 if (buffer)
265 cls->IconPath = msi_build_icon_path(package, buffer);
266 }
267
268 if (!MSI_RecordIsNull(row,10))
269 {
270 i = MSI_RecordGetInteger(row,10);
271 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
272 {
273 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
274 static const WCHAR ole32[] = {'o','l','e','3','2','.','d','l','l',0};
275
276 switch(i)
277 {
278 case 1:
279 cls->DefInprocHandler = strdupW(ole2);
280 break;
281 case 2:
282 cls->DefInprocHandler32 = strdupW(ole32);
283 break;
284 case 3:
285 cls->DefInprocHandler = strdupW(ole2);
286 cls->DefInprocHandler32 = strdupW(ole32);
287 break;
288 }
289 }
290 else
291 {
292 cls->DefInprocHandler32 = msi_dup_record_field( row, 10 );
293 msi_reduce_to_long_filename( cls->DefInprocHandler32 );
294 }
295 }
296 buffer = MSI_RecordGetString(row,11);
297 deformat_string(package,buffer,&cls->Argument);
298
299 buffer = MSI_RecordGetString(row,12);
300 cls->Feature = msi_get_loaded_feature(package, buffer);
301
302 cls->Attributes = MSI_RecordGetInteger(row,13);
303
304 return cls;
305 }
306
307 /*
308 * the Class table has 3 primary keys. Generally it is only
309 * referenced through the first CLSID key. However when loading
310 * all of the classes we need to make sure we do not ignore rows
311 * with other Context and ComponentIndexs
312 */
313 static MSICLASS *load_given_class(MSIPACKAGE *package, LPCWSTR classid)
314 {
315 static const WCHAR query[] = {
316 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
317 '`','C','l','a','s','s','`',' ','W','H','E','R','E',' ',
318 '`','C','L','S','I','D','`',' ','=',' ','\'','%','s','\'',0};
319 MSICLASS *cls;
320 MSIRECORD *row;
321
322 if (!classid)
323 return NULL;
324
325 /* check for classes already loaded */
326 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
327 {
328 if (!strcmpiW( cls->clsid, classid ))
329 {
330 TRACE("found class %s (%p)\n",debugstr_w(classid), cls);
331 return cls;
332 }
333 }
334
335 row = MSI_QueryGetRecord(package->db, query, classid);
336 if (!row)
337 return NULL;
338
339 cls = load_class(package, row);
340 msiobj_release(&row->hdr);
341 return cls;
342 }
343
344 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR extension );
345
346 static MSIMIME *load_mime( MSIPACKAGE* package, MSIRECORD *row )
347 {
348 LPCWSTR extension;
349 MSIMIME *mt;
350
351 /* fill in the data */
352
353 mt = msi_alloc_zero( sizeof(MSIMIME) );
354 if (!mt)
355 return mt;
356
357 mt->ContentType = msi_dup_record_field( row, 1 );
358 TRACE("loading mime %s\n", debugstr_w(mt->ContentType));
359
360 extension = MSI_RecordGetString( row, 2 );
361 mt->Extension = load_given_extension( package, extension );
362 mt->suffix = strdupW( extension );
363
364 mt->clsid = msi_dup_record_field( row, 3 );
365 mt->Class = load_given_class( package, mt->clsid );
366
367 list_add_tail( &package->mimes, &mt->entry );
368
369 return mt;
370 }
371
372 static MSIMIME *load_given_mime( MSIPACKAGE *package, LPCWSTR mime )
373 {
374 static const WCHAR query[] = {
375 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
376 '`','M','I','M','E','`',' ','W','H','E','R','E',' ',
377 '`','C','o','n','t','e','n','t','T','y','p','e','`',' ','=',' ','\'','%','s','\'',0};
378 MSIRECORD *row;
379 MSIMIME *mt;
380
381 if (!mime)
382 return NULL;
383
384 /* check for mime already loaded */
385 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
386 {
387 if (!strcmpiW( mt->ContentType, mime ))
388 {
389 TRACE("found mime %s (%p)\n",debugstr_w(mime), mt);
390 return mt;
391 }
392 }
393
394 row = MSI_QueryGetRecord(package->db, query, mime);
395 if (!row)
396 return NULL;
397
398 mt = load_mime(package, row);
399 msiobj_release(&row->hdr);
400 return mt;
401 }
402
403 static MSIEXTENSION *load_extension( MSIPACKAGE* package, MSIRECORD *row )
404 {
405 MSIEXTENSION *ext;
406 LPCWSTR buffer;
407
408 /* fill in the data */
409
410 ext = msi_alloc_zero( sizeof(MSIEXTENSION) );
411 if (!ext)
412 return NULL;
413
414 list_init( &ext->verbs );
415
416 list_add_tail( &package->extensions, &ext->entry );
417
418 ext->Extension = msi_dup_record_field( row, 1 );
419 TRACE("loading extension %s\n", debugstr_w(ext->Extension));
420
421 buffer = MSI_RecordGetString( row, 2 );
422 ext->Component = msi_get_loaded_component( package, buffer );
423
424 ext->ProgIDText = msi_dup_record_field( row, 3 );
425 ext->ProgID = load_given_progid( package, ext->ProgIDText );
426
427 buffer = MSI_RecordGetString( row, 4 );
428 ext->Mime = load_given_mime( package, buffer );
429
430 buffer = MSI_RecordGetString(row,5);
431 ext->Feature = msi_get_loaded_feature( package, buffer );
432
433 return ext;
434 }
435
436 /*
437 * While the extension table has 2 primary keys, this function is only looking
438 * at the Extension key which is what is referenced as a foreign key
439 */
440 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR name )
441 {
442 static const WCHAR query[] = {
443 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
444 '`','E','x','t','e','n','s','i','o','n','`',' ','W','H','E','R','E',' ',
445 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ','\'','%','s','\'',0};
446 MSIEXTENSION *ext;
447 MSIRECORD *row;
448
449 if (!name)
450 return NULL;
451
452 if (name[0] == '.')
453 name++;
454
455 /* check for extensions already loaded */
456 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
457 {
458 if (!strcmpiW( ext->Extension, name ))
459 {
460 TRACE("extension %s already loaded %p\n", debugstr_w(name), ext);
461 return ext;
462 }
463 }
464
465 row = MSI_QueryGetRecord( package->db, query, name );
466 if (!row)
467 return NULL;
468
469 ext = load_extension(package, row);
470 msiobj_release(&row->hdr);
471 return ext;
472 }
473
474 static UINT iterate_load_verb(MSIRECORD *row, LPVOID param)
475 {
476 MSIPACKAGE* package = param;
477 MSIVERB *verb;
478 LPCWSTR buffer;
479 MSIEXTENSION *extension;
480
481 buffer = MSI_RecordGetString(row,1);
482 extension = load_given_extension( package, buffer );
483 if (!extension)
484 {
485 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer));
486 return ERROR_SUCCESS;
487 }
488
489 /* fill in the data */
490
491 verb = msi_alloc_zero( sizeof(MSIVERB) );
492 if (!verb)
493 return ERROR_OUTOFMEMORY;
494
495 verb->Verb = msi_dup_record_field(row,2);
496 TRACE("loading verb %s\n",debugstr_w(verb->Verb));
497 verb->Sequence = MSI_RecordGetInteger(row,3);
498
499 buffer = MSI_RecordGetString(row,4);
500 deformat_string(package,buffer,&verb->Command);
501
502 buffer = MSI_RecordGetString(row,5);
503 deformat_string(package,buffer,&verb->Argument);
504
505 /* associate the verb with the correct extension */
506 list_add_tail( &extension->verbs, &verb->entry );
507
508 return ERROR_SUCCESS;
509 }
510
511 static UINT iterate_all_classes(MSIRECORD *rec, LPVOID param)
512 {
513 MSICOMPONENT *comp;
514 LPCWSTR clsid;
515 LPCWSTR context;
516 LPCWSTR buffer;
517 MSIPACKAGE* package = param;
518 MSICLASS *cls;
519 BOOL match = FALSE;
520
521 clsid = MSI_RecordGetString(rec,1);
522 context = MSI_RecordGetString(rec,2);
523 buffer = MSI_RecordGetString(rec,3);
524 comp = msi_get_loaded_component(package, buffer);
525
526 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
527 {
528 if (strcmpiW( clsid, cls->clsid ))
529 continue;
530 if (strcmpW( context, cls->Context ))
531 continue;
532 if (comp == cls->Component)
533 {
534 match = TRUE;
535 break;
536 }
537 }
538
539 if (!match)
540 load_class(package, rec);
541
542 return ERROR_SUCCESS;
543 }
544
545 static UINT load_all_classes( MSIPACKAGE *package )
546 {
547 static const WCHAR query[] = {
548 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ','`','C','l','a','s','s','`',0};
549 MSIQUERY *view;
550 UINT rc;
551
552 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
553 if (rc != ERROR_SUCCESS)
554 return ERROR_SUCCESS;
555
556 rc = MSI_IterateRecords(view, NULL, iterate_all_classes, package);
557 msiobj_release(&view->hdr);
558 return rc;
559 }
560
561 static UINT iterate_all_extensions(MSIRECORD *rec, LPVOID param)
562 {
563 MSICOMPONENT *comp;
564 LPCWSTR buffer;
565 LPCWSTR extension;
566 MSIPACKAGE* package = param;
567 BOOL match = FALSE;
568 MSIEXTENSION *ext;
569
570 extension = MSI_RecordGetString(rec,1);
571 buffer = MSI_RecordGetString(rec,2);
572 comp = msi_get_loaded_component(package, buffer);
573
574 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
575 {
576 if (strcmpiW(extension, ext->Extension))
577 continue;
578 if (comp == ext->Component)
579 {
580 match = TRUE;
581 break;
582 }
583 }
584
585 if (!match)
586 load_extension(package, rec);
587
588 return ERROR_SUCCESS;
589 }
590
591 static UINT load_all_extensions( MSIPACKAGE *package )
592 {
593 static const WCHAR query[] = {
594 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','E','x','t','e','n','s','i','o','n','`',0};
595 MSIQUERY *view;
596 UINT rc;
597
598 rc = MSI_DatabaseOpenViewW( package->db, query, &view );
599 if (rc != ERROR_SUCCESS)
600 return ERROR_SUCCESS;
601
602 rc = MSI_IterateRecords(view, NULL, iterate_all_extensions, package);
603 msiobj_release(&view->hdr);
604 return rc;
605 }
606
607 static UINT iterate_all_progids(MSIRECORD *rec, LPVOID param)
608 {
609 LPCWSTR buffer;
610 MSIPACKAGE* package = param;
611
612 buffer = MSI_RecordGetString(rec,1);
613 load_given_progid(package,buffer);
614 return ERROR_SUCCESS;
615 }
616
617 static UINT load_all_progids( MSIPACKAGE *package )
618 {
619 static const WCHAR query[] = {
620 'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ','F','R','O','M',' ',
621 '`','P','r','o','g','I','d','`',0};
622 MSIQUERY *view;
623 UINT rc;
624
625 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
626 if (rc != ERROR_SUCCESS)
627 return ERROR_SUCCESS;
628
629 rc = MSI_IterateRecords(view, NULL, iterate_all_progids, package);
630 msiobj_release(&view->hdr);
631 return rc;
632 }
633
634 static UINT load_all_verbs( MSIPACKAGE *package )
635 {
636 static const WCHAR query[] = {
637 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','V','e','r','b','`',0};
638 MSIQUERY *view;
639 UINT rc;
640
641 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
642 if (rc != ERROR_SUCCESS)
643 return ERROR_SUCCESS;
644
645 rc = MSI_IterateRecords(view, NULL, iterate_load_verb, package);
646 msiobj_release(&view->hdr);
647 return rc;
648 }
649
650 static UINT iterate_all_mimes(MSIRECORD *rec, LPVOID param)
651 {
652 LPCWSTR buffer;
653 MSIPACKAGE* package = param;
654
655 buffer = MSI_RecordGetString(rec,1);
656 load_given_mime(package,buffer);
657 return ERROR_SUCCESS;
658 }
659
660 static UINT load_all_mimes( MSIPACKAGE *package )
661 {
662 static const WCHAR query[] = {
663 'S','E','L','E','C','T',' ','`','C','o','n','t','e','n','t','T','y','p','e','`',' ',
664 'F','R','O','M',' ','`','M','I','M','E','`',0};
665 MSIQUERY *view;
666 UINT rc;
667
668 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
669 if (rc != ERROR_SUCCESS)
670 return ERROR_SUCCESS;
671
672 rc = MSI_IterateRecords(view, NULL, iterate_all_mimes, package);
673 msiobj_release(&view->hdr);
674 return rc;
675 }
676
677 static UINT load_classes_and_such( MSIPACKAGE *package )
678 {
679 UINT r;
680
681 TRACE("Loading all the class info and related tables\n");
682
683 /* check if already loaded */
684 if (!list_empty( &package->classes ) ||
685 !list_empty( &package->mimes ) ||
686 !list_empty( &package->extensions ) ||
687 !list_empty( &package->progids )) return ERROR_SUCCESS;
688
689 r = load_all_classes( package );
690 if (r != ERROR_SUCCESS) return r;
691
692 r = load_all_extensions( package );
693 if (r != ERROR_SUCCESS) return r;
694
695 r = load_all_progids( package );
696 if (r != ERROR_SUCCESS) return r;
697
698 /* these loads must come after the other loads */
699 r = load_all_verbs( package );
700 if (r != ERROR_SUCCESS) return r;
701
702 return load_all_mimes( package );
703 }
704
705 static void mark_progid_for_install( MSIPACKAGE* package, MSIPROGID *progid )
706 {
707 MSIPROGID *child;
708
709 if (!progid)
710 return;
711
712 if (progid->InstallMe)
713 return;
714
715 progid->InstallMe = TRUE;
716
717 /* all children if this is a parent also install */
718 LIST_FOR_EACH_ENTRY( child, &package->progids, MSIPROGID, entry )
719 {
720 if (child->Parent == progid)
721 mark_progid_for_install( package, child );
722 }
723 }
724
725 static void mark_progid_for_uninstall( MSIPACKAGE *package, MSIPROGID *progid )
726 {
727 MSIPROGID *child;
728
729 if (!progid)
730 return;
731
732 if (!progid->InstallMe)
733 return;
734
735 progid->InstallMe = FALSE;
736
737 LIST_FOR_EACH_ENTRY( child, &package->progids, MSIPROGID, entry )
738 {
739 if (child->Parent == progid)
740 mark_progid_for_uninstall( package, child );
741 }
742 }
743
744 static void mark_mime_for_install( MSIMIME *mime )
745 {
746 if (!mime)
747 return;
748 mime->InstallMe = TRUE;
749 }
750
751 static void mark_mime_for_uninstall( MSIMIME *mime )
752 {
753 if (!mime)
754 return;
755 mime->InstallMe = FALSE;
756 }
757
758 static UINT register_appid(const MSIAPPID *appid, LPCWSTR app )
759 {
760 static const WCHAR szRemoteServerName[] =
761 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
762 static const WCHAR szLocalService[] =
763 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
764 static const WCHAR szService[] =
765 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
766 static const WCHAR szDLL[] =
767 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
768 static const WCHAR szActivate[] =
769 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
770 static const WCHAR szY[] = {'Y',0};
771 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
772 static const WCHAR szUser[] =
773 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
774
775 HKEY hkey2,hkey3;
776
777 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
778 RegCreateKeyW( hkey2, appid->AppID, &hkey3 );
779 RegCloseKey(hkey2);
780 msi_reg_set_val_str( hkey3, NULL, app );
781
782 if (appid->RemoteServerName)
783 msi_reg_set_val_str( hkey3, szRemoteServerName, appid->RemoteServerName );
784
785 if (appid->LocalServer)
786 msi_reg_set_val_str( hkey3, szLocalService, appid->LocalServer );
787
788 if (appid->ServiceParameters)
789 msi_reg_set_val_str( hkey3, szService, appid->ServiceParameters );
790
791 if (appid->DllSurrogate)
792 msi_reg_set_val_str( hkey3, szDLL, appid->DllSurrogate );
793
794 if (appid->ActivateAtStorage)
795 msi_reg_set_val_str( hkey3, szActivate, szY );
796
797 if (appid->RunAsInteractiveUser)
798 msi_reg_set_val_str( hkey3, szRunAs, szUser );
799
800 RegCloseKey(hkey3);
801 return ERROR_SUCCESS;
802 }
803
804 UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
805 {
806 static const WCHAR szFileType_fmt[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
807 const WCHAR *keypath;
808 MSIRECORD *uirow;
809 HKEY hkey, hkey2, hkey3;
810 MSICLASS *cls;
811 UINT r;
812
813 r = load_classes_and_such( package );
814 if (r != ERROR_SUCCESS)
815 return r;
816
817 if (is_64bit && package->platform == PLATFORM_INTEL)
818 keypath = szWow6432NodeCLSID;
819 else
820 keypath = szCLSID;
821
822 if (RegCreateKeyW(HKEY_CLASSES_ROOT, keypath, &hkey) != ERROR_SUCCESS)
823 return ERROR_FUNCTION_FAILED;
824
825 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
826 {
827 MSICOMPONENT *comp;
828 MSIFILE *file;
829 DWORD size;
830 LPWSTR argument;
831 MSIFEATURE *feature;
832
833 comp = cls->Component;
834 if ( !comp )
835 continue;
836
837 if (!comp->Enabled)
838 {
839 TRACE("component is disabled\n");
840 continue;
841 }
842
843 feature = cls->Feature;
844 if (!feature)
845 continue;
846
847 feature->Action = msi_get_feature_action( package, feature );
848 if (feature->Action != INSTALLSTATE_LOCAL &&
849 feature->Action != INSTALLSTATE_ADVERTISED )
850 {
851 TRACE("feature %s not scheduled for installation, skipping registration of class %s\n",
852 debugstr_w(feature->Feature), debugstr_w(cls->clsid));
853 continue;
854 }
855
856 if (!comp->KeyPath || !(file = msi_get_loaded_file( package, comp->KeyPath )))
857 {
858 TRACE("COM server not provided, skipping class %s\n", debugstr_w(cls->clsid));
859 continue;
860 }
861 TRACE("Registering class %s (%p)\n", debugstr_w(cls->clsid), cls);
862
863 cls->Installed = TRUE;
864 mark_progid_for_install( package, cls->ProgID );
865
866 RegCreateKeyW( hkey, cls->clsid, &hkey2 );
867
868 if (cls->Description)
869 msi_reg_set_val_str( hkey2, NULL, cls->Description );
870
871 RegCreateKeyW( hkey2, cls->Context, &hkey3 );
872
873 /*
874 * FIXME: Implement install on demand (advertised components).
875 *
876 * ole32.dll should call msi.MsiProvideComponentFromDescriptor()
877 * when it needs an InProcServer that doesn't exist.
878 * The component advertise string should be in the "InProcServer" value.
879 */
880 size = lstrlenW( file->TargetPath )+1;
881 if (cls->Argument)
882 size += lstrlenW(cls->Argument)+1;
883
884 argument = msi_alloc( size * sizeof(WCHAR) );
885 lstrcpyW( argument, file->TargetPath );
886
887 if (cls->Argument)
888 {
889 lstrcatW( argument, szSpace );
890 lstrcatW( argument, cls->Argument );
891 }
892
893 msi_reg_set_val_str( hkey3, NULL, argument );
894 msi_free(argument);
895
896 RegCloseKey(hkey3);
897
898 if (cls->ProgID || cls->ProgIDText)
899 {
900 LPCWSTR progid;
901
902 if (cls->ProgID)
903 progid = cls->ProgID->ProgID;
904 else
905 progid = cls->ProgIDText;
906
907 msi_reg_set_subkey_val( hkey2, szProgID, NULL, progid );
908
909 if (cls->ProgID && cls->ProgID->VersionInd)
910 {
911 msi_reg_set_subkey_val( hkey2, szVIProgID, NULL,
912 cls->ProgID->VersionInd->ProgID );
913 }
914 }
915
916 if (cls->AppID)
917 {
918 MSIAPPID *appid = cls->AppID;
919 msi_reg_set_val_str( hkey2, szAppID, appid->AppID );
920 register_appid( appid, cls->Description );
921 }
922
923 if (cls->IconPath)
924 msi_reg_set_subkey_val( hkey2, szDefaultIcon, NULL, cls->IconPath );
925
926 if (cls->DefInprocHandler)
927 msi_reg_set_subkey_val( hkey2, szInprocHandler, NULL, cls->DefInprocHandler );
928
929 if (cls->DefInprocHandler32)
930 msi_reg_set_subkey_val( hkey2, szInprocHandler32, NULL, cls->DefInprocHandler32 );
931
932 RegCloseKey(hkey2);
933
934 /* if there is a FileTypeMask, register the FileType */
935 if (cls->FileTypeMask)
936 {
937 LPWSTR ptr, ptr2;
938 LPWSTR keyname;
939 INT index = 0;
940 ptr = cls->FileTypeMask;
941 while (ptr && *ptr)
942 {
943 ptr2 = strchrW(ptr,';');
944 if (ptr2)
945 *ptr2 = 0;
946 keyname = msi_alloc( (strlenW(szFileType_fmt) + strlenW(cls->clsid) + 4) * sizeof(WCHAR));
947 sprintfW( keyname, szFileType_fmt, cls->clsid, index );
948
949 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, ptr );
950 msi_free(keyname);
951
952 if (ptr2)
953 ptr = ptr2+1;
954 else
955 ptr = NULL;
956
957 index ++;
958 }
959 }
960
961 uirow = MSI_CreateRecord(1);
962 MSI_RecordSetStringW( uirow, 1, cls->clsid );
963 msi_ui_actiondata( package, szRegisterClassInfo, uirow );
964 msiobj_release(&uirow->hdr);
965 }
966 RegCloseKey(hkey);
967 return ERROR_SUCCESS;
968 }
969
970 UINT ACTION_UnregisterClassInfo( MSIPACKAGE *package )
971 {
972 static const WCHAR szFileType[] = {'F','i','l','e','T','y','p','e','\\',0};
973 const WCHAR *keypath;
974 MSIRECORD *uirow;
975 MSICLASS *cls;
976 HKEY hkey, hkey2;
977 UINT r;
978
979 r = load_classes_and_such( package );
980 if (r != ERROR_SUCCESS)
981 return r;
982
983 if (is_64bit && package->platform == PLATFORM_INTEL)
984 keypath = szWow6432NodeCLSID;
985 else
986 keypath = szCLSID;
987
988 if (RegOpenKeyW( HKEY_CLASSES_ROOT, keypath, &hkey ) != ERROR_SUCCESS)
989 return ERROR_SUCCESS;
990
991 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
992 {
993 MSIFEATURE *feature;
994 MSICOMPONENT *comp;
995 LPWSTR filetype;
996 LONG res;
997
998 comp = cls->Component;
999 if (!comp)
1000 continue;
1001
1002 if (!comp->Enabled)
1003 {
1004 TRACE("component is disabled\n");
1005 continue;
1006 }
1007
1008 feature = cls->Feature;
1009 if (!feature)
1010 continue;
1011
1012 feature->Action = msi_get_feature_action( package, feature );
1013 if (feature->Action != INSTALLSTATE_ABSENT)
1014 {
1015 TRACE("feature %s not scheduled for removal, skipping unregistration of class %s\n",
1016 debugstr_w(feature->Feature), debugstr_w(cls->clsid));
1017 continue;
1018 }
1019 TRACE("Unregistering class %s (%p)\n", debugstr_w(cls->clsid), cls);
1020
1021 cls->Installed = FALSE;
1022 mark_progid_for_uninstall( package, cls->ProgID );
1023
1024 res = RegDeleteTreeW( hkey, cls->clsid );
1025 if (res != ERROR_SUCCESS)
1026 WARN("Failed to delete class key %d\n", res);
1027
1028 if (cls->AppID)
1029 {
1030 res = RegOpenKeyW( HKEY_CLASSES_ROOT, szAppID, &hkey2 );
1031 if (res == ERROR_SUCCESS)
1032 {
1033 res = RegDeleteKeyW( hkey2, cls->AppID->AppID );
1034 if (res != ERROR_SUCCESS)
1035 WARN("Failed to delete appid key %d\n", res);
1036 RegCloseKey( hkey2 );
1037 }
1038 }
1039 if (cls->FileTypeMask)
1040 {
1041 filetype = msi_alloc( (strlenW( szFileType ) + strlenW( cls->clsid ) + 1) * sizeof(WCHAR) );
1042 if (filetype)
1043 {
1044 strcpyW( filetype, szFileType );
1045 strcatW( filetype, cls->clsid );
1046 res = RegDeleteTreeW( HKEY_CLASSES_ROOT, filetype );
1047 msi_free( filetype );
1048
1049 if (res != ERROR_SUCCESS)
1050 WARN("Failed to delete file type %d\n", res);
1051 }
1052 }
1053
1054 uirow = MSI_CreateRecord( 1 );
1055 MSI_RecordSetStringW( uirow, 1, cls->clsid );
1056 msi_ui_actiondata( package, szUnregisterClassInfo, uirow );
1057 msiobj_release( &uirow->hdr );
1058 }
1059 RegCloseKey( hkey );
1060 return ERROR_SUCCESS;
1061 }
1062
1063 static LPCWSTR get_clsid_of_progid( const MSIPROGID *progid )
1064 {
1065 while (progid)
1066 {
1067 if (progid->Class)
1068 return progid->Class->clsid;
1069 if (progid->Parent == progid)
1070 break;
1071 progid = progid->Parent;
1072 }
1073 return NULL;
1074 }
1075
1076 static UINT register_progid( const MSIPROGID* progid )
1077 {
1078 static const WCHAR szCurVer[] = {'C','u','r','V','e','r',0};
1079 HKEY hkey = 0;
1080 UINT rc;
1081
1082 rc = RegCreateKeyW( HKEY_CLASSES_ROOT, progid->ProgID, &hkey );
1083 if (rc == ERROR_SUCCESS)
1084 {
1085 LPCWSTR clsid = get_clsid_of_progid( progid );
1086
1087 if (clsid)
1088 msi_reg_set_subkey_val( hkey, szCLSID, NULL, clsid );
1089 else
1090 TRACE("%s has no class\n", debugstr_w( progid->ProgID ) );
1091
1092 if (progid->Description)
1093 msi_reg_set_val_str( hkey, NULL, progid->Description );
1094
1095 if (progid->IconPath)
1096 msi_reg_set_subkey_val( hkey, szDefaultIcon, NULL, progid->IconPath );
1097
1098 /* write out the current version */
1099 if (progid->CurVer)
1100 msi_reg_set_subkey_val( hkey, szCurVer, NULL, progid->CurVer->ProgID );
1101
1102 RegCloseKey(hkey);
1103 }
1104 else
1105 ERR("failed to create key %s\n", debugstr_w( progid->ProgID ) );
1106
1107 return rc;
1108 }
1109
1110 UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
1111 {
1112 MSIPROGID *progid;
1113 MSIRECORD *uirow;
1114 UINT r;
1115
1116 r = load_classes_and_such( package );
1117 if (r != ERROR_SUCCESS)
1118 return r;
1119
1120 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
1121 {
1122 /* check if this progid is to be installed */
1123 if (progid->Class && progid->Class->Installed)
1124 progid->InstallMe = TRUE;
1125
1126 if (!progid->InstallMe)
1127 {
1128 TRACE("progid %s not scheduled to be installed\n",
1129 debugstr_w(progid->ProgID));
1130 continue;
1131 }
1132
1133 TRACE("Registering progid %s\n", debugstr_w(progid->ProgID));
1134
1135 register_progid( progid );
1136
1137 uirow = MSI_CreateRecord( 1 );
1138 MSI_RecordSetStringW( uirow, 1, progid->ProgID );
1139 msi_ui_actiondata( package, szRegisterProgIdInfo, uirow );
1140 msiobj_release( &uirow->hdr );
1141 }
1142 return ERROR_SUCCESS;
1143 }
1144
1145 UINT ACTION_UnregisterProgIdInfo( MSIPACKAGE *package )
1146 {
1147 MSIPROGID *progid;
1148 MSIRECORD *uirow;
1149 LONG res;
1150 UINT r;
1151
1152 r = load_classes_and_such( package );
1153 if (r != ERROR_SUCCESS)
1154 return r;
1155
1156 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
1157 {
1158 /* check if this progid is to be removed */
1159 if (progid->Class && !progid->Class->Installed)
1160 progid->InstallMe = FALSE;
1161
1162 if (progid->InstallMe)
1163 {
1164 TRACE("progid %s not scheduled to be removed\n", debugstr_w(progid->ProgID));
1165 continue;
1166 }
1167
1168 TRACE("Unregistering progid %s\n", debugstr_w(progid->ProgID));
1169
1170 res = RegDeleteTreeW( HKEY_CLASSES_ROOT, progid->ProgID );
1171 if (res != ERROR_SUCCESS)
1172 TRACE("Failed to delete progid key %d\n", res);
1173
1174 uirow = MSI_CreateRecord( 1 );
1175 MSI_RecordSetStringW( uirow, 1, progid->ProgID );
1176 msi_ui_actiondata( package, szUnregisterProgIdInfo, uirow );
1177 msiobj_release( &uirow->hdr );
1178 }
1179 return ERROR_SUCCESS;
1180 }
1181
1182 static UINT register_verb(MSIPACKAGE *package, LPCWSTR progid,
1183 MSICOMPONENT* component, const MSIEXTENSION* extension,
1184 MSIVERB* verb, INT* Sequence )
1185 {
1186 LPWSTR keyname;
1187 HKEY key;
1188 static const WCHAR szShell[] = {'s','h','e','l','l',0};
1189 static const WCHAR szCommand[] = {'c','o','m','m','a','n','d',0};
1190 static const WCHAR fmt[] = {'\"','%','s','\"',' ','%','s',0};
1191 static const WCHAR fmt2[] = {'\"','%','s','\"',0};
1192 LPWSTR command;
1193 DWORD size;
1194 LPWSTR advertise;
1195
1196 keyname = msi_build_directory_name(4, progid, szShell, verb->Verb, szCommand);
1197
1198 TRACE("Making Key %s\n",debugstr_w(keyname));
1199 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
1200 size = strlenW(component->FullKeypath);
1201 if (verb->Argument)
1202 size += strlenW(verb->Argument);
1203 size += 4;
1204
1205 command = msi_alloc(size * sizeof (WCHAR));
1206 if (verb->Argument)
1207 sprintfW(command, fmt, component->FullKeypath, verb->Argument);
1208 else
1209 sprintfW(command, fmt2, component->FullKeypath);
1210
1211 msi_reg_set_val_str( key, NULL, command );
1212 msi_free(command);
1213
1214 advertise = msi_create_component_advertise_string(package, component,
1215 extension->Feature->Feature);
1216 size = strlenW(advertise);
1217
1218 if (verb->Argument)
1219 size += strlenW(verb->Argument);
1220 size += 4;
1221
1222 command = msi_alloc_zero(size * sizeof (WCHAR));
1223
1224 strcpyW(command,advertise);
1225 if (verb->Argument)
1226 {
1227 strcatW(command,szSpace);
1228 strcatW(command,verb->Argument);
1229 }
1230
1231 msi_reg_set_val_multi_str( key, szCommand, command );
1232
1233 RegCloseKey(key);
1234 msi_free(keyname);
1235 msi_free(advertise);
1236 msi_free(command);
1237
1238 if (verb->Command)
1239 {
1240 keyname = msi_build_directory_name( 3, progid, szShell, verb->Verb );
1241 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, verb->Command );
1242 msi_free(keyname);
1243 }
1244
1245 if (verb->Sequence != MSI_NULL_INTEGER)
1246 {
1247 if (*Sequence == MSI_NULL_INTEGER || verb->Sequence < *Sequence)
1248 {
1249 *Sequence = verb->Sequence;
1250 keyname = msi_build_directory_name( 2, progid, szShell );
1251 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, verb->Verb );
1252 msi_free(keyname);
1253 }
1254 }
1255 return ERROR_SUCCESS;
1256 }
1257
1258 UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
1259 {
1260 static const WCHAR szContentType[] = {'C','o','n','t','e','n','t',' ','T','y','p','e',0};
1261 HKEY hkey = NULL;
1262 MSIEXTENSION *ext;
1263 MSIRECORD *uirow;
1264 BOOL install_on_demand = TRUE;
1265 LONG res;
1266 UINT r;
1267
1268 r = load_classes_and_such( package );
1269 if (r != ERROR_SUCCESS)
1270 return r;
1271
1272 /* We need to set install_on_demand based on if the shell handles advertised
1273 * shortcuts and the like. Because Mike McCormack is working on this i am
1274 * going to default to TRUE
1275 */
1276
1277 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
1278 {
1279 LPWSTR extension;
1280 MSIFEATURE *feature;
1281
1282 if (!ext->Component)
1283 continue;
1284
1285 if (!ext->Component->Enabled)
1286 {
1287 TRACE("component is disabled\n");
1288 continue;
1289 }
1290
1291 feature = ext->Feature;
1292 if (!feature)
1293 continue;
1294
1295 /*
1296 * yes. MSDN says that these are based on _Feature_ not on
1297 * Component. So verify the feature is to be installed
1298 */
1299 feature->Action = msi_get_feature_action( package, feature );
1300 if (feature->Action != INSTALLSTATE_LOCAL &&
1301 !(install_on_demand && feature->Action == INSTALLSTATE_ADVERTISED))
1302 {
1303 TRACE("feature %s not scheduled for installation, skipping registration of extension %s\n",
1304 debugstr_w(feature->Feature), debugstr_w(ext->Extension));
1305 continue;
1306 }
1307 TRACE("Registering extension %s (%p)\n", debugstr_w(ext->Extension), ext);
1308
1309 ext->Installed = TRUE;
1310
1311 /* this is only registered if the extension has at least 1 verb
1312 * according to MSDN
1313 */
1314 if (ext->ProgID && !list_empty( &ext->verbs ) )
1315 mark_progid_for_install( package, ext->ProgID );
1316
1317 mark_mime_for_install(ext->Mime);
1318
1319 extension = msi_alloc( (strlenW( ext->Extension ) + 2) * sizeof(WCHAR) );
1320 if (extension)
1321 {
1322 extension[0] = '.';
1323 strcpyW( extension + 1, ext->Extension );
1324 res = RegCreateKeyW( HKEY_CLASSES_ROOT, extension, &hkey );
1325 msi_free( extension );
1326 if (res != ERROR_SUCCESS)
1327 WARN("Failed to create extension key %d\n", res);
1328 }
1329
1330 if (ext->Mime)
1331 msi_reg_set_val_str( hkey, szContentType, ext->Mime->ContentType );
1332
1333 if (ext->ProgID || ext->ProgIDText)
1334 {
1335 static const WCHAR szSN[] =
1336 {'\\','S','h','e','l','l','N','e','w',0};
1337 HKEY hkey2;
1338 LPWSTR newkey;
1339 LPCWSTR progid;
1340 MSIVERB *verb;
1341 INT Sequence = MSI_NULL_INTEGER;
1342
1343 if (ext->ProgID)
1344 progid = ext->ProgID->ProgID;
1345 else
1346 progid = ext->ProgIDText;
1347
1348 msi_reg_set_val_str( hkey, NULL, progid );
1349
1350 newkey = msi_alloc( (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
1351
1352 strcpyW(newkey,progid);
1353 strcatW(newkey,szSN);
1354 RegCreateKeyW(hkey,newkey,&hkey2);
1355 RegCloseKey(hkey2);
1356
1357 msi_free(newkey);
1358
1359 /* do all the verbs */
1360 LIST_FOR_EACH_ENTRY( verb, &ext->verbs, MSIVERB, entry )
1361 {
1362 register_verb( package, progid, ext->Component,
1363 ext, verb, &Sequence);
1364 }
1365 }
1366
1367 RegCloseKey(hkey);
1368
1369 uirow = MSI_CreateRecord(1);
1370 MSI_RecordSetStringW( uirow, 1, ext->Extension );
1371 msi_ui_actiondata( package, szRegisterExtensionInfo, uirow );
1372 msiobj_release(&uirow->hdr);
1373 }
1374 return ERROR_SUCCESS;
1375 }
1376
1377 UINT ACTION_UnregisterExtensionInfo( MSIPACKAGE *package )
1378 {
1379 MSIEXTENSION *ext;
1380 MSIRECORD *uirow;
1381 LONG res;
1382 UINT r;
1383
1384 r = load_classes_and_such( package );
1385 if (r != ERROR_SUCCESS)
1386 return r;
1387
1388 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
1389 {
1390 LPWSTR extension;
1391 MSIFEATURE *feature;
1392
1393 if (!ext->Component)
1394 continue;
1395
1396 if (!ext->Component->Enabled)
1397 {
1398 TRACE("component is disabled\n");
1399 continue;
1400 }
1401
1402 feature = ext->Feature;
1403 if (!feature)
1404 continue;
1405
1406 feature->Action = msi_get_feature_action( package, feature );
1407 if (feature->Action != INSTALLSTATE_ABSENT)
1408 {
1409 TRACE("feature %s not scheduled for removal, skipping unregistration of extension %s\n",
1410 debugstr_w(feature->Feature), debugstr_w(ext->Extension));
1411 continue;
1412 }
1413 TRACE("Unregistering extension %s\n", debugstr_w(ext->Extension));
1414
1415 ext->Installed = FALSE;
1416
1417 if (ext->ProgID && !list_empty( &ext->verbs ))
1418 mark_progid_for_uninstall( package, ext->ProgID );
1419
1420 mark_mime_for_uninstall( ext->Mime );
1421
1422 extension = msi_alloc( (strlenW( ext->Extension ) + 2) * sizeof(WCHAR) );
1423 if (extension)
1424 {
1425 extension[0] = '.';
1426 strcpyW( extension + 1, ext->Extension );
1427 res = RegDeleteTreeW( HKEY_CLASSES_ROOT, extension );
1428 msi_free( extension );
1429 if (res != ERROR_SUCCESS)
1430 WARN("Failed to delete extension key %d\n", res);
1431 }
1432
1433 if (ext->ProgID || ext->ProgIDText)
1434 {
1435 static const WCHAR shellW[] = {'\\','s','h','e','l','l',0};
1436 LPCWSTR progid;
1437 LPWSTR progid_shell;
1438
1439 if (ext->ProgID)
1440 progid = ext->ProgID->ProgID;
1441 else
1442 progid = ext->ProgIDText;
1443
1444 progid_shell = msi_alloc( (strlenW( progid ) + strlenW( shellW ) + 1) * sizeof(WCHAR) );
1445 if (progid_shell)
1446 {
1447 strcpyW( progid_shell, progid );
1448 strcatW( progid_shell, shellW );
1449 res = RegDeleteTreeW( HKEY_CLASSES_ROOT, progid_shell );
1450 msi_free( progid_shell );
1451 if (res != ERROR_SUCCESS)
1452 WARN("Failed to delete shell key %d\n", res);
1453 RegDeleteKeyW( HKEY_CLASSES_ROOT, progid );
1454 }
1455 }
1456
1457 uirow = MSI_CreateRecord( 1 );
1458 MSI_RecordSetStringW( uirow, 1, ext->Extension );
1459 msi_ui_actiondata( package, szUnregisterExtensionInfo, uirow );
1460 msiobj_release( &uirow->hdr );
1461 }
1462 return ERROR_SUCCESS;
1463 }
1464
1465 UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
1466 {
1467 static const WCHAR szExtension[] = {'E','x','t','e','n','s','i','o','n',0};
1468 MSIRECORD *uirow;
1469 MSIMIME *mt;
1470 UINT r;
1471
1472 r = load_classes_and_such( package );
1473 if (r != ERROR_SUCCESS)
1474 return r;
1475
1476 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
1477 {
1478 LPWSTR extension, key;
1479
1480 /*
1481 * check if the MIME is to be installed. Either as requested by an
1482 * extension or Class
1483 */
1484 mt->InstallMe = (mt->InstallMe ||
1485 (mt->Class && mt->Class->Installed) ||
1486 (mt->Extension && mt->Extension->Installed));
1487
1488 if (!mt->InstallMe)
1489 {
1490 TRACE("MIME %s not scheduled to be installed\n", debugstr_w(mt->ContentType));
1491 continue;
1492 }
1493
1494 TRACE("Registering MIME type %s\n", debugstr_w(mt->ContentType));
1495
1496 extension = msi_alloc( (strlenW( mt->Extension->Extension ) + 2) * sizeof(WCHAR) );
1497 key = msi_alloc( (strlenW( mt->ContentType ) + strlenW( szMIMEDatabase ) + 1) * sizeof(WCHAR) );
1498
1499 if (extension && key)
1500 {
1501 extension[0] = '.';
1502 strcpyW( extension + 1, mt->Extension->Extension );
1503
1504 strcpyW( key, szMIMEDatabase );
1505 strcatW( key, mt->ContentType );
1506 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, key, szExtension, extension );
1507
1508 if (mt->clsid)
1509 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, key, szCLSID, mt->clsid );
1510 }
1511 msi_free( extension );
1512 msi_free( key );
1513
1514 uirow = MSI_CreateRecord( 2 );
1515 MSI_RecordSetStringW( uirow, 1, mt->ContentType );
1516 MSI_RecordSetStringW( uirow, 2, mt->suffix );
1517 msi_ui_actiondata( package, szRegisterMIMEInfo, uirow );
1518 msiobj_release( &uirow->hdr );
1519 }
1520 return ERROR_SUCCESS;
1521 }
1522
1523 UINT ACTION_UnregisterMIMEInfo( MSIPACKAGE *package )
1524 {
1525 MSIRECORD *uirow;
1526 MSIMIME *mime;
1527 UINT r;
1528
1529 r = load_classes_and_such( package );
1530 if (r != ERROR_SUCCESS)
1531 return r;
1532
1533 LIST_FOR_EACH_ENTRY( mime, &package->mimes, MSIMIME, entry )
1534 {
1535 LONG res;
1536 LPWSTR mime_key;
1537
1538 mime->InstallMe = (mime->InstallMe ||
1539 (mime->Class && mime->Class->Installed) ||
1540 (mime->Extension && mime->Extension->Installed));
1541
1542 if (mime->InstallMe)
1543 {
1544 TRACE("MIME %s not scheduled to be removed\n", debugstr_w(mime->ContentType));
1545 continue;
1546 }
1547
1548 TRACE("Unregistering MIME type %s\n", debugstr_w(mime->ContentType));
1549
1550 mime_key = msi_alloc( (strlenW( szMIMEDatabase ) + strlenW( mime->ContentType ) + 1) * sizeof(WCHAR) );
1551 if (mime_key)
1552 {
1553 strcpyW( mime_key, szMIMEDatabase );
1554 strcatW( mime_key, mime->ContentType );
1555 res = RegDeleteKeyW( HKEY_CLASSES_ROOT, mime_key );
1556 if (res != ERROR_SUCCESS)
1557 WARN("Failed to delete MIME key %d\n", res);
1558 msi_free( mime_key );
1559 }
1560
1561 uirow = MSI_CreateRecord( 2 );
1562 MSI_RecordSetStringW( uirow, 1, mime->ContentType );
1563 MSI_RecordSetStringW( uirow, 2, mime->suffix );
1564 msi_ui_actiondata( package, szUnregisterMIMEInfo, uirow );
1565 msiobj_release( &uirow->hdr );
1566 }
1567 return ERROR_SUCCESS;
1568 }