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
24 #define NONAMELESSUNION
31 #include "wine/debug.h"
38 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
44 * These apis are defined in MSI 3.0
47 typedef struct tagMediaInfo
55 static UINT
OpenSourceKey(LPCWSTR szProduct
, HKEY
* key
, DWORD dwOptions
,
56 MSIINSTALLCONTEXT context
, BOOL create
)
59 UINT rc
= ERROR_FUNCTION_FAILED
;
60 static const WCHAR szSourceList
[] = {'S','o','u','r','c','e','L','i','s','t',0};
62 if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
64 if (dwOptions
& MSICODE_PATCH
)
65 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
67 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
70 else if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
72 if (dwOptions
& MSICODE_PATCH
)
73 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
75 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
78 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
80 if (dwOptions
& MSICODE_PATCH
)
81 rc
= MSIREG_OpenPatchesKey(szProduct
, &rootkey
, create
);
83 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
87 if (rc
!= ERROR_SUCCESS
)
89 if (dwOptions
& MSICODE_PATCH
)
90 return ERROR_UNKNOWN_PATCH
;
92 return ERROR_UNKNOWN_PRODUCT
;
96 rc
= RegCreateKeyW(rootkey
, szSourceList
, key
);
99 rc
= RegOpenKeyW(rootkey
,szSourceList
, key
);
100 if (rc
!= ERROR_SUCCESS
)
101 rc
= ERROR_BAD_CONFIGURATION
;
107 static UINT
OpenMediaSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
110 static const WCHAR media
[] = {'M','e','d','i','a',0};
113 rc
= RegCreateKeyW(rootkey
, media
, key
);
115 rc
= RegOpenKeyW(rootkey
,media
, key
);
120 static UINT
OpenNetworkSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
123 static const WCHAR net
[] = {'N','e','t',0};
126 rc
= RegCreateKeyW(rootkey
, net
, key
);
128 rc
= RegOpenKeyW(rootkey
, net
, key
);
133 static UINT
OpenURLSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
136 static const WCHAR URL
[] = {'U','R','L',0};
139 rc
= RegCreateKeyW(rootkey
, URL
, key
);
141 rc
= RegOpenKeyW(rootkey
, URL
, key
);
146 /******************************************************************
147 * MsiSourceListEnumMediaDisksA (MSI.@)
149 UINT WINAPI
MsiSourceListEnumMediaDisksA(LPCSTR szProductCodeOrPatchCode
,
150 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
151 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
152 LPSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
153 LPSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
155 LPWSTR product
= NULL
;
156 LPWSTR usersid
= NULL
;
157 LPWSTR volume
= NULL
;
158 LPWSTR prompt
= NULL
;
159 UINT r
= ERROR_INVALID_PARAMETER
;
161 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n", debugstr_a(szProductCodeOrPatchCode
),
162 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, pdwDiskId
,
163 szVolumeLabel
, pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
165 if (szDiskPrompt
&& !pcchDiskPrompt
)
166 return ERROR_INVALID_PARAMETER
;
168 if (szProductCodeOrPatchCode
) product
= strdupAtoW(szProductCodeOrPatchCode
);
169 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
171 /* FIXME: add tests for an invalid format */
174 volume
= msi_alloc(*pcchVolumeLabel
* sizeof(WCHAR
));
177 prompt
= msi_alloc(*pcchDiskPrompt
* sizeof(WCHAR
));
179 if (volume
) *volume
= '\0';
180 if (prompt
) *prompt
= '\0';
181 r
= MsiSourceListEnumMediaDisksW(product
, usersid
, dwContext
, dwOptions
,
182 dwIndex
, pdwDiskId
, volume
, pcchVolumeLabel
,
183 prompt
, pcchDiskPrompt
);
184 if (r
!= ERROR_SUCCESS
)
187 if (szVolumeLabel
&& pcchVolumeLabel
)
188 WideCharToMultiByte(CP_ACP
, 0, volume
, -1, szVolumeLabel
,
189 *pcchVolumeLabel
+ 1, NULL
, NULL
);
192 WideCharToMultiByte(CP_ACP
, 0, prompt
, -1, szDiskPrompt
,
193 *pcchDiskPrompt
+ 1, NULL
, NULL
);
204 /******************************************************************
205 * MsiSourceListEnumMediaDisksW (MSI.@)
207 UINT WINAPI
MsiSourceListEnumMediaDisksW(LPCWSTR szProductCodeOrPatchCode
,
208 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
209 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
210 LPWSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
211 LPWSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
213 WCHAR squished_pc
[GUID_SIZE
];
219 DWORD valuesz
, datasz
= 0;
224 static DWORD index
= 0;
226 static const WCHAR fmt
[] = {'#','%','d',0};
228 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p)\n", debugstr_w(szProductCodeOrPatchCode
),
229 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szVolumeLabel
,
230 pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
232 if (!szProductCodeOrPatchCode
||
233 !squash_guid(szProductCodeOrPatchCode
, squished_pc
))
234 return ERROR_INVALID_PARAMETER
;
236 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
237 return ERROR_INVALID_PARAMETER
;
239 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
240 return ERROR_INVALID_PARAMETER
;
242 if (szDiskPrompt
&& !pcchDiskPrompt
)
243 return ERROR_INVALID_PARAMETER
;
248 if (dwIndex
!= index
)
249 return ERROR_INVALID_PARAMETER
;
251 r
= OpenSourceKey(szProductCodeOrPatchCode
, &source
,
252 dwOptions
, dwContext
, FALSE
);
253 if (r
!= ERROR_SUCCESS
)
256 r
= OpenMediaSubkey(source
, &media
, FALSE
);
257 if (r
!= ERROR_SUCCESS
)
260 return ERROR_NO_MORE_ITEMS
;
263 if (!pcchVolumeLabel
&& !pcchDiskPrompt
)
265 r
= RegEnumValueW(media
, dwIndex
, NULL
, NULL
, NULL
,
270 res
= RegQueryInfoKeyW(media
, NULL
, NULL
, NULL
, NULL
, NULL
,
271 NULL
, &numvals
, &valuesz
, &datasz
, NULL
, NULL
);
272 if (res
!= ERROR_SUCCESS
)
274 r
= ERROR_BAD_CONFIGURATION
;
278 value
= msi_alloc(++valuesz
* sizeof(WCHAR
));
279 data
= msi_alloc(++datasz
* sizeof(WCHAR
));
282 r
= ERROR_OUTOFMEMORY
;
286 r
= RegEnumValueW(media
, dwIndex
, value
, &valuesz
,
287 NULL
, &type
, (LPBYTE
)data
, &datasz
);
288 if (r
!= ERROR_SUCCESS
)
292 *pdwDiskId
= atolW(value
);
295 ptr
= strchrW(data
, ';');
303 if (type
== REG_DWORD
)
305 sprintfW(convert
, fmt
, *data
);
306 size
= lstrlenW(convert
);
310 size
= lstrlenW(data
);
312 if (size
>= *pcchVolumeLabel
)
314 else if (szVolumeLabel
)
315 lstrcpyW(szVolumeLabel
, ptr2
);
317 *pcchVolumeLabel
= size
;
325 if (type
== REG_DWORD
)
327 sprintfW(convert
, fmt
, *ptr
);
328 size
= lstrlenW(convert
);
332 size
= lstrlenW(ptr
);
334 size
= lstrlenW(ptr
);
335 if (size
>= *pcchDiskPrompt
)
337 else if (szDiskPrompt
)
338 lstrcpyW(szDiskPrompt
, ptr
);
340 *pcchDiskPrompt
= size
;
353 /******************************************************************
354 * MsiSourceListEnumSourcesA (MSI.@)
356 UINT WINAPI
MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch
, LPCSTR szUserSid
,
357 MSIINSTALLCONTEXT dwContext
,
358 DWORD dwOptions
, DWORD dwIndex
,
359 LPSTR szSource
, LPDWORD pcchSource
)
361 LPWSTR product
= NULL
;
362 LPWSTR usersid
= NULL
;
363 LPWSTR source
= NULL
;
365 UINT r
= ERROR_INVALID_PARAMETER
;
366 static DWORD index
= 0;
368 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_a(szProductCodeOrPatch
),
369 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
374 if (szSource
&& !pcchSource
)
377 if (dwIndex
!= index
)
380 if (szProductCodeOrPatch
) product
= strdupAtoW(szProductCodeOrPatch
);
381 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
383 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
384 dwIndex
, NULL
, &len
);
385 if (r
!= ERROR_SUCCESS
)
388 source
= msi_alloc(++len
* sizeof(WCHAR
));
391 r
= ERROR_OUTOFMEMORY
;
396 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
397 dwIndex
, source
, &len
);
398 if (r
!= ERROR_SUCCESS
)
401 len
= WideCharToMultiByte(CP_ACP
, 0, source
, -1, NULL
, 0, NULL
, NULL
);
402 if (pcchSource
&& *pcchSource
>= len
)
403 WideCharToMultiByte(CP_ACP
, 0, source
, -1, szSource
, len
, NULL
, NULL
);
408 *pcchSource
= len
- 1;
415 if (r
== ERROR_SUCCESS
)
417 if (szSource
|| !pcchSource
) index
++;
419 else if (dwIndex
> index
)
425 /******************************************************************
426 * MsiSourceListEnumSourcesW (MSI.@)
428 UINT WINAPI
MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch
, LPCWSTR szUserSid
,
429 MSIINSTALLCONTEXT dwContext
,
430 DWORD dwOptions
, DWORD dwIndex
,
431 LPWSTR szSource
, LPDWORD pcchSource
)
433 WCHAR squished_pc
[GUID_SIZE
];
438 UINT r
= ERROR_INVALID_PARAMETER
;
439 static DWORD index
= 0;
441 static const WCHAR format
[] = {'%','d',0};
443 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch
),
444 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
449 if (!szProductCodeOrPatch
|| !squash_guid(szProductCodeOrPatch
, squished_pc
))
452 if (szSource
&& !pcchSource
)
455 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
458 if ((dwOptions
& MSISOURCETYPE_NETWORK
) && (dwOptions
& MSISOURCETYPE_URL
))
461 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
464 if (dwIndex
!= index
)
467 r
= OpenSourceKey(szProductCodeOrPatch
, &source
,
468 dwOptions
, dwContext
, FALSE
);
469 if (r
!= ERROR_SUCCESS
)
472 if (dwOptions
& MSISOURCETYPE_NETWORK
)
473 r
= OpenNetworkSubkey(source
, &subkey
, FALSE
);
474 else if (dwOptions
& MSISOURCETYPE_URL
)
475 r
= OpenURLSubkey(source
, &subkey
, FALSE
);
477 if (r
!= ERROR_SUCCESS
)
479 r
= ERROR_NO_MORE_ITEMS
;
483 sprintfW(name
, format
, dwIndex
+ 1);
485 res
= RegQueryValueExW(subkey
, name
, 0, 0, (LPBYTE
)szSource
, pcchSource
);
486 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
487 r
= ERROR_NO_MORE_ITEMS
;
493 if (r
== ERROR_SUCCESS
)
495 if (szSource
|| !pcchSource
) index
++;
497 else if (dwIndex
> index
)
503 /******************************************************************
504 * MsiSourceListGetInfoA (MSI.@)
506 UINT WINAPI
MsiSourceListGetInfoA( LPCSTR szProduct
, LPCSTR szUserSid
,
507 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
508 LPCSTR szProperty
, LPSTR szValue
,
512 LPWSTR product
= NULL
;
513 LPWSTR usersid
= NULL
;
514 LPWSTR property
= NULL
;
518 if (szValue
&& !pcchValue
)
519 return ERROR_INVALID_PARAMETER
;
521 if (szProduct
) product
= strdupAtoW(szProduct
);
522 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
523 if (szProperty
) property
= strdupAtoW(szProperty
);
525 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
526 property
, NULL
, &len
);
527 if (ret
!= ERROR_SUCCESS
)
530 value
= msi_alloc(++len
* sizeof(WCHAR
));
532 return ERROR_OUTOFMEMORY
;
535 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
536 property
, value
, &len
);
537 if (ret
!= ERROR_SUCCESS
)
540 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
541 if (*pcchValue
>= len
)
542 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
544 ret
= ERROR_MORE_DATA
;
546 *pcchValue
= len
- 1;
556 /******************************************************************
557 * MsiSourceListGetInfoW (MSI.@)
559 UINT WINAPI
MsiSourceListGetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
560 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
561 LPCWSTR szProperty
, LPWSTR szValue
,
564 WCHAR squished_pc
[GUID_SIZE
];
565 HKEY sourcekey
, media
;
570 static const WCHAR mediapack
[] = {
571 'M','e','d','i','a','P','a','c','k','a','g','e',0};
573 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szProperty
));
575 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
576 return ERROR_INVALID_PARAMETER
;
578 if (szValue
&& !pcchValue
)
579 return ERROR_INVALID_PARAMETER
;
581 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
582 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
583 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
584 return ERROR_INVALID_PARAMETER
;
587 return ERROR_INVALID_PARAMETER
;
590 FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid
));
592 if (dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
)
593 FIXME("Unhandled context %d\n", dwContext
);
595 rc
= OpenSourceKey(szProduct
, &sourcekey
, dwOptions
, dwContext
, FALSE
);
596 if (rc
!= ERROR_SUCCESS
)
599 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
600 !lstrcmpW(szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
602 rc
= OpenMediaSubkey(sourcekey
, &media
, FALSE
);
603 if (rc
!= ERROR_SUCCESS
)
605 RegCloseKey(sourcekey
);
606 return ERROR_SUCCESS
;
609 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
610 szProperty
= mediapack
;
612 RegQueryValueExW(media
, szProperty
, 0, 0, (LPBYTE
)szValue
, pcchValue
);
615 else if (!lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) ||
616 !lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
618 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
620 if (rc
!= ERROR_SUCCESS
)
622 RegCloseKey(sourcekey
);
623 return ERROR_SUCCESS
;
626 source
= msi_alloc(size
);
627 RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
628 0, 0, (LPBYTE
)source
, &size
);
633 RegCloseKey(sourcekey
);
634 return ERROR_SUCCESS
;
637 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
639 if (*source
!= 'n' && *source
!= 'u' && *source
!= 'm')
642 RegCloseKey(sourcekey
);
643 return ERROR_SUCCESS
;
651 ptr
= strrchrW(source
, ';');
660 if (strlenW(ptr
) < *pcchValue
)
661 lstrcpyW(szValue
, ptr
);
663 rc
= ERROR_MORE_DATA
;
666 *pcchValue
= lstrlenW(ptr
);
669 else if (strcmpW(INSTALLPROPERTY_PACKAGENAMEW
, szProperty
)==0)
671 *pcchValue
= *pcchValue
* sizeof(WCHAR
);
672 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0, 0,
673 (LPBYTE
)szValue
, pcchValue
);
674 if (rc
!= ERROR_SUCCESS
&& rc
!= ERROR_MORE_DATA
)
682 *pcchValue
= (*pcchValue
- 1) / sizeof(WCHAR
);
684 szValue
[*pcchValue
] = '\0';
689 FIXME("Unknown property %s\n",debugstr_w(szProperty
));
690 rc
= ERROR_UNKNOWN_PROPERTY
;
693 RegCloseKey(sourcekey
);
697 /******************************************************************
698 * MsiSourceListSetInfoA (MSI.@)
700 UINT WINAPI
MsiSourceListSetInfoA(LPCSTR szProduct
, LPCSTR szUserSid
,
701 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
702 LPCSTR szProperty
, LPCSTR szValue
)
705 LPWSTR product
= NULL
;
706 LPWSTR usersid
= NULL
;
707 LPWSTR property
= NULL
;
710 if (szProduct
) product
= strdupAtoW(szProduct
);
711 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
712 if (szProperty
) property
= strdupAtoW(szProperty
);
713 if (szValue
) value
= strdupAtoW(szValue
);
715 ret
= MsiSourceListSetInfoW(product
, usersid
, dwContext
, dwOptions
,
726 UINT
msi_set_last_used_source(LPCWSTR product
, LPCWSTR usersid
,
727 MSIINSTALLCONTEXT context
, DWORD options
,
737 static const WCHAR format
[] = {'%','c',';','%','i',';','%','s',0};
739 if (options
& MSISOURCETYPE_NETWORK
)
741 else if (options
& MSISOURCETYPE_URL
)
743 else if (options
& MSISOURCETYPE_MEDIA
)
746 return ERROR_INVALID_PARAMETER
;
748 if (!(options
& MSISOURCETYPE_MEDIA
))
750 r
= MsiSourceListAddSourceExW(product
, usersid
, context
,
752 if (r
!= ERROR_SUCCESS
)
756 while ((r
= MsiSourceListEnumSourcesW(product
, usersid
, context
, options
,
757 index
, NULL
, NULL
)) == ERROR_SUCCESS
)
760 if (r
!= ERROR_NO_MORE_ITEMS
)
764 size
= (lstrlenW(format
) + lstrlenW(value
) + 7) * sizeof(WCHAR
);
765 buffer
= msi_alloc(size
);
767 return ERROR_OUTOFMEMORY
;
769 r
= OpenSourceKey(product
, &source
, MSICODE_PRODUCT
, context
, FALSE
);
770 if (r
!= ERROR_SUCCESS
)
773 sprintfW(buffer
, format
, typechar
, index
, value
);
775 size
= (lstrlenW(buffer
) + 1) * sizeof(WCHAR
);
776 r
= RegSetValueExW(source
, INSTALLPROPERTY_LASTUSEDSOURCEW
, 0,
777 REG_SZ
, (LPBYTE
)buffer
, size
);
784 /******************************************************************
785 * MsiSourceListSetInfoW (MSI.@)
787 UINT WINAPI
MsiSourceListSetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
788 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
789 LPCWSTR szProperty
, LPCWSTR szValue
)
791 WCHAR squished_pc
[GUID_SIZE
];
792 HKEY sourcekey
, media
;
796 static const WCHAR media_package
[] = {
797 'M','e','d','i','a','P','a','c','k','a','g','e',0
800 TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
801 dwContext
, dwOptions
, debugstr_w(szProperty
), debugstr_w(szValue
));
803 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
804 return ERROR_INVALID_PARAMETER
;
807 return ERROR_INVALID_PARAMETER
;
810 return ERROR_UNKNOWN_PROPERTY
;
812 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
813 return ERROR_INVALID_PARAMETER
;
815 if (dwOptions
& MSICODE_PATCH
)
817 FIXME("Unhandled options MSICODE_PATCH\n");
818 return ERROR_UNKNOWN_PATCH
;
821 property
= szProperty
;
822 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
823 property
= media_package
;
825 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
826 if (rc
!= ERROR_SUCCESS
)
829 if (lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) &&
830 dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
))
832 RegCloseKey(sourcekey
);
833 return ERROR_INVALID_PARAMETER
;
836 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
837 !lstrcmpW(szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
839 rc
= OpenMediaSubkey(sourcekey
, &media
, TRUE
);
840 if (rc
== ERROR_SUCCESS
)
842 rc
= msi_reg_set_val_str(media
, property
, szValue
);
846 else if (strcmpW(INSTALLPROPERTY_PACKAGENAMEW
, szProperty
)==0)
848 DWORD size
= (lstrlenW(szValue
) + 1) * sizeof(WCHAR
);
849 rc
= RegSetValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0,
850 REG_SZ
, (const BYTE
*)szValue
, size
);
851 if (rc
!= ERROR_SUCCESS
)
852 rc
= ERROR_UNKNOWN_PROPERTY
;
854 else if (!lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
856 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
857 rc
= ERROR_INVALID_PARAMETER
;
859 rc
= msi_set_last_used_source(szProduct
, szUserSid
, dwContext
,
863 rc
= ERROR_UNKNOWN_PROPERTY
;
865 RegCloseKey(sourcekey
);
869 /******************************************************************
870 * MsiSourceListAddSourceW (MSI.@)
872 UINT WINAPI
MsiSourceListAddSourceW( LPCWSTR szProduct
, LPCWSTR szUserName
,
873 DWORD dwReserved
, LPCWSTR szSource
)
875 WCHAR squished_pc
[GUID_SIZE
];
877 LPWSTR sidstr
= NULL
;
884 TRACE("%s %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserName
), debugstr_w(szSource
));
886 if (!szSource
|| !*szSource
)
887 return ERROR_INVALID_PARAMETER
;
890 return ERROR_INVALID_PARAMETER
;
892 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
893 return ERROR_INVALID_PARAMETER
;
895 if (!szUserName
|| !*szUserName
)
896 context
= MSIINSTALLCONTEXT_MACHINE
;
899 if (LookupAccountNameW(NULL
, szUserName
, NULL
, &sidsize
, NULL
, &domsize
, NULL
))
901 PSID psid
= msi_alloc(sidsize
);
903 if (LookupAccountNameW(NULL
, szUserName
, psid
, &sidsize
, NULL
, &domsize
, NULL
))
904 ConvertSidToStringSidW(psid
, &sidstr
);
909 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
910 MSIINSTALLCONTEXT_USERMANAGED
, &hkey
, FALSE
);
911 if (r
== ERROR_SUCCESS
)
912 context
= MSIINSTALLCONTEXT_USERMANAGED
;
915 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
916 MSIINSTALLCONTEXT_USERUNMANAGED
,
918 if (r
!= ERROR_SUCCESS
)
919 return ERROR_UNKNOWN_PRODUCT
;
921 context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
927 ret
= MsiSourceListAddSourceExW(szProduct
, sidstr
,
928 context
, MSISOURCETYPE_NETWORK
, szSource
, 0);
936 /******************************************************************
937 * MsiSourceListAddSourceA (MSI.@)
939 UINT WINAPI
MsiSourceListAddSourceA( LPCSTR szProduct
, LPCSTR szUserName
,
940 DWORD dwReserved
, LPCSTR szSource
)
947 szwproduct
= strdupAtoW( szProduct
);
948 szwusername
= strdupAtoW( szUserName
);
949 szwsource
= strdupAtoW( szSource
);
951 ret
= MsiSourceListAddSourceW(szwproduct
, szwusername
, dwReserved
, szwsource
);
953 msi_free(szwproduct
);
954 msi_free(szwusername
);
960 /******************************************************************
961 * MsiSourceListAddSourceExA (MSI.@)
963 UINT WINAPI
MsiSourceListAddSourceExA(LPCSTR szProduct
, LPCSTR szUserSid
,
964 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCSTR szSource
, DWORD dwIndex
)
967 LPWSTR product
, usersid
, source
;
969 product
= strdupAtoW(szProduct
);
970 usersid
= strdupAtoW(szUserSid
);
971 source
= strdupAtoW(szSource
);
973 ret
= MsiSourceListAddSourceExW(product
, usersid
, dwContext
,
974 dwOptions
, source
, dwIndex
);
983 static void free_source_list(struct list
*sourcelist
)
985 while (!list_empty(sourcelist
))
987 media_info
*info
= LIST_ENTRY(list_head(sourcelist
), media_info
, entry
);
988 list_remove(&info
->entry
);
989 msi_free(info
->path
);
994 static void add_source_to_list(struct list
*sourcelist
, media_info
*info
,
999 static const WCHAR fmt
[] = {'%','i',0};
1001 if (index
) *index
= 0;
1003 if (list_empty(sourcelist
))
1005 list_add_head(sourcelist
, &info
->entry
);
1009 LIST_FOR_EACH_ENTRY(iter
, sourcelist
, media_info
, entry
)
1011 if (!found
&& info
->index
< iter
->index
)
1014 list_add_before(&iter
->entry
, &info
->entry
);
1017 /* update the rest of the list */
1019 sprintfW(iter
->szIndex
, fmt
, ++iter
->index
);
1025 list_add_after(&iter
->entry
, &info
->entry
);
1028 static UINT
fill_source_list(struct list
*sourcelist
, HKEY sourcekey
, DWORD
*count
)
1030 UINT r
= ERROR_SUCCESS
;
1033 DWORD size
, val_size
;
1038 while (r
== ERROR_SUCCESS
)
1040 size
= sizeof(name
) / sizeof(name
[0]);
1041 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
, NULL
, NULL
, &val_size
);
1042 if (r
!= ERROR_SUCCESS
)
1045 entry
= msi_alloc(sizeof(media_info
));
1049 entry
->path
= msi_alloc(val_size
);
1056 lstrcpyW(entry
->szIndex
, name
);
1057 entry
->index
= atoiW(name
);
1060 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
,
1061 NULL
, (LPBYTE
)entry
->path
, &val_size
);
1062 if (r
!= ERROR_SUCCESS
)
1064 msi_free(entry
->path
);
1070 add_source_to_list(sourcelist
, entry
, NULL
);
1075 free_source_list(sourcelist
);
1076 return ERROR_OUTOFMEMORY
;
1079 /******************************************************************
1080 * MsiSourceListAddSourceExW (MSI.@)
1082 UINT WINAPI
MsiSourceListAddSourceExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1083 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCWSTR szSource
,
1089 struct list sourcelist
;
1091 WCHAR squished_pc
[GUID_SIZE
];
1098 static const WCHAR fmt
[] = {'%','i',0};
1099 static const WCHAR one
[] = {'1',0};
1100 static const WCHAR backslash
[] = {'\\',0};
1101 static const WCHAR forwardslash
[] = {'/',0};
1103 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1104 dwContext
, dwOptions
, debugstr_w(szSource
), dwIndex
);
1106 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1107 return ERROR_INVALID_PARAMETER
;
1109 if (!szSource
|| !*szSource
)
1110 return ERROR_INVALID_PARAMETER
;
1112 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
1113 return ERROR_INVALID_PARAMETER
;
1115 if (dwOptions
& MSICODE_PATCH
)
1117 FIXME("Unhandled options MSICODE_PATCH\n");
1118 return ERROR_FUNCTION_FAILED
;
1121 if (szUserSid
&& (dwContext
& MSIINSTALLCONTEXT_MACHINE
))
1122 return ERROR_INVALID_PARAMETER
;
1124 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1125 if (rc
!= ERROR_SUCCESS
)
1128 if (dwOptions
& MSISOURCETYPE_NETWORK
)
1129 rc
= OpenNetworkSubkey(sourcekey
, &typekey
, TRUE
);
1130 else if (dwOptions
& MSISOURCETYPE_URL
)
1131 rc
= OpenURLSubkey(sourcekey
, &typekey
, TRUE
);
1132 else if (dwOptions
& MSISOURCETYPE_MEDIA
)
1133 rc
= OpenMediaSubkey(sourcekey
, &typekey
, TRUE
);
1136 ERR("unknown media type: %08x\n", dwOptions
);
1137 RegCloseKey(sourcekey
);
1138 return ERROR_FUNCTION_FAILED
;
1141 postfix
= (dwOptions
& MSISOURCETYPE_NETWORK
) ? backslash
: forwardslash
;
1142 if (szSource
[lstrlenW(szSource
) - 1] == *postfix
)
1143 source
= strdupW(szSource
);
1146 size
= lstrlenW(szSource
) + 2;
1147 source
= msi_alloc(size
* sizeof(WCHAR
));
1148 lstrcpyW(source
, szSource
);
1149 lstrcatW(source
, postfix
);
1152 list_init(&sourcelist
);
1153 rc
= fill_source_list(&sourcelist
, typekey
, &count
);
1154 if (rc
!= ERROR_NO_MORE_ITEMS
)
1157 size
= (lstrlenW(source
) + 1) * sizeof(WCHAR
);
1161 rc
= RegSetValueExW(typekey
, one
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1164 else if (dwIndex
> count
|| dwIndex
== 0)
1166 sprintfW(name
, fmt
, count
+ 1);
1167 rc
= RegSetValueExW(typekey
, name
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1172 sprintfW(name
, fmt
, dwIndex
);
1173 info
= msi_alloc(sizeof(media_info
));
1176 rc
= ERROR_OUTOFMEMORY
;
1180 info
->path
= strdupW(source
);
1181 lstrcpyW(info
->szIndex
, name
);
1182 info
->index
= dwIndex
;
1183 add_source_to_list(&sourcelist
, info
, &index
);
1185 LIST_FOR_EACH_ENTRY(info
, &sourcelist
, media_info
, entry
)
1187 if (info
->index
< index
)
1190 size
= (lstrlenW(info
->path
) + 1) * sizeof(WCHAR
);
1191 rc
= RegSetValueExW(typekey
, info
->szIndex
, 0,
1192 REG_EXPAND_SZ
, (LPBYTE
)info
->path
, size
);
1193 if (rc
!= ERROR_SUCCESS
)
1199 free_source_list(&sourcelist
);
1201 RegCloseKey(typekey
);
1202 RegCloseKey(sourcekey
);
1206 /******************************************************************
1207 * MsiSourceListAddMediaDiskA (MSI.@)
1209 UINT WINAPI
MsiSourceListAddMediaDiskA(LPCSTR szProduct
, LPCSTR szUserSid
,
1210 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1211 LPCSTR szVolumeLabel
, LPCSTR szDiskPrompt
)
1214 LPWSTR product
= NULL
;
1215 LPWSTR usersid
= NULL
;
1216 LPWSTR volume
= NULL
;
1217 LPWSTR prompt
= NULL
;
1219 if (szProduct
) product
= strdupAtoW(szProduct
);
1220 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1221 if (szVolumeLabel
) volume
= strdupAtoW(szVolumeLabel
);
1222 if (szDiskPrompt
) prompt
= strdupAtoW(szDiskPrompt
);
1224 r
= MsiSourceListAddMediaDiskW(product
, usersid
, dwContext
, dwOptions
,
1225 dwDiskId
, volume
, prompt
);
1235 /******************************************************************
1236 * MsiSourceListAddMediaDiskW (MSI.@)
1238 UINT WINAPI
MsiSourceListAddMediaDiskW(LPCWSTR szProduct
, LPCWSTR szUserSid
,
1239 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1240 LPCWSTR szVolumeLabel
, LPCWSTR szDiskPrompt
)
1246 WCHAR squished_pc
[GUID_SIZE
];
1250 static const WCHAR fmt
[] = {'%','i',0};
1251 static const WCHAR semicolon
[] = {';',0};
1253 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct
),
1254 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwDiskId
,
1255 debugstr_w(szVolumeLabel
), debugstr_w(szDiskPrompt
));
1257 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1258 return ERROR_INVALID_PARAMETER
;
1260 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
1261 return ERROR_INVALID_PARAMETER
;
1263 if ((szVolumeLabel
&& !*szVolumeLabel
) || (szDiskPrompt
&& !*szDiskPrompt
))
1264 return ERROR_INVALID_PARAMETER
;
1266 if ((dwContext
& MSIINSTALLCONTEXT_MACHINE
) && szUserSid
)
1267 return ERROR_INVALID_PARAMETER
;
1269 if (dwOptions
& MSICODE_PATCH
)
1271 FIXME("Unhandled options MSICODE_PATCH\n");
1272 return ERROR_FUNCTION_FAILED
;
1275 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1276 if (rc
!= ERROR_SUCCESS
)
1279 OpenMediaSubkey(sourcekey
, &mediakey
, TRUE
);
1281 sprintfW(szIndex
, fmt
, dwDiskId
);
1284 if (szVolumeLabel
) size
+= lstrlenW(szVolumeLabel
);
1285 if (szDiskPrompt
) size
+= lstrlenW(szDiskPrompt
);
1287 size
*= sizeof(WCHAR
);
1288 buffer
= msi_alloc(size
);
1291 if (szVolumeLabel
) lstrcpyW(buffer
, szVolumeLabel
);
1292 lstrcatW(buffer
, semicolon
);
1293 if (szDiskPrompt
) lstrcatW(buffer
, szDiskPrompt
);
1295 RegSetValueExW(mediakey
, szIndex
, 0, REG_SZ
, (LPBYTE
)buffer
, size
);
1298 RegCloseKey(sourcekey
);
1299 RegCloseKey(mediakey
);
1301 return ERROR_SUCCESS
;
1304 /******************************************************************
1305 * MsiSourceListClearAllA (MSI.@)
1307 UINT WINAPI
MsiSourceListClearAllA( LPCSTR szProduct
, LPCSTR szUserName
, DWORD dwReserved
)
1309 FIXME("(%s %s %d)\n", debugstr_a(szProduct
), debugstr_a(szUserName
), dwReserved
);
1310 return ERROR_SUCCESS
;
1313 /******************************************************************
1314 * MsiSourceListClearAllW (MSI.@)
1316 UINT WINAPI
MsiSourceListClearAllW( LPCWSTR szProduct
, LPCWSTR szUserName
, DWORD dwReserved
)
1318 FIXME("(%s %s %d)\n", debugstr_w(szProduct
), debugstr_w(szUserName
), dwReserved
);
1319 return ERROR_SUCCESS
;
1322 /******************************************************************
1323 * MsiSourceListClearSourceA (MSI.@)
1325 UINT WINAPI
MsiSourceListClearSourceA(LPCSTR szProductCodeOrPatchCode
, LPCSTR szUserSid
,
1326 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1329 FIXME("(%s %s %x %x %s)\n", debugstr_a(szProductCodeOrPatchCode
), debugstr_a(szUserSid
),
1330 dwContext
, dwOptions
, debugstr_a(szSource
));
1331 return ERROR_SUCCESS
;
1334 /******************************************************************
1335 * MsiSourceListClearSourceW (MSI.@)
1337 UINT WINAPI
MsiSourceListClearSourceW(LPCWSTR szProductCodeOrPatchCode
, LPCWSTR szUserSid
,
1338 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1341 FIXME("(%s %s %x %x %s)\n", debugstr_w(szProductCodeOrPatchCode
), debugstr_w(szUserSid
),
1342 dwContext
, dwOptions
, debugstr_w(szSource
));
1343 return ERROR_SUCCESS
;