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
23 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
26 * These apis are defined in MSI 3.0
29 typedef struct tagMediaInfo
37 static UINT
OpenSourceKey(LPCWSTR szProduct
, HKEY
* key
, DWORD dwOptions
,
38 MSIINSTALLCONTEXT context
, BOOL create
)
41 UINT rc
= ERROR_FUNCTION_FAILED
;
43 if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
45 if (dwOptions
& MSICODE_PATCH
)
46 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
48 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
51 else if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
53 if (dwOptions
& MSICODE_PATCH
)
54 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
56 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
59 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
61 if (dwOptions
& MSICODE_PATCH
)
62 rc
= MSIREG_OpenPatchesKey(szProduct
, &rootkey
, create
);
64 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
68 if (rc
!= ERROR_SUCCESS
)
70 if (dwOptions
& MSICODE_PATCH
)
71 return ERROR_UNKNOWN_PATCH
;
73 return ERROR_UNKNOWN_PRODUCT
;
77 rc
= RegCreateKeyW(rootkey
, szSourceList
, key
);
80 rc
= RegOpenKeyW(rootkey
,szSourceList
, key
);
81 if (rc
!= ERROR_SUCCESS
)
82 rc
= ERROR_BAD_CONFIGURATION
;
88 static UINT
OpenMediaSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
91 static const WCHAR media
[] = {'M','e','d','i','a',0};
94 rc
= RegCreateKeyW(rootkey
, media
, key
);
96 rc
= RegOpenKeyW(rootkey
,media
, key
);
101 static UINT
OpenNetworkSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
104 static const WCHAR net
[] = {'N','e','t',0};
107 rc
= RegCreateKeyW(rootkey
, net
, key
);
109 rc
= RegOpenKeyW(rootkey
, net
, key
);
114 static UINT
OpenURLSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
117 static const WCHAR URL
[] = {'U','R','L',0};
120 rc
= RegCreateKeyW(rootkey
, URL
, key
);
122 rc
= RegOpenKeyW(rootkey
, URL
, key
);
127 /******************************************************************
128 * MsiSourceListEnumMediaDisksA (MSI.@)
130 UINT WINAPI
MsiSourceListEnumMediaDisksA(LPCSTR szProductCodeOrPatchCode
,
131 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
132 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
133 LPSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
134 LPSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
136 LPWSTR product
= NULL
;
137 LPWSTR usersid
= NULL
;
138 LPWSTR volume
= NULL
;
139 LPWSTR prompt
= NULL
;
140 UINT r
= ERROR_INVALID_PARAMETER
;
142 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n", debugstr_a(szProductCodeOrPatchCode
),
143 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, pdwDiskId
,
144 szVolumeLabel
, pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
146 if (szDiskPrompt
&& !pcchDiskPrompt
)
147 return ERROR_INVALID_PARAMETER
;
149 if (szProductCodeOrPatchCode
) product
= strdupAtoW(szProductCodeOrPatchCode
);
150 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
152 /* FIXME: add tests for an invalid format */
155 volume
= msi_alloc(*pcchVolumeLabel
* sizeof(WCHAR
));
158 prompt
= msi_alloc(*pcchDiskPrompt
* sizeof(WCHAR
));
160 if (volume
) *volume
= '\0';
161 if (prompt
) *prompt
= '\0';
162 r
= MsiSourceListEnumMediaDisksW(product
, usersid
, dwContext
, dwOptions
,
163 dwIndex
, pdwDiskId
, volume
, pcchVolumeLabel
,
164 prompt
, pcchDiskPrompt
);
165 if (r
!= ERROR_SUCCESS
)
168 if (szVolumeLabel
&& pcchVolumeLabel
)
169 WideCharToMultiByte(CP_ACP
, 0, volume
, -1, szVolumeLabel
,
170 *pcchVolumeLabel
+ 1, NULL
, NULL
);
173 WideCharToMultiByte(CP_ACP
, 0, prompt
, -1, szDiskPrompt
,
174 *pcchDiskPrompt
+ 1, NULL
, NULL
);
185 /******************************************************************
186 * MsiSourceListEnumMediaDisksW (MSI.@)
188 UINT WINAPI
MsiSourceListEnumMediaDisksW(LPCWSTR szProductCodeOrPatchCode
,
189 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
190 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
191 LPWSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
192 LPWSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
194 WCHAR squished_pc
[GUID_SIZE
];
200 DWORD valuesz
, datasz
= 0;
205 static DWORD index
= 0;
207 static const WCHAR fmt
[] = {'#','%','d',0};
209 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p)\n", debugstr_w(szProductCodeOrPatchCode
),
210 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szVolumeLabel
,
211 pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
213 if (!szProductCodeOrPatchCode
||
214 !squash_guid(szProductCodeOrPatchCode
, squished_pc
))
215 return ERROR_INVALID_PARAMETER
;
217 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
218 return ERROR_INVALID_PARAMETER
;
220 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
221 return ERROR_INVALID_PARAMETER
;
223 if (szDiskPrompt
&& !pcchDiskPrompt
)
224 return ERROR_INVALID_PARAMETER
;
229 if (dwIndex
!= index
)
230 return ERROR_INVALID_PARAMETER
;
232 r
= OpenSourceKey(szProductCodeOrPatchCode
, &source
,
233 dwOptions
, dwContext
, FALSE
);
234 if (r
!= ERROR_SUCCESS
)
237 r
= OpenMediaSubkey(source
, &media
, FALSE
);
238 if (r
!= ERROR_SUCCESS
)
241 return ERROR_NO_MORE_ITEMS
;
244 if (!pcchVolumeLabel
&& !pcchDiskPrompt
)
246 r
= RegEnumValueW(media
, dwIndex
, NULL
, NULL
, NULL
,
251 res
= RegQueryInfoKeyW(media
, NULL
, NULL
, NULL
, NULL
, NULL
,
252 NULL
, &numvals
, &valuesz
, &datasz
, NULL
, NULL
);
253 if (res
!= ERROR_SUCCESS
)
255 r
= ERROR_BAD_CONFIGURATION
;
259 value
= msi_alloc(++valuesz
* sizeof(WCHAR
));
260 data
= msi_alloc(++datasz
* sizeof(WCHAR
));
263 r
= ERROR_OUTOFMEMORY
;
267 r
= RegEnumValueW(media
, dwIndex
, value
, &valuesz
,
268 NULL
, &type
, (LPBYTE
)data
, &datasz
);
269 if (r
!= ERROR_SUCCESS
)
273 *pdwDiskId
= atolW(value
);
276 ptr
= strchrW(data
, ';');
284 if (type
== REG_DWORD
)
286 sprintfW(convert
, fmt
, *data
);
287 size
= lstrlenW(convert
);
291 size
= lstrlenW(data
);
293 if (size
>= *pcchVolumeLabel
)
295 else if (szVolumeLabel
)
296 lstrcpyW(szVolumeLabel
, ptr2
);
298 *pcchVolumeLabel
= size
;
306 if (type
== REG_DWORD
)
308 sprintfW(convert
, fmt
, *ptr
);
309 size
= lstrlenW(convert
);
313 size
= lstrlenW(ptr
);
315 if (size
>= *pcchDiskPrompt
)
317 else if (szDiskPrompt
)
318 lstrcpyW(szDiskPrompt
, ptr
);
320 *pcchDiskPrompt
= size
;
333 /******************************************************************
334 * MsiSourceListEnumSourcesA (MSI.@)
336 UINT WINAPI
MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch
, LPCSTR szUserSid
,
337 MSIINSTALLCONTEXT dwContext
,
338 DWORD dwOptions
, DWORD dwIndex
,
339 LPSTR szSource
, LPDWORD pcchSource
)
341 LPWSTR product
= NULL
;
342 LPWSTR usersid
= NULL
;
343 LPWSTR source
= NULL
;
345 UINT r
= ERROR_INVALID_PARAMETER
;
346 static DWORD index
= 0;
348 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_a(szProductCodeOrPatch
),
349 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
354 if (szSource
&& !pcchSource
)
357 if (dwIndex
!= index
)
360 if (szProductCodeOrPatch
) product
= strdupAtoW(szProductCodeOrPatch
);
361 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
363 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
364 dwIndex
, NULL
, &len
);
365 if (r
!= ERROR_SUCCESS
)
368 source
= msi_alloc(++len
* sizeof(WCHAR
));
371 r
= ERROR_OUTOFMEMORY
;
376 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
377 dwIndex
, source
, &len
);
378 if (r
!= ERROR_SUCCESS
)
381 len
= WideCharToMultiByte(CP_ACP
, 0, source
, -1, NULL
, 0, NULL
, NULL
);
382 if (pcchSource
&& *pcchSource
>= len
)
383 WideCharToMultiByte(CP_ACP
, 0, source
, -1, szSource
, len
, NULL
, NULL
);
388 *pcchSource
= len
- 1;
395 if (r
== ERROR_SUCCESS
)
397 if (szSource
|| !pcchSource
) index
++;
399 else if (dwIndex
> index
)
405 /******************************************************************
406 * MsiSourceListEnumSourcesW (MSI.@)
408 UINT WINAPI
MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch
, LPCWSTR szUserSid
,
409 MSIINSTALLCONTEXT dwContext
,
410 DWORD dwOptions
, DWORD dwIndex
,
411 LPWSTR szSource
, LPDWORD pcchSource
)
413 WCHAR squished_pc
[GUID_SIZE
];
418 UINT r
= ERROR_INVALID_PARAMETER
;
419 static DWORD index
= 0;
421 static const WCHAR format
[] = {'%','d',0};
423 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch
),
424 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
429 if (!szProductCodeOrPatch
|| !squash_guid(szProductCodeOrPatch
, squished_pc
))
432 if (szSource
&& !pcchSource
)
435 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
438 if ((dwOptions
& MSISOURCETYPE_NETWORK
) && (dwOptions
& MSISOURCETYPE_URL
))
441 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
444 if (dwIndex
!= index
)
447 r
= OpenSourceKey(szProductCodeOrPatch
, &source
,
448 dwOptions
, dwContext
, FALSE
);
449 if (r
!= ERROR_SUCCESS
)
452 if (dwOptions
& MSISOURCETYPE_NETWORK
)
453 r
= OpenNetworkSubkey(source
, &subkey
, FALSE
);
454 else if (dwOptions
& MSISOURCETYPE_URL
)
455 r
= OpenURLSubkey(source
, &subkey
, FALSE
);
457 if (r
!= ERROR_SUCCESS
)
459 r
= ERROR_NO_MORE_ITEMS
;
463 sprintfW(name
, format
, dwIndex
+ 1);
465 res
= RegQueryValueExW(subkey
, name
, 0, 0, (LPBYTE
)szSource
, pcchSource
);
466 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
467 r
= ERROR_NO_MORE_ITEMS
;
473 if (r
== ERROR_SUCCESS
)
475 if (szSource
|| !pcchSource
) index
++;
477 else if (dwIndex
> index
)
483 /******************************************************************
484 * MsiSourceListGetInfoA (MSI.@)
486 UINT WINAPI
MsiSourceListGetInfoA( LPCSTR szProduct
, LPCSTR szUserSid
,
487 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
488 LPCSTR szProperty
, LPSTR szValue
,
492 LPWSTR product
= NULL
;
493 LPWSTR usersid
= NULL
;
494 LPWSTR property
= NULL
;
498 if (szValue
&& !pcchValue
)
499 return ERROR_INVALID_PARAMETER
;
501 if (szProduct
) product
= strdupAtoW(szProduct
);
502 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
503 if (szProperty
) property
= strdupAtoW(szProperty
);
505 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
506 property
, NULL
, &len
);
507 if (ret
!= ERROR_SUCCESS
)
510 value
= msi_alloc(++len
* sizeof(WCHAR
));
512 return ERROR_OUTOFMEMORY
;
515 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
516 property
, value
, &len
);
517 if (ret
!= ERROR_SUCCESS
)
520 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
521 if (*pcchValue
>= len
)
522 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
524 ret
= ERROR_MORE_DATA
;
526 *pcchValue
= len
- 1;
536 /******************************************************************
537 * MsiSourceListGetInfoW (MSI.@)
539 UINT WINAPI
MsiSourceListGetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
540 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
541 LPCWSTR szProperty
, LPWSTR szValue
,
544 WCHAR squished_pc
[GUID_SIZE
];
545 HKEY sourcekey
, media
;
550 static const WCHAR mediapack
[] = {
551 'M','e','d','i','a','P','a','c','k','a','g','e',0};
553 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szProperty
));
555 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
556 return ERROR_INVALID_PARAMETER
;
558 if (szValue
&& !pcchValue
)
559 return ERROR_INVALID_PARAMETER
;
561 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
562 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
563 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
564 return ERROR_INVALID_PARAMETER
;
567 return ERROR_INVALID_PARAMETER
;
570 FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid
));
572 rc
= OpenSourceKey(szProduct
, &sourcekey
, dwOptions
, dwContext
, FALSE
);
573 if (rc
!= ERROR_SUCCESS
)
576 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
577 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
579 rc
= OpenMediaSubkey(sourcekey
, &media
, FALSE
);
580 if (rc
!= ERROR_SUCCESS
)
582 RegCloseKey(sourcekey
);
583 return ERROR_SUCCESS
;
586 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
587 szProperty
= mediapack
;
589 RegQueryValueExW(media
, szProperty
, 0, 0, (LPBYTE
)szValue
, pcchValue
);
592 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) ||
593 !strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
595 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
597 if (rc
!= ERROR_SUCCESS
)
599 RegCloseKey(sourcekey
);
600 return ERROR_SUCCESS
;
603 source
= msi_alloc(size
);
604 RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
605 0, 0, (LPBYTE
)source
, &size
);
610 RegCloseKey(sourcekey
);
611 return ERROR_SUCCESS
;
614 if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
616 if (*source
!= 'n' && *source
!= 'u' && *source
!= 'm')
619 RegCloseKey(sourcekey
);
620 return ERROR_SUCCESS
;
628 ptr
= strrchrW(source
, ';');
637 if (strlenW(ptr
) < *pcchValue
)
638 lstrcpyW(szValue
, ptr
);
640 rc
= ERROR_MORE_DATA
;
643 *pcchValue
= lstrlenW(ptr
);
646 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
648 *pcchValue
= *pcchValue
* sizeof(WCHAR
);
649 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0, 0,
650 (LPBYTE
)szValue
, pcchValue
);
651 if (rc
!= ERROR_SUCCESS
&& rc
!= ERROR_MORE_DATA
)
659 *pcchValue
= (*pcchValue
- 1) / sizeof(WCHAR
);
661 szValue
[*pcchValue
] = '\0';
666 FIXME("Unknown property %s\n",debugstr_w(szProperty
));
667 rc
= ERROR_UNKNOWN_PROPERTY
;
670 RegCloseKey(sourcekey
);
674 /******************************************************************
675 * MsiSourceListSetInfoA (MSI.@)
677 UINT WINAPI
MsiSourceListSetInfoA(LPCSTR szProduct
, LPCSTR szUserSid
,
678 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
679 LPCSTR szProperty
, LPCSTR szValue
)
682 LPWSTR product
= NULL
;
683 LPWSTR usersid
= NULL
;
684 LPWSTR property
= NULL
;
687 if (szProduct
) product
= strdupAtoW(szProduct
);
688 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
689 if (szProperty
) property
= strdupAtoW(szProperty
);
690 if (szValue
) value
= strdupAtoW(szValue
);
692 ret
= MsiSourceListSetInfoW(product
, usersid
, dwContext
, dwOptions
,
703 UINT
msi_set_last_used_source(LPCWSTR product
, LPCWSTR usersid
,
704 MSIINSTALLCONTEXT context
, DWORD options
,
714 static const WCHAR format
[] = {'%','c',';','%','i',';','%','s',0};
716 if (options
& MSISOURCETYPE_NETWORK
)
718 else if (options
& MSISOURCETYPE_URL
)
720 else if (options
& MSISOURCETYPE_MEDIA
)
723 return ERROR_INVALID_PARAMETER
;
725 if (!(options
& MSISOURCETYPE_MEDIA
))
727 r
= MsiSourceListAddSourceExW(product
, usersid
, context
,
729 if (r
!= ERROR_SUCCESS
)
733 while ((r
= MsiSourceListEnumSourcesW(product
, usersid
, context
, options
,
734 index
, NULL
, NULL
)) == ERROR_SUCCESS
)
737 if (r
!= ERROR_NO_MORE_ITEMS
)
741 size
= (lstrlenW(format
) + lstrlenW(value
) + 7) * sizeof(WCHAR
);
742 buffer
= msi_alloc(size
);
744 return ERROR_OUTOFMEMORY
;
746 r
= OpenSourceKey(product
, &source
, MSICODE_PRODUCT
, context
, FALSE
);
747 if (r
!= ERROR_SUCCESS
)
753 sprintfW(buffer
, format
, typechar
, index
, value
);
755 size
= (lstrlenW(buffer
) + 1) * sizeof(WCHAR
);
756 r
= RegSetValueExW(source
, INSTALLPROPERTY_LASTUSEDSOURCEW
, 0,
757 REG_SZ
, (LPBYTE
)buffer
, size
);
764 /******************************************************************
765 * MsiSourceListSetInfoW (MSI.@)
767 UINT WINAPI
MsiSourceListSetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
768 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
769 LPCWSTR szProperty
, LPCWSTR szValue
)
771 WCHAR squished_pc
[GUID_SIZE
];
772 HKEY sourcekey
, media
;
776 static const WCHAR media_package
[] = {
777 'M','e','d','i','a','P','a','c','k','a','g','e',0
780 TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
781 dwContext
, dwOptions
, debugstr_w(szProperty
), debugstr_w(szValue
));
783 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
784 return ERROR_INVALID_PARAMETER
;
787 return ERROR_INVALID_PARAMETER
;
790 return ERROR_UNKNOWN_PROPERTY
;
792 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
793 return ERROR_INVALID_PARAMETER
;
795 if (dwOptions
& MSICODE_PATCH
)
797 FIXME("Unhandled options MSICODE_PATCH\n");
798 return ERROR_UNKNOWN_PATCH
;
801 property
= szProperty
;
802 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
803 property
= media_package
;
805 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
806 if (rc
!= ERROR_SUCCESS
)
809 if (strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) &&
810 dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
))
812 RegCloseKey(sourcekey
);
813 return ERROR_INVALID_PARAMETER
;
816 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
817 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
819 rc
= OpenMediaSubkey(sourcekey
, &media
, TRUE
);
820 if (rc
== ERROR_SUCCESS
)
822 rc
= msi_reg_set_val_str(media
, property
, szValue
);
826 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
828 DWORD size
= (lstrlenW(szValue
) + 1) * sizeof(WCHAR
);
829 rc
= RegSetValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0,
830 REG_SZ
, (const BYTE
*)szValue
, size
);
831 if (rc
!= ERROR_SUCCESS
)
832 rc
= ERROR_UNKNOWN_PROPERTY
;
834 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
836 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
837 rc
= ERROR_INVALID_PARAMETER
;
839 rc
= msi_set_last_used_source(szProduct
, szUserSid
, dwContext
,
843 rc
= ERROR_UNKNOWN_PROPERTY
;
845 RegCloseKey(sourcekey
);
849 /******************************************************************
850 * MsiSourceListAddSourceW (MSI.@)
852 UINT WINAPI
MsiSourceListAddSourceW( LPCWSTR szProduct
, LPCWSTR szUserName
,
853 DWORD dwReserved
, LPCWSTR szSource
)
855 WCHAR squished_pc
[GUID_SIZE
];
857 LPWSTR sidstr
= NULL
;
864 TRACE("%s %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserName
), debugstr_w(szSource
));
866 if (!szSource
|| !*szSource
)
867 return ERROR_INVALID_PARAMETER
;
870 return ERROR_INVALID_PARAMETER
;
872 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
873 return ERROR_INVALID_PARAMETER
;
875 if (!szUserName
|| !*szUserName
)
876 context
= MSIINSTALLCONTEXT_MACHINE
;
879 if (LookupAccountNameW(NULL
, szUserName
, NULL
, &sidsize
, NULL
, &domsize
, NULL
))
881 PSID psid
= msi_alloc(sidsize
);
883 if (LookupAccountNameW(NULL
, szUserName
, psid
, &sidsize
, NULL
, &domsize
, NULL
))
884 ConvertSidToStringSidW(psid
, &sidstr
);
889 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
890 MSIINSTALLCONTEXT_USERMANAGED
, &hkey
, FALSE
);
891 if (r
== ERROR_SUCCESS
)
892 context
= MSIINSTALLCONTEXT_USERMANAGED
;
895 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
896 MSIINSTALLCONTEXT_USERUNMANAGED
,
898 if (r
!= ERROR_SUCCESS
)
899 return ERROR_UNKNOWN_PRODUCT
;
901 context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
907 ret
= MsiSourceListAddSourceExW(szProduct
, sidstr
,
908 context
, MSISOURCETYPE_NETWORK
, szSource
, 0);
916 /******************************************************************
917 * MsiSourceListAddSourceA (MSI.@)
919 UINT WINAPI
MsiSourceListAddSourceA( LPCSTR szProduct
, LPCSTR szUserName
,
920 DWORD dwReserved
, LPCSTR szSource
)
927 szwproduct
= strdupAtoW( szProduct
);
928 szwusername
= strdupAtoW( szUserName
);
929 szwsource
= strdupAtoW( szSource
);
931 ret
= MsiSourceListAddSourceW(szwproduct
, szwusername
, dwReserved
, szwsource
);
933 msi_free(szwproduct
);
934 msi_free(szwusername
);
940 /******************************************************************
941 * MsiSourceListAddSourceExA (MSI.@)
943 UINT WINAPI
MsiSourceListAddSourceExA(LPCSTR szProduct
, LPCSTR szUserSid
,
944 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCSTR szSource
, DWORD dwIndex
)
947 LPWSTR product
, usersid
, source
;
949 product
= strdupAtoW(szProduct
);
950 usersid
= strdupAtoW(szUserSid
);
951 source
= strdupAtoW(szSource
);
953 ret
= MsiSourceListAddSourceExW(product
, usersid
, dwContext
,
954 dwOptions
, source
, dwIndex
);
963 static void free_source_list(struct list
*sourcelist
)
965 while (!list_empty(sourcelist
))
967 media_info
*info
= LIST_ENTRY(list_head(sourcelist
), media_info
, entry
);
968 list_remove(&info
->entry
);
969 msi_free(info
->path
);
974 static void add_source_to_list(struct list
*sourcelist
, media_info
*info
,
979 static const WCHAR fmt
[] = {'%','i',0};
981 if (index
) *index
= 0;
983 if (list_empty(sourcelist
))
985 list_add_head(sourcelist
, &info
->entry
);
989 LIST_FOR_EACH_ENTRY(iter
, sourcelist
, media_info
, entry
)
991 if (!found
&& info
->index
< iter
->index
)
994 list_add_before(&iter
->entry
, &info
->entry
);
997 /* update the rest of the list */
999 sprintfW(iter
->szIndex
, fmt
, ++iter
->index
);
1005 list_add_after(&iter
->entry
, &info
->entry
);
1008 static UINT
fill_source_list(struct list
*sourcelist
, HKEY sourcekey
, DWORD
*count
)
1010 UINT r
= ERROR_SUCCESS
;
1013 DWORD size
, val_size
;
1018 while (r
== ERROR_SUCCESS
)
1020 size
= sizeof(name
) / sizeof(name
[0]);
1021 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
, NULL
, NULL
, &val_size
);
1022 if (r
!= ERROR_SUCCESS
)
1025 entry
= msi_alloc(sizeof(media_info
));
1029 entry
->path
= msi_alloc(val_size
);
1036 lstrcpyW(entry
->szIndex
, name
);
1037 entry
->index
= atoiW(name
);
1040 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
,
1041 NULL
, (LPBYTE
)entry
->path
, &val_size
);
1042 if (r
!= ERROR_SUCCESS
)
1044 msi_free(entry
->path
);
1050 add_source_to_list(sourcelist
, entry
, NULL
);
1055 free_source_list(sourcelist
);
1056 return ERROR_OUTOFMEMORY
;
1059 /******************************************************************
1060 * MsiSourceListAddSourceExW (MSI.@)
1062 UINT WINAPI
MsiSourceListAddSourceExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1063 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCWSTR szSource
,
1069 struct list sourcelist
;
1071 WCHAR squished_pc
[GUID_SIZE
];
1078 static const WCHAR fmt
[] = {'%','i',0};
1080 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1081 dwContext
, dwOptions
, debugstr_w(szSource
), dwIndex
);
1083 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1084 return ERROR_INVALID_PARAMETER
;
1086 if (!szSource
|| !*szSource
)
1087 return ERROR_INVALID_PARAMETER
;
1089 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
1090 return ERROR_INVALID_PARAMETER
;
1092 if (dwOptions
& MSICODE_PATCH
)
1094 FIXME("Unhandled options MSICODE_PATCH\n");
1095 return ERROR_FUNCTION_FAILED
;
1098 if (szUserSid
&& (dwContext
& MSIINSTALLCONTEXT_MACHINE
))
1099 return ERROR_INVALID_PARAMETER
;
1101 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1102 if (rc
!= ERROR_SUCCESS
)
1105 if (dwOptions
& MSISOURCETYPE_NETWORK
)
1106 rc
= OpenNetworkSubkey(sourcekey
, &typekey
, TRUE
);
1107 else if (dwOptions
& MSISOURCETYPE_URL
)
1108 rc
= OpenURLSubkey(sourcekey
, &typekey
, TRUE
);
1109 else if (dwOptions
& MSISOURCETYPE_MEDIA
)
1110 rc
= OpenMediaSubkey(sourcekey
, &typekey
, TRUE
);
1113 ERR("unknown media type: %08x\n", dwOptions
);
1114 RegCloseKey(sourcekey
);
1115 return ERROR_FUNCTION_FAILED
;
1117 if (rc
!= ERROR_SUCCESS
)
1119 ERR("can't open subkey %u\n", rc
);
1120 RegCloseKey(sourcekey
);
1124 postfix
= (dwOptions
& MSISOURCETYPE_NETWORK
) ? szBackSlash
: szForwardSlash
;
1125 if (szSource
[lstrlenW(szSource
) - 1] == *postfix
)
1126 source
= strdupW(szSource
);
1129 size
= lstrlenW(szSource
) + 2;
1130 source
= msi_alloc(size
* sizeof(WCHAR
));
1131 lstrcpyW(source
, szSource
);
1132 lstrcatW(source
, postfix
);
1135 list_init(&sourcelist
);
1136 rc
= fill_source_list(&sourcelist
, typekey
, &count
);
1137 if (rc
!= ERROR_NO_MORE_ITEMS
)
1140 size
= (lstrlenW(source
) + 1) * sizeof(WCHAR
);
1144 rc
= RegSetValueExW(typekey
, szOne
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1147 else if (dwIndex
> count
|| dwIndex
== 0)
1149 sprintfW(name
, fmt
, count
+ 1);
1150 rc
= RegSetValueExW(typekey
, name
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1155 sprintfW(name
, fmt
, dwIndex
);
1156 info
= msi_alloc(sizeof(media_info
));
1159 rc
= ERROR_OUTOFMEMORY
;
1163 info
->path
= strdupW(source
);
1164 lstrcpyW(info
->szIndex
, name
);
1165 info
->index
= dwIndex
;
1166 add_source_to_list(&sourcelist
, info
, &index
);
1168 LIST_FOR_EACH_ENTRY(info
, &sourcelist
, media_info
, entry
)
1170 if (info
->index
< index
)
1173 size
= (lstrlenW(info
->path
) + 1) * sizeof(WCHAR
);
1174 rc
= RegSetValueExW(typekey
, info
->szIndex
, 0,
1175 REG_EXPAND_SZ
, (LPBYTE
)info
->path
, size
);
1176 if (rc
!= ERROR_SUCCESS
)
1182 free_source_list(&sourcelist
);
1184 RegCloseKey(typekey
);
1185 RegCloseKey(sourcekey
);
1189 /******************************************************************
1190 * MsiSourceListAddMediaDiskA (MSI.@)
1192 UINT WINAPI
MsiSourceListAddMediaDiskA(LPCSTR szProduct
, LPCSTR szUserSid
,
1193 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1194 LPCSTR szVolumeLabel
, LPCSTR szDiskPrompt
)
1197 LPWSTR product
= NULL
;
1198 LPWSTR usersid
= NULL
;
1199 LPWSTR volume
= NULL
;
1200 LPWSTR prompt
= NULL
;
1202 if (szProduct
) product
= strdupAtoW(szProduct
);
1203 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1204 if (szVolumeLabel
) volume
= strdupAtoW(szVolumeLabel
);
1205 if (szDiskPrompt
) prompt
= strdupAtoW(szDiskPrompt
);
1207 r
= MsiSourceListAddMediaDiskW(product
, usersid
, dwContext
, dwOptions
,
1208 dwDiskId
, volume
, prompt
);
1218 /******************************************************************
1219 * MsiSourceListAddMediaDiskW (MSI.@)
1221 UINT WINAPI
MsiSourceListAddMediaDiskW(LPCWSTR szProduct
, LPCWSTR szUserSid
,
1222 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1223 LPCWSTR szVolumeLabel
, LPCWSTR szDiskPrompt
)
1229 WCHAR squished_pc
[GUID_SIZE
];
1233 static const WCHAR fmt
[] = {'%','i',0};
1235 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct
),
1236 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwDiskId
,
1237 debugstr_w(szVolumeLabel
), debugstr_w(szDiskPrompt
));
1239 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1240 return ERROR_INVALID_PARAMETER
;
1242 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
1243 return ERROR_INVALID_PARAMETER
;
1245 if ((szVolumeLabel
&& !*szVolumeLabel
) || (szDiskPrompt
&& !*szDiskPrompt
))
1246 return ERROR_INVALID_PARAMETER
;
1248 if ((dwContext
& MSIINSTALLCONTEXT_MACHINE
) && szUserSid
)
1249 return ERROR_INVALID_PARAMETER
;
1251 if (dwOptions
& MSICODE_PATCH
)
1253 FIXME("Unhandled options MSICODE_PATCH\n");
1254 return ERROR_FUNCTION_FAILED
;
1257 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1258 if (rc
!= ERROR_SUCCESS
)
1261 OpenMediaSubkey(sourcekey
, &mediakey
, TRUE
);
1263 sprintfW(szIndex
, fmt
, dwDiskId
);
1266 if (szVolumeLabel
) size
+= lstrlenW(szVolumeLabel
);
1267 if (szDiskPrompt
) size
+= lstrlenW(szDiskPrompt
);
1269 size
*= sizeof(WCHAR
);
1270 buffer
= msi_alloc(size
);
1273 if (szVolumeLabel
) lstrcpyW(buffer
, szVolumeLabel
);
1274 lstrcatW(buffer
, szSemiColon
);
1275 if (szDiskPrompt
) lstrcatW(buffer
, szDiskPrompt
);
1277 RegSetValueExW(mediakey
, szIndex
, 0, REG_SZ
, (LPBYTE
)buffer
, size
);
1280 RegCloseKey(sourcekey
);
1281 RegCloseKey(mediakey
);
1283 return ERROR_SUCCESS
;
1286 /******************************************************************
1287 * MsiSourceListClearAllA (MSI.@)
1289 UINT WINAPI
MsiSourceListClearAllA( LPCSTR szProduct
, LPCSTR szUserName
, DWORD dwReserved
)
1291 FIXME("(%s %s %d)\n", debugstr_a(szProduct
), debugstr_a(szUserName
), dwReserved
);
1292 return ERROR_SUCCESS
;
1295 /******************************************************************
1296 * MsiSourceListClearAllW (MSI.@)
1298 UINT WINAPI
MsiSourceListClearAllW( LPCWSTR szProduct
, LPCWSTR szUserName
, DWORD dwReserved
)
1300 FIXME("(%s %s %d)\n", debugstr_w(szProduct
), debugstr_w(szUserName
), dwReserved
);
1301 return ERROR_SUCCESS
;
1304 /******************************************************************
1305 * MsiSourceListClearAllExA (MSI.@)
1307 UINT WINAPI
MsiSourceListClearAllExA( LPCSTR szProduct
, LPCSTR szUserSid
,
1308 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1310 FIXME("(%s %s %d %08x)\n", debugstr_a(szProduct
), debugstr_a(szUserSid
),
1311 dwContext
, dwOptions
);
1312 return ERROR_SUCCESS
;
1315 /******************************************************************
1316 * MsiSourceListClearAllExW (MSI.@)
1318 UINT WINAPI
MsiSourceListClearAllExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1319 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1321 FIXME("(%s %s %d %08x)\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1322 dwContext
, dwOptions
);
1323 return ERROR_SUCCESS
;
1326 /******************************************************************
1327 * MsiSourceListClearSourceA (MSI.@)
1329 UINT WINAPI
MsiSourceListClearSourceA(LPCSTR szProductCodeOrPatchCode
, LPCSTR szUserSid
,
1330 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1333 FIXME("(%s %s %x %x %s)\n", debugstr_a(szProductCodeOrPatchCode
), debugstr_a(szUserSid
),
1334 dwContext
, dwOptions
, debugstr_a(szSource
));
1335 return ERROR_SUCCESS
;
1338 /******************************************************************
1339 * MsiSourceListClearSourceW (MSI.@)
1341 UINT WINAPI
MsiSourceListClearSourceW(LPCWSTR szProductCodeOrPatchCode
, LPCWSTR szUserSid
,
1342 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1345 FIXME("(%s %s %x %x %s)\n", debugstr_w(szProductCodeOrPatchCode
), debugstr_w(szUserSid
),
1346 dwContext
, dwOptions
, debugstr_w(szSource
));
1347 return ERROR_SUCCESS
;