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 )
63 /* fill in the data */
65 appid = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MSIAPPID) );
70 MSI_RecordGetStringW(row, 1, appid->AppID, &sz);
71 TRACE("loading appid %s\n", debugstr_w( appid->AppID ));
73 buffer = MSI_RecordGetString(row,2);
74 deformat_string( package, buffer, &appid->RemoteServerName );
76 appid->LocalServer = load_dynamic_stringW(row,3);
77 appid->ServiceParameters = load_dynamic_stringW(row,4);
78 appid->DllSurrogate = load_dynamic_stringW(row,5);
80 appid->ActivateAtStorage = !MSI_RecordIsNull(row,6);
81 appid->RunAsInteractiveUser = !MSI_RecordIsNull(row,7);
83 list_add_tail( &package->appids, &appid->entry );
88 static MSIAPPID *load_given_appid( MSIPACKAGE *package, LPCWSTR name )
92 static const WCHAR ExecSeqQuery[] =
93 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
94 '`','A','p','p','I','d','`',' ','W','H','E','R','E',' ',
95 '`','A','p','p','I','d','`',' ','=',' ','\'','%','s','\'',0};
100 /* check for appids already loaded */
101 LIST_FOR_EACH_ENTRY( appid, &package->appids, MSIAPPID, entry )
103 if (lstrcmpiW( appid->AppID, name )==0)
105 TRACE("found appid %s %p\n", debugstr_w(name), appid);
110 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, name);
114 appid = load_appid(package, row);
115 msiobj_release(&row->hdr);
120 static MSIPROGID *load_given_progid(MSIPACKAGE *package, LPCWSTR progid);
121 static MSICLASS *load_given_class( MSIPACKAGE *package, LPCWSTR classid );
123 static MSIPROGID *load_progid( MSIPACKAGE* package, MSIRECORD *row )
128 /* fill in the data */
130 progid = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MSIPROGID) );
134 list_add_tail( &package->progids, &progid->entry );
136 progid->ProgID = load_dynamic_stringW(row,1);
137 TRACE("loading progid %s\n",debugstr_w(progid->ProgID));
139 buffer = MSI_RecordGetString(row,2);
140 progid->Parent = load_given_progid(package,buffer);
141 if (progid->Parent == NULL && buffer)
142 FIXME("Unknown parent ProgID %s\n",debugstr_w(buffer));
144 buffer = MSI_RecordGetString(row,3);
145 progid->Class = load_given_class(package,buffer);
146 if (progid->Class == NULL && buffer)
147 FIXME("Unknown class %s\n",debugstr_w(buffer));
149 progid->Description = load_dynamic_stringW(row,4);
151 if (!MSI_RecordIsNull(row,6))
153 INT icon_index = MSI_RecordGetInteger(row,6);
154 LPWSTR FileName = load_dynamic_stringW(row,5);
156 static const WCHAR fmt[] = {'%','s',',','%','i',0};
158 build_icon_path(package,FileName,&FilePath);
161 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+10)*
164 sprintfW(progid->IconPath,fmt,FilePath,icon_index);
166 HeapFree(GetProcessHeap(),0,FilePath);
167 HeapFree(GetProcessHeap(),0,FileName);
171 buffer = MSI_RecordGetString(row,5);
173 build_icon_path(package,buffer,&(progid->IconPath));
176 progid->CurVer = NULL;
177 progid->VersionInd = NULL;
179 /* if we have a parent then we may be that parents CurVer */
180 if (progid->Parent && progid->Parent != progid)
182 MSIPROGID *parent = progid->Parent;
184 while (parent->Parent && parent->Parent != parent)
185 parent = parent->Parent;
187 FIXME("need to determing if we are really the CurVer\n");
189 progid->CurVer = parent;
190 parent->VersionInd = progid;
196 static MSIPROGID *load_given_progid(MSIPACKAGE *package, LPCWSTR name)
200 static const WCHAR ExecSeqQuery[] =
201 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
202 '`','P','r','o','g','I','d','`',' ','W','H','E','R','E',' ',
203 '`','P','r','o','g','I','d','`',' ','=',' ','\'','%','s','\'',0};
208 /* check for progids already loaded */
209 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
211 if (strcmpiW( progid->ProgID,name )==0)
213 TRACE("found progid %s (%p)\n",debugstr_w(name), progid );
218 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, name );
222 progid = load_progid(package, row);
223 msiobj_release(&row->hdr);
228 static MSICLASS *load_class( MSIPACKAGE* package, MSIRECORD *row )
234 /* fill in the data */
236 cls = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MSICLASS) );
240 list_add_tail( &package->classes, &cls->entry );
242 sz = IDENTIFIER_SIZE;
243 MSI_RecordGetStringW(row, 1, cls->CLSID, &sz);
244 TRACE("loading class %s\n",debugstr_w(cls->CLSID));
245 sz = IDENTIFIER_SIZE;
246 MSI_RecordGetStringW(row, 2, cls->Context, &sz);
247 buffer = MSI_RecordGetString(row,3);
248 cls->Component = get_loaded_component(package, buffer);
250 cls->ProgIDText = load_dynamic_stringW(row,4);
251 cls->ProgID = load_given_progid(package, cls->ProgIDText);
253 cls->Description = load_dynamic_stringW(row,5);
255 buffer = MSI_RecordGetString(row,6);
257 cls->AppID = load_given_appid(package, buffer);
259 cls->FileTypeMask = load_dynamic_stringW(row,7);
261 if (!MSI_RecordIsNull(row,9))
264 INT icon_index = MSI_RecordGetInteger(row,9);
265 LPWSTR FileName = load_dynamic_stringW(row,8);
267 static const WCHAR fmt[] = {'%','s',',','%','i',0};
269 build_icon_path(package,FileName,&FilePath);
272 HeapAlloc(GetProcessHeap(),0,(strlenW(FilePath)+5)*
275 sprintfW(cls->IconPath,fmt,FilePath,icon_index);
277 HeapFree(GetProcessHeap(),0,FilePath);
278 HeapFree(GetProcessHeap(),0,FileName);
282 buffer = MSI_RecordGetString(row,8);
284 build_icon_path(package,buffer,&(cls->IconPath));
287 if (!MSI_RecordIsNull(row,10))
289 i = MSI_RecordGetInteger(row,10);
290 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
292 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
293 static const WCHAR ole32[] = {'o','l','e','3','2','.','d','l','l',0};
298 cls->DefInprocHandler = strdupW(ole2);
301 cls->DefInprocHandler32 = strdupW(ole32);
304 cls->DefInprocHandler = strdupW(ole2);
305 cls->DefInprocHandler32 = strdupW(ole32);
311 cls->DefInprocHandler32 = load_dynamic_stringW(
313 reduce_to_longfilename(cls->DefInprocHandler32);
316 buffer = MSI_RecordGetString(row,11);
317 deformat_string(package,buffer,&cls->Argument);
319 buffer = MSI_RecordGetString(row,12);
320 cls->Feature = get_loaded_feature(package,buffer);
322 cls->Attributes = MSI_RecordGetInteger(row,13);
328 * the Class table has 3 primary keys. Generally it is only
329 * referenced through the first CLSID key. However when loading
330 * all of the classes we need to make sure we do not ignore rows
331 * with other Context and ComponentIndexs
333 static MSICLASS *load_given_class(MSIPACKAGE *package, LPCWSTR classid)
337 static const WCHAR ExecSeqQuery[] =
338 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
339 '`','C','l','a','s','s','`',' ','W','H','E','R','E',' ',
340 '`','C','L','S','I','D','`',' ','=',' ','\'','%','s','\'',0};
345 /* check for classes already loaded */
346 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
348 if (lstrcmpiW( cls->CLSID, classid )==0)
350 TRACE("found class %s (%p)\n",debugstr_w(classid), cls);
355 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, classid);
359 cls = load_class(package, row);
360 msiobj_release(&row->hdr);
365 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR extension );
367 static MSIMIME *load_mime( MSIPACKAGE* package, MSIRECORD *row )
373 /* fill in the data */
375 mt = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MSIMIME) );
379 mt->ContentType = load_dynamic_stringW( row, 1 );
380 TRACE("loading mime %s\n", debugstr_w(mt->ContentType));
382 buffer = MSI_RecordGetString( row, 2 );
383 mt->Extension = load_given_extension( package, buffer );
385 sz = IDENTIFIER_SIZE;
386 MSI_RecordGetStringW( row, 3, mt->CLSID, &sz );
387 mt->Class = load_given_class( package, mt->CLSID );
389 list_add_tail( &package->mimes, &mt->entry );
394 static MSIMIME *load_given_mime( MSIPACKAGE *package, LPCWSTR mime )
397 static const WCHAR ExecSeqQuery[] =
398 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
399 '`','M','I','M','E','`',' ','W','H','E','R','E',' ',
400 '`','C','o','n','t','e','n','t','T','y','p','e','`',' ','=',' ',
401 '\'','%','s','\'',0};
407 /* check for mime already loaded */
408 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
410 if (strcmpiW(mt->ContentType,mime)==0)
412 TRACE("found mime %s (%p)\n",debugstr_w(mime), mt);
417 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, mime);
421 mt = load_mime(package, row);
422 msiobj_release(&row->hdr);
427 static MSIEXTENSION *load_extension( MSIPACKAGE* package, MSIRECORD *row )
432 /* fill in the data */
434 ext = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MSIEXTENSION) );
438 list_init( &ext->verbs );
440 list_add_tail( &package->extensions, &ext->entry );
442 ext->Extension = load_dynamic_stringW( row, 1 );
443 TRACE("loading extension %s\n", debugstr_w(ext->Extension));
445 buffer = MSI_RecordGetString( row, 2 );
446 ext->Component = get_loaded_component( package,buffer );
448 ext->ProgIDText = load_dynamic_stringW( row, 3 );
449 ext->ProgID = load_given_progid( package, ext->ProgIDText );
451 buffer = MSI_RecordGetString( row, 4 );
452 ext->Mime = load_given_mime( package, buffer );
454 buffer = MSI_RecordGetString(row,5);
455 ext->Feature = get_loaded_feature( package, buffer );
461 * While the extension table has 2 primary keys, this function is only looking
462 * at the Extension key which is what is referenced as a forign key
464 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR name )
468 static const WCHAR ExecSeqQuery[] =
469 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
470 '`','E','x','t','e','n','s','i','o','n','`',' ',
471 'W','H','E','R','E',' ',
472 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ',
473 '\'','%','s','\'',0};
478 /* check for extensions already loaded */
479 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
481 if (strcmpiW( ext->Extension, name )==0)
483 TRACE("extension %s already loaded %p\n", debugstr_w(name), ext);
488 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, name );
492 ext = load_extension(package, row);
493 msiobj_release(&row->hdr);
498 static UINT iterate_load_verb(MSIRECORD *row, LPVOID param)
500 MSIPACKAGE* package = (MSIPACKAGE*)param;
503 MSIEXTENSION *extension;
505 buffer = MSI_RecordGetString(row,1);
506 extension = load_given_extension( package, buffer );
509 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer));
510 return ERROR_SUCCESS;
513 /* fill in the data */
515 verb = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MSIVERB) );
517 return ERROR_OUTOFMEMORY;
519 verb->Verb = load_dynamic_stringW(row,2);
520 TRACE("loading verb %s\n",debugstr_w(verb->Verb));
521 verb->Sequence = MSI_RecordGetInteger(row,3);
523 buffer = MSI_RecordGetString(row,4);
524 deformat_string(package,buffer,&verb->Command);
526 buffer = MSI_RecordGetString(row,5);
527 deformat_string(package,buffer,&verb->Argument);
529 /* assosiate the verb with the correct extension */
530 list_add_tail( &extension->verbs, &verb->entry );
532 return ERROR_SUCCESS;
535 static UINT iterate_all_classes(MSIRECORD *rec, LPVOID param)
541 MSIPACKAGE* package =(MSIPACKAGE*)param;
545 clsid = MSI_RecordGetString(rec,1);
546 context = MSI_RecordGetString(rec,2);
547 buffer = MSI_RecordGetString(rec,3);
548 comp = get_loaded_component(package,buffer);
550 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
552 if (strcmpiW( clsid, cls->CLSID ))
554 if (strcmpW( context, cls->Context ))
556 if (comp == cls->Component)
564 load_class(package, rec);
566 return ERROR_SUCCESS;
569 static VOID load_all_classes(MSIPACKAGE *package)
571 UINT rc = ERROR_SUCCESS;
574 static const WCHAR ExecSeqQuery[] =
575 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
576 '`','C','l','a','s','s','`',0};
578 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
579 if (rc != ERROR_SUCCESS)
582 rc = MSI_IterateRecords(view, NULL, iterate_all_classes, package);
583 msiobj_release(&view->hdr);
586 static UINT iterate_all_extensions(MSIRECORD *rec, LPVOID param)
591 MSIPACKAGE* package =(MSIPACKAGE*)param;
595 extension = MSI_RecordGetString(rec,1);
596 buffer = MSI_RecordGetString(rec,2);
597 comp = get_loaded_component(package,buffer);
599 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
601 if (strcmpiW(extension,ext->Extension))
603 if (comp == ext->Component)
611 load_extension(package, rec);
613 return ERROR_SUCCESS;
616 static VOID load_all_extensions(MSIPACKAGE *package)
618 UINT rc = ERROR_SUCCESS;
621 static const WCHAR ExecSeqQuery[] =
622 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
623 '`','E','x','t','e','n','s','i','o','n','`',0};
625 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
626 if (rc != ERROR_SUCCESS)
629 rc = MSI_IterateRecords(view, NULL, iterate_all_extensions, package);
630 msiobj_release(&view->hdr);
633 static UINT iterate_all_progids(MSIRECORD *rec, LPVOID param)
636 MSIPACKAGE* package =(MSIPACKAGE*)param;
638 buffer = MSI_RecordGetString(rec,1);
639 load_given_progid(package,buffer);
640 return ERROR_SUCCESS;
643 static VOID load_all_progids(MSIPACKAGE *package)
645 UINT rc = ERROR_SUCCESS;
648 static const WCHAR ExecSeqQuery[] =
649 {'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ',
650 'F','R','O','M',' ', '`','P','r','o','g','I','d','`',0};
652 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
653 if (rc != ERROR_SUCCESS)
656 rc = MSI_IterateRecords(view, NULL, iterate_all_progids, package);
657 msiobj_release(&view->hdr);
660 static VOID load_all_verbs(MSIPACKAGE *package)
662 UINT rc = ERROR_SUCCESS;
665 static const WCHAR ExecSeqQuery[] =
666 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
667 '`','V','e','r','b','`',0};
669 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
670 if (rc != ERROR_SUCCESS)
673 rc = MSI_IterateRecords(view, NULL, iterate_load_verb, package);
674 msiobj_release(&view->hdr);
677 static UINT iterate_all_mimes(MSIRECORD *rec, LPVOID param)
680 MSIPACKAGE* package =(MSIPACKAGE*)param;
682 buffer = MSI_RecordGetString(rec,1);
683 load_given_mime(package,buffer);
684 return ERROR_SUCCESS;
687 static VOID load_all_mimes(MSIPACKAGE *package)
689 UINT rc = ERROR_SUCCESS;
692 static const WCHAR ExecSeqQuery[] =
693 {'S','E','L','E','C','T',' ',
694 '`','C','o','n','t','e','n','t','T','y','p','e','`',
695 ' ','F','R','O','M',' ',
696 '`','M','I','M','E','`',0};
698 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
699 if (rc != ERROR_SUCCESS)
702 rc = MSI_IterateRecords(view, NULL, iterate_all_mimes, package);
703 msiobj_release(&view->hdr);
706 static void load_classes_and_such(MSIPACKAGE *package)
708 TRACE("Loading all the class info and related tables\n");
710 /* check if already loaded */
711 if (!list_empty( &package->classes ) ||
712 !list_empty( &package->mimes ) ||
713 !list_empty( &package->extensions ) ||
714 !list_empty( &package->progids ) )
717 load_all_classes(package);
718 load_all_extensions(package);
719 load_all_progids(package);
720 /* these loads must come after the other loads */
721 load_all_verbs(package);
722 load_all_mimes(package);
725 static void mark_progid_for_install( MSIPACKAGE* package, MSIPROGID *progid )
732 if (progid->InstallMe == TRUE)
735 progid->InstallMe = TRUE;
737 /* all children if this is a parent also install */
738 LIST_FOR_EACH_ENTRY( child, &package->progids, MSIPROGID, entry )
740 if (child->Parent == progid)
741 mark_progid_for_install( package, child );
745 static void mark_mime_for_install( MSIMIME *mime )
749 mime->InstallMe = TRUE;
752 static UINT register_appid(MSIAPPID *appid, LPCWSTR app )
754 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
758 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
759 RegCreateKeyW( hkey2, appid->AppID, &hkey3 );
760 RegSetValueExW( hkey3, NULL, 0, REG_SZ,
761 (LPBYTE)app, (strlenW(app)+1)*sizeof(WCHAR) );
763 if (appid->RemoteServerName)
765 static const WCHAR szRemoteServerName[] =
766 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
768 size = (lstrlenW(appid->RemoteServerName)+1) * sizeof(WCHAR);
770 RegSetValueExW( hkey3, szRemoteServerName, 0, REG_SZ,
771 (LPBYTE)appid->RemoteServerName, size);
774 if (appid->LocalServer)
776 static const WCHAR szLocalService[] =
777 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
779 size = (lstrlenW(appid->LocalServer)+1) * sizeof(WCHAR);
781 RegSetValueExW( hkey3, szLocalService, 0, REG_SZ,
782 (LPBYTE)appid->LocalServer, size );
785 if (appid->ServiceParameters)
787 static const WCHAR szService[] =
788 {'S','e','r','v','i','c','e',
789 'P','a','r','a','m','e','t','e','r','s',0};
791 size = (lstrlenW(appid->ServiceParameters)+1) * sizeof(WCHAR);
792 RegSetValueExW( hkey3, szService, 0, REG_SZ,
793 (LPBYTE)appid->ServiceParameters, size );
796 if (appid->DllSurrogate)
798 static const WCHAR szDLL[] =
799 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
801 size = (lstrlenW(appid->DllSurrogate)+1) * sizeof(WCHAR);
802 RegSetValueExW( hkey3, szDLL, 0, REG_SZ,
803 (LPBYTE)appid->DllSurrogate, size );
806 if (appid->ActivateAtStorage)
808 static const WCHAR szActivate[] =
809 {'A','c','t','i','v','a','t','e','A','s',
810 'S','t','o','r','a','g','e',0};
811 static const WCHAR szY[] = {'Y',0};
813 RegSetValueExW( hkey3, szActivate, 0, REG_SZ,
814 (LPBYTE)szY, sizeof szY );
817 if (appid->RunAsInteractiveUser)
819 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
820 static const WCHAR szUser[] =
821 {'I','n','t','e','r','a','c','t','i','v','e',' ',
824 RegSetValueExW( hkey3, szRunAs, 0, REG_SZ,
825 (LPBYTE)szUser, sizeof szUser );
830 return ERROR_SUCCESS;
833 UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
836 * Again I am assuming the words, "Whose key file represents" when referring
837 * to a Component as to meaning that Components KeyPath file
842 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
843 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
844 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 };
845 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
846 static const WCHAR szSpace[] = {' ',0};
847 static const WCHAR szInprocServer32[] = {'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
848 static const WCHAR szFileType_fmt[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
849 HKEY hkey,hkey2,hkey3;
850 BOOL install_on_demand = FALSE;
854 return ERROR_INVALID_HANDLE;
856 load_classes_and_such(package);
857 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
858 if (rc != ERROR_SUCCESS)
859 return ERROR_FUNCTION_FAILED;
861 /* install_on_demand should be set if OLE supports install on demand OLE
862 * servers. For now i am defaulting to FALSE because i do not know how to
863 * check, and i am told our builtin OLE does not support it
866 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
874 comp = cls->Component;
878 feature = cls->Feature;
881 * yes. MSDN says that these are based on _Feature_ not on
882 * Component. So verify the feature is to be installed
884 if ((!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL )) &&
885 !(install_on_demand &&
886 ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED )))
888 TRACE("Skipping class %s reg due to disabled feature %s\n",
889 debugstr_w(cls->CLSID),
890 debugstr_w(feature->Feature));
895 TRACE("Registering class %s (%p)\n", debugstr_w(cls->CLSID), cls);
897 cls->Installed = TRUE;
898 mark_progid_for_install( package, cls->ProgID );
900 RegCreateKeyW( hkey, cls->CLSID, &hkey2 );
902 if (cls->Description)
903 RegSetValueExW( hkey2, NULL, 0, REG_SZ, (LPBYTE)cls->Description,
904 (strlenW(cls->Description)+1)*sizeof(WCHAR));
906 RegCreateKeyW( hkey2, cls->Context, &hkey3 );
907 file = get_loaded_file( package, comp->KeyPath );
910 /* the context server is a short path name
911 * except for if it is InprocServer32...
913 if (strcmpiW( cls->Context, szInprocServer32 )!=0)
916 sz = GetShortPathNameW( file->TargetPath, NULL, 0 );
919 ERR("Unable to find short path for CLSID COM Server\n");
924 size = sz * sizeof(WCHAR);
928 size += strlenW(cls->Argument) * sizeof(WCHAR);
929 size += sizeof(WCHAR);
932 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
933 GetShortPathNameW( file->TargetPath, argument, sz );
937 strcatW(argument,szSpace);
938 strcatW( argument, cls->Argument );
944 size = lstrlenW( file->TargetPath ) * sizeof(WCHAR);
948 size += strlenW(cls->Argument) * sizeof(WCHAR);
949 size += sizeof(WCHAR);
952 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
953 strcpyW( argument, file->TargetPath );
957 strcatW(argument,szSpace);
958 strcatW( argument, cls->Argument );
964 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPBYTE)argument, size);
965 HeapFree(GetProcessHeap(),0,argument);
970 if (cls->ProgID || cls->ProgIDText)
975 progid = cls->ProgID->ProgID;
977 progid = cls->ProgIDText;
979 RegCreateKeyW(hkey2,szProgID,&hkey3);
980 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPBYTE)progid,
981 (strlenW(progid)+1) *sizeof(WCHAR));
984 if (cls->ProgID && cls->ProgID->VersionInd)
986 LPWSTR viprogid = strdupW( cls->ProgID->VersionInd->ProgID );
987 RegCreateKeyW(hkey2,szVIProgID,&hkey3);
988 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPBYTE)viprogid,
989 (strlenW(viprogid)+1) *sizeof(WCHAR));
991 HeapFree(GetProcessHeap(), 0, viprogid);
997 MSIAPPID *appid = cls->AppID;
999 RegSetValueExW( hkey2, szAppID, 0, REG_SZ, (LPBYTE)appid->AppID,
1000 (lstrlenW(appid->AppID)+1)*sizeof(WCHAR) );
1002 register_appid( appid, cls->Description );
1007 static const WCHAR szDefaultIcon[] =
1008 {'D','e','f','a','u','l','t','I','c','o','n',0};
1010 RegCreateKeyW(hkey2,szDefaultIcon,&hkey3);
1012 RegSetValueExW( hkey3, NULL, 0, REG_SZ, (LPVOID)cls->IconPath,
1013 (strlenW(cls->IconPath)+1) * sizeof(WCHAR));
1018 if (cls->DefInprocHandler)
1020 static const WCHAR szInproc[] =
1021 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
1023 size = (strlenW(cls->DefInprocHandler) + 1) * sizeof(WCHAR);
1024 RegCreateKeyW(hkey2,szInproc,&hkey3);
1025 RegSetValueExW(hkey3,NULL,0,REG_SZ,
1026 (LPBYTE)cls->DefInprocHandler, size);
1030 if (cls->DefInprocHandler32)
1032 static const WCHAR szInproc32[] =
1033 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',
1035 size = (strlenW(cls->DefInprocHandler32) + 1) * sizeof(WCHAR);
1037 RegCreateKeyW(hkey2,szInproc32,&hkey3);
1038 RegSetValueExW(hkey3,NULL,0,REG_SZ,
1039 (LPBYTE)cls->DefInprocHandler32,size);
1045 /* if there is a FileTypeMask, register the FileType */
1046 if (cls->FileTypeMask)
1051 ptr = cls->FileTypeMask;
1054 ptr2 = strchrW(ptr,';');
1057 keyname = HeapAlloc(GetProcessHeap(),0,(strlenW(szFileType_fmt)+
1058 strlenW(cls->CLSID) + 4) * sizeof(WCHAR));
1059 sprintfW( keyname, szFileType_fmt, cls->CLSID, index );
1061 RegCreateKeyW(HKEY_CLASSES_ROOT,keyname,&hkey2);
1062 RegSetValueExW(hkey2,NULL,0,REG_SZ, (LPVOID)ptr,
1063 strlenW(ptr)*sizeof(WCHAR));
1065 HeapFree(GetProcessHeap(), 0, keyname);
1076 uirow = MSI_CreateRecord(1);
1078 MSI_RecordSetStringW( uirow, 1, cls->CLSID );
1079 ui_actiondata(package,szRegisterClassInfo,uirow);
1080 msiobj_release(&uirow->hdr);
1087 static UINT register_progid_base(MSIPACKAGE* package, MSIPROGID* progid,
1090 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
1091 static const WCHAR szDefaultIcon[] =
1092 {'D','e','f','a','u','l','t','I','c','o','n',0};
1095 RegCreateKeyW(HKEY_CLASSES_ROOT,progid->ProgID,&hkey);
1097 if (progid->Description)
1099 RegSetValueExW(hkey,NULL,0,REG_SZ,
1100 (LPVOID)progid->Description,
1101 (strlenW(progid->Description)+1) *
1107 RegCreateKeyW(hkey,szCLSID,&hkey2);
1108 RegSetValueExW( hkey2, NULL, 0, REG_SZ, (LPBYTE)progid->Class->CLSID,
1109 (strlenW(progid->Class->CLSID)+1) * sizeof(WCHAR) );
1112 strcpyW( clsid, progid->Class->CLSID );
1118 FIXME("progid (%s) with null classid\n", debugstr_w(progid->ProgID));
1121 if (progid->IconPath)
1123 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
1125 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
1126 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
1129 return ERROR_SUCCESS;
1132 static UINT register_progid(MSIPACKAGE *package, MSIPROGID* progid,
1135 UINT rc = ERROR_SUCCESS;
1137 if (progid->Parent == NULL)
1138 rc = register_progid_base(package, progid, clsid);
1143 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
1144 static const WCHAR szDefaultIcon[] =
1145 {'D','e','f','a','u','l','t','I','c','o','n',0};
1146 static const WCHAR szCurVer[] =
1147 {'C','u','r','V','e','r',0};
1149 /* check if already registered */
1150 RegCreateKeyExW(HKEY_CLASSES_ROOT, progid->ProgID, 0, NULL, 0,
1151 KEY_ALL_ACCESS, NULL, &hkey, &disp );
1152 if (disp == REG_OPENED_EXISTING_KEY)
1154 TRACE("Key already registered\n");
1159 TRACE("Registering Parent %s\n", debugstr_w(progid->Parent->ProgID) );
1160 rc = register_progid( package, progid->Parent, clsid );
1162 /* clsid is same as parent */
1163 RegCreateKeyW(hkey,szCLSID,&hkey2);
1164 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
1170 if (progid->Description)
1172 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid->Description,
1173 (strlenW(progid->Description)+1) * sizeof(WCHAR));
1176 if (progid->IconPath)
1178 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
1179 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
1180 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
1184 /* write out the current version */
1187 RegCreateKeyW(hkey,szCurVer,&hkey2);
1188 RegSetValueExW(hkey2,NULL,0,REG_SZ, (LPBYTE)progid->CurVer->ProgID,
1189 (strlenW(progid->CurVer->ProgID)+1) * sizeof(WCHAR));
1198 UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
1204 return ERROR_INVALID_HANDLE;
1206 load_classes_and_such(package);
1208 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
1210 WCHAR clsid[0x1000];
1212 /* check if this progid is to be installed */
1213 if (progid->Class && progid->Class->Installed)
1214 progid->InstallMe = TRUE;
1216 if (!progid->InstallMe)
1218 TRACE("progid %s not scheduled to be installed\n",
1219 debugstr_w(progid->ProgID));
1223 TRACE("Registering progid %s\n", debugstr_w(progid->ProgID));
1225 register_progid( package, progid, clsid );
1227 uirow = MSI_CreateRecord(1);
1228 MSI_RecordSetStringW( uirow, 1, progid->ProgID );
1229 ui_actiondata( package, szRegisterProgIdInfo, uirow );
1230 msiobj_release( &uirow->hdr );
1233 return ERROR_SUCCESS;
1236 static UINT register_verb(MSIPACKAGE *package, LPCWSTR progid,
1237 MSICOMPONENT* component, MSIEXTENSION* extension,
1238 MSIVERB* verb, INT* Sequence )
1242 static const WCHAR szShell[] = {'s','h','e','l','l',0};
1243 static const WCHAR szCommand[] = {'c','o','m','m','a','n','d',0};
1244 static const WCHAR fmt[] = {'\"','%','s','\"',' ','%','s',0};
1245 static const WCHAR fmt2[] = {'\"','%','s','\"',0};
1250 keyname = build_directory_name(4, progid, szShell, verb->Verb, szCommand);
1252 TRACE("Making Key %s\n",debugstr_w(keyname));
1253 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
1254 size = strlenW(component->FullKeypath);
1256 size += strlenW(verb->Argument);
1259 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
1261 sprintfW(command, fmt, component->FullKeypath, verb->Argument);
1263 sprintfW(command, fmt2, component->FullKeypath);
1265 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)command, (strlenW(command)+1)*
1267 HeapFree(GetProcessHeap(),0,command);
1269 advertise = create_component_advertise_string(package, component,
1270 extension->Feature->Feature);
1272 size = strlenW(advertise);
1275 size += strlenW(verb->Argument);
1278 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
1279 memset(command,0,size*sizeof(WCHAR));
1281 strcpyW(command,advertise);
1284 static const WCHAR szSpace[] = {' ',0};
1285 strcatW(command,szSpace);
1286 strcatW(command,verb->Argument);
1289 RegSetValueExW(key, szCommand, 0, REG_MULTI_SZ, (LPBYTE)command,
1290 (strlenW(command)+2)*sizeof(WCHAR));
1293 HeapFree(GetProcessHeap(),0,keyname);
1294 HeapFree(GetProcessHeap(),0,advertise);
1295 HeapFree(GetProcessHeap(),0,command);
1299 keyname = build_directory_name(3, progid, szShell, verb->Verb);
1300 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
1301 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Command,
1302 (strlenW(verb->Command)+1) *sizeof(WCHAR));
1304 HeapFree(GetProcessHeap(),0,keyname);
1307 if (verb->Sequence != MSI_NULL_INTEGER)
1309 if (*Sequence == MSI_NULL_INTEGER || verb->Sequence < *Sequence)
1311 *Sequence = verb->Sequence;
1312 keyname = build_directory_name(2, progid, szShell);
1313 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
1314 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Verb,
1315 (strlenW(verb->Verb)+1) *sizeof(WCHAR));
1317 HeapFree(GetProcessHeap(),0,keyname);
1320 return ERROR_SUCCESS;
1323 UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
1325 static const WCHAR szContentType[] =
1326 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
1330 BOOL install_on_demand = TRUE;
1333 return ERROR_INVALID_HANDLE;
1335 load_classes_and_such(package);
1337 /* We need to set install_on_demand based on if the shell handles advertised
1338 * shortcuts and the like. Because Mike McCormack is working on this i am
1339 * going to default to TRUE
1342 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
1345 MSIFEATURE *feature;
1347 if (!ext->Component)
1350 feature = ext->Feature;
1353 * yes. MSDN says that these are based on _Feature_ not on
1354 * Component. So verify the feature is to be installed
1356 if ((!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL )) &&
1357 !(install_on_demand &&
1358 ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED )))
1360 TRACE("Skipping extension %s reg due to disabled feature %s\n",
1361 debugstr_w(ext->Extension), debugstr_w(feature->Feature));
1366 TRACE("Registering extension %s (%p)\n", debugstr_w(ext->Extension), ext);
1368 ext->Installed = TRUE;
1370 /* this is only registered if the extension has at least 1 verb
1373 if (ext->ProgID && !list_empty( &ext->verbs ) )
1374 mark_progid_for_install( package, ext->ProgID );
1376 mark_mime_for_install(ext->Mime);
1378 extension = HeapAlloc( GetProcessHeap(), 0,
1379 (lstrlenW( ext->Extension ) + 2)*sizeof(WCHAR) );
1381 lstrcpyW(extension+1,ext->Extension);
1383 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
1384 HeapFree( GetProcessHeap(), 0, extension );
1388 RegSetValueExW(hkey,szContentType,0,REG_SZ,
1389 (LPBYTE)ext->Mime->ContentType,
1390 (strlenW(ext->Mime->ContentType)+1)*sizeof(WCHAR));
1393 if (ext->ProgID || ext->ProgIDText)
1395 static const WCHAR szSN[] =
1396 {'\\','S','h','e','l','l','N','e','w',0};
1401 INT Sequence = MSI_NULL_INTEGER;
1404 progid = ext->ProgID->ProgID;
1406 progid = ext->ProgIDText;
1408 RegSetValueExW( hkey, NULL, 0, REG_SZ, (LPBYTE)progid,
1409 (strlenW(progid)+1)*sizeof(WCHAR));
1411 newkey = HeapAlloc(GetProcessHeap(),0,
1412 (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
1414 strcpyW(newkey,progid);
1415 strcatW(newkey,szSN);
1416 RegCreateKeyW(hkey,newkey,&hkey2);
1419 HeapFree(GetProcessHeap(),0,newkey);
1421 /* do all the verbs */
1422 LIST_FOR_EACH_ENTRY( verb, &ext->verbs, MSIVERB, entry )
1424 register_verb( package, progid, ext->Component,
1425 ext, verb, &Sequence);
1431 uirow = MSI_CreateRecord(1);
1432 MSI_RecordSetStringW( uirow, 1, ext->Extension );
1433 ui_actiondata(package,szRegisterExtensionInfo,uirow);
1434 msiobj_release(&uirow->hdr);
1437 return ERROR_SUCCESS;
1440 UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
1442 static const WCHAR szExten[] =
1443 {'E','x','t','e','n','s','i','o','n',0 };
1449 return ERROR_INVALID_HANDLE;
1451 load_classes_and_such(package);
1453 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
1458 static const WCHAR fmt[] =
1459 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
1460 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
1464 * check if the MIME is to be installed. Either as requesed by an
1465 * extension or Class
1467 mt->InstallMe = (mt->InstallMe ||
1468 (mt->Class && mt->Class->Installed) ||
1469 (mt->Extension && mt->Extension->Installed));
1473 TRACE("MIME %s not scheduled to be installed\n",
1474 debugstr_w(mt->ContentType));
1478 mime = mt->ContentType;
1479 exten = mt->Extension->Extension;
1481 extension = HeapAlloc( GetProcessHeap(), 0,
1482 (lstrlenW( exten ) + 2)*sizeof(WCHAR) );
1484 lstrcpyW(extension+1,exten);
1486 key = HeapAlloc(GetProcessHeap(),0,(strlenW(mime)+strlenW(fmt)+1) *
1488 sprintfW(key,fmt,mime);
1489 RegCreateKeyW(HKEY_CLASSES_ROOT,key,&hkey);
1490 RegSetValueExW(hkey,szExten,0,REG_SZ,(LPBYTE)extension,
1491 (strlenW(extension)+1)*sizeof(WCHAR));
1493 HeapFree(GetProcessHeap(),0,extension);
1494 HeapFree(GetProcessHeap(),0,key);
1498 FIXME("Handle non null for field 3\n");
1503 uirow = MSI_CreateRecord(2);
1504 MSI_RecordSetStringW(uirow,1,mt->ContentType);
1505 MSI_RecordSetStringW(uirow,2,exten);
1506 ui_actiondata(package,szRegisterMIMEInfo,uirow);
1507 msiobj_release(&uirow->hdr);
1510 return ERROR_SUCCESS;