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
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
38 #include "wine/debug.h"
42 #include "msvcrt/fcntl.h"
49 #include "wine/unicode.h"
52 #define CUSTOM_ACTION_TYPE_MASK 0x3F
53 #define REG_PROGRESS_VALUE 13200
54 #define COMPONENT_PROGRESS_VALUE 24000
56 WINE_DEFAULT_DEBUG_CHANNEL(msi);
58 typedef struct tagMSIFEATURE
61 WCHAR Feature_Parent[96];
63 WCHAR Description[0x100];
69 INSTALLSTATE Installed;
70 INSTALLSTATE ActionRequest;
74 INT Components[1024]; /* yes hardcoded limit.... I am bad */
78 typedef struct tagMSICOMPONENT
81 WCHAR ComponentId[96];
84 WCHAR Condition[0x100];
87 INSTALLSTATE Installed;
88 INSTALLSTATE ActionRequest;
95 typedef struct tagMSIFOLDER
101 LPWSTR ResolvedTarget;
102 LPWSTR ResolvedSource;
103 LPWSTR Property; /* initially set property */
106 /* 0 = uninitialized */
108 /* 2 = created remove if empty */
109 /* 3 = created persist if empty */
114 typedef struct tagMSIFILE
126 /* 0 = uninitialize */
127 /* 1 = not present */
128 /* 2 = present but replace */
129 /* 3 = present do not replace */
139 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran);
140 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package);
142 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq);
143 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action);
145 static UINT ACTION_LaunchConditions(MSIPACKAGE *package);
146 static UINT ACTION_CostInitialize(MSIPACKAGE *package);
147 static UINT ACTION_CreateFolders(MSIPACKAGE *package);
148 static UINT ACTION_CostFinalize(MSIPACKAGE *package);
149 static UINT ACTION_FileCost(MSIPACKAGE *package);
150 static UINT ACTION_InstallFiles(MSIPACKAGE *package);
151 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package);
152 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package);
153 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action);
154 static UINT ACTION_InstallInitialize(MSIPACKAGE *package);
155 static UINT ACTION_InstallValidate(MSIPACKAGE *package);
156 static UINT ACTION_ProcessComponents(MSIPACKAGE *package);
157 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package);
158 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package);
159 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package);
160 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package);
161 static UINT ACTION_PublishProduct(MSIPACKAGE *package);
162 static UINT ACTION_WriteIniValues(MSIPACKAGE *package);
164 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
165 const LPWSTR target, const INT type);
166 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
167 const LPWSTR target, const INT type);
168 static UINT HANDLE_CustomType18(MSIPACKAGE *package, const LPWSTR source,
169 const LPWSTR target, const INT type);
170 static UINT HANDLE_CustomType50(MSIPACKAGE *package, const LPWSTR source,
171 const LPWSTR target, const INT type);
172 static UINT HANDLE_CustomType34(MSIPACKAGE *package, const LPWSTR source,
173 const LPWSTR target, const INT type);
175 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data);
176 static LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name,
177 BOOL source, BOOL set_prop, MSIFOLDER **folder);
179 static int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path);
182 * consts and values used
184 static const WCHAR cszSourceDir[] = {'S','o','u','r','c','e','D','i','r',0};
185 static const WCHAR cszRootDrive[] = {'R','O','O','T','D','R','I','V','E',0};
186 static const WCHAR cszTargetDir[] = {'T','A','R','G','E','T','D','I','R',0};
187 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
188 static const WCHAR cszDatabase[]={'D','A','T','A','B','A','S','E',0};
189 static const WCHAR c_collen[] = {'C',':','\\',0};
191 static const WCHAR cszlsb[]={'[',0};
192 static const WCHAR cszrsb[]={']',0};
193 static const WCHAR cszbs[]={'\\',0};
195 const static WCHAR szCreateFolders[] =
196 {'C','r','e','a','t','e','F','o','l','d','e','r','s',0};
197 const static WCHAR szCostFinalize[] =
198 {'C','o','s','t','F','i','n','a','l','i','z','e',0};
199 const static WCHAR szInstallFiles[] =
200 {'I','n','s','t','a','l','l','F','i','l','e','s',0};
201 const static WCHAR szDuplicateFiles[] =
202 {'D','u','p','l','i','c','a','t','e','F','i','l','e','s',0};
203 const static WCHAR szWriteRegistryValues[] =
204 {'W','r','i','t','e','R','e','g','i','s','t','r','y','V','a','l','u','e','s',0};
205 const static WCHAR szCostInitialize[] =
206 {'C','o','s','t','I','n','i','t','i','a','l','i','z','e',0};
207 const static WCHAR szFileCost[] = {'F','i','l','e','C','o','s','t',0};
208 const static WCHAR szInstallInitialize[] =
209 {'I','n','s','t','a','l','l','I','n','i','t','i','a','l','i','z','e',0};
210 const static WCHAR szInstallValidate[] =
211 {'I','n','s','t','a','l','l','V','a','l','i','d','a','t','e',0};
212 const static WCHAR szLaunchConditions[] =
213 {'L','a','u','n','c','h','C','o','n','d','i','t','i','o','n','s',0};
214 const static WCHAR szProcessComponents[] =
215 {'P','r','o','c','e','s','s','C','o','m','p','o','n','e','n','t','s',0};
216 const static WCHAR szRegisterTypeLibraries[] =
217 {'R','e','g','i','s','t','e','r','T','y','p','e','L','i','b','r','a','r',
219 const static WCHAR szRegisterClassInfo[] =
220 {'R','e','g','i','s','t','e','r','C','l','a','s','s','I','n','f','o',0};
221 const static WCHAR szRegisterProgIdInfo[] =
222 {'R','e','g','i','s','t','e','r','P','r','o','g','I','d','I','n','f','o',0};
223 const static WCHAR szCreateShortcuts[] =
224 {'C','r','e','a','t','e','S','h','o','r','t','c','u','t','s',0};
225 const static WCHAR szPublishProduct[] =
226 {'P','u','b','l','i','s','h','P','r','o','d','u','c','t',0};
227 const static WCHAR szWriteIniValues[] =
228 {'W','r','i','t','e','I','n','i','V','a','l','u','e','s',0};
230 /********************************************************
231 * helper functions to get around current HACKS and such
232 ********************************************************/
233 inline static void reduce_to_longfilename(WCHAR* filename)
235 LPWSTR p = strchrW(filename,'|');
237 memmove(filename, p+1, (strlenW(p+1)+1)*sizeof(WCHAR));
240 inline static char *strdupWtoA( const WCHAR *str )
245 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL
247 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
248 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
253 inline static WCHAR *strdupAtoW( const char *str )
258 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
259 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
260 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
265 static LPWSTR dupstrW(LPCWSTR src)
268 if (!src) return NULL;
269 dest = HeapAlloc(GetProcessHeap(), 0, (strlenW(src)+1)*sizeof(WCHAR));
274 inline static WCHAR *load_dynamic_stringW(MSIRECORD *row, INT index)
281 if (MSI_RecordIsNull(row,index))
284 rc = MSI_RecordGetStringW(row,index,NULL,&sz);
286 /* having an empty string is different than NULL */
289 ret = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR));
295 ret = HeapAlloc(GetProcessHeap(),0,sz * sizeof (WCHAR));
296 rc = MSI_RecordGetStringW(row,index,ret,&sz);
297 if (rc!=ERROR_SUCCESS)
299 ERR("Unable to load dynamic string\n");
300 HeapFree(GetProcessHeap(), 0, ret);
306 inline static LPWSTR load_dynamic_property(MSIPACKAGE *package, LPCWSTR prop,
313 r = MSI_GetPropertyW(package, prop, NULL, &sz);
314 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
321 str = HeapAlloc(GetProcessHeap(),0,sz*sizeof(WCHAR));
322 r = MSI_GetPropertyW(package, prop, str, &sz);
323 if (r != ERROR_SUCCESS)
325 HeapFree(GetProcessHeap(),0,str);
333 inline static int get_loaded_component(MSIPACKAGE* package, LPCWSTR Component )
338 for (i = 0; i < package->loaded_components; i++)
340 if (strcmpW(Component,package->components[i].Component)==0)
349 inline static int get_loaded_feature(MSIPACKAGE* package, LPCWSTR Feature )
354 for (i = 0; i < package->loaded_features; i++)
356 if (strcmpW(Feature,package->features[i].Feature)==0)
365 inline static int get_loaded_file(MSIPACKAGE* package, LPCWSTR file)
370 for (i = 0; i < package->loaded_files; i++)
372 if (strcmpW(file,package->files[i].File)==0)
382 static int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path)
390 for (i=0; i < package->loaded_files; i++)
391 if (strcmpW(package->files[i].File,name)==0)
394 index = package->loaded_files;
395 package->loaded_files++;
396 if (package->loaded_files== 1)
397 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
399 package->files = HeapReAlloc(GetProcessHeap(),0,
400 package->files , package->loaded_files * sizeof(MSIFILE));
402 memset(&package->files[index],0,sizeof(MSIFILE));
404 package->files[index].File = dupstrW(name);
405 package->files[index].TargetPath = dupstrW(path);
406 package->files[index].Temporary = TRUE;
408 TRACE("Tracking tempfile (%s)\n",debugstr_w(package->files[index].File));
413 void ACTION_remove_tracked_tempfiles(MSIPACKAGE* package)
420 for (i = 0; i < package->loaded_files; i++)
422 if (package->files[i].Temporary)
424 TRACE("Cleaning up %s\n",debugstr_w(package->files[i].TargetPath));
425 DeleteFileW(package->files[i].TargetPath);
431 /* Called when the package is being closed */
432 extern void ACTION_free_package_structures( MSIPACKAGE* package)
436 TRACE("Freeing package action data\n");
438 /* No dynamic buffers in features */
439 if (package->features && package->loaded_features > 0)
440 HeapFree(GetProcessHeap(),0,package->features);
442 for (i = 0; i < package->loaded_folders; i++)
444 HeapFree(GetProcessHeap(),0,package->folders[i].Directory);
445 HeapFree(GetProcessHeap(),0,package->folders[i].TargetDefault);
446 HeapFree(GetProcessHeap(),0,package->folders[i].SourceDefault);
447 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
448 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedSource);
449 HeapFree(GetProcessHeap(),0,package->folders[i].Property);
451 if (package->folders && package->loaded_folders > 0)
452 HeapFree(GetProcessHeap(),0,package->folders);
454 /* no dynamic buffers in components */
455 if (package->components && package->loaded_components > 0)
456 HeapFree(GetProcessHeap(),0,package->components);
458 for (i = 0; i < package->loaded_files; i++)
460 HeapFree(GetProcessHeap(),0,package->files[i].File);
461 HeapFree(GetProcessHeap(),0,package->files[i].FileName);
462 HeapFree(GetProcessHeap(),0,package->files[i].Version);
463 HeapFree(GetProcessHeap(),0,package->files[i].Language);
464 HeapFree(GetProcessHeap(),0,package->files[i].SourcePath);
465 HeapFree(GetProcessHeap(),0,package->files[i].TargetPath);
468 if (package->files && package->loaded_files > 0)
469 HeapFree(GetProcessHeap(),0,package->files);
472 static UINT ACTION_OpenQuery( MSIDATABASE *db, MSIQUERY **view, LPCWSTR fmt, ... )
479 /* figure out how much space we need to allocate */
481 sz = strlenW(fmt) + 1;
491 case 's': /* a string */
492 sz += strlenW(va_arg(va,LPCWSTR));
495 case 'i': /* an integer -2147483648 seems to be longest */
497 (void)va_arg(va,int);
499 case '%': /* a single % - leave it alone */
502 FIXME("Unhandled character type %c\n",*p);
508 /* construct the string */
509 szQuery = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
511 vsnprintfW(szQuery, sz, fmt, va);
514 /* perform the query */
515 rc = MSI_DatabaseOpenViewW(db, szQuery, view);
516 HeapFree(GetProcessHeap(), 0, szQuery);
520 static void ui_progress(MSIPACKAGE *package, int a, int b, int c, int d )
524 row = MSI_CreateRecord(4);
525 MSI_RecordSetInteger(row,1,a);
526 MSI_RecordSetInteger(row,2,b);
527 MSI_RecordSetInteger(row,3,c);
528 MSI_RecordSetInteger(row,4,d);
529 MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
530 msiobj_release(&row->hdr);
533 static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
535 static const WCHAR Query_t[] =
536 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
537 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
538 ' ','\'','%','s','\'',0};
545 if (!package->LastAction || strcmpW(package->LastAction,action))
547 rc = ACTION_OpenQuery(package->db, &view, Query_t, action);
548 if (rc != ERROR_SUCCESS)
551 rc = MSI_ViewExecute(view, 0);
552 if (rc != ERROR_SUCCESS)
557 rc = MSI_ViewFetch(view,&row);
558 if (rc != ERROR_SUCCESS)
564 if (MSI_RecordIsNull(row,3))
566 msiobj_release(&row->hdr);
568 msiobj_release(&view->hdr);
572 /* update the cached actionformat */
573 if (package->ActionFormat)
574 HeapFree(GetProcessHeap(),0,package->ActionFormat);
575 package->ActionFormat = load_dynamic_stringW(row,3);
577 if (package->LastAction)
578 HeapFree(GetProcessHeap(),0,package->LastAction);
579 package->LastAction = dupstrW(action);
581 msiobj_release(&row->hdr);
583 msiobj_release(&view->hdr);
587 ptr = package->ActionFormat;
595 ptr2 = strchrW(ptr,'[');
598 strncpyW(tmp,ptr,ptr2-ptr);
600 strcatW(message,tmp);
603 data = load_dynamic_stringW(record,field);
606 strcatW(message,data);
607 HeapFree(GetProcessHeap(),0,data);
609 ptr=strchrW(ptr2,']');
614 strcatW(message,ptr);
619 row = MSI_CreateRecord(1);
620 MSI_RecordSetStringW(row,1,message);
622 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, row);
623 msiobj_release(&row->hdr);
627 static void ui_actionstart(MSIPACKAGE *package, LPCWSTR action)
629 static const WCHAR template_s[]=
630 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ','%','s','.',0};
631 static const WCHAR format[] =
632 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
633 static const WCHAR Query_t[] =
634 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','c','t','i','o',
635 'n','T','e','x','t',' ','w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',
636 ' ','\'','%','s','\'',0};
642 WCHAR *ActionText=NULL;
644 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
646 rc = ACTION_OpenQuery(package->db, &view, Query_t, action);
647 if (rc != ERROR_SUCCESS)
649 rc = MSI_ViewExecute(view, 0);
650 if (rc != ERROR_SUCCESS)
653 msiobj_release(&view->hdr);
656 rc = MSI_ViewFetch(view,&row);
657 if (rc != ERROR_SUCCESS)
660 msiobj_release(&view->hdr);
664 ActionText = load_dynamic_stringW(row,2);
665 msiobj_release(&row->hdr);
667 msiobj_release(&view->hdr);
669 sprintfW(message,template_s,timet,action,ActionText);
671 row = MSI_CreateRecord(1);
672 MSI_RecordSetStringW(row,1,message);
674 MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONSTART, row);
675 msiobj_release(&row->hdr);
676 HeapFree(GetProcessHeap(),0,ActionText);
679 static void ui_actioninfo(MSIPACKAGE *package, LPCWSTR action, BOOL start,
683 static const WCHAR template_s[]=
684 {'A','c','t','i','o','n',' ','s','t','a','r','t',' ','%','s',':',' ','%','s',
686 static const WCHAR template_e[]=
687 {'A','c','t','i','o','n',' ','e','n','d','e','d',' ','%','s',':',' ','%','s',
688 '.',' ','R','e','t','u','r','n',' ','v','a','l','u','e',' ','%','i','.',0};
689 static const WCHAR format[] =
690 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
694 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
696 sprintfW(message,template_s,timet,action);
698 sprintfW(message,template_e,timet,action,rc);
700 row = MSI_CreateRecord(1);
701 MSI_RecordSetStringW(row,1,message);
703 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO, row);
704 msiobj_release(&row->hdr);
708 * build_directory_name()
710 * This function is to save messing round with directory names
711 * It handles adding backslashes between path segments,
712 * and can add \ at the end of the directory name if told to.
714 * It takes a variable number of arguments.
715 * It always allocates a new string for the result, so make sure
716 * to free the return value when finished with it.
718 * The first arg is the number of path segments that follow.
719 * The arguments following count are a list of path segments.
720 * A path segment may be NULL.
722 * Path segments will be added with a \ separating them.
723 * A \ will not be added after the last segment, however if the
724 * last segment is NULL, then the last character will be a \
727 static LPWSTR build_directory_name(DWORD count, ...)
734 for(i=0; i<count; i++)
736 LPCWSTR str = va_arg(va,LPCWSTR);
738 sz += strlenW(str) + 1;
742 dir = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
746 for(i=0; i<count; i++)
748 LPCWSTR str = va_arg(va,LPCWSTR);
752 if( ((i+1)!=count) && dir[strlenW(dir)-1]!='\\')
759 /****************************************************
760 * TOP level entry points
761 *****************************************************/
763 UINT ACTION_DoTopLevelINSTALL(MSIPACKAGE *package, LPCWSTR szPackagePath,
764 LPCWSTR szCommandLine)
769 static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
773 LPWSTR p, check, path;
775 path = dupstrW(szPackagePath);
776 p = strrchrW(path,'\\');
783 check = load_dynamic_property(package, cszSourceDir,NULL);
785 MSI_SetPropertyW(package, cszSourceDir, path);
787 HeapFree(GetProcessHeap(), 0, check);
789 HeapFree(GetProcessHeap(), 0, path);
795 ptr = (LPWSTR)szCommandLine;
802 TRACE("Looking at %s\n",debugstr_w(ptr));
804 ptr2 = strchrW(ptr,'=');
810 while (*ptr == ' ') ptr++;
812 prop = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
813 strncpyW(prop,ptr,len);
819 while (*ptr && (quote || (!quote && *ptr!=' ')))
832 val = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
833 strncpyW(val,ptr2,len);
836 if (strlenW(prop) > 0)
838 TRACE("Found commandline property (%s) = (%s)\n",
839 debugstr_w(prop), debugstr_w(val));
840 MSI_SetPropertyW(package,prop,val);
842 HeapFree(GetProcessHeap(),0,val);
843 HeapFree(GetProcessHeap(),0,prop);
850 if (MSI_GetPropertyW(package,szUILevel,buffer,&sz) == ERROR_SUCCESS)
852 if (atoiW(buffer) >= INSTALLUILEVEL_REDUCED)
854 rc = ACTION_ProcessUISequence(package);
855 if (rc == ERROR_SUCCESS)
856 rc = ACTION_ProcessExecSequence(package,TRUE);
859 rc = ACTION_ProcessExecSequence(package,FALSE);
862 rc = ACTION_ProcessExecSequence(package,FALSE);
864 /* process the ending type action */
865 if (rc == ERROR_SUCCESS)
866 rc = ACTION_PerformActionSequence(package,-1);
867 else if (rc == ERROR_FUNCTION_FAILED)
868 rc = ACTION_PerformActionSequence(package,-3);
873 static UINT ACTION_PerformActionSequence(MSIPACKAGE *package, UINT seq)
880 static const WCHAR ExecSeqQuery[] = {
881 's','e','l','e','c','t',' ','*',' ',
883 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
884 'S','e','q','u','e','n','c','e',' ',
885 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
888 rc = ACTION_OpenQuery(package->db, &view, ExecSeqQuery, seq);
890 if (rc == ERROR_SUCCESS)
892 rc = MSI_ViewExecute(view, 0);
894 if (rc != ERROR_SUCCESS)
897 msiobj_release(&view->hdr);
901 TRACE("Running the actions\n");
903 rc = MSI_ViewFetch(view,&row);
904 if (rc != ERROR_SUCCESS)
910 /* check conditions */
911 if (!MSI_RecordIsNull(row,2))
914 cond = load_dynamic_stringW(row,2);
918 /* this is a hack to skip errors in the condition code */
919 if (MSI_EvaluateConditionW(package, cond) == MSICONDITION_FALSE)
921 HeapFree(GetProcessHeap(),0,cond);
922 msiobj_release(&row->hdr);
926 HeapFree(GetProcessHeap(),0,cond);
931 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
932 if (rc != ERROR_SUCCESS)
934 ERR("Error is %x\n",rc);
935 msiobj_release(&row->hdr);
939 rc = ACTION_PerformAction(package,buffer);
940 msiobj_release(&row->hdr);
943 msiobj_release(&view->hdr);
951 static UINT ACTION_ProcessExecSequence(MSIPACKAGE *package, BOOL UIran)
955 static const WCHAR ExecSeqQuery[] = {
956 's','e','l','e','c','t',' ','*',' ',
958 'I','n','s','t','a','l','l','E','x','e','c','u','t','e',
959 'S','e','q','u','e','n','c','e',' ',
960 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ',
961 '>',' ','%','i',' ','o','r','d','e','r',' ',
962 'b','y',' ','S','e','q','u','e','n','c','e',0 };
964 static const WCHAR IVQuery[] = {
965 's','e','l','e','c','t',' ','S','e','q','u','e','n','c','e',' ',
966 'f','r','o','m',' ','I','n','s','t','a','l','l',
967 'E','x','e','c','u','t','e','S','e','q','u','e','n','c','e',' ',
968 'w','h','e','r','e',' ','A','c','t','i','o','n',' ','=',' ',
969 '`','I','n','s','t','a','l','l','V','a','l','i','d','a','t','e','`',
973 /* get the sequence number */
976 rc = MSI_DatabaseOpenViewW(package->db, IVQuery, &view);
977 if (rc != ERROR_SUCCESS)
979 rc = MSI_ViewExecute(view, 0);
980 if (rc != ERROR_SUCCESS)
983 msiobj_release(&view->hdr);
986 rc = MSI_ViewFetch(view,&row);
987 if (rc != ERROR_SUCCESS)
990 msiobj_release(&view->hdr);
993 seq = MSI_RecordGetInteger(row,1);
994 msiobj_release(&row->hdr);
996 msiobj_release(&view->hdr);
999 rc = ACTION_OpenQuery(package->db, &view, ExecSeqQuery, seq);
1000 if (rc == ERROR_SUCCESS)
1002 rc = MSI_ViewExecute(view, 0);
1004 if (rc != ERROR_SUCCESS)
1006 MSI_ViewClose(view);
1007 msiobj_release(&view->hdr);
1011 TRACE("Running the actions\n");
1015 WCHAR buffer[0x100];
1018 rc = MSI_ViewFetch(view,&row);
1019 if (rc != ERROR_SUCCESS)
1025 /* check conditions */
1026 if (!MSI_RecordIsNull(row,2))
1029 cond = load_dynamic_stringW(row,2);
1033 /* this is a hack to skip errors in the condition code */
1034 if (MSI_EvaluateConditionW(package, cond) ==
1037 HeapFree(GetProcessHeap(),0,cond);
1038 msiobj_release(&row->hdr);
1042 HeapFree(GetProcessHeap(),0,cond);
1047 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1048 if (rc != ERROR_SUCCESS)
1050 ERR("Error is %x\n",rc);
1051 msiobj_release(&row->hdr);
1055 rc = ACTION_PerformAction(package,buffer);
1057 if (rc == ERROR_FUNCTION_NOT_CALLED)
1060 if (rc != ERROR_SUCCESS)
1062 ERR("Execution halted due to error (%i)\n",rc);
1063 msiobj_release(&row->hdr);
1067 msiobj_release(&row->hdr);
1070 MSI_ViewClose(view);
1071 msiobj_release(&view->hdr);
1079 static UINT ACTION_ProcessUISequence(MSIPACKAGE *package)
1083 static const WCHAR ExecSeqQuery [] = {
1084 's','e','l','e','c','t',' ','*',' ',
1085 'f','r','o','m',' ','I','n','s','t','a','l','l',
1086 'U','I','S','e','q','u','e','n','c','e',' ',
1087 'w','h','e','r','e',' ','S','e','q','u','e','n','c','e',' ', '>',' ','0',' ',
1088 'o','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e',0};
1090 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
1092 if (rc == ERROR_SUCCESS)
1094 rc = MSI_ViewExecute(view, 0);
1096 if (rc != ERROR_SUCCESS)
1098 MSI_ViewClose(view);
1099 msiobj_release(&view->hdr);
1103 TRACE("Running the actions \n");
1107 WCHAR buffer[0x100];
1109 MSIRECORD * row = 0;
1111 rc = MSI_ViewFetch(view,&row);
1112 if (rc != ERROR_SUCCESS)
1118 /* check conditions */
1119 if (!MSI_RecordIsNull(row,2))
1122 cond = load_dynamic_stringW(row,2);
1126 /* this is a hack to skip errors in the condition code */
1127 if (MSI_EvaluateConditionW(package, cond) ==
1130 HeapFree(GetProcessHeap(),0,cond);
1131 msiobj_release(&row->hdr);
1135 HeapFree(GetProcessHeap(),0,cond);
1140 rc = MSI_RecordGetStringW(row,1,buffer,&sz);
1141 if (rc != ERROR_SUCCESS)
1143 ERR("Error is %x\n",rc);
1144 msiobj_release(&row->hdr);
1148 rc = ACTION_PerformAction(package,buffer);
1150 if (rc == ERROR_FUNCTION_NOT_CALLED)
1153 if (rc != ERROR_SUCCESS)
1155 ERR("Execution halted due to error (%i)\n",rc);
1156 msiobj_release(&row->hdr);
1160 msiobj_release(&row->hdr);
1163 MSI_ViewClose(view);
1164 msiobj_release(&view->hdr);
1171 /********************************************************
1172 * ACTION helper functions and functions that perform the actions
1173 *******************************************************/
1176 * Alot of actions are really important even if they don't do anything
1177 * explicit.. Lots of properties are set at the beginning of the installation
1178 * CostFinalize does a bunch of work to translated the directories and such
1180 * But until I get write access to the database that is hard, so I am going to
1181 * hack it to see if I can get something to run.
1183 UINT ACTION_PerformAction(MSIPACKAGE *package, const WCHAR *action)
1185 UINT rc = ERROR_SUCCESS;
1187 TRACE("Performing action (%s)\n",debugstr_w(action));
1188 ui_actioninfo(package, action, TRUE, 0);
1189 ui_actionstart(package, action);
1191 /* pre install, setup and configuration block */
1192 if (strcmpW(action,szLaunchConditions)==0)
1193 rc = ACTION_LaunchConditions(package);
1194 else if (strcmpW(action,szCostInitialize)==0)
1195 rc = ACTION_CostInitialize(package);
1196 else if (strcmpW(action,szFileCost)==0)
1197 rc = ACTION_FileCost(package);
1198 else if (strcmpW(action,szCostFinalize)==0)
1199 rc = ACTION_CostFinalize(package);
1200 else if (strcmpW(action,szInstallValidate)==0)
1201 rc = ACTION_InstallValidate(package);
1204 else if (strcmpW(action,szProcessComponents)==0)
1205 rc = ACTION_ProcessComponents(package);
1206 else if (strcmpW(action,szInstallInitialize)==0)
1207 rc = ACTION_InstallInitialize(package);
1208 else if (strcmpW(action,szCreateFolders)==0)
1209 rc = ACTION_CreateFolders(package);
1210 else if (strcmpW(action,szInstallFiles)==0)
1211 rc = ACTION_InstallFiles(package);
1212 else if (strcmpW(action,szDuplicateFiles)==0)
1213 rc = ACTION_DuplicateFiles(package);
1214 else if (strcmpW(action,szWriteRegistryValues)==0)
1215 rc = ACTION_WriteRegistryValues(package);
1216 else if (strcmpW(action,szRegisterTypeLibraries)==0)
1217 rc = ACTION_RegisterTypeLibraries(package);
1218 else if (strcmpW(action,szRegisterClassInfo)==0)
1219 rc = ACTION_RegisterClassInfo(package);
1220 else if (strcmpW(action,szRegisterProgIdInfo)==0)
1221 rc = ACTION_RegisterProgIdInfo(package);
1222 else if (strcmpW(action,szCreateShortcuts)==0)
1223 rc = ACTION_CreateShortcuts(package);
1224 else if (strcmpW(action,szPublishProduct)==0)
1225 rc = ACTION_PublishProduct(package);
1226 else if (strcmpW(action,szWriteIniValues)==0)
1227 rc = ACTION_WriteIniValues(package);
1230 Called during iTunes but unimplemented and seem important
1232 ResolveSource (sets SourceDir)
1236 else if ((rc = ACTION_CustomAction(package,action)) != ERROR_SUCCESS)
1238 FIXME("UNHANDLED MSI ACTION %s\n",debugstr_w(action));
1239 rc = ERROR_FUNCTION_NOT_CALLED;
1242 ui_actioninfo(package, action, FALSE, rc);
1247 static UINT ACTION_CustomAction(MSIPACKAGE *package,const WCHAR *action)
1249 UINT rc = ERROR_SUCCESS;
1251 MSIRECORD * row = 0;
1252 static const WCHAR ExecSeqQuery[] =
1253 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','C','u','s','t','o'
1254 ,'m','A','c','t','i','o','n',' ','w','h','e','r','e',' ','`','A','c','t','i'
1255 ,'o','n','`',' ','=',' ','`','%','s','`',0};
1259 WCHAR *deformated=NULL;
1261 rc = ACTION_OpenQuery(package->db, &view, ExecSeqQuery, action);
1262 if (rc != ERROR_SUCCESS)
1265 rc = MSI_ViewExecute(view, 0);
1266 if (rc != ERROR_SUCCESS)
1268 MSI_ViewClose(view);
1269 msiobj_release(&view->hdr);
1273 rc = MSI_ViewFetch(view,&row);
1274 if (rc != ERROR_SUCCESS)
1276 MSI_ViewClose(view);
1277 msiobj_release(&view->hdr);
1281 type = MSI_RecordGetInteger(row,2);
1283 source = load_dynamic_stringW(row,3);
1284 target = load_dynamic_stringW(row,4);
1286 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
1287 debugstr_w(source), debugstr_w(target));
1289 /* we are ignoring ALOT of flags and important synchronization stuff */
1290 switch (type & CUSTOM_ACTION_TYPE_MASK)
1292 case 1: /* DLL file stored in a Binary table stream */
1293 rc = HANDLE_CustomType1(package,source,target,type);
1295 case 2: /* EXE file stored in a Binary table strem */
1296 rc = HANDLE_CustomType2(package,source,target,type);
1298 case 18: /*EXE file installed with package */
1299 rc = HANDLE_CustomType18(package,source,target,type);
1301 case 50: /*EXE file specified by a property value */
1302 rc = HANDLE_CustomType50(package,source,target,type);
1304 case 34: /*EXE to be run in specified directory */
1305 rc = HANDLE_CustomType34(package,source,target,type);
1307 case 35: /* Directory set with formatted text. */
1308 deformat_string(package,target,&deformated);
1309 MSI_SetTargetPathW(package, source, deformated);
1310 HeapFree(GetProcessHeap(),0,deformated);
1312 case 51: /* Property set with formatted text. */
1313 deformat_string(package,target,&deformated);
1314 rc = MSI_SetPropertyW(package,source,deformated);
1315 HeapFree(GetProcessHeap(),0,deformated);
1318 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
1319 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
1320 debugstr_w(target));
1323 HeapFree(GetProcessHeap(),0,source);
1324 HeapFree(GetProcessHeap(),0,target);
1325 msiobj_release(&row->hdr);
1326 MSI_ViewClose(view);
1327 msiobj_release(&view->hdr);
1331 static UINT store_binary_to_temp(MSIPACKAGE *package, const LPWSTR source,
1336 if (MSI_GetPropertyW(package, cszTempFolder, tmp_file, &sz)
1338 GetTempPathW(MAX_PATH,tmp_file);
1340 strcatW(tmp_file,source);
1342 if (GetFileAttributesW(tmp_file) != INVALID_FILE_ATTRIBUTES)
1344 TRACE("File already exists\n");
1345 return ERROR_SUCCESS;
1349 /* write out the file */
1352 MSIRECORD * row = 0;
1353 static const WCHAR fmt[] =
1354 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','B','i'
1355 ,'n','a','r','y',' ','w','h','e','r','e',' ','N','a','m','e','=','`','%','s','`',0};
1359 if (track_tempfile(package, source, tmp_file)!=0)
1360 FIXME("File Name in temp tracking collision\n");
1362 the_file = CreateFileW(tmp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1363 FILE_ATTRIBUTE_NORMAL, NULL);
1365 if (the_file == INVALID_HANDLE_VALUE)
1366 return ERROR_FUNCTION_FAILED;
1368 rc = ACTION_OpenQuery(package->db, &view, fmt, source);
1369 if (rc != ERROR_SUCCESS)
1372 rc = MSI_ViewExecute(view, 0);
1373 if (rc != ERROR_SUCCESS)
1375 MSI_ViewClose(view);
1376 msiobj_release(&view->hdr);
1380 rc = MSI_ViewFetch(view,&row);
1381 if (rc != ERROR_SUCCESS)
1383 MSI_ViewClose(view);
1384 msiobj_release(&view->hdr);
1392 rc = MSI_RecordReadStream(row,2,buffer,&sz);
1393 if (rc != ERROR_SUCCESS)
1395 ERR("Failed to get stream\n");
1396 CloseHandle(the_file);
1397 DeleteFileW(tmp_file);
1400 WriteFile(the_file,buffer,sz,&write,NULL);
1401 } while (sz == 1024);
1403 CloseHandle(the_file);
1405 msiobj_release(&row->hdr);
1406 MSI_ViewClose(view);
1407 msiobj_release(&view->hdr);
1410 return ERROR_SUCCESS;
1413 typedef UINT __stdcall CustomEntry(MSIHANDLE);
1416 MSIPACKAGE *package;
1421 static DWORD WINAPI ACTION_CallDllFunction(thread_struct *stuff)
1427 TRACE("calling function (%s, %s) \n", debugstr_w(stuff->source),
1428 debugstr_w(stuff->target));
1430 hModule = LoadLibraryW(stuff->source);
1433 proc = strdupWtoA( stuff->target );
1434 fn = (CustomEntry*)GetProcAddress(hModule,proc);
1438 MSIPACKAGE *package = stuff->package;
1440 TRACE("Calling function %s\n", proc);
1441 hPackage = msiobj_findhandle( &package->hdr );
1445 msiobj_release( &package->hdr );
1448 ERR("Handle for object %p not found\n", package );
1451 ERR("Cannot load functon\n");
1453 HeapFree(GetProcessHeap(),0,proc);
1454 FreeLibrary(hModule);
1457 ERR("Unable to load library\n");
1458 msiobj_release( &stuff->package->hdr );
1459 HeapFree(GetProcessHeap(),0,stuff->source);
1460 HeapFree(GetProcessHeap(),0,stuff->target);
1461 HeapFree(GetProcessHeap(), 0, stuff);
1465 static DWORD WINAPI DllThread(LPVOID info)
1467 thread_struct *stuff;
1470 TRACE("MSI Thread (0x%lx) started for custom action\n",
1471 GetCurrentThreadId());
1473 stuff = (thread_struct*)info;
1474 rc = ACTION_CallDllFunction(stuff);
1476 TRACE("MSI Thread (0x%lx) finished\n",GetCurrentThreadId());
1477 /* clse all handles for this thread */
1478 MsiCloseAllHandles();
1482 static UINT HANDLE_CustomType1(MSIPACKAGE *package, const LPWSTR source,
1483 const LPWSTR target, const INT type)
1485 WCHAR tmp_file[MAX_PATH];
1486 thread_struct *info;
1488 HANDLE ThreadHandle;
1490 store_binary_to_temp(package, source, tmp_file);
1492 TRACE("Calling function %s from %s\n",debugstr_w(target),
1493 debugstr_w(tmp_file));
1495 if (!strchrW(tmp_file,'.'))
1497 static const WCHAR dot[]={'.',0};
1498 strcatW(tmp_file,dot);
1501 info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info) );
1502 msiobj_addref( &package->hdr );
1503 info->package = package;
1504 info->target = dupstrW(target);
1505 info->source = dupstrW(tmp_file);
1507 ThreadHandle = CreateThread(NULL,0,DllThread,(LPVOID)info,0,&ThreadId);
1510 WaitForSingleObject(ThreadHandle,INFINITE);
1512 CloseHandle(ThreadHandle);
1514 return ERROR_SUCCESS;
1517 static UINT HANDLE_CustomType2(MSIPACKAGE *package, const LPWSTR source,
1518 const LPWSTR target, const INT type)
1520 WCHAR tmp_file[MAX_PATH];
1522 PROCESS_INFORMATION info;
1527 static const WCHAR spc[] = {' ',0};
1529 memset(&si,0,sizeof(STARTUPINFOW));
1531 store_binary_to_temp(package, source, tmp_file);
1533 deformat_string(package,target,&deformated);
1535 len = strlenW(tmp_file)+2;
1538 len += strlenW(deformated);
1540 cmd = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*len);
1542 strcpyW(cmd,tmp_file);
1546 strcatW(cmd,deformated);
1548 HeapFree(GetProcessHeap(),0,deformated);
1551 TRACE("executing exe %s \n",debugstr_w(cmd));
1553 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1554 c_collen, &si, &info);
1556 HeapFree(GetProcessHeap(),0,cmd);
1560 ERR("Unable to execute command\n");
1561 return ERROR_SUCCESS;
1565 WaitForSingleObject(info.hProcess,INFINITE);
1567 CloseHandle( info.hProcess );
1568 CloseHandle( info.hThread );
1569 return ERROR_SUCCESS;
1572 static UINT HANDLE_CustomType18(MSIPACKAGE *package, const LPWSTR source,
1573 const LPWSTR target, const INT type)
1576 PROCESS_INFORMATION info;
1581 static const WCHAR spc[] = {' ',0};
1584 memset(&si,0,sizeof(STARTUPINFOW));
1586 index = get_loaded_file(package,source);
1588 len = strlenW(package->files[index].TargetPath);
1590 deformat_string(package,target,&deformated);
1592 len += strlenW(deformated);
1595 cmd = (WCHAR*)HeapAlloc(GetProcessHeap(),0,len * sizeof(WCHAR));
1597 strcpyW(cmd, package->files[index].TargetPath);
1601 strcatW(cmd, deformated);
1603 HeapFree(GetProcessHeap(),0,deformated);
1606 TRACE("executing exe %s \n",debugstr_w(cmd));
1608 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1609 c_collen, &si, &info);
1611 HeapFree(GetProcessHeap(),0,cmd);
1615 ERR("Unable to execute command\n");
1616 return ERROR_SUCCESS;
1620 WaitForSingleObject(info.hProcess,INFINITE);
1622 CloseHandle( info.hProcess );
1623 CloseHandle( info.hThread );
1624 return ERROR_SUCCESS;
1627 static UINT HANDLE_CustomType50(MSIPACKAGE *package, const LPWSTR source,
1628 const LPWSTR target, const INT type)
1631 PROCESS_INFORMATION info;
1638 static const WCHAR spc[] = {' ',0};
1640 memset(&si,0,sizeof(STARTUPINFOW));
1641 memset(&info,0,sizeof(PROCESS_INFORMATION));
1643 prop = load_dynamic_property(package,source,&prc);
1647 deformat_string(package,target,&deformated);
1648 len = strlenW(prop) + 2;
1650 len += strlenW(deformated);
1652 cmd = (WCHAR*)HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*len);
1658 strcatW(cmd,deformated);
1660 HeapFree(GetProcessHeap(),0,deformated);
1663 TRACE("executing exe %s \n",debugstr_w(cmd));
1665 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1666 c_collen, &si, &info);
1668 HeapFree(GetProcessHeap(),0,cmd);
1672 ERR("Unable to execute command\n");
1673 return ERROR_SUCCESS;
1677 WaitForSingleObject(info.hProcess,INFINITE);
1679 CloseHandle( info.hProcess );
1680 CloseHandle( info.hThread );
1681 return ERROR_SUCCESS;
1684 static UINT HANDLE_CustomType34(MSIPACKAGE *package, const LPWSTR source,
1685 const LPWSTR target, const INT type)
1687 LPWSTR filename, deformated;
1689 PROCESS_INFORMATION info;
1692 memset(&si,0,sizeof(STARTUPINFOW));
1694 filename = resolve_folder(package, source, FALSE, FALSE, NULL);
1697 return ERROR_FUNCTION_FAILED;
1699 SetCurrentDirectoryW(filename);
1700 HeapFree(GetProcessHeap(),0,filename);
1702 deformat_string(package,target,&deformated);
1705 return ERROR_FUNCTION_FAILED;
1707 TRACE("executing exe %s \n",debugstr_w(deformated));
1709 rc = CreateProcessW(NULL, deformated, NULL, NULL, FALSE, 0, NULL,
1710 c_collen, &si, &info);
1711 HeapFree(GetProcessHeap(),0,deformated);
1715 ERR("Unable to execute command\n");
1716 return ERROR_SUCCESS;
1720 WaitForSingleObject(info.hProcess,INFINITE);
1722 CloseHandle( info.hProcess );
1723 CloseHandle( info.hThread );
1724 return ERROR_SUCCESS;
1727 /***********************************************************************
1730 * Recursively create all directories in the path.
1732 * shamelessly stolen from setupapi/queue.c
1734 static BOOL create_full_pathW(const WCHAR *path)
1740 new_path = HeapAlloc(GetProcessHeap(), 0, (strlenW(path) + 1) *
1743 strcpyW(new_path, path);
1745 while((len = strlenW(new_path)) && new_path[len - 1] == '\\')
1746 new_path[len - 1] = 0;
1748 while(!CreateDirectoryW(new_path, NULL))
1751 DWORD last_error = GetLastError();
1752 if(last_error == ERROR_ALREADY_EXISTS)
1755 if(last_error != ERROR_PATH_NOT_FOUND)
1761 if(!(slash = strrchrW(new_path, '\\')))
1767 len = slash - new_path;
1769 if(!create_full_pathW(new_path))
1774 new_path[len] = '\\';
1777 HeapFree(GetProcessHeap(), 0, new_path);
1782 * Also we cannot enable/disable components either, so for now I am just going
1783 * to do all the directories for all the components.
1785 static UINT ACTION_CreateFolders(MSIPACKAGE *package)
1787 static const WCHAR ExecSeqQuery[] = {
1788 's','e','l','e','c','t',' ','D','i','r','e','c','t','o','r','y','_',' ',
1789 'f','r','o','m',' ','C','r','e','a','t','e','F','o','l','d','e','r',0 };
1794 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view );
1795 if (rc != ERROR_SUCCESS)
1796 return ERROR_SUCCESS;
1798 rc = MSI_ViewExecute(view, 0);
1799 if (rc != ERROR_SUCCESS)
1801 MSI_ViewClose(view);
1802 msiobj_release(&view->hdr);
1811 MSIRECORD *row = NULL, *uirow;
1813 rc = MSI_ViewFetch(view,&row);
1814 if (rc != ERROR_SUCCESS)
1821 rc = MSI_RecordGetStringW(row,1,dir,&sz);
1823 if (rc!= ERROR_SUCCESS)
1825 ERR("Unable to get folder id \n");
1826 msiobj_release(&row->hdr);
1831 full_path = resolve_folder(package,dir,FALSE,FALSE,&folder);
1834 ERR("Unable to resolve folder id %s\n",debugstr_w(dir));
1835 msiobj_release(&row->hdr);
1839 TRACE("Folder is %s\n",debugstr_w(full_path));
1842 uirow = MSI_CreateRecord(1);
1843 MSI_RecordSetStringW(uirow,1,full_path);
1844 ui_actiondata(package,szCreateFolders,uirow);
1845 msiobj_release( &uirow->hdr );
1847 if (folder->State == 0)
1848 create_full_pathW(full_path);
1852 msiobj_release(&row->hdr);
1853 HeapFree(GetProcessHeap(),0,full_path);
1855 MSI_ViewClose(view);
1856 msiobj_release(&view->hdr);
1861 static int load_component(MSIPACKAGE* package, MSIRECORD * row)
1863 int index = package->loaded_components;
1866 /* fill in the data */
1868 package->loaded_components++;
1869 if (package->loaded_components == 1)
1870 package->components = HeapAlloc(GetProcessHeap(),0,
1871 sizeof(MSICOMPONENT));
1873 package->components = HeapReAlloc(GetProcessHeap(),0,
1874 package->components, package->loaded_components *
1875 sizeof(MSICOMPONENT));
1877 memset(&package->components[index],0,sizeof(MSICOMPONENT));
1880 MSI_RecordGetStringW(row,1,package->components[index].Component,&sz);
1882 TRACE("Loading Component %s\n",
1883 debugstr_w(package->components[index].Component));
1886 if (!MSI_RecordIsNull(row,2))
1887 MSI_RecordGetStringW(row,2,package->components[index].ComponentId,&sz);
1890 MSI_RecordGetStringW(row,3,package->components[index].Directory,&sz);
1892 package->components[index].Attributes = MSI_RecordGetInteger(row,4);
1895 MSI_RecordGetStringW(row,5,package->components[index].Condition,&sz);
1898 MSI_RecordGetStringW(row,6,package->components[index].KeyPath,&sz);
1900 package->components[index].Installed = INSTALLSTATE_ABSENT;
1901 package->components[index].Action = INSTALLSTATE_UNKNOWN;
1902 package->components[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1904 package->components[index].Enabled = TRUE;
1909 static void load_feature(MSIPACKAGE* package, MSIRECORD * row)
1911 int index = package->loaded_features;
1913 static const WCHAR Query1[] = {'S','E','L','E','C','T',' ','C','o','m','p',
1914 'o','n','e','n','t','_',' ','F','R','O','M',' ','F','e','a','t','u','r','e',
1915 'C','o','m','p','o','n','e','n','t','s',' ','W','H','E','R','E',' ','F','e',
1916 'a','t','u','r','e','_','=','\'','%','s','\'',0};
1917 static const WCHAR Query2[] = {'S','E','L','E','C','T',' ','*',' ','F','R',
1918 'O','M',' ','C','o','m','p','o','n','e','n','t',' ','W','H','E','R','E',' ','C',
1919 'o','m','p','o','n','e','n','t','=','\'','%','s','\'',0};
1926 /* fill in the data */
1928 package->loaded_features ++;
1929 if (package->loaded_features == 1)
1930 package->features = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFEATURE));
1932 package->features = HeapReAlloc(GetProcessHeap(),0,package->features,
1933 package->loaded_features * sizeof(MSIFEATURE));
1935 memset(&package->features[index],0,sizeof(MSIFEATURE));
1938 MSI_RecordGetStringW(row,1,package->features[index].Feature,&sz);
1940 TRACE("Loading feature %s\n",debugstr_w(package->features[index].Feature));
1943 if (!MSI_RecordIsNull(row,2))
1944 MSI_RecordGetStringW(row,2,package->features[index].Feature_Parent,&sz);
1947 if (!MSI_RecordIsNull(row,3))
1948 MSI_RecordGetStringW(row,3,package->features[index].Title,&sz);
1951 if (!MSI_RecordIsNull(row,4))
1952 MSI_RecordGetStringW(row,4,package->features[index].Description,&sz);
1954 if (!MSI_RecordIsNull(row,5))
1955 package->features[index].Display = MSI_RecordGetInteger(row,5);
1957 package->features[index].Level= MSI_RecordGetInteger(row,6);
1960 if (!MSI_RecordIsNull(row,7))
1961 MSI_RecordGetStringW(row,7,package->features[index].Directory,&sz);
1963 package->features[index].Attributes= MSI_RecordGetInteger(row,8);
1965 package->features[index].Installed = INSTALLSTATE_ABSENT;
1966 package->features[index].Action = INSTALLSTATE_UNKNOWN;
1967 package->features[index].ActionRequest = INSTALLSTATE_UNKNOWN;
1969 /* load feature components */
1971 rc = ACTION_OpenQuery(package->db, &view, Query1, package->features[index].Feature);
1972 if (rc != ERROR_SUCCESS)
1974 rc = MSI_ViewExecute(view,0);
1975 if (rc != ERROR_SUCCESS)
1977 MSI_ViewClose(view);
1978 msiobj_release(&view->hdr);
1984 WCHAR buffer[0x100];
1987 INT cnt = package->features[index].ComponentCount;
1989 rc = MSI_ViewFetch(view,&row2);
1990 if (rc != ERROR_SUCCESS)
1994 MSI_RecordGetStringW(row2,1,buffer,&sz);
1996 /* check to see if the component is already loaded */
1997 c_indx = get_loaded_component(package,buffer);
2000 TRACE("Component %s already loaded at %i\n", debugstr_w(buffer),
2002 package->features[index].Components[cnt] = c_indx;
2003 package->features[index].ComponentCount ++;
2007 rc = ACTION_OpenQuery(package->db, &view2, Query2, buffer);
2008 if (rc != ERROR_SUCCESS)
2010 msiobj_release( &row2->hdr );
2013 rc = MSI_ViewExecute(view2,0);
2014 if (rc != ERROR_SUCCESS)
2016 msiobj_release( &row2->hdr );
2017 MSI_ViewClose(view2);
2018 msiobj_release( &view2->hdr );
2025 rc = MSI_ViewFetch(view2,&row3);
2026 if (rc != ERROR_SUCCESS)
2028 c_indx = load_component(package,row3);
2029 msiobj_release( &row3->hdr );
2031 package->features[index].Components[cnt] = c_indx;
2032 package->features[index].ComponentCount ++;
2033 TRACE("Loaded new component to index %i\n",c_indx);
2035 MSI_ViewClose(view2);
2036 msiobj_release( &view2->hdr );
2037 msiobj_release( &row2->hdr );
2039 MSI_ViewClose(view);
2040 msiobj_release(&view->hdr);
2044 * I am not doing any of the costing functionality yet.
2045 * Mostly looking at doing the Component and Feature loading
2047 * The native MSI does ALOT of modification to tables here. Mostly adding alot
2048 * of temporary columns to the Feature and Component tables.
2050 * note: native msi also tracks the short filename. but I am only going to
2051 * track the long ones. Also looking at this directory table
2052 * it appears that the directory table does not get the parents
2053 * resolved base on property only based on their entrys in the
2056 static UINT ACTION_CostInitialize(MSIPACKAGE *package)
2061 static const WCHAR Query_all[] = {
2062 'S','E','L','E','C','T',' ','*',' ',
2063 'F','R','O','M',' ','F','e','a','t','u','r','e',0};
2064 static const WCHAR szCosting[] = {
2065 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2066 static const WCHAR szZero[] = { '0', 0 };
2068 MSI_SetPropertyW(package, szCosting, szZero);
2069 MSI_SetPropertyW(package, cszRootDrive , c_collen);
2071 rc = MSI_DatabaseOpenViewW(package->db,Query_all,&view);
2072 if (rc != ERROR_SUCCESS)
2074 rc = MSI_ViewExecute(view,0);
2075 if (rc != ERROR_SUCCESS)
2077 MSI_ViewClose(view);
2078 msiobj_release(&view->hdr);
2085 rc = MSI_ViewFetch(view,&row);
2086 if (rc != ERROR_SUCCESS)
2089 load_feature(package,row);
2090 msiobj_release(&row->hdr);
2092 MSI_ViewClose(view);
2093 msiobj_release(&view->hdr);
2095 return ERROR_SUCCESS;
2098 static UINT load_file(MSIPACKAGE* package, MSIRECORD * row)
2100 DWORD index = package->loaded_files;
2104 /* fill in the data */
2106 package->loaded_files++;
2107 if (package->loaded_files== 1)
2108 package->files = HeapAlloc(GetProcessHeap(),0,sizeof(MSIFILE));
2110 package->files = HeapReAlloc(GetProcessHeap(),0,
2111 package->files , package->loaded_files * sizeof(MSIFILE));
2113 memset(&package->files[index],0,sizeof(MSIFILE));
2115 package->files[index].File = load_dynamic_stringW(row, 1);
2116 buffer = load_dynamic_stringW(row, 2);
2118 package->files[index].ComponentIndex = -1;
2119 for (i = 0; i < package->loaded_components; i++)
2120 if (strcmpW(package->components[i].Component,buffer)==0)
2122 package->files[index].ComponentIndex = i;
2125 if (package->files[index].ComponentIndex == -1)
2126 ERR("Unfound Component %s\n",debugstr_w(buffer));
2127 HeapFree(GetProcessHeap(), 0, buffer);
2129 package->files[index].FileName = load_dynamic_stringW(row,3);
2131 reduce_to_longfilename(package->files[index].FileName);
2133 package->files[index].FileSize = MSI_RecordGetInteger(row,4);
2134 package->files[index].Version = load_dynamic_stringW(row, 5);
2135 package->files[index].Language = load_dynamic_stringW(row, 6);
2136 package->files[index].Attributes= MSI_RecordGetInteger(row,7);
2137 package->files[index].Sequence= MSI_RecordGetInteger(row,8);
2139 package->files[index].Temporary = FALSE;
2140 package->files[index].State = 0;
2142 TRACE("File Loaded (%s)\n",debugstr_w(package->files[index].File));
2144 return ERROR_SUCCESS;
2147 static UINT ACTION_FileCost(MSIPACKAGE *package)
2152 static const WCHAR Query[] = {
2153 'S','E','L','E','C','T',' ','*',' ',
2154 'F','R','O','M',' ','F','i','l','e',' ',
2155 'O','r','d','e','r',' ','b','y',' ','S','e','q','u','e','n','c','e', 0};
2158 return ERROR_INVALID_HANDLE;
2160 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
2161 if (rc != ERROR_SUCCESS)
2162 return ERROR_SUCCESS;
2164 rc = MSI_ViewExecute(view, 0);
2165 if (rc != ERROR_SUCCESS)
2167 MSI_ViewClose(view);
2168 msiobj_release(&view->hdr);
2169 return ERROR_SUCCESS;
2174 rc = MSI_ViewFetch(view,&row);
2175 if (rc != ERROR_SUCCESS)
2180 load_file(package,row);
2181 msiobj_release(&row->hdr);
2183 MSI_ViewClose(view);
2184 msiobj_release(&view->hdr);
2186 return ERROR_SUCCESS;
2189 static INT load_folder(MSIPACKAGE *package, const WCHAR* dir)
2192 static const WCHAR Query[] =
2193 {'s','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','D','i','r','e','c',
2194 't','o','r','y',' ','w','h','e','r','e',' ','`','D','i','r','e','c','t',
2195 'o','r','y','`',' ','=',' ','`','%','s','`',0};
2198 LPWSTR targetdir, parent, srcdir;
2199 MSIRECORD * row = 0;
2203 TRACE("Looking for dir %s\n",debugstr_w(dir));
2205 for (i = 0; i < package->loaded_folders; i++)
2207 if (strcmpW(package->folders[i].Directory,dir)==0)
2209 TRACE(" %s retuning on index %lu\n",debugstr_w(dir),i);
2214 TRACE("Working to load %s\n",debugstr_w(dir));
2216 index = package->loaded_folders++;
2217 if (package->loaded_folders==1)
2218 package->folders = HeapAlloc(GetProcessHeap(),0,
2221 package->folders= HeapReAlloc(GetProcessHeap(),0,
2222 package->folders, package->loaded_folders*
2225 memset(&package->folders[index],0,sizeof(MSIFOLDER));
2227 package->folders[index].Directory = dupstrW(dir);
2229 rc = ACTION_OpenQuery(package->db, &view, Query, dir);
2230 if (rc != ERROR_SUCCESS)
2233 rc = MSI_ViewExecute(view, 0);
2234 if (rc != ERROR_SUCCESS)
2236 MSI_ViewClose(view);
2237 msiobj_release(&view->hdr);
2241 rc = MSI_ViewFetch(view,&row);
2242 if (rc != ERROR_SUCCESS)
2244 MSI_ViewClose(view);
2245 msiobj_release(&view->hdr);
2249 targetdir = load_dynamic_stringW(row,3);
2251 /* split src and target dir */
2252 if (strchrW(targetdir,':'))
2254 srcdir=strchrW(targetdir,':');
2261 /* for now only pick long filename versions */
2262 if (strchrW(targetdir,'|'))
2264 targetdir = strchrW(targetdir,'|');
2268 if (srcdir && strchrW(srcdir,'|'))
2270 srcdir= strchrW(srcdir,'|');
2275 /* now check for root dirs */
2276 if (targetdir[0] == '.' && targetdir[1] == 0)
2279 if (srcdir && srcdir[0] == '.' && srcdir[1] == 0)
2284 TRACE(" TargetDefault = %s\n",debugstr_w(targetdir));
2285 if (package->folders[index].TargetDefault)
2286 HeapFree(GetProcessHeap(),0, package->folders[index].TargetDefault);
2287 package->folders[index].TargetDefault = dupstrW(targetdir);
2291 package->folders[index].SourceDefault = dupstrW(srcdir);
2293 package->folders[index].SourceDefault = dupstrW(targetdir);
2294 HeapFree(GetProcessHeap(), 0, targetdir);
2296 parent = load_dynamic_stringW(row,2);
2299 i = load_folder(package,parent);
2300 package->folders[index].ParentIndex = i;
2301 TRACE("Parent is index %i... %s %s\n",
2302 package->folders[index].ParentIndex,
2303 debugstr_w(package->folders[package->folders[index].ParentIndex].Directory),
2304 debugstr_w(parent));
2307 package->folders[index].ParentIndex = -2;
2308 HeapFree(GetProcessHeap(), 0, parent);
2310 package->folders[index].Property = load_dynamic_property(package, dir,NULL);
2312 msiobj_release(&row->hdr);
2313 MSI_ViewClose(view);
2314 msiobj_release(&view->hdr);
2315 TRACE(" %s retuning on index %i\n",debugstr_w(dir),index);
2320 static LPWSTR resolve_folder(MSIPACKAGE *package, LPCWSTR name,
2321 BOOL source, BOOL set_prop, MSIFOLDER **folder)
2324 LPWSTR p, path = NULL;
2326 TRACE("Working to resolve %s\n",debugstr_w(name));
2328 /* special resolving for Target and Source root dir */
2329 if (strcmpW(name,cszTargetDir)==0 || strcmpW(name,cszSourceDir)==0)
2333 path = load_dynamic_property(package,cszTargetDir,NULL);
2336 path = load_dynamic_property(package,cszRootDrive,NULL);
2338 MSI_SetPropertyW(package,cszTargetDir,path);
2342 for (i = 0; i < package->loaded_folders; i++)
2344 if (strcmpW(package->folders[i].Directory,name)==0)
2347 *folder = &(package->folders[i]);
2353 path = load_dynamic_property(package,cszSourceDir,NULL);
2356 path = load_dynamic_property(package,cszDatabase,NULL);
2359 p = strrchrW(path,'\\');
2366 for (i = 0; i < package->loaded_folders; i++)
2368 if (strcmpW(package->folders[i].Directory,name)==0)
2371 *folder = &(package->folders[i]);
2377 for (i = 0; i < package->loaded_folders; i++)
2379 if (strcmpW(package->folders[i].Directory,name)==0)
2383 if (i >= package->loaded_folders)
2387 *folder = &(package->folders[i]);
2389 if (!source && package->folders[i].ResolvedTarget)
2391 path = dupstrW(package->folders[i].ResolvedTarget);
2392 TRACE(" already resolved to %s\n",debugstr_w(path));
2395 else if (source && package->folders[i].ResolvedSource)
2397 path = dupstrW(package->folders[i].ResolvedSource);
2400 else if (!source && package->folders[i].Property)
2402 path = dupstrW(package->folders[i].Property);
2403 TRACE(" internally set to %s\n",debugstr_w(path));
2405 MSI_SetPropertyW(package,name,path);
2409 if (package->folders[i].ParentIndex >= 0)
2411 LPWSTR parent = package->folders[package->folders[i].ParentIndex].Directory;
2413 TRACE(" ! Parent is %s\n", debugstr_w(parent));
2415 p = resolve_folder(package, parent, source, set_prop, NULL);
2418 TRACE(" TargetDefault = %s\n",debugstr_w(package->folders[i].TargetDefault));
2419 path = build_directory_name(3, p, package->folders[i].TargetDefault, NULL);
2420 package->folders[i].ResolvedTarget = dupstrW(path);
2421 TRACE(" resolved into %s\n",debugstr_w(path));
2423 MSI_SetPropertyW(package,name,path);
2427 path = build_directory_name(3, p, package->folders[i].SourceDefault, NULL);
2428 package->folders[i].ResolvedSource = dupstrW(path);
2430 HeapFree(GetProcessHeap(),0,p);
2435 static UINT SetFeatureStates(MSIPACKAGE *package)
2441 LPWSTR override = NULL;
2442 static const WCHAR all[]={'A','L','L',0};
2443 static const WCHAR szlevel[] = {
2444 'I','N','S','T','A','L','L','L','E','V','E','L',0};
2445 static const WCHAR szAddLocal[] = {
2446 'A','D','D','L','O','C','A','L',0};
2448 /* I do not know if this is where it should happen.. but */
2450 TRACE("Checking Install Level\n");
2452 level = load_dynamic_property(package,szlevel,NULL);
2455 install_level = atoiW(level);
2456 HeapFree(GetProcessHeap(), 0, level);
2461 /* ok hereis the rub
2462 * ADDLOCAL and its friend OVERRIDE INSTALLLEVLE
2463 * I have confirmed this if ADDLOCALis stated then the INSTALLLEVEL is
2464 * itnored for all the features. seems strange, epsecially since it is not
2465 * documented anywhere, but it is how it works.
2468 override = load_dynamic_property(package,szAddLocal,NULL);
2472 for(i = 0; i < package->loaded_features; i++)
2474 if (strcmpiW(override,all)==0)
2476 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2477 package->features[i].Action = INSTALLSTATE_LOCAL;
2481 LPWSTR ptr = override;
2482 LPWSTR ptr2 = strchrW(override,',');
2487 strncmpW(ptr,package->features[i].Feature, ptr2-ptr)==0)
2489 strcmpW(ptr,package->features[i].Feature)==0))
2491 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2492 package->features[i].Action = INSTALLSTATE_LOCAL;
2498 ptr2 = strchrW(ptr,',');
2505 HeapFree(GetProcessHeap(),0,override);
2509 for(i = 0; i < package->loaded_features; i++)
2511 BOOL feature_state= ((package->features[i].Level > 0) &&
2512 (package->features[i].Level <= install_level));
2516 package->features[i].ActionRequest= INSTALLSTATE_LOCAL;
2517 package->features[i].Action = INSTALLSTATE_LOCAL;
2523 * now we want to enable or disable components base on feature
2526 for(i = 0; i < package->loaded_features; i++)
2528 MSIFEATURE* feature = &package->features[i];
2529 TRACE("Examining Feature %s (Installed %i, Action %i, Request %i)\n",
2530 debugstr_w(feature->Feature), feature->Installed, feature->Action,
2531 feature->ActionRequest);
2533 for( j = 0; j < feature->ComponentCount; j++)
2535 MSICOMPONENT* component = &package->components[
2536 feature->Components[j]];
2538 if (!component->Enabled)
2540 component->Action = INSTALLSTATE_ABSENT;
2541 component->ActionRequest = INSTALLSTATE_ABSENT;
2545 if (feature->Action == INSTALLSTATE_LOCAL)
2546 component->Action = INSTALLSTATE_LOCAL;
2547 if (feature->ActionRequest == INSTALLSTATE_LOCAL)
2548 component->ActionRequest = INSTALLSTATE_LOCAL;
2553 for(i = 0; i < package->loaded_components; i++)
2555 MSICOMPONENT* component= &package->components[i];
2557 TRACE("Result: Component %s (Installed %i, Action %i, Request %i)\n",
2558 debugstr_w(component->Component), component->Installed,
2559 component->Action, component->ActionRequest);
2563 return ERROR_SUCCESS;
2567 * Alot is done in this function aside from just the costing.
2568 * The costing needs to be implemented at some point but for now I am going
2569 * to focus on the directory building
2572 static UINT ACTION_CostFinalize(MSIPACKAGE *package)
2574 static const WCHAR ExecSeqQuery[] = {
2575 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2576 'D','i','r','e','c','t','o','r','y',0};
2577 static const WCHAR ConditionQuery[] = {
2578 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
2579 'C','o','n','d','i','t','i','o','n',0};
2580 static const WCHAR szCosting[] = {
2581 'C','o','s','t','i','n','g','C','o','m','p','l','e','t','e',0 };
2582 static const WCHAR szlevel[] = {
2583 'I','N','S','T','A','L','L','L','E','V','E','L',0};
2584 static const WCHAR szOne[] = { '1', 0 };
2590 TRACE("Building Directory properties\n");
2592 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
2593 if (rc == ERROR_SUCCESS)
2595 rc = MSI_ViewExecute(view, 0);
2596 if (rc != ERROR_SUCCESS)
2598 MSI_ViewClose(view);
2599 msiobj_release(&view->hdr);
2607 MSIRECORD * row = 0;
2610 rc = MSI_ViewFetch(view,&row);
2611 if (rc != ERROR_SUCCESS)
2618 MSI_RecordGetStringW(row,1,name,&sz);
2620 /* This helper function now does ALL the work */
2621 TRACE("Dir %s ...\n",debugstr_w(name));
2622 load_folder(package,name);
2623 path = resolve_folder(package,name,FALSE,TRUE,NULL);
2624 TRACE("resolves to %s\n",debugstr_w(path));
2625 HeapFree( GetProcessHeap(), 0, path);
2627 msiobj_release(&row->hdr);
2629 MSI_ViewClose(view);
2630 msiobj_release(&view->hdr);
2633 TRACE("File calculations %i files\n",package->loaded_files);
2635 for (i = 0; i < package->loaded_files; i++)
2637 MSICOMPONENT* comp = NULL;
2638 MSIFILE* file= NULL;
2640 file = &package->files[i];
2641 if (file->ComponentIndex >= 0)
2642 comp = &package->components[file->ComponentIndex];
2644 if (file->Temporary == TRUE)
2651 /* calculate target */
2652 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
2654 if (file->TargetPath)
2655 HeapFree(GetProcessHeap(),0,file->TargetPath);
2657 TRACE("file %s is named %s\n",
2658 debugstr_w(file->File),debugstr_w(file->FileName));
2660 file->TargetPath = build_directory_name(2, p, file->FileName);
2662 HeapFree(GetProcessHeap(),0,p);
2664 TRACE("file %s resolves to %s\n",
2665 debugstr_w(file->File),debugstr_w(file->TargetPath));
2667 if (GetFileAttributesW(file->TargetPath) == INVALID_FILE_ATTRIBUTES)
2670 comp->Cost += file->FileSize;
2680 static const WCHAR name[] =
2682 static const WCHAR name_fmt[] =
2683 {'%','u','.','%','u','.','%','u','.','%','u',0};
2684 WCHAR filever[0x100];
2685 VS_FIXEDFILEINFO *lpVer;
2687 FIXME("Version comparison.. \n");
2688 versize = GetFileVersionInfoSizeW(file->TargetPath,&handle);
2689 version = HeapAlloc(GetProcessHeap(),0,versize);
2690 GetFileVersionInfoW(file->TargetPath, 0, versize, version);
2692 VerQueryValueW(version, name, (LPVOID*)&lpVer, &sz);
2694 sprintfW(filever,name_fmt,
2695 HIWORD(lpVer->dwFileVersionMS),
2696 LOWORD(lpVer->dwFileVersionMS),
2697 HIWORD(lpVer->dwFileVersionLS),
2698 LOWORD(lpVer->dwFileVersionLS));
2700 TRACE("new %s old %s\n", debugstr_w(file->Version),
2701 debugstr_w(filever));
2702 if (strcmpiW(filever,file->Version)<0)
2705 FIXME("cost should be diff in size\n");
2706 comp->Cost += file->FileSize;
2710 HeapFree(GetProcessHeap(),0,version);
2718 TRACE("Evaluating Condition Table\n");
2720 rc = MSI_DatabaseOpenViewW(package->db, ConditionQuery, &view);
2721 if (rc == ERROR_SUCCESS)
2723 rc = MSI_ViewExecute(view, 0);
2724 if (rc != ERROR_SUCCESS)
2726 MSI_ViewClose(view);
2727 msiobj_release(&view->hdr);
2733 WCHAR Feature[0x100];
2734 MSIRECORD * row = 0;
2738 rc = MSI_ViewFetch(view,&row);
2740 if (rc != ERROR_SUCCESS)
2747 MSI_RecordGetStringW(row,1,Feature,&sz);
2749 feature_index = get_loaded_feature(package,Feature);
2750 if (feature_index < 0)
2751 ERR("FAILED to find loaded feature %s\n",debugstr_w(Feature));
2755 Condition = load_dynamic_stringW(row,3);
2757 if (MSI_EvaluateConditionW(package,Condition) ==
2760 int level = MSI_RecordGetInteger(row,2);
2761 TRACE("Reseting feature %s to level %i\n",
2762 debugstr_w(Feature), level);
2763 package->features[feature_index].Level = level;
2765 HeapFree(GetProcessHeap(),0,Condition);
2768 msiobj_release(&row->hdr);
2770 MSI_ViewClose(view);
2771 msiobj_release(&view->hdr);
2774 TRACE("Enabling or Disabling Components\n");
2775 for (i = 0; i < package->loaded_components; i++)
2777 if (package->components[i].Condition[0])
2779 if (MSI_EvaluateConditionW(package,
2780 package->components[i].Condition) == MSICONDITION_FALSE)
2782 TRACE("Disabling component %s\n",
2783 debugstr_w(package->components[i].Component));
2784 package->components[i].Enabled = FALSE;
2789 MSI_SetPropertyW(package,szCosting,szOne);
2790 /* set default run level if not set */
2791 level = load_dynamic_property(package,szlevel,NULL);
2793 MSI_SetPropertyW(package,szlevel, szOne);
2795 HeapFree(GetProcessHeap(),0,level);
2797 return SetFeatureStates(package);
2802 * This is a helper function for handling embedded cabinet media
2804 static UINT writeout_cabinet_stream(MSIPACKAGE *package, WCHAR* stream_name,
2812 WCHAR tmp[MAX_PATH];
2814 rc = read_raw_stream_data(package->db,stream_name,&data,&size);
2815 if (rc != ERROR_SUCCESS)
2819 if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
2820 GetTempPathW(MAX_PATH,tmp);
2822 GetTempFileNameW(tmp,stream_name,0,source);
2824 track_tempfile(package,strrchrW(source,'\\'), source);
2825 the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2826 FILE_ATTRIBUTE_NORMAL, NULL);
2828 if (the_file == INVALID_HANDLE_VALUE)
2830 rc = ERROR_FUNCTION_FAILED;
2834 WriteFile(the_file,data,size,&write,NULL);
2835 CloseHandle(the_file);
2836 TRACE("wrote %li bytes to %s\n",write,debugstr_w(source));
2838 HeapFree(GetProcessHeap(),0,data);
2843 /* Support functions for FDI functions */
2846 MSIPACKAGE* package;
2851 static void * cabinet_alloc(ULONG cb)
2853 return HeapAlloc(GetProcessHeap(), 0, cb);
2856 static void cabinet_free(void *pv)
2858 HeapFree(GetProcessHeap(), 0, pv);
2861 static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
2864 DWORD dwShareMode = 0;
2865 DWORD dwCreateDisposition = OPEN_EXISTING;
2866 switch (oflag & _O_ACCMODE)
2869 dwAccess = GENERIC_READ;
2870 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
2873 dwAccess = GENERIC_WRITE;
2874 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2877 dwAccess = GENERIC_READ | GENERIC_WRITE;
2878 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
2881 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
2882 dwCreateDisposition = CREATE_NEW;
2883 else if (oflag & _O_CREAT)
2884 dwCreateDisposition = CREATE_ALWAYS;
2885 return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL, dwCreateDisposition, 0, NULL);
2888 static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
2891 if (ReadFile((HANDLE)hf, pv, cb, &dwRead, NULL))
2896 static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
2899 if (WriteFile((HANDLE)hf, pv, cb, &dwWritten, NULL))
2904 static int cabinet_close(INT_PTR hf)
2906 return CloseHandle((HANDLE)hf) ? 0 : -1;
2909 static long cabinet_seek(INT_PTR hf, long dist, int seektype)
2911 /* flags are compatible and so are passed straight through */
2912 return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
2915 static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
2917 /* FIXME: try to do more processing in this function */
2920 case fdintCOPY_FILE:
2922 CabData *data = (CabData*) pfdin->pv;
2923 ULONG len = strlen(data->cab_path) + strlen(pfdin->psz1);
2928 LPWSTR tracknametmp;
2929 static const WCHAR tmpprefix[] = {'C','A','B','T','M','P','_',0};
2931 if (data->file_name && strcmp(data->file_name,pfdin->psz1))
2934 file = cabinet_alloc((len+1)*sizeof(char));
2935 strcpy(file, data->cab_path);
2936 strcat(file, pfdin->psz1);
2938 TRACE("file: %s\n", debugstr_a(file));
2940 /* track this file so it can be deleted if not installed */
2941 trackpath=strdupAtoW(file);
2942 tracknametmp=strdupAtoW(strrchr(file,'\\')+1);
2943 trackname = HeapAlloc(GetProcessHeap(),0,(strlenW(tracknametmp) +
2944 strlenW(tmpprefix)+1) * sizeof(WCHAR));
2946 strcpyW(trackname,tmpprefix);
2947 strcatW(trackname,tracknametmp);
2949 track_tempfile(data->package, trackname, trackpath);
2951 HeapFree(GetProcessHeap(),0,trackpath);
2952 HeapFree(GetProcessHeap(),0,trackname);
2953 HeapFree(GetProcessHeap(),0,tracknametmp);
2955 return cabinet_open(file, _O_WRONLY | _O_CREAT, 0);
2957 case fdintCLOSE_FILE_INFO:
2961 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
2963 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
2965 if (!SetFileTime((HANDLE)pfdin->hf, &ftLocal, 0, &ftLocal))
2968 cabinet_close(pfdin->hf);
2976 /***********************************************************************
2977 * extract_cabinet_file
2979 * Extract files from a cab file.
2981 static BOOL extract_a_cabinet_file(MSIPACKAGE* package, const WCHAR* source,
2982 const WCHAR* path, const WCHAR* file)
2992 TRACE("Extracting %s (%s) to %s\n",debugstr_w(source),
2993 debugstr_w(file), debugstr_w(path));
2995 hfdi = FDICreate(cabinet_alloc,
3006 ERR("FDICreate failed\n");
3010 if (!(cabinet = strdupWtoA( source )))
3015 if (!(cab_path = strdupWtoA( path )))
3018 HeapFree(GetProcessHeap(), 0, cabinet);
3022 data.package = package;
3023 data.cab_path = cab_path;
3024 file_name = strdupWtoA(file);
3025 data.file_name = file_name;
3027 ret = FDICopy(hfdi, cabinet, "", 0, cabinet_notify, NULL, &data);
3030 ERR("FDICopy failed\n");
3034 HeapFree(GetProcessHeap(), 0, cabinet);
3035 HeapFree(GetProcessHeap(), 0, cab_path);
3036 HeapFree(GetProcessHeap(), 0, file_name);
3041 static UINT ready_media_for_file(MSIPACKAGE *package, UINT sequence,
3042 WCHAR* path, WCHAR* file)
3046 MSIRECORD * row = 0;
3047 static WCHAR source[MAX_PATH];
3048 static const WCHAR ExecSeqQuery[] = {
3049 's','e','l','e','c','t',' ','*',' ',
3050 'f','r','o','m',' ','M','e','d','i','a',' ',
3051 'w','h','e','r','e',' ','L','a','s','t','S','e','q','u','e','n','c','e',' ','>','=',' ','%','i',' ',
3052 'o','r','d','e','r',' ','b','y',' ','L','a','s','t','S','e','q','u','e','n','c','e',0};
3057 static UINT last_sequence = 0;
3059 if (sequence <= last_sequence)
3061 TRACE("Media already ready (%u, %u)\n",sequence,last_sequence);
3062 extract_a_cabinet_file(package, source,path,file);
3063 return ERROR_SUCCESS;
3066 sprintfW(Query,ExecSeqQuery,sequence);
3068 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
3069 if (rc != ERROR_SUCCESS)
3072 rc = MSI_ViewExecute(view, 0);
3073 if (rc != ERROR_SUCCESS)
3075 MSI_ViewClose(view);
3076 msiobj_release(&view->hdr);
3080 rc = MSI_ViewFetch(view,&row);
3081 if (rc != ERROR_SUCCESS)
3083 MSI_ViewClose(view);
3084 msiobj_release(&view->hdr);
3087 seq = MSI_RecordGetInteger(row,2);
3088 last_sequence = seq;
3090 if (!MSI_RecordIsNull(row,4))
3093 MSI_RecordGetStringW(row,4,cab,&sz);
3094 TRACE("Source is CAB %s\n",debugstr_w(cab));
3095 /* the stream does not contain the # character */
3098 writeout_cabinet_stream(package,&cab[1],source);
3099 strcpyW(path,source);
3100 *(strrchrW(path,'\\')+1)=0;
3105 if (MSI_GetPropertyW(package, cszSourceDir, source, &sz))
3107 ERR("No Source dir defined \n");
3108 rc = ERROR_FUNCTION_FAILED;
3112 strcpyW(path,source);
3113 strcatW(source,cab);
3114 /* extract the cab file into a folder in the temp folder */
3116 if (MSI_GetPropertyW(package, cszTempFolder,path, &sz)
3118 GetTempPathW(MAX_PATH,path);
3121 rc = !extract_a_cabinet_file(package, source,path,file);
3123 msiobj_release(&row->hdr);
3124 MSI_ViewClose(view);
3125 msiobj_release(&view->hdr);
3129 inline static UINT create_component_directory ( MSIPACKAGE* package, INT component)
3131 UINT rc = ERROR_SUCCESS;
3133 LPWSTR install_path;
3135 install_path = resolve_folder(package, package->components[component].Directory,
3136 FALSE, FALSE, &folder);
3138 return ERROR_FUNCTION_FAILED;
3140 /* create the path */
3141 if (folder->State == 0)
3143 create_full_pathW(install_path);
3146 HeapFree(GetProcessHeap(), 0, install_path);
3151 static UINT ACTION_InstallFiles(MSIPACKAGE *package)
3153 UINT rc = ERROR_SUCCESS;
3156 WCHAR uipath[MAX_PATH];
3159 return ERROR_INVALID_HANDLE;
3161 /* increment progress bar each time action data is sent */
3162 ui_progress(package,1,1,0,0);
3164 for (index = 0; index < package->loaded_files; index++)
3166 WCHAR path_to_source[MAX_PATH];
3169 file = &package->files[index];
3171 if (file->Temporary)
3174 if (package->components[file->ComponentIndex].ActionRequest !=
3177 ui_progress(package,2,file->FileSize,0,0);
3178 TRACE("File %s is not scheduled for install\n",
3179 debugstr_w(file->File));
3184 if ((file->State == 1) || (file->State == 2))
3188 MSICOMPONENT* comp = NULL;
3190 TRACE("Installing %s\n",debugstr_w(file->File));
3191 rc = ready_media_for_file(package,file->Sequence,path_to_source,
3195 * our file table could change here because a new temp file
3196 * may have been created
3198 file = &package->files[index];
3199 if (rc != ERROR_SUCCESS)
3201 ERR("Unable to ready media\n");
3202 rc = ERROR_FUNCTION_FAILED;
3206 create_component_directory( package, file->ComponentIndex);
3208 /* recalculate file paths because things may have changed */
3210 if (file->ComponentIndex >= 0)
3211 comp = &package->components[file->ComponentIndex];
3213 p = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
3214 if (file->TargetPath)
3215 HeapFree(GetProcessHeap(),0,file->TargetPath);
3217 file->TargetPath = build_directory_name(2, p, file->FileName);
3219 len = strlenW(path_to_source) + strlenW(file->File) + 2;
3220 file->SourcePath = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
3221 strcpyW(file->SourcePath, path_to_source);
3222 strcatW(file->SourcePath, file->File);
3224 TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
3225 debugstr_w(file->TargetPath));
3228 uirow=MSI_CreateRecord(9);
3229 MSI_RecordSetStringW(uirow,1,file->File);
3230 strcpyW(uipath,file->TargetPath);
3231 *(strrchrW(uipath,'\\')+1)=0;
3232 MSI_RecordSetStringW(uirow,9,uipath);
3233 MSI_RecordSetInteger(uirow,6,file->FileSize);
3234 ui_actiondata(package,szInstallFiles,uirow);
3235 msiobj_release( &uirow->hdr );
3236 ui_progress(package,2,file->FileSize,0,0);
3238 if (!MoveFileW(file->SourcePath,file->TargetPath))
3240 rc = GetLastError();
3241 ERR("Unable to move file (%s -> %s) (error %d)\n",
3242 debugstr_w(file->SourcePath), debugstr_w(file->TargetPath),
3244 if (rc == ERROR_ALREADY_EXISTS && file->State == 2)
3246 CopyFileW(file->SourcePath,file->TargetPath,FALSE);
3247 DeleteFileW(file->SourcePath);
3250 else if (rc == ERROR_FILE_NOT_FOUND)
3252 ERR("Source File Not Found! Continueing\n");
3257 ERR("Ignoring Error and continuing...\n");
3269 inline static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
3270 LPWSTR* file_source)
3275 return ERROR_INVALID_HANDLE;
3277 for (index = 0; index < package->loaded_files; index ++)
3279 if (strcmpW(file_key,package->files[index].File)==0)
3281 if (package->files[index].State >= 3)
3283 *file_source = dupstrW(package->files[index].TargetPath);
3284 return ERROR_SUCCESS;
3287 return ERROR_FILE_NOT_FOUND;
3291 return ERROR_FUNCTION_FAILED;
3294 static UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
3298 MSIRECORD * row = 0;
3299 static const WCHAR ExecSeqQuery[] = {
3300 's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ',
3301 'D','u','p','l','i','c','a','t','e','F','i','l','e',0};
3304 return ERROR_INVALID_HANDLE;
3306 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3307 if (rc != ERROR_SUCCESS)
3308 return ERROR_SUCCESS;
3310 rc = MSI_ViewExecute(view, 0);
3311 if (rc != ERROR_SUCCESS)
3313 MSI_ViewClose(view);
3314 msiobj_release(&view->hdr);
3320 WCHAR file_key[0x100];
3321 WCHAR *file_source = NULL;
3322 WCHAR dest_name[0x100];
3323 LPWSTR dest_path, dest;
3324 WCHAR component[0x100];
3325 INT component_index;
3329 rc = MSI_ViewFetch(view,&row);
3330 if (rc != ERROR_SUCCESS)
3337 rc = MSI_RecordGetStringW(row,2,component,&sz);
3338 if (rc != ERROR_SUCCESS)
3340 ERR("Unable to get component\n");
3341 msiobj_release(&row->hdr);
3345 component_index = get_loaded_component(package,component);
3346 if (package->components[component_index].ActionRequest !=
3349 TRACE("Skipping copy due to disabled component\n");
3350 msiobj_release(&row->hdr);
3355 rc = MSI_RecordGetStringW(row,3,file_key,&sz);
3356 if (rc != ERROR_SUCCESS)
3358 ERR("Unable to get file key\n");
3359 msiobj_release(&row->hdr);
3363 rc = get_file_target(package,file_key,&file_source);
3365 if (rc != ERROR_SUCCESS)
3367 ERR("Original file unknown %s\n",debugstr_w(file_key));
3368 msiobj_release(&row->hdr);
3370 HeapFree(GetProcessHeap(),0,file_source);
3374 if (MSI_RecordIsNull(row,4))
3376 strcpyW(dest_name,strrchrW(file_source,'\\')+1);
3381 MSI_RecordGetStringW(row,4,dest_name,&sz);
3382 reduce_to_longfilename(dest_name);
3385 if (MSI_RecordIsNull(row,5))
3388 dest_path = dupstrW(file_source);
3389 p = strrchrW(dest_path,'\\');
3395 WCHAR destkey[0x100];
3397 MSI_RecordGetStringW(row,5,destkey,&sz);
3399 dest_path = resolve_folder(package, destkey, FALSE,FALSE,NULL);
3402 ERR("Unable to get destination folder\n");
3403 msiobj_release(&row->hdr);
3405 HeapFree(GetProcessHeap(),0,file_source);
3410 dest = build_directory_name(2, dest_path, dest_name);
3411 HeapFree(GetProcessHeap(), 0, dest_path);
3413 TRACE("Duplicating file %s to %s\n",debugstr_w(file_source),
3416 if (strcmpW(file_source,dest))
3417 rc = !CopyFileW(file_source,dest,TRUE);
3421 if (rc != ERROR_SUCCESS)
3422 ERR("Failed to copy file\n");
3424 FIXME("We should track these duplicate files as well\n");
3426 msiobj_release(&row->hdr);
3427 HeapFree(GetProcessHeap(),0,dest);
3428 HeapFree(GetProcessHeap(),0,file_source);
3430 MSI_ViewClose(view);
3431 msiobj_release(&view->hdr);
3436 /* OK this value is "interpretted" and then formatted based on the
3437 first few characters */
3438 static LPSTR parse_value(MSIPACKAGE *package, WCHAR *value, DWORD *type,
3442 if (value[0]=='#' && value[1]!='#' && value[1]!='%')
3451 deformat_string(package, &value[2], &deformated);
3453 /* binary value type */
3456 *size = strlenW(ptr)/2;
3457 data = HeapAlloc(GetProcessHeap(),0,*size);
3469 data[count] = (BYTE)strtol(byte,NULL,0);
3472 HeapFree(GetProcessHeap(),0,deformated);
3474 TRACE("Data %li bytes(%i)\n",*size,count);
3479 deformat_string(package, &value[1], &deformated);
3482 *size = sizeof(DWORD);
3483 data = HeapAlloc(GetProcessHeap(),0,*size);
3484 *(LPDWORD)data = atoiW(deformated);
3485 TRACE("DWORD %i\n",*data);
3487 HeapFree(GetProcessHeap(),0,deformated);
3500 *type=REG_EXPAND_SZ;
3508 *size = deformat_string(package, ptr,(LPWSTR*)&data);
3513 static UINT ACTION_WriteRegistryValues(MSIPACKAGE *package)
3517 MSIRECORD * row = 0;
3518 static const WCHAR ExecSeqQuery[] = {
3519 's','e','l','e','c','t',' ','*',' ',
3520 'f','r','o','m',' ','R','e','g','i','s','t','r','y',0 };
3523 return ERROR_INVALID_HANDLE;
3525 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3526 if (rc != ERROR_SUCCESS)
3527 return ERROR_SUCCESS;
3529 rc = MSI_ViewExecute(view, 0);
3530 if (rc != ERROR_SUCCESS)
3532 MSI_ViewClose(view);
3533 msiobj_release(&view->hdr);
3537 /* increment progress bar each time action data is sent */
3538 ui_progress(package,1,REG_PROGRESS_VALUE,1,0);
3542 static const WCHAR szHCR[] =
3543 {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T','\\',0};
3544 static const WCHAR szHCU[] =
3545 {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',0};
3546 static const WCHAR szHLM[] =
3547 {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',
3549 static const WCHAR szHU[] =
3550 {'H','K','E','Y','_','U','S','E','R','S','\\',0};
3552 LPSTR value_data = NULL;
3553 HKEY root_key, hkey;
3555 LPWSTR value, key, name, component, deformated;
3557 INT component_index;
3562 rc = MSI_ViewFetch(view,&row);
3563 if (rc != ERROR_SUCCESS)
3568 ui_progress(package,2,0,0,0);
3575 component = load_dynamic_stringW(row, 6);
3576 component_index = get_loaded_component(package,component);
3578 if (package->components[component_index].ActionRequest !=
3581 TRACE("Skipping write due to disabled component\n");
3582 msiobj_release(&row->hdr);
3586 /* null values have special meanings during uninstalls and such */
3588 if(MSI_RecordIsNull(row,5))
3590 msiobj_release(&row->hdr);
3594 root = MSI_RecordGetInteger(row,2);
3595 key = load_dynamic_stringW(row, 3);
3597 name = load_dynamic_stringW(row, 4);
3599 /* get the root key */
3602 case 0: root_key = HKEY_CLASSES_ROOT;
3605 case 1: root_key = HKEY_CURRENT_USER;
3608 case 2: root_key = HKEY_LOCAL_MACHINE;
3611 case 3: root_key = HKEY_USERS;
3615 ERR("Unknown root %i\n",root);
3622 msiobj_release(&row->hdr);
3626 deformat_string(package, key , &deformated);
3627 size = strlenW(deformated) + strlenW(szRoot) + 1;
3628 uikey = HeapAlloc(GetProcessHeap(), 0, size*sizeof(WCHAR));
3629 strcpyW(uikey,szRoot);
3630 strcatW(uikey,deformated);
3632 if (RegCreateKeyW( root_key, deformated, &hkey))
3634 ERR("Could not create key %s\n",debugstr_w(deformated));
3635 msiobj_release(&row->hdr);
3636 HeapFree(GetProcessHeap(),0,deformated);
3639 HeapFree(GetProcessHeap(),0,deformated);
3641 value = load_dynamic_stringW(row,5);
3642 value_data = parse_value(package, value, &type, &size);
3644 deformat_string(package, name, &deformated);
3648 TRACE("Setting value %s\n",debugstr_w(deformated));
3649 RegSetValueExW(hkey, deformated, 0, type, value_data, size);
3651 uirow = MSI_CreateRecord(3);
3652 MSI_RecordSetStringW(uirow,2,deformated);
3653 MSI_RecordSetStringW(uirow,1,uikey);
3656 MSI_RecordSetStringW(uirow,3,(LPWSTR)value_data);
3658 MSI_RecordSetStringW(uirow,3,value);
3660 ui_actiondata(package,szWriteRegistryValues,uirow);
3661 msiobj_release( &uirow->hdr );
3663 HeapFree(GetProcessHeap(),0,value_data);
3665 HeapFree(GetProcessHeap(),0,value);
3666 HeapFree(GetProcessHeap(),0,deformated);
3668 msiobj_release(&row->hdr);
3672 HeapFree(GetProcessHeap(),0,uikey);
3674 HeapFree(GetProcessHeap(),0,key);
3676 HeapFree(GetProcessHeap(),0,name);
3678 HeapFree(GetProcessHeap(),0,component);
3680 MSI_ViewClose(view);
3681 msiobj_release(&view->hdr);
3686 * This helper function should probably go alot of places
3688 * Thinking about this, maybe this should become yet another Bison file
3690 static DWORD deformat_string(MSIPACKAGE *package, WCHAR* ptr,WCHAR** data)
3703 TRACE("Deformatting NULL string\n");
3707 TRACE("Starting with %s\n",debugstr_w(ptr));
3708 /* scan for special characters */
3709 if (!strchrW(ptr,'[') || (strchrW(ptr,'[') && !strchrW(ptr,']')))
3712 size = (strlenW(ptr)+1) * sizeof(WCHAR);
3713 *data = HeapAlloc(GetProcessHeap(),0,size);
3718 /* formatted string located */
3719 mark = strchrW(ptr,'[');
3722 INT cnt = (mark - ptr);
3723 TRACE("%i (%i) characters before marker\n",cnt,(mark-ptr));
3724 size = cnt * sizeof(WCHAR);
3725 size += sizeof(WCHAR);
3726 *data = HeapAlloc(GetProcessHeap(),0,size);
3727 strncpyW(*data,ptr,cnt);
3732 size = sizeof(WCHAR);
3733 *data = HeapAlloc(GetProcessHeap(),0,size);
3737 mark2 = strchrW(mark,']');
3738 strncpyW(key,mark,mark2-mark);
3739 key[mark2-mark] = 0;
3740 mark = strchrW(mark,']');
3742 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3744 rc = MSI_GetPropertyW(package, key, NULL, &sz);
3745 if ((rc == ERROR_SUCCESS) || (rc == ERROR_MORE_DATA))
3750 value = HeapAlloc(GetProcessHeap(),0,sz * sizeof(WCHAR));
3751 MSI_GetPropertyW(package, key, value, &sz);
3753 chunk = (strlenW(value)+1) * sizeof(WCHAR);
3755 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3757 strcatW(*data,value);
3759 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3763 chunk = (strlenW(mark)+1) * sizeof(WCHAR);
3765 newdata = HeapReAlloc(GetProcessHeap(),0,*data,size);
3767 strcatW(*data,mark);
3769 (*data)[strlenW(*data)]=0;
3770 TRACE("Current %s .. %s\n",debugstr_w(*data),debugstr_w(mark));
3772 /* recursively do this to clean up */
3773 mark = HeapAlloc(GetProcessHeap(),0,size);
3774 strcpyW(mark,*data);
3775 TRACE("String at this point %s\n",debugstr_w(mark));
3776 size = deformat_string(package,mark,data);
3777 HeapFree(GetProcessHeap(),0,mark);
3781 static UINT ACTION_InstallInitialize(MSIPACKAGE *package)
3783 return ERROR_SUCCESS;
3787 static UINT ACTION_InstallValidate(MSIPACKAGE *package)
3791 static const WCHAR q1[]={
3792 'S','E','L','E','C','T',' ','*',' ',
3793 'F','R','O','M',' ','R','e','g','i','s','t','r','y',0};
3796 MSIRECORD * row = 0;
3799 TRACE(" InstallValidate \n");
3801 rc = MSI_DatabaseOpenViewW(package->db, q1, &view);
3802 if (rc != ERROR_SUCCESS)
3803 return ERROR_SUCCESS;
3805 rc = MSI_ViewExecute(view, 0);
3806 if (rc != ERROR_SUCCESS)
3808 MSI_ViewClose(view);
3809 msiobj_release(&view->hdr);
3814 rc = MSI_ViewFetch(view,&row);
3815 if (rc != ERROR_SUCCESS)
3822 msiobj_release(&row->hdr);
3824 MSI_ViewClose(view);
3825 msiobj_release(&view->hdr);
3827 total = total + progress * REG_PROGRESS_VALUE;
3828 total = total + package->loaded_components * COMPONENT_PROGRESS_VALUE;
3829 for (i=0; i < package->loaded_files; i++)
3830 total += package->files[i].FileSize;
3831 ui_progress(package,0,total,0,0);
3833 return ERROR_SUCCESS;
3836 static UINT ACTION_LaunchConditions(MSIPACKAGE *package)
3839 MSIQUERY * view = NULL;
3840 MSIRECORD * row = 0;
3841 static const WCHAR ExecSeqQuery[] = {
3842 'S','E','L','E','C','T',' ','*',' ',
3843 'f','r','o','m',' ','L','a','u','n','c','h','C','o','n','d','i','t','i','o','n',0};
3844 static const WCHAR title[]=
3845 {'I','n','s','t','a','l','l',' ','F','a', 'i','l','e','d',0};
3847 TRACE("Checking launch conditions\n");
3849 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
3850 if (rc != ERROR_SUCCESS)
3851 return ERROR_SUCCESS;
3853 rc = MSI_ViewExecute(view, 0);
3854 if (rc != ERROR_SUCCESS)
3856 MSI_ViewClose(view);
3857 msiobj_release(&view->hdr);
3862 while (rc == ERROR_SUCCESS)
3865 LPWSTR message = NULL;
3867 rc = MSI_ViewFetch(view,&row);
3868 if (rc != ERROR_SUCCESS)
3874 cond = load_dynamic_stringW(row,1);
3876 if (MSI_EvaluateConditionW(package,cond) != MSICONDITION_TRUE)
3878 message = load_dynamic_stringW(row,2);
3879 MessageBoxW(NULL,message,title,MB_OK);
3880 HeapFree(GetProcessHeap(),0,message);
3881 rc = ERROR_FUNCTION_FAILED;
3883 HeapFree(GetProcessHeap(),0,cond);
3884 msiobj_release(&row->hdr);
3886 MSI_ViewClose(view);
3887 msiobj_release(&view->hdr);
3891 static LPWSTR resolve_keypath( MSIPACKAGE* package, INT
3894 MSICOMPONENT* cmp = &package->components[component_index];
3896 if (cmp->KeyPath[0]==0)
3898 LPWSTR p = resolve_folder(package,cmp->Directory,FALSE,FALSE,NULL);
3901 if ((cmp->Attributes & 0x4) || (cmp->Attributes & 0x20))
3903 FIXME("UNIMPLEMENTED keypath as Registry or ODBC Source\n");
3909 j = get_loaded_file(package,cmp->KeyPath);
3913 LPWSTR p = dupstrW(package->files[j].TargetPath);
3921 * Ok further analysis makes me think that this work is
3922 * actually done in the PublishComponents and PublishFeatures
3923 * step, and not here. It appears like the keypath and all that is
3924 * resolved in this step, however actually written in the Publish steps.
3925 * But we will leave it here for now because it is unclear
3927 static UINT ACTION_ProcessComponents(MSIPACKAGE *package)
3930 WCHAR squished_pc[0x100];
3931 WCHAR squished_cc[0x100];
3934 HKEY hkey=0,hkey2=0,hkey3=0;
3935 static const WCHAR szProductCode[]=
3936 {'P','r','o','d','u','c','t','C','o','d','e',0};
3937 static const WCHAR szInstaller[] = {
3938 'S','o','f','t','w','a','r','e','\\',
3939 'M','i','c','r','o','s','o','f','t','\\',
3940 'W','i','n','d','o','w','s','\\',
3941 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
3942 'I','n','s','t','a','l','l','e','r',0 };
3943 static const WCHAR szFeatures[] = {
3944 'F','e','a','t','u','r','e','s',0 };
3945 static const WCHAR szComponents[] = {
3946 'C','o','m','p','o','n','e','n','t','s',0 };
3949 return ERROR_INVALID_HANDLE;
3951 /* writes the Component and Features values to the registry */
3952 productcode = load_dynamic_property(package,szProductCode,&rc);
3956 squash_guid(productcode,squished_pc);
3957 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller,&hkey);
3958 if (rc != ERROR_SUCCESS)
3961 rc = RegCreateKeyW(hkey,szFeatures,&hkey2);
3962 if (rc != ERROR_SUCCESS)
3965 rc = RegCreateKeyW(hkey2,squished_pc,&hkey3);
3966 if (rc != ERROR_SUCCESS)
3969 /* here the guids are base 85 encoded */
3970 for (i = 0; i < package->loaded_features; i++)
3977 size = package->features[i].ComponentCount*21*sizeof(WCHAR);
3978 data = HeapAlloc(GetProcessHeap(), 0, size);
3981 for (j = 0; j < package->features[i].ComponentCount; j++)
3984 TRACE("From %s\n",debugstr_w(package->components
3985 [package->features[i].Components[j]].ComponentId));
3986 CLSIDFromString(package->components
3987 [package->features[i].Components[j]].ComponentId,
3989 encode_base85_guid(&clsid,buf);
3990 TRACE("to %s\n",debugstr_w(buf));
3994 size = strlenW(data)*sizeof(WCHAR);
3995 RegSetValueExW(hkey3,package->features[i].Feature,0,REG_SZ,
3997 HeapFree(GetProcessHeap(),0,data);
4003 rc = RegCreateKeyW(hkey,szComponents,&hkey2);
4004 if (rc != ERROR_SUCCESS)
4007 ui_progress(package,1,COMPONENT_PROGRESS_VALUE,1,0);
4008 for (i = 0; i < package->loaded_components; i++)
4010 ui_progress(package,2,0,0,0);
4011 if (package->components[i].ComponentId[0]!=0)
4013 WCHAR *keypath = NULL;
4016 squash_guid(package->components[i].ComponentId,squished_cc);
4017 rc = RegCreateKeyW(hkey2,squished_cc,&hkey3);
4018 if (rc != ERROR_SUCCESS)
4021 keypath = resolve_keypath(package,i);
4024 RegSetValueExW(hkey3,squished_pc,0,REG_SZ,(LPVOID)keypath,
4025 (strlenW(keypath)+1)*sizeof(WCHAR));
4029 uirow = MSI_CreateRecord(3);
4030 MSI_RecordSetStringW(uirow,1,productcode);
4031 MSI_RecordSetStringW(uirow,2,package->components[i].
4033 MSI_RecordSetStringW(uirow,3,keypath);
4034 ui_actiondata(package,szProcessComponents,uirow);
4035 msiobj_release( &uirow->hdr );
4036 HeapFree(GetProcessHeap(),0,keypath);
4041 HeapFree(GetProcessHeap(), 0, productcode);
4047 static UINT ACTION_RegisterTypeLibraries(MSIPACKAGE *package)
4050 * OK this is a bit confusing.. I am given a _Component key and I believe
4051 * that the file that is being registered as a type library is the "key file
4052 * of that component" which I interpret to mean "The file in the KeyPath of
4057 MSIRECORD * row = 0;
4058 static const WCHAR Query[] = {
4059 'S','E','L','E','C','T',' ','*',' ',
4060 'f','r','o','m',' ','T','y','p','e','L','i','b',0};
4065 return ERROR_INVALID_HANDLE;
4067 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4068 if (rc != ERROR_SUCCESS)
4069 return ERROR_SUCCESS;
4071 rc = MSI_ViewExecute(view, 0);
4072 if (rc != ERROR_SUCCESS)
4074 MSI_ViewClose(view);
4075 msiobj_release(&view->hdr);
4081 WCHAR component[0x100];
4085 rc = MSI_ViewFetch(view,&row);
4086 if (rc != ERROR_SUCCESS)
4093 MSI_RecordGetStringW(row,3,component,&sz);
4095 index = get_loaded_component(package,component);
4098 msiobj_release(&row->hdr);
4102 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
4104 TRACE("Skipping typelib reg due to disabled component\n");
4105 msiobj_release(&row->hdr);
4109 index = get_loaded_file(package,package->components[index].KeyPath);
4113 msiobj_release(&row->hdr);
4117 res = LoadTypeLib(package->files[index].TargetPath,&ptLib);
4121 WCHAR helpid[0x100];
4124 MSI_RecordGetStringW(row,6,helpid,&sz);
4126 help = resolve_folder(package,helpid,FALSE,FALSE,NULL);
4127 res = RegisterTypeLib(ptLib,package->files[index].TargetPath,help);
4128 HeapFree(GetProcessHeap(),0,help);
4130 if (!SUCCEEDED(res))
4131 ERR("Failed to register type library %s\n",
4132 debugstr_w(package->files[index].TargetPath));
4135 /* Yes the row has more fields than I need, but #1 is
4136 correct and the only one I need. Why make a new row? */
4138 ui_actiondata(package,szRegisterTypeLibraries,row);
4140 TRACE("Registered %s\n",
4141 debugstr_w(package->files[index].TargetPath));
4145 ITypeLib_Release(ptLib);
4148 ERR("Failed to load type library %s\n",
4149 debugstr_w(package->files[index].TargetPath));
4151 msiobj_release(&row->hdr);
4153 MSI_ViewClose(view);
4154 msiobj_release(&view->hdr);
4159 static UINT register_appid(MSIPACKAGE *package, LPCWSTR clsid, LPCWSTR app )
4161 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4164 MSIRECORD * row = 0;
4165 static const WCHAR ExecSeqQuery[] =
4166 {'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ','A','p','p','I'
4167 ,'d',' ','w','h','e','r','e',' ','A','p','p','I','d','=','`','%','s','`',0};
4172 return ERROR_INVALID_HANDLE;
4174 rc = ACTION_OpenQuery(package->db, &view, ExecSeqQuery, clsid);
4175 if (rc != ERROR_SUCCESS)
4178 rc = MSI_ViewExecute(view, 0);
4179 if (rc != ERROR_SUCCESS)
4181 MSI_ViewClose(view);
4182 msiobj_release(&view->hdr);
4186 RegCreateKeyW(HKEY_CLASSES_ROOT,szAppID,&hkey2);
4187 RegCreateKeyW(hkey2,clsid,&hkey3);
4188 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)app,
4189 (strlenW(app)+1)*sizeof(WCHAR));
4191 rc = MSI_ViewFetch(view,&row);
4192 if (rc != ERROR_SUCCESS)
4194 MSI_ViewClose(view);
4195 msiobj_release(&view->hdr);
4199 if (!MSI_RecordIsNull(row,2))
4201 LPWSTR deformated=0;
4203 static const WCHAR szRemoteServerName[] =
4204 {'R','e','m','o','t','e','S','e','r','v','e','r','N','a','m','e',0};
4205 buffer = load_dynamic_stringW(row,2);
4206 size = deformat_string(package,buffer,&deformated);
4207 RegSetValueExW(hkey3,szRemoteServerName,0,REG_SZ,(LPVOID)deformated,
4209 HeapFree(GetProcessHeap(),0,deformated);
4210 HeapFree(GetProcessHeap(),0,buffer);
4213 if (!MSI_RecordIsNull(row,3))
4215 static const WCHAR szLocalService[] =
4216 {'L','o','c','a','l','S','e','r','v','i','c','e',0};
4218 buffer = load_dynamic_stringW(row,3);
4219 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4220 RegSetValueExW(hkey3,szLocalService,0,REG_SZ,(LPVOID)buffer,size);
4221 HeapFree(GetProcessHeap(),0,buffer);
4224 if (!MSI_RecordIsNull(row,4))
4226 static const WCHAR szService[] =
4227 {'S','e','r','v','i','c','e','P','a','r','a','m','e','t','e','r','s',0};
4229 buffer = load_dynamic_stringW(row,4);
4230 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4231 RegSetValueExW(hkey3,szService,0,REG_SZ,(LPVOID)buffer,size);
4232 HeapFree(GetProcessHeap(),0,buffer);
4235 if (!MSI_RecordIsNull(row,5))
4237 static const WCHAR szDLL[] =
4238 {'D','l','l','S','u','r','r','o','g','a','t','e',0};
4240 buffer = load_dynamic_stringW(row,5);
4241 size = (strlenW(buffer)+1) * sizeof(WCHAR);
4242 RegSetValueExW(hkey3,szDLL,0,REG_SZ,(LPVOID)buffer,size);
4243 HeapFree(GetProcessHeap(),0,buffer);
4246 if (!MSI_RecordIsNull(row,6))
4248 static const WCHAR szActivate[] =
4249 {'A','c','t','i','v','a','t','e','A','s','S','t','o','r','a','g','e',0};
4250 static const WCHAR szY[] = {'Y',0};
4252 if (MSI_RecordGetInteger(row,6))
4253 RegSetValueExW(hkey3,szActivate,0,REG_SZ,(LPVOID)szY,4);
4256 if (!MSI_RecordIsNull(row,7))
4258 static const WCHAR szRunAs[] = {'R','u','n','A','s',0};
4259 static const WCHAR szUser[] =
4260 {'I','n','t','e','r','a','c','t','i','v','e',' ','U','s','e','r',0};
4262 if (MSI_RecordGetInteger(row,7))
4263 RegSetValueExW(hkey3,szRunAs,0,REG_SZ,(LPVOID)szUser,34);
4266 msiobj_release(&row->hdr);
4267 MSI_ViewClose(view);
4268 msiobj_release(&view->hdr);
4274 static UINT ACTION_RegisterClassInfo(MSIPACKAGE *package)
4277 * Again I am assuming the words, "Whose key file represents" when referring
4278 * to a Component as to meaning that Components KeyPath file
4280 * Also there is a very strong connection between ClassInfo and ProgID
4281 * that I am mostly glossing over.
4282 * What would be more propper is to load the ClassInfo and the ProgID info
4283 * into memory data structures and then be able to enable and disable them
4284 * based on component.
4289 MSIRECORD * row = 0;
4290 static const WCHAR ExecSeqQuery[] = {
4291 'S','E','L','E','C','T',' ','*',' ',
4292 'f','r','o','m',' ','C','l','a','s','s',0};
4293 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4294 static const WCHAR szProgID[] = { 'P','r','o','g','I','D',0 };
4295 static const WCHAR szAppID[] = { 'A','p','p','I','D',0 };
4296 HKEY hkey,hkey2,hkey3;
4299 return ERROR_INVALID_HANDLE;
4301 rc = RegCreateKeyW(HKEY_CLASSES_ROOT,szCLSID,&hkey);
4302 if (rc != ERROR_SUCCESS)
4303 return ERROR_FUNCTION_FAILED;
4305 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4306 if (rc != ERROR_SUCCESS)
4312 rc = MSI_ViewExecute(view, 0);
4313 if (rc != ERROR_SUCCESS)
4315 MSI_ViewClose(view);
4316 msiobj_release(&view->hdr);
4323 WCHAR buffer[0x100];
4328 rc = MSI_ViewFetch(view,&row);
4329 if (rc != ERROR_SUCCESS)
4336 MSI_RecordGetStringW(row,3,buffer,&sz);
4338 index = get_loaded_component(package,buffer);
4342 msiobj_release(&row->hdr);
4346 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
4348 TRACE("Skipping class reg due to disabled component\n");
4349 msiobj_release(&row->hdr);
4354 MSI_RecordGetStringW(row,1,clsid,&sz);
4355 RegCreateKeyW(hkey,clsid,&hkey2);
4357 if (!MSI_RecordIsNull(row,5))
4360 MSI_RecordGetStringW(row,5,desc,&sz);
4362 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)desc,
4363 (strlenW(desc)+1)*sizeof(WCHAR));
4369 MSI_RecordGetStringW(row,2,buffer,&sz);
4371 RegCreateKeyW(hkey2,buffer,&hkey3);
4373 index = get_loaded_file(package,package->components[index].KeyPath);
4374 RegSetValueExW(hkey3,NULL,0,REG_SZ,
4375 (LPVOID)package->files[index].TargetPath,
4376 (strlenW(package->files[index].TargetPath)+1)
4381 if (!MSI_RecordIsNull(row,4))
4384 MSI_RecordGetStringW(row,4,buffer,&sz);
4386 RegCreateKeyW(hkey2,szProgID,&hkey3);
4388 RegSetValueExW(hkey3,NULL,0,REG_SZ,(LPVOID)buffer,
4389 (strlenW(buffer)+1)*sizeof(WCHAR));
4394 if (!MSI_RecordIsNull(row,6))
4397 MSI_RecordGetStringW(row,6,buffer,&sz);
4399 RegSetValueExW(hkey2,szAppID,0,REG_SZ,(LPVOID)buffer,
4400 (strlenW(buffer)+1)*sizeof(WCHAR));
4402 register_appid(package,buffer,desc);
4407 FIXME("Process the rest of the fields >7\n");
4409 ui_actiondata(package,szRegisterClassInfo,row);
4411 msiobj_release(&row->hdr);
4413 MSI_ViewClose(view);
4414 msiobj_release(&view->hdr);
4421 static UINT register_progid_base(MSIRECORD * row, LPWSTR clsid)
4423 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4425 WCHAR buffer[0x100];
4430 MSI_RecordGetStringW(row,1,buffer,&sz);
4431 RegCreateKeyW(HKEY_CLASSES_ROOT,buffer,&hkey);
4433 if (!MSI_RecordIsNull(row,4))
4436 MSI_RecordGetStringW(row,4,buffer,&sz);
4437 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4441 if (!MSI_RecordIsNull(row,3))
4445 MSI_RecordGetStringW(row,3,buffer,&sz);
4446 RegCreateKeyW(hkey,szCLSID,&hkey2);
4447 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)buffer, (strlenW(buffer)+1) *
4451 strcpyW(clsid,buffer);
4457 FIXME("UNHANDLED case, Parent progid but classid is NULL\n");
4458 return ERROR_FUNCTION_FAILED;
4460 if (!MSI_RecordIsNull(row,5))
4461 FIXME ("UNHANDLED icon in Progid\n");
4462 return ERROR_SUCCESS;
4465 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid);
4467 static UINT register_parent_progid(MSIPACKAGE *package, LPCWSTR parent,
4472 MSIRECORD * row = 0;
4473 static const WCHAR Query_t[] =
4474 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','P','r','o','g'
4475 ,'I','d',' ','w','h','e','r','e',' ','P','r','o','g','I','d',' ','=',' ','`'
4479 return ERROR_INVALID_HANDLE;
4481 rc = ACTION_OpenQuery(package->db, &view, Query_t, parent);
4482 if (rc != ERROR_SUCCESS)
4485 rc = MSI_ViewExecute(view, 0);
4486 if (rc != ERROR_SUCCESS)
4488 MSI_ViewClose(view);
4489 msiobj_release(&view->hdr);
4493 rc = MSI_ViewFetch(view,&row);
4494 if (rc != ERROR_SUCCESS)
4496 MSI_ViewClose(view);
4497 msiobj_release(&view->hdr);
4501 register_progid(package,row,clsid);
4503 msiobj_release(&row->hdr);
4504 MSI_ViewClose(view);
4505 msiobj_release(&view->hdr);
4509 static UINT register_progid(MSIPACKAGE *package, MSIRECORD * row, LPWSTR clsid)
4511 UINT rc = ERROR_SUCCESS;
4513 if (MSI_RecordIsNull(row,2))
4514 rc = register_progid_base(row,clsid);
4517 WCHAR buffer[0x1000];
4520 static const WCHAR szCLSID[] = { 'C','L','S','I','D',0 };
4522 /* check if already registered */
4524 MSI_RecordGetStringW(row,1,buffer,&sz);
4525 RegCreateKeyExW(HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4526 KEY_ALL_ACCESS, NULL, &hkey, &disp );
4527 if (disp == REG_OPENED_EXISTING_KEY)
4529 TRACE("Key already registered\n");
4533 /* clsid is same as parent */
4534 RegCreateKeyW(hkey,szCLSID,&hkey2);
4535 RegSetValueExW(hkey2,NULL,0,REG_SZ,(LPVOID)clsid, (strlenW(clsid)+1) *
4541 MSI_RecordGetStringW(row,2,buffer,&sz);
4542 rc = register_parent_progid(package,buffer,clsid);
4544 if (!MSI_RecordIsNull(row,4))
4547 MSI_RecordGetStringW(row,4,buffer,&sz);
4548 RegSetValueExW(hkey,NULL,0,REG_SZ,(LPVOID)buffer,
4549 (strlenW(buffer)+1) * sizeof(WCHAR));
4552 if (!MSI_RecordIsNull(row,5))
4553 FIXME ("UNHANDLED icon in Progid\n");
4560 static UINT ACTION_RegisterProgIdInfo(MSIPACKAGE *package)
4563 * Sigh, here I am just brute force registering all progids
4564 * this needs to be linked to the Classes that have been registered
4565 * but the easiest way to do that is to load all these stuff into
4566 * memory for easy checking.
4568 * Gives me something to continue to work toward.
4572 MSIRECORD * row = 0;
4573 static const WCHAR Query[] = {
4574 'S','E','L','E','C','T',' ','*',' ',
4575 'F','R','O','M',' ','P','r','o','g','I','d',0};
4578 return ERROR_INVALID_HANDLE;
4580 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4581 if (rc != ERROR_SUCCESS)
4582 return ERROR_SUCCESS;
4584 rc = MSI_ViewExecute(view, 0);
4585 if (rc != ERROR_SUCCESS)
4587 MSI_ViewClose(view);
4588 msiobj_release(&view->hdr);
4594 WCHAR clsid[0x1000];
4596 rc = MSI_ViewFetch(view,&row);
4597 if (rc != ERROR_SUCCESS)
4603 register_progid(package,row,clsid);
4604 ui_actiondata(package,szRegisterProgIdInfo,row);
4606 msiobj_release(&row->hdr);
4608 MSI_ViewClose(view);
4609 msiobj_release(&view->hdr);
4613 static UINT build_icon_path(MSIPACKAGE *package, LPCWSTR icon_name,
4617 LPWSTR SystemFolder;
4621 static const WCHAR szInstaller[] =
4622 {'I','n','s','t','a','l','l','e','r','\\',0};
4623 static const WCHAR szProductCode[] =
4624 {'P','r','o','d','u','c','t','C','o','d','e',0};
4625 static const WCHAR szFolder[] =
4626 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4628 ProductCode = load_dynamic_property(package,szProductCode,&rc);
4632 SystemFolder = load_dynamic_property(package,szFolder,NULL);
4634 dest = build_directory_name(3, SystemFolder, szInstaller, ProductCode);
4636 create_full_pathW(dest);
4638 *FilePath = build_directory_name(2, dest, icon_name);
4640 HeapFree(GetProcessHeap(),0,SystemFolder);
4641 HeapFree(GetProcessHeap(),0,ProductCode);
4642 HeapFree(GetProcessHeap(),0,dest);
4643 return ERROR_SUCCESS;
4646 static UINT ACTION_CreateShortcuts(MSIPACKAGE *package)
4650 MSIRECORD * row = 0;
4651 static const WCHAR Query[] = {
4652 'S','E','L','E','C','T',' ','*',' ','f','r','o','m',' ',
4653 'S','h','o','r','t','c','u','t',0};
4659 return ERROR_INVALID_HANDLE;
4661 res = CoInitialize( NULL );
4664 ERR("CoInitialize failed\n");
4665 return ERROR_FUNCTION_FAILED;
4668 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4669 if (rc != ERROR_SUCCESS)
4670 return ERROR_SUCCESS;
4672 rc = MSI_ViewExecute(view, 0);
4673 if (rc != ERROR_SUCCESS)
4675 MSI_ViewClose(view);
4676 msiobj_release(&view->hdr);
4682 LPWSTR target_file, target_folder;
4683 WCHAR buffer[0x100];
4686 static const WCHAR szlnk[]={'.','l','n','k',0};
4688 rc = MSI_ViewFetch(view,&row);
4689 if (rc != ERROR_SUCCESS)
4696 MSI_RecordGetStringW(row,4,buffer,&sz);
4698 index = get_loaded_component(package,buffer);
4702 msiobj_release(&row->hdr);
4706 if (package->components[index].ActionRequest != INSTALLSTATE_LOCAL)
4708 TRACE("Skipping shortcut creation due to disabled component\n");
4709 msiobj_release(&row->hdr);
4713 ui_actiondata(package,szCreateShortcuts,row);
4715 res = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
4716 &IID_IShellLinkW, (LPVOID *) &sl );
4720 ERR("Is IID_IShellLink\n");
4721 msiobj_release(&row->hdr);
4725 res = IShellLinkW_QueryInterface( sl, &IID_IPersistFile,(LPVOID*) &pf );
4728 ERR("Is IID_IPersistFile\n");
4729 msiobj_release(&row->hdr);
4734 MSI_RecordGetStringW(row,2,buffer,&sz);
4735 target_folder = resolve_folder(package, buffer,FALSE,FALSE,NULL);
4737 /* may be needed because of a bug somehwere else */
4738 create_full_pathW(target_folder);
4741 MSI_RecordGetStringW(row,3,buffer,&sz);
4742 reduce_to_longfilename(buffer);
4743 if (!strchrW(buffer,'.') || strcmpiW(strchrW(buffer,'.'),szlnk))
4744 strcatW(buffer,szlnk);
4745 target_file = build_directory_name(2, target_folder, buffer);
4746 HeapFree(GetProcessHeap(),0,target_folder);
4749 MSI_RecordGetStringW(row,5,buffer,&sz);
4750 if (strchrW(buffer,'['))
4753 deformat_string(package,buffer,&deformated);
4754 IShellLinkW_SetPath(sl,deformated);
4755 HeapFree(GetProcessHeap(),0,deformated);
4759 FIXME("UNHANDLED shortcut format, advertised shortcut\n");
4760 IPersistFile_Release( pf );
4761 IShellLinkW_Release( sl );
4762 msiobj_release(&row->hdr);
4766 if (!MSI_RecordIsNull(row,6))
4770 MSI_RecordGetStringW(row,6,buffer,&sz);
4771 deformat_string(package,buffer,&deformated);
4772 IShellLinkW_SetArguments(sl,deformated);
4773 HeapFree(GetProcessHeap(),0,deformated);
4776 if (!MSI_RecordIsNull(row,7))
4779 deformated = load_dynamic_stringW(row,7);
4780 IShellLinkW_SetDescription(sl,deformated);
4781 HeapFree(GetProcessHeap(),0,deformated);
4784 if (!MSI_RecordIsNull(row,8))
4785 IShellLinkW_SetHotkey(sl,MSI_RecordGetInteger(row,8));
4787 if (!MSI_RecordIsNull(row,9))
4793 MSI_RecordGetStringW(row,9,buffer,&sz);
4795 build_icon_path(package,buffer,&Path);
4796 index = MSI_RecordGetInteger(row,10);
4798 IShellLinkW_SetIconLocation(sl,Path,index);
4799 HeapFree(GetProcessHeap(),0,Path);
4802 if (!MSI_RecordIsNull(row,11))
4803 IShellLinkW_SetShowCmd(sl,MSI_RecordGetInteger(row,11));
4805 if (!MSI_RecordIsNull(row,12))
4809 MSI_RecordGetStringW(row,12,buffer,&sz);
4810 Path = resolve_folder(package, buffer, FALSE, FALSE, NULL);
4811 IShellLinkW_SetWorkingDirectory(sl,Path);
4812 HeapFree(GetProcessHeap(), 0, Path);
4815 TRACE("Writing shortcut to %s\n",debugstr_w(target_file));
4816 IPersistFile_Save(pf,target_file,FALSE);
4818 HeapFree(GetProcessHeap(),0,target_file);
4820 IPersistFile_Release( pf );
4821 IShellLinkW_Release( sl );
4823 msiobj_release(&row->hdr);
4825 MSI_ViewClose(view);
4826 msiobj_release(&view->hdr);
4836 * 99% of the work done here is only done for
4837 * advertised installs. However this is where the
4838 * Icon table is processed and written out
4839 * so that is what I am going to do here.
4841 static UINT ACTION_PublishProduct(MSIPACKAGE *package)
4845 MSIRECORD * row = 0;
4846 static const WCHAR Query[]={
4847 'S','E','L','E','C','T',' ','*',' ',
4848 'f','r','o','m',' ','I','c','o','n',0};
4852 return ERROR_INVALID_HANDLE;
4854 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
4855 if (rc != ERROR_SUCCESS)
4856 return ERROR_SUCCESS;
4858 rc = MSI_ViewExecute(view, 0);
4859 if (rc != ERROR_SUCCESS)
4861 MSI_ViewClose(view);
4862 msiobj_release(&view->hdr);
4869 WCHAR *FilePath=NULL;
4870 WCHAR *FileName=NULL;
4873 rc = MSI_ViewFetch(view,&row);
4874 if (rc != ERROR_SUCCESS)
4880 FileName = load_dynamic_stringW(row,1);
4883 ERR("Unable to get FileName\n");
4884 msiobj_release(&row->hdr);
4888 build_icon_path(package,FileName,&FilePath);
4890 HeapFree(GetProcessHeap(),0,FileName);
4892 TRACE("Creating icon file at %s\n",debugstr_w(FilePath));
4894 the_file = CreateFileW(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
4895 FILE_ATTRIBUTE_NORMAL, NULL);
4897 if (the_file == INVALID_HANDLE_VALUE)
4899 ERR("Unable to create file %s\n",debugstr_w(FilePath));
4900 msiobj_release(&row->hdr);
4901 HeapFree(GetProcessHeap(),0,FilePath);
4909 rc = MSI_RecordReadStream(row,2,buffer,&sz);
4910 if (rc != ERROR_SUCCESS)
4912 ERR("Failed to get stream\n");
4913 CloseHandle(the_file);
4914 DeleteFileW(FilePath);
4917 WriteFile(the_file,buffer,sz,&write,NULL);
4918 } while (sz == 1024);
4920 HeapFree(GetProcessHeap(),0,FilePath);
4922 CloseHandle(the_file);
4923 msiobj_release(&row->hdr);
4925 MSI_ViewClose(view);
4926 msiobj_release(&view->hdr);
4931 static UINT ACTION_WriteIniValues(MSIPACKAGE *package)
4935 MSIRECORD * row = 0;
4936 static const WCHAR ExecSeqQuery[] = {'S','e','l','e','c','t',' ','*',
4937 ' ','f','r','o','m',' ','I','n','i','F','i','l','e',0};
4938 static const WCHAR szWindowsFolder[] =
4939 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
4940 static const WCHAR szbs[] = {'\\',0};
4942 rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
4943 if (rc != ERROR_SUCCESS)
4945 TRACE("no IniFile table\n");
4946 return ERROR_SUCCESS;
4949 rc = MSI_ViewExecute(view, 0);
4950 if (rc != ERROR_SUCCESS)
4952 MSI_ViewClose(view);
4953 msiobj_release(&view->hdr);
4959 LPWSTR component,filename,dirproperty,section,key,value,identifier;
4960 LPWSTR deformated_section, deformated_key, deformated_value;
4961 LPWSTR folder, fullname = NULL;
4963 INT component_index,action;
4965 rc = MSI_ViewFetch(view,&row);
4966 if (rc != ERROR_SUCCESS)
4972 component = load_dynamic_stringW(row, 8);
4973 component_index = get_loaded_component(package,component);
4975 HeapFree(GetProcessHeap(),0,component);
4977 if (package->components[component_index].ActionRequest !=
4980 TRACE("Skipping ini file due to disabled component\n");
4981 msiobj_release(&row->hdr);
4985 identifier = load_dynamic_stringW(row,1);
4986 filename = load_dynamic_stringW(row,2);
4987 dirproperty = load_dynamic_stringW(row,3);
4988 section = load_dynamic_stringW(row,4);
4989 key = load_dynamic_stringW(row,5);
4990 value = load_dynamic_stringW(row,6);
4991 action = MSI_RecordGetInteger(row,7);
4993 deformat_string(package,section,&deformated_section);
4994 deformat_string(package,key,&deformated_key);
4995 deformat_string(package,value,&deformated_value);
4999 folder = resolve_folder(package, dirproperty, FALSE, FALSE, NULL);
5001 folder = load_dynamic_property(package,dirproperty,NULL);
5004 folder = load_dynamic_property(package, szWindowsFolder, NULL);
5008 ERR("Unable to resolve folder! (%s)\n",debugstr_w(dirproperty));
5013 fullname = HeapAlloc(GetProcessHeap(),0,
5014 (strlenW(folder)+strlenW(filename)+2)*sizeof(WCHAR));
5016 strcpyW(fullname,folder);
5017 if (fullname[strlenW(folder)] != '\\')
5018 strcatW(fullname,szbs);
5019 strcatW(fullname,filename);
5023 TRACE("Adding value %s to section %s in %s\n",
5024 debugstr_w(deformated_key), debugstr_w(deformated_section),
5025 debugstr_w(fullname));
5026 WritePrivateProfileStringW(deformated_section, deformated_key,
5027 deformated_value, fullname);
5029 else if (action == 1)
5032 GetPrivateProfileStringW(deformated_section, deformated_key, NULL,
5033 returned, 10, fullname);
5034 if (returned[0] == 0)
5036 TRACE("Adding value %s to section %s in %s\n",
5037 debugstr_w(deformated_key), debugstr_w(deformated_section),
5038 debugstr_w(fullname));
5040 WritePrivateProfileStringW(deformated_section, deformated_key,
5041 deformated_value, fullname);
5044 else if (action == 3)
5046 FIXME("Append to existing section not yet implemented\n");
5049 uirow = MSI_CreateRecord(4);
5050 MSI_RecordSetStringW(uirow,1,identifier);
5051 MSI_RecordSetStringW(uirow,2,deformated_section);
5052 MSI_RecordSetStringW(uirow,3,deformated_key);
5053 MSI_RecordSetStringW(uirow,4,deformated_value);
5054 ui_actiondata(package,szWriteIniValues,uirow);
5055 msiobj_release( &uirow->hdr );
5057 HeapFree(GetProcessHeap(),0,identifier);
5058 HeapFree(GetProcessHeap(),0,fullname);
5059 HeapFree(GetProcessHeap(),0,filename);
5060 HeapFree(GetProcessHeap(),0,key);
5061 HeapFree(GetProcessHeap(),0,value);
5062 HeapFree(GetProcessHeap(),0,section);
5063 HeapFree(GetProcessHeap(),0,dirproperty);
5064 HeapFree(GetProcessHeap(),0,folder);
5065 HeapFree(GetProcessHeap(),0,deformated_key);
5066 HeapFree(GetProcessHeap(),0,deformated_value);
5067 HeapFree(GetProcessHeap(),0,deformated_section);
5068 msiobj_release(&row->hdr);
5070 MSI_ViewClose(view);
5071 msiobj_release(&view->hdr);
5075 /* Msi functions that seem appropriate here */
5076 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
5081 TRACE(" exteral attempt at action %s\n",szAction);
5084 return ERROR_FUNCTION_FAILED;
5086 return ERROR_FUNCTION_FAILED;
5088 szwAction = strdupAtoW(szAction);
5091 return ERROR_FUNCTION_FAILED;
5094 rc = MsiDoActionW(hInstall, szwAction);
5095 HeapFree(GetProcessHeap(),0,szwAction);
5099 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
5101 MSIPACKAGE *package;
5102 UINT ret = ERROR_INVALID_HANDLE;
5104 TRACE(" external attempt at action %s \n",debugstr_w(szAction));
5106 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5109 ret = ACTION_PerformAction(package,szAction);
5110 msiobj_release( &package->hdr );
5115 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
5116 LPSTR szPathBuf, DWORD* pcchPathBuf)
5122 TRACE("getting folder %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
5125 return ERROR_FUNCTION_FAILED;
5127 return ERROR_FUNCTION_FAILED;
5129 szwFolder = strdupAtoW(szFolder);
5132 return ERROR_FUNCTION_FAILED;
5134 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
5136 rc = MsiGetTargetPathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
5138 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
5139 *pcchPathBuf, NULL, NULL );
5141 HeapFree(GetProcessHeap(),0,szwFolder);
5142 HeapFree(GetProcessHeap(),0,szwPathBuf);
5147 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
5148 szPathBuf, DWORD* pcchPathBuf)
5151 UINT rc = ERROR_FUNCTION_FAILED;
5152 MSIPACKAGE *package;
5154 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
5156 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5158 return ERROR_INVALID_HANDLE;
5159 path = resolve_folder(package, szFolder, FALSE, FALSE, NULL);
5160 msiobj_release( &package->hdr );
5162 if (path && (strlenW(path) > *pcchPathBuf))
5164 *pcchPathBuf = strlenW(path)+1;
5165 rc = ERROR_MORE_DATA;
5169 *pcchPathBuf = strlenW(path)+1;
5170 strcpyW(szPathBuf,path);
5171 TRACE("Returning Path %s\n",debugstr_w(path));
5174 HeapFree(GetProcessHeap(),0,path);
5180 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder,
5181 LPSTR szPathBuf, DWORD* pcchPathBuf)
5187 TRACE("getting source %s %p %li\n",szFolder,szPathBuf, *pcchPathBuf);
5190 return ERROR_FUNCTION_FAILED;
5192 return ERROR_FUNCTION_FAILED;
5194 szwFolder = strdupAtoW(szFolder);
5196 return ERROR_FUNCTION_FAILED;
5198 szwPathBuf = HeapAlloc( GetProcessHeap(), 0 , *pcchPathBuf * sizeof(WCHAR));
5200 rc = MsiGetSourcePathW(hInstall, szwFolder, szwPathBuf,pcchPathBuf);
5202 WideCharToMultiByte( CP_ACP, 0, szwPathBuf, *pcchPathBuf, szPathBuf,
5203 *pcchPathBuf, NULL, NULL );
5205 HeapFree(GetProcessHeap(),0,szwFolder);
5206 HeapFree(GetProcessHeap(),0,szwPathBuf);
5211 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder, LPWSTR
5212 szPathBuf, DWORD* pcchPathBuf)
5215 UINT rc = ERROR_FUNCTION_FAILED;
5216 MSIPACKAGE *package;
5218 TRACE("(%s %p %li)\n",debugstr_w(szFolder),szPathBuf,*pcchPathBuf);
5220 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5222 return ERROR_INVALID_HANDLE;
5223 path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
5224 msiobj_release( &package->hdr );
5226 if (path && strlenW(path) > *pcchPathBuf)
5228 *pcchPathBuf = strlenW(path)+1;
5229 rc = ERROR_MORE_DATA;
5233 *pcchPathBuf = strlenW(path)+1;
5234 strcpyW(szPathBuf,path);
5235 TRACE("Returning Path %s\n",debugstr_w(path));
5238 HeapFree(GetProcessHeap(),0,path);
5244 UINT WINAPI MsiSetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder,
5245 LPCSTR szFolderPath)
5248 LPWSTR szwFolderPath;
5252 return ERROR_FUNCTION_FAILED;
5254 return ERROR_FUNCTION_FAILED;
5256 szwFolder = strdupAtoW(szFolder);
5258 return ERROR_FUNCTION_FAILED;
5260 szwFolderPath = strdupAtoW(szFolderPath);
5263 HeapFree(GetProcessHeap(),0,szwFolder);
5264 return ERROR_FUNCTION_FAILED;
5267 rc = MsiSetTargetPathW(hInstall, szwFolder, szwFolderPath);
5269 HeapFree(GetProcessHeap(),0,szwFolder);
5270 HeapFree(GetProcessHeap(),0,szwFolderPath);
5275 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder,
5276 LPCWSTR szFolderPath)
5280 LPWSTR path2 = NULL;
5284 TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
5287 return ERROR_INVALID_HANDLE;
5289 if (szFolderPath[0]==0)
5290 return ERROR_FUNCTION_FAILED;
5292 if (GetFileAttributesW(szFolderPath) == INVALID_FILE_ATTRIBUTES)
5293 return ERROR_FUNCTION_FAILED;
5295 path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
5298 return ERROR_INVALID_PARAMETER;
5300 if (folder->Property)
5301 HeapFree(GetProcessHeap(),0,folder->Property);
5303 len = strlenW(szFolderPath);
5305 if (szFolderPath[len-1]!='\\')
5308 folder->Property = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
5309 strcpyW(folder->Property,szFolderPath);
5310 strcatW(folder->Property,cszbs);
5313 folder->Property = dupstrW(szFolderPath);
5315 if (strcmpiW(path, szFolderPath) == 0)
5318 * Resolved Target has not really changed, so just
5319 * set this folder and do not recalculate everything.
5321 HeapFree(GetProcessHeap(),0,folder->ResolvedTarget);
5322 folder->ResolvedTarget = NULL;
5323 path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
5324 HeapFree(GetProcessHeap(),0,path2);
5328 for (i = 0; i < package->loaded_folders; i++)
5330 if (package->folders[i].ResolvedTarget)
5331 HeapFree(GetProcessHeap(),0,package->folders[i].ResolvedTarget);
5332 package->folders[i].ResolvedTarget=NULL;
5335 for (i = 0; i < package->loaded_folders; i++)
5337 path2=resolve_folder(package, package->folders[i].Directory, FALSE,
5339 HeapFree(GetProcessHeap(),0,path2);
5342 HeapFree(GetProcessHeap(),0,path);
5344 return ERROR_SUCCESS;
5347 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder,
5348 LPCWSTR szFolderPath)
5350 MSIPACKAGE *package;
5353 TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
5355 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5356 ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
5357 msiobj_release( &package->hdr );
5361 /***********************************************************************
5362 * MsiGetMode (MSI.@)
5364 * Returns an internal installer state (if it is running in a mode iRunMode)
5367 * hInstall [I] Handle to the installation
5368 * hRunMode [I] Checking run mode
5369 * MSIRUNMODE_ADMIN Administrative mode
5370 * MSIRUNMODE_ADVERTISE Advertisement mode
5371 * MSIRUNMODE_MAINTENANCE Maintenance mode
5372 * MSIRUNMODE_ROLLBACKENABLED Rollback is enabled
5373 * MSIRUNMODE_LOGENABLED Log file is writing
5374 * MSIRUNMODE_OPERATIONS Operations in progress??
5375 * MSIRUNMODE_REBOOTATEND We need to reboot after installation completed
5376 * MSIRUNMODE_REBOOTNOW We need to reboot to continue the installation
5377 * MSIRUNMODE_CABINET Files from cabinet are installed
5378 * MSIRUNMODE_SOURCESHORTNAMES Long names in source files is supressed
5379 * MSIRUNMODE_TARGETSHORTNAMES Long names in destination files is supressed
5380 * MSIRUNMODE_RESERVED11 Reserved
5381 * MSIRUNMODE_WINDOWS9X Running under Windows95/98
5382 * MSIRUNMODE_ZAWENABLED Demand installation is supported
5383 * MSIRUNMODE_RESERVED14 Reserved
5384 * MSIRUNMODE_RESERVED15 Reserved
5385 * MSIRUNMODE_SCHEDULED called from install script
5386 * MSIRUNMODE_ROLLBACK called from rollback script
5387 * MSIRUNMODE_COMMIT called from commit script
5390 * In the state: TRUE
5391 * Not in the state: FALSE
5395 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
5397 FIXME("STUB (iRunMode=%i)\n",iRunMode);
5402 * According to the docs, when this is called it immediately recalculates
5403 * all the component states as well
5405 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
5406 INSTALLSTATE iState)
5408 LPWSTR szwFeature = NULL;
5411 szwFeature = strdupAtoW(szFeature);
5414 return ERROR_FUNCTION_FAILED;
5416 rc = MsiSetFeatureStateW(hInstall,szwFeature, iState);
5418 HeapFree(GetProcessHeap(),0,szwFeature);
5423 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
5424 INSTALLSTATE iState)
5426 MSIPACKAGE* package;
5429 TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
5431 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5433 return ERROR_INVALID_HANDLE;
5435 index = get_loaded_feature(package,szFeature);
5437 return ERROR_UNKNOWN_FEATURE;
5439 package->features[index].ActionRequest= iState;
5441 return ERROR_SUCCESS;
5444 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
5445 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5447 LPWSTR szwFeature = NULL;
5450 szwFeature = strdupAtoW(szFeature);
5452 rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
5454 HeapFree( GetProcessHeap(), 0 , szwFeature);
5459 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
5460 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5464 index = get_loaded_feature(package,szFeature);
5466 return ERROR_UNKNOWN_FEATURE;
5469 *piInstalled = package->features[index].Installed;
5472 *piAction = package->features[index].Action;
5474 TRACE("returning %i %i\n",*piInstalled,*piAction);
5476 return ERROR_SUCCESS;
5479 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
5480 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5482 MSIPACKAGE* package;
5485 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
5488 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5490 return ERROR_INVALID_HANDLE;
5491 ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
5492 msiobj_release( &package->hdr );
5496 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
5497 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5499 LPWSTR szwComponent= NULL;
5502 szwComponent= strdupAtoW(szComponent);
5504 rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
5506 HeapFree( GetProcessHeap(), 0 , szwComponent);
5511 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
5512 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5516 TRACE("%p %s %p %p\n", package, debugstr_w(szComponent), piInstalled,
5519 index = get_loaded_component(package,szComponent);
5521 return ERROR_UNKNOWN_COMPONENT;
5524 *piInstalled = package->components[index].Installed;
5527 *piInstalled = package->components[index].Action;
5529 return ERROR_SUCCESS;
5532 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
5533 INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
5535 MSIPACKAGE* package;
5538 TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
5539 piInstalled, piAction);
5541 package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
5543 return ERROR_INVALID_HANDLE;
5544 ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
5545 msiobj_release( &package->hdr );
5550 static UINT ACTION_Template(MSIPACKAGE *package)
5554 MSIRECORD * row = 0;
5555 static const WCHAR ExecSeqQuery[] = {0};
5557 rc = MsiDatabaseOpenViewW(package->db, ExecSeqQuery, &view);
5558 if (rc != ERROR_SUCCESS)
5561 rc = MsiViewExecute(view, 0);
5562 if (rc != ERROR_SUCCESS)
5565 msiobj_release(&view->hdr);
5571 rc = MsiViewFetch(view,&row);
5572 if (rc != ERROR_SUCCESS)
5578 msiobj_release(&row->hdr);
5581 msiobj_release(&view->hdr);