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 != progid)
185 parent = parent->Parent;
187 FIXME("BAD BAD need to determing if we are really the CurVer\n");
189 progid->CurVer = parent;
190 progid->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 )
433 /* fill in the data */
435 ext = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MSIEXTENSION) );
439 list_init( &ext->verbs );
441 list_add_tail( &package->extensions, &ext->entry );
444 MSI_RecordGetStringW( row, 1, ext->Extension, &sz );
445 TRACE("loading extension %s\n", debugstr_w(ext->Extension));
447 buffer = MSI_RecordGetString( row, 2 );
448 ext->Component = get_loaded_component( package,buffer );
450 ext->ProgIDText = load_dynamic_stringW( row, 3 );
451 ext->ProgID = load_given_progid( package, ext->ProgIDText );
453 buffer = MSI_RecordGetString( row, 4 );
454 ext->Mime = load_given_mime( package, buffer );
456 buffer = MSI_RecordGetString(row,5);
457 ext->Feature = get_loaded_feature( package, buffer );
463 * While the extension table has 2 primary keys, this function is only looking
464 * at the Extension key which is what is referenced as a forign key
466 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR name )
470 static const WCHAR ExecSeqQuery[] =
471 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
472 '`','E','x','t','e','n','s','i','o','n','`',' ',
473 'W','H','E','R','E',' ',
474 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ',
475 '\'','%','s','\'',0};
480 /* check for extensions already loaded */
481 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
483 if (strcmpiW( ext->Extension, name )==0)
485 TRACE("extension %s already loaded %p\n", debugstr_w(name), ext);
490 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, name );
494 ext = load_extension(package, row);
495 msiobj_release(&row->hdr);
500 static UINT iterate_load_verb(MSIRECORD *row, LPVOID param)
502 MSIPACKAGE* package = (MSIPACKAGE*)param;
505 MSIEXTENSION *extension;
507 buffer = MSI_RecordGetString(row,1);
508 extension = load_given_extension( package, buffer );
511 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer));
512 return ERROR_SUCCESS;
515 /* fill in the data */
517 verb = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MSIVERB) );
519 return ERROR_OUTOFMEMORY;
521 verb->Verb = load_dynamic_stringW(row,2);
522 TRACE("loading verb %s\n",debugstr_w(verb->Verb));
523 verb->Sequence = MSI_RecordGetInteger(row,3);
525 buffer = MSI_RecordGetString(row,4);
526 deformat_string(package,buffer,&verb->Command);
528 buffer = MSI_RecordGetString(row,5);
529 deformat_string(package,buffer,&verb->Argument);
531 /* assosiate the verb with the correct extension */
532 list_add_tail( &extension->verbs, &verb->entry );
534 return ERROR_SUCCESS;
537 static UINT iterate_all_classes(MSIRECORD *rec, LPVOID param)
543 MSIPACKAGE* package =(MSIPACKAGE*)param;
547 clsid = MSI_RecordGetString(rec,1);
548 context = MSI_RecordGetString(rec,2);
549 buffer = MSI_RecordGetString(rec,3);
550 comp = get_loaded_component(package,buffer);
552 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
554 if (strcmpiW( clsid, cls->CLSID ))
556 if (strcmpW( context, cls->Context ))
558 if (comp == cls->Component)
566 load_class(package, rec);
568 return ERROR_SUCCESS;
571 static VOID load_all_classes(MSIPACKAGE *package)
573 UINT rc = ERROR_SUCCESS;
576 static const WCHAR ExecSeqQuery[] =
577 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
578 '`','C','l','a','s','s','`',0};
580 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
581 if (rc != ERROR_SUCCESS)
584 rc = MSI_IterateRecords(view, NULL, iterate_all_classes, package);
585 msiobj_release(&view->hdr);
588 static UINT iterate_all_extensions(MSIRECORD *rec, LPVOID param)
593 MSIPACKAGE* package =(MSIPACKAGE*)param;
597 extension = MSI_RecordGetString(rec,1);
598 buffer = MSI_RecordGetString(rec,2);
599 comp = get_loaded_component(package,buffer);
601 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
603 if (strcmpiW(extension,ext->Extension))
605 if (comp == ext->Component)
613 load_extension(package, rec);
615 return ERROR_SUCCESS;
618 static VOID load_all_extensions(MSIPACKAGE *package)
620 UINT rc = ERROR_SUCCESS;
623 static const WCHAR ExecSeqQuery[] =
624 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
625 '`','E','x','t','e','n','s','i','o','n','`',0};
627 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
628 if (rc != ERROR_SUCCESS)
631 rc = MSI_IterateRecords(view, NULL, iterate_all_extensions, package);
632 msiobj_release(&view->hdr);
635 static UINT iterate_all_progids(MSIRECORD *rec, LPVOID param)
638 MSIPACKAGE* package =(MSIPACKAGE*)param;
640 buffer = MSI_RecordGetString(rec,1);
641 load_given_progid(package,buffer);
642 return ERROR_SUCCESS;
645 static VOID load_all_progids(MSIPACKAGE *package)
647 UINT rc = ERROR_SUCCESS;
650 static const WCHAR ExecSeqQuery[] =
651 {'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ',
652 'F','R','O','M',' ', '`','P','r','o','g','I','d','`',0};
654 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
655 if (rc != ERROR_SUCCESS)
658 rc = MSI_IterateRecords(view, NULL, iterate_all_progids, package);
659 msiobj_release(&view->hdr);
662 static VOID load_all_verbs(MSIPACKAGE *package)
664 UINT rc = ERROR_SUCCESS;
667 static const WCHAR ExecSeqQuery[] =
668 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
669 '`','V','e','r','b','`',0};
671 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
672 if (rc != ERROR_SUCCESS)
675 rc = MSI_IterateRecords(view, NULL, iterate_load_verb, package);
676 msiobj_release(&view->hdr);
679 static UINT iterate_all_mimes(MSIRECORD *rec, LPVOID param)
682 MSIPACKAGE* package =(MSIPACKAGE*)param;
684 buffer = MSI_RecordGetString(rec,1);
685 load_given_mime(package,buffer);
686 return ERROR_SUCCESS;
689 static VOID load_all_mimes(MSIPACKAGE *package)
691 UINT rc = ERROR_SUCCESS;
694 static const WCHAR ExecSeqQuery[] =
695 {'S','E','L','E','C','T',' ',
696 '`','C','o','n','t','e','n','t','T','y','p','e','`',
697 ' ','F','R','O','M',' ',
698 '`','M','I','M','E','`',0};
700 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
701 if (rc != ERROR_SUCCESS)
704 rc = MSI_IterateRecords(view, NULL, iterate_all_mimes, package);
705 msiobj_release(&view->hdr);
708 static void load_classes_and_such(MSIPACKAGE *package)
710 TRACE("Loading all the class info and related tables\n");
712 /* check if already loaded */
713 if (!list_empty( &package->classes ) ||
714 !list_empty( &package->mimes ) ||
715 !list_empty( &package->extensions ) ||
716 !list_empty( &package->progids ) )
719 load_all_classes(package);
720 load_all_extensions(package);
721 load_all_progids(package);
722 /* these loads must come after the other loads */
723 load_all_verbs(package);
724 load_all_mimes(package);
727 static void mark_progid_for_install( MSIPACKAGE* package, MSIPROGID *progid )
734 if (progid->InstallMe == TRUE)
737 progid->InstallMe = TRUE;
739 /* all children if this is a parent also install */
740 LIST_FOR_EACH_ENTRY( child, &package->progids, MSIPROGID, entry )
742 if (child->Parent == progid)
743 mark_progid_for_install( package, child );
747 static void mark_mime_for_install( MSIMIME *mime )
751 mime->InstallMe = TRUE;
754 static UINT register_appid(MSIAPPID *appid, LPCWSTR app )
756 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
760 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
761 RegCreateKeyW( hkey2, appid->AppID, &hkey3 );
762 RegSetValueExW( hkey3, NULL, 0, REG_SZ,
763 (LPBYTE)app, (strlenW(app)+1)*sizeof(WCHAR) );
765 if (appid->RemoteServerName)
767 static const WCHAR szRemoteServerName[] =
768 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
770 size = (lstrlenW(appid->RemoteServerName)+1) * sizeof(WCHAR);
772 RegSetValueExW( hkey3, szRemoteServerName, 0, REG_SZ,
773 (LPBYTE)appid->RemoteServerName, size);
776 if (appid->LocalServer)
778 static const WCHAR szLocalService[] =
779 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
781 size = (lstrlenW(appid->LocalServer)+1) * sizeof(WCHAR);
783 RegSetValueExW( hkey3, szLocalService, 0, REG_SZ,
784 (LPBYTE)appid->LocalServer, size );
787 if (appid->ServiceParameters)
789 static const WCHAR szService[] =
790 {'S','e','r','v','i','c','e',
791 'P','a','r','a','m','e','t','e','r','s',0};
793 size = (lstrlenW(appid->ServiceParameters)+1) * sizeof(WCHAR);
794 RegSetValueExW( hkey3, szService, 0, REG_SZ,
795 (LPBYTE)appid->ServiceParameters, size );
798 if (appid->DllSurrogate)
800 static const WCHAR szDLL[] =
801 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
803 size = (lstrlenW(appid->DllSurrogate)+1) * sizeof(WCHAR);
804 RegSetValueExW( hkey3, szDLL, 0, REG_SZ,
805 (LPBYTE)appid->DllSurrogate, size );
808 if (appid->ActivateAtStorage)
810 static const WCHAR szActivate[] =
811 {'A','c','t','i','v','a','t','e','A','s',
812 'S','t','o','r','a','g','e',0};
813 static const WCHAR szY[] = {'Y',0};
815 RegSetValueExW( hkey3, szActivate, 0, REG_SZ,
816 (LPBYTE)szY, sizeof szY );
819 if (appid->RunAsInteractiveUser)
821 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
822 static const WCHAR szUser[] =
823 {'I','n','t','e','r','a','c','t','i','v','e',' ',
826 RegSetValueExW( hkey3, szRunAs, 0, REG_SZ,
827 (LPBYTE)szUser, sizeof szUser );
832 return ERROR_SUCCESS;
835 UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
838 * Again I am assuming the words, "Whose key file represents" when referring
839 * to a Component as to meaning that Components KeyPath file
844 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
845 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
846 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 };
847 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
848 static const WCHAR szSpace[] = {' ',0};
849 static const WCHAR szInprocServer32[] = {'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
850 static const WCHAR szFileType_fmt[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
851 HKEY hkey,hkey2,hkey3;
852 BOOL install_on_demand = FALSE;
856 return ERROR_INVALID_HANDLE;
858 load_classes_and_such(package);
859 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
860 if (rc != ERROR_SUCCESS)
861 return ERROR_FUNCTION_FAILED;
863 /* install_on_demand should be set if OLE supports install on demand OLE
864 * servers. For now i am defaulting to FALSE because i do not know how to
865 * check, and i am told our builtin OLE does not support it
868 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
876 comp = cls->Component;
880 feature = cls->Feature;
883 * yes. MSDN says that these are based on _Feature_ not on
884 * Component. So verify the feature is to be installed
886 if ((!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL )) &&
887 !(install_on_demand &&
888 ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED )))
890 TRACE("Skipping class %s reg due to disabled feature %s\n",
891 debugstr_w(cls->CLSID),
892 debugstr_w(feature->Feature));
897 TRACE("Registering class %s (%p)\n", debugstr_w(cls->CLSID), cls);
899 cls->Installed = TRUE;
900 mark_progid_for_install( package, cls->ProgID );
902 RegCreateKeyW( hkey, cls->CLSID, &hkey2 );
904 if (cls->Description)
905 RegSetValueExW( hkey2, NULL, 0, REG_SZ, (LPBYTE)cls->Description,
906 (strlenW(cls->Description)+1)*sizeof(WCHAR));
908 RegCreateKeyW( hkey2, cls->Context, &hkey3 );
909 file = get_loaded_file( package, comp->KeyPath );
912 /* the context server is a short path name
913 * except for if it is InprocServer32...
915 if (strcmpiW( cls->Context, szInprocServer32 )!=0)
918 sz = GetShortPathNameW( file->TargetPath, NULL, 0 );
921 ERR("Unable to find short path for CLSID COM Server\n");
926 size = sz * sizeof(WCHAR);
930 size += strlenW(cls->Argument) * sizeof(WCHAR);
931 size += sizeof(WCHAR);
934 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
935 GetShortPathNameW( file->TargetPath, argument, sz );
939 strcatW(argument,szSpace);
940 strcatW( argument, cls->Argument );
946 size = lstrlenW( file->TargetPath ) * sizeof(WCHAR);
950 size += strlenW(cls->Argument) * sizeof(WCHAR);
951 size += sizeof(WCHAR);
954 argument = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));
955 strcpyW( argument, file->TargetPath );
959 strcatW(argument,szSpace);
960 strcatW( argument, cls->Argument );
966 RegSetValueExW(hkey3,NULL,0,REG_SZ, (LPBYTE)argument, size);
967 HeapFree(GetProcessHeap(),0,argument);
972 if (cls->ProgID || cls->ProgIDText)
977 progid = cls->ProgID->ProgID;
979 progid = cls->ProgIDText;
981 RegCreateKeyW(hkey2,szProgID,&hkey3);
982 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPBYTE)progid,
983 (strlenW(progid)+1) *sizeof(WCHAR));
986 if (cls->ProgID && cls->ProgID->VersionInd)
988 LPWSTR viprogid = strdupW( cls->ProgID->VersionInd->ProgID );
989 RegCreateKeyW(hkey2,szVIProgID,&hkey3);
990 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPBYTE)viprogid,
991 (strlenW(viprogid)+1) *sizeof(WCHAR));
993 HeapFree(GetProcessHeap(), 0, viprogid);
999 MSIAPPID *appid = cls->AppID;
1001 RegSetValueExW( hkey2, szAppID, 0, REG_SZ, (LPBYTE)appid->AppID,
1002 (lstrlenW(appid->AppID)+1)*sizeof(WCHAR) );
1004 register_appid( appid, cls->Description );
1009 static const WCHAR szDefaultIcon[] =
1010 {'D','e','f','a','u','l','t','I','c','o','n',0};
1012 RegCreateKeyW(hkey2,szDefaultIcon,&hkey3);
1014 RegSetValueExW( hkey3, NULL, 0, REG_SZ, (LPVOID)cls->IconPath,
1015 (strlenW(cls->IconPath)+1) * sizeof(WCHAR));
1020 if (cls->DefInprocHandler)
1022 static const WCHAR szInproc[] =
1023 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
1025 size = (strlenW(cls->DefInprocHandler) + 1) * sizeof(WCHAR);
1026 RegCreateKeyW(hkey2,szInproc,&hkey3);
1027 RegSetValueExW(hkey3,NULL,0,REG_SZ,
1028 (LPBYTE)cls->DefInprocHandler, size);
1032 if (cls->DefInprocHandler32)
1034 static const WCHAR szInproc32[] =
1035 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',
1037 size = (strlenW(cls->DefInprocHandler32) + 1) * sizeof(WCHAR);
1039 RegCreateKeyW(hkey2,szInproc32,&hkey3);
1040 RegSetValueExW(hkey3,NULL,0,REG_SZ,
1041 (LPBYTE)cls->DefInprocHandler32,size);
1047 /* if there is a FileTypeMask, register the FileType */
1048 if (cls->FileTypeMask)
1053 ptr = cls->FileTypeMask;
1056 ptr2 = strchrW(ptr,';');
1059 keyname = HeapAlloc(GetProcessHeap(),0,(strlenW(szFileType_fmt)+
1060 strlenW(cls->CLSID) + 4) * sizeof(WCHAR));
1061 sprintfW( keyname, szFileType_fmt, cls->CLSID, index );
1063 RegCreateKeyW(HKEY_CLASSES_ROOT,keyname,&hkey2);
1064 RegSetValueExW(hkey2,NULL,0,REG_SZ, (LPVOID)ptr,
1065 strlenW(ptr)*sizeof(WCHAR));
1067 HeapFree(GetProcessHeap(), 0, keyname);
1078 uirow = MSI_CreateRecord(1);
1080 MSI_RecordSetStringW( uirow, 1, cls->CLSID );
1081 ui_actiondata(package,szRegisterClassInfo,uirow);
1082 msiobj_release(&uirow->hdr);
1089 static UINT register_progid_base(MSIPACKAGE* package, MSIPROGID* progid,
1092 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
1093 static const WCHAR szDefaultIcon[] =
1094 {'D','e','f','a','u','l','t','I','c','o','n',0};
1097 RegCreateKeyW(HKEY_CLASSES_ROOT,progid->ProgID,&hkey);
1099 if (progid->Description)
1101 RegSetValueExW(hkey,NULL,0,REG_SZ,
1102 (LPVOID)progid->Description,
1103 (strlenW(progid->Description)+1) *
1109 RegCreateKeyW(hkey,szCLSID,&hkey2);
1110 RegSetValueExW( hkey2, NULL, 0, REG_SZ, (LPBYTE)progid->Class->CLSID,
1111 (strlenW(progid->Class->CLSID)+1) * sizeof(WCHAR) );
1114 strcpyW( clsid, progid->Class->CLSID );
1120 FIXME("progid (%s) with null classid\n", debugstr_w(progid->ProgID));
1123 if (progid->IconPath)
1125 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
1127 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
1128 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
1131 return ERROR_SUCCESS;
1134 static UINT register_progid(MSIPACKAGE *package, MSIPROGID* progid,
1137 UINT rc = ERROR_SUCCESS;
1139 if (progid->Parent == NULL)
1140 rc = register_progid_base(package, progid, clsid);
1145 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
1146 static const WCHAR szDefaultIcon[] =
1147 {'D','e','f','a','u','l','t','I','c','o','n',0};
1148 static const WCHAR szCurVer[] =
1149 {'C','u','r','V','e','r',0};
1151 /* check if already registered */
1152 RegCreateKeyExW(HKEY_CLASSES_ROOT, progid->ProgID, 0, NULL, 0,
1153 KEY_ALL_ACCESS, NULL, &hkey, &disp );
1154 if (disp == REG_OPENED_EXISTING_KEY)
1156 TRACE("Key already registered\n");
1161 TRACE("Registering Parent %s\n", debugstr_w(progid->Parent->ProgID) );
1162 rc = register_progid( package, progid->Parent, clsid );
1164 /* clsid is same as parent */
1165 RegCreateKeyW(hkey,szCLSID,&hkey2);
1166 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
1172 if (progid->Description)
1174 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)progid->Description,
1175 (strlenW(progid->Description)+1) * sizeof(WCHAR));
1178 if (progid->IconPath)
1180 RegCreateKeyW(hkey,szDefaultIcon,&hkey2);
1181 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)progid->IconPath,
1182 (strlenW(progid->IconPath)+1) * sizeof(WCHAR));
1186 /* write out the current version */
1189 RegCreateKeyW(hkey,szCurVer,&hkey2);
1190 RegSetValueExW(hkey2,NULL,0,REG_SZ, (LPBYTE)progid->CurVer->ProgID,
1191 (strlenW(progid->CurVer->ProgID)+1) * sizeof(WCHAR));
1200 UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
1206 return ERROR_INVALID_HANDLE;
1208 load_classes_and_such(package);
1210 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
1212 WCHAR clsid[0x1000];
1214 /* check if this progid is to be installed */
1215 if (progid->Class && progid->Class->Installed)
1216 progid->InstallMe = TRUE;
1218 if (!progid->InstallMe)
1220 TRACE("progid %s not scheduled to be installed\n",
1221 debugstr_w(progid->ProgID));
1225 TRACE("Registering progid %s\n", debugstr_w(progid->ProgID));
1227 register_progid( package, progid, clsid );
1229 uirow = MSI_CreateRecord(1);
1230 MSI_RecordSetStringW( uirow, 1, progid->ProgID );
1231 ui_actiondata( package, szRegisterProgIdInfo, uirow );
1232 msiobj_release( &uirow->hdr );
1235 return ERROR_SUCCESS;
1238 static UINT register_verb(MSIPACKAGE *package, LPCWSTR progid,
1239 MSICOMPONENT* component, MSIEXTENSION* extension,
1240 MSIVERB* verb, INT* Sequence )
1244 static const WCHAR szShell[] = {'s','h','e','l','l',0};
1245 static const WCHAR szCommand[] = {'c','o','m','m','a','n','d',0};
1246 static const WCHAR fmt[] = {'\"','%','s','\"',' ','%','s',0};
1247 static const WCHAR fmt2[] = {'\"','%','s','\"',0};
1252 keyname = build_directory_name(4, progid, szShell, verb->Verb, szCommand);
1254 TRACE("Making Key %s\n",debugstr_w(keyname));
1255 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
1256 size = strlenW(component->FullKeypath);
1258 size += strlenW(verb->Argument);
1261 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
1263 sprintfW(command, fmt, component->FullKeypath, verb->Argument);
1265 sprintfW(command, fmt2, component->FullKeypath);
1267 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)command, (strlenW(command)+1)*
1269 HeapFree(GetProcessHeap(),0,command);
1271 advertise = create_component_advertise_string(package, component,
1272 extension->Feature->Feature);
1274 size = strlenW(advertise);
1277 size += strlenW(verb->Argument);
1280 command = HeapAlloc(GetProcessHeap(),0, size * sizeof (WCHAR));
1281 memset(command,0,size*sizeof(WCHAR));
1283 strcpyW(command,advertise);
1286 static const WCHAR szSpace[] = {' ',0};
1287 strcatW(command,szSpace);
1288 strcatW(command,verb->Argument);
1291 RegSetValueExW(key, szCommand, 0, REG_MULTI_SZ, (LPBYTE)command,
1292 (strlenW(command)+2)*sizeof(WCHAR));
1295 HeapFree(GetProcessHeap(),0,keyname);
1296 HeapFree(GetProcessHeap(),0,advertise);
1297 HeapFree(GetProcessHeap(),0,command);
1301 keyname = build_directory_name(3, progid, szShell, verb->Verb);
1302 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
1303 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Command,
1304 (strlenW(verb->Command)+1) *sizeof(WCHAR));
1306 HeapFree(GetProcessHeap(),0,keyname);
1309 if (verb->Sequence != MSI_NULL_INTEGER)
1311 if (*Sequence == MSI_NULL_INTEGER || verb->Sequence < *Sequence)
1313 *Sequence = verb->Sequence;
1314 keyname = build_directory_name(2, progid, szShell);
1315 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
1316 RegSetValueExW(key,NULL,0,REG_SZ, (LPVOID)verb->Verb,
1317 (strlenW(verb->Verb)+1) *sizeof(WCHAR));
1319 HeapFree(GetProcessHeap(),0,keyname);
1322 return ERROR_SUCCESS;
1325 UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
1327 static const WCHAR szContentType[] =
1328 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
1332 BOOL install_on_demand = TRUE;
1335 return ERROR_INVALID_HANDLE;
1337 load_classes_and_such(package);
1339 /* We need to set install_on_demand based on if the shell handles advertised
1340 * shortcuts and the like. Because Mike McCormack is working on this i am
1341 * going to default to TRUE
1344 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
1346 WCHAR extension[257];
1347 MSIFEATURE *feature;
1349 if (!ext->Component)
1352 feature = ext->Feature;
1355 * yes. MSDN says that these are based on _Feature_ not on
1356 * Component. So verify the feature is to be installed
1358 if ((!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL )) &&
1359 !(install_on_demand &&
1360 ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED )))
1362 TRACE("Skipping extension %s reg due to disabled feature %s\n",
1363 debugstr_w(ext->Extension), debugstr_w(feature->Feature));
1368 TRACE("Registering extension %s (%p)\n", debugstr_w(ext->Extension), ext);
1370 ext->Installed = TRUE;
1372 /* this is only registered if the extension has at least 1 verb
1375 if (ext->ProgID && !list_empty( &ext->verbs ) )
1376 mark_progid_for_install( package, ext->ProgID );
1378 mark_mime_for_install(ext->Mime);
1382 strcatW(extension,ext->Extension);
1384 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
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 )
1455 WCHAR extension[257];
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;
1482 strcatW(extension,exten);
1484 key = HeapAlloc(GetProcessHeap(),0,(strlenW(mime)+strlenW(fmt)+1) *
1486 sprintfW(key,fmt,mime);
1487 RegCreateKeyW(HKEY_CLASSES_ROOT,key,&hkey);
1488 RegSetValueExW(hkey,szExten,0,REG_SZ,(LPVOID)extension,
1489 (strlenW(extension)+1)*sizeof(WCHAR));
1491 HeapFree(GetProcessHeap(),0,key);
1495 FIXME("Handle non null for field 3\n");
1500 uirow = MSI_CreateRecord(2);
1501 MSI_RecordSetStringW(uirow,1,mt->ContentType);
1502 MSI_RecordSetStringW(uirow,2,exten);
1503 ui_actiondata(package,szRegisterMIMEInfo,uirow);
1504 msiobj_release(&uirow->hdr);
1507 return ERROR_SUCCESS;