2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_NO_STATUS
23 #define COM_NO_WINDOWS_H
28 #define NONAMELESSUNION
31 //#include "winbase.h"
34 //#include "shlwapi.h"
35 #include <wine/debug.h>
37 //#include "msiquery.h"
39 //#include "wincrypt.h"
41 //#include "winuser.h"
42 #include <wine/unicode.h>
45 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
48 * These apis are defined in MSI 3.0
51 typedef struct tagMediaInfo
59 static UINT
OpenSourceKey(LPCWSTR szProduct
, HKEY
* key
, DWORD dwOptions
,
60 MSIINSTALLCONTEXT context
, BOOL create
)
63 UINT rc
= ERROR_FUNCTION_FAILED
;
65 if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
67 if (dwOptions
& MSICODE_PATCH
)
68 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
70 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
73 else if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
75 if (dwOptions
& MSICODE_PATCH
)
76 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
78 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
81 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
83 if (dwOptions
& MSICODE_PATCH
)
84 rc
= MSIREG_OpenPatchesKey(szProduct
, &rootkey
, create
);
86 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
90 if (rc
!= ERROR_SUCCESS
)
92 if (dwOptions
& MSICODE_PATCH
)
93 return ERROR_UNKNOWN_PATCH
;
95 return ERROR_UNKNOWN_PRODUCT
;
99 rc
= RegCreateKeyW(rootkey
, szSourceList
, key
);
102 rc
= RegOpenKeyW(rootkey
,szSourceList
, key
);
103 if (rc
!= ERROR_SUCCESS
)
104 rc
= ERROR_BAD_CONFIGURATION
;
110 static UINT
OpenMediaSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
113 static const WCHAR media
[] = {'M','e','d','i','a',0};
116 rc
= RegCreateKeyW(rootkey
, media
, key
);
118 rc
= RegOpenKeyW(rootkey
,media
, key
);
123 static UINT
OpenNetworkSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
126 static const WCHAR net
[] = {'N','e','t',0};
129 rc
= RegCreateKeyW(rootkey
, net
, key
);
131 rc
= RegOpenKeyW(rootkey
, net
, key
);
136 static UINT
OpenURLSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
139 static const WCHAR URL
[] = {'U','R','L',0};
142 rc
= RegCreateKeyW(rootkey
, URL
, key
);
144 rc
= RegOpenKeyW(rootkey
, URL
, key
);
149 /******************************************************************
150 * MsiSourceListEnumMediaDisksA (MSI.@)
152 UINT WINAPI
MsiSourceListEnumMediaDisksA(LPCSTR szProductCodeOrPatchCode
,
153 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
154 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
155 LPSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
156 LPSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
158 LPWSTR product
= NULL
;
159 LPWSTR usersid
= NULL
;
160 LPWSTR volume
= NULL
;
161 LPWSTR prompt
= NULL
;
162 UINT r
= ERROR_INVALID_PARAMETER
;
164 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n", debugstr_a(szProductCodeOrPatchCode
),
165 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, pdwDiskId
,
166 szVolumeLabel
, pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
168 if (szDiskPrompt
&& !pcchDiskPrompt
)
169 return ERROR_INVALID_PARAMETER
;
171 if (szProductCodeOrPatchCode
) product
= strdupAtoW(szProductCodeOrPatchCode
);
172 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
174 /* FIXME: add tests for an invalid format */
177 volume
= msi_alloc(*pcchVolumeLabel
* sizeof(WCHAR
));
180 prompt
= msi_alloc(*pcchDiskPrompt
* sizeof(WCHAR
));
182 if (volume
) *volume
= '\0';
183 if (prompt
) *prompt
= '\0';
184 r
= MsiSourceListEnumMediaDisksW(product
, usersid
, dwContext
, dwOptions
,
185 dwIndex
, pdwDiskId
, volume
, pcchVolumeLabel
,
186 prompt
, pcchDiskPrompt
);
187 if (r
!= ERROR_SUCCESS
)
190 if (szVolumeLabel
&& pcchVolumeLabel
)
191 WideCharToMultiByte(CP_ACP
, 0, volume
, -1, szVolumeLabel
,
192 *pcchVolumeLabel
+ 1, NULL
, NULL
);
195 WideCharToMultiByte(CP_ACP
, 0, prompt
, -1, szDiskPrompt
,
196 *pcchDiskPrompt
+ 1, NULL
, NULL
);
207 /******************************************************************
208 * MsiSourceListEnumMediaDisksW (MSI.@)
210 UINT WINAPI
MsiSourceListEnumMediaDisksW(LPCWSTR szProductCodeOrPatchCode
,
211 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
212 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
213 LPWSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
214 LPWSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
216 WCHAR squished_pc
[GUID_SIZE
];
222 DWORD valuesz
, datasz
= 0;
227 static DWORD index
= 0;
229 static const WCHAR fmt
[] = {'#','%','d',0};
231 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p)\n", debugstr_w(szProductCodeOrPatchCode
),
232 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szVolumeLabel
,
233 pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
235 if (!szProductCodeOrPatchCode
||
236 !squash_guid(szProductCodeOrPatchCode
, squished_pc
))
237 return ERROR_INVALID_PARAMETER
;
239 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
240 return ERROR_INVALID_PARAMETER
;
242 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
243 return ERROR_INVALID_PARAMETER
;
245 if (szDiskPrompt
&& !pcchDiskPrompt
)
246 return ERROR_INVALID_PARAMETER
;
251 if (dwIndex
!= index
)
252 return ERROR_INVALID_PARAMETER
;
254 r
= OpenSourceKey(szProductCodeOrPatchCode
, &source
,
255 dwOptions
, dwContext
, FALSE
);
256 if (r
!= ERROR_SUCCESS
)
259 r
= OpenMediaSubkey(source
, &media
, FALSE
);
260 if (r
!= ERROR_SUCCESS
)
263 return ERROR_NO_MORE_ITEMS
;
266 if (!pcchVolumeLabel
&& !pcchDiskPrompt
)
268 r
= RegEnumValueW(media
, dwIndex
, NULL
, NULL
, NULL
,
273 res
= RegQueryInfoKeyW(media
, NULL
, NULL
, NULL
, NULL
, NULL
,
274 NULL
, &numvals
, &valuesz
, &datasz
, NULL
, NULL
);
275 if (res
!= ERROR_SUCCESS
)
277 r
= ERROR_BAD_CONFIGURATION
;
281 value
= msi_alloc(++valuesz
* sizeof(WCHAR
));
282 data
= msi_alloc(++datasz
* sizeof(WCHAR
));
285 r
= ERROR_OUTOFMEMORY
;
289 r
= RegEnumValueW(media
, dwIndex
, value
, &valuesz
,
290 NULL
, &type
, (LPBYTE
)data
, &datasz
);
291 if (r
!= ERROR_SUCCESS
)
295 *pdwDiskId
= atolW(value
);
298 ptr
= strchrW(data
, ';');
306 if (type
== REG_DWORD
)
308 sprintfW(convert
, fmt
, *data
);
309 size
= lstrlenW(convert
);
313 size
= lstrlenW(data
);
315 if (size
>= *pcchVolumeLabel
)
317 else if (szVolumeLabel
)
318 lstrcpyW(szVolumeLabel
, ptr2
);
320 *pcchVolumeLabel
= size
;
328 if (type
== REG_DWORD
)
330 sprintfW(convert
, fmt
, *ptr
);
331 size
= lstrlenW(convert
);
335 size
= lstrlenW(ptr
);
337 if (size
>= *pcchDiskPrompt
)
339 else if (szDiskPrompt
)
340 lstrcpyW(szDiskPrompt
, ptr
);
342 *pcchDiskPrompt
= size
;
355 /******************************************************************
356 * MsiSourceListEnumSourcesA (MSI.@)
358 UINT WINAPI
MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch
, LPCSTR szUserSid
,
359 MSIINSTALLCONTEXT dwContext
,
360 DWORD dwOptions
, DWORD dwIndex
,
361 LPSTR szSource
, LPDWORD pcchSource
)
363 LPWSTR product
= NULL
;
364 LPWSTR usersid
= NULL
;
365 LPWSTR source
= NULL
;
367 UINT r
= ERROR_INVALID_PARAMETER
;
368 static DWORD index
= 0;
370 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_a(szProductCodeOrPatch
),
371 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
376 if (szSource
&& !pcchSource
)
379 if (dwIndex
!= index
)
382 if (szProductCodeOrPatch
) product
= strdupAtoW(szProductCodeOrPatch
);
383 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
385 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
386 dwIndex
, NULL
, &len
);
387 if (r
!= ERROR_SUCCESS
)
390 source
= msi_alloc(++len
* sizeof(WCHAR
));
393 r
= ERROR_OUTOFMEMORY
;
398 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
399 dwIndex
, source
, &len
);
400 if (r
!= ERROR_SUCCESS
)
403 len
= WideCharToMultiByte(CP_ACP
, 0, source
, -1, NULL
, 0, NULL
, NULL
);
404 if (pcchSource
&& *pcchSource
>= len
)
405 WideCharToMultiByte(CP_ACP
, 0, source
, -1, szSource
, len
, NULL
, NULL
);
410 *pcchSource
= len
- 1;
417 if (r
== ERROR_SUCCESS
)
419 if (szSource
|| !pcchSource
) index
++;
421 else if (dwIndex
> index
)
427 /******************************************************************
428 * MsiSourceListEnumSourcesW (MSI.@)
430 UINT WINAPI
MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch
, LPCWSTR szUserSid
,
431 MSIINSTALLCONTEXT dwContext
,
432 DWORD dwOptions
, DWORD dwIndex
,
433 LPWSTR szSource
, LPDWORD pcchSource
)
435 WCHAR squished_pc
[GUID_SIZE
];
440 UINT r
= ERROR_INVALID_PARAMETER
;
441 static DWORD index
= 0;
443 static const WCHAR format
[] = {'%','d',0};
445 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch
),
446 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
451 if (!szProductCodeOrPatch
|| !squash_guid(szProductCodeOrPatch
, squished_pc
))
454 if (szSource
&& !pcchSource
)
457 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
460 if ((dwOptions
& MSISOURCETYPE_NETWORK
) && (dwOptions
& MSISOURCETYPE_URL
))
463 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
466 if (dwIndex
!= index
)
469 r
= OpenSourceKey(szProductCodeOrPatch
, &source
,
470 dwOptions
, dwContext
, FALSE
);
471 if (r
!= ERROR_SUCCESS
)
474 if (dwOptions
& MSISOURCETYPE_NETWORK
)
475 r
= OpenNetworkSubkey(source
, &subkey
, FALSE
);
476 else if (dwOptions
& MSISOURCETYPE_URL
)
477 r
= OpenURLSubkey(source
, &subkey
, FALSE
);
479 if (r
!= ERROR_SUCCESS
)
481 r
= ERROR_NO_MORE_ITEMS
;
485 sprintfW(name
, format
, dwIndex
+ 1);
487 res
= RegQueryValueExW(subkey
, name
, 0, 0, (LPBYTE
)szSource
, pcchSource
);
488 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
489 r
= ERROR_NO_MORE_ITEMS
;
495 if (r
== ERROR_SUCCESS
)
497 if (szSource
|| !pcchSource
) index
++;
499 else if (dwIndex
> index
)
505 /******************************************************************
506 * MsiSourceListGetInfoA (MSI.@)
508 UINT WINAPI
MsiSourceListGetInfoA( LPCSTR szProduct
, LPCSTR szUserSid
,
509 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
510 LPCSTR szProperty
, LPSTR szValue
,
514 LPWSTR product
= NULL
;
515 LPWSTR usersid
= NULL
;
516 LPWSTR property
= NULL
;
520 if (szValue
&& !pcchValue
)
521 return ERROR_INVALID_PARAMETER
;
523 if (szProduct
) product
= strdupAtoW(szProduct
);
524 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
525 if (szProperty
) property
= strdupAtoW(szProperty
);
527 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
528 property
, NULL
, &len
);
529 if (ret
!= ERROR_SUCCESS
)
532 value
= msi_alloc(++len
* sizeof(WCHAR
));
534 return ERROR_OUTOFMEMORY
;
537 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
538 property
, value
, &len
);
539 if (ret
!= ERROR_SUCCESS
)
542 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
543 if (*pcchValue
>= len
)
544 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
546 ret
= ERROR_MORE_DATA
;
548 *pcchValue
= len
- 1;
558 /******************************************************************
559 * MsiSourceListGetInfoW (MSI.@)
561 UINT WINAPI
MsiSourceListGetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
562 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
563 LPCWSTR szProperty
, LPWSTR szValue
,
566 WCHAR squished_pc
[GUID_SIZE
];
567 HKEY sourcekey
, media
;
572 static const WCHAR mediapack
[] = {
573 'M','e','d','i','a','P','a','c','k','a','g','e',0};
575 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szProperty
));
577 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
578 return ERROR_INVALID_PARAMETER
;
580 if (szValue
&& !pcchValue
)
581 return ERROR_INVALID_PARAMETER
;
583 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
584 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
585 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
586 return ERROR_INVALID_PARAMETER
;
589 return ERROR_INVALID_PARAMETER
;
592 FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid
));
594 rc
= OpenSourceKey(szProduct
, &sourcekey
, dwOptions
, dwContext
, FALSE
);
595 if (rc
!= ERROR_SUCCESS
)
598 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
599 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
601 rc
= OpenMediaSubkey(sourcekey
, &media
, FALSE
);
602 if (rc
!= ERROR_SUCCESS
)
604 RegCloseKey(sourcekey
);
605 return ERROR_SUCCESS
;
608 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
609 szProperty
= mediapack
;
611 RegQueryValueExW(media
, szProperty
, 0, 0, (LPBYTE
)szValue
, pcchValue
);
614 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) ||
615 !strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
617 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
619 if (rc
!= ERROR_SUCCESS
)
621 RegCloseKey(sourcekey
);
622 return ERROR_SUCCESS
;
625 source
= msi_alloc(size
);
626 RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
627 0, 0, (LPBYTE
)source
, &size
);
632 RegCloseKey(sourcekey
);
633 return ERROR_SUCCESS
;
636 if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
638 if (*source
!= 'n' && *source
!= 'u' && *source
!= 'm')
641 RegCloseKey(sourcekey
);
642 return ERROR_SUCCESS
;
650 ptr
= strrchrW(source
, ';');
659 if (strlenW(ptr
) < *pcchValue
)
660 lstrcpyW(szValue
, ptr
);
662 rc
= ERROR_MORE_DATA
;
665 *pcchValue
= lstrlenW(ptr
);
668 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
670 *pcchValue
= *pcchValue
* sizeof(WCHAR
);
671 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0, 0,
672 (LPBYTE
)szValue
, pcchValue
);
673 if (rc
!= ERROR_SUCCESS
&& rc
!= ERROR_MORE_DATA
)
681 *pcchValue
= (*pcchValue
- 1) / sizeof(WCHAR
);
683 szValue
[*pcchValue
] = '\0';
688 FIXME("Unknown property %s\n",debugstr_w(szProperty
));
689 rc
= ERROR_UNKNOWN_PROPERTY
;
692 RegCloseKey(sourcekey
);
696 /******************************************************************
697 * MsiSourceListSetInfoA (MSI.@)
699 UINT WINAPI
MsiSourceListSetInfoA(LPCSTR szProduct
, LPCSTR szUserSid
,
700 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
701 LPCSTR szProperty
, LPCSTR szValue
)
704 LPWSTR product
= NULL
;
705 LPWSTR usersid
= NULL
;
706 LPWSTR property
= NULL
;
709 if (szProduct
) product
= strdupAtoW(szProduct
);
710 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
711 if (szProperty
) property
= strdupAtoW(szProperty
);
712 if (szValue
) value
= strdupAtoW(szValue
);
714 ret
= MsiSourceListSetInfoW(product
, usersid
, dwContext
, dwOptions
,
725 UINT
msi_set_last_used_source(LPCWSTR product
, LPCWSTR usersid
,
726 MSIINSTALLCONTEXT context
, DWORD options
,
736 static const WCHAR format
[] = {'%','c',';','%','i',';','%','s',0};
738 if (options
& MSISOURCETYPE_NETWORK
)
740 else if (options
& MSISOURCETYPE_URL
)
742 else if (options
& MSISOURCETYPE_MEDIA
)
745 return ERROR_INVALID_PARAMETER
;
747 if (!(options
& MSISOURCETYPE_MEDIA
))
749 r
= MsiSourceListAddSourceExW(product
, usersid
, context
,
751 if (r
!= ERROR_SUCCESS
)
755 while ((r
= MsiSourceListEnumSourcesW(product
, usersid
, context
, options
,
756 index
, NULL
, NULL
)) == ERROR_SUCCESS
)
759 if (r
!= ERROR_NO_MORE_ITEMS
)
763 size
= (lstrlenW(format
) + lstrlenW(value
) + 7) * sizeof(WCHAR
);
764 buffer
= msi_alloc(size
);
766 return ERROR_OUTOFMEMORY
;
768 r
= OpenSourceKey(product
, &source
, MSICODE_PRODUCT
, context
, FALSE
);
769 if (r
!= ERROR_SUCCESS
)
775 sprintfW(buffer
, format
, typechar
, index
, value
);
777 size
= (lstrlenW(buffer
) + 1) * sizeof(WCHAR
);
778 r
= RegSetValueExW(source
, INSTALLPROPERTY_LASTUSEDSOURCEW
, 0,
779 REG_SZ
, (LPBYTE
)buffer
, size
);
786 /******************************************************************
787 * MsiSourceListSetInfoW (MSI.@)
789 UINT WINAPI
MsiSourceListSetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
790 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
791 LPCWSTR szProperty
, LPCWSTR szValue
)
793 WCHAR squished_pc
[GUID_SIZE
];
794 HKEY sourcekey
, media
;
798 static const WCHAR media_package
[] = {
799 'M','e','d','i','a','P','a','c','k','a','g','e',0
802 TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
803 dwContext
, dwOptions
, debugstr_w(szProperty
), debugstr_w(szValue
));
805 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
806 return ERROR_INVALID_PARAMETER
;
809 return ERROR_INVALID_PARAMETER
;
812 return ERROR_UNKNOWN_PROPERTY
;
814 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
815 return ERROR_INVALID_PARAMETER
;
817 if (dwOptions
& MSICODE_PATCH
)
819 FIXME("Unhandled options MSICODE_PATCH\n");
820 return ERROR_UNKNOWN_PATCH
;
823 property
= szProperty
;
824 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
825 property
= media_package
;
827 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
828 if (rc
!= ERROR_SUCCESS
)
831 if (strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) &&
832 dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
))
834 RegCloseKey(sourcekey
);
835 return ERROR_INVALID_PARAMETER
;
838 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
839 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
841 rc
= OpenMediaSubkey(sourcekey
, &media
, TRUE
);
842 if (rc
== ERROR_SUCCESS
)
844 rc
= msi_reg_set_val_str(media
, property
, szValue
);
848 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
850 DWORD size
= (lstrlenW(szValue
) + 1) * sizeof(WCHAR
);
851 rc
= RegSetValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0,
852 REG_SZ
, (const BYTE
*)szValue
, size
);
853 if (rc
!= ERROR_SUCCESS
)
854 rc
= ERROR_UNKNOWN_PROPERTY
;
856 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
858 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
859 rc
= ERROR_INVALID_PARAMETER
;
861 rc
= msi_set_last_used_source(szProduct
, szUserSid
, dwContext
,
865 rc
= ERROR_UNKNOWN_PROPERTY
;
867 RegCloseKey(sourcekey
);
871 /******************************************************************
872 * MsiSourceListAddSourceW (MSI.@)
874 UINT WINAPI
MsiSourceListAddSourceW( LPCWSTR szProduct
, LPCWSTR szUserName
,
875 DWORD dwReserved
, LPCWSTR szSource
)
877 WCHAR squished_pc
[GUID_SIZE
];
879 LPWSTR sidstr
= NULL
;
886 TRACE("%s %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserName
), debugstr_w(szSource
));
888 if (!szSource
|| !*szSource
)
889 return ERROR_INVALID_PARAMETER
;
892 return ERROR_INVALID_PARAMETER
;
894 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
895 return ERROR_INVALID_PARAMETER
;
897 if (!szUserName
|| !*szUserName
)
898 context
= MSIINSTALLCONTEXT_MACHINE
;
901 if (LookupAccountNameW(NULL
, szUserName
, NULL
, &sidsize
, NULL
, &domsize
, NULL
))
903 PSID psid
= msi_alloc(sidsize
);
905 if (LookupAccountNameW(NULL
, szUserName
, psid
, &sidsize
, NULL
, &domsize
, NULL
))
906 ConvertSidToStringSidW(psid
, &sidstr
);
911 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
912 MSIINSTALLCONTEXT_USERMANAGED
, &hkey
, FALSE
);
913 if (r
== ERROR_SUCCESS
)
914 context
= MSIINSTALLCONTEXT_USERMANAGED
;
917 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
918 MSIINSTALLCONTEXT_USERUNMANAGED
,
920 if (r
!= ERROR_SUCCESS
)
921 return ERROR_UNKNOWN_PRODUCT
;
923 context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
929 ret
= MsiSourceListAddSourceExW(szProduct
, sidstr
,
930 context
, MSISOURCETYPE_NETWORK
, szSource
, 0);
938 /******************************************************************
939 * MsiSourceListAddSourceA (MSI.@)
941 UINT WINAPI
MsiSourceListAddSourceA( LPCSTR szProduct
, LPCSTR szUserName
,
942 DWORD dwReserved
, LPCSTR szSource
)
949 szwproduct
= strdupAtoW( szProduct
);
950 szwusername
= strdupAtoW( szUserName
);
951 szwsource
= strdupAtoW( szSource
);
953 ret
= MsiSourceListAddSourceW(szwproduct
, szwusername
, dwReserved
, szwsource
);
955 msi_free(szwproduct
);
956 msi_free(szwusername
);
962 /******************************************************************
963 * MsiSourceListAddSourceExA (MSI.@)
965 UINT WINAPI
MsiSourceListAddSourceExA(LPCSTR szProduct
, LPCSTR szUserSid
,
966 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCSTR szSource
, DWORD dwIndex
)
969 LPWSTR product
, usersid
, source
;
971 product
= strdupAtoW(szProduct
);
972 usersid
= strdupAtoW(szUserSid
);
973 source
= strdupAtoW(szSource
);
975 ret
= MsiSourceListAddSourceExW(product
, usersid
, dwContext
,
976 dwOptions
, source
, dwIndex
);
985 static void free_source_list(struct list
*sourcelist
)
987 while (!list_empty(sourcelist
))
989 media_info
*info
= LIST_ENTRY(list_head(sourcelist
), media_info
, entry
);
990 list_remove(&info
->entry
);
991 msi_free(info
->path
);
996 static void add_source_to_list(struct list
*sourcelist
, media_info
*info
,
1001 static const WCHAR fmt
[] = {'%','i',0};
1003 if (index
) *index
= 0;
1005 if (list_empty(sourcelist
))
1007 list_add_head(sourcelist
, &info
->entry
);
1011 LIST_FOR_EACH_ENTRY(iter
, sourcelist
, media_info
, entry
)
1013 if (!found
&& info
->index
< iter
->index
)
1016 list_add_before(&iter
->entry
, &info
->entry
);
1019 /* update the rest of the list */
1021 sprintfW(iter
->szIndex
, fmt
, ++iter
->index
);
1027 list_add_after(&iter
->entry
, &info
->entry
);
1030 static UINT
fill_source_list(struct list
*sourcelist
, HKEY sourcekey
, DWORD
*count
)
1032 UINT r
= ERROR_SUCCESS
;
1035 DWORD size
, val_size
;
1040 while (r
== ERROR_SUCCESS
)
1042 size
= sizeof(name
) / sizeof(name
[0]);
1043 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
, NULL
, NULL
, &val_size
);
1044 if (r
!= ERROR_SUCCESS
)
1047 entry
= msi_alloc(sizeof(media_info
));
1051 entry
->path
= msi_alloc(val_size
);
1058 lstrcpyW(entry
->szIndex
, name
);
1059 entry
->index
= atoiW(name
);
1062 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
,
1063 NULL
, (LPBYTE
)entry
->path
, &val_size
);
1064 if (r
!= ERROR_SUCCESS
)
1066 msi_free(entry
->path
);
1072 add_source_to_list(sourcelist
, entry
, NULL
);
1077 free_source_list(sourcelist
);
1078 return ERROR_OUTOFMEMORY
;
1081 /******************************************************************
1082 * MsiSourceListAddSourceExW (MSI.@)
1084 UINT WINAPI
MsiSourceListAddSourceExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1085 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCWSTR szSource
,
1091 struct list sourcelist
;
1093 WCHAR squished_pc
[GUID_SIZE
];
1100 static const WCHAR fmt
[] = {'%','i',0};
1102 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1103 dwContext
, dwOptions
, debugstr_w(szSource
), dwIndex
);
1105 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1106 return ERROR_INVALID_PARAMETER
;
1108 if (!szSource
|| !*szSource
)
1109 return ERROR_INVALID_PARAMETER
;
1111 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
1112 return ERROR_INVALID_PARAMETER
;
1114 if (dwOptions
& MSICODE_PATCH
)
1116 FIXME("Unhandled options MSICODE_PATCH\n");
1117 return ERROR_FUNCTION_FAILED
;
1120 if (szUserSid
&& (dwContext
& MSIINSTALLCONTEXT_MACHINE
))
1121 return ERROR_INVALID_PARAMETER
;
1123 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1124 if (rc
!= ERROR_SUCCESS
)
1127 if (dwOptions
& MSISOURCETYPE_NETWORK
)
1128 rc
= OpenNetworkSubkey(sourcekey
, &typekey
, TRUE
);
1129 else if (dwOptions
& MSISOURCETYPE_URL
)
1130 rc
= OpenURLSubkey(sourcekey
, &typekey
, TRUE
);
1131 else if (dwOptions
& MSISOURCETYPE_MEDIA
)
1132 rc
= OpenMediaSubkey(sourcekey
, &typekey
, TRUE
);
1135 ERR("unknown media type: %08x\n", dwOptions
);
1136 RegCloseKey(sourcekey
);
1137 return ERROR_FUNCTION_FAILED
;
1139 if (rc
!= ERROR_SUCCESS
)
1141 ERR("can't open subkey %u\n", rc
);
1142 RegCloseKey(sourcekey
);
1146 postfix
= (dwOptions
& MSISOURCETYPE_NETWORK
) ? szBackSlash
: szForwardSlash
;
1147 if (szSource
[lstrlenW(szSource
) - 1] == *postfix
)
1148 source
= strdupW(szSource
);
1151 size
= lstrlenW(szSource
) + 2;
1152 source
= msi_alloc(size
* sizeof(WCHAR
));
1153 lstrcpyW(source
, szSource
);
1154 lstrcatW(source
, postfix
);
1157 list_init(&sourcelist
);
1158 rc
= fill_source_list(&sourcelist
, typekey
, &count
);
1159 if (rc
!= ERROR_NO_MORE_ITEMS
)
1162 size
= (lstrlenW(source
) + 1) * sizeof(WCHAR
);
1166 rc
= RegSetValueExW(typekey
, szOne
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1169 else if (dwIndex
> count
|| dwIndex
== 0)
1171 sprintfW(name
, fmt
, count
+ 1);
1172 rc
= RegSetValueExW(typekey
, name
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1177 sprintfW(name
, fmt
, dwIndex
);
1178 info
= msi_alloc(sizeof(media_info
));
1181 rc
= ERROR_OUTOFMEMORY
;
1185 info
->path
= strdupW(source
);
1186 lstrcpyW(info
->szIndex
, name
);
1187 info
->index
= dwIndex
;
1188 add_source_to_list(&sourcelist
, info
, &index
);
1190 LIST_FOR_EACH_ENTRY(info
, &sourcelist
, media_info
, entry
)
1192 if (info
->index
< index
)
1195 size
= (lstrlenW(info
->path
) + 1) * sizeof(WCHAR
);
1196 rc
= RegSetValueExW(typekey
, info
->szIndex
, 0,
1197 REG_EXPAND_SZ
, (LPBYTE
)info
->path
, size
);
1198 if (rc
!= ERROR_SUCCESS
)
1204 free_source_list(&sourcelist
);
1206 RegCloseKey(typekey
);
1207 RegCloseKey(sourcekey
);
1211 /******************************************************************
1212 * MsiSourceListAddMediaDiskA (MSI.@)
1214 UINT WINAPI
MsiSourceListAddMediaDiskA(LPCSTR szProduct
, LPCSTR szUserSid
,
1215 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1216 LPCSTR szVolumeLabel
, LPCSTR szDiskPrompt
)
1219 LPWSTR product
= NULL
;
1220 LPWSTR usersid
= NULL
;
1221 LPWSTR volume
= NULL
;
1222 LPWSTR prompt
= NULL
;
1224 if (szProduct
) product
= strdupAtoW(szProduct
);
1225 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1226 if (szVolumeLabel
) volume
= strdupAtoW(szVolumeLabel
);
1227 if (szDiskPrompt
) prompt
= strdupAtoW(szDiskPrompt
);
1229 r
= MsiSourceListAddMediaDiskW(product
, usersid
, dwContext
, dwOptions
,
1230 dwDiskId
, volume
, prompt
);
1240 /******************************************************************
1241 * MsiSourceListAddMediaDiskW (MSI.@)
1243 UINT WINAPI
MsiSourceListAddMediaDiskW(LPCWSTR szProduct
, LPCWSTR szUserSid
,
1244 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1245 LPCWSTR szVolumeLabel
, LPCWSTR szDiskPrompt
)
1251 WCHAR squished_pc
[GUID_SIZE
];
1255 static const WCHAR fmt
[] = {'%','i',0};
1257 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct
),
1258 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwDiskId
,
1259 debugstr_w(szVolumeLabel
), debugstr_w(szDiskPrompt
));
1261 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1262 return ERROR_INVALID_PARAMETER
;
1264 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
1265 return ERROR_INVALID_PARAMETER
;
1267 if ((szVolumeLabel
&& !*szVolumeLabel
) || (szDiskPrompt
&& !*szDiskPrompt
))
1268 return ERROR_INVALID_PARAMETER
;
1270 if ((dwContext
& MSIINSTALLCONTEXT_MACHINE
) && szUserSid
)
1271 return ERROR_INVALID_PARAMETER
;
1273 if (dwOptions
& MSICODE_PATCH
)
1275 FIXME("Unhandled options MSICODE_PATCH\n");
1276 return ERROR_FUNCTION_FAILED
;
1279 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1280 if (rc
!= ERROR_SUCCESS
)
1283 OpenMediaSubkey(sourcekey
, &mediakey
, TRUE
);
1285 sprintfW(szIndex
, fmt
, dwDiskId
);
1288 if (szVolumeLabel
) size
+= lstrlenW(szVolumeLabel
);
1289 if (szDiskPrompt
) size
+= lstrlenW(szDiskPrompt
);
1291 size
*= sizeof(WCHAR
);
1292 buffer
= msi_alloc(size
);
1295 if (szVolumeLabel
) lstrcpyW(buffer
, szVolumeLabel
);
1296 lstrcatW(buffer
, szSemiColon
);
1297 if (szDiskPrompt
) lstrcatW(buffer
, szDiskPrompt
);
1299 RegSetValueExW(mediakey
, szIndex
, 0, REG_SZ
, (LPBYTE
)buffer
, size
);
1302 RegCloseKey(sourcekey
);
1303 RegCloseKey(mediakey
);
1305 return ERROR_SUCCESS
;
1308 /******************************************************************
1309 * MsiSourceListClearAllA (MSI.@)
1311 UINT WINAPI
MsiSourceListClearAllA( LPCSTR szProduct
, LPCSTR szUserName
, DWORD dwReserved
)
1313 FIXME("(%s %s %d)\n", debugstr_a(szProduct
), debugstr_a(szUserName
), dwReserved
);
1314 return ERROR_SUCCESS
;
1317 /******************************************************************
1318 * MsiSourceListClearAllW (MSI.@)
1320 UINT WINAPI
MsiSourceListClearAllW( LPCWSTR szProduct
, LPCWSTR szUserName
, DWORD dwReserved
)
1322 FIXME("(%s %s %d)\n", debugstr_w(szProduct
), debugstr_w(szUserName
), dwReserved
);
1323 return ERROR_SUCCESS
;
1326 /******************************************************************
1327 * MsiSourceListClearAllExA (MSI.@)
1329 UINT WINAPI
MsiSourceListClearAllExA( LPCSTR szProduct
, LPCSTR szUserSid
,
1330 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1332 FIXME("(%s %s %d %08x)\n", debugstr_a(szProduct
), debugstr_a(szUserSid
),
1333 dwContext
, dwOptions
);
1334 return ERROR_SUCCESS
;
1337 /******************************************************************
1338 * MsiSourceListClearAllExW (MSI.@)
1340 UINT WINAPI
MsiSourceListClearAllExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1341 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1343 FIXME("(%s %s %d %08x)\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1344 dwContext
, dwOptions
);
1345 return ERROR_SUCCESS
;
1348 /******************************************************************
1349 * MsiSourceListClearSourceA (MSI.@)
1351 UINT WINAPI
MsiSourceListClearSourceA(LPCSTR szProductCodeOrPatchCode
, LPCSTR szUserSid
,
1352 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1355 FIXME("(%s %s %x %x %s)\n", debugstr_a(szProductCodeOrPatchCode
), debugstr_a(szUserSid
),
1356 dwContext
, dwOptions
, debugstr_a(szSource
));
1357 return ERROR_SUCCESS
;
1360 /******************************************************************
1361 * MsiSourceListClearSourceW (MSI.@)
1363 UINT WINAPI
MsiSourceListClearSourceW(LPCWSTR szProductCodeOrPatchCode
, LPCWSTR szUserSid
,
1364 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1367 FIXME("(%s %s %x %x %s)\n", debugstr_w(szProductCodeOrPatchCode
), debugstr_w(szUserSid
),
1368 dwContext
, dwOptions
, debugstr_w(szSource
));
1369 return ERROR_SUCCESS
;