DrawTextEx should allocate text buffer on stack for thread safeness.
[wine/hacks.git] / dlls / msi / action.c
blob41179805591d88655200b4afe2e4903f96cf1263
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 #define COBJMACROS
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winerror.h"
37 #include "winreg.h"
38 #include "wine/debug.h"
39 #include "fdi.h"
40 #include "msi.h"
41 #include "msiquery.h"
42 #include "msvcrt/fcntl.h"
43 #include "objbase.h"
44 #include "objidl.h"
45 #include "msipriv.h"
46 #include "winnls.h"
47 #include "winuser.h"
48 #include "shlobj.h"
49 #include "wine/unicode.h"
50 #include "ver.h"
52 #define CUSTOM_ACTION_TYPE_MASK 0x3F
54 WINE_DEFAULT_DEBUG_CHANNEL(msi);
56 typedef struct tagMSIFEATURE
58 WCHAR Feature[96];
59 WCHAR Feature_Parent[96];
60 WCHAR Title[0x100];
61 WCHAR Description[0x100];
62 INT Display;
63 INT Level;
64 WCHAR Directory[96];
65 INT Attributes;
67 INSTALLSTATE State;
68 BOOL Enabled;
69 INT ComponentCount;
70 INT Components[1024]; /* yes hardcoded limit.... I am bad */
71 INT Cost;
72 } MSIFEATURE;
74 typedef struct tagMSICOMPONENT
76 WCHAR Component[96];
77 WCHAR ComponentId[96];
78 WCHAR Directory[96];
79 INT Attributes;
80 WCHAR Condition[0x100];
81 WCHAR KeyPath[96];
83 INSTALLSTATE State;
84 BOOL FeatureState;
85 BOOL Enabled;
86 INT Cost;
87 } MSICOMPONENT;
89 typedef struct tagMSIFOLDER
91 WCHAR Directory[96];
92 WCHAR TargetDefault[96];
93 WCHAR SourceDefault[96];
95 WCHAR ResolvedTarget[MAX_PATH];
96 WCHAR ResolvedSource[MAX_PATH];
97 WCHAR Property[MAX_PATH]; /* initially set property */
98 INT ParentIndex;
99 INT State;
100 /* 0 = uninitialized */
101 /* 1 = existing */
102 /* 2 = created remove if empty */
103 /* 3 = created persist if empty */
104 INT Cost;
105 INT Space;
106 }MSIFOLDER;
108 typedef struct tagMSIFILE
110 WCHAR File[72];
111 INT ComponentIndex;
112 WCHAR FileName[MAX_PATH];
113 INT FileSize;
114 WCHAR Version[72];
115 WCHAR Language[20];
116 INT Attributes;
117 INT Sequence;
119 INT State;
120 /* 0 = uninitialize */
121 /* 1 = not present */
122 /* 2 = present but replace */
123 /* 3 = present do not replace */
124 /* 4 = Installed */
125 WCHAR SourcePath[MAX_PATH];
126 WCHAR TargetPath[MAX_PATH];
127 BOOL Temporary;
128 }MSIFILE;
131 * Prototypes
133 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran);
134 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package);
136 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action);
138 static UINT ACTION_LaunchConditions(MSIPACKAGE *package);
139 static UINT ACTION_CostInitialize(MSIPACKAGE *package);
140 static UINT ACTION_CreateFolders(MSIPACKAGE *package);
141 static UINT ACTION_CostFinalize(MSIPACKAGE *package);
142 static UINT ACTION_FileCost(MSIPACKAGE *package);
143 static UINT ACTION_InstallFiles(MSIPACKAGE *package);
144 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package);
145 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package);
146 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action);
147 static UINT ACTION_InstallInitialize(MSIPACKAGE *package);
148 static UINT ACTION_InstallValidate(MSIPACKAGE *package);
149 static UINT ACTION_ProcessComponents(MSIPACKAGE *package);
150 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package);
151 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package);
152 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package);
153 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package);
154 static UINT ACTION_PublishProduct(MSIPACKAGE *package);
156 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
157 const LPWSTR target, const INT type);
158 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
159 const LPWSTR target, const INT type);
160 static UINT HANDLE_CustomType18(MSIPACKAGE *package, const LPWSTR source,
161 const LPWSTR target, const INT type);
162 static UINT HANDLE_CustomType50(MSIPACKAGE *package, const LPWSTR source,
163 const LPWSTR target, const INT type);
164 static UINT HANDLE_CustomType34(MSIPACKAGE *package, const LPWSTR source,
165 const LPWSTR target, const INT type);
167 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data);
168 static UINT resolve_folder(MSIPACKAGE *package, LPCWSTR name, LPWSTR path,
169 BOOL source, BOOL set_prop, MSIFOLDER **folder);
171 static int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path);
174 * consts and values used
176 static const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
177 static const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
178 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
179 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
180 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
181 static const WCHAR c_collen[] = {'C',':','\\',0};
183 static const WCHAR cszlsb[]={'[',0};
184 static const WCHAR cszrsb[]={']',0};
185 static const WCHAR cszbs[]={'\\',0};
187 const static WCHAR szCreateFolders[] =
188 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
189 const static WCHAR szCostFinalize[] =
190 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
191 const static WCHAR szInstallFiles[] =
192 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
193 const static WCHAR szDuplicateFiles[] =
194 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
195 const static WCHAR szWriteRegistryValues[] =
196 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
197 const static WCHAR szCostInitialize[] =
198 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
199 const static WCHAR szFileCost[] = {'F','i','l','e','C','o','s','t',0};
200 const static WCHAR szInstallInitialize[] =
201 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
202 const static WCHAR szInstallValidate[] =
203 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
204 const static WCHAR szLaunchConditions[] =
205 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
206 const static WCHAR szProcessComponents[] =
207 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
208 const static WCHAR szRegisterTypeLibraries[] =
209 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r',
210 'i','e','s',0};
211 const static WCHAR szRegisterClassInfo[] =
212 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
213 const static WCHAR szRegisterProgIdInfo[] =
214 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
215 const static WCHAR szCreateShortcuts[] =
216 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
217 const static WCHAR szPublishProduct[] =
218 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
220 /********************************************************
221 * helper functions to get around current HACKS and such
222 ********************************************************/
223 inline static void reduce_to_longfilename(WCHAR* filename)
225 if (strchrW(filename,'|'))
227 WCHAR newname[MAX_PATH];
228 strcpyW(newname,strchrW(filename,'|')+1);
229 strcpyW(filename,newname);
233 inline static char *strdupWtoA( const WCHAR *str )
235 char *ret = NULL;
236 if (str)
238 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL
240 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
241 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
243 return ret;
246 inline static WCHAR *strdupAtoW( const char *str )
248 WCHAR *ret = NULL;
249 if (str)
251 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
252 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
253 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
255 return ret;
258 inline static WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
260 UINT rc;
261 DWORD sz;
262 LPWSTR ret;
264 sz = 0;
265 rc = MSI_RecordGetStringW(row,index,NULL,&sz);
266 if (sz <= 0)
267 return NULL;
269 sz ++;
270 ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
271 rc = MSI_RecordGetStringW(row,index,ret,&sz);
272 return ret;
275 inline static int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
277 int rc = -1;
278 DWORD i;
280 for (i = 0; i < package->loaded_components; i++)
282 if (strcmpW(Component,package->components[i].Component)==0)
284 rc = i;
285 break;
288 return rc;
291 inline static int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
293 int rc = -1;
294 DWORD i;
296 for (i = 0; i < package->loaded_features; i++)
298 if (strcmpW(Feature,package->features[i].Feature)==0)
300 rc = i;
301 break;
304 return rc;
307 inline static int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
309 int rc = -1;
310 DWORD i;
312 for (i = 0; i < package->loaded_files; i++)
314 if (strcmpW(file,package->files[i].File)==0)
316 rc = i;
317 break;
320 return rc;
323 static int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
325 DWORD i;
326 DWORD index;
328 if (!package)
329 return -2;
331 for (i=0; i < package->loaded_files; i++)
332 if (strcmpW(package->files[i].File,name)==0)
333 return -1;
335 index = package->loaded_files;
336 package->loaded_files++;
337 if (package->loaded_files== 1)
338 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
339 else
340 package->files = HeapReAlloc(GetProcessHeap(),0,
341 package->files , package->loaded_files * sizeof(MSIFILE));
343 memset(&package->files[index],0,sizeof(MSIFILE));
345 strcpyW(package->files[index].File,name);
346 strcpyW(package->files[index].TargetPath,path);
347 package->files[index].Temporary = TRUE;
349 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
351 return 0;
354 void ACTION_remove_tracked_tempfiles(MSIPACKAGE* package)
356 DWORD i;
358 if (!package)
359 return;
361 for (i = 0; i < package->loaded_files; i++)
363 if (package->files[i].Temporary)
364 DeleteFileW(package->files[i].TargetPath);
369 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
371 MSIRECORD * row;
373 row = MSI_CreateRecord(4);
374 MSI_RecordSetInteger(row,1,a);
375 MSI_RecordSetInteger(row,2,b);
376 MSI_RecordSetInteger(row,3,c);
377 MSI_RecordSetInteger(row,4,d);
378 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
379 msiobj_release(&row->hdr);
382 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
384 static const WCHAR Query_t[] =
385 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
386 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
387 ' ','\'','%','s','\'',0};
388 WCHAR message[1024];
389 UINT rc;
390 MSIQUERY * view;
391 MSIRECORD * row = 0;
392 static WCHAR *ActionFormat=NULL;
393 static WCHAR LastAction[0x100] = {0};
394 WCHAR Query[1024];
395 LPWSTR ptr;
397 if (strcmpW(LastAction,action)!=0)
399 sprintfW(Query,Query_t,action);
400 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
401 if (rc != ERROR_SUCCESS)
402 return;
403 rc = MSI_ViewExecute(view, 0);
404 if (rc != ERROR_SUCCESS)
406 MSI_ViewClose(view);
407 return;
409 rc = MSI_ViewFetch(view,&row);
410 if (rc != ERROR_SUCCESS)
412 MSI_ViewClose(view);
413 return;
416 if (MSI_RecordIsNull(row,3))
418 msiobj_release(&row->hdr);
419 MSI_ViewClose(view);
420 msiobj_release(&view->hdr);
421 return;
424 if (ActionFormat)
425 HeapFree(GetProcessHeap(),0,ActionFormat);
427 ActionFormat = load_dynamic_stringW(row,3);
428 strcpyW(LastAction,action);
429 msiobj_release(&row->hdr);
430 MSI_ViewClose(view);
431 msiobj_release(&view->hdr);
434 message[0]=0;
435 ptr = ActionFormat;
436 while (*ptr)
438 LPWSTR ptr2;
439 LPWSTR data=NULL;
440 WCHAR tmp[1023];
441 INT field;
443 ptr2 = strchrW(ptr,'[');
444 if (ptr2)
446 strncpyW(tmp,ptr,ptr2-ptr);
447 tmp[ptr2-ptr]=0;
448 strcatW(message,tmp);
449 ptr2++;
450 field = atoiW(ptr2);
451 data = load_dynamic_stringW(record,field);
452 if (data)
454 strcatW(message,data);
455 HeapFree(GetProcessHeap(),0,data);
457 ptr=strchrW(ptr2,']');
458 ptr++;
460 else
462 strcatW(message,ptr);
463 break;
467 row = MSI_CreateRecord(1);
468 MSI_RecordSetStringW(row,1,message);
470 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
471 msiobj_release(&row->hdr);
475 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
477 static const WCHAR template_s[]=
478 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ','%','s','.',0};
479 static const WCHAR format[] =
480 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
481 static const WCHAR Query_t[] =
482 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
483 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
484 ' ','\'','%','s','\'',0};
485 WCHAR message[1024];
486 WCHAR timet[0x100];
487 UINT rc;
488 MSIQUERY * view;
489 MSIRECORD * row = 0;
490 WCHAR *ActionText=NULL;
491 WCHAR Query[1024];
493 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
495 sprintfW(Query,Query_t,action);
496 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
497 if (rc != ERROR_SUCCESS)
498 return;
499 rc = MSI_ViewExecute(view, 0);
500 if (rc != ERROR_SUCCESS)
502 MSI_ViewClose(view);
503 msiobj_release(&view->hdr);
504 return;
506 rc = MSI_ViewFetch(view,&row);
507 if (rc != ERROR_SUCCESS)
509 MSI_ViewClose(view);
510 msiobj_release(&view->hdr);
511 return;
514 ActionText = load_dynamic_stringW(row,2);
515 msiobj_release(&row->hdr);
516 MSI_ViewClose(view);
517 msiobj_release(&view->hdr);
519 sprintfW(message,template_s,timet,action,ActionText);
521 row = MSI_CreateRecord(1);
522 MSI_RecordSetStringW(row,1,message);
524 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
525 msiobj_release(&row->hdr);
526 HeapFree(GetProcessHeap(),0,ActionText);
529 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
530 UINT rc)
532 MSIRECORD * row;
533 static const WCHAR template_s[]=
534 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ','%','s',
535 '.',0};
536 static const WCHAR template_e[]=
537 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ','%','s',
538 '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ','%','i','.',0};
539 static const WCHAR format[] =
540 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
541 WCHAR message[1024];
542 WCHAR timet[0x100];
544 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
545 if (start)
546 sprintfW(message,template_s,timet,action);
547 else
548 sprintfW(message,template_e,timet,action,rc);
550 row = MSI_CreateRecord(1);
551 MSI_RecordSetStringW(row,1,message);
553 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
554 msiobj_release(&row->hdr);
557 /****************************************************
558 * TOP level entry points
559 *****************************************************/
561 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
562 LPCWSTR szCommandLine)
564 DWORD sz;
565 WCHAR buffer[10];
566 UINT rc;
567 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
569 if (szPackagePath)
571 LPWSTR p;
572 WCHAR check[MAX_PATH];
573 WCHAR pth[MAX_PATH];
574 DWORD size;
576 strcpyW(pth,szPackagePath);
577 p = strrchrW(pth,'\\');
578 if (p)
580 p++;
581 *p=0;
584 size = MAX_PATH;
585 if (MSI_GetPropertyW(package,cszSourceDir,check,&size)
586 != ERROR_SUCCESS )
587 MSI_SetPropertyW(package, cszSourceDir, pth);
590 if (szCommandLine)
592 LPWSTR ptr,ptr2;
593 ptr = (LPWSTR)szCommandLine;
595 while (*ptr)
597 WCHAR prop[0x100];
598 WCHAR val[0x100];
600 TRACE("Looking at %s\n",debugstr_w(ptr));
602 ptr2 = strchrW(ptr,'=');
603 if (ptr2)
605 BOOL quote=FALSE;
606 DWORD len = 0;
608 while (*ptr == ' ') ptr++;
609 strncpyW(prop,ptr,ptr2-ptr);
610 prop[ptr2-ptr]=0;
611 ptr2++;
613 ptr = ptr2;
614 while (*ptr && (quote || (!quote && *ptr!=' ')))
616 if (*ptr == '"')
617 quote = !quote;
618 ptr++;
619 len++;
622 if (*ptr2=='"')
624 ptr2++;
625 len -= 2;
627 strncpyW(val,ptr2,len);
628 val[len]=0;
630 if (strlenW(prop) > 0)
632 TRACE("Found commandline property (%s) = (%s)\n", debugstr_w(prop), debugstr_w(val));
633 MSI_SetPropertyW(package,prop,val);
636 ptr++;
640 sz = 10;
641 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
643 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
645 rc = ACTION_ProcessUISequence(package);
646 if (rc == ERROR_SUCCESS)
647 rc = ACTION_ProcessExecSequence(package,TRUE);
649 else
650 rc = ACTION_ProcessExecSequence(package,FALSE);
652 else
653 rc = ACTION_ProcessExecSequence(package,FALSE);
655 return rc;
659 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
661 MSIQUERY * view;
662 UINT rc;
663 static const WCHAR ExecSeqQuery[] = {
664 's','e','l','e','c','t',' ','*',' ',
665 'f','r','o','m',' ',
666 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
667 'S','e','q','u','e','n','c','e',' ',
668 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
669 '>',' ','%','i',' ','o','r','d','e','r',' ',
670 'b','y',' ','S','e','q','u','e','n','c','e',0 };
671 WCHAR Query[1024];
672 MSIRECORD * row = 0;
673 static const WCHAR IVQuery[] = {
674 's','e','l','e','c','t',' ','S','e','q','u','e','n','c','e',' ',
675 'f','r','o','m',' ','I','n','s','t','a','l','l',
676 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
677 'w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',' ',
678 '`','I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`',
681 if (UIran)
683 INT seq = 0;
685 rc = MSI_DatabaseOpenViewW(package->db, IVQuery, &view);
686 if (rc != ERROR_SUCCESS)
687 return rc;
688 rc = MSI_ViewExecute(view, 0);
689 if (rc != ERROR_SUCCESS)
691 MSI_ViewClose(view);
692 msiobj_release(&view->hdr);
693 return rc;
695 rc = MSI_ViewFetch(view,&row);
696 if (rc != ERROR_SUCCESS)
698 MSI_ViewClose(view);
699 msiobj_release(&view->hdr);
700 return rc;
702 seq = MSI_RecordGetInteger(row,1);
703 msiobj_release(&row->hdr);
704 MSI_ViewClose(view);
705 msiobj_release(&view->hdr);
706 sprintfW(Query,ExecSeqQuery,seq);
708 else
709 sprintfW(Query,ExecSeqQuery,0);
711 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
712 if (rc == ERROR_SUCCESS)
714 rc = MSI_ViewExecute(view, 0);
716 if (rc != ERROR_SUCCESS)
718 MSI_ViewClose(view);
719 msiobj_release(&view->hdr);
720 goto end;
723 TRACE("Running the actions \n");
725 while (1)
727 WCHAR buffer[0x100];
728 DWORD sz = 0x100;
730 rc = MSI_ViewFetch(view,&row);
731 if (rc != ERROR_SUCCESS)
733 rc = ERROR_SUCCESS;
734 break;
737 /* check conditions */
738 if (!MSI_RecordIsNull(row,2))
740 LPWSTR cond = NULL;
741 cond = load_dynamic_stringW(row,2);
743 if (cond)
745 /* this is a hack to skip errors in the condition code */
746 if (MSI_EvaluateConditionW(package, cond) ==
747 MSICONDITION_FALSE)
749 HeapFree(GetProcessHeap(),0,cond);
750 msiobj_release(&row->hdr);
751 continue;
753 else
754 HeapFree(GetProcessHeap(),0,cond);
758 sz=0x100;
759 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
760 if (rc != ERROR_SUCCESS)
762 ERR("Error is %x\n",rc);
763 msiobj_release(&row->hdr);
764 break;
767 rc = ACTION_PerformAction(package,buffer);
769 if (rc == ERROR_FUNCTION_NOT_CALLED)
770 rc = ERROR_SUCCESS;
772 if (rc != ERROR_SUCCESS)
774 ERR("Execution halted due to error (%i)\n",rc);
775 msiobj_release(&row->hdr);
776 break;
779 msiobj_release(&row->hdr);
782 MSI_ViewClose(view);
783 msiobj_release(&view->hdr);
786 end:
787 return rc;
791 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
793 MSIQUERY * view;
794 UINT rc;
795 static const WCHAR ExecSeqQuery [] = {
796 's','e','l','e','c','t',' ','*',' ',
797 'f','r','o','m',' ','I','n','s','t','a','l','l',
798 'U','I','S','e','q','u','e','n','c','e',' ',
799 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ', '>',' ','0',' ',
800 'o','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e',0};
802 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
804 if (rc == ERROR_SUCCESS)
806 rc = MSI_ViewExecute(view, 0);
808 if (rc != ERROR_SUCCESS)
810 MSI_ViewClose(view);
811 msiobj_release(&view->hdr);
812 goto end;
815 TRACE("Running the actions \n");
817 while (1)
819 WCHAR buffer[0x100];
820 DWORD sz = 0x100;
821 MSIRECORD * row = 0;
823 rc = MSI_ViewFetch(view,&row);
824 if (rc != ERROR_SUCCESS)
826 rc = ERROR_SUCCESS;
827 break;
830 /* check conditions */
831 if (!MSI_RecordIsNull(row,2))
833 LPWSTR cond = NULL;
834 cond = load_dynamic_stringW(row,2);
836 if (cond)
838 /* this is a hack to skip errors in the condition code */
839 if (MSI_EvaluateConditionW(package, cond) ==
840 MSICONDITION_FALSE)
842 HeapFree(GetProcessHeap(),0,cond);
843 msiobj_release(&row->hdr);
844 continue;
846 else
847 HeapFree(GetProcessHeap(),0,cond);
851 sz=0x100;
852 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
853 if (rc != ERROR_SUCCESS)
855 ERR("Error is %x\n",rc);
856 msiobj_release(&row->hdr);
857 break;
860 rc = ACTION_PerformAction(package,buffer);
862 if (rc == ERROR_FUNCTION_NOT_CALLED)
863 rc = ERROR_SUCCESS;
865 if (rc != ERROR_SUCCESS)
867 ERR("Execution halted due to error (%i)\n",rc);
868 msiobj_release(&row->hdr);
869 break;
872 msiobj_release(&row->hdr);
875 MSI_ViewClose(view);
876 msiobj_release(&view->hdr);
879 end:
880 return rc;
883 /********************************************************
884 * ACTION helper functions and functions that perform the actions
885 *******************************************************/
888 * Alot of actions are really important even if they don't do anything
889 * explicit.. Lots of properties are set at the beginning of the installation
890 * CostFinalize does a bunch of work to translated the directories and such
892 * But until I get write access to the database that is hard, so I am going to
893 * hack it to see if I can get something to run.
895 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action)
897 UINT rc = ERROR_SUCCESS;
899 TRACE("Performing action (%s)\n",debugstr_w(action));
900 ui_actioninfo(package, action, TRUE, 0);
901 ui_actionstart(package, action);
902 ui_progress(package,2,1,0,0);
904 /* pre install, setup and configuration block */
905 if (strcmpW(action,szLaunchConditions)==0)
906 rc = ACTION_LaunchConditions(package);
907 else if (strcmpW(action,szCostInitialize)==0)
908 rc = ACTION_CostInitialize(package);
909 else if (strcmpW(action,szFileCost)==0)
910 rc = ACTION_FileCost(package);
911 else if (strcmpW(action,szCostFinalize)==0)
912 rc = ACTION_CostFinalize(package);
913 else if (strcmpW(action,szInstallValidate)==0)
914 rc = ACTION_InstallValidate(package);
916 /* install block */
917 else if (strcmpW(action,szProcessComponents)==0)
918 rc = ACTION_ProcessComponents(package);
919 else if (strcmpW(action,szInstallInitialize)==0)
920 rc = ACTION_InstallInitialize(package);
921 else if (strcmpW(action,szCreateFolders)==0)
922 rc = ACTION_CreateFolders(package);
923 else if (strcmpW(action,szInstallFiles)==0)
924 rc = ACTION_InstallFiles(package);
925 else if (strcmpW(action,szDuplicateFiles)==0)
926 rc = ACTION_DuplicateFiles(package);
927 else if (strcmpW(action,szWriteRegistryValues)==0)
928 rc = ACTION_WriteRegistryValues(package);
929 else if (strcmpW(action,szRegisterTypeLibraries)==0)
930 rc = ACTION_RegisterTypeLibraries(package);
931 else if (strcmpW(action,szRegisterClassInfo)==0)
932 rc = ACTION_RegisterClassInfo(package);
933 else if (strcmpW(action,szRegisterProgIdInfo)==0)
934 rc = ACTION_RegisterProgIdInfo(package);
935 else if (strcmpW(action,szCreateShortcuts)==0)
936 rc = ACTION_CreateShortcuts(package);
937 else if (strcmpW(action,szPublishProduct)==0)
938 rc = ACTION_PublishProduct(package);
941 Called during iTunes but unimplemented and seem important
943 ResolveSource (sets SourceDir)
944 RegisterProduct
945 InstallFinalize
947 else if ((rc = ACTION_CustomAction(package,action)) != ERROR_SUCCESS)
949 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
950 rc = ERROR_FUNCTION_NOT_CALLED;
953 ui_actioninfo(package, action, FALSE, rc);
954 return rc;
958 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action)
960 UINT rc = ERROR_SUCCESS;
961 MSIQUERY * view;
962 MSIRECORD * row = 0;
963 WCHAR ExecSeqQuery[1024] =
964 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','C','u','s','t','o'
965 ,'m','A','c','t','i','o','n',' ','w','h','e','r','e',' ','`','A','c','t','i'
966 ,'o','n','`',' ','=',' ','`',0};
967 static const WCHAR end[]={'`',0};
968 UINT type;
969 LPWSTR source;
970 LPWSTR target;
971 WCHAR *deformated=NULL;
973 strcatW(ExecSeqQuery,action);
974 strcatW(ExecSeqQuery,end);
976 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
978 if (rc != ERROR_SUCCESS)
979 return rc;
981 rc = MSI_ViewExecute(view, 0);
982 if (rc != ERROR_SUCCESS)
984 MSI_ViewClose(view);
985 msiobj_release(&view->hdr);
986 return rc;
989 rc = MSI_ViewFetch(view,&row);
990 if (rc != ERROR_SUCCESS)
992 MSI_ViewClose(view);
993 msiobj_release(&view->hdr);
994 return rc;
997 type = MSI_RecordGetInteger(row,2);
999 source = load_dynamic_stringW(row,3);
1000 target = load_dynamic_stringW(row,4);
1002 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
1003 debugstr_w(source), debugstr_w(target));
1005 /* we are ignoring ALOT of flags and important synchronization stuff */
1006 switch (type & CUSTOM_ACTION_TYPE_MASK)
1008 case 1: /* DLL file stored in a Binary table stream */
1009 rc = HANDLE_CustomType1(package,source,target,type);
1010 break;
1011 case 2: /* EXE file stored in a Binary table strem */
1012 rc = HANDLE_CustomType2(package,source,target,type);
1013 break;
1014 case 18: /*EXE file installed with package */
1015 rc = HANDLE_CustomType18(package,source,target,type);
1016 break;
1017 case 50: /*EXE file specified by a property value */
1018 rc = HANDLE_CustomType50(package,source,target,type);
1019 break;
1020 case 34: /*EXE to be run in specified directory */
1021 rc = HANDLE_CustomType34(package,source,target,type);
1022 break;
1023 case 35: /* Directory set with formatted text. */
1024 case 51: /* Property set with formatted text. */
1025 deformat_string(package,target,&deformated);
1026 rc = MSI_SetPropertyW(package,source,deformated);
1027 HeapFree(GetProcessHeap(),0,deformated);
1028 break;
1029 default:
1030 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
1031 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
1032 debugstr_w(target));
1035 HeapFree(GetProcessHeap(),0,source);
1036 HeapFree(GetProcessHeap(),0,target);
1037 msiobj_release(&row->hdr);
1038 MSI_ViewClose(view);
1039 msiobj_release(&view->hdr);
1040 return rc;
1043 static UINT store_binary_to_temp(MSIPACKAGE *package, const LPWSTR source,
1044 LPWSTR tmp_file)
1046 DWORD sz=MAX_PATH;
1048 if (MSI_GetPropertyW(package, cszTempFolder, tmp_file, &sz)
1049 != ERROR_SUCCESS)
1050 GetTempPathW(MAX_PATH,tmp_file);
1052 strcatW(tmp_file,source);
1054 if (GetFileAttributesW(tmp_file) != INVALID_FILE_ATTRIBUTES)
1056 TRACE("File already exists\n");
1057 return ERROR_SUCCESS;
1059 else
1061 /* write out the file */
1062 UINT rc;
1063 MSIQUERY * view;
1064 MSIRECORD * row = 0;
1065 WCHAR Query[1024] =
1066 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','B','i'
1067 ,'n','a','r','y',' ','w','h','e','r','e',' ','N','a','m','e','=','`',0};
1068 static const WCHAR end[]={'`',0};
1069 HANDLE the_file;
1070 CHAR buffer[1024];
1072 if (track_tempfile(package, source, tmp_file)!=0)
1073 FIXME("File Name in temp tracking collision\n");
1075 the_file = CreateFileW(tmp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1076 FILE_ATTRIBUTE_NORMAL, NULL);
1078 if (the_file == INVALID_HANDLE_VALUE)
1079 return ERROR_FUNCTION_FAILED;
1081 strcatW(Query,source);
1082 strcatW(Query,end);
1084 rc = MSI_DatabaseOpenViewW( package->db, Query, &view);
1085 if (rc != ERROR_SUCCESS)
1086 return rc;
1088 rc = MSI_ViewExecute(view, 0);
1089 if (rc != ERROR_SUCCESS)
1091 MSI_ViewClose(view);
1092 msiobj_release(&view->hdr);
1093 return rc;
1096 rc = MSI_ViewFetch(view,&row);
1097 if (rc != ERROR_SUCCESS)
1099 MSI_ViewClose(view);
1100 msiobj_release(&view->hdr);
1101 return rc;
1106 DWORD write;
1107 sz = 1024;
1108 rc = MSI_RecordReadStream(row,2,buffer,&sz);
1109 if (rc != ERROR_SUCCESS)
1111 ERR("Failed to get stream\n");
1112 CloseHandle(the_file);
1113 DeleteFileW(tmp_file);
1114 break;
1116 WriteFile(the_file,buffer,sz,&write,NULL);
1117 } while (sz == 1024);
1119 CloseHandle(the_file);
1121 msiobj_release(&row->hdr);
1122 MSI_ViewClose(view);
1123 msiobj_release(&view->hdr);
1126 return ERROR_SUCCESS;
1130 typedef UINT __stdcall CustomEntry(MSIHANDLE);
1131 typedef struct
1133 MSIPACKAGE *package;
1134 WCHAR target[MAX_PATH];
1135 WCHAR source[MAX_PATH];
1136 } thread_struct;
1138 #if 0
1139 static DWORD WINAPI DllThread(LPVOID info)
1141 HANDLE DLL;
1142 LPSTR proc;
1143 thread_struct *stuff;
1144 CustomEntry *fn;
1146 stuff = (thread_struct*)info;
1148 TRACE("Asynchronous start (%s, %s) \n", debugstr_w(stuff->source),
1149 debugstr_w(stuff->target));
1151 DLL = LoadLibraryW(stuff->source);
1152 if (DLL)
1154 proc = strdupWtoA( stuff->target );
1155 fn = (CustomEntry*)GetProcAddress(DLL,proc);
1156 if (fn)
1158 MSIHANDLE hPackage;
1159 MSIPACKAGE *package = stuff->package;
1161 TRACE("Calling function\n");
1162 hPackage = msiobj_findhandle( &package->hdr );
1163 if( !hPackage )
1164 ERR("Handle for object %p not found\n", package );
1165 fn(hPackage);
1166 msiobj_release( &package->hdr );
1168 else
1169 ERR("Cannot load functon\n");
1171 HeapFree(GetProcessHeap(),0,proc);
1172 FreeLibrary(DLL);
1174 else
1175 ERR("Unable to load library\n");
1176 msiobj_release( &stuff->package->hdr );
1177 HeapFree( GetProcessHeap(), 0, info );
1178 return 0;
1180 #endif
1182 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
1183 const LPWSTR target, const INT type)
1185 WCHAR tmp_file[MAX_PATH];
1186 CustomEntry *fn;
1187 HANDLE DLL;
1188 LPSTR proc;
1190 store_binary_to_temp(package, source, tmp_file);
1192 TRACE("Calling function %s from %s\n",debugstr_w(target),
1193 debugstr_w(tmp_file));
1195 if (!strchrW(tmp_file,'.'))
1197 static const WCHAR dot[]={'.',0};
1198 strcatW(tmp_file,dot);
1201 if (type & 0xc0)
1203 /* DWORD ThreadId; */
1204 thread_struct *info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) );
1206 /* msiobj_addref( &package->hdr ); */
1207 info->package = package;
1208 strcpyW(info->target,target);
1209 strcpyW(info->source,tmp_file);
1210 TRACE("Start Asynchronous execution\n");
1211 FIXME("DATABASE NOT THREADSAFE... not starting\n");
1212 /* CreateThread(NULL,0,DllThread,(LPVOID)&info,0,&ThreadId); */
1213 /* FIXME: release the package if the CreateThread fails */
1214 HeapFree( GetProcessHeap(), 0, info );
1215 return ERROR_SUCCESS;
1218 DLL = LoadLibraryW(tmp_file);
1219 if (DLL)
1221 proc = strdupWtoA( target );
1222 fn = (CustomEntry*)GetProcAddress(DLL,proc);
1223 if (fn)
1225 MSIHANDLE hPackage;
1227 TRACE("Calling function\n");
1228 hPackage = msiobj_findhandle( &package->hdr );
1229 if( !hPackage )
1230 ERR("Handle for object %p not found\n", package );
1231 fn(hPackage);
1232 msiobj_release( &package->hdr );
1234 else
1235 ERR("Cannot load functon\n");
1237 HeapFree(GetProcessHeap(),0,proc);
1238 FreeLibrary(DLL);
1240 else
1241 ERR("Unable to load library\n");
1243 return ERROR_SUCCESS;
1246 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
1247 const LPWSTR target, const INT type)
1249 WCHAR tmp_file[MAX_PATH*2];
1250 STARTUPINFOW si;
1251 PROCESS_INFORMATION info;
1252 BOOL rc;
1253 WCHAR *deformated;
1254 static const WCHAR spc[] = {' ',0};
1256 memset(&si,0,sizeof(STARTUPINFOW));
1258 store_binary_to_temp(package, source, tmp_file);
1260 strcatW(tmp_file,spc);
1261 deformat_string(package,target,&deformated);
1262 strcatW(tmp_file,deformated);
1264 HeapFree(GetProcessHeap(),0,deformated);
1266 TRACE("executing exe %s \n",debugstr_w(tmp_file));
1268 rc = CreateProcessW(NULL, tmp_file, NULL, NULL, FALSE, 0, NULL,
1269 c_collen, &si, &info);
1271 if ( !rc )
1273 ERR("Unable to execute command\n");
1274 return ERROR_SUCCESS;
1277 if (!(type & 0xc0))
1278 WaitForSingleObject(info.hProcess,INFINITE);
1280 CloseHandle( info.hProcess );
1281 CloseHandle( info.hThread );
1282 return ERROR_SUCCESS;
1285 static UINT HANDLE_CustomType18(MSIPACKAGE *package, const LPWSTR source,
1286 const LPWSTR target, const INT type)
1288 WCHAR filename[MAX_PATH*2];
1289 STARTUPINFOW si;
1290 PROCESS_INFORMATION info;
1291 BOOL rc;
1292 WCHAR *deformated;
1293 static const WCHAR spc[] = {' ',0};
1294 int index;
1296 memset(&si,0,sizeof(STARTUPINFOW));
1298 index = get_loaded_file(package,source);
1299 strcpyW(filename,package->files[index].TargetPath);
1301 strcatW(filename,spc);
1302 deformat_string(package,target,&deformated);
1303 strcatW(filename,deformated);
1305 HeapFree(GetProcessHeap(),0,deformated);
1307 TRACE("executing exe %s \n",debugstr_w(filename));
1309 rc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
1310 c_collen, &si, &info);
1312 if ( !rc )
1314 ERR("Unable to execute command\n");
1315 return ERROR_SUCCESS;
1318 if (!(type & 0xc0))
1319 WaitForSingleObject(info.hProcess,INFINITE);
1321 CloseHandle( info.hProcess );
1322 CloseHandle( info.hThread );
1323 return ERROR_SUCCESS;
1326 static UINT HANDLE_CustomType50(MSIPACKAGE *package, const LPWSTR source,
1327 const LPWSTR target, const INT type)
1329 WCHAR filename[MAX_PATH*2];
1330 STARTUPINFOW si;
1331 PROCESS_INFORMATION info;
1332 BOOL rc;
1333 WCHAR *deformated;
1334 static const WCHAR spc[] = {' ',0};
1335 DWORD sz;
1337 memset(&si,0,sizeof(STARTUPINFOW));
1339 sz = MAX_PATH*2;
1340 if (MSI_GetPropertyW(package,source,filename,&sz) != ERROR_SUCCESS)
1341 return ERROR_FUNCTION_FAILED;
1343 strcatW(filename,spc);
1344 deformat_string(package,target,&deformated);
1345 strcatW(filename,deformated);
1347 HeapFree(GetProcessHeap(),0,deformated);
1349 TRACE("executing exe %s \n",debugstr_w(filename));
1351 rc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
1352 c_collen, &si, &info);
1354 if ( !rc )
1356 ERR("Unable to execute command\n");
1357 return ERROR_SUCCESS;
1360 if (!(type & 0xc0))
1361 WaitForSingleObject(info.hProcess,INFINITE);
1363 CloseHandle( info.hProcess );
1364 CloseHandle( info.hThread );
1365 return ERROR_SUCCESS;
1368 static UINT HANDLE_CustomType34(MSIPACKAGE *package, const LPWSTR source,
1369 const LPWSTR target, const INT type)
1371 WCHAR filename[MAX_PATH*2];
1372 STARTUPINFOW si;
1373 PROCESS_INFORMATION info;
1374 BOOL rc;
1375 WCHAR *deformated;
1377 memset(&si,0,sizeof(STARTUPINFOW));
1379 rc = resolve_folder(package, source, filename, FALSE, FALSE, NULL);
1380 if (rc != ERROR_SUCCESS)
1381 return rc;
1383 SetCurrentDirectoryW(filename);
1385 deformat_string(package,target,&deformated);
1386 strcpyW(filename,deformated);
1388 HeapFree(GetProcessHeap(),0,deformated);
1390 TRACE("executing exe %s \n",debugstr_w(filename));
1392 rc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
1393 c_collen, &si, &info);
1395 if ( !rc )
1397 ERR("Unable to execute command\n");
1398 return ERROR_SUCCESS;
1401 if (!(type & 0xc0))
1402 WaitForSingleObject(info.hProcess,INFINITE);
1404 CloseHandle( info.hProcess );
1405 CloseHandle( info.hThread );
1406 return ERROR_SUCCESS;
1409 /***********************************************************************
1410 * create_full_pathW
1412 * Recursively create all directories in the path.
1414 * shamelessly stolen from setupapi/queue.c
1416 static BOOL create_full_pathW(const WCHAR *path)
1418 BOOL ret = TRUE;
1419 int len;
1420 WCHAR *new_path;
1422 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1423 sizeof(WCHAR));
1424 strcpyW(new_path, path);
1426 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1427 new_path[len - 1] = 0;
1429 while(!CreateDirectoryW(new_path, NULL))
1431 WCHAR *slash;
1432 DWORD last_error = GetLastError();
1433 if(last_error == ERROR_ALREADY_EXISTS)
1434 break;
1436 if(last_error != ERROR_PATH_NOT_FOUND)
1438 ret = FALSE;
1439 break;
1442 if(!(slash = strrchrW(new_path, '\\')))
1444 ret = FALSE;
1445 break;
1448 len = slash - new_path;
1449 new_path[len] = 0;
1450 if(!create_full_pathW(new_path))
1452 ret = FALSE;
1453 break;
1455 new_path[len] = '\\';
1458 HeapFree(GetProcessHeap(), 0, new_path);
1459 return ret;
1463 * Also we cannot enable/disable components either, so for now I am just going
1464 * to do all the directories for all the components.
1466 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1468 static const WCHAR ExecSeqQuery[] = {
1469 's','e','l','e','c','t',' ','D','i','r','e','c','t','o','r','y','_',' ',
1470 'f','r','o','m',' ','C','r','e','a','t','e','F','o','l','d','e','r',0 };
1471 UINT rc;
1472 MSIQUERY *view;
1473 MSIFOLDER *folder;
1475 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1476 if (rc != ERROR_SUCCESS)
1477 return ERROR_SUCCESS;
1479 rc = MSI_ViewExecute(view, 0);
1480 if (rc != ERROR_SUCCESS)
1482 MSI_ViewClose(view);
1483 msiobj_release(&view->hdr);
1484 return rc;
1487 while (1)
1489 WCHAR dir[0x100];
1490 WCHAR full_path[MAX_PATH];
1491 DWORD sz;
1492 MSIRECORD *row = NULL, *uirow;
1494 rc = MSI_ViewFetch(view,&row);
1495 if (rc != ERROR_SUCCESS)
1497 rc = ERROR_SUCCESS;
1498 break;
1501 sz=0x100;
1502 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1504 if (rc!= ERROR_SUCCESS)
1506 ERR("Unable to get folder id \n");
1507 msiobj_release(&row->hdr);
1508 continue;
1511 sz = MAX_PATH;
1512 rc = resolve_folder(package,dir,full_path,FALSE,FALSE,&folder);
1514 if (rc != ERROR_SUCCESS)
1516 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1517 msiobj_release(&row->hdr);
1518 continue;
1521 TRACE("Folder is %s\n",debugstr_w(full_path));
1523 /* UI stuff */
1524 uirow = MSI_CreateRecord(1);
1525 MSI_RecordSetStringW(uirow,1,full_path);
1526 ui_actiondata(package,szCreateFolders,uirow);
1527 msiobj_release( &uirow->hdr );
1529 if (folder->State == 0)
1530 create_full_pathW(full_path);
1532 folder->State = 3;
1534 msiobj_release(&row->hdr);
1536 MSI_ViewClose(view);
1537 msiobj_release(&view->hdr);
1539 return rc;
1542 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1544 int index = package->loaded_components;
1545 DWORD sz;
1547 /* fill in the data */
1549 package->loaded_components++;
1550 if (package->loaded_components == 1)
1551 package->components = HeapAlloc(GetProcessHeap(),0,
1552 sizeof(MSICOMPONENT));
1553 else
1554 package->components = HeapReAlloc(GetProcessHeap(),0,
1555 package->components, package->loaded_components *
1556 sizeof(MSICOMPONENT));
1558 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1560 sz = 96;
1561 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1563 TRACE("Loading Component %s\n",
1564 debugstr_w(package->components[index].Component));
1566 sz = 0x100;
1567 if (!MSI_RecordIsNull(row,2))
1568 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1570 sz = 96;
1571 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1573 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1575 sz = 0x100;
1576 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1578 sz = 96;
1579 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1581 package->components[index].State = INSTALLSTATE_UNKNOWN;
1582 package->components[index].Enabled = TRUE;
1583 package->components[index].FeatureState= FALSE;
1585 return index;
1588 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1590 int index = package->loaded_features;
1591 DWORD sz;
1592 static const WCHAR Query1[] = {'S','E','L','E','C','T',' ','C','o','m','p',
1593 'o','n','e','n','t','_',' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1594 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ','F','e',
1595 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1596 static const WCHAR Query2[] = {'S','E','L','E','C','T',' ','*',' ','F','R',
1597 'O','M',' ','C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ','C',
1598 'o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1599 WCHAR Query[1024];
1600 MSIQUERY * view;
1601 MSIQUERY * view2;
1602 MSIRECORD * row2;
1603 MSIRECORD * row3;
1604 UINT rc;
1606 /* fill in the data */
1608 package->loaded_features ++;
1609 if (package->loaded_features == 1)
1610 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1611 else
1612 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1613 package->loaded_features * sizeof(MSIFEATURE));
1615 memset(&package->features[index],0,sizeof(MSIFEATURE));
1617 sz = 96;
1618 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1620 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1622 sz = 96;
1623 if (!MSI_RecordIsNull(row,2))
1624 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1626 sz = 0x100;
1627 if (!MSI_RecordIsNull(row,3))
1628 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1630 sz = 0x100;
1631 if (!MSI_RecordIsNull(row,4))
1632 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1634 if (!MSI_RecordIsNull(row,5))
1635 package->features[index].Display = MSI_RecordGetInteger(row,5);
1637 package->features[index].Level= MSI_RecordGetInteger(row,6);
1639 sz = 96;
1640 if (!MSI_RecordIsNull(row,7))
1641 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1643 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1644 package->features[index].State = INSTALLSTATE_UNKNOWN;
1646 /* load feature components */
1648 sprintfW(Query,Query1,package->features[index].Feature);
1649 rc = MSI_DatabaseOpenViewW(package->db,Query,&view);
1650 if (rc != ERROR_SUCCESS)
1651 return;
1652 rc = MSI_ViewExecute(view,0);
1653 if (rc != ERROR_SUCCESS)
1655 MSI_ViewClose(view);
1656 msiobj_release(&view->hdr);
1657 return;
1659 while (1)
1661 DWORD sz = 0x100;
1662 WCHAR buffer[0x100];
1663 DWORD rc;
1664 INT c_indx;
1665 INT cnt = package->features[index].ComponentCount;
1667 rc = MSI_ViewFetch(view,&row2);
1668 if (rc != ERROR_SUCCESS)
1669 break;
1671 sz = 0x100;
1672 MSI_RecordGetStringW(row2,1,buffer,&sz);
1674 /* check to see if the component is already loaded */
1675 c_indx = get_loaded_component(package,buffer);
1676 if (c_indx != -1)
1678 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
1679 c_indx);
1680 package->features[index].Components[cnt] = c_indx;
1681 package->features[index].ComponentCount ++;
1684 sprintfW(Query,Query2,buffer);
1686 rc = MSI_DatabaseOpenViewW(package->db,Query,&view2);
1687 if (rc != ERROR_SUCCESS)
1689 msiobj_release( &row2->hdr );
1690 continue;
1692 rc = MSI_ViewExecute(view2,0);
1693 if (rc != ERROR_SUCCESS)
1695 msiobj_release( &row2->hdr );
1696 MSI_ViewClose(view2);
1697 msiobj_release( &view2->hdr );
1698 continue;
1700 while (1)
1702 DWORD rc;
1704 rc = MSI_ViewFetch(view2,&row3);
1705 if (rc != ERROR_SUCCESS)
1706 break;
1707 c_indx = load_component(package,row3);
1708 msiobj_release( &row3->hdr );
1710 package->features[index].Components[cnt] = c_indx;
1711 package->features[index].ComponentCount ++;
1713 MSI_ViewClose(view2);
1714 msiobj_release( &view2->hdr );
1715 msiobj_release( &row2->hdr );
1717 MSI_ViewClose(view);
1718 msiobj_release(&view->hdr);
1722 * I am not doing any of the costing functionality yet.
1723 * Mostly looking at doing the Component and Feature loading
1725 * The native MSI does ALOT of modification to tables here. Mostly adding alot
1726 * of temporary columns to the Feature and Component tables.
1728 * note: native msi also tracks the short filename. but I am only going to
1729 * track the long ones. Also looking at this directory table
1730 * it appears that the directory table does not get the parents
1731 * resolved base on property only based on their entrys in the
1732 * directory table.
1734 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
1736 MSIQUERY * view;
1737 MSIRECORD * row;
1738 DWORD sz;
1739 UINT rc;
1740 static const WCHAR Query_all[] = {
1741 'S','E','L','E','C','T',' ','*',' ',
1742 'F','R','O','M',' ','F','e','a','t','u','r','e',0};
1743 static const WCHAR szCosting[] = {
1744 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
1745 static const WCHAR szZero[] = { '0', 0 };
1747 MSI_SetPropertyW(package, szCosting, szZero);
1748 MSI_SetPropertyW(package, cszRootDrive , c_collen);
1750 sz = 0x100;
1751 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
1752 if (rc != ERROR_SUCCESS)
1753 return rc;
1754 rc = MSI_ViewExecute(view,0);
1755 if (rc != ERROR_SUCCESS)
1757 MSI_ViewClose(view);
1758 msiobj_release(&view->hdr);
1759 return rc;
1761 while (1)
1763 DWORD rc;
1765 rc = MSI_ViewFetch(view,&row);
1766 if (rc != ERROR_SUCCESS)
1767 break;
1769 load_feature(package,row);
1770 msiobj_release(&row->hdr);
1772 MSI_ViewClose(view);
1773 msiobj_release(&view->hdr);
1775 return ERROR_SUCCESS;
1778 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
1780 DWORD index = package->loaded_files;
1781 DWORD i;
1782 WCHAR buffer[0x100];
1783 DWORD sz;
1785 /* fill in the data */
1787 package->loaded_files++;
1788 if (package->loaded_files== 1)
1789 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
1790 else
1791 package->files = HeapReAlloc(GetProcessHeap(),0,
1792 package->files , package->loaded_files * sizeof(MSIFILE));
1794 memset(&package->files[index],0,sizeof(MSIFILE));
1796 sz = 72;
1797 MSI_RecordGetStringW(row,1,package->files[index].File,&sz);
1799 sz = 0x100;
1800 MSI_RecordGetStringW(row,2,buffer,&sz);
1802 package->files[index].ComponentIndex = -1;
1803 for (i = 0; i < package->loaded_components; i++)
1804 if (strcmpW(package->components[i].Component,buffer)==0)
1806 package->files[index].ComponentIndex = i;
1807 break;
1809 if (package->files[index].ComponentIndex == -1)
1810 ERR("Unfound Component %s\n",debugstr_w(buffer));
1812 sz = MAX_PATH;
1813 MSI_RecordGetStringW(row,3,package->files[index].FileName,&sz);
1815 reduce_to_longfilename(package->files[index].FileName);
1817 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
1819 sz = 72;
1820 if (!MSI_RecordIsNull(row,5))
1821 MSI_RecordGetStringW(row,5,package->files[index].Version,&sz);
1823 sz = 20;
1824 if (!MSI_RecordIsNull(row,6))
1825 MSI_RecordGetStringW(row,6,package->files[index].Language,&sz);
1827 if (!MSI_RecordIsNull(row,7))
1828 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
1830 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
1832 package->files[index].Temporary = FALSE;
1833 package->files[index].State = 0;
1835 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
1837 return ERROR_SUCCESS;
1840 static UINT ACTION_FileCost(MSIPACKAGE *package)
1842 MSIQUERY * view;
1843 MSIRECORD * row;
1844 UINT rc;
1845 static const WCHAR Query[] = {
1846 'S','E','L','E','C','T',' ','*',' ',
1847 'F','R','O','M',' ','F','i','l','e',' ',
1848 'O','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e', 0};
1850 if (!package)
1851 return ERROR_INVALID_HANDLE;
1853 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1854 if (rc != ERROR_SUCCESS)
1855 return ERROR_SUCCESS;
1857 rc = MSI_ViewExecute(view, 0);
1858 if (rc != ERROR_SUCCESS)
1860 MSI_ViewClose(view);
1861 msiobj_release(&view->hdr);
1862 return ERROR_SUCCESS;
1865 while (1)
1867 rc = MSI_ViewFetch(view,&row);
1868 if (rc != ERROR_SUCCESS)
1870 rc = ERROR_SUCCESS;
1871 break;
1873 load_file(package,row);
1874 msiobj_release(&row->hdr);
1876 MSI_ViewClose(view);
1877 msiobj_release(&view->hdr);
1879 return ERROR_SUCCESS;
1882 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
1885 WCHAR Query[1024] =
1886 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','D','i','r','e','c',
1887 't','o','r','y',' ','w','h','e','r','e',' ','`','D','i','r','e','c','t',
1888 'o','r','y','`',' ','=',' ','`',0};
1889 static const WCHAR end[]={'`',0};
1890 UINT rc;
1891 MSIQUERY * view;
1892 WCHAR targetbuffer[0x100];
1893 WCHAR *srcdir = NULL;
1894 WCHAR *targetdir = NULL;
1895 WCHAR parent[0x100];
1896 DWORD sz=0x100;
1897 MSIRECORD * row = 0;
1898 INT index = -1;
1899 DWORD i;
1901 TRACE("Looking for dir %s\n",debugstr_w(dir));
1903 for (i = 0; i < package->loaded_folders; i++)
1905 if (strcmpW(package->folders[i].Directory,dir)==0)
1907 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
1908 return i;
1912 TRACE("Working to load %s\n",debugstr_w(dir));
1914 index = package->loaded_folders;
1916 package->loaded_folders++;
1917 if (package->loaded_folders== 1)
1918 package->folders = HeapAlloc(GetProcessHeap(),0,
1919 sizeof(MSIFOLDER));
1920 else
1921 package->folders= HeapReAlloc(GetProcessHeap(),0,
1922 package->folders, package->loaded_folders*
1923 sizeof(MSIFOLDER));
1925 memset(&package->folders[index],0,sizeof(MSIFOLDER));
1927 strcpyW(package->folders[index].Directory,dir);
1929 strcatW(Query,dir);
1930 strcatW(Query,end);
1932 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1934 if (rc != ERROR_SUCCESS)
1935 return -1;
1937 rc = MSI_ViewExecute(view, 0);
1938 if (rc != ERROR_SUCCESS)
1940 MSI_ViewClose(view);
1941 msiobj_release(&view->hdr);
1942 return -1;
1945 rc = MSI_ViewFetch(view,&row);
1946 if (rc != ERROR_SUCCESS)
1948 MSI_ViewClose(view);
1949 msiobj_release(&view->hdr);
1950 return -1;
1953 sz=0x100;
1954 MSI_RecordGetStringW(row,3,targetbuffer,&sz);
1955 targetdir=targetbuffer;
1957 /* split src and target dir */
1958 if (strchrW(targetdir,':'))
1960 srcdir=strchrW(targetdir,':');
1961 *srcdir=0;
1962 srcdir ++;
1964 else
1965 srcdir=NULL;
1967 /* for now only pick long filename versions */
1968 if (strchrW(targetdir,'|'))
1970 targetdir = strchrW(targetdir,'|');
1971 *targetdir = 0;
1972 targetdir ++;
1974 if (srcdir && strchrW(srcdir,'|'))
1976 srcdir= strchrW(srcdir,'|');
1977 *srcdir= 0;
1978 srcdir ++;
1981 /* now check for root dirs */
1982 if (targetdir[0] == '.' && targetdir[1] == 0)
1983 targetdir = NULL;
1985 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
1986 srcdir = NULL;
1988 if (targetdir)
1989 strcpyW(package->folders[index].TargetDefault,targetdir);
1991 if (srcdir)
1992 strcpyW(package->folders[index].SourceDefault,srcdir);
1993 else if (targetdir)
1994 strcpyW(package->folders[index].SourceDefault,targetdir);
1996 if (MSI_RecordIsNull(row,2))
1997 parent[0]=0;
1998 else
2000 sz=0x100;
2001 MSI_RecordGetStringW(row,2,parent,&sz);
2004 if (parent[0])
2006 i = load_folder(package,parent);
2007 package->folders[index].ParentIndex = i;
2008 TRACE("Parent is index %i... %s %s\n",
2009 package->folders[index].ParentIndex,
2010 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
2011 debugstr_w(parent));
2013 else
2014 package->folders[index].ParentIndex = -2;
2016 sz = MAX_PATH;
2017 rc = MSI_GetPropertyW(package, dir, package->folders[index].Property, &sz);
2018 if (rc != ERROR_SUCCESS)
2019 package->folders[index].Property[0]=0;
2021 msiobj_release(&row->hdr);
2022 MSI_ViewClose(view);
2023 msiobj_release(&view->hdr);
2024 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
2025 return index;
2028 static UINT resolve_folder(MSIPACKAGE *package, LPCWSTR name, LPWSTR path,
2029 BOOL source, BOOL set_prop, MSIFOLDER **folder)
2031 DWORD i;
2032 UINT rc = ERROR_SUCCESS;
2033 DWORD sz;
2035 TRACE("Working to resolve %s\n",debugstr_w(name));
2037 if (!path)
2038 return rc;
2040 /* special resolving for Target and Source root dir */
2041 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
2043 if (!source)
2045 sz = MAX_PATH;
2046 rc = MSI_GetPropertyW(package,cszTargetDir,path,&sz);
2047 if (rc != ERROR_SUCCESS)
2049 sz = MAX_PATH;
2050 rc = MSI_GetPropertyW(package,cszRootDrive,path,&sz);
2051 if (set_prop)
2052 MSI_SetPropertyW(package,cszTargetDir,path);
2054 if (folder)
2055 *folder = &(package->folders[0]);
2056 return rc;
2058 else
2060 sz = MAX_PATH;
2061 rc = MSI_GetPropertyW(package,cszSourceDir,path,&sz);
2062 if (rc != ERROR_SUCCESS)
2064 sz = MAX_PATH;
2065 rc = MSI_GetPropertyW(package,cszDatabase,path,&sz);
2066 if (rc == ERROR_SUCCESS)
2068 LPWSTR ptr = strrchrW(path,'\\');
2069 if (ptr)
2071 ptr++;
2072 *ptr = 0;
2076 if (folder)
2077 *folder = &(package->folders[0]);
2078 return rc;
2082 for (i = 0; i < package->loaded_folders; i++)
2084 if (strcmpW(package->folders[i].Directory,name)==0)
2085 break;
2088 if (i >= package->loaded_folders)
2089 return ERROR_FUNCTION_FAILED;
2091 if (folder)
2092 *folder = &(package->folders[i]);
2094 if (!source && package->folders[i].ResolvedTarget[0])
2096 strcpyW(path,package->folders[i].ResolvedTarget);
2097 TRACE(" already resolved to %s\n",debugstr_w(path));
2098 return ERROR_SUCCESS;
2100 else if (source && package->folders[i].ResolvedSource[0])
2102 strcpyW(path,package->folders[i].ResolvedSource);
2103 return ERROR_SUCCESS;
2105 else if (!source && package->folders[i].Property[0])
2107 strcpyW(path,package->folders[i].Property);
2108 TRACE(" internally set to %s\n",debugstr_w(path));
2109 if (set_prop)
2110 MSI_SetPropertyW(package,name,path);
2111 return ERROR_SUCCESS;
2114 if (package->folders[i].ParentIndex >= 0)
2116 int len;
2117 TRACE(" ! Parent is %s\n", debugstr_w(package->folders[
2118 package->folders[i].ParentIndex].Directory));
2119 resolve_folder(package, package->folders[
2120 package->folders[i].ParentIndex].Directory, path,source,
2121 set_prop, NULL);
2123 len = strlenW(path);
2124 if (len && path[len-1] != '\\')
2125 strcatW(path, cszbs);
2127 if (!source)
2129 if (package->folders[i].TargetDefault[0])
2131 strcatW(path,package->folders[i].TargetDefault);
2132 strcatW(path,cszbs);
2134 strcpyW(package->folders[i].ResolvedTarget,path);
2135 TRACE(" resolved into %s\n",debugstr_w(path));
2136 if (set_prop)
2137 MSI_SetPropertyW(package,name,path);
2139 else
2141 if (package->folders[i].SourceDefault[0])
2143 strcatW(path,package->folders[i].SourceDefault);
2144 strcatW(path,cszbs);
2146 strcpyW(package->folders[i].ResolvedSource,path);
2149 return rc;
2153 * Alot is done in this function aside from just the costing.
2154 * The costing needs to be implemented at some point but for now I am going
2155 * to focus on the directory building
2158 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2160 static const WCHAR ExecSeqQuery[] = {
2161 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2162 'D','i','r','e','c','t','o','r','y',0};
2163 static const WCHAR ConditionQuery[] = {
2164 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2165 'C','o','n','d','i','t','i','o','n',0};
2166 static const WCHAR szCosting[] = {
2167 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2168 static const WCHAR szOne[] = { '1', 0 };
2169 UINT rc;
2170 MSIQUERY * view;
2171 DWORD i;
2173 TRACE("Building Directory properties\n");
2175 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2176 if (rc == ERROR_SUCCESS)
2178 rc = MSI_ViewExecute(view, 0);
2179 if (rc != ERROR_SUCCESS)
2181 MSI_ViewClose(view);
2182 msiobj_release(&view->hdr);
2183 return rc;
2186 while (1)
2188 WCHAR name[0x100];
2189 WCHAR path[MAX_PATH];
2190 MSIRECORD * row = 0;
2191 DWORD sz;
2193 rc = MSI_ViewFetch(view,&row);
2194 if (rc != ERROR_SUCCESS)
2196 rc = ERROR_SUCCESS;
2197 break;
2200 sz=0x100;
2201 MSI_RecordGetStringW(row,1,name,&sz);
2203 /* This helper function now does ALL the work */
2204 TRACE("Dir %s ...\n",debugstr_w(name));
2205 load_folder(package,name);
2206 resolve_folder(package,name,path,FALSE,TRUE,NULL);
2207 TRACE("resolves to %s\n",debugstr_w(path));
2209 msiobj_release(&row->hdr);
2211 MSI_ViewClose(view);
2212 msiobj_release(&view->hdr);
2215 TRACE("File calculations %i files\n",package->loaded_files);
2217 for (i = 0; i < package->loaded_files; i++)
2219 MSICOMPONENT* comp = NULL;
2220 MSIFILE* file= NULL;
2222 file = &package->files[i];
2223 if (file->ComponentIndex >= 0)
2224 comp = &package->components[file->ComponentIndex];
2226 if (comp)
2228 int len;
2229 /* calculate target */
2230 resolve_folder(package, comp->Directory, file->TargetPath, FALSE,
2231 FALSE, NULL);
2232 /* make sure that the path ends in a \ */
2233 len = strlenW(file->TargetPath);
2234 if (len && file->TargetPath[len-1] != '\\')
2235 strcatW(file->TargetPath, cszbs);
2236 strcatW(file->TargetPath,file->FileName);
2238 TRACE("file %s resolves to %s\n",
2239 debugstr_w(file->File),debugstr_w(file->TargetPath));
2241 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2243 file->State = 1;
2244 comp->Cost += file->FileSize;
2246 else
2248 if (file->Version[0])
2250 DWORD handle;
2251 DWORD versize;
2252 UINT sz;
2253 LPVOID version;
2254 static const WCHAR name[] =
2255 {'\\',0};
2256 static const WCHAR name_fmt[] =
2257 {'%','u','.','%','u','.','%','u','.','%','u',0};
2258 WCHAR filever[0x100];
2259 VS_FIXEDFILEINFO *lpVer;
2261 FIXME("Version comparison.. \n");
2262 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2263 version = HeapAlloc(GetProcessHeap(),0,versize);
2264 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2266 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2268 sprintfW(filever,name_fmt,
2269 HIWORD(lpVer->dwFileVersionMS),
2270 LOWORD(lpVer->dwFileVersionMS),
2271 HIWORD(lpVer->dwFileVersionLS),
2272 LOWORD(lpVer->dwFileVersionLS));
2274 TRACE("new %s old %s\n", debugstr_w(file->Version),
2275 debugstr_w(filever));
2276 if (strcmpiW(filever,file->Version)<0)
2278 file->State = 2;
2279 FIXME("cost should be diff in size\n");
2280 comp->Cost += file->FileSize;
2282 else
2283 file->State = 3;
2284 HeapFree(GetProcessHeap(),0,version);
2286 else
2287 file->State = 3;
2292 TRACE("Evaluating Condition Table\n");
2294 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2295 if (rc == ERROR_SUCCESS)
2297 rc = MSI_ViewExecute(view, 0);
2298 if (rc != ERROR_SUCCESS)
2300 MSI_ViewClose(view);
2301 msiobj_release(&view->hdr);
2302 return rc;
2305 while (1)
2307 WCHAR Feature[0x100];
2308 MSIRECORD * row = 0;
2309 DWORD sz;
2310 int feature_index;
2312 rc = MSI_ViewFetch(view,&row);
2314 if (rc != ERROR_SUCCESS)
2316 rc = ERROR_SUCCESS;
2317 break;
2320 sz = 0x100;
2321 MSI_RecordGetStringW(row,1,Feature,&sz);
2323 feature_index = get_loaded_feature(package,Feature);
2324 if (feature_index < 0)
2325 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2326 else
2328 LPWSTR Condition;
2329 Condition = load_dynamic_stringW(row,3);
2331 if (MSI_EvaluateConditionW(package,Condition) ==
2332 MSICONDITION_TRUE)
2334 int level = MSI_RecordGetInteger(row,2);
2335 TRACE("Reseting feature %s to level %i\n",
2336 debugstr_w(Feature), level);
2337 package->features[feature_index].Level = level;
2339 HeapFree(GetProcessHeap(),0,Condition);
2342 msiobj_release(&row->hdr);
2344 MSI_ViewClose(view);
2345 msiobj_release(&view->hdr);
2348 TRACE("Enabling or Disabling Components\n");
2349 for (i = 0; i < package->loaded_components; i++)
2351 if (package->components[i].Condition[0])
2353 if (MSI_EvaluateConditionW(package,
2354 package->components[i].Condition) == MSICONDITION_FALSE)
2356 TRACE("Disabling component %s\n",
2357 debugstr_w(package->components[i].Component));
2358 package->components[i].Enabled = FALSE;
2363 MSI_SetPropertyW(package,szCosting,szOne);
2364 return ERROR_SUCCESS;
2368 * This is a helper function for handling embedded cabinet media
2370 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2371 WCHAR* source)
2373 UINT rc;
2374 USHORT* data;
2375 UINT size;
2376 DWORD write;
2377 HANDLE the_file;
2378 WCHAR tmp[MAX_PATH];
2380 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2381 if (rc != ERROR_SUCCESS)
2382 return rc;
2384 write = MAX_PATH;
2385 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2386 GetTempPathW(MAX_PATH,tmp);
2388 GetTempFileNameW(tmp,stream_name,0,source);
2390 track_tempfile(package,strrchrW(source,'\\'), source);
2391 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2392 FILE_ATTRIBUTE_NORMAL, NULL);
2394 if (the_file == INVALID_HANDLE_VALUE)
2396 rc = ERROR_FUNCTION_FAILED;
2397 goto end;
2400 WriteFile(the_file,data,size,&write,NULL);
2401 CloseHandle(the_file);
2402 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2403 end:
2404 HeapFree(GetProcessHeap(),0,data);
2405 return rc;
2409 /* Support functions for FDI functions */
2411 static void * cabinet_alloc(ULONG cb)
2413 return HeapAlloc(GetProcessHeap(), 0, cb);
2416 static void cabinet_free(void *pv)
2418 HeapFree(GetProcessHeap(), 0, pv);
2421 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2423 DWORD dwAccess = 0;
2424 DWORD dwShareMode = 0;
2425 DWORD dwCreateDisposition = OPEN_EXISTING;
2426 switch (oflag & _O_ACCMODE)
2428 case _O_RDONLY:
2429 dwAccess = GENERIC_READ;
2430 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2431 break;
2432 case _O_WRONLY:
2433 dwAccess = GENERIC_WRITE;
2434 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2435 break;
2436 case _O_RDWR:
2437 dwAccess = GENERIC_READ | GENERIC_WRITE;
2438 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2439 break;
2441 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2442 dwCreateDisposition = CREATE_NEW;
2443 else if (oflag & _O_CREAT)
2444 dwCreateDisposition = CREATE_ALWAYS;
2445 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL, dwCreateDisposition, 0, NULL);
2448 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2450 DWORD dwRead;
2451 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2452 return dwRead;
2453 return 0;
2456 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2458 DWORD dwWritten;
2459 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2460 return dwWritten;
2461 return 0;
2464 static int cabinet_close(INT_PTR hf)
2466 return CloseHandle((HANDLE)hf) ? 0 : -1;
2469 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2471 /* flags are compatible and so are passed straight through */
2472 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2475 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2477 /* FIXME: try to do more processing in this function */
2478 switch (fdint)
2480 case fdintCOPY_FILE:
2482 ULONG len = strlen((char*)pfdin->pv) + strlen(pfdin->psz1);
2483 char *file = cabinet_alloc((len+1)*sizeof(char));
2485 strcpy(file, (char*)pfdin->pv);
2486 strcat(file, pfdin->psz1);
2488 TRACE("file: %s\n", debugstr_a(file));
2490 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2492 case fdintCLOSE_FILE_INFO:
2494 FILETIME ft;
2495 FILETIME ftLocal;
2496 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2497 return -1;
2498 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2499 return -1;
2500 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2501 return -1;
2503 cabinet_close(pfdin->hf);
2504 return 1;
2506 default:
2507 return 0;
2511 /***********************************************************************
2512 * extract_cabinet_file
2514 * Extract files from a cab file.
2516 static BOOL extract_cabinet_file(const WCHAR* source, const WCHAR* path)
2518 HFDI hfdi;
2519 ERF erf;
2520 BOOL ret;
2521 char *cabinet;
2522 char *cab_path;
2524 TRACE("Extracting %s to %s\n",debugstr_w(source), debugstr_w(path));
2526 hfdi = FDICreate(cabinet_alloc,
2527 cabinet_free,
2528 cabinet_open,
2529 cabinet_read,
2530 cabinet_write,
2531 cabinet_close,
2532 cabinet_seek,
2534 &erf);
2535 if (!hfdi)
2537 ERR("FDICreate failed\n");
2538 return FALSE;
2541 if (!(cabinet = strdupWtoA( source )))
2543 FDIDestroy(hfdi);
2544 return FALSE;
2546 if (!(cab_path = strdupWtoA( path )))
2548 FDIDestroy(hfdi);
2549 HeapFree(GetProcessHeap(), 0, cabinet);
2550 return FALSE;
2553 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, cab_path);
2555 if (!ret)
2556 ERR("FDICopy failed\n");
2558 FDIDestroy(hfdi);
2560 HeapFree(GetProcessHeap(), 0, cabinet);
2561 HeapFree(GetProcessHeap(), 0, cab_path);
2563 return ret;
2566 static UINT ready_media_for_file(MSIPACKAGE *package, UINT sequence,
2567 WCHAR* path)
2569 UINT rc;
2570 MSIQUERY * view;
2571 MSIRECORD * row = 0;
2572 WCHAR source[MAX_PATH];
2573 static const WCHAR ExecSeqQuery[] = {
2574 's','e','l','e','c','t',' ','*',' ',
2575 'f','r','o','m',' ','M','e','d','i','a',' ',
2576 'w','h','e','r','e',' ','L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%','i',' ',
2577 'o','r','d','e','r',' ','b','y',' ','L','a','s','t','S','e','q','u','e','n','c','e',0};
2578 WCHAR Query[1024];
2579 WCHAR cab[0x100];
2580 DWORD sz=0x100;
2581 INT seq;
2582 static UINT last_sequence = 0;
2584 if (sequence <= last_sequence)
2586 TRACE("Media already ready (%u, %u)\n",sequence,last_sequence);
2587 return ERROR_SUCCESS;
2590 sprintfW(Query,ExecSeqQuery,sequence);
2592 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2593 if (rc != ERROR_SUCCESS)
2594 return rc;
2596 rc = MSI_ViewExecute(view, 0);
2597 if (rc != ERROR_SUCCESS)
2599 MSI_ViewClose(view);
2600 msiobj_release(&view->hdr);
2601 return rc;
2604 rc = MSI_ViewFetch(view,&row);
2605 if (rc != ERROR_SUCCESS)
2607 MSI_ViewClose(view);
2608 msiobj_release(&view->hdr);
2609 return rc;
2611 seq = MSI_RecordGetInteger(row,2);
2612 last_sequence = seq;
2614 if (!MSI_RecordIsNull(row,4))
2616 sz=0x100;
2617 MSI_RecordGetStringW(row,4,cab,&sz);
2618 TRACE("Source is CAB %s\n",debugstr_w(cab));
2619 /* the stream does not contain the # character */
2620 if (cab[0]=='#')
2622 writeout_cabinet_stream(package,&cab[1],source);
2623 strcpyW(path,source);
2624 *(strrchrW(path,'\\')+1)=0;
2626 else
2628 sz = MAX_PATH;
2629 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
2631 ERR("No Source dir defined \n");
2632 rc = ERROR_FUNCTION_FAILED;
2634 else
2636 strcpyW(path,source);
2637 strcatW(source,cab);
2638 /* extract the cab file into a folder in the temp folder */
2639 sz = MAX_PATH;
2640 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
2641 != ERROR_SUCCESS)
2642 GetTempPathW(MAX_PATH,path);
2645 rc = !extract_cabinet_file(source,path);
2647 msiobj_release(&row->hdr);
2648 MSI_ViewClose(view);
2649 msiobj_release(&view->hdr);
2650 return rc;
2653 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
2655 UINT rc;
2656 MSIFOLDER *folder;
2657 WCHAR install_path[MAX_PATH];
2659 rc = resolve_folder(package, package->components[component].Directory,
2660 install_path, FALSE, FALSE, &folder);
2662 if (rc != ERROR_SUCCESS)
2663 return rc;
2665 /* create the path */
2666 if (folder->State == 0)
2668 create_full_pathW(install_path);
2669 folder->State = 2;
2672 return rc;
2675 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
2677 UINT rc = ERROR_SUCCESS;
2678 DWORD index;
2679 MSIRECORD * uirow;
2680 WCHAR uipath[MAX_PATH];
2682 if (!package)
2683 return ERROR_INVALID_HANDLE;
2685 /* increment progress bar each time action data is sent */
2686 ui_progress(package,1,1,1,0);
2688 for (index = 0; index < package->loaded_files; index++)
2690 WCHAR path_to_source[MAX_PATH];
2691 MSIFILE *file;
2693 file = &package->files[index];
2695 if (file->Temporary)
2696 continue;
2698 if (!package->components[file->ComponentIndex].Enabled ||
2699 !package->components[file->ComponentIndex].FeatureState)
2701 TRACE("File %s is not scheduled for install\n",
2702 debugstr_w(file->File));
2703 continue;
2706 if ((file->State == 1) || (file->State == 2))
2708 TRACE("Installing %s\n",debugstr_w(file->File));
2709 rc = ready_media_for_file(package,file->Sequence,path_to_source);
2711 * WARNING!
2712 * our file table could change here because a new temp file
2713 * may have been created
2715 file = &package->files[index];
2716 if (rc != ERROR_SUCCESS)
2718 ERR("Unable to ready media\n");
2719 rc = ERROR_FUNCTION_FAILED;
2720 break;
2723 create_component_directory( package, file->ComponentIndex);
2725 strcpyW(file->SourcePath, path_to_source);
2726 strcatW(file->SourcePath, file->File);
2728 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
2729 debugstr_w(file->TargetPath));
2731 /* the UI chunk */
2732 uirow=MSI_CreateRecord(9);
2733 MSI_RecordSetStringW(uirow,1,file->File);
2734 strcpyW(uipath,file->TargetPath);
2735 *(strrchrW(uipath,'\\')+1)=0;
2736 MSI_RecordSetStringW(uirow,9,uipath);
2737 MSI_RecordSetInteger(uirow,6,file->FileSize);
2738 ui_actiondata(package,szInstallFiles,uirow);
2739 msiobj_release( &uirow->hdr );
2741 if (!MoveFileW(file->SourcePath,file->TargetPath))
2743 rc = GetLastError();
2744 ERR("Unable to move file (%s -> %s) (error %d)\n",
2745 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
2746 rc);
2747 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
2749 CopyFileW(file->SourcePath,file->TargetPath,FALSE);
2750 DeleteFileW(file->SourcePath);
2751 rc = 0;
2753 else
2754 break;
2756 else
2757 file->State = 4;
2759 ui_progress(package,2,0,0,0);
2763 return rc;
2766 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
2767 LPWSTR file_source)
2769 DWORD index;
2771 if (!package)
2772 return ERROR_INVALID_HANDLE;
2774 for (index = 0; index < package->loaded_files; index ++)
2776 if (strcmpW(file_key,package->files[index].File)==0)
2778 if (package->files[index].State >= 3)
2780 strcpyW(file_source,package->files[index].TargetPath);
2781 return ERROR_SUCCESS;
2783 else
2784 return ERROR_FILE_NOT_FOUND;
2788 return ERROR_FUNCTION_FAILED;
2791 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
2793 UINT rc;
2794 MSIQUERY * view;
2795 MSIRECORD * row = 0;
2796 static const WCHAR ExecSeqQuery[] = {
2797 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2798 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
2800 if (!package)
2801 return ERROR_INVALID_HANDLE;
2803 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2804 if (rc != ERROR_SUCCESS)
2805 return ERROR_SUCCESS;
2807 rc = MSI_ViewExecute(view, 0);
2808 if (rc != ERROR_SUCCESS)
2810 MSI_ViewClose(view);
2811 msiobj_release(&view->hdr);
2812 return rc;
2815 while (1)
2817 WCHAR file_key[0x100];
2818 WCHAR file_source[MAX_PATH];
2819 WCHAR dest_name[0x100];
2820 WCHAR dest_path[MAX_PATH];
2821 WCHAR component[0x100];
2822 INT component_index;
2824 DWORD sz=0x100;
2826 rc = MSI_ViewFetch(view,&row);
2827 if (rc != ERROR_SUCCESS)
2829 rc = ERROR_SUCCESS;
2830 break;
2833 sz=0x100;
2834 rc = MSI_RecordGetStringW(row,2,component,&sz);
2835 if (rc != ERROR_SUCCESS)
2837 ERR("Unable to get component\n");
2838 msiobj_release(&row->hdr);
2839 break;
2842 component_index = get_loaded_component(package,component);
2843 if (!package->components[component_index].Enabled ||
2844 !package->components[component_index].FeatureState)
2846 TRACE("Skipping copy due to disabled component\n");
2847 msiobj_release(&row->hdr);
2848 continue;
2851 sz=0x100;
2852 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
2853 if (rc != ERROR_SUCCESS)
2855 ERR("Unable to get file key\n");
2856 msiobj_release(&row->hdr);
2857 break;
2860 rc = get_file_target(package,file_key,file_source);
2862 if (rc != ERROR_SUCCESS)
2864 ERR("Original file unknown %s\n",debugstr_w(file_key));
2865 msiobj_release(&row->hdr);
2866 break;
2869 if (MSI_RecordIsNull(row,4))
2871 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
2873 else
2875 sz=0x100;
2876 MSI_RecordGetStringW(row,4,dest_name,&sz);
2877 reduce_to_longfilename(dest_name);
2880 if (MSI_RecordIsNull(row,5))
2882 strcpyW(dest_path,file_source);
2883 *strrchrW(dest_path,'\\')=0;
2885 else
2887 WCHAR destkey[0x100];
2888 sz=0x100;
2889 MSI_RecordGetStringW(row,5,destkey,&sz);
2890 sz = 0x100;
2891 rc = resolve_folder(package, destkey, dest_path,FALSE,FALSE,NULL);
2892 if (rc != ERROR_SUCCESS)
2894 ERR("Unable to get destination folder\n");
2895 msiobj_release(&row->hdr);
2896 break;
2900 strcatW(dest_path,dest_name);
2902 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
2903 debugstr_w(dest_path));
2905 if (strcmpW(file_source,dest_path))
2906 rc = !CopyFileW(file_source,dest_path,TRUE);
2907 else
2908 rc = ERROR_SUCCESS;
2910 if (rc != ERROR_SUCCESS)
2911 ERR("Failed to copy file\n");
2913 FIXME("We should track these duplicate files as well\n");
2915 msiobj_release(&row->hdr);
2917 MSI_ViewClose(view);
2918 msiobj_release(&view->hdr);
2919 return rc;
2924 /* OK this value is "interpretted" and then formatted based on the
2925 first few characters */
2926 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
2927 DWORD *size)
2929 LPSTR data = NULL;
2930 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
2932 if (value[1]=='x')
2934 LPWSTR ptr;
2935 CHAR byte[5];
2936 LPWSTR deformated;
2937 int count;
2939 deformat_string(package, &value[2], &deformated);
2941 /* binary value type */
2942 ptr = deformated;
2943 *type=REG_BINARY;
2944 *size = strlenW(ptr)/2;
2945 data = HeapAlloc(GetProcessHeap(),0,*size);
2947 byte[0] = '0';
2948 byte[1] = 'x';
2949 byte[4] = 0;
2950 count = 0;
2951 while (*ptr)
2953 byte[2]= *ptr;
2954 ptr++;
2955 byte[3]= *ptr;
2956 ptr++;
2957 data[count] = (BYTE)strtol(byte,NULL,0);
2958 count ++;
2960 HeapFree(GetProcessHeap(),0,deformated);
2962 TRACE("Data %li bytes(%i)\n",*size,count);
2964 else
2966 LPWSTR deformated;
2967 deformat_string(package, &value[1], &deformated);
2969 *type=REG_DWORD;
2970 *size = sizeof(DWORD);
2971 data = HeapAlloc(GetProcessHeap(),0,*size);
2972 *(LPDWORD)data = atoiW(deformated);
2973 TRACE("DWORD %i\n",*data);
2975 HeapFree(GetProcessHeap(),0,deformated);
2978 else
2980 WCHAR *ptr;
2981 *type=REG_SZ;
2983 if (value[0]=='#')
2985 if (value[1]=='%')
2987 ptr = &value[2];
2988 *type=REG_EXPAND_SZ;
2990 else
2991 ptr = &value[1];
2993 else
2994 ptr=value;
2996 *size = deformat_string(package, ptr,(LPWSTR*)&data);
2998 return data;
3001 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3003 UINT rc;
3004 MSIQUERY * view;
3005 MSIRECORD * row = 0;
3006 static const WCHAR ExecSeqQuery[] = {
3007 's','e','l','e','c','t',' ','*',' ',
3008 'f','r','o','m',' ','R','e','g','i','s','t','r','y',0 };
3010 if (!package)
3011 return ERROR_INVALID_HANDLE;
3013 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3014 if (rc != ERROR_SUCCESS)
3015 return ERROR_SUCCESS;
3017 rc = MSI_ViewExecute(view, 0);
3018 if (rc != ERROR_SUCCESS)
3020 MSI_ViewClose(view);
3021 msiobj_release(&view->hdr);
3022 return rc;
3025 /* increment progress bar each time action data is sent */
3026 ui_progress(package,1,1,1,0);
3028 while (1)
3030 static const WCHAR szHCR[] =
3031 {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T','\\',0};
3032 static const WCHAR szHCU[] =
3033 {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',0};
3034 static const WCHAR szHLM[] =
3035 {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',
3036 '\\',0};
3037 static const WCHAR szHU[] =
3038 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3040 WCHAR key[0x100];
3041 WCHAR name[0x100];
3042 LPWSTR value;
3043 LPSTR value_data = NULL;
3044 HKEY root_key, hkey;
3045 DWORD type,size;
3046 WCHAR component[0x100];
3047 INT component_index;
3048 MSIRECORD * uirow;
3049 WCHAR uikey[0x110];
3051 INT root;
3052 DWORD sz=0x100;
3054 rc = MSI_ViewFetch(view,&row);
3055 if (rc != ERROR_SUCCESS)
3057 rc = ERROR_SUCCESS;
3058 break;
3061 sz= 0x100;
3062 MSI_RecordGetStringW(row,6,component,&sz);
3063 component_index = get_loaded_component(package,component);
3065 if (!package->components[component_index].Enabled ||
3066 !package->components[component_index].FeatureState)
3068 TRACE("Skipping write due to disabled component\n");
3069 msiobj_release(&row->hdr);
3070 continue;
3073 /* null values have special meanings during uninstalls and such */
3075 if(MSI_RecordIsNull(row,5))
3077 msiobj_release(&row->hdr);
3078 continue;
3081 root = MSI_RecordGetInteger(row,2);
3082 sz = 0x100;
3083 MSI_RecordGetStringW(row,3,key,&sz);
3085 sz = 0x100;
3086 if (MSI_RecordIsNull(row,4))
3087 name[0]=0;
3088 else
3089 MSI_RecordGetStringW(row,4,name,&sz);
3091 /* get the root key */
3092 switch (root)
3094 case 0: root_key = HKEY_CLASSES_ROOT;
3095 strcpyW(uikey,szHCR); break;
3096 case 1: root_key = HKEY_CURRENT_USER;
3097 strcpyW(uikey,szHCU); break;
3098 case 2: root_key = HKEY_LOCAL_MACHINE;
3099 strcpyW(uikey,szHLM); break;
3100 case 3: root_key = HKEY_USERS;
3101 strcpyW(uikey,szHU); break;
3102 default:
3103 ERR("Unknown root %i\n",root);
3104 root_key=NULL;
3105 break;
3107 if (!root_key)
3109 msiobj_release(&row->hdr);
3110 continue;
3113 strcatW(uikey,key);
3114 if (RegCreateKeyW( root_key, key, &hkey))
3116 ERR("Could not create key %s\n",debugstr_w(key));
3117 msiobj_release(&row->hdr);
3118 continue;
3121 value = load_dynamic_stringW(row,5);
3122 value_data = parse_value(package, value, &type, &size);
3124 if (value_data)
3126 TRACE("Setting value %s\n",debugstr_w(name));
3127 RegSetValueExW(hkey, name, 0, type, value_data, size);
3129 uirow = MSI_CreateRecord(3);
3130 MSI_RecordSetStringW(uirow,2,name);
3131 MSI_RecordSetStringW(uirow,1,uikey);
3133 if (type == REG_SZ)
3134 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3135 else
3136 MSI_RecordSetStringW(uirow,3,value);
3138 ui_actiondata(package,szWriteRegistryValues,uirow);
3139 ui_progress(package,2,0,0,0);
3140 msiobj_release( &uirow->hdr );
3142 HeapFree(GetProcessHeap(),0,value_data);
3144 HeapFree(GetProcessHeap(),0,value);
3146 msiobj_release(&row->hdr);
3147 RegCloseKey(hkey);
3149 MSI_ViewClose(view);
3150 msiobj_release(&view->hdr);
3151 return rc;
3155 * This helper function should probably go alot of places
3157 * Thinking about this, maybe this should become yet another Bison file
3159 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data)
3161 WCHAR* mark=NULL;
3162 DWORD size=0;
3163 DWORD chunk=0;
3164 WCHAR key[0x100];
3165 LPWSTR value;
3166 DWORD sz;
3167 UINT rc;
3169 /* scan for special characters */
3170 if (!strchrW(ptr,'[') || (strchrW(ptr,'[') && !strchrW(ptr,']')))
3172 /* not formatted */
3173 size = (strlenW(ptr)+1) * sizeof(WCHAR);
3174 *data = HeapAlloc(GetProcessHeap(),0,size);
3175 strcpyW(*data,ptr);
3176 return size;
3179 /* formatted string located */
3180 mark = strchrW(ptr,'[');
3181 if (mark != ptr)
3183 INT cnt = (mark - ptr);
3184 TRACE("%i (%i) characters before marker\n",cnt,(mark-ptr));
3185 size = cnt * sizeof(WCHAR);
3186 size += sizeof(WCHAR);
3187 *data = HeapAlloc(GetProcessHeap(),0,size);
3188 strncpyW(*data,ptr,cnt);
3189 (*data)[cnt]=0;
3191 else
3193 size = sizeof(WCHAR);
3194 *data = HeapAlloc(GetProcessHeap(),0,size);
3195 (*data)[0]=0;
3197 mark++;
3198 strcpyW(key,mark);
3199 *strchrW(key,']')=0;
3200 mark = strchrW(mark,']');
3201 mark++;
3202 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3203 sz = 0;
3204 rc = MSI_GetPropertyW(package, key, NULL, &sz);
3205 if ((rc == ERROR_SUCCESS) || (rc == ERROR_MORE_DATA))
3207 LPWSTR newdata;
3209 sz++;
3210 value = HeapAlloc(GetProcessHeap(),0,sz * sizeof(WCHAR));
3211 MSI_GetPropertyW(package, key, value, &sz);
3213 chunk = (strlenW(value)+1) * sizeof(WCHAR);
3214 size+=chunk;
3215 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3216 *data = newdata;
3217 strcatW(*data,value);
3219 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3220 if (*mark!=0)
3222 LPWSTR newdata;
3223 chunk = (strlenW(mark)+1) * sizeof(WCHAR);
3224 size+=chunk;
3225 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3226 *data = newdata;
3227 strcatW(*data,mark);
3229 (*data)[strlenW(*data)]=0;
3230 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3232 /* recursively do this to clean up */
3233 mark = HeapAlloc(GetProcessHeap(),0,size);
3234 strcpyW(mark,*data);
3235 TRACE("String at this point %s\n",debugstr_w(mark));
3236 size = deformat_string(package,mark,data);
3237 HeapFree(GetProcessHeap(),0,mark);
3238 return size;
3241 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3243 WCHAR level[10000];
3244 INT install_level;
3245 DWORD sz;
3246 DWORD i;
3247 INT j;
3248 DWORD rc;
3249 LPWSTR override = NULL;
3250 static const WCHAR addlocal[]={'A','D','D','L','O','C','A','L',0};
3251 static const WCHAR all[]={'A','L','L',0};
3252 static const WCHAR szlevel[] = {
3253 'I','N','S','T','A','L','L','L','E','V','E','L',0};
3254 static const WCHAR szAddLocal[] = {
3255 'A','D','D','L','O','C','A','L',0};
3257 /* I do not know if this is where it should happen.. but */
3259 TRACE("Checking Install Level\n");
3261 sz = 10000;
3262 if (MSI_GetPropertyW(package,szlevel,level,&sz)==ERROR_SUCCESS)
3263 install_level = atoiW(level);
3264 else
3265 install_level = 1;
3267 sz = 0;
3268 rc = MSI_GetPropertyW(package,szAddLocal,NULL,&sz);
3269 if (rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA)
3271 sz++;
3272 override = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
3273 MSI_GetPropertyW(package, addlocal,override,&sz);
3277 * Components FeatureState defaults to FALSE. The idea is we want to
3278 * enable the component is ANY feature that uses it is enabled to install
3280 for(i = 0; i < package->loaded_features; i++)
3282 BOOL feature_state= ((package->features[i].Level > 0) &&
3283 (package->features[i].Level <= install_level));
3285 if (override && (strcmpiW(override,all)==0 ||
3286 strstrW(override,package->features[i].Feature)))
3288 TRACE("Override of install level found\n");
3289 feature_state = TRUE;
3290 package->features[i].Enabled = feature_state;
3293 TRACE("Feature %s has a state of %i\n",
3294 debugstr_w(package->features[i].Feature), feature_state);
3295 for( j = 0; j < package->features[i].ComponentCount; j++)
3297 package->components[package->features[i].Components[j]].FeatureState
3298 |= feature_state;
3301 if (override != NULL)
3302 HeapFree(GetProcessHeap(),0,override);
3304 * So basically we ONLY want to install a component if its Enabled AND
3305 * FeatureState are both TRUE
3307 return ERROR_SUCCESS;
3310 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3312 DWORD progress = 0;
3313 static const WCHAR q1[]={
3314 'S','E','L','E','C','T',' ','*',' ',
3315 'F','R','O','M',' ','R','e','g','i','s','t','r','y',0};
3316 UINT rc;
3317 MSIQUERY * view;
3318 MSIRECORD * row = 0;
3320 TRACE(" InstallValidate \n");
3322 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3323 if (rc != ERROR_SUCCESS)
3324 return ERROR_SUCCESS;
3326 rc = MSI_ViewExecute(view, 0);
3327 if (rc != ERROR_SUCCESS)
3329 MSI_ViewClose(view);
3330 msiobj_release(&view->hdr);
3331 return rc;
3333 while (1)
3335 rc = MSI_ViewFetch(view,&row);
3336 if (rc != ERROR_SUCCESS)
3338 rc = ERROR_SUCCESS;
3339 break;
3341 progress +=1;
3343 msiobj_release(&row->hdr);
3345 MSI_ViewClose(view);
3346 msiobj_release(&view->hdr);
3348 ui_progress(package,0,progress+package->loaded_files,0,0);
3350 return ERROR_SUCCESS;
3353 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3355 UINT rc;
3356 MSIQUERY * view = NULL;
3357 MSIRECORD * row = 0;
3358 static const WCHAR ExecSeqQuery[] = {
3359 'S','E','L','E','C','T',' ','*',' ',
3360 'f','r','o','m',' ','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3361 static const WCHAR title[]=
3362 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3364 TRACE("Checking launch conditions\n");
3366 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3367 if (rc != ERROR_SUCCESS)
3368 return ERROR_SUCCESS;
3370 rc = MSI_ViewExecute(view, 0);
3371 if (rc != ERROR_SUCCESS)
3373 MSI_ViewClose(view);
3374 msiobj_release(&view->hdr);
3375 return rc;
3378 rc = ERROR_SUCCESS;
3379 while (rc == ERROR_SUCCESS)
3381 LPWSTR cond = NULL;
3382 LPWSTR message = NULL;
3384 rc = MSI_ViewFetch(view,&row);
3385 if (rc != ERROR_SUCCESS)
3387 rc = ERROR_SUCCESS;
3388 break;
3391 cond = load_dynamic_stringW(row,1);
3393 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3395 message = load_dynamic_stringW(row,2);
3396 MessageBoxW(NULL,message,title,MB_OK);
3397 HeapFree(GetProcessHeap(),0,message);
3398 rc = ERROR_FUNCTION_FAILED;
3400 HeapFree(GetProcessHeap(),0,cond);
3401 msiobj_release(&row->hdr);
3403 MSI_ViewClose(view);
3404 msiobj_release(&view->hdr);
3405 return rc;
3408 static void resolve_keypath( MSIPACKAGE* package, INT
3409 component_index, WCHAR *keypath)
3411 MSICOMPONENT* cmp = &package->components[component_index];
3413 if (cmp->KeyPath[0]==0)
3415 resolve_folder(package,cmp->Directory,keypath,FALSE,FALSE,NULL);
3416 return;
3418 if ((cmp->Attributes & 0x4) || (cmp->Attributes & 0x20))
3420 FIXME("UNIMPLEMENTED keypath as Registry or ODBC Source\n");
3421 keypath[0]=0;
3423 else
3425 int j;
3426 j = get_loaded_file(package,cmp->KeyPath);
3428 if (j>=0)
3429 strcpyW(keypath,package->files[j].TargetPath);
3434 * Ok further analysis makes me think that this work is
3435 * actually done in the PublishComponents and PublishFeatures
3436 * step, and not here. It appears like the keypath and all that is
3437 * resolved in this step, however actually written in the Publish steps.
3438 * But we will leave it here for now because it is unclear
3440 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
3442 WCHAR productcode[0x100];
3443 WCHAR squished_pc[0x100];
3444 WCHAR squished_cc[0x100];
3445 DWORD sz;
3446 UINT rc;
3447 DWORD i;
3448 HKEY hkey=0,hkey2=0,hkey3=0;
3449 static const WCHAR szProductCode[]=
3450 {'P','r','o','d','u','c','t','C','o','d','e',0};
3451 static const WCHAR szInstaller[] = {
3452 'S','o','f','t','w','a','r','e','\\',
3453 'M','i','c','r','o','s','o','f','t','\\',
3454 'W','i','n','d','o','w','s','\\',
3455 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3456 'I','n','s','t','a','l','l','e','r',0 };
3457 static const WCHAR szFeatures[] = {
3458 'F','e','a','t','u','r','e','s',0 };
3459 static const WCHAR szComponents[] = {
3460 'C','o','m','p','o','n','e','n','t','s',0 };
3462 if (!package)
3463 return ERROR_INVALID_HANDLE;
3465 /* writes the Component and Features values to the registry */
3466 sz = 0x100;
3467 rc = MSI_GetPropertyW(package,szProductCode,productcode,&sz);
3468 if (rc != ERROR_SUCCESS)
3469 return ERROR_SUCCESS;
3471 squash_guid(productcode,squished_pc);
3472 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller,&hkey);
3473 if (rc != ERROR_SUCCESS)
3474 goto end;
3476 rc = RegCreateKeyW(hkey,szFeatures,&hkey2);
3477 if (rc != ERROR_SUCCESS)
3478 goto end;
3480 rc = RegCreateKeyW(hkey2,squished_pc,&hkey3);
3481 if (rc != ERROR_SUCCESS)
3482 goto end;
3484 /* here the guids are base 85 encoded */
3485 for (i = 0; i < package->loaded_features; i++)
3487 LPWSTR data = NULL;
3488 GUID clsid;
3489 int j;
3490 INT size;
3492 size = package->features[i].ComponentCount*21*sizeof(WCHAR);
3493 data = HeapAlloc(GetProcessHeap(), 0, size);
3495 data[0] = 0;
3496 for (j = 0; j < package->features[i].ComponentCount; j++)
3498 WCHAR buf[21];
3499 TRACE("From %s\n",debugstr_w(package->components
3500 [package->features[i].Components[j]].ComponentId));
3501 CLSIDFromString(package->components
3502 [package->features[i].Components[j]].ComponentId,
3503 &clsid);
3504 encode_base85_guid(&clsid,buf);
3505 TRACE("to %s\n",debugstr_w(buf));
3506 strcatW(data,buf);
3509 size = strlenW(data)*sizeof(WCHAR);
3510 RegSetValueExW(hkey3,package->features[i].Feature,0,REG_SZ,
3511 (LPSTR)data,size);
3512 HeapFree(GetProcessHeap(),0,data);
3515 RegCloseKey(hkey3);
3516 RegCloseKey(hkey2);
3518 rc = RegCreateKeyW(hkey,szComponents,&hkey2);
3519 if (rc != ERROR_SUCCESS)
3520 goto end;
3522 for (i = 0; i < package->loaded_components; i++)
3524 if (package->components[i].ComponentId[0]!=0)
3526 WCHAR keypath[0x1000];
3527 MSIRECORD * uirow;
3529 squash_guid(package->components[i].ComponentId,squished_cc);
3530 rc = RegCreateKeyW(hkey2,squished_cc,&hkey3);
3531 if (rc != ERROR_SUCCESS)
3532 continue;
3534 resolve_keypath(package,i,keypath);
3536 RegSetValueExW(hkey3,squished_pc,0,REG_SZ,(LPVOID)keypath,
3537 (strlenW(keypath)+1)*sizeof(WCHAR));
3538 RegCloseKey(hkey3);
3540 /* UI stuff */
3541 uirow = MSI_CreateRecord(3);
3542 MSI_RecordSetStringW(uirow,1,productcode);
3543 MSI_RecordSetStringW(uirow,2,package->components[i].ComponentId);
3544 MSI_RecordSetStringW(uirow,3,keypath);
3545 ui_actiondata(package,szProcessComponents,uirow);
3546 msiobj_release( &uirow->hdr );
3549 end:
3550 RegCloseKey(hkey2);
3551 RegCloseKey(hkey);
3552 return rc;
3555 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
3558 * OK this is a bit confusing.. I am given a _Component key and I believe
3559 * that the file that is being registered as a type library is the "key file
3560 * of that component" which I interpret to mean "The file in the KeyPath of
3561 * that component".
3563 UINT rc;
3564 MSIQUERY * view;
3565 MSIRECORD * row = 0;
3566 static const WCHAR Query[] = {
3567 'S','E','L','E','C','T',' ','*',' ',
3568 'f','r','o','m',' ','T','y','p','e','L','i','b',0};
3569 ITypeLib *ptLib;
3570 HRESULT res;
3572 if (!package)
3573 return ERROR_INVALID_HANDLE;
3575 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3576 if (rc != ERROR_SUCCESS)
3577 return ERROR_SUCCESS;
3579 rc = MSI_ViewExecute(view, 0);
3580 if (rc != ERROR_SUCCESS)
3582 MSI_ViewClose(view);
3583 msiobj_release(&view->hdr);
3584 return rc;
3587 while (1)
3589 WCHAR component[0x100];
3590 DWORD sz;
3591 INT index;
3593 rc = MSI_ViewFetch(view,&row);
3594 if (rc != ERROR_SUCCESS)
3596 rc = ERROR_SUCCESS;
3597 break;
3600 sz = 0x100;
3601 MSI_RecordGetStringW(row,3,component,&sz);
3603 index = get_loaded_component(package,component);
3604 if (index < 0)
3606 msiobj_release(&row->hdr);
3607 continue;
3610 if (!package->components[index].Enabled ||
3611 !package->components[index].FeatureState)
3613 TRACE("Skipping typelib reg due to disabled component\n");
3614 msiobj_release(&row->hdr);
3615 continue;
3618 index = get_loaded_file(package,package->components[index].KeyPath);
3620 if (index < 0)
3622 msiobj_release(&row->hdr);
3623 continue;
3626 res = LoadTypeLib(package->files[index].TargetPath,&ptLib);
3627 if (SUCCEEDED(res))
3629 WCHAR help[MAX_PATH];
3630 WCHAR helpid[0x100];
3632 sz = 0x100;
3633 MSI_RecordGetStringW(row,6,helpid,&sz);
3635 resolve_folder(package,helpid,help,FALSE,FALSE,NULL);
3637 res = RegisterTypeLib(ptLib,package->files[index].TargetPath,help);
3638 if (!SUCCEEDED(res))
3639 ERR("Failed to register type library %s\n",
3640 debugstr_w(package->files[index].TargetPath));
3641 else
3643 /* Yes the row has more fields than I need, but #1 is
3644 correct and the only one I need. Why make a new row? */
3646 ui_actiondata(package,szRegisterTypeLibraries,row);
3648 TRACE("Registered %s\n",
3649 debugstr_w(package->files[index].TargetPath));
3652 if (ptLib)
3653 ITypeLib_Release(ptLib);
3655 else
3656 ERR("Failed to load type library %s\n",
3657 debugstr_w(package->files[index].TargetPath));
3659 msiobj_release(&row->hdr);
3661 MSI_ViewClose(view);
3662 msiobj_release(&view->hdr);
3663 return rc;
3667 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
3669 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3670 UINT rc;
3671 MSIQUERY * view;
3672 MSIRECORD * row = 0;
3673 static const WCHAR ExecSeqQuery[] =
3674 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','p','p','I'
3675 ,'d',' ','w','h','e','r','e',' ','A','p','p','I','d','=','`','%','s','`',0};
3676 WCHAR Query[0x1000];
3677 HKEY hkey2,hkey3;
3678 LPWSTR buffer=0;
3680 if (!package)
3681 return ERROR_INVALID_HANDLE;
3683 sprintfW(Query,ExecSeqQuery,clsid);
3685 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3686 if (rc != ERROR_SUCCESS)
3687 return rc;
3689 rc = MSI_ViewExecute(view, 0);
3690 if (rc != ERROR_SUCCESS)
3692 MSI_ViewClose(view);
3693 msiobj_release(&view->hdr);
3694 return rc;
3697 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
3698 RegCreateKeyW(hkey2,clsid,&hkey3);
3699 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
3700 (strlenW(app)+1)*sizeof(WCHAR));
3702 rc = MSI_ViewFetch(view,&row);
3703 if (rc != ERROR_SUCCESS)
3705 MSI_ViewClose(view);
3706 msiobj_release(&view->hdr);
3707 return rc;
3710 if (!MSI_RecordIsNull(row,2))
3712 LPWSTR deformated=0;
3713 UINT size;
3714 static const WCHAR szRemoteServerName[] =
3715 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
3716 buffer = load_dynamic_stringW(row,2);
3717 size = deformat_string(package,buffer,&deformated);
3718 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
3719 size);
3720 HeapFree(GetProcessHeap(),0,deformated);
3721 HeapFree(GetProcessHeap(),0,buffer);
3724 if (!MSI_RecordIsNull(row,3))
3726 static const WCHAR szLocalService[] =
3727 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
3728 UINT size;
3729 buffer = load_dynamic_stringW(row,3);
3730 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3731 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
3732 HeapFree(GetProcessHeap(),0,buffer);
3735 if (!MSI_RecordIsNull(row,4))
3737 static const WCHAR szService[] =
3738 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
3739 UINT size;
3740 buffer = load_dynamic_stringW(row,4);
3741 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3742 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
3743 HeapFree(GetProcessHeap(),0,buffer);
3746 if (!MSI_RecordIsNull(row,5))
3748 static const WCHAR szDLL[] =
3749 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
3750 UINT size;
3751 buffer = load_dynamic_stringW(row,5);
3752 size = (strlenW(buffer)+1) * sizeof(WCHAR);
3753 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
3754 HeapFree(GetProcessHeap(),0,buffer);
3757 if (!MSI_RecordIsNull(row,6))
3759 static const WCHAR szActivate[] =
3760 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
3761 static const WCHAR szY[] = {'Y',0};
3763 if (MSI_RecordGetInteger(row,6))
3764 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
3767 if (!MSI_RecordIsNull(row,7))
3769 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
3770 static const WCHAR szUser[] =
3771 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
3773 if (MSI_RecordGetInteger(row,7))
3774 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
3777 msiobj_release(&row->hdr);
3778 MSI_ViewClose(view);
3779 msiobj_release(&view->hdr);
3780 RegCloseKey(hkey3);
3781 RegCloseKey(hkey2);
3782 return rc;
3785 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
3788 * Again I am assuming the words, "Whose key file represents" when referring
3789 * to a Component as to meaning that Components KeyPath file
3791 * Also there is a very strong connection between ClassInfo and ProgID
3792 * that I am mostly glossing over.
3793 * What would be more propper is to load the ClassInfo and the ProgID info
3794 * into memory data structures and then be able to enable and disable them
3795 * based on component.
3798 UINT rc;
3799 MSIQUERY * view;
3800 MSIRECORD * row = 0;
3801 static const WCHAR ExecSeqQuery[] = {
3802 'S','E','L','E','C','T',' ','*',' ',
3803 'f','r','o','m',' ','C','l','a','s','s',0};
3804 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3805 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
3806 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
3807 HKEY hkey,hkey2,hkey3;
3809 if (!package)
3810 return ERROR_INVALID_HANDLE;
3812 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
3813 if (rc != ERROR_SUCCESS)
3814 return ERROR_FUNCTION_FAILED;
3816 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3817 if (rc != ERROR_SUCCESS)
3819 rc = ERROR_SUCCESS;
3820 goto end;
3823 rc = MSI_ViewExecute(view, 0);
3824 if (rc != ERROR_SUCCESS)
3826 MSI_ViewClose(view);
3827 msiobj_release(&view->hdr);
3828 goto end;
3831 while (1)
3833 WCHAR clsid[0x100];
3834 WCHAR buffer[0x100];
3835 WCHAR desc[0x100];
3836 DWORD sz;
3837 INT index;
3839 rc = MSI_ViewFetch(view,&row);
3840 if (rc != ERROR_SUCCESS)
3842 rc = ERROR_SUCCESS;
3843 break;
3846 sz=0x100;
3847 MSI_RecordGetStringW(row,3,buffer,&sz);
3849 index = get_loaded_component(package,buffer);
3851 if (index < 0)
3853 msiobj_release(&row->hdr);
3854 continue;
3857 if (!package->components[index].Enabled ||
3858 !package->components[index].FeatureState)
3860 TRACE("Skipping class reg due to disabled component\n");
3861 msiobj_release(&row->hdr);
3862 continue;
3865 sz=0x100;
3866 MSI_RecordGetStringW(row,1,clsid,&sz);
3867 RegCreateKeyW(hkey,clsid,&hkey2);
3869 if (!MSI_RecordIsNull(row,5))
3871 sz=0x100;
3872 MSI_RecordGetStringW(row,5,desc,&sz);
3874 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
3875 (strlenW(desc)+1)*sizeof(WCHAR));
3877 else
3878 desc[0]=0;
3880 sz=0x100;
3881 MSI_RecordGetStringW(row,2,buffer,&sz);
3883 RegCreateKeyW(hkey2,buffer,&hkey3);
3885 index = get_loaded_file(package,package->components[index].KeyPath);
3886 RegSetValueExW(hkey3,NULL,0,REG_SZ,
3887 (LPVOID)package->files[index].TargetPath,
3888 (strlenW(package->files[index].TargetPath)+1)
3889 *sizeof(WCHAR));
3891 RegCloseKey(hkey3);
3893 if (!MSI_RecordIsNull(row,4))
3895 sz=0x100;
3896 MSI_RecordGetStringW(row,4,buffer,&sz);
3898 RegCreateKeyW(hkey2,szProgID,&hkey3);
3900 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
3901 (strlenW(buffer)+1)*sizeof(WCHAR));
3903 RegCloseKey(hkey3);
3906 if (!MSI_RecordIsNull(row,6))
3908 sz=0x100;
3909 MSI_RecordGetStringW(row,6,buffer,&sz);
3911 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
3912 (strlenW(buffer)+1)*sizeof(WCHAR));
3914 register_appid(package,buffer,desc);
3917 RegCloseKey(hkey2);
3919 FIXME("Process the rest of the fields >7\n");
3921 ui_actiondata(package,szRegisterClassInfo,row);
3923 msiobj_release(&row->hdr);
3925 MSI_ViewClose(view);
3926 msiobj_release(&view->hdr);
3928 end:
3929 RegCloseKey(hkey);
3930 return rc;
3933 static UINT register_progid_base(MSIRECORD * row, LPWSTR clsid)
3935 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
3936 HKEY hkey,hkey2;
3937 WCHAR buffer[0x100];
3938 DWORD sz;
3941 sz = 0x100;
3942 MSI_RecordGetStringW(row,1,buffer,&sz);
3943 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
3945 if (!MSI_RecordIsNull(row,4))
3947 sz = 0x100;
3948 MSI_RecordGetStringW(row,4,buffer,&sz);
3949 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
3950 sizeof(WCHAR));
3953 if (!MSI_RecordIsNull(row,3))
3955 sz = 0x100;
3957 MSI_RecordGetStringW(row,3,buffer,&sz);
3958 RegCreateKeyW(hkey,szCLSID,&hkey2);
3959 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
3960 sizeof(WCHAR));
3962 if (clsid)
3963 strcpyW(clsid,buffer);
3965 RegCloseKey(hkey2);
3967 else
3969 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
3970 return ERROR_FUNCTION_FAILED;
3972 if (!MSI_RecordIsNull(row,5))
3973 FIXME ("UNHANDLED icon in Progid\n");
3974 return ERROR_SUCCESS;
3977 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
3979 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
3980 LPWSTR clsid)
3982 UINT rc;
3983 MSIQUERY * view;
3984 MSIRECORD * row = 0;
3985 static const WCHAR Query_t[] =
3986 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','P','r','o','g'
3987 ,'I','d',' ','w','h','e','r','e',' ','P','r','o','g','I','d',' ','=',' ','`'
3988 ,'%','s','`',0};
3989 WCHAR Query[0x1000];
3991 if (!package)
3992 return ERROR_INVALID_HANDLE;
3994 sprintfW(Query,Query_t,parent);
3996 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3997 if (rc != ERROR_SUCCESS)
3998 return rc;
4000 rc = MSI_ViewExecute(view, 0);
4001 if (rc != ERROR_SUCCESS)
4003 MSI_ViewClose(view);
4004 msiobj_release(&view->hdr);
4005 return rc;
4008 rc = MSI_ViewFetch(view,&row);
4009 if (rc != ERROR_SUCCESS)
4011 MSI_ViewClose(view);
4012 msiobj_release(&view->hdr);
4013 return rc;
4016 register_progid(package,row,clsid);
4018 msiobj_release(&row->hdr);
4019 MSI_ViewClose(view);
4020 msiobj_release(&view->hdr);
4021 return rc;
4024 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
4026 UINT rc = ERROR_SUCCESS;
4028 if (MSI_RecordIsNull(row,2))
4029 rc = register_progid_base(row,clsid);
4030 else
4032 WCHAR buffer[0x1000];
4033 DWORD sz, disp;
4034 HKEY hkey,hkey2;
4035 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4037 /* check if already registered */
4038 sz = 0x100;
4039 MSI_RecordGetStringW(row,1,buffer,&sz);
4040 RegCreateKeyExW(HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4041 KEY_ALL_ACCESS, NULL, &hkey, &disp );
4042 if (disp == REG_OPENED_EXISTING_KEY)
4044 TRACE("Key already registered\n");
4045 RegCloseKey(hkey);
4046 return rc;
4048 /* clsid is same as parent */
4049 RegCreateKeyW(hkey,szCLSID,&hkey2);
4050 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
4051 sizeof(WCHAR));
4053 RegCloseKey(hkey2);
4055 sz = 0x100;
4056 MSI_RecordGetStringW(row,2,buffer,&sz);
4057 rc = register_parent_progid(package,buffer,clsid);
4059 if (!MSI_RecordIsNull(row,4))
4061 sz = 0x100;
4062 MSI_RecordGetStringW(row,4,buffer,&sz);
4063 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
4064 (strlenW(buffer)+1) * sizeof(WCHAR));
4067 if (!MSI_RecordIsNull(row,5))
4068 FIXME ("UNHANDLED icon in Progid\n");
4070 RegCloseKey(hkey);
4072 return rc;
4075 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
4078 * Sigh, here I am just brute force registering all progids
4079 * this needs to be linked to the Classes that have been registered
4080 * but the easiest way to do that is to load all these stuff into
4081 * memory for easy checking.
4083 * Gives me something to continue to work toward.
4085 UINT rc;
4086 MSIQUERY * view;
4087 MSIRECORD * row = 0;
4088 static const WCHAR Query[] = {
4089 'S','E','L','E','C','T',' ','*',' ',
4090 'F','R','O','M',' ','P','r','o','g','I','d',0};
4092 if (!package)
4093 return ERROR_INVALID_HANDLE;
4095 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4096 if (rc != ERROR_SUCCESS)
4097 return ERROR_SUCCESS;
4099 rc = MSI_ViewExecute(view, 0);
4100 if (rc != ERROR_SUCCESS)
4102 MSI_ViewClose(view);
4103 msiobj_release(&view->hdr);
4104 return rc;
4107 while (1)
4109 WCHAR clsid[0x1000];
4111 rc = MSI_ViewFetch(view,&row);
4112 if (rc != ERROR_SUCCESS)
4114 rc = ERROR_SUCCESS;
4115 break;
4118 register_progid(package,row,clsid);
4119 ui_actiondata(package,szRegisterProgIdInfo,row);
4121 msiobj_release(&row->hdr);
4123 MSI_ViewClose(view);
4124 msiobj_release(&view->hdr);
4125 return rc;
4128 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
4129 LPWSTR FilePath)
4131 WCHAR ProductCode[0x100];
4132 WCHAR SystemFolder[MAX_PATH];
4133 DWORD sz;
4135 static const WCHAR szInstaller[] =
4136 {'I','n','s','t','a','l','l','e','r','\\',0};
4137 static const WCHAR szProductCode[] =
4138 {'P','r','o','d','u','c','t','C','o','d','e',0};
4139 static const WCHAR szFolder[] =
4140 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4142 sz = 0x100;
4143 MSI_GetPropertyW(package,szProductCode,ProductCode,&sz);
4144 if (strlenW(ProductCode)==0)
4145 return ERROR_FUNCTION_FAILED;
4147 sz = MAX_PATH;
4148 MSI_GetPropertyW(package,szFolder,SystemFolder,&sz);
4149 strcatW(SystemFolder,szInstaller);
4150 strcatW(SystemFolder,ProductCode);
4151 create_full_pathW(SystemFolder);
4153 strcpyW(FilePath,SystemFolder);
4154 strcatW(FilePath,cszbs);
4155 strcatW(FilePath,icon_name);
4156 return ERROR_SUCCESS;
4159 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
4161 UINT rc;
4162 MSIQUERY * view;
4163 MSIRECORD * row = 0;
4164 static const WCHAR Query[] = {
4165 'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
4166 'S','h','o','r','t','c','u','t',0};
4167 IShellLinkW *sl;
4168 IPersistFile *pf;
4169 HRESULT res;
4171 if (!package)
4172 return ERROR_INVALID_HANDLE;
4174 res = CoInitialize( NULL );
4175 if (FAILED (res))
4177 ERR("CoInitialize failed\n");
4178 return ERROR_FUNCTION_FAILED;
4181 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4182 if (rc != ERROR_SUCCESS)
4183 return ERROR_SUCCESS;
4185 rc = MSI_ViewExecute(view, 0);
4186 if (rc != ERROR_SUCCESS)
4188 MSI_ViewClose(view);
4189 msiobj_release(&view->hdr);
4190 return rc;
4193 while (1)
4195 WCHAR target_file[MAX_PATH];
4196 WCHAR buffer[0x100];
4197 DWORD sz;
4198 DWORD index;
4199 static const WCHAR szlnk[]={'.','l','n','k',0};
4201 rc = MSI_ViewFetch(view,&row);
4202 if (rc != ERROR_SUCCESS)
4204 rc = ERROR_SUCCESS;
4205 break;
4208 sz = 0x100;
4209 MSI_RecordGetStringW(row,4,buffer,&sz);
4211 index = get_loaded_component(package,buffer);
4213 if (index < 0)
4215 msiobj_release(&row->hdr);
4216 continue;
4219 if (!package->components[index].Enabled ||
4220 !package->components[index].FeatureState)
4222 TRACE("Skipping shortcut creation due to disabled component\n");
4223 msiobj_release(&row->hdr);
4224 continue;
4227 ui_actiondata(package,szCreateShortcuts,row);
4229 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
4230 &IID_IShellLinkW, (LPVOID *) &sl );
4232 if (FAILED(res))
4234 ERR("Is IID_IShellLink\n");
4235 msiobj_release(&row->hdr);
4236 continue;
4239 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
4240 if( FAILED( res ) )
4242 ERR("Is IID_IPersistFile\n");
4243 msiobj_release(&row->hdr);
4244 continue;
4247 sz = 0x100;
4248 MSI_RecordGetStringW(row,2,buffer,&sz);
4249 resolve_folder(package, buffer,target_file,FALSE,FALSE,NULL);
4251 sz = 0x100;
4252 MSI_RecordGetStringW(row,3,buffer,&sz);
4253 reduce_to_longfilename(buffer);
4254 strcatW(target_file,buffer);
4255 if (!strchrW(target_file,'.'))
4256 strcatW(target_file,szlnk);
4258 sz = 0x100;
4259 MSI_RecordGetStringW(row,5,buffer,&sz);
4260 if (strchrW(buffer,'['))
4262 LPWSTR deformated;
4263 deformat_string(package,buffer,&deformated);
4264 IShellLinkW_SetPath(sl,deformated);
4265 HeapFree(GetProcessHeap(),0,deformated);
4267 else
4269 FIXME("UNHANDLED shortcut format, advertised shortcut\n");
4270 IPersistFile_Release( pf );
4271 IShellLinkW_Release( sl );
4272 msiobj_release(&row->hdr);
4273 continue;
4276 if (!MSI_RecordIsNull(row,6))
4278 LPWSTR deformated;
4279 sz = 0x100;
4280 MSI_RecordGetStringW(row,6,buffer,&sz);
4281 deformat_string(package,buffer,&deformated);
4282 IShellLinkW_SetArguments(sl,deformated);
4283 HeapFree(GetProcessHeap(),0,deformated);
4286 if (!MSI_RecordIsNull(row,7))
4288 LPWSTR deformated;
4289 deformated = load_dynamic_stringW(row,7);
4290 IShellLinkW_SetDescription(sl,deformated);
4291 HeapFree(GetProcessHeap(),0,deformated);
4294 if (!MSI_RecordIsNull(row,8))
4295 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
4297 if (!MSI_RecordIsNull(row,9))
4299 WCHAR Path[MAX_PATH];
4300 INT index;
4302 sz = 0x100;
4303 MSI_RecordGetStringW(row,9,buffer,&sz);
4305 build_icon_path(package,buffer,Path);
4306 index = MSI_RecordGetInteger(row,10);
4308 IShellLinkW_SetIconLocation(sl,Path,index);
4311 if (!MSI_RecordIsNull(row,11))
4312 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
4314 if (!MSI_RecordIsNull(row,12))
4316 WCHAR Path[MAX_PATH];
4318 sz = 0x100;
4319 MSI_RecordGetStringW(row,12,buffer,&sz);
4320 resolve_folder(package, buffer, Path, FALSE, FALSE, NULL);
4321 IShellLinkW_SetWorkingDirectory(sl,Path);
4324 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
4325 IPersistFile_Save(pf,target_file,FALSE);
4327 IPersistFile_Release( pf );
4328 IShellLinkW_Release( sl );
4330 msiobj_release(&row->hdr);
4332 MSI_ViewClose(view);
4333 msiobj_release(&view->hdr);
4336 CoUninitialize();
4338 return rc;
4343 * 99% of the work done here is only done for
4344 * advertised installs. However this is where the
4345 * Icon table is processed and written out
4346 * so that is what I am going to do here.
4348 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
4350 UINT rc;
4351 MSIQUERY * view;
4352 MSIRECORD * row = 0;
4353 static const WCHAR Query[]={
4354 'S','E','L','E','C','T',' ','*',' ',
4355 'f','r','o','m',' ','I','c','o','n',0};
4356 DWORD sz;
4358 if (!package)
4359 return ERROR_INVALID_HANDLE;
4361 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4362 if (rc != ERROR_SUCCESS)
4363 return ERROR_SUCCESS;
4365 rc = MSI_ViewExecute(view, 0);
4366 if (rc != ERROR_SUCCESS)
4368 MSI_ViewClose(view);
4369 msiobj_release(&view->hdr);
4370 return rc;
4373 while (1)
4375 HANDLE the_file;
4376 WCHAR FilePath[MAX_PATH];
4377 WCHAR FileName[MAX_PATH];
4378 CHAR buffer[1024];
4380 rc = MSI_ViewFetch(view,&row);
4381 if (rc != ERROR_SUCCESS)
4383 rc = ERROR_SUCCESS;
4384 break;
4387 sz = MAX_PATH;
4388 MSI_RecordGetStringW(row,1,FileName,&sz);
4389 if (sz == 0)
4391 ERR("Unable to get FileName\n");
4392 msiobj_release(&row->hdr);
4393 continue;
4396 build_icon_path(package,FileName,FilePath);
4398 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
4400 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
4401 FILE_ATTRIBUTE_NORMAL, NULL);
4403 if (the_file == INVALID_HANDLE_VALUE)
4405 ERR("Unable to create file %s\n",debugstr_w(FilePath));
4406 msiobj_release(&row->hdr);
4407 continue;
4412 DWORD write;
4413 sz = 1024;
4414 rc = MSI_RecordReadStream(row,2,buffer,&sz);
4415 if (rc != ERROR_SUCCESS)
4417 ERR("Failed to get stream\n");
4418 CloseHandle(the_file);
4419 DeleteFileW(FilePath);
4420 break;
4422 WriteFile(the_file,buffer,sz,&write,NULL);
4423 } while (sz == 1024);
4425 CloseHandle(the_file);
4426 msiobj_release(&row->hdr);
4428 MSI_ViewClose(view);
4429 msiobj_release(&view->hdr);
4430 return rc;
4434 /* Msi functions that seem appropriate here */
4435 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
4437 LPWSTR szwAction;
4438 UINT rc;
4440 TRACE(" exteral attempt at action %s\n",szAction);
4442 if (!szAction)
4443 return ERROR_FUNCTION_FAILED;
4444 if (hInstall == 0)
4445 return ERROR_FUNCTION_FAILED;
4447 szwAction = strdupAtoW(szAction);
4449 if (!szwAction)
4450 return ERROR_FUNCTION_FAILED;
4453 rc = MsiDoActionW(hInstall, szwAction);
4454 HeapFree(GetProcessHeap(),0,szwAction);
4455 return rc;
4458 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
4460 MSIPACKAGE *package;
4461 UINT ret = ERROR_INVALID_HANDLE;
4463 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
4465 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4466 if( package )
4468 ret = ACTION_PerformAction(package,szAction);
4469 msiobj_release( &package->hdr );
4471 return ret;
4474 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
4475 LPSTR szPathBuf, DWORD* pcchPathBuf)
4477 LPWSTR szwFolder;
4478 LPWSTR szwPathBuf;
4479 UINT rc;
4481 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4483 if (!szFolder)
4484 return ERROR_FUNCTION_FAILED;
4485 if (hInstall == 0)
4486 return ERROR_FUNCTION_FAILED;
4488 szwFolder = strdupAtoW(szFolder);
4490 if (!szwFolder)
4491 return ERROR_FUNCTION_FAILED;
4493 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4495 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4497 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4498 *pcchPathBuf, NULL, NULL );
4500 HeapFree(GetProcessHeap(),0,szwFolder);
4501 HeapFree(GetProcessHeap(),0,szwPathBuf);
4503 return rc;
4506 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4507 szPathBuf, DWORD* pcchPathBuf)
4509 WCHAR path[MAX_PATH];
4510 UINT rc;
4511 MSIPACKAGE *package;
4513 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
4515 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4516 if( !package )
4517 return ERROR_INVALID_HANDLE;
4518 rc = resolve_folder(package, szFolder, path, FALSE, FALSE, NULL);
4519 msiobj_release( &package->hdr );
4521 if (rc == ERROR_SUCCESS && strlenW(path) > *pcchPathBuf)
4523 *pcchPathBuf = strlenW(path)+1;
4524 return ERROR_MORE_DATA;
4526 else if (rc == ERROR_SUCCESS)
4528 *pcchPathBuf = strlenW(path)+1;
4529 strcpyW(szPathBuf,path);
4530 TRACE("Returning Path %s\n",debugstr_w(path));
4533 return rc;
4537 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
4538 LPSTR szPathBuf, DWORD* pcchPathBuf)
4540 LPWSTR szwFolder;
4541 LPWSTR szwPathBuf;
4542 UINT rc;
4544 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
4546 if (!szFolder)
4547 return ERROR_FUNCTION_FAILED;
4548 if (hInstall == 0)
4549 return ERROR_FUNCTION_FAILED;
4551 szwFolder = strdupAtoW(szFolder);
4552 if (!szwFolder)
4553 return ERROR_FUNCTION_FAILED;
4555 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
4557 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
4559 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
4560 *pcchPathBuf, NULL, NULL );
4562 HeapFree(GetProcessHeap(),0,szwFolder);
4563 HeapFree(GetProcessHeap(),0,szwPathBuf);
4565 return rc;
4568 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
4569 szPathBuf, DWORD* pcchPathBuf)
4571 WCHAR path[MAX_PATH];
4572 UINT rc;
4573 MSIPACKAGE *package;
4575 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
4577 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4578 if( !package )
4579 return ERROR_INVALID_HANDLE;
4580 rc = resolve_folder(package, szFolder, path, TRUE, FALSE, NULL);
4581 msiobj_release( &package->hdr );
4583 if (rc == ERROR_SUCCESS && strlenW(path) > *pcchPathBuf)
4585 *pcchPathBuf = strlenW(path)+1;
4586 return ERROR_MORE_DATA;
4588 else if (rc == ERROR_SUCCESS)
4590 *pcchPathBuf = strlenW(path)+1;
4591 strcpyW(szPathBuf,path);
4592 TRACE("Returning Path %s\n",debugstr_w(path));
4595 return rc;
4599 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
4600 LPCSTR szFolderPath)
4602 LPWSTR szwFolder;
4603 LPWSTR szwFolderPath;
4604 UINT rc;
4606 if (!szFolder)
4607 return ERROR_FUNCTION_FAILED;
4608 if (hInstall == 0)
4609 return ERROR_FUNCTION_FAILED;
4611 szwFolder = strdupAtoW(szFolder);
4612 if (!szwFolder)
4613 return ERROR_FUNCTION_FAILED;
4615 szwFolderPath = strdupAtoW(szFolderPath);
4616 if (!szwFolderPath)
4618 HeapFree(GetProcessHeap(),0,szwFolder);
4619 return ERROR_FUNCTION_FAILED;
4622 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
4624 HeapFree(GetProcessHeap(),0,szwFolder);
4625 HeapFree(GetProcessHeap(),0,szwFolderPath);
4627 return rc;
4630 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
4631 LPCWSTR szFolderPath)
4633 DWORD i;
4634 WCHAR path[MAX_PATH];
4635 MSIFOLDER *folder;
4637 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
4639 if (package==NULL)
4640 return ERROR_INVALID_HANDLE;
4642 if (szFolderPath[0]==0)
4643 return ERROR_FUNCTION_FAILED;
4645 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
4646 return ERROR_FUNCTION_FAILED;
4648 resolve_folder(package,szFolder,path,FALSE,FALSE,&folder);
4650 if (!folder)
4651 return ERROR_INVALID_PARAMETER;
4653 strcpyW(folder->Property,szFolderPath);
4655 for (i = 0; i < package->loaded_folders; i++)
4656 package->folders[i].ResolvedTarget[0]=0;
4658 for (i = 0; i < package->loaded_folders; i++)
4659 resolve_folder(package, package->folders[i].Directory, path, FALSE,
4660 TRUE, NULL);
4662 return ERROR_SUCCESS;
4665 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
4666 LPCWSTR szFolderPath)
4668 MSIPACKAGE *package;
4669 UINT ret;
4671 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
4673 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4674 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
4675 msiobj_release( &package->hdr );
4676 return ret;
4679 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, DWORD iRunMode)
4681 FIXME("STUB (%li)\n",iRunMode);
4682 return FALSE;
4686 * According to the docs, when this is called it immediately recalculates
4687 * all the component states as well
4689 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
4690 INSTALLSTATE iState)
4692 LPWSTR szwFeature = NULL;
4693 UINT rc;
4695 szwFeature = strdupAtoW(szFeature);
4697 if (!szwFeature)
4698 return ERROR_FUNCTION_FAILED;
4700 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
4702 HeapFree(GetProcessHeap(),0,szwFeature);
4704 return rc;
4707 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
4708 INSTALLSTATE iState)
4710 MSIPACKAGE* package;
4711 INT index;
4713 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
4715 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4716 if (!package)
4717 return ERROR_INVALID_HANDLE;
4719 index = get_loaded_feature(package,szFeature);
4720 if (index < 0)
4721 return ERROR_UNKNOWN_FEATURE;
4723 package->features[index].State = iState;
4725 return ERROR_SUCCESS;
4728 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
4729 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4731 LPWSTR szwFeature = NULL;
4732 UINT rc;
4734 szwFeature = strdupAtoW(szFeature);
4736 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
4738 HeapFree( GetProcessHeap(), 0 , szwFeature);
4740 return rc;
4743 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
4744 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4746 INT index;
4748 index = get_loaded_feature(package,szFeature);
4749 if (index < 0)
4750 return ERROR_UNKNOWN_FEATURE;
4752 if (piInstalled)
4753 *piInstalled = package->features[index].State;
4755 if (piAction)
4757 if (package->features[index].Enabled)
4758 *piAction = INSTALLSTATE_LOCAL;
4759 else
4760 *piAction = INSTALLSTATE_UNKNOWN;
4763 return ERROR_SUCCESS;
4766 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
4767 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4769 MSIPACKAGE* package;
4770 UINT ret;
4772 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
4773 piAction);
4775 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4776 if (!package)
4777 return ERROR_INVALID_HANDLE;
4778 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
4779 msiobj_release( &package->hdr );
4780 return ret;
4783 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
4784 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4786 LPWSTR szwComponent= NULL;
4787 UINT rc;
4789 szwComponent= strdupAtoW(szComponent);
4791 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
4793 HeapFree( GetProcessHeap(), 0 , szwComponent);
4795 return rc;
4798 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
4799 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4801 INT index;
4803 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
4804 piAction);
4806 index = get_loaded_component(package,szComponent);
4807 if (index < 0)
4808 return ERROR_UNKNOWN_COMPONENT;
4810 if (piInstalled)
4811 *piInstalled = package->components[index].State;
4813 if (piAction)
4815 if (package->components[index].Enabled &&
4816 package->components[index].FeatureState)
4817 *piAction = INSTALLSTATE_LOCAL;
4818 else
4819 *piAction = INSTALLSTATE_UNKNOWN;
4822 return ERROR_SUCCESS;
4825 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
4826 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
4828 MSIPACKAGE* package;
4829 UINT ret;
4831 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
4832 piInstalled, piAction);
4834 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
4835 if (!package)
4836 return ERROR_INVALID_HANDLE;
4837 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
4838 msiobj_release( &package->hdr );
4839 return ret;
4842 #if 0
4843 static UINT ACTION_Template(MSIPACKAGE *package)
4845 UINT rc;
4846 MSIQUERY * view;
4847 MSIRECORD * row = 0;
4848 static const WCHAR ExecSeqQuery[] = {0};
4850 rc = MsiDatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4851 if (rc != ERROR_SUCCESS)
4852 return rc;
4854 rc = MsiViewExecute(view, 0);
4855 if (rc != ERROR_SUCCESS)
4857 MsiViewClose(view);
4858 msiobj_release(&view->hdr);
4859 return rc;
4862 while (1)
4864 rc = MsiViewFetch(view,&row);
4865 if (rc != ERROR_SUCCESS)
4867 rc = ERROR_SUCCESS;
4868 break;
4871 msiobj_release(&row->hdr);
4873 MsiViewClose(view);
4874 msiobj_release(&view->hdr);
4875 return rc;
4877 #endif