gdi32: Don't set the bitmap owner when selecting a pattern brush.
[wine.git] / dlls / msi / classes.c
blobafc1b1cb83b2567ee2a88b5a3946735d5cae4802
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
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 static const WCHAR query[] = {
78 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
79 '`','A','p','p','I','d','`',' ','W','H','E','R','E',' ',
80 '`','A','p','p','I','d','`',' ','=',' ','\'','%','s','\'',0};
81 MSIRECORD *row;
82 MSIAPPID *appid;
84 if (!name)
85 return NULL;
87 /* check for appids already loaded */
88 LIST_FOR_EACH_ENTRY( appid, &package->appids, MSIAPPID, entry )
90 if (!strcmpiW( appid->AppID, name ))
92 TRACE("found appid %s %p\n", debugstr_w(name), appid);
93 return appid;
97 row = MSI_QueryGetRecord(package->db, query, name);
98 if (!row)
99 return NULL;
101 appid = load_appid(package, row);
102 msiobj_release(&row->hdr);
103 return appid;
106 static MSIPROGID *load_given_progid(MSIPACKAGE *package, LPCWSTR progid);
107 static MSICLASS *load_given_class( MSIPACKAGE *package, LPCWSTR classid );
109 static MSIPROGID *load_progid( MSIPACKAGE* package, MSIRECORD *row )
111 MSIPROGID *progid;
112 LPCWSTR buffer;
114 /* fill in the data */
116 progid = msi_alloc_zero( sizeof(MSIPROGID) );
117 if (!progid)
118 return NULL;
120 list_add_tail( &package->progids, &progid->entry );
122 progid->ProgID = msi_dup_record_field(row,1);
123 TRACE("loading progid %s\n",debugstr_w(progid->ProgID));
125 buffer = MSI_RecordGetString(row,2);
126 progid->Parent = load_given_progid(package,buffer);
127 if (progid->Parent == NULL && buffer)
128 FIXME("Unknown parent ProgID %s\n",debugstr_w(buffer));
130 buffer = MSI_RecordGetString(row,3);
131 progid->Class = load_given_class(package,buffer);
132 if (progid->Class == NULL && buffer)
133 FIXME("Unknown class %s\n",debugstr_w(buffer));
135 progid->Description = msi_dup_record_field(row,4);
137 if (!MSI_RecordIsNull(row,6))
139 INT icon_index = MSI_RecordGetInteger(row,6);
140 LPCWSTR FileName = MSI_RecordGetString(row,5);
141 LPWSTR FilePath;
142 static const WCHAR fmt[] = {'%','s',',','%','i',0};
144 FilePath = msi_build_icon_path(package, FileName);
146 progid->IconPath = msi_alloc( (strlenW(FilePath)+10)* sizeof(WCHAR) );
148 sprintfW(progid->IconPath,fmt,FilePath,icon_index);
150 msi_free(FilePath);
152 else
154 buffer = MSI_RecordGetString(row,5);
155 if (buffer)
156 progid->IconPath = msi_build_icon_path(package, buffer);
159 progid->CurVer = NULL;
160 progid->VersionInd = NULL;
162 /* if we have a parent then we may be that parents CurVer */
163 if (progid->Parent && progid->Parent != progid)
165 MSIPROGID *parent = progid->Parent;
167 while (parent->Parent && parent->Parent != parent)
168 parent = parent->Parent;
170 /* FIXME: need to determine if we are really the CurVer */
172 progid->CurVer = parent;
173 parent->VersionInd = progid;
176 return progid;
179 static MSIPROGID *load_given_progid(MSIPACKAGE *package, LPCWSTR name)
181 static const WCHAR query[] = {
182 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
183 '`','P','r','o','g','I','d','`',' ','W','H','E','R','E',' ',
184 '`','P','r','o','g','I','d','`',' ','=',' ','\'','%','s','\'',0};
185 MSIPROGID *progid;
186 MSIRECORD *row;
188 if (!name)
189 return NULL;
191 /* check for progids already loaded */
192 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
194 if (!strcmpiW( progid->ProgID, name ))
196 TRACE("found progid %s (%p)\n",debugstr_w(name), progid );
197 return progid;
201 row = MSI_QueryGetRecord( package->db, query, name );
202 if (!row)
203 return NULL;
205 progid = load_progid(package, row);
206 msiobj_release(&row->hdr);
207 return progid;
210 static MSICLASS *load_class( MSIPACKAGE* package, MSIRECORD *row )
212 MSICLASS *cls;
213 DWORD i;
214 LPCWSTR buffer;
216 /* fill in the data */
218 cls = msi_alloc_zero( sizeof(MSICLASS) );
219 if (!cls)
220 return NULL;
222 list_add_tail( &package->classes, &cls->entry );
224 cls->clsid = msi_dup_record_field( row, 1 );
225 TRACE("loading class %s\n",debugstr_w(cls->clsid));
226 cls->Context = msi_dup_record_field( row, 2 );
227 buffer = MSI_RecordGetString(row,3);
228 cls->Component = msi_get_loaded_component( package, buffer );
230 cls->ProgIDText = msi_dup_record_field(row,4);
231 cls->ProgID = load_given_progid(package, cls->ProgIDText);
233 cls->Description = msi_dup_record_field(row,5);
235 buffer = MSI_RecordGetString(row,6);
236 if (buffer)
237 cls->AppID = load_given_appid(package, buffer);
239 cls->FileTypeMask = msi_dup_record_field(row,7);
241 if (!MSI_RecordIsNull(row,9))
244 INT icon_index = MSI_RecordGetInteger(row,9);
245 LPCWSTR FileName = MSI_RecordGetString(row,8);
246 LPWSTR FilePath;
247 static const WCHAR fmt[] = {'%','s',',','%','i',0};
249 FilePath = msi_build_icon_path(package, FileName);
251 cls->IconPath = msi_alloc( (strlenW(FilePath)+5)* sizeof(WCHAR) );
253 sprintfW(cls->IconPath,fmt,FilePath,icon_index);
255 msi_free(FilePath);
257 else
259 buffer = MSI_RecordGetString(row,8);
260 if (buffer)
261 cls->IconPath = msi_build_icon_path(package, buffer);
264 if (!MSI_RecordIsNull(row,10))
266 i = MSI_RecordGetInteger(row,10);
267 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
269 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
270 static const WCHAR ole32[] = {'o','l','e','3','2','.','d','l','l',0};
272 switch(i)
274 case 1:
275 cls->DefInprocHandler = strdupW(ole2);
276 break;
277 case 2:
278 cls->DefInprocHandler32 = strdupW(ole32);
279 break;
280 case 3:
281 cls->DefInprocHandler = strdupW(ole2);
282 cls->DefInprocHandler32 = strdupW(ole32);
283 break;
286 else
288 cls->DefInprocHandler32 = msi_dup_record_field( row, 10 );
289 msi_reduce_to_long_filename( cls->DefInprocHandler32 );
292 buffer = MSI_RecordGetString(row,11);
293 deformat_string(package,buffer,&cls->Argument);
295 buffer = MSI_RecordGetString(row,12);
296 cls->Feature = msi_get_loaded_feature(package, buffer);
298 cls->Attributes = MSI_RecordGetInteger(row,13);
300 return cls;
304 * the Class table has 3 primary keys. Generally it is only
305 * referenced through the first CLSID key. However when loading
306 * all of the classes we need to make sure we do not ignore rows
307 * with other Context and ComponentIndexs
309 static MSICLASS *load_given_class(MSIPACKAGE *package, LPCWSTR classid)
311 static const WCHAR query[] = {
312 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
313 '`','C','l','a','s','s','`',' ','W','H','E','R','E',' ',
314 '`','C','L','S','I','D','`',' ','=',' ','\'','%','s','\'',0};
315 MSICLASS *cls;
316 MSIRECORD *row;
318 if (!classid)
319 return NULL;
321 /* check for classes already loaded */
322 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
324 if (!strcmpiW( cls->clsid, classid ))
326 TRACE("found class %s (%p)\n",debugstr_w(classid), cls);
327 return cls;
331 row = MSI_QueryGetRecord(package->db, query, classid);
332 if (!row)
333 return NULL;
335 cls = load_class(package, row);
336 msiobj_release(&row->hdr);
337 return cls;
340 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR extension );
342 static MSIMIME *load_mime( MSIPACKAGE* package, MSIRECORD *row )
344 LPCWSTR extension;
345 MSIMIME *mt;
347 /* fill in the data */
349 mt = msi_alloc_zero( sizeof(MSIMIME) );
350 if (!mt)
351 return mt;
353 mt->ContentType = msi_dup_record_field( row, 1 );
354 TRACE("loading mime %s\n", debugstr_w(mt->ContentType));
356 extension = MSI_RecordGetString( row, 2 );
357 mt->Extension = load_given_extension( package, extension );
358 mt->suffix = strdupW( extension );
360 mt->clsid = msi_dup_record_field( row, 3 );
361 mt->Class = load_given_class( package, mt->clsid );
363 list_add_tail( &package->mimes, &mt->entry );
365 return mt;
368 static MSIMIME *load_given_mime( MSIPACKAGE *package, LPCWSTR mime )
370 static const WCHAR query[] = {
371 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
372 '`','M','I','M','E','`',' ','W','H','E','R','E',' ',
373 '`','C','o','n','t','e','n','t','T','y','p','e','`',' ','=',' ','\'','%','s','\'',0};
374 MSIRECORD *row;
375 MSIMIME *mt;
377 if (!mime)
378 return NULL;
380 /* check for mime already loaded */
381 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
383 if (!strcmpiW( mt->ContentType, mime ))
385 TRACE("found mime %s (%p)\n",debugstr_w(mime), mt);
386 return mt;
390 row = MSI_QueryGetRecord(package->db, query, mime);
391 if (!row)
392 return NULL;
394 mt = load_mime(package, row);
395 msiobj_release(&row->hdr);
396 return mt;
399 static MSIEXTENSION *load_extension( MSIPACKAGE* package, MSIRECORD *row )
401 MSIEXTENSION *ext;
402 LPCWSTR buffer;
404 /* fill in the data */
406 ext = msi_alloc_zero( sizeof(MSIEXTENSION) );
407 if (!ext)
408 return NULL;
410 list_init( &ext->verbs );
412 list_add_tail( &package->extensions, &ext->entry );
414 ext->Extension = msi_dup_record_field( row, 1 );
415 TRACE("loading extension %s\n", debugstr_w(ext->Extension));
417 buffer = MSI_RecordGetString( row, 2 );
418 ext->Component = msi_get_loaded_component( package, buffer );
420 ext->ProgIDText = msi_dup_record_field( row, 3 );
421 ext->ProgID = load_given_progid( package, ext->ProgIDText );
423 buffer = MSI_RecordGetString( row, 4 );
424 ext->Mime = load_given_mime( package, buffer );
426 buffer = MSI_RecordGetString(row,5);
427 ext->Feature = msi_get_loaded_feature( package, buffer );
429 return ext;
433 * While the extension table has 2 primary keys, this function is only looking
434 * at the Extension key which is what is referenced as a foreign key
436 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR name )
438 static const WCHAR query[] = {
439 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
440 '`','E','x','t','e','n','s','i','o','n','`',' ','W','H','E','R','E',' ',
441 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ','\'','%','s','\'',0};
442 MSIEXTENSION *ext;
443 MSIRECORD *row;
445 if (!name)
446 return NULL;
448 if (name[0] == '.')
449 name++;
451 /* check for extensions already loaded */
452 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
454 if (!strcmpiW( ext->Extension, name ))
456 TRACE("extension %s already loaded %p\n", debugstr_w(name), ext);
457 return ext;
461 row = MSI_QueryGetRecord( package->db, query, name );
462 if (!row)
463 return NULL;
465 ext = load_extension(package, row);
466 msiobj_release(&row->hdr);
467 return ext;
470 static UINT iterate_load_verb(MSIRECORD *row, LPVOID param)
472 MSIPACKAGE* package = param;
473 MSIVERB *verb;
474 LPCWSTR buffer;
475 MSIEXTENSION *extension;
477 buffer = MSI_RecordGetString(row,1);
478 extension = load_given_extension( package, buffer );
479 if (!extension)
481 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer));
482 return ERROR_SUCCESS;
485 /* fill in the data */
487 verb = msi_alloc_zero( sizeof(MSIVERB) );
488 if (!verb)
489 return ERROR_OUTOFMEMORY;
491 verb->Verb = msi_dup_record_field(row,2);
492 TRACE("loading verb %s\n",debugstr_w(verb->Verb));
493 verb->Sequence = MSI_RecordGetInteger(row,3);
495 buffer = MSI_RecordGetString(row,4);
496 deformat_string(package,buffer,&verb->Command);
498 buffer = MSI_RecordGetString(row,5);
499 deformat_string(package,buffer,&verb->Argument);
501 /* associate the verb with the correct extension */
502 list_add_tail( &extension->verbs, &verb->entry );
504 return ERROR_SUCCESS;
507 static UINT iterate_all_classes(MSIRECORD *rec, LPVOID param)
509 MSICOMPONENT *comp;
510 LPCWSTR clsid;
511 LPCWSTR context;
512 LPCWSTR buffer;
513 MSIPACKAGE* package = param;
514 MSICLASS *cls;
515 BOOL match = FALSE;
517 clsid = MSI_RecordGetString(rec,1);
518 context = MSI_RecordGetString(rec,2);
519 buffer = MSI_RecordGetString(rec,3);
520 comp = msi_get_loaded_component(package, buffer);
522 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
524 if (strcmpiW( clsid, cls->clsid ))
525 continue;
526 if (strcmpW( context, cls->Context ))
527 continue;
528 if (comp == cls->Component)
530 match = TRUE;
531 break;
535 if (!match)
536 load_class(package, rec);
538 return ERROR_SUCCESS;
541 static UINT load_all_classes( MSIPACKAGE *package )
543 static const WCHAR query[] = {
544 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ','`','C','l','a','s','s','`',0};
545 MSIQUERY *view;
546 UINT rc;
548 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
549 if (rc != ERROR_SUCCESS)
550 return ERROR_SUCCESS;
552 rc = MSI_IterateRecords(view, NULL, iterate_all_classes, package);
553 msiobj_release(&view->hdr);
554 return rc;
557 static UINT iterate_all_extensions(MSIRECORD *rec, LPVOID param)
559 MSICOMPONENT *comp;
560 LPCWSTR buffer;
561 LPCWSTR extension;
562 MSIPACKAGE* package = param;
563 BOOL match = FALSE;
564 MSIEXTENSION *ext;
566 extension = MSI_RecordGetString(rec,1);
567 buffer = MSI_RecordGetString(rec,2);
568 comp = msi_get_loaded_component(package, buffer);
570 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
572 if (strcmpiW(extension, ext->Extension))
573 continue;
574 if (comp == ext->Component)
576 match = TRUE;
577 break;
581 if (!match)
582 load_extension(package, rec);
584 return ERROR_SUCCESS;
587 static UINT load_all_extensions( MSIPACKAGE *package )
589 static const WCHAR query[] = {
590 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','E','x','t','e','n','s','i','o','n','`',0};
591 MSIQUERY *view;
592 UINT rc;
594 rc = MSI_DatabaseOpenViewW( package->db, query, &view );
595 if (rc != ERROR_SUCCESS)
596 return ERROR_SUCCESS;
598 rc = MSI_IterateRecords(view, NULL, iterate_all_extensions, package);
599 msiobj_release(&view->hdr);
600 return rc;
603 static UINT iterate_all_progids(MSIRECORD *rec, LPVOID param)
605 LPCWSTR buffer;
606 MSIPACKAGE* package = param;
608 buffer = MSI_RecordGetString(rec,1);
609 load_given_progid(package,buffer);
610 return ERROR_SUCCESS;
613 static UINT load_all_progids( MSIPACKAGE *package )
615 static const WCHAR query[] = {
616 'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ','F','R','O','M',' ',
617 '`','P','r','o','g','I','d','`',0};
618 MSIQUERY *view;
619 UINT rc;
621 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
622 if (rc != ERROR_SUCCESS)
623 return ERROR_SUCCESS;
625 rc = MSI_IterateRecords(view, NULL, iterate_all_progids, package);
626 msiobj_release(&view->hdr);
627 return rc;
630 static UINT load_all_verbs( MSIPACKAGE *package )
632 static const WCHAR query[] = {
633 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','V','e','r','b','`',0};
634 MSIQUERY *view;
635 UINT rc;
637 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
638 if (rc != ERROR_SUCCESS)
639 return ERROR_SUCCESS;
641 rc = MSI_IterateRecords(view, NULL, iterate_load_verb, package);
642 msiobj_release(&view->hdr);
643 return rc;
646 static UINT iterate_all_mimes(MSIRECORD *rec, LPVOID param)
648 LPCWSTR buffer;
649 MSIPACKAGE* package = param;
651 buffer = MSI_RecordGetString(rec,1);
652 load_given_mime(package,buffer);
653 return ERROR_SUCCESS;
656 static UINT load_all_mimes( MSIPACKAGE *package )
658 static const WCHAR query[] = {
659 'S','E','L','E','C','T',' ','`','C','o','n','t','e','n','t','T','y','p','e','`',' ',
660 'F','R','O','M',' ','`','M','I','M','E','`',0};
661 MSIQUERY *view;
662 UINT rc;
664 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
665 if (rc != ERROR_SUCCESS)
666 return ERROR_SUCCESS;
668 rc = MSI_IterateRecords(view, NULL, iterate_all_mimes, package);
669 msiobj_release(&view->hdr);
670 return rc;
673 static UINT load_classes_and_such( MSIPACKAGE *package )
675 UINT r;
677 TRACE("Loading all the class info and related tables\n");
679 /* check if already loaded */
680 if (!list_empty( &package->classes ) ||
681 !list_empty( &package->mimes ) ||
682 !list_empty( &package->extensions ) ||
683 !list_empty( &package->progids )) return ERROR_SUCCESS;
685 r = load_all_classes( package );
686 if (r != ERROR_SUCCESS) return r;
688 r = load_all_extensions( package );
689 if (r != ERROR_SUCCESS) return r;
691 r = load_all_progids( package );
692 if (r != ERROR_SUCCESS) return r;
694 /* these loads must come after the other loads */
695 r = load_all_verbs( package );
696 if (r != ERROR_SUCCESS) return r;
698 return load_all_mimes( package );
701 static void mark_progid_for_install( MSIPACKAGE* package, MSIPROGID *progid )
703 MSIPROGID *child;
705 if (!progid)
706 return;
708 if (progid->InstallMe)
709 return;
711 progid->InstallMe = TRUE;
713 /* all children if this is a parent also install */
714 LIST_FOR_EACH_ENTRY( child, &package->progids, MSIPROGID, entry )
716 if (child->Parent == progid)
717 mark_progid_for_install( package, child );
721 static void mark_progid_for_uninstall( MSIPACKAGE *package, MSIPROGID *progid )
723 MSIPROGID *child;
725 if (!progid)
726 return;
728 if (!progid->InstallMe)
729 return;
731 progid->InstallMe = FALSE;
733 LIST_FOR_EACH_ENTRY( child, &package->progids, MSIPROGID, entry )
735 if (child->Parent == progid)
736 mark_progid_for_uninstall( package, child );
740 static void mark_mime_for_install( MSIMIME *mime )
742 if (!mime)
743 return;
744 mime->InstallMe = TRUE;
747 static void mark_mime_for_uninstall( MSIMIME *mime )
749 if (!mime)
750 return;
751 mime->InstallMe = FALSE;
754 static UINT register_appid(const MSIAPPID *appid, LPCWSTR app )
756 static const WCHAR szRemoteServerName[] =
757 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
758 static const WCHAR szLocalService[] =
759 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
760 static const WCHAR szService[] =
761 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
762 static const WCHAR szDLL[] =
763 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
764 static const WCHAR szActivate[] =
765 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
766 static const WCHAR szY[] = {'Y',0};
767 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
768 static const WCHAR szUser[] =
769 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
771 HKEY hkey2,hkey3;
773 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
774 RegCreateKeyW( hkey2, appid->AppID, &hkey3 );
775 RegCloseKey(hkey2);
776 msi_reg_set_val_str( hkey3, NULL, app );
778 if (appid->RemoteServerName)
779 msi_reg_set_val_str( hkey3, szRemoteServerName, appid->RemoteServerName );
781 if (appid->LocalServer)
782 msi_reg_set_val_str( hkey3, szLocalService, appid->LocalServer );
784 if (appid->ServiceParameters)
785 msi_reg_set_val_str( hkey3, szService, appid->ServiceParameters );
787 if (appid->DllSurrogate)
788 msi_reg_set_val_str( hkey3, szDLL, appid->DllSurrogate );
790 if (appid->ActivateAtStorage)
791 msi_reg_set_val_str( hkey3, szActivate, szY );
793 if (appid->RunAsInteractiveUser)
794 msi_reg_set_val_str( hkey3, szRunAs, szUser );
796 RegCloseKey(hkey3);
797 return ERROR_SUCCESS;
800 UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
802 static const WCHAR szFileType_fmt[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
803 const WCHAR *keypath;
804 MSIRECORD *uirow;
805 HKEY hkey, hkey2, hkey3;
806 MSICLASS *cls;
807 UINT r;
809 r = load_classes_and_such( package );
810 if (r != ERROR_SUCCESS)
811 return r;
813 if (is_64bit && package->platform == PLATFORM_INTEL)
814 keypath = szWow6432NodeCLSID;
815 else
816 keypath = szCLSID;
818 if (RegCreateKeyW(HKEY_CLASSES_ROOT, keypath, &hkey) != ERROR_SUCCESS)
819 return ERROR_FUNCTION_FAILED;
821 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
823 MSICOMPONENT *comp;
824 MSIFILE *file;
825 DWORD size;
826 LPWSTR argument;
827 MSIFEATURE *feature;
829 comp = cls->Component;
830 if ( !comp )
831 continue;
833 if (!comp->Enabled)
835 TRACE("component is disabled\n");
836 continue;
839 feature = cls->Feature;
840 if (!feature)
841 continue;
843 feature->Action = msi_get_feature_action( package, feature );
844 if (feature->Action != INSTALLSTATE_LOCAL &&
845 feature->Action != INSTALLSTATE_ADVERTISED )
847 TRACE("feature %s not scheduled for installation, skipping registration of class %s\n",
848 debugstr_w(feature->Feature), debugstr_w(cls->clsid));
849 continue;
852 if (!comp->KeyPath || !(file = msi_get_loaded_file( package, comp->KeyPath )))
854 TRACE("COM server not provided, skipping class %s\n", debugstr_w(cls->clsid));
855 continue;
857 TRACE("Registering class %s (%p)\n", debugstr_w(cls->clsid), cls);
859 cls->Installed = TRUE;
860 mark_progid_for_install( package, cls->ProgID );
862 RegCreateKeyW( hkey, cls->clsid, &hkey2 );
864 if (cls->Description)
865 msi_reg_set_val_str( hkey2, NULL, cls->Description );
867 RegCreateKeyW( hkey2, cls->Context, &hkey3 );
870 * FIXME: Implement install on demand (advertised components).
872 * ole32.dll should call msi.MsiProvideComponentFromDescriptor()
873 * when it needs an InProcServer that doesn't exist.
874 * The component advertise string should be in the "InProcServer" value.
876 size = lstrlenW( file->TargetPath )+1;
877 if (cls->Argument)
878 size += lstrlenW(cls->Argument)+1;
880 argument = msi_alloc( size * sizeof(WCHAR) );
881 lstrcpyW( argument, file->TargetPath );
883 if (cls->Argument)
885 lstrcatW( argument, szSpace );
886 lstrcatW( argument, cls->Argument );
889 msi_reg_set_val_str( hkey3, NULL, argument );
890 msi_free(argument);
892 RegCloseKey(hkey3);
894 if (cls->ProgID || cls->ProgIDText)
896 LPCWSTR progid;
898 if (cls->ProgID)
899 progid = cls->ProgID->ProgID;
900 else
901 progid = cls->ProgIDText;
903 msi_reg_set_subkey_val( hkey2, szProgID, NULL, progid );
905 if (cls->ProgID && cls->ProgID->VersionInd)
907 msi_reg_set_subkey_val( hkey2, szVIProgID, NULL,
908 cls->ProgID->VersionInd->ProgID );
912 if (cls->AppID)
914 MSIAPPID *appid = cls->AppID;
915 msi_reg_set_val_str( hkey2, szAppID, appid->AppID );
916 register_appid( appid, cls->Description );
919 if (cls->IconPath)
920 msi_reg_set_subkey_val( hkey2, szDefaultIcon, NULL, cls->IconPath );
922 if (cls->DefInprocHandler)
923 msi_reg_set_subkey_val( hkey2, szInprocHandler, NULL, cls->DefInprocHandler );
925 if (cls->DefInprocHandler32)
926 msi_reg_set_subkey_val( hkey2, szInprocHandler32, 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);
958 MSI_RecordSetStringW( uirow, 1, cls->clsid );
959 msi_ui_actiondata( package, szRegisterClassInfo, uirow );
960 msiobj_release(&uirow->hdr);
962 RegCloseKey(hkey);
963 return ERROR_SUCCESS;
966 UINT ACTION_UnregisterClassInfo( MSIPACKAGE *package )
968 static const WCHAR szFileType[] = {'F','i','l','e','T','y','p','e','\\',0};
969 const WCHAR *keypath;
970 MSIRECORD *uirow;
971 MSICLASS *cls;
972 HKEY hkey, hkey2;
973 UINT r;
975 r = load_classes_and_such( package );
976 if (r != ERROR_SUCCESS)
977 return r;
979 if (is_64bit && package->platform == PLATFORM_INTEL)
980 keypath = szWow6432NodeCLSID;
981 else
982 keypath = szCLSID;
984 if (RegOpenKeyW( HKEY_CLASSES_ROOT, keypath, &hkey ) != ERROR_SUCCESS)
985 return ERROR_SUCCESS;
987 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
989 MSIFEATURE *feature;
990 MSICOMPONENT *comp;
991 LPWSTR filetype;
992 LONG res;
994 comp = cls->Component;
995 if (!comp)
996 continue;
998 if (!comp->Enabled)
1000 TRACE("component is disabled\n");
1001 continue;
1004 feature = cls->Feature;
1005 if (!feature)
1006 continue;
1008 feature->Action = msi_get_feature_action( package, feature );
1009 if (feature->Action != INSTALLSTATE_ABSENT)
1011 TRACE("feature %s not scheduled for removal, skipping unregistration of class %s\n",
1012 debugstr_w(feature->Feature), debugstr_w(cls->clsid));
1013 continue;
1015 TRACE("Unregistering class %s (%p)\n", debugstr_w(cls->clsid), cls);
1017 cls->Installed = FALSE;
1018 mark_progid_for_uninstall( package, cls->ProgID );
1020 res = RegDeleteTreeW( hkey, cls->clsid );
1021 if (res != ERROR_SUCCESS)
1022 WARN("Failed to delete class key %d\n", res);
1024 if (cls->AppID)
1026 res = RegOpenKeyW( HKEY_CLASSES_ROOT, szAppID, &hkey2 );
1027 if (res == ERROR_SUCCESS)
1029 res = RegDeleteKeyW( hkey2, cls->AppID->AppID );
1030 if (res != ERROR_SUCCESS)
1031 WARN("Failed to delete appid key %d\n", res);
1032 RegCloseKey( hkey2 );
1035 if (cls->FileTypeMask)
1037 filetype = msi_alloc( (strlenW( szFileType ) + strlenW( cls->clsid ) + 1) * sizeof(WCHAR) );
1038 if (filetype)
1040 strcpyW( filetype, szFileType );
1041 strcatW( filetype, cls->clsid );
1042 res = RegDeleteTreeW( HKEY_CLASSES_ROOT, filetype );
1043 msi_free( filetype );
1045 if (res != ERROR_SUCCESS)
1046 WARN("Failed to delete file type %d\n", res);
1050 uirow = MSI_CreateRecord( 1 );
1051 MSI_RecordSetStringW( uirow, 1, cls->clsid );
1052 msi_ui_actiondata( package, szUnregisterClassInfo, uirow );
1053 msiobj_release( &uirow->hdr );
1055 RegCloseKey( hkey );
1056 return ERROR_SUCCESS;
1059 static LPCWSTR get_clsid_of_progid( const MSIPROGID *progid )
1061 while (progid)
1063 if (progid->Class)
1064 return progid->Class->clsid;
1065 if (progid->Parent == progid)
1066 break;
1067 progid = progid->Parent;
1069 return NULL;
1072 static UINT register_progid( const MSIPROGID* progid )
1074 static const WCHAR szCurVer[] = {'C','u','r','V','e','r',0};
1075 HKEY hkey = 0;
1076 UINT rc;
1078 rc = RegCreateKeyW( HKEY_CLASSES_ROOT, progid->ProgID, &hkey );
1079 if (rc == ERROR_SUCCESS)
1081 LPCWSTR clsid = get_clsid_of_progid( progid );
1083 if (clsid)
1084 msi_reg_set_subkey_val( hkey, szCLSID, NULL, clsid );
1085 else
1086 TRACE("%s has no class\n", debugstr_w( progid->ProgID ) );
1088 if (progid->Description)
1089 msi_reg_set_val_str( hkey, NULL, progid->Description );
1091 if (progid->IconPath)
1092 msi_reg_set_subkey_val( hkey, szDefaultIcon, NULL, progid->IconPath );
1094 /* write out the current version */
1095 if (progid->CurVer)
1096 msi_reg_set_subkey_val( hkey, szCurVer, NULL, progid->CurVer->ProgID );
1098 RegCloseKey(hkey);
1100 else
1101 ERR("failed to create key %s\n", debugstr_w( progid->ProgID ) );
1103 return rc;
1106 UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
1108 MSIPROGID *progid;
1109 MSIRECORD *uirow;
1110 UINT r;
1112 r = load_classes_and_such( package );
1113 if (r != ERROR_SUCCESS)
1114 return r;
1116 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
1118 /* check if this progid is to be installed */
1119 if (progid->Class && progid->Class->Installed)
1120 progid->InstallMe = TRUE;
1122 if (!progid->InstallMe)
1124 TRACE("progid %s not scheduled to be installed\n",
1125 debugstr_w(progid->ProgID));
1126 continue;
1129 TRACE("Registering progid %s\n", debugstr_w(progid->ProgID));
1131 register_progid( progid );
1133 uirow = MSI_CreateRecord( 1 );
1134 MSI_RecordSetStringW( uirow, 1, progid->ProgID );
1135 msi_ui_actiondata( package, szRegisterProgIdInfo, uirow );
1136 msiobj_release( &uirow->hdr );
1138 return ERROR_SUCCESS;
1141 UINT ACTION_UnregisterProgIdInfo( MSIPACKAGE *package )
1143 MSIPROGID *progid;
1144 MSIRECORD *uirow;
1145 LONG res;
1146 UINT r;
1148 r = load_classes_and_such( package );
1149 if (r != ERROR_SUCCESS)
1150 return r;
1152 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
1154 /* check if this progid is to be removed */
1155 if (progid->Class && !progid->Class->Installed)
1156 progid->InstallMe = FALSE;
1158 if (progid->InstallMe)
1160 TRACE("progid %s not scheduled to be removed\n", debugstr_w(progid->ProgID));
1161 continue;
1164 TRACE("Unregistering progid %s\n", debugstr_w(progid->ProgID));
1166 res = RegDeleteTreeW( HKEY_CLASSES_ROOT, progid->ProgID );
1167 if (res != ERROR_SUCCESS)
1168 TRACE("Failed to delete progid key %d\n", res);
1170 uirow = MSI_CreateRecord( 1 );
1171 MSI_RecordSetStringW( uirow, 1, progid->ProgID );
1172 msi_ui_actiondata( package, szUnregisterProgIdInfo, uirow );
1173 msiobj_release( &uirow->hdr );
1175 return ERROR_SUCCESS;
1178 static UINT register_verb(MSIPACKAGE *package, LPCWSTR progid,
1179 MSICOMPONENT* component, const MSIEXTENSION* extension,
1180 MSIVERB* verb, INT* Sequence )
1182 LPWSTR keyname;
1183 HKEY key;
1184 static const WCHAR szShell[] = {'s','h','e','l','l',0};
1185 static const WCHAR szCommand[] = {'c','o','m','m','a','n','d',0};
1186 static const WCHAR fmt[] = {'\"','%','s','\"',' ','%','s',0};
1187 static const WCHAR fmt2[] = {'\"','%','s','\"',0};
1188 LPWSTR command;
1189 DWORD size;
1190 LPWSTR advertise;
1192 keyname = msi_build_directory_name(4, progid, szShell, verb->Verb, szCommand);
1194 TRACE("Making Key %s\n",debugstr_w(keyname));
1195 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
1196 size = strlenW(component->FullKeypath);
1197 if (verb->Argument)
1198 size += strlenW(verb->Argument);
1199 size += 4;
1201 command = msi_alloc(size * sizeof (WCHAR));
1202 if (verb->Argument)
1203 sprintfW(command, fmt, component->FullKeypath, verb->Argument);
1204 else
1205 sprintfW(command, fmt2, component->FullKeypath);
1207 msi_reg_set_val_str( key, NULL, command );
1208 msi_free(command);
1210 advertise = msi_create_component_advertise_string(package, component,
1211 extension->Feature->Feature);
1212 size = strlenW(advertise);
1214 if (verb->Argument)
1215 size += strlenW(verb->Argument);
1216 size += 4;
1218 command = msi_alloc_zero(size * sizeof (WCHAR));
1220 strcpyW(command,advertise);
1221 if (verb->Argument)
1223 strcatW(command,szSpace);
1224 strcatW(command,verb->Argument);
1227 msi_reg_set_val_multi_str( key, szCommand, command );
1229 RegCloseKey(key);
1230 msi_free(keyname);
1231 msi_free(advertise);
1232 msi_free(command);
1234 if (verb->Command)
1236 keyname = msi_build_directory_name( 3, progid, szShell, verb->Verb );
1237 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, verb->Command );
1238 msi_free(keyname);
1241 if (verb->Sequence != MSI_NULL_INTEGER)
1243 if (*Sequence == MSI_NULL_INTEGER || verb->Sequence < *Sequence)
1245 *Sequence = verb->Sequence;
1246 keyname = msi_build_directory_name( 2, progid, szShell );
1247 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, verb->Verb );
1248 msi_free(keyname);
1251 return ERROR_SUCCESS;
1254 UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
1256 static const WCHAR szContentType[] = {'C','o','n','t','e','n','t',' ','T','y','p','e',0};
1257 HKEY hkey = NULL;
1258 MSIEXTENSION *ext;
1259 MSIRECORD *uirow;
1260 BOOL install_on_demand = TRUE;
1261 LONG res;
1262 UINT r;
1264 r = load_classes_and_such( package );
1265 if (r != ERROR_SUCCESS)
1266 return r;
1268 /* We need to set install_on_demand based on if the shell handles advertised
1269 * shortcuts and the like. Because Mike McCormack is working on this i am
1270 * going to default to TRUE
1273 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
1275 LPWSTR extension;
1276 MSIFEATURE *feature;
1278 if (!ext->Component)
1279 continue;
1281 if (!ext->Component->Enabled)
1283 TRACE("component is disabled\n");
1284 continue;
1287 feature = ext->Feature;
1288 if (!feature)
1289 continue;
1292 * yes. MSDN says that these are based on _Feature_ not on
1293 * Component. So verify the feature is to be installed
1295 feature->Action = msi_get_feature_action( package, feature );
1296 if (feature->Action != INSTALLSTATE_LOCAL &&
1297 !(install_on_demand && feature->Action == INSTALLSTATE_ADVERTISED))
1299 TRACE("feature %s not scheduled for installation, skipping registration of extension %s\n",
1300 debugstr_w(feature->Feature), debugstr_w(ext->Extension));
1301 continue;
1303 TRACE("Registering extension %s (%p)\n", debugstr_w(ext->Extension), ext);
1305 ext->Installed = TRUE;
1307 /* this is only registered if the extension has at least 1 verb
1308 * according to MSDN
1310 if (ext->ProgID && !list_empty( &ext->verbs ) )
1311 mark_progid_for_install( package, ext->ProgID );
1313 mark_mime_for_install(ext->Mime);
1315 extension = msi_alloc( (strlenW( ext->Extension ) + 2) * sizeof(WCHAR) );
1316 if (extension)
1318 extension[0] = '.';
1319 strcpyW( extension + 1, ext->Extension );
1320 res = RegCreateKeyW( HKEY_CLASSES_ROOT, extension, &hkey );
1321 msi_free( extension );
1322 if (res != ERROR_SUCCESS)
1323 WARN("Failed to create extension key %d\n", res);
1326 if (ext->Mime)
1327 msi_reg_set_val_str( hkey, szContentType, ext->Mime->ContentType );
1329 if (ext->ProgID || ext->ProgIDText)
1331 static const WCHAR szSN[] =
1332 {'\\','S','h','e','l','l','N','e','w',0};
1333 HKEY hkey2;
1334 LPWSTR newkey;
1335 LPCWSTR progid;
1336 MSIVERB *verb;
1337 INT Sequence = MSI_NULL_INTEGER;
1339 if (ext->ProgID)
1340 progid = ext->ProgID->ProgID;
1341 else
1342 progid = ext->ProgIDText;
1344 msi_reg_set_val_str( hkey, NULL, progid );
1346 newkey = msi_alloc( (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
1348 strcpyW(newkey,progid);
1349 strcatW(newkey,szSN);
1350 RegCreateKeyW(hkey,newkey,&hkey2);
1351 RegCloseKey(hkey2);
1353 msi_free(newkey);
1355 /* do all the verbs */
1356 LIST_FOR_EACH_ENTRY( verb, &ext->verbs, MSIVERB, entry )
1358 register_verb( package, progid, ext->Component,
1359 ext, verb, &Sequence);
1363 RegCloseKey(hkey);
1365 uirow = MSI_CreateRecord(1);
1366 MSI_RecordSetStringW( uirow, 1, ext->Extension );
1367 msi_ui_actiondata( package, szRegisterExtensionInfo, uirow );
1368 msiobj_release(&uirow->hdr);
1370 return ERROR_SUCCESS;
1373 UINT ACTION_UnregisterExtensionInfo( MSIPACKAGE *package )
1375 MSIEXTENSION *ext;
1376 MSIRECORD *uirow;
1377 LONG res;
1378 UINT r;
1380 r = load_classes_and_such( package );
1381 if (r != ERROR_SUCCESS)
1382 return r;
1384 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
1386 LPWSTR extension;
1387 MSIFEATURE *feature;
1389 if (!ext->Component)
1390 continue;
1392 if (!ext->Component->Enabled)
1394 TRACE("component is disabled\n");
1395 continue;
1398 feature = ext->Feature;
1399 if (!feature)
1400 continue;
1402 feature->Action = msi_get_feature_action( package, feature );
1403 if (feature->Action != INSTALLSTATE_ABSENT)
1405 TRACE("feature %s not scheduled for removal, skipping unregistration of extension %s\n",
1406 debugstr_w(feature->Feature), debugstr_w(ext->Extension));
1407 continue;
1409 TRACE("Unregistering extension %s\n", debugstr_w(ext->Extension));
1411 ext->Installed = FALSE;
1413 if (ext->ProgID && !list_empty( &ext->verbs ))
1414 mark_progid_for_uninstall( package, ext->ProgID );
1416 mark_mime_for_uninstall( ext->Mime );
1418 extension = msi_alloc( (strlenW( ext->Extension ) + 2) * sizeof(WCHAR) );
1419 if (extension)
1421 extension[0] = '.';
1422 strcpyW( extension + 1, ext->Extension );
1423 res = RegDeleteTreeW( HKEY_CLASSES_ROOT, extension );
1424 msi_free( extension );
1425 if (res != ERROR_SUCCESS)
1426 WARN("Failed to delete extension key %d\n", res);
1429 if (ext->ProgID || ext->ProgIDText)
1431 static const WCHAR shellW[] = {'\\','s','h','e','l','l',0};
1432 LPCWSTR progid;
1433 LPWSTR progid_shell;
1435 if (ext->ProgID)
1436 progid = ext->ProgID->ProgID;
1437 else
1438 progid = ext->ProgIDText;
1440 progid_shell = msi_alloc( (strlenW( progid ) + strlenW( shellW ) + 1) * sizeof(WCHAR) );
1441 if (progid_shell)
1443 strcpyW( progid_shell, progid );
1444 strcatW( progid_shell, shellW );
1445 res = RegDeleteTreeW( HKEY_CLASSES_ROOT, progid_shell );
1446 msi_free( progid_shell );
1447 if (res != ERROR_SUCCESS)
1448 WARN("Failed to delete shell key %d\n", res);
1449 RegDeleteKeyW( HKEY_CLASSES_ROOT, progid );
1453 uirow = MSI_CreateRecord( 1 );
1454 MSI_RecordSetStringW( uirow, 1, ext->Extension );
1455 msi_ui_actiondata( package, szUnregisterExtensionInfo, uirow );
1456 msiobj_release( &uirow->hdr );
1458 return ERROR_SUCCESS;
1461 UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
1463 static const WCHAR szExtension[] = {'E','x','t','e','n','s','i','o','n',0};
1464 MSIRECORD *uirow;
1465 MSIMIME *mt;
1466 UINT r;
1468 r = load_classes_and_such( package );
1469 if (r != ERROR_SUCCESS)
1470 return r;
1472 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
1474 LPWSTR extension, key;
1477 * check if the MIME is to be installed. Either as requested by an
1478 * extension or Class
1480 mt->InstallMe = (mt->InstallMe ||
1481 (mt->Class && mt->Class->Installed) ||
1482 (mt->Extension && mt->Extension->Installed));
1484 if (!mt->InstallMe)
1486 TRACE("MIME %s not scheduled to be installed\n", debugstr_w(mt->ContentType));
1487 continue;
1490 TRACE("Registering MIME type %s\n", debugstr_w(mt->ContentType));
1492 extension = msi_alloc( (strlenW( mt->Extension->Extension ) + 2) * sizeof(WCHAR) );
1493 key = msi_alloc( (strlenW( mt->ContentType ) + strlenW( szMIMEDatabase ) + 1) * sizeof(WCHAR) );
1495 if (extension && key)
1497 extension[0] = '.';
1498 strcpyW( extension + 1, mt->Extension->Extension );
1500 strcpyW( key, szMIMEDatabase );
1501 strcatW( key, mt->ContentType );
1502 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, key, szExtension, extension );
1504 if (mt->clsid)
1505 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, key, szCLSID, mt->clsid );
1507 msi_free( extension );
1508 msi_free( key );
1510 uirow = MSI_CreateRecord( 2 );
1511 MSI_RecordSetStringW( uirow, 1, mt->ContentType );
1512 MSI_RecordSetStringW( uirow, 2, mt->suffix );
1513 msi_ui_actiondata( package, szRegisterMIMEInfo, uirow );
1514 msiobj_release( &uirow->hdr );
1516 return ERROR_SUCCESS;
1519 UINT ACTION_UnregisterMIMEInfo( MSIPACKAGE *package )
1521 MSIRECORD *uirow;
1522 MSIMIME *mime;
1523 UINT r;
1525 r = load_classes_and_such( package );
1526 if (r != ERROR_SUCCESS)
1527 return r;
1529 LIST_FOR_EACH_ENTRY( mime, &package->mimes, MSIMIME, entry )
1531 LONG res;
1532 LPWSTR mime_key;
1534 mime->InstallMe = (mime->InstallMe ||
1535 (mime->Class && mime->Class->Installed) ||
1536 (mime->Extension && mime->Extension->Installed));
1538 if (mime->InstallMe)
1540 TRACE("MIME %s not scheduled to be removed\n", debugstr_w(mime->ContentType));
1541 continue;
1544 TRACE("Unregistering MIME type %s\n", debugstr_w(mime->ContentType));
1546 mime_key = msi_alloc( (strlenW( szMIMEDatabase ) + strlenW( mime->ContentType ) + 1) * sizeof(WCHAR) );
1547 if (mime_key)
1549 strcpyW( mime_key, szMIMEDatabase );
1550 strcatW( mime_key, mime->ContentType );
1551 res = RegDeleteKeyW( HKEY_CLASSES_ROOT, mime_key );
1552 if (res != ERROR_SUCCESS)
1553 WARN("Failed to delete MIME key %d\n", res);
1554 msi_free( mime_key );
1557 uirow = MSI_CreateRecord( 2 );
1558 MSI_RecordSetStringW( uirow, 1, mime->ContentType );
1559 MSI_RecordSetStringW( uirow, 2, mime->suffix );
1560 msi_ui_actiondata( package, szUnregisterMIMEInfo, uirow );
1561 msiobj_release( &uirow->hdr );
1563 return ERROR_SUCCESS;