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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* actions handled in this module
24 * RegisterExtensionInfo
26 * UnRegisterClassInfo (TODO)
27 * UnRegisterProgIdInfo (TODO)
28 * UnRegisterExtensionInfo (TODO)
29 * UnRegisterMIMEInfo (TODO)
38 #include "wine/debug.h"
41 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msi);
47 extern const WCHAR szRegisterClassInfo[];
48 extern const WCHAR szRegisterProgIdInfo[];
49 extern const WCHAR szRegisterExtensionInfo[];
50 extern const WCHAR szRegisterMIMEInfo[];
52 extern const WCHAR szUnregisterClassInfo[];
53 extern const WCHAR szUnregisterExtensionInfo[];
54 extern const WCHAR szUnregisterMIMEInfo[];
55 extern const WCHAR szUnregisterProgIdInfo[];
57 static MSIAPPID *load_appid( MSIPACKAGE* package, MSIRECORD *row )
62 /* fill in the data */
64 appid = msi_alloc_zero( sizeof(MSIAPPID) );
68 appid->AppID = msi_dup_record_field( row, 1 );
69 TRACE("loading appid %s\n", debugstr_w( appid->AppID ));
71 buffer = MSI_RecordGetString(row,2);
72 deformat_string( package, buffer, &appid->RemoteServerName );
74 appid->LocalServer = msi_dup_record_field(row,3);
75 appid->ServiceParameters = msi_dup_record_field(row,4);
76 appid->DllSurrogate = msi_dup_record_field(row,5);
78 appid->ActivateAtStorage = !MSI_RecordIsNull(row,6);
79 appid->RunAsInteractiveUser = !MSI_RecordIsNull(row,7);
81 list_add_tail( &package->appids, &appid->entry );
86 static MSIAPPID *load_given_appid( MSIPACKAGE *package, LPCWSTR name )
90 static const WCHAR ExecSeqQuery[] =
91 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
92 '`','A','p','p','I','d','`',' ','W','H','E','R','E',' ',
93 '`','A','p','p','I','d','`',' ','=',' ','\'','%','s','\'',0};
98 /* check for appids already loaded */
99 LIST_FOR_EACH_ENTRY( appid, &package->appids, MSIAPPID, entry )
101 if (lstrcmpiW( appid->AppID, name )==0)
103 TRACE("found appid %s %p\n", debugstr_w(name), appid);
108 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, name);
112 appid = load_appid(package, row);
113 msiobj_release(&row->hdr);
118 static MSIPROGID *load_given_progid(MSIPACKAGE *package, LPCWSTR progid);
119 static MSICLASS *load_given_class( MSIPACKAGE *package, LPCWSTR classid );
121 static MSIPROGID *load_progid( MSIPACKAGE* package, MSIRECORD *row )
126 /* fill in the data */
128 progid = msi_alloc_zero( sizeof(MSIPROGID) );
132 list_add_tail( &package->progids, &progid->entry );
134 progid->ProgID = msi_dup_record_field(row,1);
135 TRACE("loading progid %s\n",debugstr_w(progid->ProgID));
137 buffer = MSI_RecordGetString(row,2);
138 progid->Parent = load_given_progid(package,buffer);
139 if (progid->Parent == NULL && buffer)
140 FIXME("Unknown parent ProgID %s\n",debugstr_w(buffer));
142 buffer = MSI_RecordGetString(row,3);
143 progid->Class = load_given_class(package,buffer);
144 if (progid->Class == NULL && buffer)
145 FIXME("Unknown class %s\n",debugstr_w(buffer));
147 progid->Description = msi_dup_record_field(row,4);
149 if (!MSI_RecordIsNull(row,6))
151 INT icon_index = MSI_RecordGetInteger(row,6);
152 LPCWSTR FileName = MSI_RecordGetString(row,5);
154 static const WCHAR fmt[] = {'%','s',',','%','i',0};
156 FilePath = build_icon_path(package,FileName);
158 progid->IconPath = msi_alloc( (strlenW(FilePath)+10)* sizeof(WCHAR) );
160 sprintfW(progid->IconPath,fmt,FilePath,icon_index);
166 buffer = MSI_RecordGetString(row,5);
168 progid->IconPath = build_icon_path(package,buffer);
171 progid->CurVer = NULL;
172 progid->VersionInd = NULL;
174 /* if we have a parent then we may be that parents CurVer */
175 if (progid->Parent && progid->Parent != progid)
177 MSIPROGID *parent = progid->Parent;
179 while (parent->Parent && parent->Parent != parent)
180 parent = parent->Parent;
182 /* FIXME: need to determing if we are really the CurVer */
184 progid->CurVer = parent;
185 parent->VersionInd = progid;
191 static MSIPROGID *load_given_progid(MSIPACKAGE *package, LPCWSTR name)
195 static const WCHAR ExecSeqQuery[] =
196 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
197 '`','P','r','o','g','I','d','`',' ','W','H','E','R','E',' ',
198 '`','P','r','o','g','I','d','`',' ','=',' ','\'','%','s','\'',0};
203 /* check for progids already loaded */
204 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
206 if (strcmpiW( progid->ProgID,name )==0)
208 TRACE("found progid %s (%p)\n",debugstr_w(name), progid );
213 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, name );
217 progid = load_progid(package, row);
218 msiobj_release(&row->hdr);
223 static MSICLASS *load_class( MSIPACKAGE* package, MSIRECORD *row )
229 /* fill in the data */
231 cls = msi_alloc_zero( sizeof(MSICLASS) );
235 list_add_tail( &package->classes, &cls->entry );
237 cls->clsid = msi_dup_record_field( row, 1 );
238 TRACE("loading class %s\n",debugstr_w(cls->clsid));
239 cls->Context = msi_dup_record_field( row, 2 );
240 buffer = MSI_RecordGetString(row,3);
241 cls->Component = get_loaded_component(package, buffer);
243 cls->ProgIDText = msi_dup_record_field(row,4);
244 cls->ProgID = load_given_progid(package, cls->ProgIDText);
246 cls->Description = msi_dup_record_field(row,5);
248 buffer = MSI_RecordGetString(row,6);
250 cls->AppID = load_given_appid(package, buffer);
252 cls->FileTypeMask = msi_dup_record_field(row,7);
254 if (!MSI_RecordIsNull(row,9))
257 INT icon_index = MSI_RecordGetInteger(row,9);
258 LPCWSTR FileName = MSI_RecordGetString(row,8);
260 static const WCHAR fmt[] = {'%','s',',','%','i',0};
262 FilePath = build_icon_path(package,FileName);
264 cls->IconPath = msi_alloc( (strlenW(FilePath)+5)* sizeof(WCHAR) );
266 sprintfW(cls->IconPath,fmt,FilePath,icon_index);
272 buffer = MSI_RecordGetString(row,8);
274 cls->IconPath = build_icon_path(package,buffer);
277 if (!MSI_RecordIsNull(row,10))
279 i = MSI_RecordGetInteger(row,10);
280 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
282 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
283 static const WCHAR ole32[] = {'o','l','e','3','2','.','d','l','l',0};
288 cls->DefInprocHandler = strdupW(ole2);
291 cls->DefInprocHandler32 = strdupW(ole32);
294 cls->DefInprocHandler = strdupW(ole2);
295 cls->DefInprocHandler32 = strdupW(ole32);
301 cls->DefInprocHandler32 = msi_dup_record_field( row, 10);
302 reduce_to_longfilename(cls->DefInprocHandler32);
305 buffer = MSI_RecordGetString(row,11);
306 deformat_string(package,buffer,&cls->Argument);
308 buffer = MSI_RecordGetString(row,12);
309 cls->Feature = get_loaded_feature(package,buffer);
311 cls->Attributes = MSI_RecordGetInteger(row,13);
317 * the Class table has 3 primary keys. Generally it is only
318 * referenced through the first CLSID key. However when loading
319 * all of the classes we need to make sure we do not ignore rows
320 * with other Context and ComponentIndexs
322 static MSICLASS *load_given_class(MSIPACKAGE *package, LPCWSTR classid)
326 static const WCHAR ExecSeqQuery[] =
327 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
328 '`','C','l','a','s','s','`',' ','W','H','E','R','E',' ',
329 '`','C','L','S','I','D','`',' ','=',' ','\'','%','s','\'',0};
334 /* check for classes already loaded */
335 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
337 if (lstrcmpiW( cls->clsid, classid )==0)
339 TRACE("found class %s (%p)\n",debugstr_w(classid), cls);
344 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, classid);
348 cls = load_class(package, row);
349 msiobj_release(&row->hdr);
354 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR extension );
356 static MSIMIME *load_mime( MSIPACKAGE* package, MSIRECORD *row )
361 /* fill in the data */
363 mt = msi_alloc_zero( sizeof(MSIMIME) );
367 mt->ContentType = msi_dup_record_field( row, 1 );
368 TRACE("loading mime %s\n", debugstr_w(mt->ContentType));
370 buffer = MSI_RecordGetString( row, 2 );
371 mt->Extension = load_given_extension( package, buffer );
373 mt->clsid = msi_dup_record_field( row, 3 );
374 mt->Class = load_given_class( package, mt->clsid );
376 list_add_tail( &package->mimes, &mt->entry );
381 static MSIMIME *load_given_mime( MSIPACKAGE *package, LPCWSTR mime )
384 static const WCHAR ExecSeqQuery[] =
385 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
386 '`','M','I','M','E','`',' ','W','H','E','R','E',' ',
387 '`','C','o','n','t','e','n','t','T','y','p','e','`',' ','=',' ',
388 '\'','%','s','\'',0};
394 /* check for mime already loaded */
395 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
397 if (strcmpiW(mt->ContentType,mime)==0)
399 TRACE("found mime %s (%p)\n",debugstr_w(mime), mt);
404 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, mime);
408 mt = load_mime(package, row);
409 msiobj_release(&row->hdr);
414 static MSIEXTENSION *load_extension( MSIPACKAGE* package, MSIRECORD *row )
419 /* fill in the data */
421 ext = msi_alloc_zero( sizeof(MSIEXTENSION) );
425 list_init( &ext->verbs );
427 list_add_tail( &package->extensions, &ext->entry );
429 ext->Extension = msi_dup_record_field( row, 1 );
430 TRACE("loading extension %s\n", debugstr_w(ext->Extension));
432 buffer = MSI_RecordGetString( row, 2 );
433 ext->Component = get_loaded_component( package,buffer );
435 ext->ProgIDText = msi_dup_record_field( row, 3 );
436 ext->ProgID = load_given_progid( package, ext->ProgIDText );
438 buffer = MSI_RecordGetString( row, 4 );
439 ext->Mime = load_given_mime( package, buffer );
441 buffer = MSI_RecordGetString(row,5);
442 ext->Feature = get_loaded_feature( package, buffer );
448 * While the extension table has 2 primary keys, this function is only looking
449 * at the Extension key which is what is referenced as a forign key
451 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR name )
455 static const WCHAR ExecSeqQuery[] =
456 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
457 '`','E','x','t','e','n','s','i','o','n','`',' ',
458 'W','H','E','R','E',' ',
459 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ',
460 '\'','%','s','\'',0};
465 /* check for extensions already loaded */
466 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
468 if (strcmpiW( ext->Extension, name )==0)
470 TRACE("extension %s already loaded %p\n", debugstr_w(name), ext);
475 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, name );
479 ext = load_extension(package, row);
480 msiobj_release(&row->hdr);
485 static UINT iterate_load_verb(MSIRECORD *row, LPVOID param)
487 MSIPACKAGE* package = (MSIPACKAGE*)param;
490 MSIEXTENSION *extension;
492 buffer = MSI_RecordGetString(row,1);
493 extension = load_given_extension( package, buffer );
496 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer));
497 return ERROR_SUCCESS;
500 /* fill in the data */
502 verb = msi_alloc_zero( sizeof(MSIVERB) );
504 return ERROR_OUTOFMEMORY;
506 verb->Verb = msi_dup_record_field(row,2);
507 TRACE("loading verb %s\n",debugstr_w(verb->Verb));
508 verb->Sequence = MSI_RecordGetInteger(row,3);
510 buffer = MSI_RecordGetString(row,4);
511 deformat_string(package,buffer,&verb->Command);
513 buffer = MSI_RecordGetString(row,5);
514 deformat_string(package,buffer,&verb->Argument);
516 /* assosiate the verb with the correct extension */
517 list_add_tail( &extension->verbs, &verb->entry );
519 return ERROR_SUCCESS;
522 static UINT iterate_all_classes(MSIRECORD *rec, LPVOID param)
528 MSIPACKAGE* package =(MSIPACKAGE*)param;
532 clsid = MSI_RecordGetString(rec,1);
533 context = MSI_RecordGetString(rec,2);
534 buffer = MSI_RecordGetString(rec,3);
535 comp = get_loaded_component(package,buffer);
537 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
539 if (strcmpiW( clsid, cls->clsid ))
541 if (strcmpW( context, cls->Context ))
543 if (comp == cls->Component)
551 load_class(package, rec);
553 return ERROR_SUCCESS;
556 static VOID load_all_classes(MSIPACKAGE *package)
558 UINT rc = ERROR_SUCCESS;
561 static const WCHAR ExecSeqQuery[] =
562 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
563 '`','C','l','a','s','s','`',0};
565 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
566 if (rc != ERROR_SUCCESS)
569 rc = MSI_IterateRecords(view, NULL, iterate_all_classes, package);
570 msiobj_release(&view->hdr);
573 static UINT iterate_all_extensions(MSIRECORD *rec, LPVOID param)
578 MSIPACKAGE* package =(MSIPACKAGE*)param;
582 extension = MSI_RecordGetString(rec,1);
583 buffer = MSI_RecordGetString(rec,2);
584 comp = get_loaded_component(package,buffer);
586 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
588 if (strcmpiW(extension,ext->Extension))
590 if (comp == ext->Component)
598 load_extension(package, rec);
600 return ERROR_SUCCESS;
603 static VOID load_all_extensions(MSIPACKAGE *package)
605 UINT rc = ERROR_SUCCESS;
608 static const WCHAR ExecSeqQuery[] =
609 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
610 '`','E','x','t','e','n','s','i','o','n','`',0};
612 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
613 if (rc != ERROR_SUCCESS)
616 rc = MSI_IterateRecords(view, NULL, iterate_all_extensions, package);
617 msiobj_release(&view->hdr);
620 static UINT iterate_all_progids(MSIRECORD *rec, LPVOID param)
623 MSIPACKAGE* package =(MSIPACKAGE*)param;
625 buffer = MSI_RecordGetString(rec,1);
626 load_given_progid(package,buffer);
627 return ERROR_SUCCESS;
630 static VOID load_all_progids(MSIPACKAGE *package)
632 UINT rc = ERROR_SUCCESS;
635 static const WCHAR ExecSeqQuery[] =
636 {'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ',
637 'F','R','O','M',' ', '`','P','r','o','g','I','d','`',0};
639 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
640 if (rc != ERROR_SUCCESS)
643 rc = MSI_IterateRecords(view, NULL, iterate_all_progids, package);
644 msiobj_release(&view->hdr);
647 static VOID load_all_verbs(MSIPACKAGE *package)
649 UINT rc = ERROR_SUCCESS;
652 static const WCHAR ExecSeqQuery[] =
653 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
654 '`','V','e','r','b','`',0};
656 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
657 if (rc != ERROR_SUCCESS)
660 rc = MSI_IterateRecords(view, NULL, iterate_load_verb, package);
661 msiobj_release(&view->hdr);
664 static UINT iterate_all_mimes(MSIRECORD *rec, LPVOID param)
667 MSIPACKAGE* package =(MSIPACKAGE*)param;
669 buffer = MSI_RecordGetString(rec,1);
670 load_given_mime(package,buffer);
671 return ERROR_SUCCESS;
674 static VOID load_all_mimes(MSIPACKAGE *package)
676 UINT rc = ERROR_SUCCESS;
679 static const WCHAR ExecSeqQuery[] =
680 {'S','E','L','E','C','T',' ',
681 '`','C','o','n','t','e','n','t','T','y','p','e','`',
682 ' ','F','R','O','M',' ',
683 '`','M','I','M','E','`',0};
685 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
686 if (rc != ERROR_SUCCESS)
689 rc = MSI_IterateRecords(view, NULL, iterate_all_mimes, package);
690 msiobj_release(&view->hdr);
693 static void load_classes_and_such(MSIPACKAGE *package)
695 TRACE("Loading all the class info and related tables\n");
697 /* check if already loaded */
698 if (!list_empty( &package->classes ) ||
699 !list_empty( &package->mimes ) ||
700 !list_empty( &package->extensions ) ||
701 !list_empty( &package->progids ) )
704 load_all_classes(package);
705 load_all_extensions(package);
706 load_all_progids(package);
707 /* these loads must come after the other loads */
708 load_all_verbs(package);
709 load_all_mimes(package);
712 static void mark_progid_for_install( MSIPACKAGE* package, MSIPROGID *progid )
719 if (progid->InstallMe == TRUE)
722 progid->InstallMe = TRUE;
724 /* all children if this is a parent also install */
725 LIST_FOR_EACH_ENTRY( child, &package->progids, MSIPROGID, entry )
727 if (child->Parent == progid)
728 mark_progid_for_install( package, child );
732 static void mark_mime_for_install( MSIMIME *mime )
736 mime->InstallMe = TRUE;
739 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
741 DWORD len = value ? (lstrlenW(value) + 1) * sizeof (WCHAR) : 0;
742 return RegSetValueExW( hkey, name, 0, REG_SZ, (LPBYTE)value, len );
745 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
748 while (*p) p += lstrlenW(p) + 1;
749 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
750 (LPBYTE)value, (p + 1 - value) * sizeof(WCHAR) );
753 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
755 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
758 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
763 r = RegCreateKeyW( hkey, path, &hsubkey );
764 if (r != ERROR_SUCCESS)
766 r = msi_reg_set_val_str( hsubkey, name, val );
767 RegCloseKey( hsubkey );
771 static UINT register_appid(MSIAPPID *appid, LPCWSTR app )
773 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
774 static const WCHAR szRemoteServerName[] =
775 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
776 static const WCHAR szLocalService[] =
777 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
778 static const WCHAR szService[] =
779 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
780 static const WCHAR szDLL[] =
781 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
782 static const WCHAR szActivate[] =
783 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
784 static const WCHAR szY[] = {'Y',0};
785 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
786 static const WCHAR szUser[] =
787 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
791 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
792 RegCreateKeyW( hkey2, appid->AppID, &hkey3 );
794 msi_reg_set_val_str( hkey3, NULL, app );
796 if (appid->RemoteServerName)
797 msi_reg_set_val_str( hkey3, szRemoteServerName, appid->RemoteServerName );
799 if (appid->LocalServer)
800 msi_reg_set_val_str( hkey3, szLocalService, appid->LocalServer );
802 if (appid->ServiceParameters)
803 msi_reg_set_val_str( hkey3, szService, appid->ServiceParameters );
805 if (appid->DllSurrogate)
806 msi_reg_set_val_str( hkey3, szDLL, appid->DllSurrogate );
808 if (appid->ActivateAtStorage)
809 msi_reg_set_val_str( hkey3, szActivate, szY );
811 if (appid->RunAsInteractiveUser)
812 msi_reg_set_val_str( hkey3, szRunAs, szUser );
815 return ERROR_SUCCESS;
818 UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
821 * Again I am assuming the words, "Whose key file represents" when referring
822 * to a Component as to meaning that Components KeyPath file
827 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
828 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
829 static const WCHAR szVIProgID[] = { 'V','e','r','s','i','o','n','I','n','d','e','p','e','n','d','e','n','t','P','r','o','g','I','D',0 };
830 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
831 static const WCHAR szSpace[] = {' ',0};
832 static const WCHAR szInprocServer32[] = {'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
833 static const WCHAR szFileType_fmt[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
834 HKEY hkey,hkey2,hkey3;
835 BOOL install_on_demand = FALSE;
838 load_classes_and_such(package);
839 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
840 if (rc != ERROR_SUCCESS)
841 return ERROR_FUNCTION_FAILED;
843 /* install_on_demand should be set if OLE supports install on demand OLE
844 * servers. For now i am defaulting to FALSE because i do not know how to
845 * check, and i am told our builtin OLE does not support it
848 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
856 comp = cls->Component;
860 feature = cls->Feature;
863 * yes. MSDN says that these are based on _Feature_ not on
864 * Component. So verify the feature is to be installed
866 if ((!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL )) &&
867 !(install_on_demand &&
868 ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED )))
870 TRACE("Skipping class %s reg due to disabled feature %s\n",
871 debugstr_w(cls->clsid),
872 debugstr_w(feature->Feature));
877 TRACE("Registering class %s (%p)\n", debugstr_w(cls->clsid), cls);
879 cls->Installed = TRUE;
880 mark_progid_for_install( package, cls->ProgID );
882 RegCreateKeyW( hkey, cls->clsid, &hkey2 );
884 if (cls->Description)
885 msi_reg_set_val_str( hkey2, NULL, cls->Description );
887 RegCreateKeyW( hkey2, cls->Context, &hkey3 );
888 file = get_loaded_file( package, comp->KeyPath );
891 /* the context server is a short path name
892 * except for if it is InprocServer32...
894 if (strcmpiW( cls->Context, szInprocServer32 )!=0)
896 sz = GetShortPathNameW( file->TargetPath, NULL, 0 );
899 ERR("Unable to find short path for CLSID COM Server\n");
904 size = sz * sizeof(WCHAR);
908 size += strlenW(cls->Argument) * sizeof(WCHAR);
909 size += sizeof(WCHAR);
912 argument = msi_alloc( size + sizeof(WCHAR));
913 GetShortPathNameW( file->TargetPath, argument, sz );
917 strcatW(argument,szSpace);
918 strcatW( argument, cls->Argument );
924 size = lstrlenW( file->TargetPath ) * sizeof(WCHAR);
928 size += strlenW(cls->Argument) * sizeof(WCHAR);
929 size += sizeof(WCHAR);
932 argument = msi_alloc( size + sizeof(WCHAR));
933 strcpyW( argument, file->TargetPath );
937 strcatW(argument,szSpace);
938 strcatW( argument, cls->Argument );
944 msi_reg_set_val_str( hkey3, NULL, argument );
950 if (cls->ProgID || cls->ProgIDText)
955 progid = cls->ProgID->ProgID;
957 progid = cls->ProgIDText;
959 msi_reg_set_subkey_val( hkey2, szProgID, NULL, progid );
961 if (cls->ProgID && cls->ProgID->VersionInd)
963 msi_reg_set_subkey_val( hkey2, szVIProgID, NULL,
964 cls->ProgID->VersionInd->ProgID );
970 MSIAPPID *appid = cls->AppID;
972 msi_reg_set_val_str( hkey2, szAppID, appid->AppID );
974 register_appid( appid, cls->Description );
979 static const WCHAR szDefaultIcon[] =
980 {'D','e','f','a','u','l','t','I','c','o','n',0};
982 msi_reg_set_subkey_val( hkey2, szDefaultIcon, NULL, cls->IconPath );
985 if (cls->DefInprocHandler)
987 static const WCHAR szInproc[] =
988 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
990 msi_reg_set_subkey_val( hkey2, szInproc, NULL, cls->DefInprocHandler );
993 if (cls->DefInprocHandler32)
995 static const WCHAR szInproc32[] =
996 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',0};
998 msi_reg_set_subkey_val( hkey2, szInproc32, NULL, cls->DefInprocHandler32 );
1003 /* if there is a FileTypeMask, register the FileType */
1004 if (cls->FileTypeMask)
1009 ptr = cls->FileTypeMask;
1012 ptr2 = strchrW(ptr,';');
1015 keyname = msi_alloc( (strlenW(szFileType_fmt) + strlenW(cls->clsid) + 4) * sizeof(WCHAR));
1016 sprintfW( keyname, szFileType_fmt, cls->clsid, index );
1018 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, ptr );
1030 uirow = MSI_CreateRecord(1);
1032 MSI_RecordSetStringW( uirow, 1, cls->clsid );
1033 ui_actiondata(package,szRegisterClassInfo,uirow);
1034 msiobj_release(&uirow->hdr);
1041 static LPCWSTR get_clsid_of_progid( MSIPROGID *progid )
1046 return progid->Class->clsid;
1047 progid = progid->Parent;
1052 static UINT register_progid( MSIPROGID* progid )
1054 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
1055 static const WCHAR szDefaultIcon[] =
1056 {'D','e','f','a','u','l','t','I','c','o','n',0};
1057 static const WCHAR szCurVer[] =
1058 {'C','u','r','V','e','r',0};
1062 rc = RegCreateKeyW( HKEY_CLASSES_ROOT, progid->ProgID, &hkey );
1063 if (rc == ERROR_SUCCESS)
1065 LPCWSTR clsid = get_clsid_of_progid( progid );
1068 msi_reg_set_subkey_val( hkey, szCLSID, NULL, clsid );
1070 ERR("%s has no class\n", debugstr_w( progid->ProgID ) );
1072 if (progid->Description)
1073 msi_reg_set_val_str( hkey, NULL, progid->Description );
1075 if (progid->IconPath)
1076 msi_reg_set_subkey_val( hkey, szDefaultIcon, NULL, progid->IconPath );
1078 /* write out the current version */
1080 msi_reg_set_subkey_val( hkey, szCurVer, NULL, progid->CurVer->ProgID );
1085 ERR("failed to create key %s\n", debugstr_w( progid->ProgID ) );
1090 UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
1095 load_classes_and_such(package);
1097 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
1099 /* check if this progid is to be installed */
1100 if (progid->Class && progid->Class->Installed)
1101 progid->InstallMe = TRUE;
1103 if (!progid->InstallMe)
1105 TRACE("progid %s not scheduled to be installed\n",
1106 debugstr_w(progid->ProgID));
1110 TRACE("Registering progid %s\n", debugstr_w(progid->ProgID));
1112 register_progid( progid );
1114 uirow = MSI_CreateRecord( 1 );
1115 MSI_RecordSetStringW( uirow, 1, progid->ProgID );
1116 ui_actiondata( package, szRegisterProgIdInfo, uirow );
1117 msiobj_release( &uirow->hdr );
1120 return ERROR_SUCCESS;
1123 static UINT register_verb(MSIPACKAGE *package, LPCWSTR progid,
1124 MSICOMPONENT* component, MSIEXTENSION* extension,
1125 MSIVERB* verb, INT* Sequence )
1129 static const WCHAR szShell[] = {'s','h','e','l','l',0};
1130 static const WCHAR szCommand[] = {'c','o','m','m','a','n','d',0};
1131 static const WCHAR fmt[] = {'\"','%','s','\"',' ','%','s',0};
1132 static const WCHAR fmt2[] = {'\"','%','s','\"',0};
1137 keyname = build_directory_name(4, progid, szShell, verb->Verb, szCommand);
1139 TRACE("Making Key %s\n",debugstr_w(keyname));
1140 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
1141 size = strlenW(component->FullKeypath);
1143 size += strlenW(verb->Argument);
1146 command = msi_alloc(size * sizeof (WCHAR));
1148 sprintfW(command, fmt, component->FullKeypath, verb->Argument);
1150 sprintfW(command, fmt2, component->FullKeypath);
1152 msi_reg_set_val_str( key, NULL, command );
1155 advertise = create_component_advertise_string(package, component,
1156 extension->Feature->Feature);
1158 size = strlenW(advertise);
1161 size += strlenW(verb->Argument);
1164 command = msi_alloc(size * sizeof (WCHAR));
1165 memset(command,0,size*sizeof(WCHAR));
1167 strcpyW(command,advertise);
1170 static const WCHAR szSpace[] = {' ',0};
1171 strcatW(command,szSpace);
1172 strcatW(command,verb->Argument);
1175 msi_reg_set_val_multi_str( key, szCommand, command );
1179 msi_free(advertise);
1184 keyname = build_directory_name(3, progid, szShell, verb->Verb);
1185 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, verb->Command );
1189 if (verb->Sequence != MSI_NULL_INTEGER)
1191 if (*Sequence == MSI_NULL_INTEGER || verb->Sequence < *Sequence)
1193 *Sequence = verb->Sequence;
1194 keyname = build_directory_name(2, progid, szShell);
1195 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, verb->Verb );
1199 return ERROR_SUCCESS;
1202 UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
1204 static const WCHAR szContentType[] =
1205 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
1209 BOOL install_on_demand = TRUE;
1211 load_classes_and_such(package);
1213 /* We need to set install_on_demand based on if the shell handles advertised
1214 * shortcuts and the like. Because Mike McCormack is working on this i am
1215 * going to default to TRUE
1218 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
1221 MSIFEATURE *feature;
1223 if (!ext->Component)
1226 feature = ext->Feature;
1229 * yes. MSDN says that these are based on _Feature_ not on
1230 * Component. So verify the feature is to be installed
1232 if ((!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL )) &&
1233 !(install_on_demand &&
1234 ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED )))
1236 TRACE("Skipping extension %s reg due to disabled feature %s\n",
1237 debugstr_w(ext->Extension), debugstr_w(feature->Feature));
1242 TRACE("Registering extension %s (%p)\n", debugstr_w(ext->Extension), ext);
1244 ext->Installed = TRUE;
1246 /* this is only registered if the extension has at least 1 verb
1249 if (ext->ProgID && !list_empty( &ext->verbs ) )
1250 mark_progid_for_install( package, ext->ProgID );
1252 mark_mime_for_install(ext->Mime);
1254 extension = msi_alloc( (lstrlenW( ext->Extension ) + 2)*sizeof(WCHAR) );
1256 lstrcpyW(extension+1,ext->Extension);
1258 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
1259 msi_free( extension );
1262 msi_reg_set_val_str( hkey, szContentType, ext->Mime->ContentType );
1264 if (ext->ProgID || ext->ProgIDText)
1266 static const WCHAR szSN[] =
1267 {'\\','S','h','e','l','l','N','e','w',0};
1272 INT Sequence = MSI_NULL_INTEGER;
1275 progid = ext->ProgID->ProgID;
1277 progid = ext->ProgIDText;
1279 msi_reg_set_val_str( hkey, NULL, progid );
1281 newkey = msi_alloc( (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
1283 strcpyW(newkey,progid);
1284 strcatW(newkey,szSN);
1285 RegCreateKeyW(hkey,newkey,&hkey2);
1290 /* do all the verbs */
1291 LIST_FOR_EACH_ENTRY( verb, &ext->verbs, MSIVERB, entry )
1293 register_verb( package, progid, ext->Component,
1294 ext, verb, &Sequence);
1300 uirow = MSI_CreateRecord(1);
1301 MSI_RecordSetStringW( uirow, 1, ext->Extension );
1302 ui_actiondata(package,szRegisterExtensionInfo,uirow);
1303 msiobj_release(&uirow->hdr);
1306 return ERROR_SUCCESS;
1309 UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
1311 static const WCHAR szExten[] =
1312 {'E','x','t','e','n','s','i','o','n',0 };
1316 load_classes_and_such(package);
1318 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
1323 static const WCHAR fmt[] =
1324 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
1325 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
1329 * check if the MIME is to be installed. Either as requesed by an
1330 * extension or Class
1332 mt->InstallMe = (mt->InstallMe ||
1333 (mt->Class && mt->Class->Installed) ||
1334 (mt->Extension && mt->Extension->Installed));
1338 TRACE("MIME %s not scheduled to be installed\n",
1339 debugstr_w(mt->ContentType));
1343 mime = mt->ContentType;
1344 exten = mt->Extension->Extension;
1346 extension = msi_alloc( (lstrlenW( exten ) + 2)*sizeof(WCHAR) );
1348 lstrcpyW(extension+1,exten);
1350 key = msi_alloc( (strlenW(mime)+strlenW(fmt)+1) * sizeof(WCHAR) );
1351 sprintfW(key,fmt,mime);
1352 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, key, szExten, extension );
1354 msi_free(extension);
1358 FIXME("Handle non null for field 3\n");
1360 uirow = MSI_CreateRecord(2);
1361 MSI_RecordSetStringW(uirow,1,mt->ContentType);
1362 MSI_RecordSetStringW(uirow,2,exten);
1363 ui_actiondata(package,szRegisterMIMEInfo,uirow);
1364 msiobj_release(&uirow->hdr);
1367 return ERROR_SUCCESS;