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