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"
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
)
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};
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
);
97 row
= MSI_QueryGetRecord(package
->db
, query
, name
);
101 appid
= load_appid(package
, row
);
102 msiobj_release(&row
->hdr
);
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
)
114 /* fill in the data */
116 progid
= msi_alloc_zero( sizeof(MSIPROGID
) );
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);
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
);
154 buffer
= MSI_RecordGetString(row
,5);
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
;
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};
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
);
201 row
= MSI_QueryGetRecord( package
->db
, query
, name
);
205 progid
= load_progid(package
, row
);
206 msiobj_release(&row
->hdr
);
210 static MSICLASS
*load_class( MSIPACKAGE
* package
, MSIRECORD
*row
)
216 /* fill in the data */
218 cls
= msi_alloc_zero( sizeof(MSICLASS
) );
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);
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);
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
);
259 buffer
= MSI_RecordGetString(row
,8);
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};
275 cls
->DefInprocHandler
= strdupW(ole2
);
278 cls
->DefInprocHandler32
= strdupW(ole32
);
281 cls
->DefInprocHandler
= strdupW(ole2
);
282 cls
->DefInprocHandler32
= strdupW(ole32
);
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);
299 cls
->action
= INSTALLSTATE_UNKNOWN
;
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};
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
);
331 row
= MSI_QueryGetRecord(package
->db
, query
, classid
);
335 cls
= load_class(package
, row
);
336 msiobj_release(&row
->hdr
);
340 static MSIEXTENSION
*load_given_extension( MSIPACKAGE
*package
, LPCWSTR extension
);
342 static MSIMIME
*load_mime( MSIPACKAGE
* package
, MSIRECORD
*row
)
347 /* fill in the data */
349 mt
= msi_alloc_zero( sizeof(MSIMIME
) );
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
);
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};
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
);
390 row
= MSI_QueryGetRecord(package
->db
, query
, mime
);
394 mt
= load_mime(package
, row
);
395 msiobj_release(&row
->hdr
);
399 static MSIEXTENSION
*load_extension( MSIPACKAGE
* package
, MSIRECORD
*row
)
404 /* fill in the data */
406 ext
= msi_alloc_zero( sizeof(MSIEXTENSION
) );
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
);
428 ext
->action
= INSTALLSTATE_UNKNOWN
;
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};
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
);
461 row
= MSI_QueryGetRecord( package
->db
, query
, name
);
465 ext
= load_extension(package
, row
);
466 msiobj_release(&row
->hdr
);
470 static UINT
iterate_load_verb(MSIRECORD
*row
, LPVOID param
)
472 MSIPACKAGE
* package
= param
;
475 MSIEXTENSION
*extension
;
477 buffer
= MSI_RecordGetString(row
,1);
478 extension
= load_given_extension( package
, buffer
);
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
) );
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
)
513 MSIPACKAGE
* package
= param
;
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
))
526 if (strcmpW( context
, cls
->Context
))
528 if (comp
== cls
->Component
)
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};
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
);
557 static UINT
iterate_all_extensions(MSIRECORD
*rec
, LPVOID param
)
562 MSIPACKAGE
* package
= param
;
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
))
574 if (comp
== ext
->Component
)
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};
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
);
603 static UINT
iterate_all_progids(MSIRECORD
*rec
, LPVOID param
)
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};
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
);
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};
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
);
646 static UINT
iterate_all_mimes(MSIRECORD
*rec
, LPVOID param
)
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};
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
);
673 static UINT
load_classes_and_such( MSIPACKAGE
*package
)
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 UINT
register_appid(const MSIAPPID
*appid
, LPCWSTR app
)
703 static const WCHAR szRemoteServerName
[] =
704 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
705 static const WCHAR szLocalService
[] =
706 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
707 static const WCHAR szService
[] =
708 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
709 static const WCHAR szDLL
[] =
710 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
711 static const WCHAR szActivate
[] =
712 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
713 static const WCHAR szY
[] = {'Y',0};
714 static const WCHAR szRunAs
[] = {'R','u','n','A','s',0};
715 static const WCHAR szUser
[] =
716 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
720 RegCreateKeyW(HKEY_CLASSES_ROOT
,szAppID
,&hkey2
);
721 RegCreateKeyW( hkey2
, appid
->AppID
, &hkey3
);
723 msi_reg_set_val_str( hkey3
, NULL
, app
);
725 if (appid
->RemoteServerName
)
726 msi_reg_set_val_str( hkey3
, szRemoteServerName
, appid
->RemoteServerName
);
728 if (appid
->LocalServer
)
729 msi_reg_set_val_str( hkey3
, szLocalService
, appid
->LocalServer
);
731 if (appid
->ServiceParameters
)
732 msi_reg_set_val_str( hkey3
, szService
, appid
->ServiceParameters
);
734 if (appid
->DllSurrogate
)
735 msi_reg_set_val_str( hkey3
, szDLL
, appid
->DllSurrogate
);
737 if (appid
->ActivateAtStorage
)
738 msi_reg_set_val_str( hkey3
, szActivate
, szY
);
740 if (appid
->RunAsInteractiveUser
)
741 msi_reg_set_val_str( hkey3
, szRunAs
, szUser
);
744 return ERROR_SUCCESS
;
747 UINT
ACTION_RegisterClassInfo(MSIPACKAGE
*package
)
749 static const WCHAR szFileType_fmt
[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
750 const WCHAR
*keypath
;
752 HKEY hkey
, hkey2
, hkey3
;
756 r
= load_classes_and_such( package
);
757 if (r
!= ERROR_SUCCESS
)
760 if (is_64bit
&& package
->platform
== PLATFORM_INTEL
)
761 keypath
= szWow6432NodeCLSID
;
765 if (RegCreateKeyW(HKEY_CLASSES_ROOT
, keypath
, &hkey
) != ERROR_SUCCESS
)
766 return ERROR_FUNCTION_FAILED
;
768 LIST_FOR_EACH_ENTRY( cls
, &package
->classes
, MSICLASS
, entry
)
776 comp
= cls
->Component
;
782 TRACE("component is disabled\n");
786 feature
= cls
->Feature
;
790 feature
->Action
= msi_get_feature_action( package
, feature
);
791 if (feature
->Action
!= INSTALLSTATE_LOCAL
&&
792 feature
->Action
!= INSTALLSTATE_ADVERTISED
)
794 TRACE("feature %s not scheduled for installation, skipping registration of class %s\n",
795 debugstr_w(feature
->Feature
), debugstr_w(cls
->clsid
));
799 if (!comp
->KeyPath
|| !(file
= msi_get_loaded_file( package
, comp
->KeyPath
)))
801 TRACE("COM server not provided, skipping class %s\n", debugstr_w(cls
->clsid
));
804 TRACE("Registering class %s (%p)\n", debugstr_w(cls
->clsid
), cls
);
806 cls
->action
= INSTALLSTATE_LOCAL
;
808 RegCreateKeyW( hkey
, cls
->clsid
, &hkey2
);
810 if (cls
->Description
)
811 msi_reg_set_val_str( hkey2
, NULL
, cls
->Description
);
813 RegCreateKeyW( hkey2
, cls
->Context
, &hkey3
);
816 * FIXME: Implement install on demand (advertised components).
818 * ole32.dll should call msi.MsiProvideComponentFromDescriptor()
819 * when it needs an InProcServer that doesn't exist.
820 * The component advertise string should be in the "InProcServer" value.
822 size
= lstrlenW( file
->TargetPath
)+1;
824 size
+= lstrlenW(cls
->Argument
)+1;
826 argument
= msi_alloc( size
* sizeof(WCHAR
) );
827 lstrcpyW( argument
, file
->TargetPath
);
831 lstrcatW( argument
, szSpace
);
832 lstrcatW( argument
, cls
->Argument
);
835 msi_reg_set_val_str( hkey3
, NULL
, argument
);
840 if (cls
->ProgID
|| cls
->ProgIDText
)
845 progid
= cls
->ProgID
->ProgID
;
847 progid
= cls
->ProgIDText
;
849 msi_reg_set_subkey_val( hkey2
, szProgID
, NULL
, progid
);
851 if (cls
->ProgID
&& cls
->ProgID
->VersionInd
)
853 msi_reg_set_subkey_val( hkey2
, szVIProgID
, NULL
,
854 cls
->ProgID
->VersionInd
->ProgID
);
860 MSIAPPID
*appid
= cls
->AppID
;
861 msi_reg_set_val_str( hkey2
, szAppID
, appid
->AppID
);
862 register_appid( appid
, cls
->Description
);
866 msi_reg_set_subkey_val( hkey2
, szDefaultIcon
, NULL
, cls
->IconPath
);
868 if (cls
->DefInprocHandler
)
869 msi_reg_set_subkey_val( hkey2
, szInprocHandler
, NULL
, cls
->DefInprocHandler
);
871 if (cls
->DefInprocHandler32
)
872 msi_reg_set_subkey_val( hkey2
, szInprocHandler32
, NULL
, cls
->DefInprocHandler32
);
876 /* if there is a FileTypeMask, register the FileType */
877 if (cls
->FileTypeMask
)
882 ptr
= cls
->FileTypeMask
;
885 ptr2
= strchrW(ptr
,';');
888 keyname
= msi_alloc( (strlenW(szFileType_fmt
) + strlenW(cls
->clsid
) + 4) * sizeof(WCHAR
));
889 sprintfW( keyname
, szFileType_fmt
, cls
->clsid
, index
);
891 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, keyname
, NULL
, ptr
);
903 uirow
= MSI_CreateRecord(1);
904 MSI_RecordSetStringW( uirow
, 1, cls
->clsid
);
905 msi_ui_actiondata( package
, szRegisterClassInfo
, uirow
);
906 msiobj_release(&uirow
->hdr
);
909 return ERROR_SUCCESS
;
912 UINT
ACTION_UnregisterClassInfo( MSIPACKAGE
*package
)
914 static const WCHAR szFileType
[] = {'F','i','l','e','T','y','p','e','\\',0};
915 const WCHAR
*keypath
;
921 r
= load_classes_and_such( package
);
922 if (r
!= ERROR_SUCCESS
)
925 if (is_64bit
&& package
->platform
== PLATFORM_INTEL
)
926 keypath
= szWow6432NodeCLSID
;
930 if (RegOpenKeyW( HKEY_CLASSES_ROOT
, keypath
, &hkey
) != ERROR_SUCCESS
)
931 return ERROR_SUCCESS
;
933 LIST_FOR_EACH_ENTRY( cls
, &package
->classes
, MSICLASS
, entry
)
940 comp
= cls
->Component
;
946 TRACE("component is disabled\n");
950 feature
= cls
->Feature
;
954 feature
->Action
= msi_get_feature_action( package
, feature
);
955 if (feature
->Action
!= INSTALLSTATE_ABSENT
)
957 TRACE("feature %s not scheduled for removal, skipping unregistration of class %s\n",
958 debugstr_w(feature
->Feature
), debugstr_w(cls
->clsid
));
961 TRACE("Unregistering class %s (%p)\n", debugstr_w(cls
->clsid
), cls
);
963 cls
->action
= INSTALLSTATE_ABSENT
;
965 res
= RegDeleteTreeW( hkey
, cls
->clsid
);
966 if (res
!= ERROR_SUCCESS
)
967 WARN("Failed to delete class key %d\n", res
);
971 res
= RegOpenKeyW( HKEY_CLASSES_ROOT
, szAppID
, &hkey2
);
972 if (res
== ERROR_SUCCESS
)
974 res
= RegDeleteKeyW( hkey2
, cls
->AppID
->AppID
);
975 if (res
!= ERROR_SUCCESS
)
976 WARN("Failed to delete appid key %d\n", res
);
977 RegCloseKey( hkey2
);
980 if (cls
->FileTypeMask
)
982 filetype
= msi_alloc( (strlenW( szFileType
) + strlenW( cls
->clsid
) + 1) * sizeof(WCHAR
) );
985 strcpyW( filetype
, szFileType
);
986 strcatW( filetype
, cls
->clsid
);
987 res
= RegDeleteTreeW( HKEY_CLASSES_ROOT
, filetype
);
988 msi_free( filetype
);
990 if (res
!= ERROR_SUCCESS
)
991 WARN("Failed to delete file type %d\n", res
);
995 uirow
= MSI_CreateRecord( 1 );
996 MSI_RecordSetStringW( uirow
, 1, cls
->clsid
);
997 msi_ui_actiondata( package
, szUnregisterClassInfo
, uirow
);
998 msiobj_release( &uirow
->hdr
);
1000 RegCloseKey( hkey
);
1001 return ERROR_SUCCESS
;
1004 static LPCWSTR
get_clsid_of_progid( const MSIPROGID
*progid
)
1009 return progid
->Class
->clsid
;
1010 if (progid
->Parent
== progid
)
1012 progid
= progid
->Parent
;
1017 static UINT
register_progid( const MSIPROGID
* progid
)
1019 static const WCHAR szCurVer
[] = {'C','u','r','V','e','r',0};
1023 rc
= RegCreateKeyW( HKEY_CLASSES_ROOT
, progid
->ProgID
, &hkey
);
1024 if (rc
== ERROR_SUCCESS
)
1026 LPCWSTR clsid
= get_clsid_of_progid( progid
);
1029 msi_reg_set_subkey_val( hkey
, szCLSID
, NULL
, clsid
);
1031 TRACE("%s has no class\n", debugstr_w( progid
->ProgID
) );
1033 if (progid
->Description
)
1034 msi_reg_set_val_str( hkey
, NULL
, progid
->Description
);
1036 if (progid
->IconPath
)
1037 msi_reg_set_subkey_val( hkey
, szDefaultIcon
, NULL
, progid
->IconPath
);
1039 /* write out the current version */
1041 msi_reg_set_subkey_val( hkey
, szCurVer
, NULL
, progid
->CurVer
->ProgID
);
1046 ERR("failed to create key %s\n", debugstr_w( progid
->ProgID
) );
1051 static const MSICLASS
*get_progid_class( const MSIPROGID
*progid
)
1055 if (progid
->Parent
) progid
= progid
->Parent
;
1056 if (progid
->Class
) return progid
->Class
;
1057 if (!progid
->Parent
) break;
1062 static BOOL
has_class_installed( const MSIPROGID
*progid
)
1064 const MSICLASS
*class = get_progid_class( progid
);
1065 if (!class || !class->ProgID
) return FALSE
;
1066 return (class->action
== INSTALLSTATE_LOCAL
);
1069 static BOOL
has_one_extension_installed( const MSIPACKAGE
*package
, const MSIPROGID
*progid
)
1071 const MSIEXTENSION
*extension
;
1072 LIST_FOR_EACH_ENTRY( extension
, &package
->extensions
, MSIEXTENSION
, entry
)
1074 if (extension
->ProgID
== progid
&& !list_empty( &extension
->verbs
) &&
1075 extension
->action
== INSTALLSTATE_LOCAL
) return TRUE
;
1080 UINT
ACTION_RegisterProgIdInfo(MSIPACKAGE
*package
)
1086 r
= load_classes_and_such( package
);
1087 if (r
!= ERROR_SUCCESS
)
1090 LIST_FOR_EACH_ENTRY( progid
, &package
->progids
, MSIPROGID
, entry
)
1092 if (!has_class_installed( progid
) && !has_one_extension_installed( package
, progid
))
1094 TRACE("progid %s not scheduled to be installed\n", debugstr_w(progid
->ProgID
));
1097 TRACE("Registering progid %s\n", debugstr_w(progid
->ProgID
));
1099 register_progid( progid
);
1101 uirow
= MSI_CreateRecord( 1 );
1102 MSI_RecordSetStringW( uirow
, 1, progid
->ProgID
);
1103 msi_ui_actiondata( package
, szRegisterProgIdInfo
, uirow
);
1104 msiobj_release( &uirow
->hdr
);
1106 return ERROR_SUCCESS
;
1109 static BOOL
has_class_removed( const MSIPROGID
*progid
)
1111 const MSICLASS
*class = get_progid_class( progid
);
1112 if (!class || !class->ProgID
) return FALSE
;
1113 return (class->action
== INSTALLSTATE_ABSENT
);
1116 static BOOL
has_extensions( const MSIPACKAGE
*package
, const MSIPROGID
*progid
)
1118 const MSIEXTENSION
*extension
;
1119 LIST_FOR_EACH_ENTRY( extension
, &package
->extensions
, MSIEXTENSION
, entry
)
1121 if (extension
->ProgID
== progid
&& !list_empty( &extension
->verbs
)) return TRUE
;
1126 static BOOL
has_all_extensions_removed( const MSIPACKAGE
*package
, const MSIPROGID
*progid
)
1129 const MSIEXTENSION
*extension
;
1130 LIST_FOR_EACH_ENTRY( extension
, &package
->extensions
, MSIEXTENSION
, entry
)
1132 if (extension
->ProgID
== progid
&& !list_empty( &extension
->verbs
) &&
1133 extension
->action
== INSTALLSTATE_ABSENT
) ret
= TRUE
;
1139 UINT
ACTION_UnregisterProgIdInfo( MSIPACKAGE
*package
)
1146 r
= load_classes_and_such( package
);
1147 if (r
!= ERROR_SUCCESS
)
1150 LIST_FOR_EACH_ENTRY( progid
, &package
->progids
, MSIPROGID
, entry
)
1152 if (!has_class_removed( progid
) ||
1153 (has_extensions( package
, progid
) && !has_all_extensions_removed( package
, progid
)))
1155 TRACE("progid %s not scheduled to be removed\n", debugstr_w(progid
->ProgID
));
1158 TRACE("Unregistering progid %s\n", debugstr_w(progid
->ProgID
));
1160 res
= RegDeleteTreeW( HKEY_CLASSES_ROOT
, progid
->ProgID
);
1161 if (res
!= ERROR_SUCCESS
)
1162 TRACE("Failed to delete progid key %d\n", res
);
1164 uirow
= MSI_CreateRecord( 1 );
1165 MSI_RecordSetStringW( uirow
, 1, progid
->ProgID
);
1166 msi_ui_actiondata( package
, szUnregisterProgIdInfo
, uirow
);
1167 msiobj_release( &uirow
->hdr
);
1169 return ERROR_SUCCESS
;
1172 static UINT
register_verb(MSIPACKAGE
*package
, LPCWSTR progid
,
1173 MSICOMPONENT
* component
, const MSIEXTENSION
* extension
,
1174 MSIVERB
* verb
, INT
* Sequence
)
1178 static const WCHAR szShell
[] = {'s','h','e','l','l',0};
1179 static const WCHAR szCommand
[] = {'c','o','m','m','a','n','d',0};
1180 static const WCHAR fmt
[] = {'\"','%','s','\"',' ','%','s',0};
1181 static const WCHAR fmt2
[] = {'\"','%','s','\"',0};
1186 keyname
= msi_build_directory_name(4, progid
, szShell
, verb
->Verb
, szCommand
);
1188 TRACE("Making Key %s\n",debugstr_w(keyname
));
1189 RegCreateKeyW(HKEY_CLASSES_ROOT
, keyname
, &key
);
1190 size
= strlenW(component
->FullKeypath
);
1192 size
+= strlenW(verb
->Argument
);
1195 command
= msi_alloc(size
* sizeof (WCHAR
));
1197 sprintfW(command
, fmt
, component
->FullKeypath
, verb
->Argument
);
1199 sprintfW(command
, fmt2
, component
->FullKeypath
);
1201 msi_reg_set_val_str( key
, NULL
, command
);
1204 advertise
= msi_create_component_advertise_string(package
, component
,
1205 extension
->Feature
->Feature
);
1206 size
= strlenW(advertise
);
1209 size
+= strlenW(verb
->Argument
);
1212 command
= msi_alloc_zero(size
* sizeof (WCHAR
));
1214 strcpyW(command
,advertise
);
1217 strcatW(command
,szSpace
);
1218 strcatW(command
,verb
->Argument
);
1221 msi_reg_set_val_multi_str( key
, szCommand
, command
);
1225 msi_free(advertise
);
1230 keyname
= msi_build_directory_name( 3, progid
, szShell
, verb
->Verb
);
1231 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, keyname
, NULL
, verb
->Command
);
1235 if (verb
->Sequence
!= MSI_NULL_INTEGER
)
1237 if (*Sequence
== MSI_NULL_INTEGER
|| verb
->Sequence
< *Sequence
)
1239 *Sequence
= verb
->Sequence
;
1240 keyname
= msi_build_directory_name( 2, progid
, szShell
);
1241 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, keyname
, NULL
, verb
->Verb
);
1245 return ERROR_SUCCESS
;
1248 UINT
ACTION_RegisterExtensionInfo(MSIPACKAGE
*package
)
1250 static const WCHAR szContentType
[] = {'C','o','n','t','e','n','t',' ','T','y','p','e',0};
1254 BOOL install_on_demand
= TRUE
;
1258 r
= load_classes_and_such( package
);
1259 if (r
!= ERROR_SUCCESS
)
1262 /* We need to set install_on_demand based on if the shell handles advertised
1263 * shortcuts and the like. Because Mike McCormack is working on this i am
1264 * going to default to TRUE
1267 LIST_FOR_EACH_ENTRY( ext
, &package
->extensions
, MSIEXTENSION
, entry
)
1270 MSIFEATURE
*feature
;
1272 if (!ext
->Component
)
1275 if (!ext
->Component
->Enabled
)
1277 TRACE("component is disabled\n");
1281 feature
= ext
->Feature
;
1286 * yes. MSDN says that these are based on _Feature_ not on
1287 * Component. So verify the feature is to be installed
1289 feature
->Action
= msi_get_feature_action( package
, feature
);
1290 if (feature
->Action
!= INSTALLSTATE_LOCAL
&&
1291 !(install_on_demand
&& feature
->Action
== INSTALLSTATE_ADVERTISED
))
1293 TRACE("feature %s not scheduled for installation, skipping registration of extension %s\n",
1294 debugstr_w(feature
->Feature
), debugstr_w(ext
->Extension
));
1297 TRACE("Registering extension %s (%p)\n", debugstr_w(ext
->Extension
), ext
);
1299 ext
->action
= INSTALLSTATE_LOCAL
;
1301 extension
= msi_alloc( (strlenW( ext
->Extension
) + 2) * sizeof(WCHAR
) );
1305 strcpyW( extension
+ 1, ext
->Extension
);
1306 res
= RegCreateKeyW( HKEY_CLASSES_ROOT
, extension
, &hkey
);
1307 msi_free( extension
);
1308 if (res
!= ERROR_SUCCESS
)
1309 WARN("Failed to create extension key %d\n", res
);
1313 msi_reg_set_val_str( hkey
, szContentType
, ext
->Mime
->ContentType
);
1315 if (ext
->ProgID
|| ext
->ProgIDText
)
1317 static const WCHAR szSN
[] =
1318 {'\\','S','h','e','l','l','N','e','w',0};
1323 INT Sequence
= MSI_NULL_INTEGER
;
1326 progid
= ext
->ProgID
->ProgID
;
1328 progid
= ext
->ProgIDText
;
1330 msi_reg_set_val_str( hkey
, NULL
, progid
);
1332 newkey
= msi_alloc( (strlenW(progid
)+strlenW(szSN
)+1) * sizeof(WCHAR
));
1334 strcpyW(newkey
,progid
);
1335 strcatW(newkey
,szSN
);
1336 RegCreateKeyW(hkey
,newkey
,&hkey2
);
1341 /* do all the verbs */
1342 LIST_FOR_EACH_ENTRY( verb
, &ext
->verbs
, MSIVERB
, entry
)
1344 register_verb( package
, progid
, ext
->Component
,
1345 ext
, verb
, &Sequence
);
1351 uirow
= MSI_CreateRecord(1);
1352 MSI_RecordSetStringW( uirow
, 1, ext
->Extension
);
1353 msi_ui_actiondata( package
, szRegisterExtensionInfo
, uirow
);
1354 msiobj_release(&uirow
->hdr
);
1356 return ERROR_SUCCESS
;
1359 UINT
ACTION_UnregisterExtensionInfo( MSIPACKAGE
*package
)
1366 r
= load_classes_and_such( package
);
1367 if (r
!= ERROR_SUCCESS
)
1370 LIST_FOR_EACH_ENTRY( ext
, &package
->extensions
, MSIEXTENSION
, entry
)
1373 MSIFEATURE
*feature
;
1375 if (!ext
->Component
)
1378 if (!ext
->Component
->Enabled
)
1380 TRACE("component is disabled\n");
1384 feature
= ext
->Feature
;
1388 feature
->Action
= msi_get_feature_action( package
, feature
);
1389 if (feature
->Action
!= INSTALLSTATE_ABSENT
)
1391 TRACE("feature %s not scheduled for removal, skipping unregistration of extension %s\n",
1392 debugstr_w(feature
->Feature
), debugstr_w(ext
->Extension
));
1395 TRACE("Unregistering extension %s\n", debugstr_w(ext
->Extension
));
1397 ext
->action
= INSTALLSTATE_ABSENT
;
1399 extension
= msi_alloc( (strlenW( ext
->Extension
) + 2) * sizeof(WCHAR
) );
1403 strcpyW( extension
+ 1, ext
->Extension
);
1404 res
= RegDeleteTreeW( HKEY_CLASSES_ROOT
, extension
);
1405 msi_free( extension
);
1406 if (res
!= ERROR_SUCCESS
)
1407 WARN("Failed to delete extension key %d\n", res
);
1410 if (ext
->ProgID
|| ext
->ProgIDText
)
1412 static const WCHAR shellW
[] = {'\\','s','h','e','l','l',0};
1414 LPWSTR progid_shell
;
1417 progid
= ext
->ProgID
->ProgID
;
1419 progid
= ext
->ProgIDText
;
1421 progid_shell
= msi_alloc( (strlenW( progid
) + strlenW( shellW
) + 1) * sizeof(WCHAR
) );
1424 strcpyW( progid_shell
, progid
);
1425 strcatW( progid_shell
, shellW
);
1426 res
= RegDeleteTreeW( HKEY_CLASSES_ROOT
, progid_shell
);
1427 msi_free( progid_shell
);
1428 if (res
!= ERROR_SUCCESS
)
1429 WARN("Failed to delete shell key %d\n", res
);
1430 RegDeleteKeyW( HKEY_CLASSES_ROOT
, progid
);
1434 uirow
= MSI_CreateRecord( 1 );
1435 MSI_RecordSetStringW( uirow
, 1, ext
->Extension
);
1436 msi_ui_actiondata( package
, szUnregisterExtensionInfo
, uirow
);
1437 msiobj_release( &uirow
->hdr
);
1439 return ERROR_SUCCESS
;
1442 UINT
ACTION_RegisterMIMEInfo(MSIPACKAGE
*package
)
1444 static const WCHAR szExtension
[] = {'E','x','t','e','n','s','i','o','n',0};
1449 r
= load_classes_and_such( package
);
1450 if (r
!= ERROR_SUCCESS
)
1453 LIST_FOR_EACH_ENTRY( mt
, &package
->mimes
, MSIMIME
, entry
)
1455 LPWSTR extension
, key
;
1458 * check if the MIME is to be installed. Either as requested by an
1459 * extension or Class
1461 if ((!mt
->Class
|| mt
->Class
->action
!= INSTALLSTATE_LOCAL
) &&
1462 mt
->Extension
->action
!= INSTALLSTATE_LOCAL
)
1464 TRACE("MIME %s not scheduled to be installed\n", debugstr_w(mt
->ContentType
));
1468 TRACE("Registering MIME type %s\n", debugstr_w(mt
->ContentType
));
1470 extension
= msi_alloc( (strlenW( mt
->Extension
->Extension
) + 2) * sizeof(WCHAR
) );
1471 key
= msi_alloc( (strlenW( mt
->ContentType
) + strlenW( szMIMEDatabase
) + 1) * sizeof(WCHAR
) );
1473 if (extension
&& key
)
1476 strcpyW( extension
+ 1, mt
->Extension
->Extension
);
1478 strcpyW( key
, szMIMEDatabase
);
1479 strcatW( key
, mt
->ContentType
);
1480 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, key
, szExtension
, extension
);
1483 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT
, key
, szCLSID
, mt
->clsid
);
1485 msi_free( extension
);
1488 uirow
= MSI_CreateRecord( 2 );
1489 MSI_RecordSetStringW( uirow
, 1, mt
->ContentType
);
1490 MSI_RecordSetStringW( uirow
, 2, mt
->suffix
);
1491 msi_ui_actiondata( package
, szRegisterMIMEInfo
, uirow
);
1492 msiobj_release( &uirow
->hdr
);
1494 return ERROR_SUCCESS
;
1497 UINT
ACTION_UnregisterMIMEInfo( MSIPACKAGE
*package
)
1503 r
= load_classes_and_such( package
);
1504 if (r
!= ERROR_SUCCESS
)
1507 LIST_FOR_EACH_ENTRY( mime
, &package
->mimes
, MSIMIME
, entry
)
1512 if ((!mime
->Class
|| mime
->Class
->action
!= INSTALLSTATE_ABSENT
) &&
1513 mime
->Extension
->action
!= INSTALLSTATE_ABSENT
)
1515 TRACE("MIME %s not scheduled to be removed\n", debugstr_w(mime
->ContentType
));
1519 TRACE("Unregistering MIME type %s\n", debugstr_w(mime
->ContentType
));
1521 mime_key
= msi_alloc( (strlenW( szMIMEDatabase
) + strlenW( mime
->ContentType
) + 1) * sizeof(WCHAR
) );
1524 strcpyW( mime_key
, szMIMEDatabase
);
1525 strcatW( mime_key
, mime
->ContentType
);
1526 res
= RegDeleteKeyW( HKEY_CLASSES_ROOT
, mime_key
);
1527 if (res
!= ERROR_SUCCESS
)
1528 WARN("Failed to delete MIME key %d\n", res
);
1529 msi_free( mime_key
);
1532 uirow
= MSI_CreateRecord( 2 );
1533 MSI_RecordSetStringW( uirow
, 1, mime
->ContentType
);
1534 MSI_RecordSetStringW( uirow
, 2, mime
->suffix
);
1535 msi_ui_actiondata( package
, szUnregisterMIMEInfo
, uirow
);
1536 msiobj_release( &uirow
->hdr
);
1538 return ERROR_SUCCESS
;