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
30 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
42 * These apis are defined in MSI 3.0
45 typedef struct tagMediaInfo
53 static UINT
OpenSourceKey(LPCWSTR szProduct
, HKEY
* key
, DWORD dwOptions
,
54 MSIINSTALLCONTEXT context
, BOOL create
)
57 UINT rc
= ERROR_FUNCTION_FAILED
;
59 if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
61 if (dwOptions
& MSICODE_PATCH
)
62 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
64 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
67 else if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
69 if (dwOptions
& MSICODE_PATCH
)
70 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
72 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
75 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
77 if (dwOptions
& MSICODE_PATCH
)
78 rc
= MSIREG_OpenPatchesKey(szProduct
, &rootkey
, create
);
80 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
84 if (rc
!= ERROR_SUCCESS
)
86 if (dwOptions
& MSICODE_PATCH
)
87 return ERROR_UNKNOWN_PATCH
;
89 return ERROR_UNKNOWN_PRODUCT
;
93 rc
= RegCreateKeyW(rootkey
, szSourceList
, key
);
96 rc
= RegOpenKeyW(rootkey
,szSourceList
, key
);
97 if (rc
!= ERROR_SUCCESS
)
98 rc
= ERROR_BAD_CONFIGURATION
;
100 RegCloseKey(rootkey
);
105 static UINT
OpenMediaSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
108 static const WCHAR media
[] = {'M','e','d','i','a',0};
111 rc
= RegCreateKeyW(rootkey
, media
, key
);
113 rc
= RegOpenKeyW(rootkey
,media
, key
);
118 static UINT
OpenNetworkSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
121 static const WCHAR net
[] = {'N','e','t',0};
124 rc
= RegCreateKeyW(rootkey
, net
, key
);
126 rc
= RegOpenKeyW(rootkey
, net
, key
);
131 static UINT
OpenURLSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
134 static const WCHAR URL
[] = {'U','R','L',0};
137 rc
= RegCreateKeyW(rootkey
, URL
, key
);
139 rc
= RegOpenKeyW(rootkey
, URL
, key
);
144 /******************************************************************
145 * MsiSourceListEnumMediaDisksA (MSI.@)
147 UINT WINAPI
MsiSourceListEnumMediaDisksA(LPCSTR szProductCodeOrPatchCode
,
148 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
149 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
150 LPSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
151 LPSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
153 LPWSTR product
= NULL
;
154 LPWSTR usersid
= NULL
;
155 LPWSTR volume
= NULL
;
156 LPWSTR prompt
= NULL
;
157 UINT r
= ERROR_INVALID_PARAMETER
;
159 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n", debugstr_a(szProductCodeOrPatchCode
),
160 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, pdwDiskId
,
161 szVolumeLabel
, pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
163 if (szDiskPrompt
&& !pcchDiskPrompt
)
164 return ERROR_INVALID_PARAMETER
;
166 if (szProductCodeOrPatchCode
) product
= strdupAtoW(szProductCodeOrPatchCode
);
167 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
169 /* FIXME: add tests for an invalid format */
172 volume
= msi_alloc(*pcchVolumeLabel
* sizeof(WCHAR
));
175 prompt
= msi_alloc(*pcchDiskPrompt
* sizeof(WCHAR
));
177 if (volume
) *volume
= '\0';
178 if (prompt
) *prompt
= '\0';
179 r
= MsiSourceListEnumMediaDisksW(product
, usersid
, dwContext
, dwOptions
,
180 dwIndex
, pdwDiskId
, volume
, pcchVolumeLabel
,
181 prompt
, pcchDiskPrompt
);
182 if (r
!= ERROR_SUCCESS
)
185 if (szVolumeLabel
&& pcchVolumeLabel
)
186 WideCharToMultiByte(CP_ACP
, 0, volume
, -1, szVolumeLabel
,
187 *pcchVolumeLabel
+ 1, NULL
, NULL
);
190 WideCharToMultiByte(CP_ACP
, 0, prompt
, -1, szDiskPrompt
,
191 *pcchDiskPrompt
+ 1, NULL
, NULL
);
202 /******************************************************************
203 * MsiSourceListEnumMediaDisksW (MSI.@)
205 UINT WINAPI
MsiSourceListEnumMediaDisksW(LPCWSTR szProductCodeOrPatchCode
,
206 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
207 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
208 LPWSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
209 LPWSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
211 static const WCHAR fmt
[] = {'#','%','d',0};
212 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
], convert
[11];
213 WCHAR
*value
= NULL
, *data
= NULL
, *ptr
, *ptr2
;
215 DWORD valuesz
, datasz
= 0, type
, numvals
, size
;
218 static DWORD index
= 0;
220 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p)\n", debugstr_w(szProductCodeOrPatchCode
),
221 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szVolumeLabel
,
222 pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
224 if (!szProductCodeOrPatchCode
|| !squash_guid( szProductCodeOrPatchCode
, squashed_pc
))
225 return ERROR_INVALID_PARAMETER
;
227 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
228 return ERROR_INVALID_PARAMETER
;
230 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
231 return ERROR_INVALID_PARAMETER
;
233 if (szDiskPrompt
&& !pcchDiskPrompt
)
234 return ERROR_INVALID_PARAMETER
;
239 if (dwIndex
!= index
)
240 return ERROR_INVALID_PARAMETER
;
242 r
= OpenSourceKey(szProductCodeOrPatchCode
, &source
, dwOptions
, dwContext
, FALSE
);
243 if (r
!= ERROR_SUCCESS
)
246 r
= OpenMediaSubkey(source
, &media
, FALSE
);
247 if (r
!= ERROR_SUCCESS
)
250 return ERROR_NO_MORE_ITEMS
;
253 res
= RegQueryInfoKeyW(media
, NULL
, NULL
, NULL
, NULL
, NULL
,
254 NULL
, &numvals
, &valuesz
, &datasz
, NULL
, NULL
);
255 if (res
!= ERROR_SUCCESS
)
257 r
= ERROR_BAD_CONFIGURATION
;
261 value
= msi_alloc(++valuesz
* sizeof(WCHAR
));
262 data
= msi_alloc(++datasz
* sizeof(WCHAR
));
265 r
= ERROR_OUTOFMEMORY
;
269 r
= RegEnumValueW(media
, dwIndex
, value
, &valuesz
,
270 NULL
, &type
, (LPBYTE
)data
, &datasz
);
271 if (r
!= ERROR_SUCCESS
)
275 *pdwDiskId
= wcstol(value
, NULL
, 10);
278 ptr
= wcschr(data
, ';');
286 if (type
== REG_DWORD
)
288 swprintf(convert
, ARRAY_SIZE(convert
), fmt
, *data
);
289 size
= lstrlenW(convert
);
293 size
= lstrlenW(data
);
295 if (size
>= *pcchVolumeLabel
)
297 else if (szVolumeLabel
)
298 lstrcpyW(szVolumeLabel
, ptr2
);
300 *pcchVolumeLabel
= size
;
308 if (type
== REG_DWORD
)
310 swprintf(convert
, ARRAY_SIZE(convert
), fmt
, *ptr
);
311 size
= lstrlenW(convert
);
315 size
= lstrlenW(ptr
);
317 if (size
>= *pcchDiskPrompt
)
319 else if (szDiskPrompt
)
320 lstrcpyW(szDiskPrompt
, ptr
);
322 *pcchDiskPrompt
= size
;
335 /******************************************************************
336 * MsiSourceListEnumSourcesA (MSI.@)
338 UINT WINAPI
MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch
, LPCSTR szUserSid
,
339 MSIINSTALLCONTEXT dwContext
,
340 DWORD dwOptions
, DWORD dwIndex
,
341 LPSTR szSource
, LPDWORD pcchSource
)
343 LPWSTR product
= NULL
;
344 LPWSTR usersid
= NULL
;
345 LPWSTR source
= NULL
;
347 UINT r
= ERROR_INVALID_PARAMETER
;
348 static DWORD index
= 0;
350 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_a(szProductCodeOrPatch
),
351 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
356 if (szSource
&& !pcchSource
)
359 if (dwIndex
!= index
)
362 if (szProductCodeOrPatch
) product
= strdupAtoW(szProductCodeOrPatch
);
363 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
365 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
366 dwIndex
, NULL
, &len
);
367 if (r
!= ERROR_SUCCESS
)
370 source
= msi_alloc(++len
* sizeof(WCHAR
));
373 r
= ERROR_OUTOFMEMORY
;
378 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
379 dwIndex
, source
, &len
);
380 if (r
!= ERROR_SUCCESS
)
383 len
= WideCharToMultiByte(CP_ACP
, 0, source
, -1, NULL
, 0, NULL
, NULL
);
384 if (pcchSource
&& *pcchSource
>= len
)
385 WideCharToMultiByte(CP_ACP
, 0, source
, -1, szSource
, len
, NULL
, NULL
);
390 *pcchSource
= len
- 1;
397 if (r
== ERROR_SUCCESS
)
399 if (szSource
|| !pcchSource
) index
++;
401 else if (dwIndex
> index
)
407 /******************************************************************
408 * MsiSourceListEnumSourcesW (MSI.@)
410 UINT WINAPI
MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch
, LPCWSTR szUserSid
,
411 MSIINSTALLCONTEXT dwContext
,
412 DWORD dwOptions
, DWORD dwIndex
,
413 LPWSTR szSource
, LPDWORD pcchSource
)
415 static const WCHAR format
[] = {'%','d',0};
416 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
], name
[32];
417 HKEY source
= NULL
, subkey
= NULL
;
419 UINT r
= ERROR_INVALID_PARAMETER
;
420 static DWORD index
= 0;
422 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch
),
423 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
428 if (!szProductCodeOrPatch
|| !squash_guid( szProductCodeOrPatch
, squashed_pc
))
431 if (szSource
&& !pcchSource
)
434 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
437 if ((dwOptions
& MSISOURCETYPE_NETWORK
) && (dwOptions
& MSISOURCETYPE_URL
))
440 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
443 if (dwIndex
!= index
)
446 r
= OpenSourceKey( szProductCodeOrPatch
, &source
, dwOptions
, dwContext
, FALSE
);
447 if (r
!= ERROR_SUCCESS
)
450 if (dwOptions
& MSISOURCETYPE_NETWORK
)
451 r
= OpenNetworkSubkey(source
, &subkey
, FALSE
);
452 else if (dwOptions
& MSISOURCETYPE_URL
)
453 r
= OpenURLSubkey(source
, &subkey
, FALSE
);
455 if (r
!= ERROR_SUCCESS
)
457 r
= ERROR_NO_MORE_ITEMS
;
461 swprintf(name
, ARRAY_SIZE(name
), format
, dwIndex
+ 1);
463 res
= RegQueryValueExW(subkey
, name
, 0, 0, (LPBYTE
)szSource
, pcchSource
);
464 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
465 r
= ERROR_NO_MORE_ITEMS
;
471 if (r
== ERROR_SUCCESS
)
473 if (szSource
|| !pcchSource
) index
++;
475 else if (dwIndex
> index
)
481 /******************************************************************
482 * MsiSourceListGetInfoA (MSI.@)
484 UINT WINAPI
MsiSourceListGetInfoA( LPCSTR szProduct
, LPCSTR szUserSid
,
485 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
486 LPCSTR szProperty
, LPSTR szValue
,
490 LPWSTR product
= NULL
;
491 LPWSTR usersid
= NULL
;
492 LPWSTR property
= NULL
;
496 if (szValue
&& !pcchValue
)
497 return ERROR_INVALID_PARAMETER
;
499 if (szProduct
) product
= strdupAtoW(szProduct
);
500 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
501 if (szProperty
) property
= strdupAtoW(szProperty
);
503 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
504 property
, NULL
, &len
);
505 if (ret
!= ERROR_SUCCESS
)
508 value
= msi_alloc(++len
* sizeof(WCHAR
));
510 return ERROR_OUTOFMEMORY
;
513 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
514 property
, value
, &len
);
515 if (ret
!= ERROR_SUCCESS
)
518 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
519 if (*pcchValue
>= len
)
520 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
522 ret
= ERROR_MORE_DATA
;
524 *pcchValue
= len
- 1;
534 /******************************************************************
535 * MsiSourceListGetInfoW (MSI.@)
537 UINT WINAPI
MsiSourceListGetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
538 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
539 LPCWSTR szProperty
, LPWSTR szValue
,
542 static const WCHAR mediapack
[] = {'M','e','d','i','a','P','a','c','k','a','g','e',0};
543 WCHAR
*source
, *ptr
, squashed_pc
[SQUASHED_GUID_SIZE
];
544 HKEY sourcekey
, media
;
548 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szProperty
));
550 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
551 return ERROR_INVALID_PARAMETER
;
553 if (szValue
&& !pcchValue
)
554 return ERROR_INVALID_PARAMETER
;
556 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
557 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
558 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
559 return ERROR_INVALID_PARAMETER
;
562 return ERROR_INVALID_PARAMETER
;
565 FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid
));
567 rc
= OpenSourceKey(szProduct
, &sourcekey
, dwOptions
, dwContext
, FALSE
);
568 if (rc
!= ERROR_SUCCESS
)
571 if (!wcscmp( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
572 !wcscmp( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
574 rc
= OpenMediaSubkey(sourcekey
, &media
, FALSE
);
575 if (rc
!= ERROR_SUCCESS
)
577 RegCloseKey(sourcekey
);
578 return ERROR_SUCCESS
;
581 if (!wcscmp( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
582 szProperty
= mediapack
;
584 RegQueryValueExW(media
, szProperty
, 0, 0, (LPBYTE
)szValue
, pcchValue
);
587 else if (!wcscmp( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) ||
588 !wcscmp( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
590 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
592 if (rc
!= ERROR_SUCCESS
)
594 static WCHAR szEmpty
[1] = { '\0' };
601 source
= msi_alloc(size
);
602 RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
603 0, 0, (LPBYTE
)source
, &size
);
608 RegCloseKey(sourcekey
);
609 return ERROR_SUCCESS
;
612 if (!wcscmp( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
614 if (*source
!= 'n' && *source
!= 'u' && *source
!= 'm')
617 RegCloseKey(sourcekey
);
618 return ERROR_SUCCESS
;
626 ptr
= wcsrchr(source
, ';');
635 if (lstrlenW(ptr
) < *pcchValue
)
636 lstrcpyW(szValue
, ptr
);
638 rc
= ERROR_MORE_DATA
;
641 *pcchValue
= lstrlenW(ptr
);
644 else if (!wcscmp( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
646 *pcchValue
= *pcchValue
* sizeof(WCHAR
);
647 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0, 0,
648 (LPBYTE
)szValue
, pcchValue
);
649 if (rc
!= ERROR_SUCCESS
&& rc
!= ERROR_MORE_DATA
)
657 *pcchValue
= (*pcchValue
- 1) / sizeof(WCHAR
);
659 szValue
[*pcchValue
] = '\0';
664 FIXME("Unknown property %s\n",debugstr_w(szProperty
));
665 rc
= ERROR_UNKNOWN_PROPERTY
;
668 RegCloseKey(sourcekey
);
672 /******************************************************************
673 * MsiSourceListSetInfoA (MSI.@)
675 UINT WINAPI
MsiSourceListSetInfoA(LPCSTR szProduct
, LPCSTR szUserSid
,
676 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
677 LPCSTR szProperty
, LPCSTR szValue
)
680 LPWSTR product
= NULL
;
681 LPWSTR usersid
= NULL
;
682 LPWSTR property
= NULL
;
685 if (szProduct
) product
= strdupAtoW(szProduct
);
686 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
687 if (szProperty
) property
= strdupAtoW(szProperty
);
688 if (szValue
) value
= strdupAtoW(szValue
);
690 ret
= MsiSourceListSetInfoW(product
, usersid
, dwContext
, dwOptions
,
701 UINT
msi_set_last_used_source(LPCWSTR product
, LPCWSTR usersid
,
702 MSIINSTALLCONTEXT context
, DWORD options
,
712 static const WCHAR format
[] = {'%','c',';','%','i',';','%','s',0};
714 if (options
& MSISOURCETYPE_NETWORK
)
716 else if (options
& MSISOURCETYPE_URL
)
718 else if (options
& MSISOURCETYPE_MEDIA
)
721 return ERROR_INVALID_PARAMETER
;
723 if (!(options
& MSISOURCETYPE_MEDIA
))
725 r
= MsiSourceListAddSourceExW(product
, usersid
, context
,
727 if (r
!= ERROR_SUCCESS
)
731 while ((r
= MsiSourceListEnumSourcesW(product
, usersid
, context
, options
,
732 index
, NULL
, NULL
)) == ERROR_SUCCESS
)
735 if (r
!= ERROR_NO_MORE_ITEMS
)
739 size
= lstrlenW(format
) + lstrlenW(value
) + 7;
740 buffer
= msi_alloc(size
* sizeof(WCHAR
));
742 return ERROR_OUTOFMEMORY
;
744 r
= OpenSourceKey(product
, &source
, MSICODE_PRODUCT
, context
, FALSE
);
745 if (r
!= ERROR_SUCCESS
)
751 swprintf(buffer
, size
, format
, typechar
, index
, value
);
753 size
= (lstrlenW(buffer
) + 1) * sizeof(WCHAR
);
754 r
= RegSetValueExW(source
, INSTALLPROPERTY_LASTUSEDSOURCEW
, 0,
755 REG_SZ
, (LPBYTE
)buffer
, size
);
762 /******************************************************************
763 * MsiSourceListSetInfoW (MSI.@)
765 UINT WINAPI
MsiSourceListSetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
766 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
767 LPCWSTR szProperty
, LPCWSTR szValue
)
769 static const WCHAR media_package
[] = {'M','e','d','i','a','P','a','c','k','a','g','e',0};
770 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
];
771 HKEY sourcekey
, media
;
775 TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
776 dwContext
, dwOptions
, debugstr_w(szProperty
), debugstr_w(szValue
));
778 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
779 return ERROR_INVALID_PARAMETER
;
782 return ERROR_INVALID_PARAMETER
;
785 return ERROR_UNKNOWN_PROPERTY
;
787 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
788 return ERROR_INVALID_PARAMETER
;
790 if (dwOptions
& MSICODE_PATCH
)
792 FIXME("Unhandled options MSICODE_PATCH\n");
793 return ERROR_UNKNOWN_PATCH
;
796 property
= szProperty
;
797 if (!wcscmp( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
798 property
= media_package
;
800 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
801 if (rc
!= ERROR_SUCCESS
)
804 if (wcscmp( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) &&
805 dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
))
807 RegCloseKey(sourcekey
);
808 return ERROR_INVALID_PARAMETER
;
811 if (!wcscmp( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
812 !wcscmp( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
814 rc
= OpenMediaSubkey(sourcekey
, &media
, TRUE
);
815 if (rc
== ERROR_SUCCESS
)
817 rc
= msi_reg_set_val_str(media
, property
, szValue
);
821 else if (!wcscmp( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
823 DWORD size
= (lstrlenW(szValue
) + 1) * sizeof(WCHAR
);
824 rc
= RegSetValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0,
825 REG_SZ
, (const BYTE
*)szValue
, size
);
826 if (rc
!= ERROR_SUCCESS
)
827 rc
= ERROR_UNKNOWN_PROPERTY
;
829 else if (!wcscmp( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
831 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
832 rc
= ERROR_INVALID_PARAMETER
;
834 rc
= msi_set_last_used_source(szProduct
, szUserSid
, dwContext
,
838 rc
= ERROR_UNKNOWN_PROPERTY
;
840 RegCloseKey(sourcekey
);
844 /******************************************************************
845 * MsiSourceListAddSourceW (MSI.@)
847 UINT WINAPI
MsiSourceListAddSourceW( LPCWSTR szProduct
, LPCWSTR szUserName
,
848 DWORD dwReserved
, LPCWSTR szSource
)
850 WCHAR
*sidstr
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
];
852 DWORD sidsize
= 0, domsize
= 0, context
;
856 TRACE("%s %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserName
), debugstr_w(szSource
));
858 if (!szSource
|| !*szSource
)
859 return ERROR_INVALID_PARAMETER
;
862 return ERROR_INVALID_PARAMETER
;
864 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
865 return ERROR_INVALID_PARAMETER
;
867 if (!szUserName
|| !*szUserName
)
868 context
= MSIINSTALLCONTEXT_MACHINE
;
871 if (LookupAccountNameW(NULL
, szUserName
, NULL
, &sidsize
, NULL
, &domsize
, NULL
))
873 PSID psid
= msi_alloc(sidsize
);
875 if (LookupAccountNameW(NULL
, szUserName
, psid
, &sidsize
, NULL
, &domsize
, NULL
))
876 ConvertSidToStringSidW(psid
, &sidstr
);
881 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
882 MSIINSTALLCONTEXT_USERMANAGED
, &hkey
, FALSE
);
883 if (r
== ERROR_SUCCESS
)
884 context
= MSIINSTALLCONTEXT_USERMANAGED
;
887 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
888 MSIINSTALLCONTEXT_USERUNMANAGED
,
890 if (r
!= ERROR_SUCCESS
)
891 return ERROR_UNKNOWN_PRODUCT
;
893 context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
899 ret
= MsiSourceListAddSourceExW(szProduct
, sidstr
,
900 context
, MSISOURCETYPE_NETWORK
, szSource
, 0);
908 /******************************************************************
909 * MsiSourceListAddSourceA (MSI.@)
911 UINT WINAPI
MsiSourceListAddSourceA( LPCSTR szProduct
, LPCSTR szUserName
,
912 DWORD dwReserved
, LPCSTR szSource
)
919 szwproduct
= strdupAtoW( szProduct
);
920 szwusername
= strdupAtoW( szUserName
);
921 szwsource
= strdupAtoW( szSource
);
923 ret
= MsiSourceListAddSourceW(szwproduct
, szwusername
, dwReserved
, szwsource
);
925 msi_free(szwproduct
);
926 msi_free(szwusername
);
932 /******************************************************************
933 * MsiSourceListAddSourceExA (MSI.@)
935 UINT WINAPI
MsiSourceListAddSourceExA(LPCSTR szProduct
, LPCSTR szUserSid
,
936 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCSTR szSource
, DWORD dwIndex
)
939 LPWSTR product
, usersid
, source
;
941 product
= strdupAtoW(szProduct
);
942 usersid
= strdupAtoW(szUserSid
);
943 source
= strdupAtoW(szSource
);
945 ret
= MsiSourceListAddSourceExW(product
, usersid
, dwContext
,
946 dwOptions
, source
, dwIndex
);
955 static void free_source_list(struct list
*sourcelist
)
957 while (!list_empty(sourcelist
))
959 media_info
*info
= LIST_ENTRY(list_head(sourcelist
), media_info
, entry
);
960 list_remove(&info
->entry
);
961 msi_free(info
->path
);
966 static void add_source_to_list(struct list
*sourcelist
, media_info
*info
,
971 static const WCHAR fmt
[] = {'%','i',0};
973 if (index
) *index
= 0;
975 if (list_empty(sourcelist
))
977 list_add_head(sourcelist
, &info
->entry
);
981 LIST_FOR_EACH_ENTRY(iter
, sourcelist
, media_info
, entry
)
983 if (!found
&& info
->index
< iter
->index
)
986 list_add_before(&iter
->entry
, &info
->entry
);
989 /* update the rest of the list */
991 swprintf(iter
->szIndex
, ARRAY_SIZE(iter
->szIndex
), fmt
, ++iter
->index
);
997 list_add_after(&iter
->entry
, &info
->entry
);
1000 static UINT
fill_source_list(struct list
*sourcelist
, HKEY sourcekey
, DWORD
*count
)
1002 UINT r
= ERROR_SUCCESS
;
1005 DWORD size
, val_size
;
1010 while (r
== ERROR_SUCCESS
)
1012 size
= ARRAY_SIZE(name
);
1013 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
, NULL
, NULL
, &val_size
);
1014 if (r
!= ERROR_SUCCESS
)
1017 entry
= msi_alloc(sizeof(media_info
));
1021 entry
->path
= msi_alloc(val_size
);
1028 lstrcpyW(entry
->szIndex
, name
);
1029 entry
->index
= wcstol(name
, NULL
, 10);
1032 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
,
1033 NULL
, (LPBYTE
)entry
->path
, &val_size
);
1034 if (r
!= ERROR_SUCCESS
)
1036 msi_free(entry
->path
);
1042 add_source_to_list(sourcelist
, entry
, NULL
);
1047 free_source_list(sourcelist
);
1048 return ERROR_OUTOFMEMORY
;
1051 /******************************************************************
1052 * MsiSourceListAddSourceExW (MSI.@)
1054 UINT WINAPI
MsiSourceListAddSourceExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1055 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCWSTR szSource
,
1058 static const WCHAR fmt
[] = {'%','i',0};
1059 HKEY sourcekey
, typekey
;
1061 struct list sourcelist
;
1063 WCHAR
*source
, squashed_pc
[SQUASHED_GUID_SIZE
], name
[10];
1065 DWORD size
, count
, index
;
1067 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1068 dwContext
, dwOptions
, debugstr_w(szSource
), dwIndex
);
1070 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
1071 return ERROR_INVALID_PARAMETER
;
1073 if (!szSource
|| !*szSource
)
1074 return ERROR_INVALID_PARAMETER
;
1076 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
1077 return ERROR_INVALID_PARAMETER
;
1079 if (dwOptions
& MSICODE_PATCH
)
1081 FIXME("Unhandled options MSICODE_PATCH\n");
1082 return ERROR_FUNCTION_FAILED
;
1085 if (szUserSid
&& (dwContext
& MSIINSTALLCONTEXT_MACHINE
))
1086 return ERROR_INVALID_PARAMETER
;
1088 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1089 if (rc
!= ERROR_SUCCESS
)
1092 if (dwOptions
& MSISOURCETYPE_NETWORK
)
1093 rc
= OpenNetworkSubkey(sourcekey
, &typekey
, TRUE
);
1094 else if (dwOptions
& MSISOURCETYPE_URL
)
1095 rc
= OpenURLSubkey(sourcekey
, &typekey
, TRUE
);
1096 else if (dwOptions
& MSISOURCETYPE_MEDIA
)
1097 rc
= OpenMediaSubkey(sourcekey
, &typekey
, TRUE
);
1100 ERR("unknown media type: %08x\n", dwOptions
);
1101 RegCloseKey(sourcekey
);
1102 return ERROR_FUNCTION_FAILED
;
1104 if (rc
!= ERROR_SUCCESS
)
1106 ERR("can't open subkey %u\n", rc
);
1107 RegCloseKey(sourcekey
);
1111 postfix
= (dwOptions
& MSISOURCETYPE_NETWORK
) ? szBackSlash
: szForwardSlash
;
1112 if (szSource
[lstrlenW(szSource
) - 1] == *postfix
)
1113 source
= strdupW(szSource
);
1116 size
= lstrlenW(szSource
) + 2;
1117 source
= msi_alloc(size
* sizeof(WCHAR
));
1118 lstrcpyW(source
, szSource
);
1119 lstrcatW(source
, postfix
);
1122 list_init(&sourcelist
);
1123 rc
= fill_source_list(&sourcelist
, typekey
, &count
);
1124 if (rc
!= ERROR_NO_MORE_ITEMS
)
1127 size
= (lstrlenW(source
) + 1) * sizeof(WCHAR
);
1131 rc
= RegSetValueExW(typekey
, szOne
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1134 else if (dwIndex
> count
|| dwIndex
== 0)
1136 swprintf(name
, ARRAY_SIZE(name
), fmt
, count
+ 1);
1137 rc
= RegSetValueExW(typekey
, name
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1142 swprintf(name
, ARRAY_SIZE(name
), fmt
, dwIndex
);
1143 info
= msi_alloc(sizeof(media_info
));
1146 rc
= ERROR_OUTOFMEMORY
;
1150 info
->path
= strdupW(source
);
1151 lstrcpyW(info
->szIndex
, name
);
1152 info
->index
= dwIndex
;
1153 add_source_to_list(&sourcelist
, info
, &index
);
1155 LIST_FOR_EACH_ENTRY(info
, &sourcelist
, media_info
, entry
)
1157 if (info
->index
< index
)
1160 size
= (lstrlenW(info
->path
) + 1) * sizeof(WCHAR
);
1161 rc
= RegSetValueExW(typekey
, info
->szIndex
, 0,
1162 REG_EXPAND_SZ
, (LPBYTE
)info
->path
, size
);
1163 if (rc
!= ERROR_SUCCESS
)
1169 free_source_list(&sourcelist
);
1171 RegCloseKey(typekey
);
1172 RegCloseKey(sourcekey
);
1176 /******************************************************************
1177 * MsiSourceListAddMediaDiskA (MSI.@)
1179 UINT WINAPI
MsiSourceListAddMediaDiskA(LPCSTR szProduct
, LPCSTR szUserSid
,
1180 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1181 LPCSTR szVolumeLabel
, LPCSTR szDiskPrompt
)
1184 LPWSTR product
= NULL
;
1185 LPWSTR usersid
= NULL
;
1186 LPWSTR volume
= NULL
;
1187 LPWSTR prompt
= NULL
;
1189 if (szProduct
) product
= strdupAtoW(szProduct
);
1190 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1191 if (szVolumeLabel
) volume
= strdupAtoW(szVolumeLabel
);
1192 if (szDiskPrompt
) prompt
= strdupAtoW(szDiskPrompt
);
1194 r
= MsiSourceListAddMediaDiskW(product
, usersid
, dwContext
, dwOptions
,
1195 dwDiskId
, volume
, prompt
);
1205 /******************************************************************
1206 * MsiSourceListAddMediaDiskW (MSI.@)
1208 UINT WINAPI
MsiSourceListAddMediaDiskW(LPCWSTR szProduct
, LPCWSTR szUserSid
,
1209 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1210 LPCWSTR szVolumeLabel
, LPCWSTR szDiskPrompt
)
1212 static const WCHAR fmt
[] = {'%','i',0};
1213 HKEY sourcekey
, mediakey
;
1215 WCHAR
*buffer
, squashed_pc
[SQUASHED_GUID_SIZE
], szIndex
[10];
1218 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct
),
1219 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwDiskId
,
1220 debugstr_w(szVolumeLabel
), debugstr_w(szDiskPrompt
));
1222 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
1223 return ERROR_INVALID_PARAMETER
;
1225 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
1226 return ERROR_INVALID_PARAMETER
;
1228 if ((szVolumeLabel
&& !*szVolumeLabel
) || (szDiskPrompt
&& !*szDiskPrompt
))
1229 return ERROR_INVALID_PARAMETER
;
1231 if ((dwContext
& MSIINSTALLCONTEXT_MACHINE
) && szUserSid
)
1232 return ERROR_INVALID_PARAMETER
;
1234 if (dwOptions
& MSICODE_PATCH
)
1236 FIXME("Unhandled options MSICODE_PATCH\n");
1237 return ERROR_FUNCTION_FAILED
;
1240 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1241 if (rc
!= ERROR_SUCCESS
)
1244 OpenMediaSubkey(sourcekey
, &mediakey
, TRUE
);
1246 swprintf(szIndex
, ARRAY_SIZE(szIndex
), fmt
, dwDiskId
);
1249 if (szVolumeLabel
) size
+= lstrlenW(szVolumeLabel
);
1250 if (szDiskPrompt
) size
+= lstrlenW(szDiskPrompt
);
1252 size
*= sizeof(WCHAR
);
1253 buffer
= msi_alloc(size
);
1256 if (szVolumeLabel
) lstrcpyW(buffer
, szVolumeLabel
);
1257 lstrcatW(buffer
, szSemiColon
);
1258 if (szDiskPrompt
) lstrcatW(buffer
, szDiskPrompt
);
1260 RegSetValueExW(mediakey
, szIndex
, 0, REG_SZ
, (LPBYTE
)buffer
, size
);
1263 RegCloseKey(sourcekey
);
1264 RegCloseKey(mediakey
);
1266 return ERROR_SUCCESS
;
1269 /******************************************************************
1270 * MsiSourceListClearAllA (MSI.@)
1272 UINT WINAPI
MsiSourceListClearAllA( LPCSTR szProduct
, LPCSTR szUserName
, DWORD dwReserved
)
1274 FIXME("(%s %s %d)\n", debugstr_a(szProduct
), debugstr_a(szUserName
), dwReserved
);
1275 return ERROR_SUCCESS
;
1278 /******************************************************************
1279 * MsiSourceListClearAllW (MSI.@)
1281 UINT WINAPI
MsiSourceListClearAllW( LPCWSTR szProduct
, LPCWSTR szUserName
, DWORD dwReserved
)
1283 FIXME("(%s %s %d)\n", debugstr_w(szProduct
), debugstr_w(szUserName
), dwReserved
);
1284 return ERROR_SUCCESS
;
1287 /******************************************************************
1288 * MsiSourceListClearAllExA (MSI.@)
1290 UINT WINAPI
MsiSourceListClearAllExA( LPCSTR szProduct
, LPCSTR szUserSid
,
1291 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1293 FIXME("(%s %s %d %08x)\n", debugstr_a(szProduct
), debugstr_a(szUserSid
),
1294 dwContext
, dwOptions
);
1295 return ERROR_SUCCESS
;
1298 /******************************************************************
1299 * MsiSourceListClearAllExW (MSI.@)
1301 UINT WINAPI
MsiSourceListClearAllExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1302 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1304 FIXME("(%s %s %d %08x)\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1305 dwContext
, dwOptions
);
1306 return ERROR_SUCCESS
;
1309 /******************************************************************
1310 * MsiSourceListClearSourceA (MSI.@)
1312 UINT WINAPI
MsiSourceListClearSourceA(LPCSTR szProductCodeOrPatchCode
, LPCSTR szUserSid
,
1313 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1316 FIXME("(%s %s %x %x %s)\n", debugstr_a(szProductCodeOrPatchCode
), debugstr_a(szUserSid
),
1317 dwContext
, dwOptions
, debugstr_a(szSource
));
1318 return ERROR_SUCCESS
;
1321 /******************************************************************
1322 * MsiSourceListClearSourceW (MSI.@)
1324 UINT WINAPI
MsiSourceListClearSourceW(LPCWSTR szProductCodeOrPatchCode
, LPCWSTR szUserSid
,
1325 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1328 FIXME("(%s %s %x %x %s)\n", debugstr_w(szProductCodeOrPatchCode
), debugstr_w(szUserSid
),
1329 dwContext
, dwOptions
, debugstr_w(szSource
));
1330 return ERROR_SUCCESS
;
1333 /******************************************************************
1334 * MsiSourceListForceResolutionA (MSI.@)
1336 UINT WINAPI
MsiSourceListForceResolutionA(const CHAR
*product
, const CHAR
*user
, DWORD reserved
)
1338 FIXME("(%s %s %x)\n", debugstr_a(product
), debugstr_a(user
), reserved
);
1339 return ERROR_SUCCESS
;
1342 /******************************************************************
1343 * MsiSourceListForceResolutionW (MSI.@)
1345 UINT WINAPI
MsiSourceListForceResolutionW(const WCHAR
*product
, const WCHAR
*user
, DWORD reserved
)
1347 FIXME("(%s %s %x)\n", debugstr_w(product
), debugstr_w(user
), reserved
);
1348 return ERROR_SUCCESS
;