wined3d: Implement more GLSL instructions and a little cleanup.
[wine] / dlls / msi / install.c
1 /*
2  * Implementation of the Microsoft Installer (msi.dll)
3  *
4  * Copyright 2005 Aric Stewart for CodeWeavers
5  *
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.
10  *
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.
15  *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 /* Msi top level apis directly related to installs */
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "wine/debug.h"
29 #include "msi.h"
30 #include "msidefs.h"
31 #include "msipriv.h"
32 #include "winuser.h"
33 #include "wine/unicode.h"
34 #include "action.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(msi);
37
38 /***********************************************************************
39  * MsiDoActionA       (MSI.@)
40  */
41 UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
42 {
43     LPWSTR szwAction;
44     UINT ret;
45
46     TRACE("%s\n", debugstr_a(szAction));
47
48     szwAction = strdupAtoW(szAction);
49     if (szAction && !szwAction)
50         return ERROR_FUNCTION_FAILED; 
51
52     ret = MsiDoActionW( hInstall, szwAction );
53     msi_free( szwAction );
54     return ret;
55 }
56
57 /***********************************************************************
58  * MsiDoActionW       (MSI.@)
59  */
60 UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
61 {
62     MSIPACKAGE *package;
63     UINT ret;
64
65     TRACE("%s\n",debugstr_w(szAction));
66
67     if (!szAction)
68         return ERROR_INVALID_PARAMETER;
69
70     package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
71     if (!package)
72         return ERROR_INVALID_HANDLE;
73  
74     ret = ACTION_PerformUIAction( package, szAction );
75     msiobj_release( &package->hdr );
76
77     return ret;
78 }
79
80 /***********************************************************************
81  * MsiSequenceA       (MSI.@)
82  */
83 UINT WINAPI MsiSequenceA( MSIHANDLE hInstall, LPCSTR szTable, INT iSequenceMode )
84 {
85     LPWSTR szwTable;
86     UINT ret;
87
88     TRACE("%s\n", debugstr_a(szTable));
89
90     szwTable = strdupAtoW(szTable);
91     if (szTable && !szwTable)
92         return ERROR_FUNCTION_FAILED; 
93
94     ret = MsiSequenceW( hInstall, szwTable, iSequenceMode );
95     msi_free( szwTable );
96     return ret;
97 }
98
99 /***********************************************************************
100  * MsiSequenceW       (MSI.@)
101  */
102 UINT WINAPI MsiSequenceW( MSIHANDLE hInstall, LPCWSTR szTable, INT iSequenceMode )
103 {
104     MSIPACKAGE *package;
105     UINT ret;
106
107     TRACE("%s\n", debugstr_w(szTable));
108
109     package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
110     if (!package)
111         return ERROR_INVALID_HANDLE;
112
113     ret = MSI_Sequence( package, szTable, iSequenceMode );
114     msiobj_release( &package->hdr );
115  
116     return ret;
117 }
118
119 UINT msi_strcpy_to_awstring( LPCWSTR str, awstring *awbuf, DWORD *sz )
120 {
121     UINT len, r = ERROR_SUCCESS;
122
123     if (awbuf->str.w && !sz )
124         return ERROR_INVALID_PARAMETER;
125
126     if (!sz)
127         return r;
128  
129     if (awbuf->unicode)
130     {
131         len = lstrlenW( str );
132         if (awbuf->str.w) 
133             lstrcpynW( awbuf->str.w, str, *sz );
134     }
135     else
136     {
137         len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
138         if (len)
139             len--;
140         WideCharToMultiByte( CP_ACP, 0, str, -1, awbuf->str.a, *sz, NULL, NULL );
141         if ( *sz && (len >= *sz) )
142             awbuf->str.a[*sz - 1] = 0;
143     }
144
145     if (awbuf->str.w && len >= *sz)
146         r = ERROR_MORE_DATA;
147     *sz = len;
148     return r;
149 }
150
151 /***********************************************************************
152  * MsiGetTargetPath   (internal)
153  */
154 UINT WINAPI MSI_GetTargetPath( MSIHANDLE hInstall, LPCWSTR szFolder,
155                                awstring *szPathBuf, DWORD* pcchPathBuf )
156 {
157     MSIPACKAGE *package;
158     LPWSTR path;
159     UINT r;
160
161     if (!szFolder)
162         return ERROR_INVALID_PARAMETER;
163
164     package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
165     if (!package)
166         return ERROR_INVALID_HANDLE;
167
168     path = resolve_folder( package, szFolder, FALSE, FALSE, NULL );
169     msiobj_release( &package->hdr );
170
171     if (!path)
172         return ERROR_DIRECTORY;
173
174     r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
175     msi_free( path );
176     return r;
177 }
178
179 /***********************************************************************
180  * MsiGetTargetPathA        (MSI.@)
181  */
182 UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder, 
183                                LPSTR szPathBuf, DWORD* pcchPathBuf )
184 {
185     LPWSTR szwFolder;
186     awstring path;
187     UINT r;
188
189     TRACE("%s %p %p\n", debugstr_a(szFolder), szPathBuf, pcchPathBuf);
190
191     szwFolder = strdupAtoW(szFolder);
192     if (szFolder && !szwFolder)
193         return ERROR_FUNCTION_FAILED; 
194
195     path.unicode = FALSE;
196     path.str.a = szPathBuf;
197
198     r = MSI_GetTargetPath( hInstall, szwFolder, &path, pcchPathBuf );
199
200     msi_free( szwFolder );
201
202     return r;
203 }
204
205 /***********************************************************************
206  * MsiGetTargetPathW        (MSI.@)
207  */
208 UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder,
209                                LPWSTR szPathBuf, DWORD* pcchPathBuf )
210 {
211     awstring path;
212
213     TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf);
214
215     path.unicode = TRUE;
216     path.str.w = szPathBuf;
217
218     return MSI_GetTargetPath( hInstall, szFolder, &path, pcchPathBuf );
219 }
220
221 /***********************************************************************
222  * MsiGetSourcePath   (internal)
223  */
224 static UINT MSI_GetSourcePath( MSIHANDLE hInstall, LPCWSTR szFolder,
225                                awstring *szPathBuf, DWORD* pcchPathBuf )
226 {
227     MSIPACKAGE *package;
228     LPWSTR path;
229     UINT r;
230
231     TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
232
233     if (!szFolder)
234         return ERROR_INVALID_PARAMETER;
235
236     package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
237     if (!package)
238         return ERROR_INVALID_HANDLE;
239
240     if (szPathBuf->str.w && !pcchPathBuf )
241     {
242         msiobj_release( &package->hdr );
243         return ERROR_INVALID_PARAMETER;
244     }
245
246     path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
247     msiobj_release( &package->hdr );
248
249     TRACE("path = %s\n",debugstr_w(path));
250     if (!path)
251         return ERROR_DIRECTORY;
252
253     r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
254     msi_free( path );
255     return r;
256 }
257
258 /***********************************************************************
259  * MsiGetSourcePathA     (MSI.@)
260  */
261 UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder, 
262                                LPSTR szPathBuf, DWORD* pcchPathBuf )
263 {
264     LPWSTR folder;
265     awstring str;
266     UINT r;
267
268     TRACE("%s %p %p\n", szFolder, debugstr_a(szPathBuf), pcchPathBuf);
269
270     str.unicode = FALSE;
271     str.str.a = szPathBuf;
272
273     folder = strdupAtoW( szFolder );
274     r = MSI_GetSourcePath( hInstall, folder, &str, pcchPathBuf );
275     msi_free( folder );
276
277     return r;
278 }
279
280 /***********************************************************************
281  * MsiGetSourcePathW     (MSI.@)
282  */
283 UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder,
284                                LPWSTR szPathBuf, DWORD* pcchPathBuf )
285 {
286     awstring str;
287
288     TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
289
290     str.unicode = TRUE;
291     str.str.w = szPathBuf;
292
293     return MSI_GetSourcePath( hInstall, szFolder, &str, pcchPathBuf );
294 }
295
296 /***********************************************************************
297  * MsiSetTargetPathA  (MSI.@)
298  */
299 UINT WINAPI MsiSetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
300                                LPCSTR szFolderPath )
301 {
302     LPWSTR szwFolder = NULL, szwFolderPath = NULL;
303     UINT rc = ERROR_OUTOFMEMORY;
304
305     if ( !szFolder || !szFolderPath )
306         return ERROR_INVALID_PARAMETER;
307
308     szwFolder = strdupAtoW(szFolder);
309     szwFolderPath = strdupAtoW(szFolderPath);
310     if (!szwFolder || !szwFolderPath)
311         goto end;
312
313     rc = MsiSetTargetPathW( hInstall, szwFolder, szwFolderPath );
314
315 end:
316     msi_free(szwFolder);
317     msi_free(szwFolderPath);
318
319     return rc;
320 }
321
322 /*
323  * Ok my original interpretation of this was wrong. And it looks like msdn has
324  * changed a bit also. The given folder path does not have to actually already
325  * exist, it just cannot be read only and must be a legal folder path.
326  */
327 UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder, 
328                              LPCWSTR szFolderPath)
329 {
330     DWORD attrib;
331     LPWSTR path = NULL;
332     LPWSTR path2 = NULL;
333     MSIFOLDER *folder;
334
335     TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));
336
337     attrib = GetFileAttributesW(szFolderPath);
338     if ( attrib != INVALID_FILE_ATTRIBUTES &&
339           (attrib & FILE_ATTRIBUTE_OFFLINE ||
340            attrib & FILE_ATTRIBUTE_READONLY)) /* actually native MSI tests writeability by making temporary files at each drive */
341         return ERROR_FUNCTION_FAILED;
342
343     path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
344     if (!path)
345         return ERROR_DIRECTORY;
346
347
348     msi_free(folder->Property);
349     folder->Property = build_directory_name(2, szFolderPath, NULL);
350
351     if (lstrcmpiW(path, folder->Property) == 0)
352     {
353         /*
354          *  Resolved Target has not really changed, so just 
355          *  set this folder and do not recalculate everything.
356          */
357         msi_free(folder->ResolvedTarget);
358         folder->ResolvedTarget = NULL;
359         path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
360         msi_free(path2);
361     }
362     else
363     {
364         MSIFOLDER *f;
365
366         LIST_FOR_EACH_ENTRY( f, &package->folders, MSIFOLDER, entry )
367         {
368             msi_free(f->ResolvedTarget);
369             f->ResolvedTarget=NULL;
370         }
371
372         LIST_FOR_EACH_ENTRY( f, &package->folders, MSIFOLDER, entry )
373         {
374             path2 = resolve_folder(package, f->Directory, FALSE, TRUE, NULL);
375             msi_free(path2);
376         }
377     }
378     msi_free(path);
379
380     return ERROR_SUCCESS;
381 }
382
383 /***********************************************************************
384  * MsiSetTargetPathW  (MSI.@)
385  */
386 UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder, 
387                              LPCWSTR szFolderPath)
388 {
389     MSIPACKAGE *package;
390     UINT ret;
391
392     TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));
393
394     if ( !szFolder || !szFolderPath )
395         return ERROR_INVALID_PARAMETER;
396
397     package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
398     if (!package)
399         return ERROR_INVALID_HANDLE;
400
401     ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
402     msiobj_release( &package->hdr );
403     return ret;
404 }
405
406 /***********************************************************************
407  *           MsiGetMode    (MSI.@)
408  *
409  * Returns an internal installer state (if it is running in a mode iRunMode)
410  *
411  * PARAMS
412  *   hInstall    [I]  Handle to the installation
413  *   hRunMode    [I]  Checking run mode
414  *        MSIRUNMODE_ADMIN             Administrative mode
415  *        MSIRUNMODE_ADVERTISE         Advertisement mode
416  *        MSIRUNMODE_MAINTENANCE       Maintenance mode
417  *        MSIRUNMODE_ROLLBACKENABLED   Rollback is enabled
418  *        MSIRUNMODE_LOGENABLED        Log file is writing
419  *        MSIRUNMODE_OPERATIONS        Operations in progress??
420  *        MSIRUNMODE_REBOOTATEND       We need to reboot after installation completed
421  *        MSIRUNMODE_REBOOTNOW         We need to reboot to continue the installation
422  *        MSIRUNMODE_CABINET           Files from cabinet are installed
423  *        MSIRUNMODE_SOURCESHORTNAMES  Long names in source files is suppressed
424  *        MSIRUNMODE_TARGETSHORTNAMES  Long names in destination files is suppressed
425  *        MSIRUNMODE_RESERVED11        Reserved
426  *        MSIRUNMODE_WINDOWS9X         Running under Windows95/98
427  *        MSIRUNMODE_ZAWENABLED        Demand installation is supported
428  *        MSIRUNMODE_RESERVED14        Reserved
429  *        MSIRUNMODE_RESERVED15        Reserved
430  *        MSIRUNMODE_SCHEDULED         called from install script
431  *        MSIRUNMODE_ROLLBACK          called from rollback script
432  *        MSIRUNMODE_COMMIT            called from commit script
433  *
434  * RETURNS
435  *    In the state: TRUE
436  *    Not in the state: FALSE
437  *
438  */
439
440 BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
441 {
442     BOOL r = FALSE;
443
444     switch (iRunMode)
445     {
446     case MSIRUNMODE_WINDOWS9X:
447         if (GetVersion() & 0x80000000)
448             r = TRUE;
449         break;
450
451     case MSIRUNMODE_RESERVED11:
452     case MSIRUNMODE_RESERVED14:
453     case MSIRUNMODE_RESERVED15:
454         break;
455
456     case MSIRUNMODE_SCHEDULED:
457     case MSIRUNMODE_ROLLBACK:
458     case MSIRUNMODE_COMMIT:
459         break;
460
461     default:
462         FIXME("%ld %d\n", hInstall, iRunMode);
463         r = TRUE;
464     }
465
466     return r;
467 }
468
469 /***********************************************************************
470  *           MsiSetMode    (MSI.@)
471  */
472 BOOL WINAPI MsiSetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode, BOOL fState)
473 {
474     switch (iRunMode)
475     {
476     case MSIRUNMODE_RESERVED11:
477     case MSIRUNMODE_WINDOWS9X:
478     case MSIRUNMODE_RESERVED14:
479     case MSIRUNMODE_RESERVED15:
480         return FALSE;
481     default:
482         FIXME("%ld %d %d\n", hInstall, iRunMode, fState);
483     }
484     return TRUE;
485 }
486
487 /***********************************************************************
488  * MsiSetFeatureStateA (MSI.@)
489  *
490  * According to the docs, when this is called it immediately recalculates
491  * all the component states as well
492  */
493 UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
494                                 INSTALLSTATE iState)
495 {
496     LPWSTR szwFeature = NULL;
497     UINT rc;
498
499     szwFeature = strdupAtoW(szFeature);
500
501     if (!szwFeature)
502         return ERROR_FUNCTION_FAILED;
503    
504     rc = MsiSetFeatureStateW(hInstall,szwFeature, iState); 
505
506     msi_free(szwFeature);
507
508     return rc;
509 }
510
511
512
513 UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE* package, LPCWSTR szFeature,
514                                 INSTALLSTATE iState)
515 {
516     UINT rc = ERROR_SUCCESS;
517     MSIFEATURE *feature, *child;
518
519     TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
520
521     feature = get_loaded_feature(package,szFeature);
522     if (!feature)
523         return ERROR_UNKNOWN_FEATURE;
524
525     if (iState == INSTALLSTATE_ADVERTISED && 
526         feature->Attributes & msidbFeatureAttributesDisallowAdvertise)
527         return ERROR_FUNCTION_FAILED;
528
529     feature->ActionRequest = iState;
530     feature->Action = iState;
531
532     ACTION_UpdateComponentStates(package,szFeature);
533
534     /* update all the features that are children of this feature */
535     LIST_FOR_EACH_ENTRY( child, &package->features, MSIFEATURE, entry )
536     {
537         if (lstrcmpW(szFeature, child->Feature_Parent) == 0)
538             MSI_SetFeatureStateW(package, child->Feature, iState);
539     }
540     
541     return rc;
542 }
543
544 /***********************************************************************
545  * MsiSetFeatureStateW (MSI.@)
546  */
547 UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
548                                 INSTALLSTATE iState)
549 {
550     MSIPACKAGE* package;
551     UINT rc = ERROR_SUCCESS;
552
553     TRACE(" %s to %i\n",debugstr_w(szFeature), iState);
554
555     package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
556     if (!package)
557         return ERROR_INVALID_HANDLE;
558
559     rc = MSI_SetFeatureStateW(package,szFeature,iState);
560
561     msiobj_release( &package->hdr );
562     return rc;
563 }
564
565 /***********************************************************************
566 * MsiGetFeatureStateA   (MSI.@)
567 */
568 UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
569                   INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
570 {
571     LPWSTR szwFeature = NULL;
572     UINT rc;
573     
574     szwFeature = strdupAtoW(szFeature);
575
576     rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);
577
578     msi_free( szwFeature);
579
580     return rc;
581 }
582
583 UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
584                   INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
585 {
586     MSIFEATURE *feature;
587
588     feature = get_loaded_feature(package,szFeature);
589     if (!feature)
590         return ERROR_UNKNOWN_FEATURE;
591
592     if (piInstalled)
593         *piInstalled = feature->Installed;
594
595     if (piAction)
596         *piAction = feature->Action;
597
598     TRACE("returning %i %i\n", feature->Installed, feature->Action);
599
600     return ERROR_SUCCESS;
601 }
602
603 /***********************************************************************
604 * MsiGetFeatureStateW   (MSI.@)
605 */
606 UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
607                   INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
608 {
609     MSIPACKAGE* package;
610     UINT ret;
611
612     TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
613 piAction);
614
615     package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
616     if (!package)
617         return ERROR_INVALID_HANDLE;
618     ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
619     msiobj_release( &package->hdr );
620     return ret;
621 }
622
623 /***********************************************************************
624  * MsiSetComponentStateA (MSI.@)
625  */
626 UINT WINAPI MsiSetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
627                                   INSTALLSTATE iState)
628 {
629     UINT rc;
630     LPWSTR szwComponent = strdupAtoW(szComponent);
631
632     rc = MsiSetComponentStateW(hInstall, szwComponent, iState);
633
634     msi_free(szwComponent);
635
636     return rc;
637 }
638
639 /***********************************************************************
640  * MsiGetComponentStateA (MSI.@)
641  */
642 UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
643                   INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
644 {
645     LPWSTR szwComponent= NULL;
646     UINT rc;
647     
648     szwComponent= strdupAtoW(szComponent);
649
650     rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);
651
652     msi_free( szwComponent);
653
654     return rc;
655 }
656
657 static UINT MSI_SetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
658                                    INSTALLSTATE iState)
659 {
660     MSICOMPONENT *comp;
661
662     TRACE("%p %s %d\n", package, debugstr_w(szComponent), iState);
663
664     comp = get_loaded_component(package, szComponent);
665     if (!comp)
666         return ERROR_UNKNOWN_COMPONENT;
667
668     comp->Installed = iState;
669
670     return ERROR_SUCCESS;
671 }
672
673 UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
674                   INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
675 {
676     MSICOMPONENT *comp;
677
678     TRACE("%p %s %p %p\n", package, debugstr_w(szComponent),
679            piInstalled, piAction);
680
681     comp = get_loaded_component(package,szComponent);
682     if (!comp)
683         return ERROR_UNKNOWN_COMPONENT;
684
685     if (piInstalled)
686         *piInstalled = comp->Installed;
687
688     if (piAction)
689         *piAction = comp->Action;
690
691     TRACE("states (%i, %i)\n", comp->Installed, comp->Action );
692
693     return ERROR_SUCCESS;
694 }
695
696 /***********************************************************************
697  * MsiSetComponentStateW (MSI.@)
698  */
699 UINT WINAPI MsiSetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
700                                   INSTALLSTATE iState)
701 {
702     MSIPACKAGE* package;
703     UINT ret;
704
705     package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
706     if (!package)
707         return ERROR_INVALID_HANDLE;
708     ret = MSI_SetComponentStateW(package, szComponent, iState);
709     msiobj_release(&package->hdr);
710     return ret;
711 }
712
713 /***********************************************************************
714  * MsiGetComponentStateW (MSI.@)
715  */
716 UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
717                   INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
718 {
719     MSIPACKAGE* package;
720     UINT ret;
721
722     TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
723            piInstalled, piAction);
724
725     package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
726     if (!package)
727         return ERROR_INVALID_HANDLE;
728     ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
729     msiobj_release( &package->hdr );
730     return ret;
731 }
732
733 /***********************************************************************
734  * MsiGetLanguage (MSI.@)
735  */
736 LANGID WINAPI MsiGetLanguage(MSIHANDLE hInstall)
737 {
738     MSIPACKAGE* package;
739     LANGID langid;
740     LPWSTR buffer;
741     static const WCHAR szProductLanguage[] =
742         {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
743     
744     package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
745     if (!package)
746         return ERROR_INVALID_HANDLE;
747
748     buffer = msi_dup_property( package, szProductLanguage );
749     langid = atoiW(buffer);
750
751     msi_free(buffer);
752     msiobj_release (&package->hdr);
753     return langid;
754 }