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:
25 * RegisterExtensionInfo
28 * UnRegisterProgIdInfo
29 * UnRegisterExtensionInfo (TODO)
30 * UnRegisterMIMEInfo (TODO)
39 #include "wine/debug.h"
42 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
46 static MSIAPPID
*load_appid( MSIPACKAGE
* package
, MSIRECORD
*row
)
51 /* fill in the data */
53 appid
= msi_alloc_zero( sizeof(MSIAPPID
) );
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
);
75 static MSIAPPID
*load_given_appid( MSIPACKAGE
*package
, LPCWSTR name
)
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};
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
);
97 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, name
);
101 appid
= load_appid(package
, row
);
102 msiobj_release(&row
->hdr
);
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
)
115 /* fill in the data */
117 progid
= msi_alloc_zero( sizeof(MSIPROGID
) );
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);
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
);
155 buffer
= MSI_RecordGetString(row
,5);
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
;
180 static MSIPROGID
*load_given_progid(MSIPACKAGE
*package
, LPCWSTR name
)
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};
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
);
202 row
= MSI_QueryGetRecord( package
->db
, ExecSeqQuery
, name
);
206 progid
= load_progid(package
, row
);
207 msiobj_release(&row
->hdr
);
212 static MSICLASS
*load_class( MSIPACKAGE
* package
, MSIRECORD
*row
)
218 /* fill in the data */
220 cls
= msi_alloc_zero( sizeof(MSICLASS
) );
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);
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);
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
);
261 buffer
= MSI_RecordGetString(row
,8);
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};
277 cls
->DefInprocHandler
= strdupW(ole2
);
280 cls
->DefInprocHandler32
= strdupW(ole32
);
283 cls
->DefInprocHandler
= strdupW(ole2
);
284 cls
->DefInprocHandler32
= strdupW(ole32
);
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);
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
)
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};
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
);
333 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, classid
);
337 cls
= load_class(package
, row
);
338 msiobj_release(&row
->hdr
);
343 static MSIEXTENSION
*load_given_extension( MSIPACKAGE
*package
, LPCWSTR extension
);
345 static MSIMIME
*load_mime( MSIPACKAGE
* package
, MSIRECORD
*row
)
350 /* fill in the data */
352 mt
= msi_alloc_zero( sizeof(MSIMIME
) );
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
);
370 static MSIMIME
*load_given_mime( MSIPACKAGE
*package
, LPCWSTR mime
)
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};
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
);
393 row
= MSI_QueryGetRecord(package
->db
, ExecSeqQuery
, mime
);
397 mt
= load_mime(package
, row
);
398 msiobj_release(&row
->hdr
);
403 static MSIEXTENSION
*load_extension( MSIPACKAGE
* package
, MSIRECORD
*row
)
408 /* fill in the data */
410 ext
= msi_alloc_zero( sizeof(MSIEXTENSION
) );
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
);
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
)
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};
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
);
467 row
= MSI_QueryGetRecord( package
->db
, ExecSeqQuery
, name
);
471 ext
= load_extension(package
, row
);
472 msiobj_release(&row
->hdr
);
477 static UINT
iterate_load_verb(MSIRECORD
*row
, LPVOID param
)
479 MSIPACKAGE
* package
= param
;
482 MSIEXTENSION
*extension
;
484 buffer
= MSI_RecordGetString(row
,1);
485 extension
= load_given_extension( package
, buffer
);
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
) );
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
)
520 MSIPACKAGE
* package
= param
;
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
))
533 if (strcmpW( context
, cls
->Context
))
535 if (comp
== cls
->Component
)
543 load_class(package
, rec
);
545 return ERROR_SUCCESS
;
548 static VOID
load_all_classes(MSIPACKAGE
*package
)
550 UINT rc
= ERROR_SUCCESS
;
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
)
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
)
570 MSIPACKAGE
* package
= param
;
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
))
582 if (comp
== ext
->Component
)
590 load_extension(package
, rec
);
592 return ERROR_SUCCESS
;
595 static VOID
load_all_extensions(MSIPACKAGE
*package
)
597 UINT rc
= ERROR_SUCCESS
;
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
)
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
)
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
;
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
)
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
;
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
)
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
)
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
;
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
)
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
) )
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
)
711 if (progid
->InstallMe
)
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
)
731 if (!progid
->InstallMe
)
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
)
747 mime
->InstallMe
= TRUE
;
750 static UINT
register_appid(const MSIAPPID
*appid
, LPCWSTR app
)
752 static const WCHAR szRemoteServerName
[] =
753 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
754 static const WCHAR szLocalService
[] =
755 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
756 static const WCHAR szService
[] =
757 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
758 static const WCHAR szDLL
[] =
759 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
760 static const WCHAR szActivate
[] =
761 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
762 static const WCHAR szY
[] = {'Y',0};
763 static const WCHAR szRunAs
[] = {'R','u','n','A','s',0};
764 static const WCHAR szUser
[] =
765 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
769 RegCreateKeyW(HKEY_CLASSES_ROOT
,szAppID
,&hkey2
);
770 RegCreateKeyW( hkey2
, appid
->AppID
, &hkey3
);
772 msi_reg_set_val_str( hkey3
, NULL
, app
);
774 if (appid
->RemoteServerName
)
775 msi_reg_set_val_str( hkey3
, szRemoteServerName
, appid
->RemoteServerName
);
777 if (appid
->LocalServer
)
778 msi_reg_set_val_str( hkey3
, szLocalService
, appid
->LocalServer
);
780 if (appid
->ServiceParameters
)
781 msi_reg_set_val_str( hkey3
, szService
, appid
->ServiceParameters
);
783 if (appid
->DllSurrogate
)
784 msi_reg_set_val_str( hkey3
, szDLL
, appid
->DllSurrogate
);
786 if (appid
->ActivateAtStorage
)
787 msi_reg_set_val_str( hkey3
, szActivate
, szY
);
789 if (appid
->RunAsInteractiveUser
)
790 msi_reg_set_val_str( hkey3
, szRunAs
, szUser
);
793 return ERROR_SUCCESS
;
796 UINT
ACTION_RegisterClassInfo(MSIPACKAGE
*package
)
798 static const WCHAR szFileType_fmt
[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
800 HKEY hkey
,hkey2
,hkey3
;
803 load_classes_and_such(package
);
804 if (RegCreateKeyW(HKEY_CLASSES_ROOT
, szCLSID
, &hkey
) != ERROR_SUCCESS
)
805 return ERROR_FUNCTION_FAILED
;
807 LIST_FOR_EACH_ENTRY( cls
, &package
->classes
, MSICLASS
, entry
)
815 comp
= cls
->Component
;
819 feature
= cls
->Feature
;
823 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
&&
824 feature
->ActionRequest
!= INSTALLSTATE_ADVERTISED
)
826 TRACE("Feature %s not scheduled for installation, skipping registration of class %s\n",
827 debugstr_w(feature
->Feature
), debugstr_w(cls
->clsid
));
830 feature
->Action
= feature
->ActionRequest
;
832 file
= get_loaded_file( package
, comp
->KeyPath
);
835 TRACE("COM server not provided, skipping class %s\n", debugstr_w(cls
->clsid
));
839 TRACE("Registering class %s (%p)\n", debugstr_w(cls
->clsid
), cls
);
841 cls
->Installed
= TRUE
;
842 mark_progid_for_install( package
, cls
->ProgID
);
844 RegCreateKeyW( hkey
, cls
->clsid
, &hkey2
);
846 if (cls
->Description
)
847 msi_reg_set_val_str( hkey2
, NULL
, cls
->Description
);
849 RegCreateKeyW( hkey2
, cls
->Context
, &hkey3
);
852 * FIXME: Implement install on demand (advertised components).
854 * ole32.dll should call msi.MsiProvideComponentFromDescriptor()
855 * when it needs an InProcServer that doesn't exist.
856 * The component advertise string should be in the "InProcServer" value.
858 size
= lstrlenW( file
->TargetPath
)+1;
860 size
+= lstrlenW(cls
->Argument
)+1;
862 argument
= msi_alloc( size
* sizeof(WCHAR
) );
863 lstrcpyW( argument
, file
->TargetPath
);
867 lstrcatW( argument
, szSpace
);
868 lstrcatW( argument
, cls
->Argument
);
871 msi_reg_set_val_str( hkey3
, NULL
, argument
);
876 if (cls
->ProgID
|| cls
->ProgIDText
)
881 progid
= cls
->ProgID
->ProgID
;
883 progid
= cls
->ProgIDText
;
885 msi_reg_set_subkey_val( hkey2
, szProgID
, NULL
, progid
);
887 if (cls
->ProgID
&& cls
->ProgID
->VersionInd
)
889 msi_reg_set_subkey_val( hkey2
, szVIProgID
, NULL
,
890 cls
->ProgID
->VersionInd
->ProgID
);
896 MSIAPPID
*appid
= cls
->AppID
;
897 msi_reg_set_val_str( hkey2
, szAppID
, appid
->AppID
);
898 register_appid( appid
, cls
->Description
);
902 msi_reg_set_subkey_val( hkey2
, szDefaultIcon
, NULL
, cls
->IconPath
);
904 if (cls
->DefInprocHandler
)
905 msi_reg_set_subkey_val( hkey2
, szInprocHandler
, NULL
, cls
->DefInprocHandler
);
907 if (cls
->DefInprocHandler32
)
908 msi_reg_set_subkey_val( hkey2
, szInprocHandler32
, NULL
, cls
->DefInprocHandler32
);
912 /* if there is a FileTypeMask, register the FileType */
913 if (cls
->FileTypeMask
)
918 ptr
= cls
->FileTypeMask
;
921 ptr2
= strchrW(ptr
,';');
924 keyname
= msi_alloc( (strlenW(szFileType_fmt
) + strlenW(cls
->clsid
) + 4) * sizeof(WCHAR
));
925 sprintfW( keyname
, szFileType_fmt
, cls
->clsid
, index
);
927 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, keyname
, NULL
, ptr
);
939 uirow
= MSI_CreateRecord(1);
940 MSI_RecordSetStringW( uirow
, 1, cls
->clsid
);
941 ui_actiondata(package
,szRegisterClassInfo
,uirow
);
942 msiobj_release(&uirow
->hdr
);
946 return ERROR_SUCCESS
;
949 UINT
ACTION_UnregisterClassInfo( MSIPACKAGE
*package
)
951 static const WCHAR szFileType
[] = {'F','i','l','e','T','y','p','e','\\',0};
956 load_classes_and_such( package
);
957 if (RegOpenKeyW( HKEY_CLASSES_ROOT
, szCLSID
, &hkey
) != ERROR_SUCCESS
)
958 return ERROR_SUCCESS
;
960 LIST_FOR_EACH_ENTRY( cls
, &package
->classes
, MSICLASS
, entry
)
967 comp
= cls
->Component
;
971 feature
= cls
->Feature
;
975 if (feature
->ActionRequest
!= INSTALLSTATE_ABSENT
)
977 TRACE("Feature %s not scheduled for removal, skipping unregistration of class %s\n",
978 debugstr_w(feature
->Feature
), debugstr_w(cls
->clsid
));
981 feature
->Action
= feature
->ActionRequest
;
983 TRACE("Unregistering class %s (%p)\n", debugstr_w(cls
->clsid
), cls
);
985 cls
->Installed
= FALSE
;
986 mark_progid_for_uninstall( package
, cls
->ProgID
);
988 res
= RegDeleteTreeW( hkey
, cls
->clsid
);
989 if (res
!= ERROR_SUCCESS
)
990 WARN("Failed to delete class key %d\n", res
);
994 res
= RegOpenKeyW( HKEY_CLASSES_ROOT
, szAppID
, &hkey2
);
995 if (res
== ERROR_SUCCESS
)
997 res
= RegDeleteKeyW( hkey2
, cls
->AppID
->AppID
);
998 if (res
!= ERROR_SUCCESS
)
999 WARN("Failed to delete appid key %d\n", res
);
1000 RegCloseKey( hkey2
);
1003 if (cls
->FileTypeMask
)
1005 filetype
= msi_alloc( (strlenW( szFileType
) + strlenW( cls
->clsid
) + 1) * sizeof(WCHAR
) );
1008 strcpyW( filetype
, szFileType
);
1009 strcatW( filetype
, cls
->clsid
);
1010 res
= RegDeleteTreeW( HKEY_CLASSES_ROOT
, filetype
);
1011 msi_free( filetype
);
1013 if (res
!= ERROR_SUCCESS
)
1014 WARN("Failed to delete file type %d\n", res
);
1018 uirow
= MSI_CreateRecord( 1 );
1019 MSI_RecordSetStringW( uirow
, 1, cls
->clsid
);
1020 ui_actiondata( package
, szUnregisterClassInfo
, uirow
);
1021 msiobj_release( &uirow
->hdr
);
1024 RegCloseKey( hkey
);
1025 return ERROR_SUCCESS
;
1028 static LPCWSTR
get_clsid_of_progid( const MSIPROGID
*progid
)
1033 return progid
->Class
->clsid
;
1034 if (progid
->Parent
== progid
)
1036 progid
= progid
->Parent
;
1041 static UINT
register_progid( const MSIPROGID
* progid
)
1043 static const WCHAR szCurVer
[] = {'C','u','r','V','e','r',0};
1047 rc
= RegCreateKeyW( HKEY_CLASSES_ROOT
, progid
->ProgID
, &hkey
);
1048 if (rc
== ERROR_SUCCESS
)
1050 LPCWSTR clsid
= get_clsid_of_progid( progid
);
1053 msi_reg_set_subkey_val( hkey
, szCLSID
, NULL
, clsid
);
1055 ERR("%s has no class\n", debugstr_w( progid
->ProgID
) );
1057 if (progid
->Description
)
1058 msi_reg_set_val_str( hkey
, NULL
, progid
->Description
);
1060 if (progid
->IconPath
)
1061 msi_reg_set_subkey_val( hkey
, szDefaultIcon
, NULL
, progid
->IconPath
);
1063 /* write out the current version */
1065 msi_reg_set_subkey_val( hkey
, szCurVer
, NULL
, progid
->CurVer
->ProgID
);
1070 ERR("failed to create key %s\n", debugstr_w( progid
->ProgID
) );
1075 UINT
ACTION_RegisterProgIdInfo(MSIPACKAGE
*package
)
1080 load_classes_and_such(package
);
1082 LIST_FOR_EACH_ENTRY( progid
, &package
->progids
, MSIPROGID
, entry
)
1084 /* check if this progid is to be installed */
1085 if (progid
->Class
&& progid
->Class
->Installed
)
1086 progid
->InstallMe
= TRUE
;
1088 if (!progid
->InstallMe
)
1090 TRACE("progid %s not scheduled to be installed\n",
1091 debugstr_w(progid
->ProgID
));
1095 TRACE("Registering progid %s\n", debugstr_w(progid
->ProgID
));
1097 register_progid( progid
);
1099 uirow
= MSI_CreateRecord( 1 );
1100 MSI_RecordSetStringW( uirow
, 1, progid
->ProgID
);
1101 ui_actiondata( package
, szRegisterProgIdInfo
, uirow
);
1102 msiobj_release( &uirow
->hdr
);
1105 return ERROR_SUCCESS
;
1108 UINT
ACTION_UnregisterProgIdInfo( MSIPACKAGE
*package
)
1114 load_classes_and_such( package
);
1116 LIST_FOR_EACH_ENTRY( progid
, &package
->progids
, MSIPROGID
, entry
)
1118 /* check if this progid is to be removed */
1119 if (progid
->Class
&& !progid
->Class
->Installed
)
1120 progid
->InstallMe
= FALSE
;
1122 if (progid
->InstallMe
)
1124 TRACE("progid %s not scheduled to be removed\n", debugstr_w(progid
->ProgID
));
1128 TRACE("Unregistering progid %s\n", debugstr_w(progid
->ProgID
));
1130 res
= RegDeleteTreeW( HKEY_CLASSES_ROOT
, progid
->ProgID
);
1131 if (res
!= ERROR_SUCCESS
)
1132 WARN("Failed to delete progid key %d\n", res
);
1134 uirow
= MSI_CreateRecord( 1 );
1135 MSI_RecordSetStringW( uirow
, 1, progid
->ProgID
);
1136 ui_actiondata( package
, szUnregisterProgIdInfo
, uirow
);
1137 msiobj_release( &uirow
->hdr
);
1140 return ERROR_SUCCESS
;
1143 static UINT
register_verb(MSIPACKAGE
*package
, LPCWSTR progid
,
1144 MSICOMPONENT
* component
, const MSIEXTENSION
* extension
,
1145 MSIVERB
* verb
, INT
* Sequence
)
1149 static const WCHAR szShell
[] = {'s','h','e','l','l',0};
1150 static const WCHAR szCommand
[] = {'c','o','m','m','a','n','d',0};
1151 static const WCHAR fmt
[] = {'\"','%','s','\"',' ','%','s',0};
1152 static const WCHAR fmt2
[] = {'\"','%','s','\"',0};
1157 keyname
= build_directory_name(4, progid
, szShell
, verb
->Verb
, szCommand
);
1159 TRACE("Making Key %s\n",debugstr_w(keyname
));
1160 RegCreateKeyW(HKEY_CLASSES_ROOT
, keyname
, &key
);
1161 size
= strlenW(component
->FullKeypath
);
1163 size
+= strlenW(verb
->Argument
);
1166 command
= msi_alloc(size
* sizeof (WCHAR
));
1168 sprintfW(command
, fmt
, component
->FullKeypath
, verb
->Argument
);
1170 sprintfW(command
, fmt2
, component
->FullKeypath
);
1172 msi_reg_set_val_str( key
, NULL
, command
);
1175 advertise
= create_component_advertise_string(package
, component
,
1176 extension
->Feature
->Feature
);
1178 size
= strlenW(advertise
);
1181 size
+= strlenW(verb
->Argument
);
1184 command
= msi_alloc_zero(size
* sizeof (WCHAR
));
1186 strcpyW(command
,advertise
);
1189 strcatW(command
,szSpace
);
1190 strcatW(command
,verb
->Argument
);
1193 msi_reg_set_val_multi_str( key
, szCommand
, command
);
1197 msi_free(advertise
);
1202 keyname
= build_directory_name(3, progid
, szShell
, verb
->Verb
);
1203 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, keyname
, NULL
, verb
->Command
);
1207 if (verb
->Sequence
!= MSI_NULL_INTEGER
)
1209 if (*Sequence
== MSI_NULL_INTEGER
|| verb
->Sequence
< *Sequence
)
1211 *Sequence
= verb
->Sequence
;
1212 keyname
= build_directory_name(2, progid
, szShell
);
1213 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, keyname
, NULL
, verb
->Verb
);
1217 return ERROR_SUCCESS
;
1220 UINT
ACTION_RegisterExtensionInfo(MSIPACKAGE
*package
)
1222 static const WCHAR szContentType
[] =
1223 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
1227 BOOL install_on_demand
= TRUE
;
1229 load_classes_and_such(package
);
1231 /* We need to set install_on_demand based on if the shell handles advertised
1232 * shortcuts and the like. Because Mike McCormack is working on this i am
1233 * going to default to TRUE
1236 LIST_FOR_EACH_ENTRY( ext
, &package
->extensions
, MSIEXTENSION
, entry
)
1239 MSIFEATURE
*feature
;
1241 if (!ext
->Component
)
1244 feature
= ext
->Feature
;
1249 * yes. MSDN says that these are based on _Feature_ not on
1250 * Component. So verify the feature is to be installed
1252 if (feature
->ActionRequest
!= INSTALLSTATE_LOCAL
&&
1253 !(install_on_demand
&& feature
->ActionRequest
== INSTALLSTATE_ADVERTISED
))
1255 TRACE("Feature %s not scheduled for installation, skipping registration of extension %s\n",
1256 debugstr_w(feature
->Feature
), debugstr_w(ext
->Extension
));
1259 feature
->Action
= feature
->ActionRequest
;
1261 TRACE("Registering extension %s (%p)\n", debugstr_w(ext
->Extension
), ext
);
1263 ext
->Installed
= TRUE
;
1265 /* this is only registered if the extension has at least 1 verb
1268 if (ext
->ProgID
&& !list_empty( &ext
->verbs
) )
1269 mark_progid_for_install( package
, ext
->ProgID
);
1271 mark_mime_for_install(ext
->Mime
);
1273 extension
= msi_alloc( (lstrlenW( ext
->Extension
) + 2)*sizeof(WCHAR
) );
1275 lstrcpyW(extension
+1,ext
->Extension
);
1277 RegCreateKeyW(HKEY_CLASSES_ROOT
,extension
,&hkey
);
1278 msi_free( extension
);
1281 msi_reg_set_val_str( hkey
, szContentType
, ext
->Mime
->ContentType
);
1283 if (ext
->ProgID
|| ext
->ProgIDText
)
1285 static const WCHAR szSN
[] =
1286 {'\\','S','h','e','l','l','N','e','w',0};
1291 INT Sequence
= MSI_NULL_INTEGER
;
1294 progid
= ext
->ProgID
->ProgID
;
1296 progid
= ext
->ProgIDText
;
1298 msi_reg_set_val_str( hkey
, NULL
, progid
);
1300 newkey
= msi_alloc( (strlenW(progid
)+strlenW(szSN
)+1) * sizeof(WCHAR
));
1302 strcpyW(newkey
,progid
);
1303 strcatW(newkey
,szSN
);
1304 RegCreateKeyW(hkey
,newkey
,&hkey2
);
1309 /* do all the verbs */
1310 LIST_FOR_EACH_ENTRY( verb
, &ext
->verbs
, MSIVERB
, entry
)
1312 register_verb( package
, progid
, ext
->Component
,
1313 ext
, verb
, &Sequence
);
1319 uirow
= MSI_CreateRecord(1);
1320 MSI_RecordSetStringW( uirow
, 1, ext
->Extension
);
1321 ui_actiondata(package
,szRegisterExtensionInfo
,uirow
);
1322 msiobj_release(&uirow
->hdr
);
1325 return ERROR_SUCCESS
;
1328 UINT
ACTION_RegisterMIMEInfo(MSIPACKAGE
*package
)
1330 static const WCHAR szExten
[] =
1331 {'E','x','t','e','n','s','i','o','n',0 };
1335 load_classes_and_such(package
);
1337 LIST_FOR_EACH_ENTRY( mt
, &package
->mimes
, MSIMIME
, entry
)
1342 static const WCHAR fmt
[] =
1343 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
1344 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
1348 * check if the MIME is to be installed. Either as requested by an
1349 * extension or Class
1351 mt
->InstallMe
= (mt
->InstallMe
||
1352 (mt
->Class
&& mt
->Class
->Installed
) ||
1353 (mt
->Extension
&& mt
->Extension
->Installed
));
1357 TRACE("MIME %s not scheduled to be installed\n",
1358 debugstr_w(mt
->ContentType
));
1362 mime
= mt
->ContentType
;
1363 exten
= mt
->Extension
->Extension
;
1365 extension
= msi_alloc( (lstrlenW( exten
) + 2)*sizeof(WCHAR
) );
1367 lstrcpyW(extension
+1,exten
);
1369 key
= msi_alloc( (strlenW(mime
)+strlenW(fmt
)+1) * sizeof(WCHAR
) );
1370 sprintfW(key
,fmt
,mime
);
1371 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, key
, szExten
, extension
);
1373 msi_free(extension
);
1377 FIXME("Handle non null for field 3\n");
1379 uirow
= MSI_CreateRecord(2);
1380 MSI_RecordSetStringW(uirow
,1,mt
->ContentType
);
1381 MSI_RecordSetStringW(uirow
,2,exten
);
1382 ui_actiondata(package
,szRegisterMIMEInfo
,uirow
);
1383 msiobj_release(&uirow
->hdr
);
1386 return ERROR_SUCCESS
;