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
39 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
45 static MSIAPPID
*load_appid( MSIPACKAGE
* package
, MSIRECORD
*row
)
50 /* fill in the data */
52 appid
= msi_alloc_zero( sizeof(MSIAPPID
) );
56 appid
->AppID
= msi_dup_record_field( row
, 1 );
57 TRACE("loading appid %s\n", debugstr_w( appid
->AppID
));
59 buffer
= MSI_RecordGetString(row
,2);
60 deformat_string( package
, buffer
, &appid
->RemoteServerName
);
62 appid
->LocalServer
= msi_dup_record_field(row
,3);
63 appid
->ServiceParameters
= msi_dup_record_field(row
,4);
64 appid
->DllSurrogate
= msi_dup_record_field(row
,5);
66 appid
->ActivateAtStorage
= !MSI_RecordIsNull(row
,6);
67 appid
->RunAsInteractiveUser
= !MSI_RecordIsNull(row
,7);
69 list_add_tail( &package
->appids
, &appid
->entry
);
74 static MSIAPPID
*load_given_appid( MSIPACKAGE
*package
, LPCWSTR name
)
82 /* check for appids already loaded */
83 LIST_FOR_EACH_ENTRY( appid
, &package
->appids
, MSIAPPID
, entry
)
85 if (!wcsicmp( appid
->AppID
, name
))
87 TRACE("found appid %s %p\n", debugstr_w(name
), appid
);
92 row
= MSI_QueryGetRecord(package
->db
, L
"SELECT * FROM `AppId` WHERE `AppId` = '%s'", name
);
96 appid
= load_appid(package
, row
);
97 msiobj_release(&row
->hdr
);
101 static MSIPROGID
*load_given_progid(MSIPACKAGE
*package
, LPCWSTR progid
);
102 static MSICLASS
*load_given_class( MSIPACKAGE
*package
, LPCWSTR classid
);
104 static MSIPROGID
*load_progid( MSIPACKAGE
* package
, MSIRECORD
*row
)
109 /* fill in the data */
111 progid
= msi_alloc_zero( sizeof(MSIPROGID
) );
115 list_add_tail( &package
->progids
, &progid
->entry
);
117 progid
->ProgID
= msi_dup_record_field(row
,1);
118 TRACE("loading progid %s\n",debugstr_w(progid
->ProgID
));
120 buffer
= MSI_RecordGetString(row
,2);
121 progid
->Parent
= load_given_progid(package
,buffer
);
122 if (progid
->Parent
== NULL
&& buffer
)
123 FIXME("Unknown parent ProgID %s\n",debugstr_w(buffer
));
125 buffer
= MSI_RecordGetString(row
,3);
126 progid
->Class
= load_given_class(package
,buffer
);
127 if (progid
->Class
== NULL
&& buffer
)
128 FIXME("Unknown class %s\n",debugstr_w(buffer
));
130 progid
->Description
= msi_dup_record_field(row
,4);
132 if (!MSI_RecordIsNull(row
,6))
134 INT icon_index
= MSI_RecordGetInteger(row
,6);
135 LPCWSTR FileName
= MSI_RecordGetString(row
,5);
138 FilePath
= msi_build_icon_path(package
, FileName
);
140 progid
->IconPath
= msi_alloc( (lstrlenW(FilePath
) + 10) * sizeof(WCHAR
) );
141 swprintf( progid
->IconPath
, lstrlenW(FilePath
) + 10, L
"%s,%d", FilePath
, icon_index
);
146 buffer
= MSI_RecordGetString(row
,5);
148 progid
->IconPath
= msi_build_icon_path(package
, buffer
);
151 progid
->CurVer
= NULL
;
152 progid
->VersionInd
= NULL
;
154 /* if we have a parent then we may be that parents CurVer */
155 if (progid
->Parent
&& progid
->Parent
!= progid
)
157 MSIPROGID
*parent
= progid
->Parent
;
159 while (parent
->Parent
&& parent
->Parent
!= parent
)
160 parent
= parent
->Parent
;
162 /* FIXME: need to determine if we are really the CurVer */
164 progid
->CurVer
= parent
;
165 parent
->VersionInd
= progid
;
171 static MSIPROGID
*load_given_progid(MSIPACKAGE
*package
, LPCWSTR name
)
179 /* check for progids already loaded */
180 LIST_FOR_EACH_ENTRY( progid
, &package
->progids
, MSIPROGID
, entry
)
182 if (!wcsicmp( progid
->ProgID
, name
))
184 TRACE("found progid %s (%p)\n",debugstr_w(name
), progid
);
189 row
= MSI_QueryGetRecord( package
->db
, L
"SELECT * FROM `ProgId` WHERE `ProgId` = '%s'", name
);
193 progid
= load_progid(package
, row
);
194 msiobj_release(&row
->hdr
);
198 static MSICLASS
*load_class( MSIPACKAGE
* package
, MSIRECORD
*row
)
204 /* fill in the data */
206 cls
= msi_alloc_zero( sizeof(MSICLASS
) );
210 list_add_tail( &package
->classes
, &cls
->entry
);
212 cls
->clsid
= msi_dup_record_field( row
, 1 );
213 TRACE("loading class %s\n",debugstr_w(cls
->clsid
));
214 cls
->Context
= msi_dup_record_field( row
, 2 );
215 buffer
= MSI_RecordGetString(row
,3);
216 cls
->Component
= msi_get_loaded_component( package
, buffer
);
218 cls
->ProgIDText
= msi_dup_record_field(row
,4);
219 cls
->ProgID
= load_given_progid(package
, cls
->ProgIDText
);
221 cls
->Description
= msi_dup_record_field(row
,5);
223 buffer
= MSI_RecordGetString(row
,6);
225 cls
->AppID
= load_given_appid(package
, buffer
);
227 cls
->FileTypeMask
= msi_dup_record_field(row
,7);
229 if (!MSI_RecordIsNull(row
,9))
232 INT icon_index
= MSI_RecordGetInteger(row
,9);
233 LPCWSTR FileName
= MSI_RecordGetString(row
,8);
236 FilePath
= msi_build_icon_path(package
, FileName
);
238 cls
->IconPath
= msi_alloc( (lstrlenW(FilePath
) + 5) * sizeof(WCHAR
) );
239 swprintf( cls
->IconPath
, lstrlenW(FilePath
) + 5, L
"%s,%d", FilePath
, icon_index
);
244 buffer
= MSI_RecordGetString(row
,8);
246 cls
->IconPath
= msi_build_icon_path(package
, buffer
);
249 if (!MSI_RecordIsNull(row
,10))
251 i
= MSI_RecordGetInteger(row
,10);
252 if (i
!= MSI_NULL_INTEGER
&& i
> 0 && i
< 4)
257 cls
->DefInprocHandler
= strdupW(L
"ole2.dll");
260 cls
->DefInprocHandler32
= strdupW(L
"ole32.dll");
263 cls
->DefInprocHandler
= strdupW(L
"ole2.dll");
264 cls
->DefInprocHandler32
= strdupW(L
"ole32.dll");
270 cls
->DefInprocHandler32
= msi_dup_record_field( row
, 10 );
271 msi_reduce_to_long_filename( cls
->DefInprocHandler32
);
274 buffer
= MSI_RecordGetString(row
,11);
275 deformat_string(package
,buffer
,&cls
->Argument
);
277 buffer
= MSI_RecordGetString(row
,12);
278 cls
->Feature
= msi_get_loaded_feature(package
, buffer
);
280 cls
->Attributes
= MSI_RecordGetInteger(row
,13);
281 cls
->action
= INSTALLSTATE_UNKNOWN
;
286 * the Class table has 3 primary keys. Generally it is only
287 * referenced through the first CLSID key. However when loading
288 * all of the classes we need to make sure we do not ignore rows
289 * with other Context and ComponentIndexs
291 static MSICLASS
*load_given_class(MSIPACKAGE
*package
, LPCWSTR classid
)
299 /* check for classes already loaded */
300 LIST_FOR_EACH_ENTRY( cls
, &package
->classes
, MSICLASS
, entry
)
302 if (!wcsicmp( cls
->clsid
, classid
))
304 TRACE("found class %s (%p)\n",debugstr_w(classid
), cls
);
309 row
= MSI_QueryGetRecord( package
->db
, L
"SELECT * FROM `Class` WHERE `CLSID` = '%s'", classid
);
313 cls
= load_class(package
, row
);
314 msiobj_release(&row
->hdr
);
318 static MSIEXTENSION
*load_given_extension( MSIPACKAGE
*package
, LPCWSTR extension
);
320 static MSIMIME
*load_mime( MSIPACKAGE
* package
, MSIRECORD
*row
)
325 /* fill in the data */
327 mt
= msi_alloc_zero( sizeof(MSIMIME
) );
331 mt
->ContentType
= msi_dup_record_field( row
, 1 );
332 TRACE("loading mime %s\n", debugstr_w(mt
->ContentType
));
334 extension
= MSI_RecordGetString( row
, 2 );
335 mt
->Extension
= load_given_extension( package
, extension
);
336 mt
->suffix
= strdupW( extension
);
338 mt
->clsid
= msi_dup_record_field( row
, 3 );
339 mt
->Class
= load_given_class( package
, mt
->clsid
);
341 list_add_tail( &package
->mimes
, &mt
->entry
);
346 static MSIMIME
*load_given_mime( MSIPACKAGE
*package
, LPCWSTR mime
)
354 /* check for mime already loaded */
355 LIST_FOR_EACH_ENTRY( mt
, &package
->mimes
, MSIMIME
, entry
)
357 if (!wcsicmp( mt
->ContentType
, mime
))
359 TRACE("found mime %s (%p)\n",debugstr_w(mime
), mt
);
364 row
= MSI_QueryGetRecord( package
->db
, L
"SELECT * FROM `MIME` WHERE `ContentType` = '%s'", mime
);
368 mt
= load_mime(package
, row
);
369 msiobj_release(&row
->hdr
);
373 static MSIEXTENSION
*load_extension( MSIPACKAGE
* package
, MSIRECORD
*row
)
378 /* fill in the data */
380 ext
= msi_alloc_zero( sizeof(MSIEXTENSION
) );
384 list_init( &ext
->verbs
);
386 list_add_tail( &package
->extensions
, &ext
->entry
);
388 ext
->Extension
= msi_dup_record_field( row
, 1 );
389 TRACE("loading extension %s\n", debugstr_w(ext
->Extension
));
391 buffer
= MSI_RecordGetString( row
, 2 );
392 ext
->Component
= msi_get_loaded_component( package
, buffer
);
394 ext
->ProgIDText
= msi_dup_record_field( row
, 3 );
395 ext
->ProgID
= load_given_progid( package
, ext
->ProgIDText
);
397 buffer
= MSI_RecordGetString( row
, 4 );
398 ext
->Mime
= load_given_mime( package
, buffer
);
400 buffer
= MSI_RecordGetString(row
,5);
401 ext
->Feature
= msi_get_loaded_feature( package
, buffer
);
402 ext
->action
= INSTALLSTATE_UNKNOWN
;
407 * While the extension table has 2 primary keys, this function is only looking
408 * at the Extension key which is what is referenced as a foreign key
410 static MSIEXTENSION
*load_given_extension( MSIPACKAGE
*package
, LPCWSTR name
)
421 /* check for extensions already loaded */
422 LIST_FOR_EACH_ENTRY( ext
, &package
->extensions
, MSIEXTENSION
, entry
)
424 if (!wcsicmp( ext
->Extension
, name
))
426 TRACE("extension %s already loaded %p\n", debugstr_w(name
), ext
);
431 row
= MSI_QueryGetRecord( package
->db
, L
"SELECT * FROM `Extension` WHERE `Extension` = '%s'", name
);
435 ext
= load_extension(package
, row
);
436 msiobj_release(&row
->hdr
);
440 static UINT
iterate_load_verb(MSIRECORD
*row
, LPVOID param
)
442 MSIPACKAGE
* package
= param
;
445 MSIEXTENSION
*extension
;
447 buffer
= MSI_RecordGetString(row
,1);
448 extension
= load_given_extension( package
, buffer
);
451 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer
));
452 return ERROR_SUCCESS
;
455 /* fill in the data */
457 verb
= msi_alloc_zero( sizeof(MSIVERB
) );
459 return ERROR_OUTOFMEMORY
;
461 verb
->Verb
= msi_dup_record_field(row
,2);
462 TRACE("loading verb %s\n",debugstr_w(verb
->Verb
));
463 verb
->Sequence
= MSI_RecordGetInteger(row
,3);
465 buffer
= MSI_RecordGetString(row
,4);
466 deformat_string(package
,buffer
,&verb
->Command
);
468 buffer
= MSI_RecordGetString(row
,5);
469 deformat_string(package
,buffer
,&verb
->Argument
);
471 /* associate the verb with the correct extension */
472 list_add_tail( &extension
->verbs
, &verb
->entry
);
474 return ERROR_SUCCESS
;
477 static UINT
iterate_all_classes(MSIRECORD
*rec
, LPVOID param
)
483 MSIPACKAGE
* package
= param
;
487 clsid
= MSI_RecordGetString(rec
,1);
488 context
= MSI_RecordGetString(rec
,2);
489 buffer
= MSI_RecordGetString(rec
,3);
490 comp
= msi_get_loaded_component(package
, buffer
);
492 LIST_FOR_EACH_ENTRY( cls
, &package
->classes
, MSICLASS
, entry
)
494 if (wcsicmp( clsid
, cls
->clsid
))
496 if (wcscmp( context
, cls
->Context
))
498 if (comp
== cls
->Component
)
506 load_class(package
, rec
);
508 return ERROR_SUCCESS
;
511 static UINT
load_all_classes( MSIPACKAGE
*package
)
516 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Class`", &view
);
517 if (rc
!= ERROR_SUCCESS
)
518 return ERROR_SUCCESS
;
520 rc
= MSI_IterateRecords(view
, NULL
, iterate_all_classes
, package
);
521 msiobj_release(&view
->hdr
);
525 static UINT
iterate_all_extensions(MSIRECORD
*rec
, LPVOID param
)
530 MSIPACKAGE
* package
= param
;
534 extension
= MSI_RecordGetString(rec
,1);
535 buffer
= MSI_RecordGetString(rec
,2);
536 comp
= msi_get_loaded_component(package
, buffer
);
538 LIST_FOR_EACH_ENTRY( ext
, &package
->extensions
, MSIEXTENSION
, entry
)
540 if (wcsicmp(extension
, ext
->Extension
))
542 if (comp
== ext
->Component
)
550 load_extension(package
, rec
);
552 return ERROR_SUCCESS
;
555 static UINT
load_all_extensions( MSIPACKAGE
*package
)
560 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Extension`", &view
);
561 if (rc
!= ERROR_SUCCESS
)
562 return ERROR_SUCCESS
;
564 rc
= MSI_IterateRecords(view
, NULL
, iterate_all_extensions
, package
);
565 msiobj_release(&view
->hdr
);
569 static UINT
iterate_all_progids(MSIRECORD
*rec
, LPVOID param
)
572 MSIPACKAGE
* package
= param
;
574 buffer
= MSI_RecordGetString(rec
,1);
575 load_given_progid(package
,buffer
);
576 return ERROR_SUCCESS
;
579 static UINT
load_all_progids( MSIPACKAGE
*package
)
584 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT `ProgId` FROM `ProgId`", &view
);
585 if (rc
!= ERROR_SUCCESS
)
586 return ERROR_SUCCESS
;
588 rc
= MSI_IterateRecords(view
, NULL
, iterate_all_progids
, package
);
589 msiobj_release(&view
->hdr
);
593 static UINT
load_all_verbs( MSIPACKAGE
*package
)
598 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT * FROM `Verb`", &view
);
599 if (rc
!= ERROR_SUCCESS
)
600 return ERROR_SUCCESS
;
602 rc
= MSI_IterateRecords(view
, NULL
, iterate_load_verb
, package
);
603 msiobj_release(&view
->hdr
);
607 static UINT
iterate_all_mimes(MSIRECORD
*rec
, LPVOID param
)
610 MSIPACKAGE
* package
= param
;
612 buffer
= MSI_RecordGetString(rec
,1);
613 load_given_mime(package
,buffer
);
614 return ERROR_SUCCESS
;
617 static UINT
load_all_mimes( MSIPACKAGE
*package
)
622 rc
= MSI_DatabaseOpenViewW( package
->db
, L
"SELECT `ContentType` FROM `MIME`", &view
);
623 if (rc
!= ERROR_SUCCESS
)
624 return ERROR_SUCCESS
;
626 rc
= MSI_IterateRecords(view
, NULL
, iterate_all_mimes
, package
);
627 msiobj_release(&view
->hdr
);
631 static UINT
load_classes_and_such( MSIPACKAGE
*package
)
635 TRACE("Loading all the class info and related tables\n");
637 /* check if already loaded */
638 if (!list_empty( &package
->classes
) ||
639 !list_empty( &package
->mimes
) ||
640 !list_empty( &package
->extensions
) ||
641 !list_empty( &package
->progids
)) return ERROR_SUCCESS
;
643 r
= load_all_classes( package
);
644 if (r
!= ERROR_SUCCESS
) return r
;
646 r
= load_all_extensions( package
);
647 if (r
!= ERROR_SUCCESS
) return r
;
649 r
= load_all_progids( package
);
650 if (r
!= ERROR_SUCCESS
) return r
;
652 /* these loads must come after the other loads */
653 r
= load_all_verbs( package
);
654 if (r
!= ERROR_SUCCESS
) return r
;
656 return load_all_mimes( package
);
659 static UINT
register_appid(const MSIAPPID
*appid
, LPCWSTR app
)
663 RegCreateKeyW( HKEY_CLASSES_ROOT
, L
"AppID", &hkey2
);
664 RegCreateKeyW( hkey2
, appid
->AppID
, &hkey3
);
666 msi_reg_set_val_str( hkey3
, NULL
, app
);
668 if (appid
->RemoteServerName
)
669 msi_reg_set_val_str( hkey3
, L
"RemoteServerName", appid
->RemoteServerName
);
671 if (appid
->LocalServer
)
672 msi_reg_set_val_str( hkey3
, L
"LocalService", appid
->LocalServer
);
674 if (appid
->ServiceParameters
)
675 msi_reg_set_val_str( hkey3
, L
"ServiceParameters", appid
->ServiceParameters
);
677 if (appid
->DllSurrogate
)
678 msi_reg_set_val_str( hkey3
, L
"DllSurrogate", appid
->DllSurrogate
);
680 if (appid
->ActivateAtStorage
)
681 msi_reg_set_val_str( hkey3
, L
"ActivateAtStorage", L
"Y" );
683 if (appid
->RunAsInteractiveUser
)
684 msi_reg_set_val_str( hkey3
, L
"RunAs", L
"Interactive User" );
687 return ERROR_SUCCESS
;
690 UINT
ACTION_RegisterClassInfo(MSIPACKAGE
*package
)
692 REGSAM access
= KEY_ALL_ACCESS
;
694 HKEY hkey
, hkey2
, hkey3
;
698 if (package
->script
== SCRIPT_NONE
)
699 return msi_schedule_action( package
, SCRIPT_INSTALL
, L
"RegisterClassInfo" );
701 r
= load_classes_and_such( package
);
702 if (r
!= ERROR_SUCCESS
)
705 if (package
->platform
== PLATFORM_INTEL
)
706 access
|= KEY_WOW64_32KEY
;
708 access
|= KEY_WOW64_64KEY
;
710 if (RegCreateKeyExW( HKEY_CLASSES_ROOT
, L
"CLSID", 0, NULL
, 0, access
, NULL
, &hkey
, NULL
))
711 return ERROR_FUNCTION_FAILED
;
713 LIST_FOR_EACH_ENTRY( cls
, &package
->classes
, MSICLASS
, entry
)
721 comp
= cls
->Component
;
727 TRACE("component is disabled\n");
731 feature
= cls
->Feature
;
735 feature
->Action
= msi_get_feature_action( package
, feature
);
736 if (feature
->Action
!= INSTALLSTATE_LOCAL
&&
737 feature
->Action
!= INSTALLSTATE_ADVERTISED
)
739 TRACE("feature %s not scheduled for installation, skipping registration of class %s\n",
740 debugstr_w(feature
->Feature
), debugstr_w(cls
->clsid
));
744 if (!comp
->KeyPath
|| !(file
= msi_get_loaded_file( package
, comp
->KeyPath
)))
746 TRACE("COM server not provided, skipping class %s\n", debugstr_w(cls
->clsid
));
749 TRACE("Registering class %s (%p)\n", debugstr_w(cls
->clsid
), cls
);
751 cls
->action
= INSTALLSTATE_LOCAL
;
753 RegCreateKeyW( hkey
, cls
->clsid
, &hkey2
);
755 if (cls
->Description
)
756 msi_reg_set_val_str( hkey2
, NULL
, cls
->Description
);
758 RegCreateKeyW( hkey2
, cls
->Context
, &hkey3
);
761 * FIXME: Implement install on demand (advertised components).
763 * ole32.dll should call msi.MsiProvideComponentFromDescriptor()
764 * when it needs an InProcServer that doesn't exist.
765 * The component advertise string should be in the "InProcServer" value.
767 size
= lstrlenW( file
->TargetPath
)+1;
769 size
+= lstrlenW(cls
->Argument
)+1;
771 argument
= msi_alloc( size
* sizeof(WCHAR
) );
772 lstrcpyW( argument
, file
->TargetPath
);
776 lstrcatW( argument
, L
" " );
777 lstrcatW( argument
, cls
->Argument
);
780 msi_reg_set_val_str( hkey3
, NULL
, argument
);
785 if (cls
->ProgID
|| cls
->ProgIDText
)
790 progid
= cls
->ProgID
->ProgID
;
792 progid
= cls
->ProgIDText
;
794 msi_reg_set_subkey_val( hkey2
, L
"ProgID", NULL
, progid
);
796 if (cls
->ProgID
&& cls
->ProgID
->VersionInd
)
798 msi_reg_set_subkey_val( hkey2
, L
"VersionIndependentProgID", NULL
,
799 cls
->ProgID
->VersionInd
->ProgID
);
805 MSIAPPID
*appid
= cls
->AppID
;
806 msi_reg_set_val_str( hkey2
, L
"AppID", appid
->AppID
);
807 register_appid( appid
, cls
->Description
);
811 msi_reg_set_subkey_val( hkey2
, L
"DefaultIcon", NULL
, cls
->IconPath
);
813 if (cls
->DefInprocHandler
)
814 msi_reg_set_subkey_val( hkey2
, L
"InprocHandler", NULL
, cls
->DefInprocHandler
);
816 if (cls
->DefInprocHandler32
)
817 msi_reg_set_subkey_val( hkey2
, L
"InprocHandler32", NULL
, cls
->DefInprocHandler32
);
820 /* if there is a FileTypeMask, register the FileType */
821 if (cls
->FileTypeMask
)
826 ptr
= cls
->FileTypeMask
;
829 ptr2
= wcschr(ptr
,';');
832 keyname
= msi_alloc( (lstrlenW(L
"FileType\\%s\\%d") + lstrlenW(cls
->clsid
) + 4) * sizeof(WCHAR
));
833 swprintf( keyname
, lstrlenW(L
"FileType\\%s\\%d") + lstrlenW(cls
->clsid
) + 4,
834 L
"FileType\\%s\\%d", cls
->clsid
, index
);
836 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, keyname
, NULL
, ptr
);
848 uirow
= MSI_CreateRecord(1);
849 MSI_RecordSetStringW( uirow
, 1, cls
->clsid
);
850 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
851 msiobj_release(&uirow
->hdr
);
854 return ERROR_SUCCESS
;
857 UINT
ACTION_UnregisterClassInfo( MSIPACKAGE
*package
)
859 REGSAM access
= KEY_ALL_ACCESS
;
865 if (package
->script
== SCRIPT_NONE
)
866 return msi_schedule_action( package
, SCRIPT_INSTALL
, L
"UnregisterClassInfo" );
868 r
= load_classes_and_such( package
);
869 if (r
!= ERROR_SUCCESS
)
872 if (package
->platform
== PLATFORM_INTEL
)
873 access
|= KEY_WOW64_32KEY
;
875 access
|= KEY_WOW64_64KEY
;
877 if (RegCreateKeyExW( HKEY_CLASSES_ROOT
, L
"CLSID", 0, NULL
, 0, access
, NULL
, &hkey
, NULL
))
878 return ERROR_FUNCTION_FAILED
;
880 LIST_FOR_EACH_ENTRY( cls
, &package
->classes
, MSICLASS
, entry
)
887 comp
= cls
->Component
;
893 TRACE("component is disabled\n");
897 feature
= cls
->Feature
;
901 feature
->Action
= msi_get_feature_action( package
, feature
);
902 if (feature
->Action
!= INSTALLSTATE_ABSENT
)
904 TRACE("feature %s not scheduled for removal, skipping unregistration of class %s\n",
905 debugstr_w(feature
->Feature
), debugstr_w(cls
->clsid
));
908 TRACE("Unregistering class %s (%p)\n", debugstr_w(cls
->clsid
), cls
);
910 cls
->action
= INSTALLSTATE_ABSENT
;
912 res
= RegDeleteTreeW( hkey
, cls
->clsid
);
913 if (res
!= ERROR_SUCCESS
)
914 WARN("Failed to delete class key %d\n", res
);
918 res
= RegOpenKeyW( HKEY_CLASSES_ROOT
, L
"AppID", &hkey2
);
919 if (res
== ERROR_SUCCESS
)
921 res
= RegDeleteKeyW( hkey2
, cls
->AppID
->AppID
);
922 if (res
!= ERROR_SUCCESS
)
923 WARN("Failed to delete appid key %d\n", res
);
924 RegCloseKey( hkey2
);
927 if (cls
->FileTypeMask
)
929 filetype
= msi_alloc( (lstrlenW( L
"FileType\\" ) + lstrlenW( cls
->clsid
) + 1) * sizeof(WCHAR
) );
932 lstrcpyW( filetype
, L
"FileType\\" );
933 lstrcatW( filetype
, cls
->clsid
);
934 res
= RegDeleteTreeW( HKEY_CLASSES_ROOT
, filetype
);
935 msi_free( filetype
);
937 if (res
!= ERROR_SUCCESS
)
938 WARN("Failed to delete file type %d\n", res
);
942 uirow
= MSI_CreateRecord( 1 );
943 MSI_RecordSetStringW( uirow
, 1, cls
->clsid
);
944 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
945 msiobj_release( &uirow
->hdr
);
948 return ERROR_SUCCESS
;
951 static LPCWSTR
get_clsid_of_progid( const MSIPROGID
*progid
)
956 return progid
->Class
->clsid
;
957 if (progid
->Parent
== progid
)
959 progid
= progid
->Parent
;
964 static UINT
register_progid( const MSIPROGID
* progid
)
969 rc
= RegCreateKeyW( HKEY_CLASSES_ROOT
, progid
->ProgID
, &hkey
);
970 if (rc
== ERROR_SUCCESS
)
972 LPCWSTR clsid
= get_clsid_of_progid( progid
);
975 msi_reg_set_subkey_val( hkey
, L
"CLSID", NULL
, clsid
);
977 TRACE("%s has no class\n", debugstr_w( progid
->ProgID
) );
979 if (progid
->Description
)
980 msi_reg_set_val_str( hkey
, NULL
, progid
->Description
);
982 if (progid
->IconPath
)
983 msi_reg_set_subkey_val( hkey
, L
"DefaultIcon", NULL
, progid
->IconPath
);
985 /* write out the current version */
987 msi_reg_set_subkey_val( hkey
, L
"CurVer", NULL
, progid
->CurVer
->ProgID
);
992 ERR("failed to create key %s\n", debugstr_w( progid
->ProgID
) );
997 static const MSICLASS
*get_progid_class( const MSIPROGID
*progid
)
1001 if (progid
->Parent
) progid
= progid
->Parent
;
1002 if (progid
->Class
) return progid
->Class
;
1003 if (!progid
->Parent
|| progid
->Parent
== progid
) break;
1008 static BOOL
has_class_installed( const MSIPROGID
*progid
)
1010 const MSICLASS
*class = get_progid_class( progid
);
1011 if (!class || !class->ProgID
) return FALSE
;
1012 return (class->action
== INSTALLSTATE_LOCAL
);
1015 static BOOL
has_one_extension_installed( const MSIPACKAGE
*package
, const MSIPROGID
*progid
)
1017 const MSIEXTENSION
*extension
;
1018 LIST_FOR_EACH_ENTRY( extension
, &package
->extensions
, MSIEXTENSION
, entry
)
1020 if (extension
->ProgID
== progid
&& !list_empty( &extension
->verbs
) &&
1021 extension
->action
== INSTALLSTATE_LOCAL
) return TRUE
;
1026 UINT
ACTION_RegisterProgIdInfo(MSIPACKAGE
*package
)
1032 if (package
->script
== SCRIPT_NONE
)
1033 return msi_schedule_action( package
, SCRIPT_INSTALL
, L
"RegisterProgIdInfo" );
1035 r
= load_classes_and_such( package
);
1036 if (r
!= ERROR_SUCCESS
)
1039 LIST_FOR_EACH_ENTRY( progid
, &package
->progids
, MSIPROGID
, entry
)
1041 if (!has_class_installed( progid
) && !has_one_extension_installed( package
, progid
))
1043 TRACE("progid %s not scheduled to be installed\n", debugstr_w(progid
->ProgID
));
1046 TRACE("Registering progid %s\n", debugstr_w(progid
->ProgID
));
1048 register_progid( progid
);
1050 uirow
= MSI_CreateRecord( 1 );
1051 MSI_RecordSetStringW( uirow
, 1, progid
->ProgID
);
1052 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1053 msiobj_release( &uirow
->hdr
);
1055 return ERROR_SUCCESS
;
1058 static BOOL
has_class_removed( const MSIPROGID
*progid
)
1060 const MSICLASS
*class = get_progid_class( progid
);
1061 if (!class || !class->ProgID
) return FALSE
;
1062 return (class->action
== INSTALLSTATE_ABSENT
);
1065 static BOOL
has_extensions( const MSIPACKAGE
*package
, const MSIPROGID
*progid
)
1067 const MSIEXTENSION
*extension
;
1068 LIST_FOR_EACH_ENTRY( extension
, &package
->extensions
, MSIEXTENSION
, entry
)
1070 if (extension
->ProgID
== progid
&& !list_empty( &extension
->verbs
)) return TRUE
;
1075 static BOOL
has_all_extensions_removed( const MSIPACKAGE
*package
, const MSIPROGID
*progid
)
1078 const MSIEXTENSION
*extension
;
1079 LIST_FOR_EACH_ENTRY( extension
, &package
->extensions
, MSIEXTENSION
, entry
)
1081 if (extension
->ProgID
== progid
&& !list_empty( &extension
->verbs
) &&
1082 extension
->action
== INSTALLSTATE_ABSENT
) ret
= TRUE
;
1088 UINT
ACTION_UnregisterProgIdInfo( MSIPACKAGE
*package
)
1095 if (package
->script
== SCRIPT_NONE
)
1096 return msi_schedule_action( package
, SCRIPT_INSTALL
, L
"UnregisterProgIdInfo" );
1098 r
= load_classes_and_such( package
);
1099 if (r
!= ERROR_SUCCESS
)
1102 LIST_FOR_EACH_ENTRY( progid
, &package
->progids
, MSIPROGID
, entry
)
1104 if (!has_class_removed( progid
) ||
1105 (has_extensions( package
, progid
) && !has_all_extensions_removed( package
, progid
)))
1107 TRACE("progid %s not scheduled to be removed\n", debugstr_w(progid
->ProgID
));
1110 TRACE("Unregistering progid %s\n", debugstr_w(progid
->ProgID
));
1112 res
= RegDeleteTreeW( HKEY_CLASSES_ROOT
, progid
->ProgID
);
1113 if (res
!= ERROR_SUCCESS
)
1114 TRACE("Failed to delete progid key %d\n", res
);
1116 uirow
= MSI_CreateRecord( 1 );
1117 MSI_RecordSetStringW( uirow
, 1, progid
->ProgID
);
1118 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1119 msiobj_release( &uirow
->hdr
);
1121 return ERROR_SUCCESS
;
1124 static UINT
register_verb(MSIPACKAGE
*package
, LPCWSTR progid
,
1125 MSICOMPONENT
* component
, const MSIEXTENSION
* extension
,
1126 MSIVERB
* verb
, INT
* Sequence
)
1134 keyname
= msi_build_directory_name(4, progid
, L
"shell", verb
->Verb
, L
"command");
1136 TRACE("Making Key %s\n",debugstr_w(keyname
));
1137 RegCreateKeyW(HKEY_CLASSES_ROOT
, keyname
, &key
);
1138 size
= lstrlenW(component
->FullKeypath
);
1140 size
+= lstrlenW(verb
->Argument
);
1143 command
= msi_alloc(size
* sizeof (WCHAR
));
1145 swprintf(command
, size
, L
"\"%s\" %s", component
->FullKeypath
, verb
->Argument
);
1147 swprintf(command
, size
, L
"\"%s\"", component
->FullKeypath
);
1149 msi_reg_set_val_str( key
, NULL
, command
);
1152 advertise
= msi_create_component_advertise_string(package
, component
,
1153 extension
->Feature
->Feature
);
1154 size
= lstrlenW(advertise
);
1157 size
+= lstrlenW(verb
->Argument
);
1160 command
= msi_alloc_zero(size
* sizeof (WCHAR
));
1162 lstrcpyW(command
,advertise
);
1165 lstrcatW(command
, L
" ");
1166 lstrcatW(command
, verb
->Argument
);
1169 msi_reg_set_val_multi_str( key
, L
"command", command
);
1173 msi_free(advertise
);
1178 keyname
= msi_build_directory_name( 3, progid
, L
"shell", verb
->Verb
);
1179 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, keyname
, NULL
, verb
->Command
);
1183 if (verb
->Sequence
!= MSI_NULL_INTEGER
)
1185 if (*Sequence
== MSI_NULL_INTEGER
|| verb
->Sequence
< *Sequence
)
1187 *Sequence
= verb
->Sequence
;
1188 keyname
= msi_build_directory_name( 2, progid
, L
"shell" );
1189 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, keyname
, NULL
, verb
->Verb
);
1193 return ERROR_SUCCESS
;
1196 UINT
ACTION_RegisterExtensionInfo(MSIPACKAGE
*package
)
1201 BOOL install_on_demand
= TRUE
;
1205 if (package
->script
== SCRIPT_NONE
)
1206 return msi_schedule_action( package
, SCRIPT_INSTALL
, L
"RegisterExtensionInfo" );
1208 r
= load_classes_and_such( package
);
1209 if (r
!= ERROR_SUCCESS
)
1212 /* We need to set install_on_demand based on if the shell handles advertised
1213 * shortcuts and the like. Because Mike McCormack is working on this i am
1214 * going to default to TRUE
1217 LIST_FOR_EACH_ENTRY( ext
, &package
->extensions
, MSIEXTENSION
, entry
)
1220 MSIFEATURE
*feature
;
1222 if (!ext
->Component
)
1225 if (!ext
->Component
->Enabled
)
1227 TRACE("component is disabled\n");
1231 feature
= ext
->Feature
;
1236 * yes. MSDN says that these are based on _Feature_ not on
1237 * Component. So verify the feature is to be installed
1239 feature
->Action
= msi_get_feature_action( package
, feature
);
1240 if (feature
->Action
!= INSTALLSTATE_LOCAL
&&
1241 !(install_on_demand
&& feature
->Action
== INSTALLSTATE_ADVERTISED
))
1243 TRACE("feature %s not scheduled for installation, skipping registration of extension %s\n",
1244 debugstr_w(feature
->Feature
), debugstr_w(ext
->Extension
));
1247 TRACE("Registering extension %s (%p)\n", debugstr_w(ext
->Extension
), ext
);
1249 ext
->action
= INSTALLSTATE_LOCAL
;
1251 extension
= msi_alloc( (lstrlenW( ext
->Extension
) + 2) * sizeof(WCHAR
) );
1255 lstrcpyW( extension
+ 1, ext
->Extension
);
1256 res
= RegCreateKeyW( HKEY_CLASSES_ROOT
, extension
, &hkey
);
1257 msi_free( extension
);
1258 if (res
!= ERROR_SUCCESS
)
1259 WARN("Failed to create extension key %d\n", res
);
1263 msi_reg_set_val_str( hkey
, L
"Content Type", ext
->Mime
->ContentType
);
1265 if (ext
->ProgID
|| ext
->ProgIDText
)
1271 INT Sequence
= MSI_NULL_INTEGER
;
1274 progid
= ext
->ProgID
->ProgID
;
1276 progid
= ext
->ProgIDText
;
1278 msi_reg_set_val_str( hkey
, NULL
, progid
);
1280 newkey
= msi_alloc( (lstrlenW(progid
) + lstrlenW(L
"\\ShellNew") + 1) * sizeof(WCHAR
));
1282 lstrcpyW(newkey
, progid
);
1283 lstrcatW(newkey
, L
"\\ShellNew");
1284 RegCreateKeyW(hkey
, newkey
, &hkey2
);
1289 /* do all the verbs */
1290 LIST_FOR_EACH_ENTRY( verb
, &ext
->verbs
, MSIVERB
, entry
)
1292 register_verb( package
, progid
, ext
->Component
,
1293 ext
, verb
, &Sequence
);
1299 uirow
= MSI_CreateRecord(1);
1300 MSI_RecordSetStringW( uirow
, 1, ext
->Extension
);
1301 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1302 msiobj_release(&uirow
->hdr
);
1304 return ERROR_SUCCESS
;
1307 UINT
ACTION_UnregisterExtensionInfo( MSIPACKAGE
*package
)
1314 if (package
->script
== SCRIPT_NONE
)
1315 return msi_schedule_action( package
, SCRIPT_INSTALL
, L
"UnregisterExtensionInfo" );
1317 r
= load_classes_and_such( package
);
1318 if (r
!= ERROR_SUCCESS
)
1321 LIST_FOR_EACH_ENTRY( ext
, &package
->extensions
, MSIEXTENSION
, entry
)
1324 MSIFEATURE
*feature
;
1326 if (!ext
->Component
)
1329 if (!ext
->Component
->Enabled
)
1331 TRACE("component is disabled\n");
1335 feature
= ext
->Feature
;
1339 feature
->Action
= msi_get_feature_action( package
, feature
);
1340 if (feature
->Action
!= INSTALLSTATE_ABSENT
)
1342 TRACE("feature %s not scheduled for removal, skipping unregistration of extension %s\n",
1343 debugstr_w(feature
->Feature
), debugstr_w(ext
->Extension
));
1346 TRACE("Unregistering extension %s\n", debugstr_w(ext
->Extension
));
1348 ext
->action
= INSTALLSTATE_ABSENT
;
1350 extension
= msi_alloc( (lstrlenW( ext
->Extension
) + 2) * sizeof(WCHAR
) );
1354 lstrcpyW( extension
+ 1, ext
->Extension
);
1355 res
= RegDeleteTreeW( HKEY_CLASSES_ROOT
, extension
);
1356 msi_free( extension
);
1357 if (res
!= ERROR_SUCCESS
)
1358 WARN("Failed to delete extension key %d\n", res
);
1361 if (ext
->ProgID
|| ext
->ProgIDText
)
1364 LPWSTR progid_shell
;
1367 progid
= ext
->ProgID
->ProgID
;
1369 progid
= ext
->ProgIDText
;
1371 progid_shell
= msi_alloc( (lstrlenW( progid
) + lstrlenW( L
"\\shell" ) + 1) * sizeof(WCHAR
) );
1374 lstrcpyW( progid_shell
, progid
);
1375 lstrcatW( progid_shell
, L
"\\shell" );
1376 res
= RegDeleteTreeW( HKEY_CLASSES_ROOT
, progid_shell
);
1377 msi_free( progid_shell
);
1378 if (res
!= ERROR_SUCCESS
)
1379 WARN("Failed to delete shell key %d\n", res
);
1380 RegDeleteKeyW( HKEY_CLASSES_ROOT
, progid
);
1384 uirow
= MSI_CreateRecord( 1 );
1385 MSI_RecordSetStringW( uirow
, 1, ext
->Extension
);
1386 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1387 msiobj_release( &uirow
->hdr
);
1389 return ERROR_SUCCESS
;
1392 UINT
ACTION_RegisterMIMEInfo(MSIPACKAGE
*package
)
1398 if (package
->script
== SCRIPT_NONE
)
1399 return msi_schedule_action( package
, SCRIPT_INSTALL
, L
"RegisterMIMEInfo" );
1401 r
= load_classes_and_such( package
);
1402 if (r
!= ERROR_SUCCESS
)
1405 LIST_FOR_EACH_ENTRY( mt
, &package
->mimes
, MSIMIME
, entry
)
1407 LPWSTR extension
= NULL
, key
;
1410 * check if the MIME is to be installed. Either as requested by an
1411 * extension or Class
1413 if ((!mt
->Class
|| mt
->Class
->action
!= INSTALLSTATE_LOCAL
) &&
1414 (!mt
->Extension
|| mt
->Extension
->action
!= INSTALLSTATE_LOCAL
))
1416 TRACE("MIME %s not scheduled to be installed\n", debugstr_w(mt
->ContentType
));
1420 TRACE("Registering MIME type %s\n", debugstr_w(mt
->ContentType
));
1422 if (mt
->Extension
) extension
= msi_alloc( (lstrlenW( mt
->Extension
->Extension
) + 2) * sizeof(WCHAR
) );
1423 key
= msi_alloc( (lstrlenW( mt
->ContentType
) +
1424 lstrlenW( L
"MIME\\Database\\Content Type\\" ) + 1) * sizeof(WCHAR
) );
1426 if (extension
&& key
)
1429 lstrcpyW( extension
+ 1, mt
->Extension
->Extension
);
1431 lstrcpyW( key
, L
"MIME\\Database\\Content Type\\" );
1432 lstrcatW( key
, mt
->ContentType
);
1433 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, key
, L
"Extension", extension
);
1436 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, key
, L
"CLSID", mt
->clsid
);
1438 msi_free( extension
);
1441 uirow
= MSI_CreateRecord( 2 );
1442 MSI_RecordSetStringW( uirow
, 1, mt
->ContentType
);
1443 MSI_RecordSetStringW( uirow
, 2, mt
->suffix
);
1444 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1445 msiobj_release( &uirow
->hdr
);
1447 return ERROR_SUCCESS
;
1450 UINT
ACTION_UnregisterMIMEInfo( MSIPACKAGE
*package
)
1456 if (package
->script
== SCRIPT_NONE
)
1457 return msi_schedule_action( package
, SCRIPT_INSTALL
, L
"UnregisterMIMEInfo" );
1459 r
= load_classes_and_such( package
);
1460 if (r
!= ERROR_SUCCESS
)
1463 LIST_FOR_EACH_ENTRY( mime
, &package
->mimes
, MSIMIME
, entry
)
1468 if ((!mime
->Class
|| mime
->Class
->action
!= INSTALLSTATE_ABSENT
) &&
1469 (!mime
->Extension
|| mime
->Extension
->action
!= INSTALLSTATE_ABSENT
))
1471 TRACE("MIME %s not scheduled to be removed\n", debugstr_w(mime
->ContentType
));
1475 TRACE("Unregistering MIME type %s\n", debugstr_w(mime
->ContentType
));
1477 mime_key
= msi_alloc( (lstrlenW( L
"MIME\\Database\\Content Type\\" ) +
1478 lstrlenW( mime
->ContentType
) + 1) * sizeof(WCHAR
) );
1481 lstrcpyW( mime_key
, L
"MIME\\Database\\Content Type\\" );
1482 lstrcatW( mime_key
, mime
->ContentType
);
1483 res
= RegDeleteKeyW( HKEY_CLASSES_ROOT
, mime_key
);
1484 if (res
!= ERROR_SUCCESS
)
1485 WARN("Failed to delete MIME key %d\n", res
);
1486 msi_free( mime_key
);
1489 uirow
= MSI_CreateRecord( 2 );
1490 MSI_RecordSetStringW( uirow
, 1, mime
->ContentType
);
1491 MSI_RecordSetStringW( uirow
, 2, mime
->suffix
);
1492 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
1493 msiobj_release( &uirow
->hdr
);
1495 return ERROR_SUCCESS
;