Status update.
[wine.git] / dlls / msi / action.c
blobb56d06202fd58b4c4d0472359bb2826298724f73
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 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
22 * Pages I need
24 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installexecutesequence_table.asp
26 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/standard_actions_reference.asp
29 #include <stdarg.h>
30 #include <stdio.h>
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winerror.h"
35 #include "winreg.h"
36 #include "wine/debug.h"
37 #include "fdi.h"
38 #include "msi.h"
39 #include "msiquery.h"
40 #include "msvcrt/fcntl.h"
41 #include "objbase.h"
42 #include "objidl.h"
43 #include "msipriv.h"
44 #include "winnls.h"
45 #include "winuser.h"
46 #include "shlobj.h"
47 #include "wine/unicode.h"
48 #include "ver.h"
50 #define CUSTOM_ACTION_TYPE_MASK 0x3F
52 WINE_DEFAULT_DEBUG_CHANNEL(msi);
54 typedef struct tagMSIFEATURE
56 WCHAR Feature[96];
57 WCHAR Feature_Parent[96];
58 WCHAR Title[0x100];
59 WCHAR Description[0x100];
60 INT Display;
61 INT Level;
62 WCHAR Directory[96];
63 INT Attributes;
65 INSTALLSTATE State;
66 BOOL Enabled;
67 INT ComponentCount;
68 INT Components[1024]; /* yes hardcoded limit.... I am bad */
69 INT Cost;
70 } MSIFEATURE;
72 typedef struct tagMSICOMPONENT
74 WCHAR Component[96];
75 WCHAR ComponentId[96];
76 WCHAR Directory[96];
77 INT Attributes;
78 WCHAR Condition[0x100];
79 WCHAR KeyPath[96];
81 INSTALLSTATE State;
82 BOOL FeatureState;
83 BOOL Enabled;
84 INT Cost;
85 } MSICOMPONENT;
87 typedef struct tagMSIFOLDER
89 WCHAR Directory[96];
90 WCHAR TargetDefault[96];
91 WCHAR SourceDefault[96];
93 WCHAR ResolvedTarget[MAX_PATH];
94 WCHAR ResolvedSource[MAX_PATH];
95 WCHAR Property[MAX_PATH]; /* initially set property */
96 INT ParentIndex;
97 INT State;
98 /* 0 = uninitialized */
99 /* 1 = existing */
100 /* 2 = created remove if empty */
101 /* 3 = created persist if empty */
102 INT Cost;
103 INT Space;
104 }MSIFOLDER;
106 typedef struct tagMSIFILE
108 WCHAR File[72];
109 INT ComponentIndex;
110 WCHAR FileName[MAX_PATH];
111 INT FileSize;
112 WCHAR Version[72];
113 WCHAR Language[20];
114 INT Attributes;
115 INT Sequence;
117 INT State;
118 /* 0 = uninitialize */
119 /* 1 = not present */
120 /* 2 = present but replace */
121 /* 3 = present do not replace */
122 /* 4 = Installed */
123 WCHAR SourcePath[MAX_PATH];
124 WCHAR TargetPath[MAX_PATH];
125 BOOL Temporary;
126 }MSIFILE;
129 * Prototypes
131 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran);
132 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package);
134 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action);
136 static UINT ACTION_LaunchConditions(MSIPACKAGE *package);
137 static UINT ACTION_CostInitialize(MSIPACKAGE *package);
138 static UINT ACTION_CreateFolders(MSIPACKAGE *package);
139 static UINT ACTION_CostFinalize(MSIPACKAGE *package);
140 static UINT ACTION_FileCost(MSIPACKAGE *package);
141 static UINT ACTION_InstallFiles(MSIPACKAGE *package);
142 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package);
143 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package);
144 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action);
145 static UINT ACTION_InstallInitialize(MSIPACKAGE *package);
146 static UINT ACTION_InstallValidate(MSIPACKAGE *package);
147 static UINT ACTION_ProcessComponents(MSIPACKAGE *package);
148 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package);
149 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package);
150 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package);
151 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package);
152 static UINT ACTION_PublishProduct(MSIPACKAGE *package);
154 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
155 const LPWSTR target, const INT type);
156 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
157 const LPWSTR target, const INT type);
159 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data);
160 static UINT resolve_folder(MSIPACKAGE *package, LPCWSTR name, LPWSTR path,
161 BOOL source, BOOL set_prop, MSIFOLDER **folder);
163 static int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path);
166 * consts and values used
168 static const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
169 static const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
170 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
171 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
172 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
173 static const WCHAR c_collen[] = {'C',':','\\',0};
175 static const WCHAR cszlsb[]={'[',0};
176 static const WCHAR cszrsb[]={']',0};
177 static const WCHAR cszbs[]={'\\',0};
179 const static WCHAR szCreateFolders[] =
180 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
181 const static WCHAR szCostFinalize[] =
182 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
183 const static WCHAR szInstallFiles[] =
184 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
185 const static WCHAR szDuplicateFiles[] =
186 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
187 const static WCHAR szWriteRegistryValues[] =
188 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
189 const static WCHAR szCostInitialize[] =
190 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
191 const static WCHAR szFileCost[] = {'F','i','l','e','C','o','s','t',0};
192 const static WCHAR szInstallInitialize[] =
193 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
194 const static WCHAR szInstallValidate[] =
195 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
196 const static WCHAR szLaunchConditions[] =
197 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
198 const static WCHAR szProcessComponents[] =
199 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
200 const static WCHAR szRegisterTypeLibraries[] =
201 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r',
202 'i','e','s',0};
203 const static WCHAR szRegisterClassInfo[] =
204 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
205 const static WCHAR szRegisterProgIdInfo[] =
206 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
207 const static WCHAR szCreateShortcuts[] =
208 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
209 const static WCHAR szPublishProduct[] =
210 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
212 /********************************************************
213 * helper functions to get around current HACKS and such
214 ********************************************************/
215 inline static void reduce_to_longfilename(WCHAR* filename)
217 if (strchrW(filename,'|'))
219 WCHAR newname[MAX_PATH];
220 strcpyW(newname,strchrW(filename,'|')+1);
221 strcpyW(filename,newname);
225 inline static char *strdupWtoA( const WCHAR *str )
227 char *ret = NULL;
228 if (str)
230 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL
232 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
233 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
235 return ret;
238 inline static WCHAR *strdupAtoW( const char *str )
240 WCHAR *ret = NULL;
241 if (str)
243 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
244 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
245 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
247 return ret;
250 inline static WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
252 UINT rc;
253 DWORD sz;
254 LPWSTR ret;
256 sz = 0;
257 rc = MSI_RecordGetStringW(row,index,NULL,&sz);
258 if (sz <= 0)
259 return NULL;
261 sz ++;
262 ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
263 rc = MSI_RecordGetStringW(row,index,ret,&sz);
264 return ret;
267 inline static int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
269 int rc = -1;
270 DWORD i;
272 for (i = 0; i < package->loaded_components; i++)
274 if (strcmpW(Component,package->components[i].Component)==0)
276 rc = i;
277 break;
280 return rc;
283 inline static int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
285 int rc = -1;
286 DWORD i;
288 for (i = 0; i < package->loaded_features; i++)
290 if (strcmpW(Feature,package->features[i].Feature)==0)
292 rc = i;
293 break;
296 return rc;
299 inline static int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
301 int rc = -1;
302 DWORD i;
304 for (i = 0; i < package->loaded_files; i++)
306 if (strcmpW(file,package->files[i].File)==0)
308 rc = i;
309 break;
312 return rc;
315 static int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
317 DWORD i;
318 DWORD index;
320 if (!package)
321 return -2;
323 for (i=0; i < package->loaded_files; i++)
324 if (strcmpW(package->files[i].File,name)==0)
325 return -1;
327 index = package->loaded_files;
328 package->loaded_files++;
329 if (package->loaded_files== 1)
330 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
331 else
332 package->files = HeapReAlloc(GetProcessHeap(),0,
333 package->files , package->loaded_files * sizeof(MSIFILE));
335 memset(&package->files[index],0,sizeof(MSIFILE));
337 strcpyW(package->files[index].File,name);
338 strcpyW(package->files[index].TargetPath,path);
339 package->files[index].Temporary = TRUE;
341 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
343 return 0;
346 void ACTION_remove_tracked_tempfiles(MSIPACKAGE* package)
348 DWORD i;
350 if (!package)
351 return;
353 for (i = 0; i < package->loaded_files; i++)
355 if (package->files[i].Temporary)
356 DeleteFileW(package->files[i].TargetPath);
361 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
363 MSIRECORD * row;
365 row = MSI_CreateRecord(4);
366 MSI_RecordSetInteger(row,1,a);
367 MSI_RecordSetInteger(row,2,b);
368 MSI_RecordSetInteger(row,3,c);
369 MSI_RecordSetInteger(row,4,d);
370 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
371 msiobj_release(&row->hdr);
374 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
376 static const WCHAR Query_t[] =
377 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
378 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
379 ' ','\'','%','s','\'',0};
380 WCHAR message[1024];
381 UINT rc;
382 MSIQUERY * view;
383 MSIRECORD * row = 0;
384 static WCHAR *ActionFormat=NULL;
385 static WCHAR LastAction[0x100] = {0};
386 WCHAR Query[1024];
387 LPWSTR ptr;
389 if (strcmpW(LastAction,action)!=0)
391 sprintfW(Query,Query_t,action);
392 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
393 if (rc != ERROR_SUCCESS)
394 return;
395 rc = MSI_ViewExecute(view, 0);
396 if (rc != ERROR_SUCCESS)
398 MSI_ViewClose(view);
399 return;
401 rc = MSI_ViewFetch(view,&row);
402 if (rc != ERROR_SUCCESS)
404 MSI_ViewClose(view);
405 return;
408 if (MSI_RecordIsNull(row,3))
410 msiobj_release(&row->hdr);
411 MSI_ViewClose(view);
412 msiobj_release(&view->hdr);
413 return;
416 if (ActionFormat)
417 HeapFree(GetProcessHeap(),0,ActionFormat);
419 ActionFormat = load_dynamic_stringW(row,3);
420 strcpyW(LastAction,action);
421 msiobj_release(&row->hdr);
422 MSI_ViewClose(view);
423 msiobj_release(&view->hdr);
426 message[0]=0;
427 ptr = ActionFormat;
428 while (*ptr)
430 LPWSTR ptr2;
431 LPWSTR data=NULL;
432 WCHAR tmp[1023];
433 INT field;
435 ptr2 = strchrW(ptr,'[');
436 if (ptr2)
438 strncpyW(tmp,ptr,ptr2-ptr);
439 tmp[ptr2-ptr]=0;
440 strcatW(message,tmp);
441 ptr2++;
442 field = atoiW(ptr2);
443 data = load_dynamic_stringW(record,field);
444 if (data)
446 strcatW(message,data);
447 HeapFree(GetProcessHeap(),0,data);
449 ptr=strchrW(ptr2,']');
450 ptr++;
452 else
454 strcatW(message,ptr);
455 break;
459 row = MSI_CreateRecord(1);
460 MSI_RecordSetStringW(row,1,message);
462 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
463 msiobj_release(&row->hdr);
467 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
469 static const WCHAR template_s[]=
470 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ','%','s','.',0};
471 static const WCHAR format[] =
472 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
473 static const WCHAR Query_t[] =
474 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
475 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
476 ' ','\'','%','s','\'',0};
477 WCHAR message[1024];
478 WCHAR timet[0x100];
479 UINT rc;
480 MSIQUERY * view;
481 MSIRECORD * row = 0;
482 WCHAR *ActionText=NULL;
483 WCHAR Query[1024];
485 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
487 sprintfW(Query,Query_t,action);
488 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
489 if (rc != ERROR_SUCCESS)
490 return;
491 rc = MSI_ViewExecute(view, 0);
492 if (rc != ERROR_SUCCESS)
494 MSI_ViewClose(view);
495 msiobj_release(&view->hdr);
496 return;
498 rc = MSI_ViewFetch(view,&row);
499 if (rc != ERROR_SUCCESS)
501 MSI_ViewClose(view);
502 msiobj_release(&view->hdr);
503 return;
506 ActionText = load_dynamic_stringW(row,2);
507 msiobj_release(&row->hdr);
508 MSI_ViewClose(view);
509 msiobj_release(&view->hdr);
511 sprintfW(message,template_s,timet,action,ActionText);
513 row = MSI_CreateRecord(1);
514 MSI_RecordSetStringW(row,1,message);
516 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
517 msiobj_release(&row->hdr);
518 HeapFree(GetProcessHeap(),0,ActionText);
521 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
522 UINT rc)
524 MSIRECORD * row;
525 static const WCHAR template_s[]=
526 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ','%','s',
527 '.',0};
528 static const WCHAR template_e[]=
529 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ','%','s',
530 '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ','%','i','.',0};
531 static const WCHAR format[] =
532 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
533 WCHAR message[1024];
534 WCHAR timet[0x100];
536 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
537 if (start)
538 sprintfW(message,template_s,timet,action);
539 else
540 sprintfW(message,template_e,timet,action,rc);
542 row = MSI_CreateRecord(1);
543 MSI_RecordSetStringW(row,1,message);
545 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
546 msiobj_release(&row->hdr);
549 /****************************************************
550 * TOP level entry points
551 *****************************************************/
553 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
554 LPCWSTR szCommandLine)
556 DWORD sz;
557 WCHAR buffer[10];
558 UINT rc;
559 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
561 if (szPackagePath)
563 LPWSTR p;
564 WCHAR check[MAX_PATH];
565 WCHAR pth[MAX_PATH];
566 DWORD size;
568 strcpyW(pth,szPackagePath);
569 p = strrchrW(pth,'\\');
570 if (p)
572 p++;
573 *p=0;
576 size = MAX_PATH;
577 if (MSI_GetPropertyW(package,cszSourceDir,check,&size)
578 != ERROR_SUCCESS )
579 MSI_SetPropertyW(package, cszSourceDir, pth);
582 if (szCommandLine)
584 LPWSTR ptr,ptr2;
585 ptr = (LPWSTR)szCommandLine;
587 while (*ptr)
589 WCHAR prop[0x100];
590 WCHAR val[0x100];
592 TRACE("Looking at %s\n",debugstr_w(ptr));
594 ptr2 = strchrW(ptr,'=');
595 if (ptr2)
597 BOOL quote=FALSE;
598 DWORD len = 0;
600 while (*ptr == ' ') ptr++;
601 strncpyW(prop,ptr,ptr2-ptr);
602 prop[ptr2-ptr]=0;
603 ptr2++;
605 ptr = ptr2;
606 while (*ptr && (quote || (!quote && *ptr!=' ')))
608 if (*ptr == '"')
609 quote = !quote;
610 ptr++;
611 len++;
614 if (*ptr2=='"')
616 ptr2++;
617 len -= 2;
619 strncpyW(val,ptr2,len);
620 val[len]=0;
622 if (strlenW(prop) > 0)
624 TRACE("Found commandline property (%s) = (%s)\n", debugstr_w(prop), debugstr_w(val));
625 MSI_SetPropertyW(package,prop,val);
628 ptr++;
632 sz = 10;
633 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
635 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
637 rc = ACTION_ProcessUISequence(package);
638 if (rc == ERROR_SUCCESS)
639 rc = ACTION_ProcessExecSequence(package,TRUE);
641 else
642 rc = ACTION_ProcessExecSequence(package,FALSE);
644 else
645 rc = ACTION_ProcessExecSequence(package,FALSE);
647 return rc;
651 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
653 MSIQUERY * view;
654 UINT rc;
655 static const WCHAR ExecSeqQuery[] = {
656 's','e','l','e','c','t',' ','*',' ',
657 'f','r','o','m',' ',
658 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
659 'S','e','q','u','e','n','c','e',' ',
660 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
661 '>',' ','%','i',' ','o','r','d','e','r',' ',
662 'b','y',' ','S','e','q','u','e','n','c','e',0 };
663 WCHAR Query[1024];
664 MSIRECORD * row = 0;
665 static const WCHAR IVQuery[] = {
666 's','e','l','e','c','t',' ','S','e','q','u','e','n','c','e',' ',
667 'f','r','o','m',' ','I','n','s','t','a','l','l',
668 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
669 'w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',' ',
670 '`','I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`',
673 if (UIran)
675 INT seq = 0;
677 rc = MSI_DatabaseOpenViewW(package->db, IVQuery, &view);
678 if (rc != ERROR_SUCCESS)
679 return rc;
680 rc = MSI_ViewExecute(view, 0);
681 if (rc != ERROR_SUCCESS)
683 MSI_ViewClose(view);
684 msiobj_release(&view->hdr);
685 return rc;
687 rc = MSI_ViewFetch(view,&row);
688 if (rc != ERROR_SUCCESS)
690 MSI_ViewClose(view);
691 msiobj_release(&view->hdr);
692 return rc;
694 seq = MSI_RecordGetInteger(row,1);
695 msiobj_release(&row->hdr);
696 MSI_ViewClose(view);
697 msiobj_release(&view->hdr);
698 sprintfW(Query,ExecSeqQuery,seq);
700 else
701 sprintfW(Query,ExecSeqQuery,0);
703 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
704 if (rc == ERROR_SUCCESS)
706 rc = MSI_ViewExecute(view, 0);
708 if (rc != ERROR_SUCCESS)
710 MSI_ViewClose(view);
711 msiobj_release(&view->hdr);
712 goto end;
715 TRACE("Running the actions \n");
717 while (1)
719 WCHAR buffer[0x100];
720 DWORD sz = 0x100;
722 rc = MSI_ViewFetch(view,&row);
723 if (rc != ERROR_SUCCESS)
725 rc = ERROR_SUCCESS;
726 break;
729 /* check conditions */
730 if (!MSI_RecordIsNull(row,2))
732 LPWSTR cond = NULL;
733 cond = load_dynamic_stringW(row,2);
735 if (cond)
737 /* this is a hack to skip errors in the condition code */
738 if (MSI_EvaluateConditionW(package, cond) ==
739 MSICONDITION_FALSE)
741 HeapFree(GetProcessHeap(),0,cond);
742 msiobj_release(&row->hdr);
743 continue;
745 else
746 HeapFree(GetProcessHeap(),0,cond);
750 sz=0x100;
751 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
752 if (rc != ERROR_SUCCESS)
754 ERR("Error is %x\n",rc);
755 msiobj_release(&row->hdr);
756 break;
759 rc = ACTION_PerformAction(package,buffer);
761 if (rc != ERROR_SUCCESS)
763 ERR("Execution halted due to error (%i)\n",rc);
764 msiobj_release(&row->hdr);
765 break;
768 msiobj_release(&row->hdr);
771 MSI_ViewClose(view);
772 msiobj_release(&view->hdr);
775 end:
776 return rc;
780 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
782 MSIQUERY * view;
783 UINT rc;
784 static const WCHAR ExecSeqQuery [] = {
785 's','e','l','e','c','t',' ','*',' ',
786 'f','r','o','m',' ','I','n','s','t','a','l','l',
787 'U','I','S','e','q','u','e','n','c','e',' ',
788 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ', '>',' ','0',' ',
789 'o','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e',0};
791 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
793 if (rc == ERROR_SUCCESS)
795 rc = MSI_ViewExecute(view, 0);
797 if (rc != ERROR_SUCCESS)
799 MSI_ViewClose(view);
800 msiobj_release(&view->hdr);
801 goto end;
804 TRACE("Running the actions \n");
806 while (1)
808 WCHAR buffer[0x100];
809 DWORD sz = 0x100;
810 MSIRECORD * row = 0;
812 rc = MSI_ViewFetch(view,&row);
813 if (rc != ERROR_SUCCESS)
815 rc = ERROR_SUCCESS;
816 break;
819 /* check conditions */
820 if (!MSI_RecordIsNull(row,2))
822 LPWSTR cond = NULL;
823 cond = load_dynamic_stringW(row,2);
825 if (cond)
827 /* this is a hack to skip errors in the condition code */
828 if (MSI_EvaluateConditionW(package, cond) ==
829 MSICONDITION_FALSE)
831 HeapFree(GetProcessHeap(),0,cond);
832 msiobj_release(&row->hdr);
833 continue;
835 else
836 HeapFree(GetProcessHeap(),0,cond);
840 sz=0x100;
841 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
842 if (rc != ERROR_SUCCESS)
844 ERR("Error is %x\n",rc);
845 msiobj_release(&row->hdr);
846 break;
849 rc = ACTION_PerformAction(package,buffer);
851 if (rc != ERROR_SUCCESS)
853 ERR("Execution halted due to error (%i)\n",rc);
854 msiobj_release(&row->hdr);
855 break;
858 msiobj_release(&row->hdr);
861 MSI_ViewClose(view);
862 msiobj_release(&view->hdr);
865 end:
866 return rc;
869 /********************************************************
870 * ACTION helper functions and functions that perform the actions
871 *******************************************************/
874 * Alot of actions are really important even if they don't do anything
875 * explicit.. Lots of properties are set at the beginning of the installation
876 * CostFinalize does a bunch of work to translated the directories and such
878 * But until I get write access to the database that is hard, so I am going to
879 * hack it to see if I can get something to run.
881 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action)
883 UINT rc = ERROR_SUCCESS;
885 TRACE("Performing action (%s)\n",debugstr_w(action));
886 ui_actioninfo(package, action, TRUE, 0);
887 ui_actionstart(package, action);
888 ui_progress(package,2,1,0,0);
890 /* pre install, setup and configuration block */
891 if (strcmpW(action,szLaunchConditions)==0)
892 rc = ACTION_LaunchConditions(package);
893 else if (strcmpW(action,szCostInitialize)==0)
894 rc = ACTION_CostInitialize(package);
895 else if (strcmpW(action,szFileCost)==0)
896 rc = ACTION_FileCost(package);
897 else if (strcmpW(action,szCostFinalize)==0)
898 rc = ACTION_CostFinalize(package);
899 else if (strcmpW(action,szInstallValidate)==0)
900 rc = ACTION_InstallValidate(package);
902 /* install block */
903 else if (strcmpW(action,szProcessComponents)==0)
904 rc = ACTION_ProcessComponents(package);
905 else if (strcmpW(action,szInstallInitialize)==0)
906 rc = ACTION_InstallInitialize(package);
907 else if (strcmpW(action,szCreateFolders)==0)
908 rc = ACTION_CreateFolders(package);
909 else if (strcmpW(action,szInstallFiles)==0)
910 rc = ACTION_InstallFiles(package);
911 else if (strcmpW(action,szDuplicateFiles)==0)
912 rc = ACTION_DuplicateFiles(package);
913 else if (strcmpW(action,szWriteRegistryValues)==0)
914 rc = ACTION_WriteRegistryValues(package);
915 else if (strcmpW(action,szRegisterTypeLibraries)==0)
916 rc = ACTION_RegisterTypeLibraries(package);
917 else if (strcmpW(action,szRegisterClassInfo)==0)
918 rc = ACTION_RegisterClassInfo(package);
919 else if (strcmpW(action,szRegisterProgIdInfo)==0)
920 rc = ACTION_RegisterProgIdInfo(package);
921 else if (strcmpW(action,szCreateShortcuts)==0)
922 rc = ACTION_CreateShortcuts(package);
923 else if (strcmpW(action,szPublishProduct)==0)
924 rc = ACTION_PublishProduct(package);
927 Called during iTunes but unimplemented and seem important
929 ResolveSource (sets SourceDir)
930 RegisterProduct
931 InstallFinalize
933 else if ((rc = ACTION_CustomAction(package,action)) != ERROR_SUCCESS)
935 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
936 rc = ERROR_SUCCESS;
939 ui_actioninfo(package, action, FALSE, rc);
940 return rc;
944 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action)
946 UINT rc = ERROR_SUCCESS;
947 MSIQUERY * view;
948 MSIRECORD * row = 0;
949 WCHAR ExecSeqQuery[1024] =
950 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','C','u','s','t','o'
951 ,'m','A','c','t','i','o','n',' ','w','h','e','r','e',' ','`','A','c','t','i'
952 ,'o','n','`',' ','=',' ','`',0};
953 static const WCHAR end[]={'`',0};
954 UINT type;
955 LPWSTR source;
956 LPWSTR target;
957 WCHAR *deformated=NULL;
959 strcatW(ExecSeqQuery,action);
960 strcatW(ExecSeqQuery,end);
962 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
964 if (rc != ERROR_SUCCESS)
965 return rc;
967 rc = MSI_ViewExecute(view, 0);
968 if (rc != ERROR_SUCCESS)
970 MSI_ViewClose(view);
971 msiobj_release(&view->hdr);
972 return rc;
975 rc = MSI_ViewFetch(view,&row);
976 if (rc != ERROR_SUCCESS)
978 MSI_ViewClose(view);
979 msiobj_release(&view->hdr);
980 return rc;
983 type = MSI_RecordGetInteger(row,2);
985 source = load_dynamic_stringW(row,3);
986 target = load_dynamic_stringW(row,4);
988 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
989 debugstr_w(source), debugstr_w(target));
991 /* we are ignoring ALOT of flags and important synchronization stuff */
992 switch (type & CUSTOM_ACTION_TYPE_MASK)
994 case 1: /* DLL file stored in a Binary table stream */
995 rc = HANDLE_CustomType1(package,source,target,type);
996 break;
997 case 2: /* EXE file stored in a Binary table strem */
998 rc = HANDLE_CustomType2(package,source,target,type);
999 break;
1000 case 35: /* Directory set with formatted text. */
1001 case 51: /* Property set with formatted text. */
1002 deformat_string(package,target,&deformated);
1003 rc = MSI_SetPropertyW(package,source,deformated);
1004 HeapFree(GetProcessHeap(),0,deformated);
1005 break;
1006 default:
1007 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
1008 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
1009 debugstr_w(target));
1012 HeapFree(GetProcessHeap(),0,source);
1013 HeapFree(GetProcessHeap(),0,target);
1014 msiobj_release(&row->hdr);
1015 MSI_ViewClose(view);
1016 msiobj_release(&view->hdr);
1017 return rc;
1020 static UINT store_binary_to_temp(MSIPACKAGE *package, const LPWSTR source,
1021 LPWSTR tmp_file)
1023 DWORD sz=MAX_PATH;
1025 if (MSI_GetPropertyW(package, cszTempFolder, tmp_file, &sz)
1026 != ERROR_SUCCESS)
1027 GetTempPathW(MAX_PATH,tmp_file);
1029 strcatW(tmp_file,source);
1031 if (GetFileAttributesW(tmp_file) != INVALID_FILE_ATTRIBUTES)
1033 TRACE("File already exists\n");
1034 return ERROR_SUCCESS;
1036 else
1038 /* write out the file */
1039 UINT rc;
1040 MSIQUERY * view;
1041 MSIRECORD * row = 0;
1042 WCHAR Query[1024] =
1043 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','B','i'
1044 ,'n','a','r','y',' ','w','h','e','r','e',' ','N','a','m','e','=','`',0};
1045 static const WCHAR end[]={'`',0};
1046 HANDLE the_file;
1047 CHAR buffer[1024];
1049 if (track_tempfile(package, source, tmp_file)!=0)
1050 FIXME("File Name in temp tracking collision\n");
1052 the_file = CreateFileW(tmp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1053 FILE_ATTRIBUTE_NORMAL, NULL);
1055 if (the_file == INVALID_HANDLE_VALUE)
1056 return ERROR_FUNCTION_FAILED;
1058 strcatW(Query,source);
1059 strcatW(Query,end);
1061 rc = MSI_DatabaseOpenViewW( package->db, Query, &view);
1062 if (rc != ERROR_SUCCESS)
1063 return rc;
1065 rc = MSI_ViewExecute(view, 0);
1066 if (rc != ERROR_SUCCESS)
1068 MSI_ViewClose(view);
1069 msiobj_release(&view->hdr);
1070 return rc;
1073 rc = MSI_ViewFetch(view,&row);
1074 if (rc != ERROR_SUCCESS)
1076 MSI_ViewClose(view);
1077 msiobj_release(&view->hdr);
1078 return rc;
1083 DWORD write;
1084 sz = 1024;
1085 rc = MSI_RecordReadStream(row,2,buffer,&sz);
1086 if (rc != ERROR_SUCCESS)
1088 ERR("Failed to get stream\n");
1089 CloseHandle(the_file);
1090 DeleteFileW(tmp_file);
1091 break;
1093 WriteFile(the_file,buffer,sz,&write,NULL);
1094 } while (sz == 1024);
1096 CloseHandle(the_file);
1098 msiobj_release(&row->hdr);
1099 MSI_ViewClose(view);
1100 msiobj_release(&view->hdr);
1103 return ERROR_SUCCESS;
1107 typedef UINT __stdcall CustomEntry(MSIHANDLE);
1108 typedef struct
1110 MSIPACKAGE *package;
1111 WCHAR target[MAX_PATH];
1112 WCHAR source[MAX_PATH];
1113 } thread_struct;
1115 #if 0
1116 static DWORD WINAPI DllThread(LPVOID info)
1118 HANDLE DLL;
1119 LPSTR proc;
1120 thread_struct *stuff;
1121 CustomEntry *fn;
1123 stuff = (thread_struct*)info;
1125 TRACE("Asynchronous start (%s, %s) \n", debugstr_w(stuff->source),
1126 debugstr_w(stuff->target));
1128 DLL = LoadLibraryW(stuff->source);
1129 if (DLL)
1131 proc = strdupWtoA( stuff->target );
1132 fn = (CustomEntry*)GetProcAddress(DLL,proc);
1133 if (fn)
1135 MSIHANDLE hPackage;
1136 MSIPACKAGE *package = stuff->package;
1138 TRACE("Calling function\n");
1139 hPackage = msiobj_findhandle( &package->hdr );
1140 if( !hPackage )
1141 ERR("Handle for object %p not found\n", package );
1142 fn(hPackage);
1143 msiobj_release( &package->hdr );
1145 else
1146 ERR("Cannot load functon\n");
1148 HeapFree(GetProcessHeap(),0,proc);
1149 FreeLibrary(DLL);
1151 else
1152 ERR("Unable to load library\n");
1153 msiobj_release( &stuff->package->hdr );
1154 HeapFree( GetProcessHeap(), 0, info );
1155 return 0;
1157 #endif
1159 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
1160 const LPWSTR target, const INT type)
1162 WCHAR tmp_file[MAX_PATH];
1163 CustomEntry *fn;
1164 HANDLE DLL;
1165 LPSTR proc;
1167 store_binary_to_temp(package, source, tmp_file);
1169 TRACE("Calling function %s from %s\n",debugstr_w(target),
1170 debugstr_w(tmp_file));
1172 if (!strchrW(tmp_file,'.'))
1174 static const WCHAR dot[]={'.',0};
1175 strcatW(tmp_file,dot);
1178 if (type & 0xc0)
1180 /* DWORD ThreadId; */
1181 thread_struct *info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) );
1183 /* msiobj_addref( &package->hdr ); */
1184 info->package = package;
1185 strcpyW(info->target,target);
1186 strcpyW(info->source,tmp_file);
1187 TRACE("Start Asynchronous execution\n");
1188 FIXME("DATABASE NOT THREADSAFE... not starting\n");
1189 /* CreateThread(NULL,0,DllThread,(LPVOID)&info,0,&ThreadId); */
1190 /* FIXME: release the package if the CreateThread fails */
1191 HeapFree( GetProcessHeap(), 0, info );
1192 return ERROR_SUCCESS;
1195 DLL = LoadLibraryW(tmp_file);
1196 if (DLL)
1198 proc = strdupWtoA( target );
1199 fn = (CustomEntry*)GetProcAddress(DLL,proc);
1200 if (fn)
1202 MSIHANDLE hPackage;
1204 TRACE("Calling function\n");
1205 hPackage = msiobj_findhandle( &package->hdr );
1206 if( !hPackage )
1207 ERR("Handle for object %p not found\n", package );
1208 fn(hPackage);
1209 msiobj_release( &package->hdr );
1211 else
1212 ERR("Cannot load functon\n");
1214 HeapFree(GetProcessHeap(),0,proc);
1215 FreeLibrary(DLL);
1217 else
1218 ERR("Unable to load library\n");
1220 return ERROR_SUCCESS;
1223 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
1224 const LPWSTR target, const INT type)
1226 WCHAR tmp_file[MAX_PATH*2];
1227 STARTUPINFOW si;
1228 PROCESS_INFORMATION info;
1229 BOOL rc;
1230 WCHAR *deformated;
1231 static const WCHAR spc[] = {' ',0};
1233 memset(&si,0,sizeof(STARTUPINFOW));
1234 memset(&info,0,sizeof(PROCESS_INFORMATION));
1236 store_binary_to_temp(package, source, tmp_file);
1238 strcatW(tmp_file,spc);
1239 deformat_string(package,target,&deformated);
1240 strcatW(tmp_file,deformated);
1242 HeapFree(GetProcessHeap(),0,deformated);
1244 TRACE("executing exe %s \n",debugstr_w(tmp_file));
1246 rc = CreateProcessW(NULL, tmp_file, NULL, NULL, FALSE, 0, NULL,
1247 c_collen, &si, &info);
1249 if ( !rc )
1251 ERR("Unable to execute command\n");
1252 return ERROR_SUCCESS;
1255 if (!(type & 0xc0))
1256 WaitForSingleObject(info.hProcess,INFINITE);
1258 return ERROR_SUCCESS;
1261 /***********************************************************************
1262 * create_full_pathW
1264 * Recursively create all directories in the path.
1266 * shamelessly stolen from setupapi/queue.c
1268 static BOOL create_full_pathW(const WCHAR *path)
1270 BOOL ret = TRUE;
1271 int len;
1272 WCHAR *new_path;
1274 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1275 sizeof(WCHAR));
1276 strcpyW(new_path, path);
1278 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1279 new_path[len - 1] = 0;
1281 while(!CreateDirectoryW(new_path, NULL))
1283 WCHAR *slash;
1284 DWORD last_error = GetLastError();
1285 if(last_error == ERROR_ALREADY_EXISTS)
1286 break;
1288 if(last_error != ERROR_PATH_NOT_FOUND)
1290 ret = FALSE;
1291 break;
1294 if(!(slash = strrchrW(new_path, '\\')))
1296 ret = FALSE;
1297 break;
1300 len = slash - new_path;
1301 new_path[len] = 0;
1302 if(!create_full_pathW(new_path))
1304 ret = FALSE;
1305 break;
1307 new_path[len] = '\\';
1310 HeapFree(GetProcessHeap(), 0, new_path);
1311 return ret;
1315 * Also we cannot enable/disable components either, so for now I am just going
1316 * to do all the directories for all the components.
1318 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1320 static const WCHAR ExecSeqQuery[] = {
1321 's','e','l','e','c','t',' ','D','i','r','e','c','t','o','r','y','_',' ',
1322 'f','r','o','m',' ','C','r','e','a','t','e','F','o','l','d','e','r',0 };
1323 UINT rc;
1324 MSIQUERY *view;
1325 MSIFOLDER *folder;
1327 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1328 if (rc != ERROR_SUCCESS)
1329 return ERROR_SUCCESS;
1331 rc = MSI_ViewExecute(view, 0);
1332 if (rc != ERROR_SUCCESS)
1334 MSI_ViewClose(view);
1335 msiobj_release(&view->hdr);
1336 return rc;
1339 while (1)
1341 WCHAR dir[0x100];
1342 WCHAR full_path[MAX_PATH];
1343 DWORD sz;
1344 MSIRECORD *row = NULL, *uirow;
1346 rc = MSI_ViewFetch(view,&row);
1347 if (rc != ERROR_SUCCESS)
1349 rc = ERROR_SUCCESS;
1350 break;
1353 sz=0x100;
1354 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1356 if (rc!= ERROR_SUCCESS)
1358 ERR("Unable to get folder id \n");
1359 msiobj_release(&row->hdr);
1360 continue;
1363 sz = MAX_PATH;
1364 rc = resolve_folder(package,dir,full_path,FALSE,FALSE,&folder);
1366 if (rc != ERROR_SUCCESS)
1368 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1369 msiobj_release(&row->hdr);
1370 continue;
1373 TRACE("Folder is %s\n",debugstr_w(full_path));
1375 /* UI stuff */
1376 uirow = MSI_CreateRecord(1);
1377 MSI_RecordSetStringW(uirow,1,full_path);
1378 ui_actiondata(package,szCreateFolders,uirow);
1379 msiobj_release( &uirow->hdr );
1381 if (folder->State == 0)
1382 create_full_pathW(full_path);
1384 folder->State = 3;
1386 msiobj_release(&row->hdr);
1388 MSI_ViewClose(view);
1389 msiobj_release(&view->hdr);
1391 return rc;
1394 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1396 int index = package->loaded_components;
1397 DWORD sz;
1399 /* fill in the data */
1401 package->loaded_components++;
1402 if (package->loaded_components == 1)
1403 package->components = HeapAlloc(GetProcessHeap(),0,
1404 sizeof(MSICOMPONENT));
1405 else
1406 package->components = HeapReAlloc(GetProcessHeap(),0,
1407 package->components, package->loaded_components *
1408 sizeof(MSICOMPONENT));
1410 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1412 sz = 96;
1413 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1415 TRACE("Loading Component %s\n",
1416 debugstr_w(package->components[index].Component));
1418 sz = 0x100;
1419 if (!MSI_RecordIsNull(row,2))
1420 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1422 sz = 96;
1423 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1425 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1427 sz = 0x100;
1428 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1430 sz = 96;
1431 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1433 package->components[index].State = INSTALLSTATE_UNKNOWN;
1434 package->components[index].Enabled = TRUE;
1435 package->components[index].FeatureState= FALSE;
1437 return index;
1440 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1442 int index = package->loaded_features;
1443 DWORD sz;
1444 static const WCHAR Query1[] = {'S','E','L','E','C','T',' ','C','o','m','p',
1445 'o','n','e','n','t','_',' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1446 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ','F','e',
1447 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1448 static const WCHAR Query2[] = {'S','E','L','E','C','T',' ','*',' ','F','R',
1449 'O','M',' ','C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ','C',
1450 'o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1451 WCHAR Query[1024];
1452 MSIQUERY * view;
1453 MSIQUERY * view2;
1454 MSIRECORD * row2;
1455 MSIRECORD * row3;
1456 UINT rc;
1458 /* fill in the data */
1460 package->loaded_features ++;
1461 if (package->loaded_features == 1)
1462 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1463 else
1464 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1465 package->loaded_features * sizeof(MSIFEATURE));
1467 memset(&package->features[index],0,sizeof(MSIFEATURE));
1469 sz = 96;
1470 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1472 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1474 sz = 96;
1475 if (!MSI_RecordIsNull(row,2))
1476 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1478 sz = 0x100;
1479 if (!MSI_RecordIsNull(row,3))
1480 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1482 sz = 0x100;
1483 if (!MSI_RecordIsNull(row,4))
1484 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1486 if (!MSI_RecordIsNull(row,5))
1487 package->features[index].Display = MSI_RecordGetInteger(row,5);
1489 package->features[index].Level= MSI_RecordGetInteger(row,6);
1491 sz = 96;
1492 if (!MSI_RecordIsNull(row,7))
1493 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1495 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1496 package->features[index].State = INSTALLSTATE_UNKNOWN;
1498 /* load feature components */
1500 sprintfW(Query,Query1,package->features[index].Feature);
1501 rc = MSI_DatabaseOpenViewW(package->db,Query,&view);
1502 if (rc != ERROR_SUCCESS)
1503 return;
1504 rc = MSI_ViewExecute(view,0);
1505 if (rc != ERROR_SUCCESS)
1507 MSI_ViewClose(view);
1508 msiobj_release(&view->hdr);
1509 return;
1511 while (1)
1513 DWORD sz = 0x100;
1514 WCHAR buffer[0x100];
1515 DWORD rc;
1516 INT c_indx;
1517 INT cnt = package->features[index].ComponentCount;
1519 rc = MSI_ViewFetch(view,&row2);
1520 if (rc != ERROR_SUCCESS)
1521 break;
1523 sz = 0x100;
1524 MSI_RecordGetStringW(row2,1,buffer,&sz);
1526 /* check to see if the component is already loaded */
1527 c_indx = get_loaded_component(package,buffer);
1528 if (c_indx != -1)
1530 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1531 c_indx);
1532 package->features[index].Components[cnt] = c_indx;
1533 package->features[index].ComponentCount ++;
1536 sprintfW(Query,Query2,buffer);
1538 rc = MSI_DatabaseOpenViewW(package->db,Query,&view2);
1539 if (rc != ERROR_SUCCESS)
1541 msiobj_release( &row2->hdr );
1542 continue;
1544 rc = MSI_ViewExecute(view2,0);
1545 if (rc != ERROR_SUCCESS)
1547 msiobj_release( &row2->hdr );
1548 MSI_ViewClose(view2);
1549 msiobj_release( &view2->hdr );
1550 continue;
1552 while (1)
1554 DWORD rc;
1556 rc = MSI_ViewFetch(view2,&row3);
1557 if (rc != ERROR_SUCCESS)
1558 break;
1559 c_indx = load_component(package,row3);
1560 msiobj_release( &row3->hdr );
1562 package->features[index].Components[cnt] = c_indx;
1563 package->features[index].ComponentCount ++;
1565 MSI_ViewClose(view2);
1566 msiobj_release( &view2->hdr );
1567 msiobj_release( &row2->hdr );
1569 MSI_ViewClose(view);
1570 msiobj_release(&view->hdr);
1574 * I am not doing any of the costing functionality yet.
1575 * Mostly looking at doing the Component and Feature loading
1577 * The native MSI does ALOT of modification to tables here. Mostly adding alot
1578 * of temporary columns to the Feature and Component tables.
1580 * note: native msi also tracks the short filename. but I am only going to
1581 * track the long ones. Also looking at this directory table
1582 * it appears that the directory table does not get the parents
1583 * resolved base on property only based on their entrys in the
1584 * directory table.
1586 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1588 MSIQUERY * view;
1589 MSIRECORD * row;
1590 DWORD sz;
1591 UINT rc;
1592 static const WCHAR Query_all[] = {
1593 'S','E','L','E','C','T',' ','*',' ',
1594 'F','R','O','M',' ','F','e','a','t','u','r','e',0};
1595 static const WCHAR szCosting[] = {
1596 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1597 static const WCHAR szZero[] = { '0', 0 };
1599 MSI_SetPropertyW(package, szCosting, szZero);
1600 MSI_SetPropertyW(package, cszRootDrive , c_collen);
1602 sz = 0x100;
1603 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1604 if (rc != ERROR_SUCCESS)
1605 return rc;
1606 rc = MSI_ViewExecute(view,0);
1607 if (rc != ERROR_SUCCESS)
1609 MSI_ViewClose(view);
1610 msiobj_release(&view->hdr);
1611 return rc;
1613 while (1)
1615 DWORD rc;
1617 rc = MSI_ViewFetch(view,&row);
1618 if (rc != ERROR_SUCCESS)
1619 break;
1621 load_feature(package,row);
1622 msiobj_release(&row->hdr);
1624 MSI_ViewClose(view);
1625 msiobj_release(&view->hdr);
1627 return ERROR_SUCCESS;
1630 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1632 DWORD index = package->loaded_files;
1633 DWORD i;
1634 WCHAR buffer[0x100];
1635 DWORD sz;
1637 /* fill in the data */
1639 package->loaded_files++;
1640 if (package->loaded_files== 1)
1641 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1642 else
1643 package->files = HeapReAlloc(GetProcessHeap(),0,
1644 package->files , package->loaded_files * sizeof(MSIFILE));
1646 memset(&package->files[index],0,sizeof(MSIFILE));
1648 sz = 72;
1649 MSI_RecordGetStringW(row,1,package->files[index].File,&sz);
1651 sz = 0x100;
1652 MSI_RecordGetStringW(row,2,buffer,&sz);
1654 package->files[index].ComponentIndex = -1;
1655 for (i = 0; i < package->loaded_components; i++)
1656 if (strcmpW(package->components[i].Component,buffer)==0)
1658 package->files[index].ComponentIndex = i;
1659 break;
1661 if (package->files[index].ComponentIndex == -1)
1662 ERR("Unfound Component %s\n",debugstr_w(buffer));
1664 sz = MAX_PATH;
1665 MSI_RecordGetStringW(row,3,package->files[index].FileName,&sz);
1667 reduce_to_longfilename(package->files[index].FileName);
1669 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1671 sz = 72;
1672 if (!MSI_RecordIsNull(row,5))
1673 MSI_RecordGetStringW(row,5,package->files[index].Version,&sz);
1675 sz = 20;
1676 if (!MSI_RecordIsNull(row,6))
1677 MSI_RecordGetStringW(row,6,package->files[index].Language,&sz);
1679 if (!MSI_RecordIsNull(row,7))
1680 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1682 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1684 package->files[index].Temporary = FALSE;
1685 package->files[index].State = 0;
1687 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1689 return ERROR_SUCCESS;
1692 static UINT ACTION_FileCost(MSIPACKAGE *package)
1694 MSIQUERY * view;
1695 MSIRECORD * row;
1696 UINT rc;
1697 static const WCHAR Query[] = {
1698 'S','E','L','E','C','T',' ','*',' ',
1699 'F','R','O','M',' ','F','i','l','e',' ',
1700 'O','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e', 0};
1702 if (!package)
1703 return ERROR_INVALID_HANDLE;
1705 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1706 if (rc != ERROR_SUCCESS)
1707 return ERROR_SUCCESS;
1709 rc = MSI_ViewExecute(view, 0);
1710 if (rc != ERROR_SUCCESS)
1712 MSI_ViewClose(view);
1713 msiobj_release(&view->hdr);
1714 return ERROR_SUCCESS;
1717 while (1)
1719 rc = MSI_ViewFetch(view,&row);
1720 if (rc != ERROR_SUCCESS)
1722 rc = ERROR_SUCCESS;
1723 break;
1725 load_file(package,row);
1726 msiobj_release(&row->hdr);
1728 MSI_ViewClose(view);
1729 msiobj_release(&view->hdr);
1731 return ERROR_SUCCESS;
1734 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1737 WCHAR Query[1024] =
1738 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','D','i','r','e','c',
1739 't','o','r','y',' ','w','h','e','r','e',' ','`','D','i','r','e','c','t',
1740 'o','r','y','`',' ','=',' ','`',0};
1741 static const WCHAR end[]={'`',0};
1742 UINT rc;
1743 MSIQUERY * view;
1744 WCHAR targetbuffer[0x100];
1745 WCHAR *srcdir = NULL;
1746 WCHAR *targetdir = NULL;
1747 WCHAR parent[0x100];
1748 DWORD sz=0x100;
1749 MSIRECORD * row = 0;
1750 INT index = -1;
1751 DWORD i;
1753 TRACE("Looking for dir %s\n",debugstr_w(dir));
1755 for (i = 0; i < package->loaded_folders; i++)
1757 if (strcmpW(package->folders[i].Directory,dir)==0)
1759 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
1760 return i;
1764 TRACE("Working to load %s\n",debugstr_w(dir));
1766 index = package->loaded_folders;
1768 package->loaded_folders++;
1769 if (package->loaded_folders== 1)
1770 package->folders = HeapAlloc(GetProcessHeap(),0,
1771 sizeof(MSIFOLDER));
1772 else
1773 package->folders= HeapReAlloc(GetProcessHeap(),0,
1774 package->folders, package->loaded_folders*
1775 sizeof(MSIFOLDER));
1777 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1779 strcpyW(package->folders[index].Directory,dir);
1781 strcatW(Query,dir);
1782 strcatW(Query,end);
1784 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1786 if (rc != ERROR_SUCCESS)
1787 return -1;
1789 rc = MSI_ViewExecute(view, 0);
1790 if (rc != ERROR_SUCCESS)
1792 MSI_ViewClose(view);
1793 msiobj_release(&view->hdr);
1794 return -1;
1797 rc = MSI_ViewFetch(view,&row);
1798 if (rc != ERROR_SUCCESS)
1800 MSI_ViewClose(view);
1801 msiobj_release(&view->hdr);
1802 return -1;
1805 sz=0x100;
1806 MSI_RecordGetStringW(row,3,targetbuffer,&sz);
1807 targetdir=targetbuffer;
1809 /* split src and target dir */
1810 if (strchrW(targetdir,':'))
1812 srcdir=strchrW(targetdir,':');
1813 *srcdir=0;
1814 srcdir ++;
1816 else
1817 srcdir=NULL;
1819 /* for now only pick long filename versions */
1820 if (strchrW(targetdir,'|'))
1822 targetdir = strchrW(targetdir,'|');
1823 *targetdir = 0;
1824 targetdir ++;
1826 if (srcdir && strchrW(srcdir,'|'))
1828 srcdir= strchrW(srcdir,'|');
1829 *srcdir= 0;
1830 srcdir ++;
1833 /* now check for root dirs */
1834 if (targetdir[0] == '.' && targetdir[1] == 0)
1835 targetdir = NULL;
1837 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
1838 srcdir = NULL;
1840 if (targetdir)
1841 strcpyW(package->folders[index].TargetDefault,targetdir);
1843 if (srcdir)
1844 strcpyW(package->folders[index].SourceDefault,srcdir);
1845 else if (targetdir)
1846 strcpyW(package->folders[index].SourceDefault,targetdir);
1848 if (MSI_RecordIsNull(row,2))
1849 parent[0]=0;
1850 else
1852 sz=0x100;
1853 MSI_RecordGetStringW(row,2,parent,&sz);
1856 if (parent[0])
1858 i = load_folder(package,parent);
1859 package->folders[index].ParentIndex = i;
1860 TRACE("Parent is index %i... %s %s\n",
1861 package->folders[index].ParentIndex,
1862 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
1863 debugstr_w(parent));
1865 else
1866 package->folders[index].ParentIndex = -2;
1868 sz = MAX_PATH;
1869 rc = MSI_GetPropertyW(package, dir, package->folders[index].Property, &sz);
1870 if (rc != ERROR_SUCCESS)
1871 package->folders[index].Property[0]=0;
1873 msiobj_release(&row->hdr);
1874 MSI_ViewClose(view);
1875 msiobj_release(&view->hdr);
1876 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
1877 return index;
1880 static UINT resolve_folder(MSIPACKAGE *package, LPCWSTR name, LPWSTR path,
1881 BOOL source, BOOL set_prop, MSIFOLDER **folder)
1883 DWORD i;
1884 UINT rc = ERROR_SUCCESS;
1885 DWORD sz;
1887 TRACE("Working to resolve %s\n",debugstr_w(name));
1889 if (!path)
1890 return rc;
1892 /* special resolving for Target and Source root dir */
1893 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
1895 if (!source)
1897 sz = MAX_PATH;
1898 rc = MSI_GetPropertyW(package,cszTargetDir,path,&sz);
1899 if (rc != ERROR_SUCCESS)
1901 sz = MAX_PATH;
1902 rc = MSI_GetPropertyW(package,cszRootDrive,path,&sz);
1903 if (set_prop)
1904 MSI_SetPropertyW(package,cszTargetDir,path);
1906 if (folder)
1907 *folder = &(package->folders[0]);
1908 return rc;
1910 else
1912 sz = MAX_PATH;
1913 rc = MSI_GetPropertyW(package,cszSourceDir,path,&sz);
1914 if (rc != ERROR_SUCCESS)
1916 sz = MAX_PATH;
1917 rc = MSI_GetPropertyW(package,cszDatabase,path,&sz);
1918 if (rc == ERROR_SUCCESS)
1920 LPWSTR ptr = strrchrW(path,'\\');
1921 if (ptr)
1923 ptr++;
1924 *ptr = 0;
1928 if (folder)
1929 *folder = &(package->folders[0]);
1930 return rc;
1934 for (i = 0; i < package->loaded_folders; i++)
1936 if (strcmpW(package->folders[i].Directory,name)==0)
1937 break;
1940 if (i >= package->loaded_folders)
1941 return ERROR_FUNCTION_FAILED;
1943 if (folder)
1944 *folder = &(package->folders[i]);
1946 if (!source && package->folders[i].ResolvedTarget[0])
1948 strcpyW(path,package->folders[i].ResolvedTarget);
1949 TRACE(" already resolved to %s\n",debugstr_w(path));
1950 return ERROR_SUCCESS;
1952 else if (source && package->folders[i].ResolvedSource[0])
1954 strcpyW(path,package->folders[i].ResolvedSource);
1955 return ERROR_SUCCESS;
1957 else if (!source && package->folders[i].Property[0])
1959 strcpyW(path,package->folders[i].Property);
1960 TRACE(" internally set to %s\n",debugstr_w(path));
1961 if (set_prop)
1962 MSI_SetPropertyW(package,name,path);
1963 return ERROR_SUCCESS;
1966 if (package->folders[i].ParentIndex >= 0)
1968 TRACE(" ! Parent is %s\n", debugstr_w(package->folders[
1969 package->folders[i].ParentIndex].Directory));
1970 resolve_folder(package, package->folders[
1971 package->folders[i].ParentIndex].Directory, path,source,
1972 set_prop, NULL);
1974 if (!source)
1976 if (package->folders[i].TargetDefault[0])
1978 strcatW(path,package->folders[i].TargetDefault);
1979 strcatW(path,cszbs);
1981 strcpyW(package->folders[i].ResolvedTarget,path);
1982 TRACE(" resolved into %s\n",debugstr_w(path));
1983 if (set_prop)
1984 MSI_SetPropertyW(package,name,path);
1986 else
1988 if (package->folders[i].SourceDefault[0])
1990 strcatW(path,package->folders[i].SourceDefault);
1991 strcatW(path,cszbs);
1993 strcpyW(package->folders[i].ResolvedSource,path);
1996 return rc;
2000 * Alot is done in this function aside from just the costing.
2001 * The costing needs to be implemented at some point but for now I am going
2002 * to focus on the directory building
2005 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2007 static const WCHAR ExecSeqQuery[] = {
2008 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2009 'D','i','r','e','c','t','o','r','y',0};
2010 static const WCHAR ConditionQuery[] = {
2011 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2012 'C','o','n','d','i','t','i','o','n',0};
2013 static const WCHAR szCosting[] = {
2014 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2015 static const WCHAR szOne[] = { '1', 0 };
2016 UINT rc;
2017 MSIQUERY * view;
2018 DWORD i;
2020 TRACE("Building Directory properties\n");
2022 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2023 if (rc == ERROR_SUCCESS)
2025 rc = MSI_ViewExecute(view, 0);
2026 if (rc != ERROR_SUCCESS)
2028 MSI_ViewClose(view);
2029 msiobj_release(&view->hdr);
2030 return rc;
2033 while (1)
2035 WCHAR name[0x100];
2036 WCHAR path[MAX_PATH];
2037 MSIRECORD * row = 0;
2038 DWORD sz;
2040 rc = MSI_ViewFetch(view,&row);
2041 if (rc != ERROR_SUCCESS)
2043 rc = ERROR_SUCCESS;
2044 break;
2047 sz=0x100;
2048 MSI_RecordGetStringW(row,1,name,&sz);
2050 /* This helper function now does ALL the work */
2051 TRACE("Dir %s ...\n",debugstr_w(name));
2052 load_folder(package,name);
2053 resolve_folder(package,name,path,FALSE,TRUE,NULL);
2054 TRACE("resolves to %s\n",debugstr_w(path));
2056 msiobj_release(&row->hdr);
2058 MSI_ViewClose(view);
2059 msiobj_release(&view->hdr);
2062 TRACE("File calculations %i files\n",package->loaded_files);
2064 for (i = 0; i < package->loaded_files; i++)
2066 MSICOMPONENT* comp = NULL;
2067 MSIFILE* file= NULL;
2069 file = &package->files[i];
2070 if (file->ComponentIndex >= 0)
2071 comp = &package->components[file->ComponentIndex];
2073 if (comp)
2075 /* calculate target */
2076 resolve_folder(package, comp->Directory, file->TargetPath, FALSE,
2077 FALSE, NULL);
2078 strcatW(file->TargetPath,file->FileName);
2080 TRACE("file %s resolves to %s\n",
2081 debugstr_w(file->File),debugstr_w(file->TargetPath));
2083 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2085 file->State = 1;
2086 comp->Cost += file->FileSize;
2088 else
2090 if (file->Version[0])
2092 DWORD handle;
2093 DWORD versize;
2094 UINT sz;
2095 LPVOID version;
2096 WCHAR filever[0x100];
2097 static const WCHAR name[] =
2098 {'\\','V','a','r','F','i','l','e','I','n','f','o',
2099 '\\','F','i','l','e','V','e','r','s','i','o','n',0};
2101 FIXME("Version comparison.. Untried Untested and most "
2102 "likely very very wrong\n");
2103 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2104 version = HeapAlloc(GetProcessHeap(),0,versize);
2105 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2106 sz = 0x100;
2107 VerQueryValueW(version,name,(LPVOID)filever,&sz);
2108 HeapFree(GetProcessHeap(),0,version);
2110 if (strcmpW(version,file->Version)<0)
2112 file->State = 2;
2113 FIXME("cost should be diff in size\n");
2114 comp->Cost += file->FileSize;
2116 else
2117 file->State = 3;
2119 else
2120 file->State = 3;
2125 TRACE("Evaluating Condition Table\n");
2127 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2128 if (rc == ERROR_SUCCESS)
2130 rc = MSI_ViewExecute(view, 0);
2131 if (rc != ERROR_SUCCESS)
2133 MSI_ViewClose(view);
2134 msiobj_release(&view->hdr);
2135 return rc;
2138 while (1)
2140 WCHAR Feature[0x100];
2141 MSIRECORD * row = 0;
2142 DWORD sz;
2143 int feature_index;
2145 rc = MSI_ViewFetch(view,&row);
2147 if (rc != ERROR_SUCCESS)
2149 rc = ERROR_SUCCESS;
2150 break;
2153 sz = 0x100;
2154 MSI_RecordGetStringW(row,1,Feature,&sz);
2156 feature_index = get_loaded_feature(package,Feature);
2157 if (feature_index < 0)
2158 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2159 else
2161 LPWSTR Condition;
2162 Condition = load_dynamic_stringW(row,3);
2164 if (MSI_EvaluateConditionW(package,Condition) ==
2165 MSICONDITION_TRUE)
2167 int level = MSI_RecordGetInteger(row,2);
2168 TRACE("Reseting feature %s to level %i\n",
2169 debugstr_w(Feature), level);
2170 package->features[feature_index].Level = level;
2172 HeapFree(GetProcessHeap(),0,Condition);
2175 msiobj_release(&row->hdr);
2177 MSI_ViewClose(view);
2178 msiobj_release(&view->hdr);
2181 TRACE("Enabling or Disabling Components\n");
2182 for (i = 0; i < package->loaded_components; i++)
2184 if (package->components[i].Condition[0])
2186 if (MSI_EvaluateConditionW(package,
2187 package->components[i].Condition) == MSICONDITION_FALSE)
2189 TRACE("Disabling component %s\n",
2190 debugstr_w(package->components[i].Component));
2191 package->components[i].Enabled = FALSE;
2196 MSI_SetPropertyW(package,szCosting,szOne);
2197 return ERROR_SUCCESS;
2201 * This is a helper function for handling embedded cabinet media
2203 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2204 WCHAR* source)
2206 UINT rc;
2207 USHORT* data;
2208 UINT size;
2209 DWORD write;
2210 HANDLE the_file;
2211 WCHAR tmp[MAX_PATH];
2213 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2214 if (rc != ERROR_SUCCESS)
2215 return rc;
2217 write = MAX_PATH;
2218 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2219 GetTempPathW(MAX_PATH,tmp);
2221 GetTempFileNameW(tmp,stream_name,0,source);
2223 track_tempfile(package,strrchrW(source,'\\'), source);
2224 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2225 FILE_ATTRIBUTE_NORMAL, NULL);
2227 if (the_file == INVALID_HANDLE_VALUE)
2229 rc = ERROR_FUNCTION_FAILED;
2230 goto end;
2233 WriteFile(the_file,data,size,&write,NULL);
2234 CloseHandle(the_file);
2235 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2236 end:
2237 HeapFree(GetProcessHeap(),0,data);
2238 return rc;
2242 /* Support functions for FDI functions */
2244 static void * cabinet_alloc(ULONG cb)
2246 return HeapAlloc(GetProcessHeap(), 0, cb);
2249 static void cabinet_free(void *pv)
2251 HeapFree(GetProcessHeap(), 0, pv);
2254 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2256 DWORD dwAccess = 0;
2257 DWORD dwShareMode = 0;
2258 DWORD dwCreateDisposition = OPEN_EXISTING;
2259 switch (oflag & _O_ACCMODE)
2261 case _O_RDONLY:
2262 dwAccess = GENERIC_READ;
2263 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2264 break;
2265 case _O_WRONLY:
2266 dwAccess = GENERIC_WRITE;
2267 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2268 break;
2269 case _O_RDWR:
2270 dwAccess = GENERIC_READ | GENERIC_WRITE;
2271 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2272 break;
2274 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2275 dwCreateDisposition = CREATE_NEW;
2276 else if (oflag & _O_CREAT)
2277 dwCreateDisposition = CREATE_ALWAYS;
2278 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL, dwCreateDisposition, 0, NULL);
2281 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2283 DWORD dwRead;
2284 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2285 return dwRead;
2286 return 0;
2289 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2291 DWORD dwWritten;
2292 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2293 return dwWritten;
2294 return 0;
2297 static int cabinet_close(INT_PTR hf)
2299 return CloseHandle((HANDLE)hf) ? 0 : -1;
2302 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2304 /* flags are compatible and so are passed straight through */
2305 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2308 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2310 /* FIXME: try to do more processing in this function */
2311 switch (fdint)
2313 case fdintCOPY_FILE:
2315 ULONG len = strlen((char*)pfdin->pv) + strlen(pfdin->psz1);
2316 char *file = cabinet_alloc((len+1)*sizeof(char));
2318 strcpy(file, (char*)pfdin->pv);
2319 strcat(file, pfdin->psz1);
2321 TRACE("file: %s\n", debugstr_a(file));
2323 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2325 case fdintCLOSE_FILE_INFO:
2327 FILETIME ft;
2328 FILETIME ftLocal;
2329 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2330 return -1;
2331 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2332 return -1;
2333 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2334 return -1;
2336 cabinet_close(pfdin->hf);
2337 return 1;
2339 default:
2340 return 0;
2344 /***********************************************************************
2345 * extract_cabinet_file
2347 * Extract files from a cab file.
2349 static BOOL extract_cabinet_file(const WCHAR* source, const WCHAR* path)
2351 HFDI hfdi;
2352 ERF erf;
2353 BOOL ret;
2354 char *cabinet;
2355 char *cab_path;
2357 TRACE("Extracting %s to %s\n",debugstr_w(source), debugstr_w(path));
2359 hfdi = FDICreate(cabinet_alloc,
2360 cabinet_free,
2361 cabinet_open,
2362 cabinet_read,
2363 cabinet_write,
2364 cabinet_close,
2365 cabinet_seek,
2367 &erf);
2368 if (!hfdi)
2370 ERR("FDICreate failed\n");
2371 return FALSE;
2374 if (!(cabinet = strdupWtoA( source )))
2376 FDIDestroy(hfdi);
2377 return FALSE;
2379 if (!(cab_path = strdupWtoA( path )))
2381 FDIDestroy(hfdi);
2382 HeapFree(GetProcessHeap(), 0, cabinet);
2383 return FALSE;
2386 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, cab_path);
2388 if (!ret)
2389 ERR("FDICopy failed\n");
2391 FDIDestroy(hfdi);
2393 HeapFree(GetProcessHeap(), 0, cabinet);
2394 HeapFree(GetProcessHeap(), 0, cab_path);
2396 return ret;
2399 static UINT ready_media_for_file(MSIPACKAGE *package, UINT sequence,
2400 WCHAR* path)
2402 UINT rc;
2403 MSIQUERY * view;
2404 MSIRECORD * row = 0;
2405 WCHAR source[MAX_PATH];
2406 static const WCHAR ExecSeqQuery[] = {
2407 's','e','l','e','c','t',' ','*',' ',
2408 'f','r','o','m',' ','M','e','d','i','a',' ',
2409 'w','h','e','r','e',' ','L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%','i',' ',
2410 'o','r','d','e','r',' ','b','y',' ','L','a','s','t','S','e','q','u','e','n','c','e',0};
2411 WCHAR Query[1024];
2412 WCHAR cab[0x100];
2413 DWORD sz=0x100;
2414 INT seq;
2415 static UINT last_sequence = 0;
2417 if (sequence <= last_sequence)
2419 TRACE("Media already ready (%u, %u)\n",sequence,last_sequence);
2420 return ERROR_SUCCESS;
2423 sprintfW(Query,ExecSeqQuery,sequence);
2425 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2426 if (rc != ERROR_SUCCESS)
2427 return rc;
2429 rc = MSI_ViewExecute(view, 0);
2430 if (rc != ERROR_SUCCESS)
2432 MSI_ViewClose(view);
2433 msiobj_release(&view->hdr);
2434 return rc;
2437 rc = MSI_ViewFetch(view,&row);
2438 if (rc != ERROR_SUCCESS)
2440 MSI_ViewClose(view);
2441 msiobj_release(&view->hdr);
2442 return rc;
2444 seq = MSI_RecordGetInteger(row,2);
2445 last_sequence = seq;
2447 if (!MSI_RecordIsNull(row,4))
2449 sz=0x100;
2450 MSI_RecordGetStringW(row,4,cab,&sz);
2451 TRACE("Source is CAB %s\n",debugstr_w(cab));
2452 /* the stream does not contain the # character */
2453 if (cab[0]=='#')
2455 writeout_cabinet_stream(package,&cab[1],source);
2456 strcpyW(path,source);
2457 *(strrchrW(path,'\\')+1)=0;
2459 else
2461 sz = MAX_PATH;
2462 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
2464 ERR("No Source dir defined \n");
2465 rc = ERROR_FUNCTION_FAILED;
2467 else
2469 strcpyW(path,source);
2470 strcatW(source,cab);
2471 /* extract the cab file into a folder in the temp folder */
2472 sz = MAX_PATH;
2473 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
2474 != ERROR_SUCCESS)
2475 GetTempPathW(MAX_PATH,path);
2478 rc = !extract_cabinet_file(source,path);
2480 msiobj_release(&row->hdr);
2481 MSI_ViewClose(view);
2482 msiobj_release(&view->hdr);
2483 return rc;
2486 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
2488 UINT rc;
2489 MSIFOLDER *folder;
2490 WCHAR install_path[MAX_PATH];
2492 rc = resolve_folder(package, package->components[component].Directory,
2493 install_path, FALSE, FALSE, &folder);
2495 if (rc != ERROR_SUCCESS)
2496 return rc;
2498 /* create the path */
2499 if (folder->State == 0)
2501 create_full_pathW(install_path);
2502 folder->State = 2;
2505 return rc;
2508 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
2510 UINT rc = ERROR_SUCCESS;
2511 DWORD index;
2512 MSIRECORD * uirow;
2513 WCHAR uipath[MAX_PATH];
2515 if (!package)
2516 return ERROR_INVALID_HANDLE;
2518 /* increment progress bar each time action data is sent */
2519 ui_progress(package,1,1,1,0);
2521 for (index = 0; index < package->loaded_files; index++)
2523 WCHAR path_to_source[MAX_PATH];
2524 MSIFILE *file;
2526 file = &package->files[index];
2528 if (file->Temporary)
2529 continue;
2531 if (!package->components[file->ComponentIndex].Enabled ||
2532 !package->components[file->ComponentIndex].FeatureState)
2534 TRACE("File %s is not scheduled for install\n",
2535 debugstr_w(file->File));
2536 continue;
2539 if ((file->State == 1) || (file->State == 2))
2541 TRACE("Installing %s\n",debugstr_w(file->File));
2542 rc = ready_media_for_file(package,file->Sequence,path_to_source);
2544 * WARNING!
2545 * our file table could change here because a new temp file
2546 * may have been created
2548 file = &package->files[index];
2549 if (rc != ERROR_SUCCESS)
2551 ERR("Unable to ready media\n");
2552 rc = ERROR_FUNCTION_FAILED;
2553 break;
2556 create_component_directory( package, file->ComponentIndex);
2558 strcpyW(file->SourcePath, path_to_source);
2559 strcatW(file->SourcePath, file->File);
2561 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
2562 debugstr_w(file->TargetPath));
2564 /* the UI chunk */
2565 uirow=MSI_CreateRecord(9);
2566 MSI_RecordSetStringW(uirow,1,file->File);
2567 strcpyW(uipath,file->TargetPath);
2568 *(strrchrW(uipath,'\\')+1)=0;
2569 MSI_RecordSetStringW(uirow,9,uipath);
2570 MSI_RecordSetInteger(uirow,6,file->FileSize);
2571 ui_actiondata(package,szInstallFiles,uirow);
2572 msiobj_release( &uirow->hdr );
2574 if (!MoveFileW(file->SourcePath,file->TargetPath))
2576 rc = GetLastError();
2577 ERR("Unable to move file (error %d)\n", rc);
2578 break;
2580 else
2581 file->State = 4;
2583 ui_progress(package,2,0,0,0);
2587 return rc;
2590 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
2591 LPWSTR file_source)
2593 DWORD index;
2595 if (!package)
2596 return ERROR_INVALID_HANDLE;
2598 for (index = 0; index < package->loaded_files; index ++)
2600 if (strcmpW(file_key,package->files[index].File)==0)
2602 if (package->files[index].State >= 3)
2604 strcpyW(file_source,package->files[index].TargetPath);
2605 return ERROR_SUCCESS;
2607 else
2608 return ERROR_FILE_NOT_FOUND;
2612 return ERROR_FUNCTION_FAILED;
2615 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
2617 UINT rc;
2618 MSIQUERY * view;
2619 MSIRECORD * row = 0;
2620 static const WCHAR ExecSeqQuery[] = {
2621 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2622 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
2624 if (!package)
2625 return ERROR_INVALID_HANDLE;
2627 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2628 if (rc != ERROR_SUCCESS)
2629 return ERROR_SUCCESS;
2631 rc = MSI_ViewExecute(view, 0);
2632 if (rc != ERROR_SUCCESS)
2634 MSI_ViewClose(view);
2635 msiobj_release(&view->hdr);
2636 return rc;
2639 while (1)
2641 WCHAR file_key[0x100];
2642 WCHAR file_source[MAX_PATH];
2643 WCHAR dest_name[0x100];
2644 WCHAR dest_path[MAX_PATH];
2645 WCHAR component[0x100];
2646 INT component_index;
2648 DWORD sz=0x100;
2650 rc = MSI_ViewFetch(view,&row);
2651 if (rc != ERROR_SUCCESS)
2653 rc = ERROR_SUCCESS;
2654 break;
2657 sz=0x100;
2658 rc = MSI_RecordGetStringW(row,2,component,&sz);
2659 if (rc != ERROR_SUCCESS)
2661 ERR("Unable to get component\n");
2662 msiobj_release(&row->hdr);
2663 break;
2666 component_index = get_loaded_component(package,component);
2667 if (!package->components[component_index].Enabled ||
2668 !package->components[component_index].FeatureState)
2670 TRACE("Skipping copy due to disabled component\n");
2671 msiobj_release(&row->hdr);
2672 continue;
2675 sz=0x100;
2676 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
2677 if (rc != ERROR_SUCCESS)
2679 ERR("Unable to get file key\n");
2680 msiobj_release(&row->hdr);
2681 break;
2684 rc = get_file_target(package,file_key,file_source);
2686 if (rc != ERROR_SUCCESS)
2688 ERR("Original file unknown %s\n",debugstr_w(file_key));
2689 msiobj_release(&row->hdr);
2690 break;
2693 if (MSI_RecordIsNull(row,4))
2695 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
2697 else
2699 sz=0x100;
2700 MSI_RecordGetStringW(row,4,dest_name,&sz);
2701 reduce_to_longfilename(dest_name);
2704 if (MSI_RecordIsNull(row,5))
2706 strcpyW(dest_path,file_source);
2707 *strrchrW(dest_path,'\\')=0;
2709 else
2711 WCHAR destkey[0x100];
2712 sz=0x100;
2713 MSI_RecordGetStringW(row,5,destkey,&sz);
2714 sz = 0x100;
2715 rc = resolve_folder(package, destkey, dest_path,FALSE,FALSE,NULL);
2716 if (rc != ERROR_SUCCESS)
2718 ERR("Unable to get destination folder\n");
2719 msiobj_release(&row->hdr);
2720 break;
2724 strcatW(dest_path,dest_name);
2726 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
2727 debugstr_w(dest_path));
2729 if (strcmpW(file_source,dest_path))
2730 rc = !CopyFileW(file_source,dest_path,TRUE);
2731 else
2732 rc = ERROR_SUCCESS;
2734 if (rc != ERROR_SUCCESS)
2735 ERR("Failed to copy file\n");
2737 FIXME("We should track these duplicate files as well\n");
2739 msiobj_release(&row->hdr);
2741 MSI_ViewClose(view);
2742 msiobj_release(&view->hdr);
2743 return rc;
2748 /* OK this value is "interpretted" and then formatted based on the
2749 first few characters */
2750 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
2751 DWORD *size)
2753 LPSTR data = NULL;
2754 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
2756 if (value[1]=='x')
2758 LPWSTR ptr;
2759 CHAR byte[5];
2760 LPWSTR deformated;
2761 int count;
2763 deformat_string(package, &value[2], &deformated);
2765 /* binary value type */
2766 ptr = deformated;
2767 *type=REG_BINARY;
2768 *size = strlenW(ptr)/2;
2769 data = HeapAlloc(GetProcessHeap(),0,*size);
2771 byte[0] = '0';
2772 byte[1] = 'x';
2773 byte[4] = 0;
2774 count = 0;
2775 while (*ptr)
2777 byte[2]= *ptr;
2778 ptr++;
2779 byte[3]= *ptr;
2780 ptr++;
2781 data[count] = (BYTE)strtol(byte,NULL,0);
2782 count ++;
2784 HeapFree(GetProcessHeap(),0,deformated);
2786 TRACE("Data %li bytes(%i)\n",*size,count);
2788 else
2790 LPWSTR deformated;
2791 deformat_string(package, &value[1], &deformated);
2793 *type=REG_DWORD;
2794 *size = sizeof(DWORD);
2795 data = HeapAlloc(GetProcessHeap(),0,*size);
2796 *(LPDWORD)data = atoiW(deformated);
2797 TRACE("DWORD %i\n",*data);
2799 HeapFree(GetProcessHeap(),0,deformated);
2802 else
2804 WCHAR *ptr;
2805 *type=REG_SZ;
2807 if (value[0]=='#')
2809 if (value[1]=='%')
2811 ptr = &value[2];
2812 *type=REG_EXPAND_SZ;
2814 else
2815 ptr = &value[1];
2817 else
2818 ptr=value;
2820 *size = deformat_string(package, ptr,(LPWSTR*)&data);
2822 return data;
2825 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
2827 UINT rc;
2828 MSIQUERY * view;
2829 MSIRECORD * row = 0;
2830 static const WCHAR ExecSeqQuery[] = {
2831 's','e','l','e','c','t',' ','*',' ',
2832 'f','r','o','m',' ','R','e','g','i','s','t','r','y',0 };
2834 if (!package)
2835 return ERROR_INVALID_HANDLE;
2837 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2838 if (rc != ERROR_SUCCESS)
2839 return ERROR_SUCCESS;
2841 rc = MSI_ViewExecute(view, 0);
2842 if (rc != ERROR_SUCCESS)
2844 MSI_ViewClose(view);
2845 msiobj_release(&view->hdr);
2846 return rc;
2849 /* increment progress bar each time action data is sent */
2850 ui_progress(package,1,1,1,0);
2852 while (1)
2854 static const WCHAR szHCR[] =
2855 {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T','\\',0};
2856 static const WCHAR szHCU[] =
2857 {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',0};
2858 static const WCHAR szHLM[] =
2859 {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',
2860 '\\',0};
2861 static const WCHAR szHU[] =
2862 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
2864 WCHAR key[0x100];
2865 WCHAR name[0x100];
2866 LPWSTR value;
2867 LPSTR value_data = NULL;
2868 HKEY root_key, hkey;
2869 DWORD type,size;
2870 WCHAR component[0x100];
2871 INT component_index;
2872 MSIRECORD * uirow;
2873 WCHAR uikey[0x110];
2875 INT root;
2876 DWORD sz=0x100;
2878 rc = MSI_ViewFetch(view,&row);
2879 if (rc != ERROR_SUCCESS)
2881 rc = ERROR_SUCCESS;
2882 break;
2885 sz= 0x100;
2886 MSI_RecordGetStringW(row,6,component,&sz);
2887 component_index = get_loaded_component(package,component);
2889 if (!package->components[component_index].Enabled ||
2890 !package->components[component_index].FeatureState)
2892 TRACE("Skipping write due to disabled component\n");
2893 msiobj_release(&row->hdr);
2894 continue;
2897 /* null values have special meanings during uninstalls and such */
2899 if(MSI_RecordIsNull(row,5))
2901 msiobj_release(&row->hdr);
2902 continue;
2905 root = MSI_RecordGetInteger(row,2);
2906 sz = 0x100;
2907 MSI_RecordGetStringW(row,3,key,&sz);
2909 sz = 0x100;
2910 if (MSI_RecordIsNull(row,4))
2911 name[0]=0;
2912 else
2913 MSI_RecordGetStringW(row,4,name,&sz);
2915 /* get the root key */
2916 switch (root)
2918 case 0: root_key = HKEY_CLASSES_ROOT;
2919 strcpyW(uikey,szHCR); break;
2920 case 1: root_key = HKEY_CURRENT_USER;
2921 strcpyW(uikey,szHCU); break;
2922 case 2: root_key = HKEY_LOCAL_MACHINE;
2923 strcpyW(uikey,szHLM); break;
2924 case 3: root_key = HKEY_USERS;
2925 strcpyW(uikey,szHU); break;
2926 default:
2927 ERR("Unknown root %i\n",root);
2928 root_key=NULL;
2929 break;
2931 if (!root_key)
2933 msiobj_release(&row->hdr);
2934 continue;
2937 strcatW(uikey,key);
2938 if (RegCreateKeyW( root_key, key, &hkey))
2940 ERR("Could not create key %s\n",debugstr_w(key));
2941 msiobj_release(&row->hdr);
2942 continue;
2945 value = load_dynamic_stringW(row,5);
2946 value_data = parse_value(package, value, &type, &size);
2948 if (value_data)
2950 TRACE("Setting value %s\n",debugstr_w(name));
2951 RegSetValueExW(hkey, name, 0, type, value_data, size);
2953 uirow = MSI_CreateRecord(3);
2954 MSI_RecordSetStringW(uirow,2,name);
2955 MSI_RecordSetStringW(uirow,1,uikey);
2957 if (type == REG_SZ)
2958 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
2959 else
2960 MSI_RecordSetStringW(uirow,3,value);
2962 ui_actiondata(package,szWriteRegistryValues,uirow);
2963 ui_progress(package,2,0,0,0);
2964 msiobj_release( &uirow->hdr );
2966 HeapFree(GetProcessHeap(),0,value_data);
2968 HeapFree(GetProcessHeap(),0,value);
2970 msiobj_release(&row->hdr);
2971 RegCloseKey(hkey);
2973 MSI_ViewClose(view);
2974 msiobj_release(&view->hdr);
2975 return rc;
2979 * This helper function should probably go alot of places
2981 * Thinking about this, maybe this should become yet another Bison file
2983 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data)
2985 WCHAR* mark=NULL;
2986 DWORD size=0;
2987 DWORD chunk=0;
2988 WCHAR key[0x100];
2989 LPWSTR value;
2990 DWORD sz;
2991 UINT rc;
2993 /* scan for special characters */
2994 if (!strchrW(ptr,'[') || (strchrW(ptr,'[') && !strchrW(ptr,']')))
2996 /* not formatted */
2997 size = (strlenW(ptr)+1) * sizeof(WCHAR);
2998 *data = HeapAlloc(GetProcessHeap(),0,size);
2999 strcpyW(*data,ptr);
3000 return size;
3003 /* formatted string located */
3004 mark = strchrW(ptr,'[');
3005 if (mark != ptr)
3007 INT cnt = (mark - ptr);
3008 TRACE("%i (%i) characters before marker\n",cnt,(mark-ptr));
3009 size = cnt * sizeof(WCHAR);
3010 size += sizeof(WCHAR);
3011 *data = HeapAlloc(GetProcessHeap(),0,size);
3012 strncpyW(*data,ptr,cnt);
3013 (*data)[cnt]=0;
3015 else
3017 size = sizeof(WCHAR);
3018 *data = HeapAlloc(GetProcessHeap(),0,size);
3019 (*data)[0]=0;
3021 mark++;
3022 strcpyW(key,mark);
3023 *strchrW(key,']')=0;
3024 mark = strchrW(mark,']');
3025 mark++;
3026 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3027 sz = 0;
3028 rc = MSI_GetPropertyW(package, key, NULL, &sz);
3029 if ((rc == ERROR_SUCCESS) || (rc == ERROR_MORE_DATA))
3031 LPWSTR newdata;
3033 sz++;
3034 value = HeapAlloc(GetProcessHeap(),0,sz * sizeof(WCHAR));
3035 MSI_GetPropertyW(package, key, value, &sz);
3037 chunk = (strlenW(value)+1) * sizeof(WCHAR);
3038 size+=chunk;
3039 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3040 *data = newdata;
3041 strcatW(*data,value);
3043 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3044 if (*mark!=0)
3046 LPWSTR newdata;
3047 chunk = (strlenW(mark)+1) * sizeof(WCHAR);
3048 size+=chunk;
3049 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3050 *data = newdata;
3051 strcatW(*data,mark);
3053 (*data)[strlenW(*data)]=0;
3054 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3056 /* recursively do this to clean up */
3057 mark = HeapAlloc(GetProcessHeap(),0,size);
3058 strcpyW(mark,*data);
3059 TRACE("String at this point %s\n",debugstr_w(mark));
3060 size = deformat_string(package,mark,data);
3061 HeapFree(GetProcessHeap(),0,mark);
3062 return size;
3065 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3067 WCHAR level[10000];
3068 INT install_level;
3069 DWORD sz;
3070 DWORD i;
3071 INT j;
3072 DWORD rc;
3073 LPWSTR override = NULL;
3074 static const WCHAR addlocal[]={'A','D','D','L','O','C','A','L',0};
3075 static const WCHAR all[]={'A','L','L',0};
3076 static const WCHAR szlevel[] = {
3077 'I','N','S','T','A','L','L','L','E','V','E','L',0};
3078 static const WCHAR szAddLocal[] = {
3079 'A','D','D','L','O','C','A','L',0};
3081 /* I do not know if this is where it should happen.. but */
3083 TRACE("Checking Install Level\n");
3085 sz = 10000;
3086 if (MSI_GetPropertyW(package,szlevel,level,&sz)==ERROR_SUCCESS)
3087 install_level = atoiW(level);
3088 else
3089 install_level = 1;
3091 sz = 0;
3092 rc = MSI_GetPropertyW(package,szAddLocal,NULL,&sz);
3093 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
3095 sz++;
3096 override = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
3097 MSI_GetPropertyW(package, addlocal,override,&sz);
3101 * Components FeatureState defaults to FALSE. The idea is we want to
3102 * enable the component is ANY feature that uses it is enabled to install
3104 for(i = 0; i < package->loaded_features; i++)
3106 BOOL feature_state= ((package->features[i].Level > 0) &&
3107 (package->features[i].Level <= install_level));
3109 if (override && (strcmpiW(override,all)==0 ||
3110 strstrW(override,package->features[i].Feature)))
3112 TRACE("Override of install level found\n");
3113 feature_state = TRUE;
3114 package->features[i].Enabled = feature_state;
3117 TRACE("Feature %s has a state of %i\n",
3118 debugstr_w(package->features[i].Feature), feature_state);
3119 for( j = 0; j < package->features[i].ComponentCount; j++)
3121 package->components[package->features[i].Components[j]].FeatureState
3122 |= feature_state;
3125 if (override != NULL)
3126 HeapFree(GetProcessHeap(),0,override);
3128 * So basically we ONLY want to install a component if its Enabled AND
3129 * FeatureState are both TRUE
3131 return ERROR_SUCCESS;
3134 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3136 DWORD progress = 0;
3137 static const WCHAR q1[]={
3138 'S','E','L','E','C','T',' ','*',' ',
3139 'F','R','O','M',' ','R','e','g','i','s','t','r','y',0};
3140 UINT rc;
3141 MSIQUERY * view;
3142 MSIRECORD * row = 0;
3144 TRACE(" InstallValidate \n");
3146 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3147 if (rc != ERROR_SUCCESS)
3148 return ERROR_SUCCESS;
3150 rc = MSI_ViewExecute(view, 0);
3151 if (rc != ERROR_SUCCESS)
3153 MSI_ViewClose(view);
3154 msiobj_release(&view->hdr);
3155 return rc;
3157 while (1)
3159 rc = MSI_ViewFetch(view,&row);
3160 if (rc != ERROR_SUCCESS)
3162 rc = ERROR_SUCCESS;
3163 break;
3165 progress +=1;
3167 msiobj_release(&row->hdr);
3169 MSI_ViewClose(view);
3170 msiobj_release(&view->hdr);
3172 ui_progress(package,0,progress+package->loaded_files,0,0);
3174 return ERROR_SUCCESS;
3177 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3179 UINT rc;
3180 MSIQUERY * view = NULL;
3181 MSIRECORD * row = 0;
3182 static const WCHAR ExecSeqQuery[] = {
3183 'S','E','L','E','C','T',' ','*',' ',
3184 'f','r','o','m',' ','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3185 static const WCHAR title[]=
3186 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3188 TRACE("Checking launch conditions\n");
3190 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3191 if (rc != ERROR_SUCCESS)
3192 return ERROR_SUCCESS;
3194 rc = MSI_ViewExecute(view, 0);
3195 if (rc != ERROR_SUCCESS)
3197 MSI_ViewClose(view);
3198 msiobj_release(&view->hdr);
3199 return rc;
3202 rc = ERROR_SUCCESS;
3203 while (rc == ERROR_SUCCESS)
3205 LPWSTR cond = NULL;
3206 LPWSTR message = NULL;
3208 rc = MSI_ViewFetch(view,&row);
3209 if (rc != ERROR_SUCCESS)
3211 rc = ERROR_SUCCESS;
3212 break;
3215 cond = load_dynamic_stringW(row,1);
3217 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3219 message = load_dynamic_stringW(row,2);
3220 MessageBoxW(NULL,message,title,MB_OK);
3221 HeapFree(GetProcessHeap(),0,message);
3222 rc = ERROR_FUNCTION_FAILED;
3224 HeapFree(GetProcessHeap(),0,cond);
3225 msiobj_release(&row->hdr);
3227 MSI_ViewClose(view);
3228 msiobj_release(&view->hdr);
3229 return rc;
3232 static void resolve_keypath( MSIPACKAGE* package, INT
3233 component_index, WCHAR *keypath)
3235 MSICOMPONENT* cmp = &package->components[component_index];
3237 if (cmp->KeyPath[0]==0)
3239 resolve_folder(package,cmp->Directory,keypath,FALSE,FALSE,NULL);
3240 return;
3242 if ((cmp->Attributes & 0x4) || (cmp->Attributes & 0x20))
3244 FIXME("UNIMPLEMENTED keypath as Registry or ODBC Source\n");
3245 keypath[0]=0;
3247 else
3249 int j;
3250 j = get_loaded_file(package,cmp->KeyPath);
3252 if (j>=0)
3253 strcpyW(keypath,package->files[j].TargetPath);
3258 * Ok further analysis makes me think that this work is
3259 * actually done in the PublishComponents and PublishFeatures
3260 * step, and not here. It appears like the keypath and all that is
3261 * resolved in this step, however actually written in the Publish steps.
3262 * But we will leave it here for now because it is unclear
3264 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
3266 WCHAR productcode[0x100];
3267 WCHAR squished_pc[0x100];
3268 WCHAR squished_cc[0x100];
3269 DWORD sz;
3270 UINT rc;
3271 DWORD i;
3272 HKEY hkey=0,hkey2=0,hkey3=0;
3273 static const WCHAR szProductCode[]=
3274 {'P','r','o','d','u','c','t','C','o','d','e',0};
3275 static const WCHAR szInstaller[] = {
3276 'S','o','f','t','w','a','r','e','\\',
3277 'M','i','c','r','o','s','o','f','t','\\',
3278 'W','i','n','d','o','w','s','\\',
3279 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3280 'I','n','s','t','a','l','l','e','r',0 };
3281 static const WCHAR szFeatures[] = {
3282 'F','e','a','t','u','r','e','s',0 };
3283 static const WCHAR szComponents[] = {
3284 'C','o','m','p','o','n','e','n','t','s',0 };
3286 if (!package)
3287 return ERROR_INVALID_HANDLE;
3289 /* writes the Component and Features values to the registry */
3290 sz = 0x100;
3291 rc = MSI_GetPropertyW(package,szProductCode,productcode,&sz);
3292 if (rc != ERROR_SUCCESS)
3293 return ERROR_SUCCESS;
3295 squash_guid(productcode,squished_pc);
3296 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller,&hkey);
3297 if (rc != ERROR_SUCCESS)
3298 goto end;
3300 rc = RegCreateKeyW(hkey,szFeatures,&hkey2);
3301 if (rc != ERROR_SUCCESS)
3302 goto end;
3304 rc = RegCreateKeyW(hkey2,squished_pc,&hkey3);
3305 if (rc != ERROR_SUCCESS)
3306 goto end;
3308 /* here the guids are base 85 encoded */
3309 for (i = 0; i < package->loaded_features; i++)
3311 LPWSTR data = NULL;
3312 GUID clsid;
3313 int j;
3314 INT size;
3316 size = package->features[i].ComponentCount*21*sizeof(WCHAR);
3317 data = HeapAlloc(GetProcessHeap(), 0, size);
3319 data[0] = 0;
3320 for (j = 0; j < package->features[i].ComponentCount; j++)
3322 WCHAR buf[21];
3323 TRACE("From %s\n",debugstr_w(package->components
3324 [package->features[i].Components[j]].ComponentId));
3325 CLSIDFromString(package->components
3326 [package->features[i].Components[j]].ComponentId,
3327 &clsid);
3328 encode_base85_guid(&clsid,buf);
3329 TRACE("to %s\n",debugstr_w(buf));
3330 strcatW(data,buf);
3333 size = strlenW(data)*sizeof(WCHAR);
3334 RegSetValueExW(hkey3,package->features[i].Feature,0,REG_SZ,
3335 (LPSTR)data,size);
3336 HeapFree(GetProcessHeap(),0,data);
3339 RegCloseKey(hkey3);
3340 RegCloseKey(hkey2);
3342 rc = RegCreateKeyW(hkey,szComponents,&hkey2);
3343 if (rc != ERROR_SUCCESS)
3344 goto end;
3346 for (i = 0; i < package->loaded_components; i++)
3348 if (package->components[i].ComponentId[0]!=0)
3350 WCHAR keypath[0x1000];
3351 MSIRECORD * uirow;
3353 squash_guid(package->components[i].ComponentId,squished_cc);
3354 rc = RegCreateKeyW(hkey2,squished_cc,&hkey3);
3355 if (rc != ERROR_SUCCESS)
3356 continue;
3358 resolve_keypath(package,i,keypath);
3360 RegSetValueExW(hkey3,squished_pc,0,REG_SZ,(LPVOID)keypath,
3361 (strlenW(keypath)+1)*sizeof(WCHAR));
3362 RegCloseKey(hkey3);
3364 /* UI stuff */
3365 uirow = MSI_CreateRecord(3);
3366 MSI_RecordSetStringW(uirow,1,productcode);
3367 MSI_RecordSetStringW(uirow,2,package->components[i].ComponentId);
3368 MSI_RecordSetStringW(uirow,3,keypath);
3369 ui_actiondata(package,szProcessComponents,uirow);
3370 msiobj_release( &uirow->hdr );
3373 end:
3374 RegCloseKey(hkey2);
3375 RegCloseKey(hkey);
3376 return rc;
3379 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
3382 * OK this is a bit confusing.. I am given a _Component key and I believe
3383 * that the file that is being registered as a type library is the "key file
3384 * of that component" which I interpret to mean "The file in the KeyPath of
3385 * that component".
3387 UINT rc;
3388 MSIQUERY * view;
3389 MSIRECORD * row = 0;
3390 static const WCHAR Query[] = {
3391 'S','E','L','E','C','T',' ','*',' ',
3392 'f','r','o','m',' ','T','y','p','e','L','i','b',0};
3393 ITypeLib *ptLib;
3394 HRESULT res;
3396 if (!package)
3397 return ERROR_INVALID_HANDLE;
3399 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3400 if (rc != ERROR_SUCCESS)
3401 return ERROR_SUCCESS;
3403 rc = MSI_ViewExecute(view, 0);
3404 if (rc != ERROR_SUCCESS)
3406 MSI_ViewClose(view);
3407 msiobj_release(&view->hdr);
3408 return rc;
3411 while (1)
3413 WCHAR component[0x100];
3414 DWORD sz;
3415 INT index;
3417 rc = MSI_ViewFetch(view,&row);
3418 if (rc != ERROR_SUCCESS)
3420 rc = ERROR_SUCCESS;
3421 break;
3424 sz = 0x100;
3425 MSI_RecordGetStringW(row,3,component,&sz);
3427 index = get_loaded_component(package,component);
3428 if (index < 0)
3430 msiobj_release(&row->hdr);
3431 continue;
3434 if (!package->components[index].Enabled ||
3435 !package->components[index].FeatureState)
3437 TRACE("Skipping typelib reg due to disabled component\n");
3438 msiobj_release(&row->hdr);
3439 continue;
3442 index = get_loaded_file(package,package->components[index].KeyPath);
3444 if (index < 0)
3446 msiobj_release(&row->hdr);
3447 continue;
3450 res = LoadTypeLib(package->files[index].TargetPath,&ptLib);
3451 if (SUCCEEDED(res))
3453 WCHAR help[MAX_PATH];
3454 WCHAR helpid[0x100];
3456 sz = 0x100;
3457 MSI_RecordGetStringW(row,6,helpid,&sz);
3459 resolve_folder(package,helpid,help,FALSE,FALSE,NULL);
3461 res = RegisterTypeLib(ptLib,package->files[index].TargetPath,help);
3462 if (!SUCCEEDED(res))
3463 ERR("Failed to register type library %s\n",
3464 debugstr_w(package->files[index].TargetPath));
3465 else
3467 /* Yes the row has more fields than I need, but #1 is
3468 correct and the only one I need. Why make a new row? */
3470 ui_actiondata(package,szRegisterTypeLibraries,row);
3472 TRACE("Registered %s\n",
3473 debugstr_w(package->files[index].TargetPath));
3476 if (ptLib)
3477 ITypeLib_Release(ptLib);
3479 else
3480 ERR("Failed to load type library %s\n",
3481 debugstr_w(package->files[index].TargetPath));
3483 msiobj_release(&row->hdr);
3485 MSI_ViewClose(view);
3486 msiobj_release(&view->hdr);
3487 return rc;
3491 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
3493 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3494 UINT rc;
3495 MSIQUERY * view;
3496 MSIRECORD * row = 0;
3497 static const WCHAR ExecSeqQuery[] =
3498 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','p','p','I'
3499 ,'d',' ','w','h','e','r','e',' ','A','p','p','I','d','=','`','%','s','`',0};
3500 WCHAR Query[0x1000];
3501 HKEY hkey2,hkey3;
3502 LPWSTR buffer=0;
3504 if (!package)
3505 return ERROR_INVALID_HANDLE;
3507 sprintfW(Query,ExecSeqQuery,clsid);
3509 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3510 if (rc != ERROR_SUCCESS)
3511 return rc;
3513 rc = MSI_ViewExecute(view, 0);
3514 if (rc != ERROR_SUCCESS)
3516 MSI_ViewClose(view);
3517 msiobj_release(&view->hdr);
3518 return rc;
3521 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
3522 RegCreateKeyW(hkey2,clsid,&hkey3);
3523 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
3524 (strlenW(app)+1)*sizeof(WCHAR));
3526 rc = MSI_ViewFetch(view,&row);
3527 if (rc != ERROR_SUCCESS)
3529 MSI_ViewClose(view);
3530 msiobj_release(&view->hdr);
3531 return rc;
3534 if (!MSI_RecordIsNull(row,2))
3536 LPWSTR deformated=0;
3537 UINT size;
3538 static const WCHAR szRemoteServerName[] =
3539 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
3540 buffer = load_dynamic_stringW(row,2);
3541 size = deformat_string(package,buffer,&deformated);
3542 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
3543 size);
3544 HeapFree(GetProcessHeap(),0,deformated);
3545 HeapFree(GetProcessHeap(),0,buffer);
3548 if (!MSI_RecordIsNull(row,3))
3550 static const WCHAR szLocalService[] =
3551 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
3552 UINT size;
3553 buffer = load_dynamic_stringW(row,3);
3554 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3555 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
3556 HeapFree(GetProcessHeap(),0,buffer);
3559 if (!MSI_RecordIsNull(row,4))
3561 static const WCHAR szService[] =
3562 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
3563 UINT size;
3564 buffer = load_dynamic_stringW(row,4);
3565 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3566 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
3567 HeapFree(GetProcessHeap(),0,buffer);
3570 if (!MSI_RecordIsNull(row,5))
3572 static const WCHAR szDLL[] =
3573 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
3574 UINT size;
3575 buffer = load_dynamic_stringW(row,5);
3576 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3577 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
3578 HeapFree(GetProcessHeap(),0,buffer);
3581 if (!MSI_RecordIsNull(row,6))
3583 static const WCHAR szActivate[] =
3584 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
3585 static const WCHAR szY[] = {'Y',0};
3587 if (MSI_RecordGetInteger(row,6))
3588 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
3591 if (!MSI_RecordIsNull(row,7))
3593 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
3594 static const WCHAR szUser[] =
3595 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
3597 if (MSI_RecordGetInteger(row,7))
3598 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
3601 msiobj_release(&row->hdr);
3602 MSI_ViewClose(view);
3603 msiobj_release(&view->hdr);
3604 RegCloseKey(hkey3);
3605 RegCloseKey(hkey2);
3606 return rc;
3609 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
3612 * Again I am assuming the words, "Whose key file represents" when referring
3613 * to a Component as to meaning that Components KeyPath file
3615 * Also there is a very strong connection between ClassInfo and ProgID
3616 * that I am mostly glossing over.
3617 * What would be more propper is to load the ClassInfo and the ProgID info
3618 * into memory data structures and then be able to enable and disable them
3619 * based on component.
3622 UINT rc;
3623 MSIQUERY * view;
3624 MSIRECORD * row = 0;
3625 static const WCHAR ExecSeqQuery[] = {
3626 'S','E','L','E','C','T',' ','*',' ',
3627 'f','r','o','m',' ','C','l','a','s','s',0};
3628 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3629 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
3630 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3631 HKEY hkey,hkey2,hkey3;
3633 if (!package)
3634 return ERROR_INVALID_HANDLE;
3636 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
3637 if (rc != ERROR_SUCCESS)
3638 return ERROR_FUNCTION_FAILED;
3640 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3641 if (rc != ERROR_SUCCESS)
3643 rc = ERROR_SUCCESS;
3644 goto end;
3647 rc = MSI_ViewExecute(view, 0);
3648 if (rc != ERROR_SUCCESS)
3650 MSI_ViewClose(view);
3651 msiobj_release(&view->hdr);
3652 goto end;
3655 while (1)
3657 WCHAR clsid[0x100];
3658 WCHAR buffer[0x100];
3659 WCHAR desc[0x100];
3660 DWORD sz;
3661 INT index;
3663 rc = MSI_ViewFetch(view,&row);
3664 if (rc != ERROR_SUCCESS)
3666 rc = ERROR_SUCCESS;
3667 break;
3670 sz=0x100;
3671 MSI_RecordGetStringW(row,3,buffer,&sz);
3673 index = get_loaded_component(package,buffer);
3675 if (index < 0)
3677 msiobj_release(&row->hdr);
3678 continue;
3681 if (!package->components[index].Enabled ||
3682 !package->components[index].FeatureState)
3684 TRACE("Skipping class reg due to disabled component\n");
3685 msiobj_release(&row->hdr);
3686 continue;
3689 sz=0x100;
3690 MSI_RecordGetStringW(row,1,clsid,&sz);
3691 RegCreateKeyW(hkey,clsid,&hkey2);
3693 if (!MSI_RecordIsNull(row,5))
3695 sz=0x100;
3696 MSI_RecordGetStringW(row,5,desc,&sz);
3698 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
3699 (strlenW(desc)+1)*sizeof(WCHAR));
3701 else
3702 desc[0]=0;
3704 sz=0x100;
3705 MSI_RecordGetStringW(row,2,buffer,&sz);
3707 RegCreateKeyW(hkey2,buffer,&hkey3);
3709 index = get_loaded_file(package,package->components[index].KeyPath);
3710 RegSetValueExW(hkey3,NULL,0,REG_SZ,
3711 (LPVOID)package->files[index].TargetPath,
3712 (strlenW(package->files[index].TargetPath)+1)
3713 *sizeof(WCHAR));
3715 RegCloseKey(hkey3);
3717 if (!MSI_RecordIsNull(row,4))
3719 sz=0x100;
3720 MSI_RecordGetStringW(row,4,buffer,&sz);
3722 RegCreateKeyW(hkey2,szProgID,&hkey3);
3724 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
3725 (strlenW(buffer)+1)*sizeof(WCHAR));
3727 RegCloseKey(hkey3);
3730 if (!MSI_RecordIsNull(row,6))
3732 sz=0x100;
3733 MSI_RecordGetStringW(row,6,buffer,&sz);
3735 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
3736 (strlenW(buffer)+1)*sizeof(WCHAR));
3738 register_appid(package,buffer,desc);
3741 RegCloseKey(hkey2);
3743 FIXME("Process the rest of the fields >7\n");
3745 ui_actiondata(package,szRegisterClassInfo,row);
3747 msiobj_release(&row->hdr);
3749 MSI_ViewClose(view);
3750 msiobj_release(&view->hdr);
3752 end:
3753 RegCloseKey(hkey);
3754 return rc;
3757 static UINT register_progid_base(MSIRECORD * row, LPWSTR clsid)
3759 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3760 HKEY hkey,hkey2;
3761 WCHAR buffer[0x100];
3762 DWORD sz;
3765 sz = 0x100;
3766 MSI_RecordGetStringW(row,1,buffer,&sz);
3767 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
3769 if (!MSI_RecordIsNull(row,4))
3771 sz = 0x100;
3772 MSI_RecordGetStringW(row,4,buffer,&sz);
3773 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
3774 sizeof(WCHAR));
3777 if (!MSI_RecordIsNull(row,3))
3779 sz = 0x100;
3781 MSI_RecordGetStringW(row,3,buffer,&sz);
3782 RegCreateKeyW(hkey,szCLSID,&hkey2);
3783 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
3784 sizeof(WCHAR));
3786 if (clsid)
3787 strcpyW(clsid,buffer);
3789 RegCloseKey(hkey2);
3791 else
3793 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
3794 return ERROR_FUNCTION_FAILED;
3796 if (!MSI_RecordIsNull(row,5))
3797 FIXME ("UNHANDLED icon in Progid\n");
3798 return ERROR_SUCCESS;
3801 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
3803 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
3804 LPWSTR clsid)
3806 UINT rc;
3807 MSIQUERY * view;
3808 MSIRECORD * row = 0;
3809 static const WCHAR Query_t[] =
3810 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','P','r','o','g'
3811 ,'I','d',' ','w','h','e','r','e',' ','P','r','o','g','I','d',' ','=',' ','`'
3812 ,'%','s','`',0};
3813 WCHAR Query[0x1000];
3815 if (!package)
3816 return ERROR_INVALID_HANDLE;
3818 sprintfW(Query,Query_t,parent);
3820 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3821 if (rc != ERROR_SUCCESS)
3822 return rc;
3824 rc = MSI_ViewExecute(view, 0);
3825 if (rc != ERROR_SUCCESS)
3827 MSI_ViewClose(view);
3828 msiobj_release(&view->hdr);
3829 return rc;
3832 rc = MSI_ViewFetch(view,&row);
3833 if (rc != ERROR_SUCCESS)
3835 MSI_ViewClose(view);
3836 msiobj_release(&view->hdr);
3837 return rc;
3840 register_progid(package,row,clsid);
3842 msiobj_release(&row->hdr);
3843 MSI_ViewClose(view);
3844 msiobj_release(&view->hdr);
3845 return rc;
3848 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
3850 UINT rc = ERROR_SUCCESS;
3852 if (MSI_RecordIsNull(row,2))
3853 rc = register_progid_base(row,clsid);
3854 else
3856 WCHAR buffer[0x1000];
3857 DWORD sz;
3858 HKEY hkey,hkey2;
3859 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3861 sz = 0x100;
3862 MSI_RecordGetStringW(row,2,buffer,&sz);
3863 rc = register_parent_progid(package,buffer,clsid);
3865 sz = 0x100;
3866 MSI_RecordGetStringW(row,1,buffer,&sz);
3867 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
3868 /* clasid is same as parent */
3869 RegCreateKeyW(hkey,szCLSID,&hkey2);
3870 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
3871 sizeof(WCHAR));
3873 RegCloseKey(hkey2);
3874 if (!MSI_RecordIsNull(row,4))
3876 sz = 0x100;
3877 MSI_RecordGetStringW(row,4,buffer,&sz);
3878 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
3879 (strlenW(buffer)+1) * sizeof(WCHAR));
3882 if (!MSI_RecordIsNull(row,5))
3883 FIXME ("UNHANDLED icon in Progid\n");
3885 RegCloseKey(hkey);
3887 return rc;
3890 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
3893 * Sigh, here I am just brute force registering all progids
3894 * this needs to be linked to the Classes that have been registered
3895 * but the easiest way to do that is to load all these stuff into
3896 * memory for easy checking.
3898 * Gives me something to continue to work toward.
3900 UINT rc;
3901 MSIQUERY * view;
3902 MSIRECORD * row = 0;
3903 static const WCHAR Query[] = {
3904 'S','E','L','E','C','T',' ','*',' ',
3905 'F','R','O','M',' ','P','r','o','g','I','d',0};
3907 if (!package)
3908 return ERROR_INVALID_HANDLE;
3910 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3911 if (rc != ERROR_SUCCESS)
3912 return ERROR_SUCCESS;
3914 rc = MSI_ViewExecute(view, 0);
3915 if (rc != ERROR_SUCCESS)
3917 MSI_ViewClose(view);
3918 msiobj_release(&view->hdr);
3919 return rc;
3922 while (1)
3924 WCHAR clsid[0x1000];
3926 rc = MSI_ViewFetch(view,&row);
3927 if (rc != ERROR_SUCCESS)
3929 rc = ERROR_SUCCESS;
3930 break;
3933 register_progid(package,row,clsid);
3934 ui_actiondata(package,szRegisterProgIdInfo,row);
3936 msiobj_release(&row->hdr);
3938 MSI_ViewClose(view);
3939 msiobj_release(&view->hdr);
3940 return rc;
3943 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
3944 LPWSTR FilePath)
3946 WCHAR ProductCode[0x100];
3947 WCHAR SystemFolder[MAX_PATH];
3948 DWORD sz;
3950 static const WCHAR szInstaller[] =
3951 {'I','n','s','t','a','l','l','e','r','\\',0};
3952 static const WCHAR szProductCode[] =
3953 {'P','r','o','d','u','c','t','C','o','d','e',0};
3954 static const WCHAR szFolder[] =
3955 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
3957 sz = 0x100;
3958 MSI_GetPropertyW(package,szProductCode,ProductCode,&sz);
3959 if (strlenW(ProductCode)==0)
3960 return ERROR_FUNCTION_FAILED;
3962 sz = MAX_PATH;
3963 MSI_GetPropertyW(package,szFolder,SystemFolder,&sz);
3964 strcatW(SystemFolder,szInstaller);
3965 strcatW(SystemFolder,ProductCode);
3966 create_full_pathW(SystemFolder);
3968 strcpyW(FilePath,SystemFolder);
3969 strcatW(FilePath,cszbs);
3970 strcatW(FilePath,icon_name);
3971 return ERROR_SUCCESS;
3974 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
3976 UINT rc;
3977 MSIQUERY * view;
3978 MSIRECORD * row = 0;
3979 static const WCHAR Query[] = {
3980 'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
3981 'S','h','o','r','t','c','u','t',0};
3982 IShellLinkW *sl;
3983 IPersistFile *pf;
3984 HRESULT res;
3986 if (!package)
3987 return ERROR_INVALID_HANDLE;
3989 res = CoInitialize( NULL );
3990 if (FAILED (res))
3992 ERR("CoInitialize failed\n");
3993 return ERROR_FUNCTION_FAILED;
3996 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3997 if (rc != ERROR_SUCCESS)
3998 return ERROR_SUCCESS;
4000 rc = MSI_ViewExecute(view, 0);
4001 if (rc != ERROR_SUCCESS)
4003 MSI_ViewClose(view);
4004 msiobj_release(&view->hdr);
4005 return rc;
4008 while (1)
4010 WCHAR target_file[MAX_PATH];
4011 WCHAR buffer[0x100];
4012 DWORD sz;
4013 DWORD index;
4014 static const WCHAR szlnk[]={'.','l','n','k',0};
4016 rc = MSI_ViewFetch(view,&row);
4017 if (rc != ERROR_SUCCESS)
4019 rc = ERROR_SUCCESS;
4020 break;
4023 sz = 0x100;
4024 MSI_RecordGetStringW(row,4,buffer,&sz);
4026 index = get_loaded_component(package,buffer);
4028 if (index < 0)
4030 msiobj_release(&row->hdr);
4031 continue;
4034 if (!package->components[index].Enabled ||
4035 !package->components[index].FeatureState)
4037 TRACE("Skipping shortcut creation due to disabled component\n");
4038 msiobj_release(&row->hdr);
4039 continue;
4042 ui_actiondata(package,szCreateShortcuts,row);
4044 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
4045 &IID_IShellLinkW, (LPVOID *) &sl );
4047 if (FAILED(res))
4049 ERR("Is IID_IShellLink\n");
4050 msiobj_release(&row->hdr);
4051 continue;
4054 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
4055 if( FAILED( res ) )
4057 ERR("Is IID_IPersistFile\n");
4058 msiobj_release(&row->hdr);
4059 continue;
4062 sz = 0x100;
4063 MSI_RecordGetStringW(row,2,buffer,&sz);
4064 resolve_folder(package, buffer,target_file,FALSE,FALSE,NULL);
4066 sz = 0x100;
4067 MSI_RecordGetStringW(row,3,buffer,&sz);
4068 reduce_to_longfilename(buffer);
4069 strcatW(target_file,buffer);
4070 if (!strchrW(target_file,'.'))
4071 strcatW(target_file,szlnk);
4073 sz = 0x100;
4074 MSI_RecordGetStringW(row,5,buffer,&sz);
4075 if (strchrW(buffer,'['))
4077 LPWSTR deformated;
4078 deformat_string(package,buffer,&deformated);
4079 IShellLinkW_SetPath(sl,deformated);
4080 HeapFree(GetProcessHeap(),0,deformated);
4082 else
4084 FIXME("UNHANDLED shortcut format, advertised shortcut\n");
4085 IPersistFile_Release( pf );
4086 IShellLinkW_Release( sl );
4087 msiobj_release(&row->hdr);
4088 continue;
4091 if (!MSI_RecordIsNull(row,6))
4093 LPWSTR deformated;
4094 sz = 0x100;
4095 MSI_RecordGetStringW(row,6,buffer,&sz);
4096 deformat_string(package,buffer,&deformated);
4097 IShellLinkW_SetArguments(sl,deformated);
4098 HeapFree(GetProcessHeap(),0,deformated);
4101 if (!MSI_RecordIsNull(row,7))
4103 LPWSTR deformated;
4104 deformated = load_dynamic_stringW(row,7);
4105 IShellLinkW_SetDescription(sl,deformated);
4106 HeapFree(GetProcessHeap(),0,deformated);
4109 if (!MSI_RecordIsNull(row,8))
4110 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
4112 if (!MSI_RecordIsNull(row,9))
4114 WCHAR Path[MAX_PATH];
4115 INT index;
4117 sz = 0x100;
4118 MSI_RecordGetStringW(row,9,buffer,&sz);
4120 build_icon_path(package,buffer,Path);
4121 index = MSI_RecordGetInteger(row,10);
4123 IShellLinkW_SetIconLocation(sl,Path,index);
4126 if (!MSI_RecordIsNull(row,11))
4127 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
4129 if (!MSI_RecordIsNull(row,12))
4131 WCHAR Path[MAX_PATH];
4133 sz = 0x100;
4134 MSI_RecordGetStringW(row,12,buffer,&sz);
4135 resolve_folder(package, buffer, Path, FALSE, FALSE, NULL);
4136 IShellLinkW_SetWorkingDirectory(sl,Path);
4139 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
4140 IPersistFile_Save(pf,target_file,FALSE);
4142 IPersistFile_Release( pf );
4143 IShellLinkW_Release( sl );
4145 msiobj_release(&row->hdr);
4147 MSI_ViewClose(view);
4148 msiobj_release(&view->hdr);
4151 CoUninitialize();
4153 return rc;
4158 * 99% of the work done here is only done for
4159 * advertised installs. However this is where the
4160 * Icon table is processed and written out
4161 * so that is what I am going to do here.
4163 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
4165 UINT rc;
4166 MSIQUERY * view;
4167 MSIRECORD * row = 0;
4168 static const WCHAR Query[]={
4169 'S','E','L','E','C','T',' ','*',' ',
4170 'f','r','o','m',' ','I','c','o','n',0};
4171 DWORD sz;
4173 if (!package)
4174 return ERROR_INVALID_HANDLE;
4176 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4177 if (rc != ERROR_SUCCESS)
4178 return ERROR_SUCCESS;
4180 rc = MSI_ViewExecute(view, 0);
4181 if (rc != ERROR_SUCCESS)
4183 MSI_ViewClose(view);
4184 msiobj_release(&view->hdr);
4185 return rc;
4188 while (1)
4190 HANDLE the_file;
4191 WCHAR FilePath[MAX_PATH];
4192 WCHAR FileName[MAX_PATH];
4193 CHAR buffer[1024];
4195 rc = MSI_ViewFetch(view,&row);
4196 if (rc != ERROR_SUCCESS)
4198 rc = ERROR_SUCCESS;
4199 break;
4202 sz = MAX_PATH;
4203 MSI_RecordGetStringW(row,1,FileName,&sz);
4204 if (sz == 0)
4206 ERR("Unable to get FileName\n");
4207 msiobj_release(&row->hdr);
4208 continue;
4211 build_icon_path(package,FileName,FilePath);
4213 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
4215 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
4216 FILE_ATTRIBUTE_NORMAL, NULL);
4218 if (the_file == INVALID_HANDLE_VALUE)
4220 ERR("Unable to create file %s\n",debugstr_w(FilePath));
4221 msiobj_release(&row->hdr);
4222 continue;
4227 DWORD write;
4228 sz = 1024;
4229 rc = MSI_RecordReadStream(row,2,buffer,&sz);
4230 if (rc != ERROR_SUCCESS)
4232 ERR("Failed to get stream\n");
4233 CloseHandle(the_file);
4234 DeleteFileW(FilePath);
4235 break;
4237 WriteFile(the_file,buffer,sz,&write,NULL);
4238 } while (sz == 1024);
4240 CloseHandle(the_file);
4241 msiobj_release(&row->hdr);
4243 MSI_ViewClose(view);
4244 msiobj_release(&view->hdr);
4245 return rc;
4249 /* Msi functions that seem appropriate here */
4250 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
4252 LPWSTR szwAction;
4253 UINT rc;
4255 TRACE(" exteral attempt at action %s\n",szAction);
4257 if (!szAction)
4258 return ERROR_FUNCTION_FAILED;
4259 if (hInstall == 0)
4260 return ERROR_FUNCTION_FAILED;
4262 szwAction = strdupAtoW(szAction);
4264 if (!szwAction)
4265 return ERROR_FUNCTION_FAILED;
4268 rc = MsiDoActionW(hInstall, szwAction);
4269 HeapFree(GetProcessHeap(),0,szwAction);
4270 return rc;
4273 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
4275 MSIPACKAGE *package;
4276 UINT ret = ERROR_INVALID_HANDLE;
4278 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
4280 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4281 if( package )
4283 ret = ACTION_PerformAction(package,szAction);
4284 msiobj_release( &package->hdr );
4286 return ret;
4289 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
4290 LPSTR szPathBuf, DWORD* pcchPathBuf)
4292 LPWSTR szwFolder;
4293 LPWSTR szwPathBuf;
4294 UINT rc;
4296 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4298 if (!szFolder)
4299 return ERROR_FUNCTION_FAILED;
4300 if (hInstall == 0)
4301 return ERROR_FUNCTION_FAILED;
4303 szwFolder = strdupAtoW(szFolder);
4305 if (!szwFolder)
4306 return ERROR_FUNCTION_FAILED;
4308 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4310 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4312 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4313 *pcchPathBuf, NULL, NULL );
4315 HeapFree(GetProcessHeap(),0,szwFolder);
4316 HeapFree(GetProcessHeap(),0,szwPathBuf);
4318 return rc;
4321 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4322 szPathBuf, DWORD* pcchPathBuf)
4324 WCHAR path[MAX_PATH];
4325 UINT rc;
4326 MSIPACKAGE *package;
4328 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
4330 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4331 if( !package )
4332 return ERROR_INVALID_HANDLE;
4333 rc = resolve_folder(package, szFolder, path, FALSE, FALSE, NULL);
4334 msiobj_release( &package->hdr );
4336 if (rc == ERROR_SUCCESS && strlenW(path) > *pcchPathBuf)
4338 *pcchPathBuf = strlenW(path)+1;
4339 return ERROR_MORE_DATA;
4341 else if (rc == ERROR_SUCCESS)
4343 *pcchPathBuf = strlenW(path)+1;
4344 strcpyW(szPathBuf,path);
4345 TRACE("Returning Path %s\n",debugstr_w(path));
4348 return rc;
4352 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
4353 LPSTR szPathBuf, DWORD* pcchPathBuf)
4355 LPWSTR szwFolder;
4356 LPWSTR szwPathBuf;
4357 UINT rc;
4359 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4361 if (!szFolder)
4362 return ERROR_FUNCTION_FAILED;
4363 if (hInstall == 0)
4364 return ERROR_FUNCTION_FAILED;
4366 szwFolder = strdupAtoW(szFolder);
4367 if (!szwFolder)
4368 return ERROR_FUNCTION_FAILED;
4370 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4372 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4374 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4375 *pcchPathBuf, NULL, NULL );
4377 HeapFree(GetProcessHeap(),0,szwFolder);
4378 HeapFree(GetProcessHeap(),0,szwPathBuf);
4380 return rc;
4383 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4384 szPathBuf, DWORD* pcchPathBuf)
4386 WCHAR path[MAX_PATH];
4387 UINT rc;
4388 MSIPACKAGE *package;
4390 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
4392 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4393 if( !package )
4394 return ERROR_INVALID_HANDLE;
4395 rc = resolve_folder(package, szFolder, path, TRUE, FALSE, NULL);
4396 msiobj_release( &package->hdr );
4398 if (rc == ERROR_SUCCESS && strlenW(path) > *pcchPathBuf)
4400 *pcchPathBuf = strlenW(path)+1;
4401 return ERROR_MORE_DATA;
4403 else if (rc == ERROR_SUCCESS)
4405 *pcchPathBuf = strlenW(path)+1;
4406 strcpyW(szPathBuf,path);
4407 TRACE("Returning Path %s\n",debugstr_w(path));
4410 return rc;
4414 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
4415 LPCSTR szFolderPath)
4417 LPWSTR szwFolder;
4418 LPWSTR szwFolderPath;
4419 UINT rc;
4421 if (!szFolder)
4422 return ERROR_FUNCTION_FAILED;
4423 if (hInstall == 0)
4424 return ERROR_FUNCTION_FAILED;
4426 szwFolder = strdupAtoW(szFolder);
4427 if (!szwFolder)
4428 return ERROR_FUNCTION_FAILED;
4430 szwFolderPath = strdupAtoW(szFolderPath);
4431 if (!szwFolderPath)
4433 HeapFree(GetProcessHeap(),0,szwFolder);
4434 return ERROR_FUNCTION_FAILED;
4437 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
4439 HeapFree(GetProcessHeap(),0,szwFolder);
4440 HeapFree(GetProcessHeap(),0,szwFolderPath);
4442 return rc;
4445 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
4446 LPCWSTR szFolderPath)
4448 DWORD i;
4449 WCHAR path[MAX_PATH];
4450 MSIFOLDER *folder;
4452 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
4454 if (package==NULL)
4455 return ERROR_INVALID_HANDLE;
4457 if (szFolderPath[0]==0)
4458 return ERROR_FUNCTION_FAILED;
4460 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
4461 return ERROR_FUNCTION_FAILED;
4463 resolve_folder(package,szFolder,path,FALSE,FALSE,&folder);
4465 if (!folder)
4466 return ERROR_INVALID_PARAMETER;
4468 strcpyW(folder->Property,szFolderPath);
4470 for (i = 0; i < package->loaded_folders; i++)
4471 package->folders[i].ResolvedTarget[0]=0;
4473 for (i = 0; i < package->loaded_folders; i++)
4474 resolve_folder(package, package->folders[i].Directory, path, FALSE,
4475 TRUE, NULL);
4477 return ERROR_SUCCESS;
4480 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
4481 LPCWSTR szFolderPath)
4483 MSIPACKAGE *package;
4484 UINT ret;
4486 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
4488 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4489 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
4490 msiobj_release( &package->hdr );
4491 return ret;
4494 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, DWORD iRunMode)
4496 FIXME("STUB (%li)\n",iRunMode);
4497 return FALSE;
4501 * according to the docs when this is called it immediently recalculates all the
4502 * components states as well
4504 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
4505 INSTALLSTATE iState)
4507 LPWSTR szwFeature = NULL;
4508 UINT rc;
4510 szwFeature = strdupAtoW(szFeature);
4512 if (!szwFeature)
4513 return ERROR_FUNCTION_FAILED;
4515 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
4517 HeapFree(GetProcessHeap(),0,szwFeature);
4519 return rc;
4522 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
4523 INSTALLSTATE iState)
4525 MSIPACKAGE* package;
4526 INT index;
4528 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
4530 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4531 if (!package)
4532 return ERROR_INVALID_HANDLE;
4534 index = get_loaded_feature(package,szFeature);
4535 if (index < 0)
4536 return ERROR_UNKNOWN_FEATURE;
4538 package->features[index].State = iState;
4540 return ERROR_SUCCESS;
4543 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
4544 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4546 LPWSTR szwFeature = NULL;
4547 UINT rc;
4549 szwFeature = strdupAtoW(szFeature);
4551 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
4553 HeapFree( GetProcessHeap(), 0 , szwFeature);
4555 return rc;
4558 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
4559 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4561 INT index;
4563 index = get_loaded_feature(package,szFeature);
4564 if (index < 0)
4565 return ERROR_UNKNOWN_FEATURE;
4567 if (piInstalled)
4568 *piInstalled = package->features[index].State;
4570 if (piAction)
4572 if (package->features[index].Enabled)
4573 *piAction = INSTALLSTATE_LOCAL;
4574 else
4575 *piAction = INSTALLSTATE_UNKNOWN;
4578 return ERROR_SUCCESS;
4581 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
4582 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4584 MSIPACKAGE* package;
4585 UINT ret;
4587 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
4588 piAction);
4590 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4591 if (!package)
4592 return ERROR_INVALID_HANDLE;
4593 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
4594 msiobj_release( &package->hdr );
4595 return ret;
4598 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
4599 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4601 LPWSTR szwComponent= NULL;
4602 UINT rc;
4604 szwComponent= strdupAtoW(szComponent);
4606 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
4608 HeapFree( GetProcessHeap(), 0 , szwComponent);
4610 return rc;
4613 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
4614 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4616 INT index;
4618 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
4619 piAction);
4621 index = get_loaded_component(package,szComponent);
4622 if (index < 0)
4623 return ERROR_UNKNOWN_COMPONENT;
4625 if (piInstalled)
4626 *piInstalled = package->components[index].State;
4628 if (piAction)
4630 if (package->components[index].Enabled &&
4631 package->components[index].FeatureState)
4632 *piAction = INSTALLSTATE_LOCAL;
4633 else
4634 *piAction = INSTALLSTATE_UNKNOWN;
4637 return ERROR_SUCCESS;
4640 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
4641 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4643 MSIPACKAGE* package;
4644 UINT ret;
4646 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
4647 piInstalled, piAction);
4649 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4650 if (!package)
4651 return ERROR_INVALID_HANDLE;
4652 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
4653 msiobj_release( &package->hdr );
4654 return ret;
4657 #if 0
4658 static UINT ACTION_Template(MSIPACKAGE *package)
4660 UINT rc;
4661 MSIQUERY * view;
4662 MSIRECORD * row = 0;
4663 static const WCHAR ExecSeqQuery[] = {0};
4665 rc = MsiDatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4666 if (rc != ERROR_SUCCESS)
4667 return rc;
4669 rc = MsiViewExecute(view, 0);
4670 if (rc != ERROR_SUCCESS)
4672 MsiViewClose(view);
4673 msiobj_release(&view->hdr);
4674 return rc;
4677 while (1)
4679 rc = MsiViewFetch(view,&row);
4680 if (rc != ERROR_SUCCESS)
4682 rc = ERROR_SUCCESS;
4683 break;
4686 msiobj_release(&row->hdr);
4688 MsiViewClose(view);
4689 msiobj_release(&view->hdr);
4690 return rc;
4692 #endif