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