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