msi: Implement the UnregisterExtensionInfo standard action.
[wine.git] / dlls / msi / classes.c
blob744acfbf8d346c2f3a97520ed490943a427a8a9f
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:
23 * RegisterClassInfo
24 * RegisterProgIdInfo
25 * RegisterExtensionInfo
26 * RegisterMIMEInfo
27 * UnregisterClassInfo
28 * UnregisterProgIdInfo
29 * UnregisterExtensionInfo
30 * UnregisterMIMEInfo (TODO)
33 #include <stdarg.h>
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winerror.h"
38 #include "winreg.h"
39 #include "wine/debug.h"
40 #include "msipriv.h"
41 #include "winuser.h"
42 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msi);
46 static MSIAPPID *load_appid( MSIPACKAGE* package, MSIRECORD *row )
48 LPCWSTR buffer;
49 MSIAPPID *appid;
51 /* fill in the data */
53 appid = msi_alloc_zero( sizeof(MSIAPPID) );
54 if (!appid)
55 return NULL;
57 appid->AppID = msi_dup_record_field( row, 1 );
58 TRACE("loading appid %s\n", debugstr_w( appid->AppID ));
60 buffer = MSI_RecordGetString(row,2);
61 deformat_string( package, buffer, &appid->RemoteServerName );
63 appid->LocalServer = msi_dup_record_field(row,3);
64 appid->ServiceParameters = msi_dup_record_field(row,4);
65 appid->DllSurrogate = msi_dup_record_field(row,5);
67 appid->ActivateAtStorage = !MSI_RecordIsNull(row,6);
68 appid->RunAsInteractiveUser = !MSI_RecordIsNull(row,7);
70 list_add_tail( &package->appids, &appid->entry );
72 return appid;
75 static MSIAPPID *load_given_appid( MSIPACKAGE *package, LPCWSTR name )
77 MSIRECORD *row;
78 MSIAPPID *appid;
79 static const WCHAR ExecSeqQuery[] =
80 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
81 '`','A','p','p','I','d','`',' ','W','H','E','R','E',' ',
82 '`','A','p','p','I','d','`',' ','=',' ','\'','%','s','\'',0};
84 if (!name)
85 return NULL;
87 /* check for appids already loaded */
88 LIST_FOR_EACH_ENTRY( appid, &package->appids, MSIAPPID, entry )
90 if (lstrcmpiW( appid->AppID, name )==0)
92 TRACE("found appid %s %p\n", debugstr_w(name), appid);
93 return appid;
97 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, name);
98 if (!row)
99 return NULL;
101 appid = load_appid(package, row);
102 msiobj_release(&row->hdr);
104 return appid;
107 static MSIPROGID *load_given_progid(MSIPACKAGE *package, LPCWSTR progid);
108 static MSICLASS *load_given_class( MSIPACKAGE *package, LPCWSTR classid );
110 static MSIPROGID *load_progid( MSIPACKAGE* package, MSIRECORD *row )
112 MSIPROGID *progid;
113 LPCWSTR buffer;
115 /* fill in the data */
117 progid = msi_alloc_zero( sizeof(MSIPROGID) );
118 if (!progid)
119 return NULL;
121 list_add_tail( &package->progids, &progid->entry );
123 progid->ProgID = msi_dup_record_field(row,1);
124 TRACE("loading progid %s\n",debugstr_w(progid->ProgID));
126 buffer = MSI_RecordGetString(row,2);
127 progid->Parent = load_given_progid(package,buffer);
128 if (progid->Parent == NULL && buffer)
129 FIXME("Unknown parent ProgID %s\n",debugstr_w(buffer));
131 buffer = MSI_RecordGetString(row,3);
132 progid->Class = load_given_class(package,buffer);
133 if (progid->Class == NULL && buffer)
134 FIXME("Unknown class %s\n",debugstr_w(buffer));
136 progid->Description = msi_dup_record_field(row,4);
138 if (!MSI_RecordIsNull(row,6))
140 INT icon_index = MSI_RecordGetInteger(row,6);
141 LPCWSTR FileName = MSI_RecordGetString(row,5);
142 LPWSTR FilePath;
143 static const WCHAR fmt[] = {'%','s',',','%','i',0};
145 FilePath = build_icon_path(package,FileName);
147 progid->IconPath = msi_alloc( (strlenW(FilePath)+10)* sizeof(WCHAR) );
149 sprintfW(progid->IconPath,fmt,FilePath,icon_index);
151 msi_free(FilePath);
153 else
155 buffer = MSI_RecordGetString(row,5);
156 if (buffer)
157 progid->IconPath = build_icon_path(package,buffer);
160 progid->CurVer = NULL;
161 progid->VersionInd = NULL;
163 /* if we have a parent then we may be that parents CurVer */
164 if (progid->Parent && progid->Parent != progid)
166 MSIPROGID *parent = progid->Parent;
168 while (parent->Parent && parent->Parent != parent)
169 parent = parent->Parent;
171 /* FIXME: need to determine if we are really the CurVer */
173 progid->CurVer = parent;
174 parent->VersionInd = progid;
177 return progid;
180 static MSIPROGID *load_given_progid(MSIPACKAGE *package, LPCWSTR name)
182 MSIPROGID *progid;
183 MSIRECORD *row;
184 static const WCHAR ExecSeqQuery[] =
185 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
186 '`','P','r','o','g','I','d','`',' ','W','H','E','R','E',' ',
187 '`','P','r','o','g','I','d','`',' ','=',' ','\'','%','s','\'',0};
189 if (!name)
190 return NULL;
192 /* check for progids already loaded */
193 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
195 if (strcmpiW( progid->ProgID,name )==0)
197 TRACE("found progid %s (%p)\n",debugstr_w(name), progid );
198 return progid;
202 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, name );
203 if (!row)
204 return NULL;
206 progid = load_progid(package, row);
207 msiobj_release(&row->hdr);
209 return progid;
212 static MSICLASS *load_class( MSIPACKAGE* package, MSIRECORD *row )
214 MSICLASS *cls;
215 DWORD i;
216 LPCWSTR buffer;
218 /* fill in the data */
220 cls = msi_alloc_zero( sizeof(MSICLASS) );
221 if (!cls)
222 return NULL;
224 list_add_tail( &package->classes, &cls->entry );
226 cls->clsid = msi_dup_record_field( row, 1 );
227 TRACE("loading class %s\n",debugstr_w(cls->clsid));
228 cls->Context = msi_dup_record_field( row, 2 );
229 buffer = MSI_RecordGetString(row,3);
230 cls->Component = get_loaded_component(package, buffer);
232 cls->ProgIDText = msi_dup_record_field(row,4);
233 cls->ProgID = load_given_progid(package, cls->ProgIDText);
235 cls->Description = msi_dup_record_field(row,5);
237 buffer = MSI_RecordGetString(row,6);
238 if (buffer)
239 cls->AppID = load_given_appid(package, buffer);
241 cls->FileTypeMask = msi_dup_record_field(row,7);
243 if (!MSI_RecordIsNull(row,9))
246 INT icon_index = MSI_RecordGetInteger(row,9);
247 LPCWSTR FileName = MSI_RecordGetString(row,8);
248 LPWSTR FilePath;
249 static const WCHAR fmt[] = {'%','s',',','%','i',0};
251 FilePath = build_icon_path(package,FileName);
253 cls->IconPath = msi_alloc( (strlenW(FilePath)+5)* sizeof(WCHAR) );
255 sprintfW(cls->IconPath,fmt,FilePath,icon_index);
257 msi_free(FilePath);
259 else
261 buffer = MSI_RecordGetString(row,8);
262 if (buffer)
263 cls->IconPath = build_icon_path(package,buffer);
266 if (!MSI_RecordIsNull(row,10))
268 i = MSI_RecordGetInteger(row,10);
269 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
271 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
272 static const WCHAR ole32[] = {'o','l','e','3','2','.','d','l','l',0};
274 switch(i)
276 case 1:
277 cls->DefInprocHandler = strdupW(ole2);
278 break;
279 case 2:
280 cls->DefInprocHandler32 = strdupW(ole32);
281 break;
282 case 3:
283 cls->DefInprocHandler = strdupW(ole2);
284 cls->DefInprocHandler32 = strdupW(ole32);
285 break;
288 else
290 cls->DefInprocHandler32 = msi_dup_record_field( row, 10);
291 reduce_to_longfilename(cls->DefInprocHandler32);
294 buffer = MSI_RecordGetString(row,11);
295 deformat_string(package,buffer,&cls->Argument);
297 buffer = MSI_RecordGetString(row,12);
298 cls->Feature = get_loaded_feature(package,buffer);
300 cls->Attributes = MSI_RecordGetInteger(row,13);
302 return cls;
306 * the Class table has 3 primary keys. Generally it is only
307 * referenced through the first CLSID key. However when loading
308 * all of the classes we need to make sure we do not ignore rows
309 * with other Context and ComponentIndexs
311 static MSICLASS *load_given_class(MSIPACKAGE *package, LPCWSTR classid)
313 MSICLASS *cls;
314 MSIRECORD *row;
315 static const WCHAR ExecSeqQuery[] =
316 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
317 '`','C','l','a','s','s','`',' ','W','H','E','R','E',' ',
318 '`','C','L','S','I','D','`',' ','=',' ','\'','%','s','\'',0};
320 if (!classid)
321 return NULL;
323 /* check for classes already loaded */
324 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
326 if (lstrcmpiW( cls->clsid, classid )==0)
328 TRACE("found class %s (%p)\n",debugstr_w(classid), cls);
329 return cls;
333 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, classid);
334 if (!row)
335 return NULL;
337 cls = load_class(package, row);
338 msiobj_release(&row->hdr);
340 return cls;
343 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR extension );
345 static MSIMIME *load_mime( MSIPACKAGE* package, MSIRECORD *row )
347 LPCWSTR buffer;
348 MSIMIME *mt;
350 /* fill in the data */
352 mt = msi_alloc_zero( sizeof(MSIMIME) );
353 if (!mt)
354 return mt;
356 mt->ContentType = msi_dup_record_field( row, 1 );
357 TRACE("loading mime %s\n", debugstr_w(mt->ContentType));
359 buffer = MSI_RecordGetString( row, 2 );
360 mt->Extension = load_given_extension( package, buffer );
362 mt->clsid = msi_dup_record_field( row, 3 );
363 mt->Class = load_given_class( package, mt->clsid );
365 list_add_tail( &package->mimes, &mt->entry );
367 return mt;
370 static MSIMIME *load_given_mime( MSIPACKAGE *package, LPCWSTR mime )
372 MSIRECORD *row;
373 static const WCHAR ExecSeqQuery[] =
374 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
375 '`','M','I','M','E','`',' ','W','H','E','R','E',' ',
376 '`','C','o','n','t','e','n','t','T','y','p','e','`',' ','=',' ',
377 '\'','%','s','\'',0};
378 MSIMIME *mt;
380 if (!mime)
381 return NULL;
383 /* check for mime already loaded */
384 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
386 if (strcmpiW(mt->ContentType,mime)==0)
388 TRACE("found mime %s (%p)\n",debugstr_w(mime), mt);
389 return mt;
393 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, mime);
394 if (!row)
395 return NULL;
397 mt = load_mime(package, row);
398 msiobj_release(&row->hdr);
400 return mt;
403 static MSIEXTENSION *load_extension( MSIPACKAGE* package, MSIRECORD *row )
405 MSIEXTENSION *ext;
406 LPCWSTR buffer;
408 /* fill in the data */
410 ext = msi_alloc_zero( sizeof(MSIEXTENSION) );
411 if (!ext)
412 return NULL;
414 list_init( &ext->verbs );
416 list_add_tail( &package->extensions, &ext->entry );
418 ext->Extension = msi_dup_record_field( row, 1 );
419 TRACE("loading extension %s\n", debugstr_w(ext->Extension));
421 buffer = MSI_RecordGetString( row, 2 );
422 ext->Component = get_loaded_component( package,buffer );
424 ext->ProgIDText = msi_dup_record_field( row, 3 );
425 ext->ProgID = load_given_progid( package, ext->ProgIDText );
427 buffer = MSI_RecordGetString( row, 4 );
428 ext->Mime = load_given_mime( package, buffer );
430 buffer = MSI_RecordGetString(row,5);
431 ext->Feature = get_loaded_feature( package, buffer );
433 return ext;
437 * While the extension table has 2 primary keys, this function is only looking
438 * at the Extension key which is what is referenced as a foreign key
440 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR name )
442 MSIRECORD *row;
443 MSIEXTENSION *ext;
444 static const WCHAR ExecSeqQuery[] =
445 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
446 '`','E','x','t','e','n','s','i','o','n','`',' ',
447 'W','H','E','R','E',' ',
448 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ',
449 '\'','%','s','\'',0};
451 if (!name)
452 return NULL;
454 if (name[0] == '.')
455 name++;
457 /* check for extensions already loaded */
458 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
460 if (strcmpiW( ext->Extension, name )==0)
462 TRACE("extension %s already loaded %p\n", debugstr_w(name), ext);
463 return ext;
467 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, name );
468 if (!row)
469 return NULL;
471 ext = load_extension(package, row);
472 msiobj_release(&row->hdr);
474 return ext;
477 static UINT iterate_load_verb(MSIRECORD *row, LPVOID param)
479 MSIPACKAGE* package = param;
480 MSIVERB *verb;
481 LPCWSTR buffer;
482 MSIEXTENSION *extension;
484 buffer = MSI_RecordGetString(row,1);
485 extension = load_given_extension( package, buffer );
486 if (!extension)
488 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer));
489 return ERROR_SUCCESS;
492 /* fill in the data */
494 verb = msi_alloc_zero( sizeof(MSIVERB) );
495 if (!verb)
496 return ERROR_OUTOFMEMORY;
498 verb->Verb = msi_dup_record_field(row,2);
499 TRACE("loading verb %s\n",debugstr_w(verb->Verb));
500 verb->Sequence = MSI_RecordGetInteger(row,3);
502 buffer = MSI_RecordGetString(row,4);
503 deformat_string(package,buffer,&verb->Command);
505 buffer = MSI_RecordGetString(row,5);
506 deformat_string(package,buffer,&verb->Argument);
508 /* associate the verb with the correct extension */
509 list_add_tail( &extension->verbs, &verb->entry );
511 return ERROR_SUCCESS;
514 static UINT iterate_all_classes(MSIRECORD *rec, LPVOID param)
516 MSICOMPONENT *comp;
517 LPCWSTR clsid;
518 LPCWSTR context;
519 LPCWSTR buffer;
520 MSIPACKAGE* package = param;
521 MSICLASS *cls;
522 BOOL match = FALSE;
524 clsid = MSI_RecordGetString(rec,1);
525 context = MSI_RecordGetString(rec,2);
526 buffer = MSI_RecordGetString(rec,3);
527 comp = get_loaded_component(package,buffer);
529 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
531 if (strcmpiW( clsid, cls->clsid ))
532 continue;
533 if (strcmpW( context, cls->Context ))
534 continue;
535 if (comp == cls->Component)
537 match = TRUE;
538 break;
542 if (!match)
543 load_class(package, rec);
545 return ERROR_SUCCESS;
548 static VOID load_all_classes(MSIPACKAGE *package)
550 UINT rc = ERROR_SUCCESS;
551 MSIQUERY *view;
553 static const WCHAR ExecSeqQuery[] =
554 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
555 '`','C','l','a','s','s','`',0};
557 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
558 if (rc != ERROR_SUCCESS)
559 return;
561 rc = MSI_IterateRecords(view, NULL, iterate_all_classes, package);
562 msiobj_release(&view->hdr);
565 static UINT iterate_all_extensions(MSIRECORD *rec, LPVOID param)
567 MSICOMPONENT *comp;
568 LPCWSTR buffer;
569 LPCWSTR extension;
570 MSIPACKAGE* package = param;
571 BOOL match = FALSE;
572 MSIEXTENSION *ext;
574 extension = MSI_RecordGetString(rec,1);
575 buffer = MSI_RecordGetString(rec,2);
576 comp = get_loaded_component(package,buffer);
578 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
580 if (strcmpiW(extension,ext->Extension))
581 continue;
582 if (comp == ext->Component)
584 match = TRUE;
585 break;
589 if (!match)
590 load_extension(package, rec);
592 return ERROR_SUCCESS;
595 static VOID load_all_extensions(MSIPACKAGE *package)
597 UINT rc = ERROR_SUCCESS;
598 MSIQUERY *view;
600 static const WCHAR ExecSeqQuery[] =
601 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
602 '`','E','x','t','e','n','s','i','o','n','`',0};
604 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
605 if (rc != ERROR_SUCCESS)
606 return;
608 rc = MSI_IterateRecords(view, NULL, iterate_all_extensions, package);
609 msiobj_release(&view->hdr);
612 static UINT iterate_all_progids(MSIRECORD *rec, LPVOID param)
614 LPCWSTR buffer;
615 MSIPACKAGE* package = param;
617 buffer = MSI_RecordGetString(rec,1);
618 load_given_progid(package,buffer);
619 return ERROR_SUCCESS;
622 static VOID load_all_progids(MSIPACKAGE *package)
624 UINT rc = ERROR_SUCCESS;
625 MSIQUERY *view;
627 static const WCHAR ExecSeqQuery[] =
628 {'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ',
629 'F','R','O','M',' ', '`','P','r','o','g','I','d','`',0};
631 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
632 if (rc != ERROR_SUCCESS)
633 return;
635 rc = MSI_IterateRecords(view, NULL, iterate_all_progids, package);
636 msiobj_release(&view->hdr);
639 static VOID load_all_verbs(MSIPACKAGE *package)
641 UINT rc = ERROR_SUCCESS;
642 MSIQUERY *view;
644 static const WCHAR ExecSeqQuery[] =
645 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
646 '`','V','e','r','b','`',0};
648 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
649 if (rc != ERROR_SUCCESS)
650 return;
652 rc = MSI_IterateRecords(view, NULL, iterate_load_verb, package);
653 msiobj_release(&view->hdr);
656 static UINT iterate_all_mimes(MSIRECORD *rec, LPVOID param)
658 LPCWSTR buffer;
659 MSIPACKAGE* package = param;
661 buffer = MSI_RecordGetString(rec,1);
662 load_given_mime(package,buffer);
663 return ERROR_SUCCESS;
666 static VOID load_all_mimes(MSIPACKAGE *package)
668 UINT rc = ERROR_SUCCESS;
669 MSIQUERY *view;
671 static const WCHAR ExecSeqQuery[] =
672 {'S','E','L','E','C','T',' ',
673 '`','C','o','n','t','e','n','t','T','y','p','e','`',
674 ' ','F','R','O','M',' ',
675 '`','M','I','M','E','`',0};
677 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
678 if (rc != ERROR_SUCCESS)
679 return;
681 rc = MSI_IterateRecords(view, NULL, iterate_all_mimes, package);
682 msiobj_release(&view->hdr);
685 static void load_classes_and_such(MSIPACKAGE *package)
687 TRACE("Loading all the class info and related tables\n");
689 /* check if already loaded */
690 if (!list_empty( &package->classes ) ||
691 !list_empty( &package->mimes ) ||
692 !list_empty( &package->extensions ) ||
693 !list_empty( &package->progids ) )
694 return;
696 load_all_classes(package);
697 load_all_extensions(package);
698 load_all_progids(package);
699 /* these loads must come after the other loads */
700 load_all_verbs(package);
701 load_all_mimes(package);
704 static void mark_progid_for_install( MSIPACKAGE* package, MSIPROGID *progid )
706 MSIPROGID *child;
708 if (!progid)
709 return;
711 if (progid->InstallMe)
712 return;
714 progid->InstallMe = TRUE;
716 /* all children if this is a parent also install */
717 LIST_FOR_EACH_ENTRY( child, &package->progids, MSIPROGID, entry )
719 if (child->Parent == progid)
720 mark_progid_for_install( package, child );
724 static void mark_progid_for_uninstall( MSIPACKAGE *package, MSIPROGID *progid )
726 MSIPROGID *child;
728 if (!progid)
729 return;
731 if (!progid->InstallMe)
732 return;
734 progid->InstallMe = FALSE;
736 LIST_FOR_EACH_ENTRY( child, &package->progids, MSIPROGID, entry )
738 if (child->Parent == progid)
739 mark_progid_for_uninstall( package, child );
743 static void mark_mime_for_install( MSIMIME *mime )
745 if (!mime)
746 return;
747 mime->InstallMe = TRUE;
750 static void mark_mime_for_uninstall( MSIMIME *mime )
752 if (!mime)
753 return;
754 mime->InstallMe = FALSE;
757 static UINT register_appid(const MSIAPPID *appid, LPCWSTR app )
759 static const WCHAR szRemoteServerName[] =
760 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
761 static const WCHAR szLocalService[] =
762 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
763 static const WCHAR szService[] =
764 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
765 static const WCHAR szDLL[] =
766 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
767 static const WCHAR szActivate[] =
768 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
769 static const WCHAR szY[] = {'Y',0};
770 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
771 static const WCHAR szUser[] =
772 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
774 HKEY hkey2,hkey3;
776 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
777 RegCreateKeyW( hkey2, appid->AppID, &hkey3 );
778 RegCloseKey(hkey2);
779 msi_reg_set_val_str( hkey3, NULL, app );
781 if (appid->RemoteServerName)
782 msi_reg_set_val_str( hkey3, szRemoteServerName, appid->RemoteServerName );
784 if (appid->LocalServer)
785 msi_reg_set_val_str( hkey3, szLocalService, appid->LocalServer );
787 if (appid->ServiceParameters)
788 msi_reg_set_val_str( hkey3, szService, appid->ServiceParameters );
790 if (appid->DllSurrogate)
791 msi_reg_set_val_str( hkey3, szDLL, appid->DllSurrogate );
793 if (appid->ActivateAtStorage)
794 msi_reg_set_val_str( hkey3, szActivate, szY );
796 if (appid->RunAsInteractiveUser)
797 msi_reg_set_val_str( hkey3, szRunAs, szUser );
799 RegCloseKey(hkey3);
800 return ERROR_SUCCESS;
803 UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
805 static const WCHAR szFileType_fmt[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
806 MSIRECORD *uirow;
807 HKEY hkey,hkey2,hkey3;
808 MSICLASS *cls;
810 load_classes_and_such(package);
811 if (RegCreateKeyW(HKEY_CLASSES_ROOT, szCLSID, &hkey) != ERROR_SUCCESS)
812 return ERROR_FUNCTION_FAILED;
814 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
816 MSICOMPONENT *comp;
817 MSIFILE *file;
818 DWORD size;
819 LPWSTR argument;
820 MSIFEATURE *feature;
822 comp = cls->Component;
823 if ( !comp )
824 continue;
826 feature = cls->Feature;
827 if (!feature)
828 continue;
830 if (feature->ActionRequest != INSTALLSTATE_LOCAL &&
831 feature->ActionRequest != INSTALLSTATE_ADVERTISED )
833 TRACE("Feature %s not scheduled for installation, skipping registration of class %s\n",
834 debugstr_w(feature->Feature), debugstr_w(cls->clsid));
835 continue;
837 feature->Action = feature->ActionRequest;
839 file = get_loaded_file( package, comp->KeyPath );
840 if (!file)
842 TRACE("COM server not provided, skipping class %s\n", debugstr_w(cls->clsid));
843 continue;
846 TRACE("Registering class %s (%p)\n", debugstr_w(cls->clsid), cls);
848 cls->Installed = TRUE;
849 mark_progid_for_install( package, cls->ProgID );
851 RegCreateKeyW( hkey, cls->clsid, &hkey2 );
853 if (cls->Description)
854 msi_reg_set_val_str( hkey2, NULL, cls->Description );
856 RegCreateKeyW( hkey2, cls->Context, &hkey3 );
859 * FIXME: Implement install on demand (advertised components).
861 * ole32.dll should call msi.MsiProvideComponentFromDescriptor()
862 * when it needs an InProcServer that doesn't exist.
863 * The component advertise string should be in the "InProcServer" value.
865 size = lstrlenW( file->TargetPath )+1;
866 if (cls->Argument)
867 size += lstrlenW(cls->Argument)+1;
869 argument = msi_alloc( size * sizeof(WCHAR) );
870 lstrcpyW( argument, file->TargetPath );
872 if (cls->Argument)
874 lstrcatW( argument, szSpace );
875 lstrcatW( argument, cls->Argument );
878 msi_reg_set_val_str( hkey3, NULL, argument );
879 msi_free(argument);
881 RegCloseKey(hkey3);
883 if (cls->ProgID || cls->ProgIDText)
885 LPCWSTR progid;
887 if (cls->ProgID)
888 progid = cls->ProgID->ProgID;
889 else
890 progid = cls->ProgIDText;
892 msi_reg_set_subkey_val( hkey2, szProgID, NULL, progid );
894 if (cls->ProgID && cls->ProgID->VersionInd)
896 msi_reg_set_subkey_val( hkey2, szVIProgID, NULL,
897 cls->ProgID->VersionInd->ProgID );
901 if (cls->AppID)
903 MSIAPPID *appid = cls->AppID;
904 msi_reg_set_val_str( hkey2, szAppID, appid->AppID );
905 register_appid( appid, cls->Description );
908 if (cls->IconPath)
909 msi_reg_set_subkey_val( hkey2, szDefaultIcon, NULL, cls->IconPath );
911 if (cls->DefInprocHandler)
912 msi_reg_set_subkey_val( hkey2, szInprocHandler, NULL, cls->DefInprocHandler );
914 if (cls->DefInprocHandler32)
915 msi_reg_set_subkey_val( hkey2, szInprocHandler32, NULL, cls->DefInprocHandler32 );
917 RegCloseKey(hkey2);
919 /* if there is a FileTypeMask, register the FileType */
920 if (cls->FileTypeMask)
922 LPWSTR ptr, ptr2;
923 LPWSTR keyname;
924 INT index = 0;
925 ptr = cls->FileTypeMask;
926 while (ptr && *ptr)
928 ptr2 = strchrW(ptr,';');
929 if (ptr2)
930 *ptr2 = 0;
931 keyname = msi_alloc( (strlenW(szFileType_fmt) + strlenW(cls->clsid) + 4) * sizeof(WCHAR));
932 sprintfW( keyname, szFileType_fmt, cls->clsid, index );
934 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, ptr );
935 msi_free(keyname);
937 if (ptr2)
938 ptr = ptr2+1;
939 else
940 ptr = NULL;
942 index ++;
946 uirow = MSI_CreateRecord(1);
947 MSI_RecordSetStringW( uirow, 1, cls->clsid );
948 ui_actiondata(package,szRegisterClassInfo,uirow);
949 msiobj_release(&uirow->hdr);
952 RegCloseKey(hkey);
953 return ERROR_SUCCESS;
956 UINT ACTION_UnregisterClassInfo( MSIPACKAGE *package )
958 static const WCHAR szFileType[] = {'F','i','l','e','T','y','p','e','\\',0};
959 MSIRECORD *uirow;
960 MSICLASS *cls;
961 HKEY hkey, hkey2;
963 load_classes_and_such( package );
964 if (RegOpenKeyW( HKEY_CLASSES_ROOT, szCLSID, &hkey ) != ERROR_SUCCESS)
965 return ERROR_SUCCESS;
967 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
969 MSIFEATURE *feature;
970 MSICOMPONENT *comp;
971 LPWSTR filetype;
972 LONG res;
974 comp = cls->Component;
975 if (!comp)
976 continue;
978 feature = cls->Feature;
979 if (!feature)
980 continue;
982 if (feature->ActionRequest != INSTALLSTATE_ABSENT)
984 TRACE("Feature %s not scheduled for removal, skipping unregistration of class %s\n",
985 debugstr_w(feature->Feature), debugstr_w(cls->clsid));
986 continue;
988 feature->Action = feature->ActionRequest;
990 TRACE("Unregistering class %s (%p)\n", debugstr_w(cls->clsid), cls);
992 cls->Installed = FALSE;
993 mark_progid_for_uninstall( package, cls->ProgID );
995 res = RegDeleteTreeW( hkey, cls->clsid );
996 if (res != ERROR_SUCCESS)
997 WARN("Failed to delete class key %d\n", res);
999 if (cls->AppID)
1001 res = RegOpenKeyW( HKEY_CLASSES_ROOT, szAppID, &hkey2 );
1002 if (res == ERROR_SUCCESS)
1004 res = RegDeleteKeyW( hkey2, cls->AppID->AppID );
1005 if (res != ERROR_SUCCESS)
1006 WARN("Failed to delete appid key %d\n", res);
1007 RegCloseKey( hkey2 );
1010 if (cls->FileTypeMask)
1012 filetype = msi_alloc( (strlenW( szFileType ) + strlenW( cls->clsid ) + 1) * sizeof(WCHAR) );
1013 if (filetype)
1015 strcpyW( filetype, szFileType );
1016 strcatW( filetype, cls->clsid );
1017 res = RegDeleteTreeW( HKEY_CLASSES_ROOT, filetype );
1018 msi_free( filetype );
1020 if (res != ERROR_SUCCESS)
1021 WARN("Failed to delete file type %d\n", res);
1025 uirow = MSI_CreateRecord( 1 );
1026 MSI_RecordSetStringW( uirow, 1, cls->clsid );
1027 ui_actiondata( package, szUnregisterClassInfo, uirow );
1028 msiobj_release( &uirow->hdr );
1031 RegCloseKey( hkey );
1032 return ERROR_SUCCESS;
1035 static LPCWSTR get_clsid_of_progid( const MSIPROGID *progid )
1037 while (progid)
1039 if (progid->Class)
1040 return progid->Class->clsid;
1041 if (progid->Parent == progid)
1042 break;
1043 progid = progid->Parent;
1045 return NULL;
1048 static UINT register_progid( const MSIPROGID* progid )
1050 static const WCHAR szCurVer[] = {'C','u','r','V','e','r',0};
1051 HKEY hkey = 0;
1052 UINT rc;
1054 rc = RegCreateKeyW( HKEY_CLASSES_ROOT, progid->ProgID, &hkey );
1055 if (rc == ERROR_SUCCESS)
1057 LPCWSTR clsid = get_clsid_of_progid( progid );
1059 if (clsid)
1060 msi_reg_set_subkey_val( hkey, szCLSID, NULL, clsid );
1061 else
1062 ERR("%s has no class\n", debugstr_w( progid->ProgID ) );
1064 if (progid->Description)
1065 msi_reg_set_val_str( hkey, NULL, progid->Description );
1067 if (progid->IconPath)
1068 msi_reg_set_subkey_val( hkey, szDefaultIcon, NULL, progid->IconPath );
1070 /* write out the current version */
1071 if (progid->CurVer)
1072 msi_reg_set_subkey_val( hkey, szCurVer, NULL, progid->CurVer->ProgID );
1074 RegCloseKey(hkey);
1076 else
1077 ERR("failed to create key %s\n", debugstr_w( progid->ProgID ) );
1079 return rc;
1082 UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
1084 MSIPROGID *progid;
1085 MSIRECORD *uirow;
1087 load_classes_and_such(package);
1089 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
1091 /* check if this progid is to be installed */
1092 if (progid->Class && progid->Class->Installed)
1093 progid->InstallMe = TRUE;
1095 if (!progid->InstallMe)
1097 TRACE("progid %s not scheduled to be installed\n",
1098 debugstr_w(progid->ProgID));
1099 continue;
1102 TRACE("Registering progid %s\n", debugstr_w(progid->ProgID));
1104 register_progid( progid );
1106 uirow = MSI_CreateRecord( 1 );
1107 MSI_RecordSetStringW( uirow, 1, progid->ProgID );
1108 ui_actiondata( package, szRegisterProgIdInfo, uirow );
1109 msiobj_release( &uirow->hdr );
1112 return ERROR_SUCCESS;
1115 UINT ACTION_UnregisterProgIdInfo( MSIPACKAGE *package )
1117 MSIPROGID *progid;
1118 MSIRECORD *uirow;
1119 LONG res;
1121 load_classes_and_such( package );
1123 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
1125 /* check if this progid is to be removed */
1126 if (progid->Class && !progid->Class->Installed)
1127 progid->InstallMe = FALSE;
1129 if (progid->InstallMe)
1131 TRACE("progid %s not scheduled to be removed\n", debugstr_w(progid->ProgID));
1132 continue;
1135 TRACE("Unregistering progid %s\n", debugstr_w(progid->ProgID));
1137 res = RegDeleteTreeW( HKEY_CLASSES_ROOT, progid->ProgID );
1138 if (res != ERROR_SUCCESS)
1139 WARN("Failed to delete progid key %d\n", res);
1141 uirow = MSI_CreateRecord( 1 );
1142 MSI_RecordSetStringW( uirow, 1, progid->ProgID );
1143 ui_actiondata( package, szUnregisterProgIdInfo, uirow );
1144 msiobj_release( &uirow->hdr );
1147 return ERROR_SUCCESS;
1150 static UINT register_verb(MSIPACKAGE *package, LPCWSTR progid,
1151 MSICOMPONENT* component, const MSIEXTENSION* extension,
1152 MSIVERB* verb, INT* Sequence )
1154 LPWSTR keyname;
1155 HKEY key;
1156 static const WCHAR szShell[] = {'s','h','e','l','l',0};
1157 static const WCHAR szCommand[] = {'c','o','m','m','a','n','d',0};
1158 static const WCHAR fmt[] = {'\"','%','s','\"',' ','%','s',0};
1159 static const WCHAR fmt2[] = {'\"','%','s','\"',0};
1160 LPWSTR command;
1161 DWORD size;
1162 LPWSTR advertise;
1164 keyname = build_directory_name(4, progid, szShell, verb->Verb, szCommand);
1166 TRACE("Making Key %s\n",debugstr_w(keyname));
1167 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
1168 size = strlenW(component->FullKeypath);
1169 if (verb->Argument)
1170 size += strlenW(verb->Argument);
1171 size += 4;
1173 command = msi_alloc(size * sizeof (WCHAR));
1174 if (verb->Argument)
1175 sprintfW(command, fmt, component->FullKeypath, verb->Argument);
1176 else
1177 sprintfW(command, fmt2, component->FullKeypath);
1179 msi_reg_set_val_str( key, NULL, command );
1180 msi_free(command);
1182 advertise = create_component_advertise_string(package, component,
1183 extension->Feature->Feature);
1185 size = strlenW(advertise);
1187 if (verb->Argument)
1188 size += strlenW(verb->Argument);
1189 size += 4;
1191 command = msi_alloc_zero(size * sizeof (WCHAR));
1193 strcpyW(command,advertise);
1194 if (verb->Argument)
1196 strcatW(command,szSpace);
1197 strcatW(command,verb->Argument);
1200 msi_reg_set_val_multi_str( key, szCommand, command );
1202 RegCloseKey(key);
1203 msi_free(keyname);
1204 msi_free(advertise);
1205 msi_free(command);
1207 if (verb->Command)
1209 keyname = build_directory_name(3, progid, szShell, verb->Verb);
1210 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, verb->Command );
1211 msi_free(keyname);
1214 if (verb->Sequence != MSI_NULL_INTEGER)
1216 if (*Sequence == MSI_NULL_INTEGER || verb->Sequence < *Sequence)
1218 *Sequence = verb->Sequence;
1219 keyname = build_directory_name(2, progid, szShell);
1220 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, verb->Verb );
1221 msi_free(keyname);
1224 return ERROR_SUCCESS;
1227 UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
1229 static const WCHAR szContentType[] =
1230 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
1231 HKEY hkey = NULL;
1232 MSIEXTENSION *ext;
1233 MSIRECORD *uirow;
1234 BOOL install_on_demand = TRUE;
1235 LONG res;
1237 load_classes_and_such(package);
1239 /* We need to set install_on_demand based on if the shell handles advertised
1240 * shortcuts and the like. Because Mike McCormack is working on this i am
1241 * going to default to TRUE
1244 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
1246 LPWSTR extension;
1247 MSIFEATURE *feature;
1249 if (!ext->Component)
1250 continue;
1252 feature = ext->Feature;
1253 if (!feature)
1254 continue;
1257 * yes. MSDN says that these are based on _Feature_ not on
1258 * Component. So verify the feature is to be installed
1260 if (feature->ActionRequest != INSTALLSTATE_LOCAL &&
1261 !(install_on_demand && feature->ActionRequest == INSTALLSTATE_ADVERTISED))
1263 TRACE("Feature %s not scheduled for installation, skipping registration of extension %s\n",
1264 debugstr_w(feature->Feature), debugstr_w(ext->Extension));
1265 continue;
1267 feature->Action = feature->ActionRequest;
1269 TRACE("Registering extension %s (%p)\n", debugstr_w(ext->Extension), ext);
1271 ext->Installed = TRUE;
1273 /* this is only registered if the extension has at least 1 verb
1274 * according to MSDN
1276 if (ext->ProgID && !list_empty( &ext->verbs ) )
1277 mark_progid_for_install( package, ext->ProgID );
1279 mark_mime_for_install(ext->Mime);
1281 extension = msi_alloc( (strlenW( ext->Extension ) + 2) * sizeof(WCHAR) );
1282 if (extension)
1284 extension[0] = '.';
1285 strcpyW( extension + 1, ext->Extension );
1286 res = RegCreateKeyW( HKEY_CLASSES_ROOT, extension, &hkey );
1287 msi_free( extension );
1288 if (res != ERROR_SUCCESS)
1289 WARN("Failed to create extension key %d\n", res);
1292 if (ext->Mime)
1293 msi_reg_set_val_str( hkey, szContentType, ext->Mime->ContentType );
1295 if (ext->ProgID || ext->ProgIDText)
1297 static const WCHAR szSN[] =
1298 {'\\','S','h','e','l','l','N','e','w',0};
1299 HKEY hkey2;
1300 LPWSTR newkey;
1301 LPCWSTR progid;
1302 MSIVERB *verb;
1303 INT Sequence = MSI_NULL_INTEGER;
1305 if (ext->ProgID)
1306 progid = ext->ProgID->ProgID;
1307 else
1308 progid = ext->ProgIDText;
1310 msi_reg_set_val_str( hkey, NULL, progid );
1312 newkey = msi_alloc( (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
1314 strcpyW(newkey,progid);
1315 strcatW(newkey,szSN);
1316 RegCreateKeyW(hkey,newkey,&hkey2);
1317 RegCloseKey(hkey2);
1319 msi_free(newkey);
1321 /* do all the verbs */
1322 LIST_FOR_EACH_ENTRY( verb, &ext->verbs, MSIVERB, entry )
1324 register_verb( package, progid, ext->Component,
1325 ext, verb, &Sequence);
1329 RegCloseKey(hkey);
1331 uirow = MSI_CreateRecord(1);
1332 MSI_RecordSetStringW( uirow, 1, ext->Extension );
1333 ui_actiondata(package,szRegisterExtensionInfo,uirow);
1334 msiobj_release(&uirow->hdr);
1337 return ERROR_SUCCESS;
1340 UINT ACTION_UnregisterExtensionInfo( MSIPACKAGE *package )
1342 MSIEXTENSION *ext;
1343 MSIRECORD *uirow;
1344 LONG res;
1346 load_classes_and_such( package );
1348 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
1350 LPWSTR extension;
1351 MSIFEATURE *feature;
1353 if (!ext->Component)
1354 continue;
1356 feature = ext->Feature;
1357 if (!feature)
1358 continue;
1360 if (feature->ActionRequest != INSTALLSTATE_ABSENT)
1362 TRACE("Feature %s not scheduled for removal, skipping unregistration of extension %s\n",
1363 debugstr_w(feature->Feature), debugstr_w(ext->Extension));
1364 continue;
1367 TRACE("Unregistering extension %s\n", debugstr_w(ext->Extension));
1369 ext->Installed = FALSE;
1371 if (ext->ProgID && !list_empty( &ext->verbs ))
1372 mark_progid_for_uninstall( package, ext->ProgID );
1374 mark_mime_for_uninstall( ext->Mime );
1376 extension = msi_alloc( (strlenW( ext->Extension ) + 2) * sizeof(WCHAR) );
1377 if (extension)
1379 extension[0] = '.';
1380 strcpyW( extension + 1, ext->Extension );
1381 res = RegDeleteTreeW( HKEY_CLASSES_ROOT, extension );
1382 msi_free( extension );
1383 if (res != ERROR_SUCCESS)
1384 WARN("Failed to delete extension key %d\n", res);
1387 if (ext->ProgID || ext->ProgIDText)
1389 static const WCHAR shellW[] = {'\\','s','h','e','l','l',0};
1390 LPCWSTR progid;
1391 LPWSTR progid_shell;
1393 if (ext->ProgID)
1394 progid = ext->ProgID->ProgID;
1395 else
1396 progid = ext->ProgIDText;
1398 progid_shell = msi_alloc( (strlenW( progid ) + strlenW( shellW ) + 1) * sizeof(WCHAR) );
1399 if (progid_shell)
1401 strcpyW( progid_shell, progid );
1402 strcatW( progid_shell, shellW );
1403 res = RegDeleteTreeW( HKEY_CLASSES_ROOT, progid_shell );
1404 msi_free( progid_shell );
1405 if (res != ERROR_SUCCESS)
1406 WARN("Failed to delete shell key %d\n", res);
1407 RegDeleteKeyW( HKEY_CLASSES_ROOT, progid );
1411 uirow = MSI_CreateRecord( 1 );
1412 MSI_RecordSetStringW( uirow, 1, ext->Extension );
1413 ui_actiondata( package, szUnregisterExtensionInfo, uirow );
1414 msiobj_release( &uirow->hdr );
1417 return ERROR_SUCCESS;
1420 UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
1422 static const WCHAR szExten[] =
1423 {'E','x','t','e','n','s','i','o','n',0 };
1424 MSIRECORD *uirow;
1425 MSIMIME *mt;
1427 load_classes_and_such(package);
1429 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
1431 LPWSTR extension;
1432 LPCWSTR exten;
1433 LPCWSTR mime;
1434 static const WCHAR fmt[] =
1435 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
1436 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
1437 LPWSTR key;
1440 * check if the MIME is to be installed. Either as requested by an
1441 * extension or Class
1443 mt->InstallMe = (mt->InstallMe ||
1444 (mt->Class && mt->Class->Installed) ||
1445 (mt->Extension && mt->Extension->Installed));
1447 if (!mt->InstallMe)
1449 TRACE("MIME %s not scheduled to be installed\n",
1450 debugstr_w(mt->ContentType));
1451 continue;
1454 mime = mt->ContentType;
1455 exten = mt->Extension->Extension;
1457 extension = msi_alloc( (lstrlenW( exten ) + 2)*sizeof(WCHAR) );
1458 extension[0] = '.';
1459 lstrcpyW(extension+1,exten);
1461 key = msi_alloc( (strlenW(mime)+strlenW(fmt)+1) * sizeof(WCHAR) );
1462 sprintfW(key,fmt,mime);
1463 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, key, szExten, extension );
1465 msi_free(extension);
1466 msi_free(key);
1468 if (mt->clsid)
1469 FIXME("Handle non null for field 3\n");
1471 uirow = MSI_CreateRecord(2);
1472 MSI_RecordSetStringW(uirow,1,mt->ContentType);
1473 MSI_RecordSetStringW(uirow,2,exten);
1474 ui_actiondata(package,szRegisterMIMEInfo,uirow);
1475 msiobj_release(&uirow->hdr);
1478 return ERROR_SUCCESS;