Release 20050930.
[wine/gsoc-2012-control.git] / dlls / msi / classes.c
blobc83453131cdf82e26ff17e6e5bd7d57b3b5f039f
1 /*
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
22 * RegisterClassInfo
23 * RegisterProgIdInfo
24 * RegisterExtensionInfo
25 * RegisterMIMEInfo
26 * UnRegisterClassInfo (TODO)
27 * UnRegisterProgIdInfo (TODO)
28 * UnRegisterExtensionInfo (TODO)
29 * UnRegisterMIMEInfo (TODO)
32 #include <stdarg.h>
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winerror.h"
37 #include "winreg.h"
38 #include "wine/debug.h"
39 #include "msipriv.h"
40 #include "winuser.h"
41 #include "wine/unicode.h"
42 #include "action.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 )
59 LPCWSTR buffer;
60 MSIAPPID *appid;
62 /* fill in the data */
64 appid = msi_alloc_zero( sizeof(MSIAPPID) );
65 if (!appid)
66 return NULL;
68 appid->AppID = load_dynamic_stringW( 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 = load_dynamic_stringW(row,3);
75 appid->ServiceParameters = load_dynamic_stringW(row,4);
76 appid->DllSurrogate = load_dynamic_stringW(row,5);
78 appid->ActivateAtStorage = !MSI_RecordIsNull(row,6);
79 appid->RunAsInteractiveUser = !MSI_RecordIsNull(row,7);
81 list_add_tail( &package->appids, &appid->entry );
83 return appid;
86 static MSIAPPID *load_given_appid( MSIPACKAGE *package, LPCWSTR name )
88 MSIRECORD *row;
89 MSIAPPID *appid;
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};
95 if (!name)
96 return NULL;
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);
104 return appid;
108 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, name);
109 if (!row)
110 return NULL;
112 appid = load_appid(package, row);
113 msiobj_release(&row->hdr);
115 return appid;
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 )
123 MSIPROGID *progid;
124 LPCWSTR buffer;
126 /* fill in the data */
128 progid = msi_alloc_zero( sizeof(MSIPROGID) );
129 if (!progid)
130 return NULL;
132 list_add_tail( &package->progids, &progid->entry );
134 progid->ProgID = load_dynamic_stringW(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 = load_dynamic_stringW(row,4);
149 if (!MSI_RecordIsNull(row,6))
151 INT icon_index = MSI_RecordGetInteger(row,6);
152 LPWSTR FileName = load_dynamic_stringW(row,5);
153 LPWSTR FilePath;
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);
162 msi_free(FilePath);
163 msi_free(FileName);
165 else
167 buffer = MSI_RecordGetString(row,5);
168 if (buffer)
169 progid->IconPath = build_icon_path(package,buffer);
172 progid->CurVer = NULL;
173 progid->VersionInd = NULL;
175 /* if we have a parent then we may be that parents CurVer */
176 if (progid->Parent && progid->Parent != progid)
178 MSIPROGID *parent = progid->Parent;
180 while (parent->Parent && parent->Parent != parent)
181 parent = parent->Parent;
183 FIXME("need to determing if we are really the CurVer\n");
185 progid->CurVer = parent;
186 parent->VersionInd = progid;
189 return progid;
192 static MSIPROGID *load_given_progid(MSIPACKAGE *package, LPCWSTR name)
194 MSIPROGID *progid;
195 MSIRECORD *row;
196 static const WCHAR ExecSeqQuery[] =
197 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
198 '`','P','r','o','g','I','d','`',' ','W','H','E','R','E',' ',
199 '`','P','r','o','g','I','d','`',' ','=',' ','\'','%','s','\'',0};
201 if (!name)
202 return NULL;
204 /* check for progids already loaded */
205 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
207 if (strcmpiW( progid->ProgID,name )==0)
209 TRACE("found progid %s (%p)\n",debugstr_w(name), progid );
210 return progid;
214 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, name );
215 if (!row)
216 return NULL;
218 progid = load_progid(package, row);
219 msiobj_release(&row->hdr);
221 return progid;
224 static MSICLASS *load_class( MSIPACKAGE* package, MSIRECORD *row )
226 MSICLASS *cls;
227 DWORD i;
228 LPCWSTR buffer;
230 /* fill in the data */
232 cls = msi_alloc_zero( sizeof(MSICLASS) );
233 if (!cls)
234 return NULL;
236 list_add_tail( &package->classes, &cls->entry );
238 cls->clsid = load_dynamic_stringW( row, 1 );
239 TRACE("loading class %s\n",debugstr_w(cls->clsid));
240 cls->Context = load_dynamic_stringW( row, 2 );
241 buffer = MSI_RecordGetString(row,3);
242 cls->Component = get_loaded_component(package, buffer);
244 cls->ProgIDText = load_dynamic_stringW(row,4);
245 cls->ProgID = load_given_progid(package, cls->ProgIDText);
247 cls->Description = load_dynamic_stringW(row,5);
249 buffer = MSI_RecordGetString(row,6);
250 if (buffer)
251 cls->AppID = load_given_appid(package, buffer);
253 cls->FileTypeMask = load_dynamic_stringW(row,7);
255 if (!MSI_RecordIsNull(row,9))
258 INT icon_index = MSI_RecordGetInteger(row,9);
259 LPWSTR FileName = load_dynamic_stringW(row,8);
260 LPWSTR FilePath;
261 static const WCHAR fmt[] = {'%','s',',','%','i',0};
263 FilePath = build_icon_path(package,FileName);
265 cls->IconPath = msi_alloc( (strlenW(FilePath)+5)* sizeof(WCHAR) );
267 sprintfW(cls->IconPath,fmt,FilePath,icon_index);
269 msi_free(FilePath);
270 msi_free(FileName);
272 else
274 buffer = MSI_RecordGetString(row,8);
275 if (buffer)
276 cls->IconPath = build_icon_path(package,buffer);
279 if (!MSI_RecordIsNull(row,10))
281 i = MSI_RecordGetInteger(row,10);
282 if (i != MSI_NULL_INTEGER && i > 0 && i < 4)
284 static const WCHAR ole2[] = {'o','l','e','2','.','d','l','l',0};
285 static const WCHAR ole32[] = {'o','l','e','3','2','.','d','l','l',0};
287 switch(i)
289 case 1:
290 cls->DefInprocHandler = strdupW(ole2);
291 break;
292 case 2:
293 cls->DefInprocHandler32 = strdupW(ole32);
294 break;
295 case 3:
296 cls->DefInprocHandler = strdupW(ole2);
297 cls->DefInprocHandler32 = strdupW(ole32);
298 break;
301 else
303 cls->DefInprocHandler32 = load_dynamic_stringW( row, 10);
304 reduce_to_longfilename(cls->DefInprocHandler32);
307 buffer = MSI_RecordGetString(row,11);
308 deformat_string(package,buffer,&cls->Argument);
310 buffer = MSI_RecordGetString(row,12);
311 cls->Feature = get_loaded_feature(package,buffer);
313 cls->Attributes = MSI_RecordGetInteger(row,13);
315 return cls;
319 * the Class table has 3 primary keys. Generally it is only
320 * referenced through the first CLSID key. However when loading
321 * all of the classes we need to make sure we do not ignore rows
322 * with other Context and ComponentIndexs
324 static MSICLASS *load_given_class(MSIPACKAGE *package, LPCWSTR classid)
326 MSICLASS *cls;
327 MSIRECORD *row;
328 static const WCHAR ExecSeqQuery[] =
329 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
330 '`','C','l','a','s','s','`',' ','W','H','E','R','E',' ',
331 '`','C','L','S','I','D','`',' ','=',' ','\'','%','s','\'',0};
333 if (!classid)
334 return NULL;
336 /* check for classes already loaded */
337 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
339 if (lstrcmpiW( cls->clsid, classid )==0)
341 TRACE("found class %s (%p)\n",debugstr_w(classid), cls);
342 return cls;
346 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, classid);
347 if (!row)
348 return NULL;
350 cls = load_class(package, row);
351 msiobj_release(&row->hdr);
353 return cls;
356 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR extension );
358 static MSIMIME *load_mime( MSIPACKAGE* package, MSIRECORD *row )
360 LPCWSTR buffer;
361 MSIMIME *mt;
363 /* fill in the data */
365 mt = msi_alloc_zero( sizeof(MSIMIME) );
366 if (!mt)
367 return mt;
369 mt->ContentType = load_dynamic_stringW( row, 1 );
370 TRACE("loading mime %s\n", debugstr_w(mt->ContentType));
372 buffer = MSI_RecordGetString( row, 2 );
373 mt->Extension = load_given_extension( package, buffer );
375 mt->clsid = load_dynamic_stringW( row, 3 );
376 mt->Class = load_given_class( package, mt->clsid );
378 list_add_tail( &package->mimes, &mt->entry );
380 return mt;
383 static MSIMIME *load_given_mime( MSIPACKAGE *package, LPCWSTR mime )
385 MSIRECORD *row;
386 static const WCHAR ExecSeqQuery[] =
387 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
388 '`','M','I','M','E','`',' ','W','H','E','R','E',' ',
389 '`','C','o','n','t','e','n','t','T','y','p','e','`',' ','=',' ',
390 '\'','%','s','\'',0};
391 MSIMIME *mt;
393 if (!mime)
394 return NULL;
396 /* check for mime already loaded */
397 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
399 if (strcmpiW(mt->ContentType,mime)==0)
401 TRACE("found mime %s (%p)\n",debugstr_w(mime), mt);
402 return mt;
406 row = MSI_QueryGetRecord(package->db, ExecSeqQuery, mime);
407 if (!row)
408 return NULL;
410 mt = load_mime(package, row);
411 msiobj_release(&row->hdr);
413 return mt;
416 static MSIEXTENSION *load_extension( MSIPACKAGE* package, MSIRECORD *row )
418 MSIEXTENSION *ext;
419 LPCWSTR buffer;
421 /* fill in the data */
423 ext = msi_alloc_zero( sizeof(MSIEXTENSION) );
424 if (!ext)
425 return NULL;
427 list_init( &ext->verbs );
429 list_add_tail( &package->extensions, &ext->entry );
431 ext->Extension = load_dynamic_stringW( row, 1 );
432 TRACE("loading extension %s\n", debugstr_w(ext->Extension));
434 buffer = MSI_RecordGetString( row, 2 );
435 ext->Component = get_loaded_component( package,buffer );
437 ext->ProgIDText = load_dynamic_stringW( row, 3 );
438 ext->ProgID = load_given_progid( package, ext->ProgIDText );
440 buffer = MSI_RecordGetString( row, 4 );
441 ext->Mime = load_given_mime( package, buffer );
443 buffer = MSI_RecordGetString(row,5);
444 ext->Feature = get_loaded_feature( package, buffer );
446 return ext;
450 * While the extension table has 2 primary keys, this function is only looking
451 * at the Extension key which is what is referenced as a forign key
453 static MSIEXTENSION *load_given_extension( MSIPACKAGE *package, LPCWSTR name )
455 MSIRECORD *row;
456 MSIEXTENSION *ext;
457 static const WCHAR ExecSeqQuery[] =
458 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
459 '`','E','x','t','e','n','s','i','o','n','`',' ',
460 'W','H','E','R','E',' ',
461 '`','E','x','t','e','n','s','i','o','n','`',' ','=',' ',
462 '\'','%','s','\'',0};
464 if (!name)
465 return NULL;
467 /* check for extensions already loaded */
468 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
470 if (strcmpiW( ext->Extension, name )==0)
472 TRACE("extension %s already loaded %p\n", debugstr_w(name), ext);
473 return ext;
477 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, name );
478 if (!row)
479 return NULL;
481 ext = load_extension(package, row);
482 msiobj_release(&row->hdr);
484 return ext;
487 static UINT iterate_load_verb(MSIRECORD *row, LPVOID param)
489 MSIPACKAGE* package = (MSIPACKAGE*)param;
490 MSIVERB *verb;
491 LPCWSTR buffer;
492 MSIEXTENSION *extension;
494 buffer = MSI_RecordGetString(row,1);
495 extension = load_given_extension( package, buffer );
496 if (!extension)
498 ERR("Verb unable to find loaded extension %s\n", debugstr_w(buffer));
499 return ERROR_SUCCESS;
502 /* fill in the data */
504 verb = msi_alloc_zero( sizeof(MSIVERB) );
505 if (!verb)
506 return ERROR_OUTOFMEMORY;
508 verb->Verb = load_dynamic_stringW(row,2);
509 TRACE("loading verb %s\n",debugstr_w(verb->Verb));
510 verb->Sequence = MSI_RecordGetInteger(row,3);
512 buffer = MSI_RecordGetString(row,4);
513 deformat_string(package,buffer,&verb->Command);
515 buffer = MSI_RecordGetString(row,5);
516 deformat_string(package,buffer,&verb->Argument);
518 /* assosiate the verb with the correct extension */
519 list_add_tail( &extension->verbs, &verb->entry );
521 return ERROR_SUCCESS;
524 static UINT iterate_all_classes(MSIRECORD *rec, LPVOID param)
526 MSICOMPONENT *comp;
527 LPCWSTR clsid;
528 LPCWSTR context;
529 LPCWSTR buffer;
530 MSIPACKAGE* package =(MSIPACKAGE*)param;
531 MSICLASS *cls;
532 BOOL match = FALSE;
534 clsid = MSI_RecordGetString(rec,1);
535 context = MSI_RecordGetString(rec,2);
536 buffer = MSI_RecordGetString(rec,3);
537 comp = get_loaded_component(package,buffer);
539 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
541 if (strcmpiW( clsid, cls->clsid ))
542 continue;
543 if (strcmpW( context, cls->Context ))
544 continue;
545 if (comp == cls->Component)
547 match = TRUE;
548 break;
552 if (!match)
553 load_class(package, rec);
555 return ERROR_SUCCESS;
558 static VOID load_all_classes(MSIPACKAGE *package)
560 UINT rc = ERROR_SUCCESS;
561 MSIQUERY *view;
563 static const WCHAR ExecSeqQuery[] =
564 {'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
565 '`','C','l','a','s','s','`',0};
567 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
568 if (rc != ERROR_SUCCESS)
569 return;
571 rc = MSI_IterateRecords(view, NULL, iterate_all_classes, package);
572 msiobj_release(&view->hdr);
575 static UINT iterate_all_extensions(MSIRECORD *rec, LPVOID param)
577 MSICOMPONENT *comp;
578 LPCWSTR buffer;
579 LPCWSTR extension;
580 MSIPACKAGE* package =(MSIPACKAGE*)param;
581 BOOL match = FALSE;
582 MSIEXTENSION *ext;
584 extension = MSI_RecordGetString(rec,1);
585 buffer = MSI_RecordGetString(rec,2);
586 comp = get_loaded_component(package,buffer);
588 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
590 if (strcmpiW(extension,ext->Extension))
591 continue;
592 if (comp == ext->Component)
594 match = TRUE;
595 break;
599 if (!match)
600 load_extension(package, rec);
602 return ERROR_SUCCESS;
605 static VOID load_all_extensions(MSIPACKAGE *package)
607 UINT rc = ERROR_SUCCESS;
608 MSIQUERY *view;
610 static const WCHAR ExecSeqQuery[] =
611 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
612 '`','E','x','t','e','n','s','i','o','n','`',0};
614 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
615 if (rc != ERROR_SUCCESS)
616 return;
618 rc = MSI_IterateRecords(view, NULL, iterate_all_extensions, package);
619 msiobj_release(&view->hdr);
622 static UINT iterate_all_progids(MSIRECORD *rec, LPVOID param)
624 LPCWSTR buffer;
625 MSIPACKAGE* package =(MSIPACKAGE*)param;
627 buffer = MSI_RecordGetString(rec,1);
628 load_given_progid(package,buffer);
629 return ERROR_SUCCESS;
632 static VOID load_all_progids(MSIPACKAGE *package)
634 UINT rc = ERROR_SUCCESS;
635 MSIQUERY *view;
637 static const WCHAR ExecSeqQuery[] =
638 {'S','E','L','E','C','T',' ','`','P','r','o','g','I','d','`',' ',
639 'F','R','O','M',' ', '`','P','r','o','g','I','d','`',0};
641 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
642 if (rc != ERROR_SUCCESS)
643 return;
645 rc = MSI_IterateRecords(view, NULL, iterate_all_progids, package);
646 msiobj_release(&view->hdr);
649 static VOID load_all_verbs(MSIPACKAGE *package)
651 UINT rc = ERROR_SUCCESS;
652 MSIQUERY *view;
654 static const WCHAR ExecSeqQuery[] =
655 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
656 '`','V','e','r','b','`',0};
658 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
659 if (rc != ERROR_SUCCESS)
660 return;
662 rc = MSI_IterateRecords(view, NULL, iterate_load_verb, package);
663 msiobj_release(&view->hdr);
666 static UINT iterate_all_mimes(MSIRECORD *rec, LPVOID param)
668 LPCWSTR buffer;
669 MSIPACKAGE* package =(MSIPACKAGE*)param;
671 buffer = MSI_RecordGetString(rec,1);
672 load_given_mime(package,buffer);
673 return ERROR_SUCCESS;
676 static VOID load_all_mimes(MSIPACKAGE *package)
678 UINT rc = ERROR_SUCCESS;
679 MSIQUERY *view;
681 static const WCHAR ExecSeqQuery[] =
682 {'S','E','L','E','C','T',' ',
683 '`','C','o','n','t','e','n','t','T','y','p','e','`',
684 ' ','F','R','O','M',' ',
685 '`','M','I','M','E','`',0};
687 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
688 if (rc != ERROR_SUCCESS)
689 return;
691 rc = MSI_IterateRecords(view, NULL, iterate_all_mimes, package);
692 msiobj_release(&view->hdr);
695 static void load_classes_and_such(MSIPACKAGE *package)
697 TRACE("Loading all the class info and related tables\n");
699 /* check if already loaded */
700 if (!list_empty( &package->classes ) ||
701 !list_empty( &package->mimes ) ||
702 !list_empty( &package->extensions ) ||
703 !list_empty( &package->progids ) )
704 return;
706 load_all_classes(package);
707 load_all_extensions(package);
708 load_all_progids(package);
709 /* these loads must come after the other loads */
710 load_all_verbs(package);
711 load_all_mimes(package);
714 static void mark_progid_for_install( MSIPACKAGE* package, MSIPROGID *progid )
716 MSIPROGID *child;
718 if (!progid)
719 return;
721 if (progid->InstallMe == TRUE)
722 return;
724 progid->InstallMe = TRUE;
726 /* all children if this is a parent also install */
727 LIST_FOR_EACH_ENTRY( child, &package->progids, MSIPROGID, entry )
729 if (child->Parent == progid)
730 mark_progid_for_install( package, child );
734 static void mark_mime_for_install( MSIMIME *mime )
736 if (!mime)
737 return;
738 mime->InstallMe = TRUE;
741 LONG msi_reg_set_val_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
743 DWORD len = value ? (lstrlenW(value) + 1) * sizeof (WCHAR) : 0;
744 return RegSetValueExW( hkey, name, 0, REG_SZ, (LPBYTE)value, len );
747 LONG msi_reg_set_val_multi_str( HKEY hkey, LPCWSTR name, LPCWSTR value )
749 LPCWSTR p = value;
750 while (*p) p += lstrlenW(p) + 1;
751 return RegSetValueExW( hkey, name, 0, REG_MULTI_SZ,
752 (LPBYTE)value, (p + 1 - value) * sizeof(WCHAR) );
755 LONG msi_reg_set_val_dword( HKEY hkey, LPCWSTR name, DWORD val )
757 return RegSetValueExW( hkey, name, 0, REG_DWORD, (LPBYTE)&val, sizeof (DWORD) );
760 LONG msi_reg_set_subkey_val( HKEY hkey, LPCWSTR path, LPCWSTR name, LPCWSTR val )
762 HKEY hsubkey = 0;
763 LONG r;
765 r = RegCreateKeyW( hkey, path, &hsubkey );
766 if (r != ERROR_SUCCESS)
767 return r;
768 r = msi_reg_set_val_str( hsubkey, name, val );
769 RegCloseKey( hsubkey );
770 return r;
773 static UINT register_appid(MSIAPPID *appid, LPCWSTR app )
775 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
776 static const WCHAR szRemoteServerName[] =
777 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
778 static const WCHAR szLocalService[] =
779 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
780 static const WCHAR szService[] =
781 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
782 static const WCHAR szDLL[] =
783 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
784 static const WCHAR szActivate[] =
785 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
786 static const WCHAR szY[] = {'Y',0};
787 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
788 static const WCHAR szUser[] =
789 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
791 HKEY hkey2,hkey3;
793 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
794 RegCreateKeyW( hkey2, appid->AppID, &hkey3 );
795 RegCloseKey(hkey2);
796 msi_reg_set_val_str( hkey3, NULL, app );
798 if (appid->RemoteServerName)
799 msi_reg_set_val_str( hkey3, szRemoteServerName, appid->RemoteServerName );
801 if (appid->LocalServer)
802 msi_reg_set_val_str( hkey3, szLocalService, appid->LocalServer );
804 if (appid->ServiceParameters)
805 msi_reg_set_val_str( hkey3, szService, appid->ServiceParameters );
807 if (appid->DllSurrogate)
808 msi_reg_set_val_str( hkey3, szDLL, appid->DllSurrogate );
810 if (appid->ActivateAtStorage)
811 msi_reg_set_val_str( hkey3, szActivate, szY );
813 if (appid->RunAsInteractiveUser)
814 msi_reg_set_val_str( hkey3, szRunAs, szUser );
816 RegCloseKey(hkey3);
817 return ERROR_SUCCESS;
820 UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
823 * Again I am assuming the words, "Whose key file represents" when referring
824 * to a Component as to meaning that Components KeyPath file
827 UINT rc;
828 MSIRECORD *uirow;
829 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
830 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
831 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 };
832 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
833 static const WCHAR szSpace[] = {' ',0};
834 static const WCHAR szInprocServer32[] = {'I','n','p','r','o','c','S','e','r','v','e','r','3','2',0};
835 static const WCHAR szFileType_fmt[] = {'F','i','l','e','T','y','p','e','\\','%','s','\\','%','i',0};
836 HKEY hkey,hkey2,hkey3;
837 BOOL install_on_demand = FALSE;
838 MSICLASS *cls;
840 if (!package)
841 return ERROR_INVALID_HANDLE;
843 load_classes_and_such(package);
844 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
845 if (rc != ERROR_SUCCESS)
846 return ERROR_FUNCTION_FAILED;
848 /* install_on_demand should be set if OLE supports install on demand OLE
849 * servers. For now i am defaulting to FALSE because i do not know how to
850 * check, and i am told our builtin OLE does not support it
853 LIST_FOR_EACH_ENTRY( cls, &package->classes, MSICLASS, entry )
855 MSICOMPONENT *comp;
856 MSIFILE *file;
857 DWORD size, sz;
858 LPWSTR argument;
859 MSIFEATURE *feature;
861 comp = cls->Component;
862 if ( !comp )
863 continue;
865 feature = cls->Feature;
868 * yes. MSDN says that these are based on _Feature_ not on
869 * Component. So verify the feature is to be installed
871 if ((!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL )) &&
872 !(install_on_demand &&
873 ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED )))
875 TRACE("Skipping class %s reg due to disabled feature %s\n",
876 debugstr_w(cls->clsid),
877 debugstr_w(feature->Feature));
879 continue;
882 TRACE("Registering class %s (%p)\n", debugstr_w(cls->clsid), cls);
884 cls->Installed = TRUE;
885 mark_progid_for_install( package, cls->ProgID );
887 RegCreateKeyW( hkey, cls->clsid, &hkey2 );
889 if (cls->Description)
890 msi_reg_set_val_str( hkey2, NULL, cls->Description );
892 RegCreateKeyW( hkey2, cls->Context, &hkey3 );
893 file = get_loaded_file( package, comp->KeyPath );
896 /* the context server is a short path name
897 * except for if it is InprocServer32...
899 if (strcmpiW( cls->Context, szInprocServer32 )!=0)
901 sz = GetShortPathNameW( file->TargetPath, NULL, 0 );
902 if (sz == 0)
904 ERR("Unable to find short path for CLSID COM Server\n");
905 argument = NULL;
907 else
909 size = sz * sizeof(WCHAR);
911 if (cls->Argument)
913 size += strlenW(cls->Argument) * sizeof(WCHAR);
914 size += sizeof(WCHAR);
917 argument = msi_alloc( size + sizeof(WCHAR));
918 GetShortPathNameW( file->TargetPath, argument, sz );
920 if (cls->Argument)
922 strcatW(argument,szSpace);
923 strcatW( argument, cls->Argument );
927 else
929 size = lstrlenW( file->TargetPath ) * sizeof(WCHAR);
931 if (cls->Argument)
933 size += strlenW(cls->Argument) * sizeof(WCHAR);
934 size += sizeof(WCHAR);
937 argument = msi_alloc( size + sizeof(WCHAR));
938 strcpyW( argument, file->TargetPath );
940 if (cls->Argument)
942 strcatW(argument,szSpace);
943 strcatW( argument, cls->Argument );
947 if (argument)
949 msi_reg_set_val_str( hkey3, NULL, argument );
950 msi_free(argument);
953 RegCloseKey(hkey3);
955 if (cls->ProgID || cls->ProgIDText)
957 LPCWSTR progid;
959 if (cls->ProgID)
960 progid = cls->ProgID->ProgID;
961 else
962 progid = cls->ProgIDText;
964 msi_reg_set_subkey_val( hkey2, szProgID, NULL, progid );
966 if (cls->ProgID && cls->ProgID->VersionInd)
968 msi_reg_set_subkey_val( hkey2, szVIProgID, NULL,
969 cls->ProgID->VersionInd->ProgID );
973 if (cls->AppID)
975 MSIAPPID *appid = cls->AppID;
977 msi_reg_set_val_str( hkey2, szAppID, appid->AppID );
979 register_appid( appid, cls->Description );
982 if (cls->IconPath)
984 static const WCHAR szDefaultIcon[] =
985 {'D','e','f','a','u','l','t','I','c','o','n',0};
987 msi_reg_set_subkey_val( hkey2, szDefaultIcon, NULL, cls->IconPath );
990 if (cls->DefInprocHandler)
992 static const WCHAR szInproc[] =
993 {'I','n','p','r','o','c','H','a','n','d','l','e','r',0};
995 msi_reg_set_subkey_val( hkey2, szInproc, NULL, cls->DefInprocHandler );
998 if (cls->DefInprocHandler32)
1000 static const WCHAR szInproc32[] =
1001 {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',0};
1003 msi_reg_set_subkey_val( hkey2, szInproc32, NULL, cls->DefInprocHandler32 );
1006 RegCloseKey(hkey2);
1008 /* if there is a FileTypeMask, register the FileType */
1009 if (cls->FileTypeMask)
1011 LPWSTR ptr, ptr2;
1012 LPWSTR keyname;
1013 INT index = 0;
1014 ptr = cls->FileTypeMask;
1015 while (ptr && *ptr)
1017 ptr2 = strchrW(ptr,';');
1018 if (ptr2)
1019 *ptr2 = 0;
1020 keyname = msi_alloc( (strlenW(szFileType_fmt) + strlenW(cls->clsid) + 4) * sizeof(WCHAR));
1021 sprintfW( keyname, szFileType_fmt, cls->clsid, index );
1023 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, ptr );
1024 msi_free(keyname);
1026 if (ptr2)
1027 ptr = ptr2+1;
1028 else
1029 ptr = NULL;
1031 index ++;
1035 uirow = MSI_CreateRecord(1);
1037 MSI_RecordSetStringW( uirow, 1, cls->clsid );
1038 ui_actiondata(package,szRegisterClassInfo,uirow);
1039 msiobj_release(&uirow->hdr);
1042 RegCloseKey(hkey);
1043 return rc;
1046 static UINT register_progid_base(MSIPACKAGE* package, MSIPROGID* progid,
1047 LPWSTR clsid)
1049 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
1050 static const WCHAR szDefaultIcon[] =
1051 {'D','e','f','a','u','l','t','I','c','o','n',0};
1052 HKEY hkey;
1054 RegCreateKeyW(HKEY_CLASSES_ROOT,progid->ProgID,&hkey);
1056 if (progid->Description)
1057 msi_reg_set_val_str( hkey, NULL, progid->Description );
1059 if (progid->Class)
1061 msi_reg_set_subkey_val( hkey, szCLSID, NULL, progid->Class->clsid );
1062 if (clsid)
1063 strcpyW( clsid, progid->Class->clsid );
1065 else
1067 FIXME("progid (%s) with null classid\n", debugstr_w(progid->ProgID));
1070 if (progid->IconPath)
1071 msi_reg_set_subkey_val( hkey, szDefaultIcon, NULL, progid->IconPath );
1073 return ERROR_SUCCESS;
1076 static UINT register_progid(MSIPACKAGE *package, MSIPROGID* progid,
1077 LPWSTR clsid)
1079 UINT rc = ERROR_SUCCESS;
1081 if (progid->Parent == NULL)
1082 rc = register_progid_base(package, progid, clsid);
1083 else
1085 DWORD disp;
1086 HKEY hkey;
1087 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
1088 static const WCHAR szDefaultIcon[] =
1089 {'D','e','f','a','u','l','t','I','c','o','n',0};
1090 static const WCHAR szCurVer[] =
1091 {'C','u','r','V','e','r',0};
1093 /* check if already registered */
1094 RegCreateKeyExW(HKEY_CLASSES_ROOT, progid->ProgID, 0, NULL, 0,
1095 KEY_ALL_ACCESS, NULL, &hkey, &disp );
1096 if (disp == REG_OPENED_EXISTING_KEY)
1098 TRACE("Key already registered\n");
1099 RegCloseKey(hkey);
1100 return rc;
1103 TRACE("Registering Parent %s\n", debugstr_w(progid->Parent->ProgID) );
1104 rc = register_progid( package, progid->Parent, clsid );
1106 /* clsid is same as parent */
1107 msi_reg_set_subkey_val( hkey, szCLSID, NULL, clsid );
1109 if (progid->Description)
1110 msi_reg_set_val_str( hkey, NULL, progid->Description );
1112 if (progid->IconPath)
1113 msi_reg_set_subkey_val( hkey, szDefaultIcon, NULL, progid->IconPath );
1115 /* write out the current version */
1116 if (progid->CurVer)
1117 msi_reg_set_subkey_val( hkey, szCurVer, NULL, progid->CurVer->ProgID );
1119 RegCloseKey(hkey);
1121 return rc;
1124 UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
1126 MSIPROGID *progid;
1127 MSIRECORD *uirow;
1129 if (!package)
1130 return ERROR_INVALID_HANDLE;
1132 load_classes_and_such(package);
1134 LIST_FOR_EACH_ENTRY( progid, &package->progids, MSIPROGID, entry )
1136 WCHAR clsid[0x1000];
1138 /* check if this progid is to be installed */
1139 if (progid->Class && progid->Class->Installed)
1140 progid->InstallMe = TRUE;
1142 if (!progid->InstallMe)
1144 TRACE("progid %s not scheduled to be installed\n",
1145 debugstr_w(progid->ProgID));
1146 continue;
1149 TRACE("Registering progid %s\n", debugstr_w(progid->ProgID));
1151 register_progid( package, progid, clsid );
1153 uirow = MSI_CreateRecord(1);
1154 MSI_RecordSetStringW( uirow, 1, progid->ProgID );
1155 ui_actiondata( package, szRegisterProgIdInfo, uirow );
1156 msiobj_release( &uirow->hdr );
1159 return ERROR_SUCCESS;
1162 static UINT register_verb(MSIPACKAGE *package, LPCWSTR progid,
1163 MSICOMPONENT* component, MSIEXTENSION* extension,
1164 MSIVERB* verb, INT* Sequence )
1166 LPWSTR keyname;
1167 HKEY key;
1168 static const WCHAR szShell[] = {'s','h','e','l','l',0};
1169 static const WCHAR szCommand[] = {'c','o','m','m','a','n','d',0};
1170 static const WCHAR fmt[] = {'\"','%','s','\"',' ','%','s',0};
1171 static const WCHAR fmt2[] = {'\"','%','s','\"',0};
1172 LPWSTR command;
1173 DWORD size;
1174 LPWSTR advertise;
1176 keyname = build_directory_name(4, progid, szShell, verb->Verb, szCommand);
1178 TRACE("Making Key %s\n",debugstr_w(keyname));
1179 RegCreateKeyW(HKEY_CLASSES_ROOT, keyname, &key);
1180 size = strlenW(component->FullKeypath);
1181 if (verb->Argument)
1182 size += strlenW(verb->Argument);
1183 size += 4;
1185 command = msi_alloc(size * sizeof (WCHAR));
1186 if (verb->Argument)
1187 sprintfW(command, fmt, component->FullKeypath, verb->Argument);
1188 else
1189 sprintfW(command, fmt2, component->FullKeypath);
1191 msi_reg_set_val_str( key, NULL, command );
1192 msi_free(command);
1194 advertise = create_component_advertise_string(package, component,
1195 extension->Feature->Feature);
1197 size = strlenW(advertise);
1199 if (verb->Argument)
1200 size += strlenW(verb->Argument);
1201 size += 4;
1203 command = msi_alloc(size * sizeof (WCHAR));
1204 memset(command,0,size*sizeof(WCHAR));
1206 strcpyW(command,advertise);
1207 if (verb->Argument)
1209 static const WCHAR szSpace[] = {' ',0};
1210 strcatW(command,szSpace);
1211 strcatW(command,verb->Argument);
1214 msi_reg_set_val_multi_str( key, szCommand, command );
1216 RegCloseKey(key);
1217 msi_free(keyname);
1218 msi_free(advertise);
1219 msi_free(command);
1221 if (verb->Command)
1223 keyname = build_directory_name(3, progid, szShell, verb->Verb);
1224 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, verb->Command );
1225 msi_free(keyname);
1228 if (verb->Sequence != MSI_NULL_INTEGER)
1230 if (*Sequence == MSI_NULL_INTEGER || verb->Sequence < *Sequence)
1232 *Sequence = verb->Sequence;
1233 keyname = build_directory_name(2, progid, szShell);
1234 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, keyname, NULL, verb->Verb );
1235 msi_free(keyname);
1238 return ERROR_SUCCESS;
1241 UINT ACTION_RegisterExtensionInfo(MSIPACKAGE *package)
1243 static const WCHAR szContentType[] =
1244 {'C','o','n','t','e','n','t',' ','T','y','p','e',0 };
1245 HKEY hkey;
1246 MSIEXTENSION *ext;
1247 MSIRECORD *uirow;
1248 BOOL install_on_demand = TRUE;
1250 if (!package)
1251 return ERROR_INVALID_HANDLE;
1253 load_classes_and_such(package);
1255 /* We need to set install_on_demand based on if the shell handles advertised
1256 * shortcuts and the like. Because Mike McCormack is working on this i am
1257 * going to default to TRUE
1260 LIST_FOR_EACH_ENTRY( ext, &package->extensions, MSIEXTENSION, entry )
1262 LPWSTR extension;
1263 MSIFEATURE *feature;
1265 if (!ext->Component)
1266 continue;
1268 feature = ext->Feature;
1271 * yes. MSDN says that these are based on _Feature_ not on
1272 * Component. So verify the feature is to be installed
1274 if ((!ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_LOCAL )) &&
1275 !(install_on_demand &&
1276 ACTION_VerifyFeatureForAction( feature, INSTALLSTATE_ADVERTISED )))
1278 TRACE("Skipping extension %s reg due to disabled feature %s\n",
1279 debugstr_w(ext->Extension), debugstr_w(feature->Feature));
1281 continue;
1284 TRACE("Registering extension %s (%p)\n", debugstr_w(ext->Extension), ext);
1286 ext->Installed = TRUE;
1288 /* this is only registered if the extension has at least 1 verb
1289 * according to MSDN
1291 if (ext->ProgID && !list_empty( &ext->verbs ) )
1292 mark_progid_for_install( package, ext->ProgID );
1294 mark_mime_for_install(ext->Mime);
1296 extension = msi_alloc( (lstrlenW( ext->Extension ) + 2)*sizeof(WCHAR) );
1297 extension[0] = '.';
1298 lstrcpyW(extension+1,ext->Extension);
1300 RegCreateKeyW(HKEY_CLASSES_ROOT,extension,&hkey);
1301 msi_free( extension );
1303 if (ext->Mime)
1304 msi_reg_set_val_str( hkey, szContentType, ext->Mime->ContentType );
1306 if (ext->ProgID || ext->ProgIDText)
1308 static const WCHAR szSN[] =
1309 {'\\','S','h','e','l','l','N','e','w',0};
1310 HKEY hkey2;
1311 LPWSTR newkey;
1312 LPCWSTR progid;
1313 MSIVERB *verb;
1314 INT Sequence = MSI_NULL_INTEGER;
1316 if (ext->ProgID)
1317 progid = ext->ProgID->ProgID;
1318 else
1319 progid = ext->ProgIDText;
1321 msi_reg_set_val_str( hkey, NULL, progid );
1323 newkey = msi_alloc( (strlenW(progid)+strlenW(szSN)+1) * sizeof(WCHAR));
1325 strcpyW(newkey,progid);
1326 strcatW(newkey,szSN);
1327 RegCreateKeyW(hkey,newkey,&hkey2);
1328 RegCloseKey(hkey2);
1330 msi_free(newkey);
1332 /* do all the verbs */
1333 LIST_FOR_EACH_ENTRY( verb, &ext->verbs, MSIVERB, entry )
1335 register_verb( package, progid, ext->Component,
1336 ext, verb, &Sequence);
1340 RegCloseKey(hkey);
1342 uirow = MSI_CreateRecord(1);
1343 MSI_RecordSetStringW( uirow, 1, ext->Extension );
1344 ui_actiondata(package,szRegisterExtensionInfo,uirow);
1345 msiobj_release(&uirow->hdr);
1348 return ERROR_SUCCESS;
1351 UINT ACTION_RegisterMIMEInfo(MSIPACKAGE *package)
1353 static const WCHAR szExten[] =
1354 {'E','x','t','e','n','s','i','o','n',0 };
1355 MSIRECORD *uirow;
1356 MSIMIME *mt;
1358 if (!package)
1359 return ERROR_INVALID_HANDLE;
1361 load_classes_and_such(package);
1363 LIST_FOR_EACH_ENTRY( mt, &package->mimes, MSIMIME, entry )
1365 LPWSTR extension;
1366 LPCWSTR exten;
1367 LPCWSTR mime;
1368 static const WCHAR fmt[] =
1369 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
1370 'C','o','n','t','e','n','t',' ','T','y','p','e','\\', '%','s',0};
1371 LPWSTR key;
1374 * check if the MIME is to be installed. Either as requesed by an
1375 * extension or Class
1377 mt->InstallMe = (mt->InstallMe ||
1378 (mt->Class && mt->Class->Installed) ||
1379 (mt->Extension && mt->Extension->Installed));
1381 if (!mt->InstallMe)
1383 TRACE("MIME %s not scheduled to be installed\n",
1384 debugstr_w(mt->ContentType));
1385 continue;
1388 mime = mt->ContentType;
1389 exten = mt->Extension->Extension;
1391 extension = msi_alloc( (lstrlenW( exten ) + 2)*sizeof(WCHAR) );
1392 extension[0] = '.';
1393 lstrcpyW(extension+1,exten);
1395 key = msi_alloc( (strlenW(mime)+strlenW(fmt)+1) * sizeof(WCHAR) );
1396 sprintfW(key,fmt,mime);
1397 msi_reg_set_subkey_val( HKEY_CLASSES_ROOT, key, szExten, extension );
1399 msi_free(extension);
1400 msi_free(key);
1402 if (mt->clsid)
1403 FIXME("Handle non null for field 3\n");
1405 uirow = MSI_CreateRecord(2);
1406 MSI_RecordSetStringW(uirow,1,mt->ContentType);
1407 MSI_RecordSetStringW(uirow,2,exten);
1408 ui_actiondata(package,szRegisterMIMEInfo,uirow);
1409 msiobj_release(&uirow->hdr);
1412 return ERROR_SUCCESS;