kernel32: Delete the .windows-label file if the label is empty.
[wine/multimedia.git] / dlls / msi / classes.c
blob45254ef999aca8e21a0572c3ca136b49c32a6f05
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Aric Stewart for CodeWeavers
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.
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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
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)
32 #include <stdarg.h>
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"
43 WINE_DEFAULT_DEBUG_CHANNEL(msi);
46 extern const WCHAR szRegisterClassInfo[];
47 extern const WCHAR szRegisterProgIdInfo[];
48 extern const WCHAR szRegisterExtensionInfo[];
49 extern const WCHAR szRegisterMIMEInfo[];
51 extern const WCHAR szUnregisterClassInfo[];
52 extern const WCHAR szUnregisterExtensionInfo[];
53 extern const WCHAR szUnregisterMIMEInfo[];
54 extern const WCHAR szUnregisterProgIdInfo[];
56 static MSIAPPID *load_appid( MSIPACKAGE* package, MSIRECORD *row )
58 LPCWSTR buffer;
59 MSIAPPID *appid;
61 /* fill in the data */
63 appid = msi_alloc_zero( sizeof(MSIAPPID) );
64 if (!appid)
65 return NULL;
67 appid->AppID = msi_dup_record_field( row, 1 );
68 TRACE("loading appid %s\n", debugstr_w( appid->AppID ));
70 buffer = MSI_RecordGetString(row,2);
71 deformat_string( package, buffer, &appid->RemoteServerName );
73 appid->LocalServer = msi_dup_record_field(row,3);
74 appid->ServiceParameters = msi_dup_record_field(row,4);
75 appid->DllSurrogate = msi_dup_record_field(row,5);
77 appid->ActivateAtStorage = !MSI_RecordIsNull(row,6);
78 appid->RunAsInteractiveUser = !MSI_RecordIsNull(row,7);
80 list_add_tail( &package->appids, &appid->entry );
82 return appid;
85 static MSIAPPID *load_given_appid( MSIPACKAGE *package, LPCWSTR name )
87 MSIRECORD *row;
88 MSIAPPID *appid;
89 static const WCHAR ExecSeqQuery[] =
90 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
91 '`','A','p','p','I','d','`',' ','W','H','E','R','E',' ',
92 '`','A','p','p','I','d','`',' ','=',' ','\'','%','s','\'',0};
94 if (!name)
95 return NULL;
97 /* check for appids already loaded */
98 LIST_FOR_EACH_ENTRY( appid, &package->appids, MSIAPPID, entry )
100 if (lstrcmpiW( appid->AppID, name )==0)
102 TRACE("found appid %s %p\n", debugstr_w(name), appid);
103 return appid;
107 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, name);
108 if (!row)
109 return NULL;
111 appid = load_appid(package, row);
112 msiobj_release(&row->hdr);
114 return appid;
117 static MSIPROGID *load_given_progid(MSIPACKAGE *package, LPCWSTR progid);
118 static MSICLASS *load_given_class( MSIPACKAGE *package, LPCWSTR classid );
120 static MSIPROGID *load_progid( MSIPACKAGE* package, MSIRECORD *row )
122 MSIPROGID *progid;
123 LPCWSTR buffer;
125 /* fill in the data */
127 progid = msi_alloc_zero( sizeof(MSIPROGID) );
128 if (!progid)
129 return NULL;
131 list_add_tail( &package->progids, &progid->entry );
133 progid->ProgID = msi_dup_record_field(row,1);
134 TRACE("loading progid %s\n",debugstr_w(progid->ProgID));
136 buffer = MSI_RecordGetString(row,2);
137 progid->Parent = load_given_progid(package,buffer);
138 if (progid->Parent == NULL && buffer)
139 FIXME("Unknown parent ProgID %s\n",debugstr_w(buffer));
141 buffer = MSI_RecordGetString(row,3);
142 progid->Class = load_given_class(package,buffer);
143 if (progid->Class == NULL && buffer)
144 FIXME("Unknown class %s\n",debugstr_w(buffer));
146 progid->Description = msi_dup_record_field(row,4);
148 if (!MSI_RecordIsNull(row,6))
150 INT icon_index = MSI_RecordGetInteger(row,6);
151 LPCWSTR FileName = MSI_RecordGetString(row,5);
152 LPWSTR FilePath;
153 static const WCHAR fmt[] = {'%','s',',','%','i',0};
155 FilePath = build_icon_path(package,FileName);
157 progid->IconPath = msi_alloc( (strlenW(FilePath)+10)* sizeof(WCHAR) );
159 sprintfW(progid->IconPath,fmt,FilePath,icon_index);
161 msi_free(FilePath);
163 else
165 buffer = MSI_RecordGetString(row,5);
166 if (buffer)
167 progid->IconPath = build_icon_path(package,buffer);
170 progid->CurVer = NULL;
171 progid->VersionInd = NULL;
173 /* if we have a parent then we may be that parents CurVer */
174 if (progid->Parent && progid->Parent != progid)
176 MSIPROGID *parent = progid->Parent;
178 while (parent->Parent && parent->Parent != parent)
179 parent = parent->Parent;
181 /* FIXME: need to determine if we are really the CurVer */
183 progid->CurVer = parent;
184 parent->VersionInd = progid;
187 return progid;
190 static MSIPROGID *load_given_progid(MSIPACKAGE *package, LPCWSTR name)
192 MSIPROGID *progid;
193 MSIRECORD *row;
194 static const WCHAR ExecSeqQuery[] =
195 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
196 '`','P','r','o','g','I','d','`',' ','W','H','E','R','E',' ',
197 '`','P','r','o','g','I','d','`',' ','=',' ','\'','%','s','\'',0};
199 if (!name)
200 return NULL;
202 /* check for progids already loaded */
203 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
205 if (strcmpiW( progid->ProgID,name )==0)
207 TRACE("found progid %s (%p)\n",debugstr_w(name), progid );
208 return progid;
212 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, name );
213 if (!row)
214 return NULL;
216 progid = load_progid(package, row);
217 msiobj_release(&row->hdr);
219 return progid;
222 static MSICLASS *load_class( MSIPACKAGE* package, MSIRECORD *row )
224 MSICLASS *cls;
225 DWORD i;
226 LPCWSTR buffer;
228 /* fill in the data */
230 cls = msi_alloc_zero( sizeof(MSICLASS) );
231 if (!cls)
232 return NULL;
234 list_add_tail( &package->classes, &cls->entry );
236 cls->clsid = msi_dup_record_field( row, 1 );
237 TRACE("loading class %s\n",debugstr_w(cls->clsid));
238 cls->Context = msi_dup_record_field( row, 2 );
239 buffer = MSI_RecordGetString(row,3);
240 cls->Component = get_loaded_component(package, buffer);
242 cls->ProgIDText = msi_dup_record_field(row,4);
243 cls->ProgID = load_given_progid(package, cls->ProgIDText);
245 cls->Description = msi_dup_record_field(row,5);
247 buffer = MSI_RecordGetString(row,6);
248 if (buffer)
249 cls->AppID = load_given_appid(package, buffer);
251 cls->FileTypeMask = msi_dup_record_field(row,7);
253 if (!MSI_RecordIsNull(row,9))
256 INT icon_index = MSI_RecordGetInteger(row,9);
257 LPCWSTR FileName = MSI_RecordGetString(row,8);
258 LPWSTR FilePath;
259 static const WCHAR fmt[] = {'%','s',',','%','i',0};
261 FilePath = build_icon_path(package,FileName);
263 cls->IconPath = msi_alloc( (strlenW(FilePath)+5)* sizeof(WCHAR) );
265 sprintfW(cls->IconPath,fmt,FilePath,icon_index);
267 msi_free(FilePath);
269 else
271 buffer = MSI_RecordGetString(row,8);
272 if (buffer)
273 cls->IconPath = build_icon_path(package,buffer);
276 if (!MSI_RecordIsNull(row,10))
278 i = MSI_RecordGetInteger(row,10);
279 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
281 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
282 static const WCHAR ole32[] = {'o','l','e','3','2','.','d','l','l',0};
284 switch(i)
286 case 1:
287 cls->DefInprocHandler = strdupW(ole2);
288 break;
289 case 2:
290 cls->DefInprocHandler32 = strdupW(ole32);
291 break;
292 case 3:
293 cls->DefInprocHandler = strdupW(ole2);
294 cls->DefInprocHandler32 = strdupW(ole32);
295 break;
298 else
300 cls->DefInprocHandler32 = msi_dup_record_field( row, 10);
301 reduce_to_longfilename(cls->DefInprocHandler32);
304 buffer = MSI_RecordGetString(row,11);
305 deformat_string(package,buffer,&cls->Argument);
307 buffer = MSI_RecordGetString(row,12);
308 cls->Feature = get_loaded_feature(package,buffer);
310 cls->Attributes = MSI_RecordGetInteger(row,13);
312 return cls;
316 * the Class table has 3 primary keys. Generally it is only
317 * referenced through the first CLSID key. However when loading
318 * all of the classes we need to make sure we do not ignore rows
319 * with other Context and ComponentIndexs
321 static MSICLASS *load_given_class(MSIPACKAGE *package, LPCWSTR classid)
323 MSICLASS *cls;
324 MSIRECORD *row;
325 static const WCHAR ExecSeqQuery[] =
326 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
327 '`','C','l','a','s','s','`',' ','W','H','E','R','E',' ',
328 '`','C','L','S','I','D','`',' ','=',' ','\'','%','s','\'',0};
330 if (!classid)
331 return NULL;
333 /* check for classes already loaded */
334 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
336 if (lstrcmpiW( cls->clsid, classid )==0)
338 TRACE("found class %s (%p)\n",debugstr_w(classid), cls);
339 return cls;
343 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, classid);
344 if (!row)
345 return NULL;
347 cls = load_class(package, row);
348 msiobj_release(&row->hdr);
350 return cls;
353 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR extension );
355 static MSIMIME *load_mime( MSIPACKAGE* package, MSIRECORD *row )
357 LPCWSTR buffer;
358 MSIMIME *mt;
360 /* fill in the data */
362 mt = msi_alloc_zero( sizeof(MSIMIME) );
363 if (!mt)
364 return mt;
366 mt->ContentType = msi_dup_record_field( row, 1 );
367 TRACE("loading mime %s\n", debugstr_w(mt->ContentType));
369 buffer = MSI_RecordGetString( row, 2 );
370 mt->Extension = load_given_extension( package, buffer );
372 mt->clsid = msi_dup_record_field( row, 3 );
373 mt->Class = load_given_class( package, mt->clsid );
375 list_add_tail( &package->mimes, &mt->entry );
377 return mt;
380 static MSIMIME *load_given_mime( MSIPACKAGE *package, LPCWSTR mime )
382 MSIRECORD *row;
383 static const WCHAR ExecSeqQuery[] =
384 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
385 '`','M','I','M','E','`',' ','W','H','E','R','E',' ',
386 '`','C','o','n','t','e','n','t','T','y','p','e','`',' ','=',' ',
387 '\'','%','s','\'',0};
388 MSIMIME *mt;
390 if (!mime)
391 return NULL;
393 /* check for mime already loaded */
394 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
396 if (strcmpiW(mt->ContentType,mime)==0)
398 TRACE("found mime %s (%p)\n",debugstr_w(mime), mt);
399 return mt;
403 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, mime);
404 if (!row)
405 return NULL;
407 mt = load_mime(package, row);
408 msiobj_release(&row->hdr);
410 return mt;
413 static MSIEXTENSION *load_extension( MSIPACKAGE* package, MSIRECORD *row )
415 MSIEXTENSION *ext;
416 LPCWSTR buffer;
418 /* fill in the data */
420 ext = msi_alloc_zero( sizeof(MSIEXTENSION) );
421 if (!ext)
422 return NULL;
424 list_init( &ext->verbs );
426 list_add_tail( &package->extensions, &ext->entry );
428 ext->Extension = msi_dup_record_field( row, 1 );
429 TRACE("loading extension %s\n", debugstr_w(ext->Extension));
431 buffer = MSI_RecordGetString( row, 2 );
432 ext->Component = get_loaded_component( package,buffer );
434 ext->ProgIDText = msi_dup_record_field( row, 3 );
435 ext->ProgID = load_given_progid( package, ext->ProgIDText );
437 buffer = MSI_RecordGetString( row, 4 );
438 ext->Mime = load_given_mime( package, buffer );
440 buffer = MSI_RecordGetString(row,5);
441 ext->Feature = get_loaded_feature( package, buffer );
443 return ext;
447 * While the extension table has 2 primary keys, this function is only looking
448 * at the Extension key which is what is referenced as a foreign key
450 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR name )
452 MSIRECORD *row;
453 MSIEXTENSION *ext;
454 static const WCHAR ExecSeqQuery[] =
455 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
456 '`','E','x','t','e','n','s','i','o','n','`',' ',
457 'W','H','E','R','E',' ',
458 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ',
459 '\'','%','s','\'',0};
461 if (!name)
462 return NULL;
464 /* check for extensions already loaded */
465 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
467 if (strcmpiW( ext->Extension, name )==0)
469 TRACE("extension %s already loaded %p\n", debugstr_w(name), ext);
470 return ext;
474 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, name );
475 if (!row)
476 return NULL;
478 ext = load_extension(package, row);
479 msiobj_release(&row->hdr);
481 return ext;
484 static UINT iterate_load_verb(MSIRECORD *row, LPVOID param)
486 MSIPACKAGE* package = (MSIPACKAGE*)param;
487 MSIVERB *verb;
488 LPCWSTR buffer;
489 MSIEXTENSION *extension;
491 buffer = MSI_RecordGetString(row,1);
492 extension = load_given_extension( package, buffer );
493 if (!extension)
495 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer));
496 return ERROR_SUCCESS;
499 /* fill in the data */
501 verb = msi_alloc_zero( sizeof(MSIVERB) );
502 if (!verb)
503 return ERROR_OUTOFMEMORY;
505 verb->Verb = msi_dup_record_field(row,2);
506 TRACE("loading verb %s\n",debugstr_w(verb->Verb));
507 verb->Sequence = MSI_RecordGetInteger(row,3);
509 buffer = MSI_RecordGetString(row,4);
510 deformat_string(package,buffer,&verb->Command);
512 buffer = MSI_RecordGetString(row,5);
513 deformat_string(package,buffer,&verb->Argument);
515 /* associate the verb with the correct extension */
516 list_add_tail( &extension->verbs, &verb->entry );
518 return ERROR_SUCCESS;
521 static UINT iterate_all_classes(MSIRECORD *rec, LPVOID param)
523 MSICOMPONENT *comp;
524 LPCWSTR clsid;
525 LPCWSTR context;
526 LPCWSTR buffer;
527 MSIPACKAGE* package =(MSIPACKAGE*)param;
528 MSICLASS *cls;
529 BOOL match = FALSE;
531 clsid = MSI_RecordGetString(rec,1);
532 context = MSI_RecordGetString(rec,2);
533 buffer = MSI_RecordGetString(rec,3);
534 comp = get_loaded_component(package,buffer);
536 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
538 if (strcmpiW( clsid, cls->clsid ))
539 continue;
540 if (strcmpW( context, cls->Context ))
541 continue;
542 if (comp == cls->Component)
544 match = TRUE;
545 break;
549 if (!match)
550 load_class(package, rec);
552 return ERROR_SUCCESS;
555 static VOID load_all_classes(MSIPACKAGE *package)
557 UINT rc = ERROR_SUCCESS;
558 MSIQUERY *view;
560 static const WCHAR ExecSeqQuery[] =
561 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
562 '`','C','l','a','s','s','`',0};
564 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
565 if (rc != ERROR_SUCCESS)
566 return;
568 rc = MSI_IterateRecords(view, NULL, iterate_all_classes, package);
569 msiobj_release(&view->hdr);
572 static UINT iterate_all_extensions(MSIRECORD *rec, LPVOID param)
574 MSICOMPONENT *comp;
575 LPCWSTR buffer;
576 LPCWSTR extension;
577 MSIPACKAGE* package =(MSIPACKAGE*)param;
578 BOOL match = FALSE;
579 MSIEXTENSION *ext;
581 extension = MSI_RecordGetString(rec,1);
582 buffer = MSI_RecordGetString(rec,2);
583 comp = get_loaded_component(package,buffer);
585 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
587 if (strcmpiW(extension,ext->Extension))
588 continue;
589 if (comp == ext->Component)
591 match = TRUE;
592 break;
596 if (!match)
597 load_extension(package, rec);
599 return ERROR_SUCCESS;
602 static VOID load_all_extensions(MSIPACKAGE *package)
604 UINT rc = ERROR_SUCCESS;
605 MSIQUERY *view;
607 static const WCHAR ExecSeqQuery[] =
608 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
609 '`','E','x','t','e','n','s','i','o','n','`',0};
611 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
612 if (rc != ERROR_SUCCESS)
613 return;
615 rc = MSI_IterateRecords(view, NULL, iterate_all_extensions, package);
616 msiobj_release(&view->hdr);
619 static UINT iterate_all_progids(MSIRECORD *rec, LPVOID param)
621 LPCWSTR buffer;
622 MSIPACKAGE* package =(MSIPACKAGE*)param;
624 buffer = MSI_RecordGetString(rec,1);
625 load_given_progid(package,buffer);
626 return ERROR_SUCCESS;
629 static VOID load_all_progids(MSIPACKAGE *package)
631 UINT rc = ERROR_SUCCESS;
632 MSIQUERY *view;
634 static const WCHAR ExecSeqQuery[] =
635 {'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ',
636 'F','R','O','M',' ', '`','P','r','o','g','I','d','`',0};
638 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
639 if (rc != ERROR_SUCCESS)
640 return;
642 rc = MSI_IterateRecords(view, NULL, iterate_all_progids, package);
643 msiobj_release(&view->hdr);
646 static VOID load_all_verbs(MSIPACKAGE *package)
648 UINT rc = ERROR_SUCCESS;
649 MSIQUERY *view;
651 static const WCHAR ExecSeqQuery[] =
652 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
653 '`','V','e','r','b','`',0};
655 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
656 if (rc != ERROR_SUCCESS)
657 return;
659 rc = MSI_IterateRecords(view, NULL, iterate_load_verb, package);
660 msiobj_release(&view->hdr);
663 static UINT iterate_all_mimes(MSIRECORD *rec, LPVOID param)
665 LPCWSTR buffer;
666 MSIPACKAGE* package =(MSIPACKAGE*)param;
668 buffer = MSI_RecordGetString(rec,1);
669 load_given_mime(package,buffer);
670 return ERROR_SUCCESS;
673 static VOID load_all_mimes(MSIPACKAGE *package)
675 UINT rc = ERROR_SUCCESS;
676 MSIQUERY *view;
678 static const WCHAR ExecSeqQuery[] =
679 {'S','E','L','E','C','T',' ',
680 '`','C','o','n','t','e','n','t','T','y','p','e','`',
681 ' ','F','R','O','M',' ',
682 '`','M','I','M','E','`',0};
684 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
685 if (rc != ERROR_SUCCESS)
686 return;
688 rc = MSI_IterateRecords(view, NULL, iterate_all_mimes, package);
689 msiobj_release(&view->hdr);
692 static void load_classes_and_such(MSIPACKAGE *package)
694 TRACE("Loading all the class info and related tables\n");
696 /* check if already loaded */
697 if (!list_empty( &package->classes ) ||
698 !list_empty( &package->mimes ) ||
699 !list_empty( &package->extensions ) ||
700 !list_empty( &package->progids ) )
701 return;
703 load_all_classes(package);
704 load_all_extensions(package);
705 load_all_progids(package);
706 /* these loads must come after the other loads */
707 load_all_verbs(package);
708 load_all_mimes(package);
711 static void mark_progid_for_install( MSIPACKAGE* package, MSIPROGID *progid )
713 MSIPROGID *child;
715 if (!progid)
716 return;
718 if (progid->InstallMe)
719 return;
721 progid->InstallMe = TRUE;
723 /* all children if this is a parent also install */
724 LIST_FOR_EACH_ENTRY( child, &package->progids, MSIPROGID, entry )
726 if (child->Parent == progid)
727 mark_progid_for_install( package, child );
731 static void mark_mime_for_install( MSIMIME *mime )
733 if (!mime)
734 return;
735 mime->InstallMe = TRUE;
738 static UINT register_appid(const MSIAPPID *appid, LPCWSTR app )
740 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
741 static const WCHAR szRemoteServerName[] =
742 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
743 static const WCHAR szLocalService[] =
744 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
745 static const WCHAR szService[] =
746 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
747 static const WCHAR szDLL[] =
748 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
749 static const WCHAR szActivate[] =
750 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
751 static const WCHAR szY[] = {'Y',0};
752 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
753 static const WCHAR szUser[] =
754 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
756 HKEY hkey2,hkey3;
758 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
759 RegCreateKeyW( hkey2, appid->AppID, &hkey3 );
760 RegCloseKey(hkey2);
761 msi_reg_set_val_str( hkey3, NULL, app );
763 if (appid->RemoteServerName)
764 msi_reg_set_val_str( hkey3, szRemoteServerName, appid->RemoteServerName );
766 if (appid->LocalServer)
767 msi_reg_set_val_str( hkey3, szLocalService, appid->LocalServer );
769 if (appid->ServiceParameters)
770 msi_reg_set_val_str( hkey3, szService, appid->ServiceParameters );
772 if (appid->DllSurrogate)
773 msi_reg_set_val_str( hkey3, szDLL, appid->DllSurrogate );
775 if (appid->ActivateAtStorage)
776 msi_reg_set_val_str( hkey3, szActivate, szY );
778 if (appid->RunAsInteractiveUser)
779 msi_reg_set_val_str( hkey3, szRunAs, szUser );
781 RegCloseKey(hkey3);
782 return ERROR_SUCCESS;
785 UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
788 * Again I am assuming the words, "Whose key file represents" when referring
789 * to a Component as to meaning that Components KeyPath file
792 UINT rc;
793 MSIRECORD *uirow;
794 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
795 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
796 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 };
797 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
798 static const WCHAR szSpace[] = {' ',0};
799 static const WCHAR szFileType_fmt[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
800 HKEY hkey,hkey2,hkey3;
801 MSICLASS *cls;
803 load_classes_and_such(package);
804 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
805 if (rc != ERROR_SUCCESS)
806 return ERROR_FUNCTION_FAILED;
808 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
810 MSICOMPONENT *comp;
811 MSIFILE *file;
812 DWORD size;
813 LPWSTR argument;
814 MSIFEATURE *feature;
816 comp = cls->Component;
817 if ( !comp )
818 continue;
820 feature = cls->Feature;
823 * MSDN says that these are based on Feature not on Component.
825 if (!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL ) &&
826 !ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED ))
828 TRACE("Skipping class %s reg due to disabled feature %s\n",
829 debugstr_w(cls->clsid), debugstr_w(feature->Feature));
831 continue;
834 TRACE("Registering class %s (%p)\n", debugstr_w(cls->clsid), cls);
836 cls->Installed = TRUE;
837 mark_progid_for_install( package, cls->ProgID );
839 RegCreateKeyW( hkey, cls->clsid, &hkey2 );
841 if (cls->Description)
842 msi_reg_set_val_str( hkey2, NULL, cls->Description );
844 RegCreateKeyW( hkey2, cls->Context, &hkey3 );
845 file = get_loaded_file( package, comp->KeyPath );
846 if (!file)
848 TRACE("COM server not provided, skipping class %s\n", debugstr_w(cls->clsid));
849 continue;
853 * FIXME: Implement install on demand (advertised components).
855 * ole32.dll should call msi.MsiProvideComponentFromDescriptor()
856 * when it needs an InProcServer that doesn't exist.
857 * The component advertise string should be in the "InProcServer" value.
859 size = lstrlenW( file->TargetPath )+1;
860 if (cls->Argument)
861 size += lstrlenW(cls->Argument)+1;
863 argument = msi_alloc( size * sizeof(WCHAR) );
864 lstrcpyW( argument, file->TargetPath );
866 if (cls->Argument)
868 lstrcatW( argument, szSpace );
869 lstrcatW( argument, cls->Argument );
872 msi_reg_set_val_str( hkey3, NULL, argument );
873 msi_free(argument);
875 RegCloseKey(hkey3);
877 if (cls->ProgID || cls->ProgIDText)
879 LPCWSTR progid;
881 if (cls->ProgID)
882 progid = cls->ProgID->ProgID;
883 else
884 progid = cls->ProgIDText;
886 msi_reg_set_subkey_val( hkey2, szProgID, NULL, progid );
888 if (cls->ProgID && cls->ProgID->VersionInd)
890 msi_reg_set_subkey_val( hkey2, szVIProgID, NULL,
891 cls->ProgID->VersionInd->ProgID );
895 if (cls->AppID)
897 MSIAPPID *appid = cls->AppID;
899 msi_reg_set_val_str( hkey2, szAppID, appid->AppID );
901 register_appid( appid, cls->Description );
904 if (cls->IconPath)
906 static const WCHAR szDefaultIcon[] =
907 {'D','e','f','a','u','l','t','I','c','o','n',0};
909 msi_reg_set_subkey_val( hkey2, szDefaultIcon, NULL, cls->IconPath );
912 if (cls->DefInprocHandler)
914 static const WCHAR szInproc[] =
915 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
917 msi_reg_set_subkey_val( hkey2, szInproc, NULL, cls->DefInprocHandler );
920 if (cls->DefInprocHandler32)
922 static const WCHAR szInproc32[] =
923 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',0};
925 msi_reg_set_subkey_val( hkey2, szInproc32, NULL, cls->DefInprocHandler32 );
928 RegCloseKey(hkey2);
930 /* if there is a FileTypeMask, register the FileType */
931 if (cls->FileTypeMask)
933 LPWSTR ptr, ptr2;
934 LPWSTR keyname;
935 INT index = 0;
936 ptr = cls->FileTypeMask;
937 while (ptr && *ptr)
939 ptr2 = strchrW(ptr,';');
940 if (ptr2)
941 *ptr2 = 0;
942 keyname = msi_alloc( (strlenW(szFileType_fmt) + strlenW(cls->clsid) + 4) * sizeof(WCHAR));
943 sprintfW( keyname, szFileType_fmt, cls->clsid, index );
945 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, ptr );
946 msi_free(keyname);
948 if (ptr2)
949 ptr = ptr2+1;
950 else
951 ptr = NULL;
953 index ++;
957 uirow = MSI_CreateRecord(1);
959 MSI_RecordSetStringW( uirow, 1, cls->clsid );
960 ui_actiondata(package,szRegisterClassInfo,uirow);
961 msiobj_release(&uirow->hdr);
964 RegCloseKey(hkey);
965 return rc;
968 static LPCWSTR get_clsid_of_progid( const MSIPROGID *progid )
970 while (progid)
972 if (progid->Class)
973 return progid->Class->clsid;
974 if (progid->Parent == progid)
975 break;
976 progid = progid->Parent;
978 return NULL;
981 static UINT register_progid( const MSIPROGID* progid )
983 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
984 static const WCHAR szDefaultIcon[] =
985 {'D','e','f','a','u','l','t','I','c','o','n',0};
986 static const WCHAR szCurVer[] =
987 {'C','u','r','V','e','r',0};
988 HKEY hkey = 0;
989 UINT rc;
991 rc = RegCreateKeyW( HKEY_CLASSES_ROOT, progid->ProgID, &hkey );
992 if (rc == ERROR_SUCCESS)
994 LPCWSTR clsid = get_clsid_of_progid( progid );
996 if (clsid)
997 msi_reg_set_subkey_val( hkey, szCLSID, NULL, clsid );
998 else
999 ERR("%s has no class\n", debugstr_w( progid->ProgID ) );
1001 if (progid->Description)
1002 msi_reg_set_val_str( hkey, NULL, progid->Description );
1004 if (progid->IconPath)
1005 msi_reg_set_subkey_val( hkey, szDefaultIcon, NULL, progid->IconPath );
1007 /* write out the current version */
1008 if (progid->CurVer)
1009 msi_reg_set_subkey_val( hkey, szCurVer, NULL, progid->CurVer->ProgID );
1011 RegCloseKey(hkey);
1013 else
1014 ERR("failed to create key %s\n", debugstr_w( progid->ProgID ) );
1016 return rc;
1019 UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
1021 MSIPROGID *progid;
1022 MSIRECORD *uirow;
1024 load_classes_and_such(package);
1026 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
1028 /* check if this progid is to be installed */
1029 if (progid->Class && progid->Class->Installed)
1030 progid->InstallMe = TRUE;
1032 if (!progid->InstallMe)
1034 TRACE("progid %s not scheduled to be installed\n",
1035 debugstr_w(progid->ProgID));
1036 continue;
1039 TRACE("Registering progid %s\n", debugstr_w(progid->ProgID));
1041 register_progid( progid );
1043 uirow = MSI_CreateRecord( 1 );
1044 MSI_RecordSetStringW( uirow, 1, progid->ProgID );
1045 ui_actiondata( package, szRegisterProgIdInfo, uirow );
1046 msiobj_release( &uirow->hdr );
1049 return ERROR_SUCCESS;
1052 static UINT register_verb(MSIPACKAGE *package, LPCWSTR progid,
1053 MSICOMPONENT* component, const MSIEXTENSION* extension,
1054 MSIVERB* verb, INT* Sequence )
1056 LPWSTR keyname;
1057 HKEY key;
1058 static const WCHAR szShell[] = {'s','h','e','l','l',0};
1059 static const WCHAR szCommand[] = {'c','o','m','m','a','n','d',0};
1060 static const WCHAR fmt[] = {'\"','%','s','\"',' ','%','s',0};
1061 static const WCHAR fmt2[] = {'\"','%','s','\"',0};
1062 LPWSTR command;
1063 DWORD size;
1064 LPWSTR advertise;
1066 keyname = build_directory_name(4, progid, szShell, verb->Verb, szCommand);
1068 TRACE("Making Key %s\n",debugstr_w(keyname));
1069 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
1070 size = strlenW(component->FullKeypath);
1071 if (verb->Argument)
1072 size += strlenW(verb->Argument);
1073 size += 4;
1075 command = msi_alloc(size * sizeof (WCHAR));
1076 if (verb->Argument)
1077 sprintfW(command, fmt, component->FullKeypath, verb->Argument);
1078 else
1079 sprintfW(command, fmt2, component->FullKeypath);
1081 msi_reg_set_val_str( key, NULL, command );
1082 msi_free(command);
1084 advertise = create_component_advertise_string(package, component,
1085 extension->Feature->Feature);
1087 size = strlenW(advertise);
1089 if (verb->Argument)
1090 size += strlenW(verb->Argument);
1091 size += 4;
1093 command = msi_alloc_zero(size * sizeof (WCHAR));
1095 strcpyW(command,advertise);
1096 if (verb->Argument)
1098 static const WCHAR szSpace[] = {' ',0};
1099 strcatW(command,szSpace);
1100 strcatW(command,verb->Argument);
1103 msi_reg_set_val_multi_str( key, szCommand, command );
1105 RegCloseKey(key);
1106 msi_free(keyname);
1107 msi_free(advertise);
1108 msi_free(command);
1110 if (verb->Command)
1112 keyname = build_directory_name(3, progid, szShell, verb->Verb);
1113 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, verb->Command );
1114 msi_free(keyname);
1117 if (verb->Sequence != MSI_NULL_INTEGER)
1119 if (*Sequence == MSI_NULL_INTEGER || verb->Sequence < *Sequence)
1121 *Sequence = verb->Sequence;
1122 keyname = build_directory_name(2, progid, szShell);
1123 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, verb->Verb );
1124 msi_free(keyname);
1127 return ERROR_SUCCESS;
1130 UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
1132 static const WCHAR szContentType[] =
1133 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
1134 HKEY hkey;
1135 MSIEXTENSION *ext;
1136 MSIRECORD *uirow;
1137 BOOL install_on_demand = TRUE;
1139 load_classes_and_such(package);
1141 /* We need to set install_on_demand based on if the shell handles advertised
1142 * shortcuts and the like. Because Mike McCormack is working on this i am
1143 * going to default to TRUE
1146 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
1148 LPWSTR extension;
1149 MSIFEATURE *feature;
1151 if (!ext->Component)
1152 continue;
1154 feature = ext->Feature;
1157 * yes. MSDN says that these are based on _Feature_ not on
1158 * Component. So verify the feature is to be installed
1160 if ((!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL )) &&
1161 !(install_on_demand &&
1162 ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED )))
1164 TRACE("Skipping extension %s reg due to disabled feature %s\n",
1165 debugstr_w(ext->Extension), debugstr_w(feature->Feature));
1167 continue;
1170 TRACE("Registering extension %s (%p)\n", debugstr_w(ext->Extension), ext);
1172 ext->Installed = TRUE;
1174 /* this is only registered if the extension has at least 1 verb
1175 * according to MSDN
1177 if (ext->ProgID && !list_empty( &ext->verbs ) )
1178 mark_progid_for_install( package, ext->ProgID );
1180 mark_mime_for_install(ext->Mime);
1182 extension = msi_alloc( (lstrlenW( ext->Extension ) + 2)*sizeof(WCHAR) );
1183 extension[0] = '.';
1184 lstrcpyW(extension+1,ext->Extension);
1186 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
1187 msi_free( extension );
1189 if (ext->Mime)
1190 msi_reg_set_val_str( hkey, szContentType, ext->Mime->ContentType );
1192 if (ext->ProgID || ext->ProgIDText)
1194 static const WCHAR szSN[] =
1195 {'\\','S','h','e','l','l','N','e','w',0};
1196 HKEY hkey2;
1197 LPWSTR newkey;
1198 LPCWSTR progid;
1199 MSIVERB *verb;
1200 INT Sequence = MSI_NULL_INTEGER;
1202 if (ext->ProgID)
1203 progid = ext->ProgID->ProgID;
1204 else
1205 progid = ext->ProgIDText;
1207 msi_reg_set_val_str( hkey, NULL, progid );
1209 newkey = msi_alloc( (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
1211 strcpyW(newkey,progid);
1212 strcatW(newkey,szSN);
1213 RegCreateKeyW(hkey,newkey,&hkey2);
1214 RegCloseKey(hkey2);
1216 msi_free(newkey);
1218 /* do all the verbs */
1219 LIST_FOR_EACH_ENTRY( verb, &ext->verbs, MSIVERB, entry )
1221 register_verb( package, progid, ext->Component,
1222 ext, verb, &Sequence);
1226 RegCloseKey(hkey);
1228 uirow = MSI_CreateRecord(1);
1229 MSI_RecordSetStringW( uirow, 1, ext->Extension );
1230 ui_actiondata(package,szRegisterExtensionInfo,uirow);
1231 msiobj_release(&uirow->hdr);
1234 return ERROR_SUCCESS;
1237 UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
1239 static const WCHAR szExten[] =
1240 {'E','x','t','e','n','s','i','o','n',0 };
1241 MSIRECORD *uirow;
1242 MSIMIME *mt;
1244 load_classes_and_such(package);
1246 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
1248 LPWSTR extension;
1249 LPCWSTR exten;
1250 LPCWSTR mime;
1251 static const WCHAR fmt[] =
1252 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
1253 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
1254 LPWSTR key;
1257 * check if the MIME is to be installed. Either as requested by an
1258 * extension or Class
1260 mt->InstallMe = (mt->InstallMe ||
1261 (mt->Class && mt->Class->Installed) ||
1262 (mt->Extension && mt->Extension->Installed));
1264 if (!mt->InstallMe)
1266 TRACE("MIME %s not scheduled to be installed\n",
1267 debugstr_w(mt->ContentType));
1268 continue;
1271 mime = mt->ContentType;
1272 exten = mt->Extension->Extension;
1274 extension = msi_alloc( (lstrlenW( exten ) + 2)*sizeof(WCHAR) );
1275 extension[0] = '.';
1276 lstrcpyW(extension+1,exten);
1278 key = msi_alloc( (strlenW(mime)+strlenW(fmt)+1) * sizeof(WCHAR) );
1279 sprintfW(key,fmt,mime);
1280 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, key, szExten, extension );
1282 msi_free(extension);
1283 msi_free(key);
1285 if (mt->clsid)
1286 FIXME("Handle non null for field 3\n");
1288 uirow = MSI_CreateRecord(2);
1289 MSI_RecordSetStringW(uirow,1,mt->ContentType);
1290 MSI_RecordSetStringW(uirow,2,exten);
1291 ui_actiondata(package,szRegisterMIMEInfo,uirow);
1292 msiobj_release(&uirow->hdr);
1295 return ERROR_SUCCESS;