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"
37 #include "wine/unicode.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
43 * These apis are defined in MSI 3.0
46 typedef struct tagMediaInfo
54 static UINT
OpenSourceKey(LPCWSTR szProduct
, HKEY
* key
, DWORD dwOptions
,
55 MSIINSTALLCONTEXT context
, BOOL create
)
58 UINT rc
= ERROR_FUNCTION_FAILED
;
60 if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
62 if (dwOptions
& MSICODE_PATCH
)
63 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
65 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
68 else if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
70 if (dwOptions
& MSICODE_PATCH
)
71 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
73 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
76 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
78 if (dwOptions
& MSICODE_PATCH
)
79 rc
= MSIREG_OpenPatchesKey(szProduct
, &rootkey
, create
);
81 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
85 if (rc
!= ERROR_SUCCESS
)
87 if (dwOptions
& MSICODE_PATCH
)
88 return ERROR_UNKNOWN_PATCH
;
90 return ERROR_UNKNOWN_PRODUCT
;
94 rc
= RegCreateKeyW(rootkey
, szSourceList
, key
);
97 rc
= RegOpenKeyW(rootkey
,szSourceList
, key
);
98 if (rc
!= ERROR_SUCCESS
)
99 rc
= ERROR_BAD_CONFIGURATION
;
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
= atolW(value
);
278 ptr
= strchrW(data
, ';');
286 if (type
== REG_DWORD
)
288 sprintfW(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 sprintfW(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 sprintfW(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 (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
572 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
574 rc
= OpenMediaSubkey(sourcekey
, &media
, FALSE
);
575 if (rc
!= ERROR_SUCCESS
)
577 RegCloseKey(sourcekey
);
578 return ERROR_SUCCESS
;
581 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
582 szProperty
= mediapack
;
584 RegQueryValueExW(media
, szProperty
, 0, 0, (LPBYTE
)szValue
, pcchValue
);
587 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) ||
588 !strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
590 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
592 if (rc
!= ERROR_SUCCESS
)
594 RegCloseKey(sourcekey
);
595 return ERROR_SUCCESS
;
598 source
= msi_alloc(size
);
599 RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
600 0, 0, (LPBYTE
)source
, &size
);
605 RegCloseKey(sourcekey
);
606 return ERROR_SUCCESS
;
609 if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
611 if (*source
!= 'n' && *source
!= 'u' && *source
!= 'm')
614 RegCloseKey(sourcekey
);
615 return ERROR_SUCCESS
;
623 ptr
= strrchrW(source
, ';');
632 if (strlenW(ptr
) < *pcchValue
)
633 lstrcpyW(szValue
, ptr
);
635 rc
= ERROR_MORE_DATA
;
638 *pcchValue
= lstrlenW(ptr
);
641 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
643 *pcchValue
= *pcchValue
* sizeof(WCHAR
);
644 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0, 0,
645 (LPBYTE
)szValue
, pcchValue
);
646 if (rc
!= ERROR_SUCCESS
&& rc
!= ERROR_MORE_DATA
)
654 *pcchValue
= (*pcchValue
- 1) / sizeof(WCHAR
);
656 szValue
[*pcchValue
] = '\0';
661 FIXME("Unknown property %s\n",debugstr_w(szProperty
));
662 rc
= ERROR_UNKNOWN_PROPERTY
;
665 RegCloseKey(sourcekey
);
669 /******************************************************************
670 * MsiSourceListSetInfoA (MSI.@)
672 UINT WINAPI
MsiSourceListSetInfoA(LPCSTR szProduct
, LPCSTR szUserSid
,
673 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
674 LPCSTR szProperty
, LPCSTR szValue
)
677 LPWSTR product
= NULL
;
678 LPWSTR usersid
= NULL
;
679 LPWSTR property
= NULL
;
682 if (szProduct
) product
= strdupAtoW(szProduct
);
683 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
684 if (szProperty
) property
= strdupAtoW(szProperty
);
685 if (szValue
) value
= strdupAtoW(szValue
);
687 ret
= MsiSourceListSetInfoW(product
, usersid
, dwContext
, dwOptions
,
698 UINT
msi_set_last_used_source(LPCWSTR product
, LPCWSTR usersid
,
699 MSIINSTALLCONTEXT context
, DWORD options
,
709 static const WCHAR format
[] = {'%','c',';','%','i',';','%','s',0};
711 if (options
& MSISOURCETYPE_NETWORK
)
713 else if (options
& MSISOURCETYPE_URL
)
715 else if (options
& MSISOURCETYPE_MEDIA
)
718 return ERROR_INVALID_PARAMETER
;
720 if (!(options
& MSISOURCETYPE_MEDIA
))
722 r
= MsiSourceListAddSourceExW(product
, usersid
, context
,
724 if (r
!= ERROR_SUCCESS
)
728 while ((r
= MsiSourceListEnumSourcesW(product
, usersid
, context
, options
,
729 index
, NULL
, NULL
)) == ERROR_SUCCESS
)
732 if (r
!= ERROR_NO_MORE_ITEMS
)
736 size
= (lstrlenW(format
) + lstrlenW(value
) + 7) * sizeof(WCHAR
);
737 buffer
= msi_alloc(size
);
739 return ERROR_OUTOFMEMORY
;
741 r
= OpenSourceKey(product
, &source
, MSICODE_PRODUCT
, context
, FALSE
);
742 if (r
!= ERROR_SUCCESS
)
748 sprintfW(buffer
, format
, typechar
, index
, value
);
750 size
= (lstrlenW(buffer
) + 1) * sizeof(WCHAR
);
751 r
= RegSetValueExW(source
, INSTALLPROPERTY_LASTUSEDSOURCEW
, 0,
752 REG_SZ
, (LPBYTE
)buffer
, size
);
759 /******************************************************************
760 * MsiSourceListSetInfoW (MSI.@)
762 UINT WINAPI
MsiSourceListSetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
763 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
764 LPCWSTR szProperty
, LPCWSTR szValue
)
766 static const WCHAR media_package
[] = {'M','e','d','i','a','P','a','c','k','a','g','e',0};
767 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
];
768 HKEY sourcekey
, media
;
772 TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
773 dwContext
, dwOptions
, debugstr_w(szProperty
), debugstr_w(szValue
));
775 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
776 return ERROR_INVALID_PARAMETER
;
779 return ERROR_INVALID_PARAMETER
;
782 return ERROR_UNKNOWN_PROPERTY
;
784 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
785 return ERROR_INVALID_PARAMETER
;
787 if (dwOptions
& MSICODE_PATCH
)
789 FIXME("Unhandled options MSICODE_PATCH\n");
790 return ERROR_UNKNOWN_PATCH
;
793 property
= szProperty
;
794 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
795 property
= media_package
;
797 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
798 if (rc
!= ERROR_SUCCESS
)
801 if (strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) &&
802 dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
))
804 RegCloseKey(sourcekey
);
805 return ERROR_INVALID_PARAMETER
;
808 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
809 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
811 rc
= OpenMediaSubkey(sourcekey
, &media
, TRUE
);
812 if (rc
== ERROR_SUCCESS
)
814 rc
= msi_reg_set_val_str(media
, property
, szValue
);
818 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
820 DWORD size
= (lstrlenW(szValue
) + 1) * sizeof(WCHAR
);
821 rc
= RegSetValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0,
822 REG_SZ
, (const BYTE
*)szValue
, size
);
823 if (rc
!= ERROR_SUCCESS
)
824 rc
= ERROR_UNKNOWN_PROPERTY
;
826 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
828 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
829 rc
= ERROR_INVALID_PARAMETER
;
831 rc
= msi_set_last_used_source(szProduct
, szUserSid
, dwContext
,
835 rc
= ERROR_UNKNOWN_PROPERTY
;
837 RegCloseKey(sourcekey
);
841 /******************************************************************
842 * MsiSourceListAddSourceW (MSI.@)
844 UINT WINAPI
MsiSourceListAddSourceW( LPCWSTR szProduct
, LPCWSTR szUserName
,
845 DWORD dwReserved
, LPCWSTR szSource
)
847 WCHAR
*sidstr
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
];
849 DWORD sidsize
= 0, domsize
= 0, context
;
853 TRACE("%s %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserName
), debugstr_w(szSource
));
855 if (!szSource
|| !*szSource
)
856 return ERROR_INVALID_PARAMETER
;
859 return ERROR_INVALID_PARAMETER
;
861 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
862 return ERROR_INVALID_PARAMETER
;
864 if (!szUserName
|| !*szUserName
)
865 context
= MSIINSTALLCONTEXT_MACHINE
;
868 if (LookupAccountNameW(NULL
, szUserName
, NULL
, &sidsize
, NULL
, &domsize
, NULL
))
870 PSID psid
= msi_alloc(sidsize
);
872 if (LookupAccountNameW(NULL
, szUserName
, psid
, &sidsize
, NULL
, &domsize
, NULL
))
873 ConvertSidToStringSidW(psid
, &sidstr
);
878 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
879 MSIINSTALLCONTEXT_USERMANAGED
, &hkey
, FALSE
);
880 if (r
== ERROR_SUCCESS
)
881 context
= MSIINSTALLCONTEXT_USERMANAGED
;
884 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
885 MSIINSTALLCONTEXT_USERUNMANAGED
,
887 if (r
!= ERROR_SUCCESS
)
888 return ERROR_UNKNOWN_PRODUCT
;
890 context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
896 ret
= MsiSourceListAddSourceExW(szProduct
, sidstr
,
897 context
, MSISOURCETYPE_NETWORK
, szSource
, 0);
905 /******************************************************************
906 * MsiSourceListAddSourceA (MSI.@)
908 UINT WINAPI
MsiSourceListAddSourceA( LPCSTR szProduct
, LPCSTR szUserName
,
909 DWORD dwReserved
, LPCSTR szSource
)
916 szwproduct
= strdupAtoW( szProduct
);
917 szwusername
= strdupAtoW( szUserName
);
918 szwsource
= strdupAtoW( szSource
);
920 ret
= MsiSourceListAddSourceW(szwproduct
, szwusername
, dwReserved
, szwsource
);
922 msi_free(szwproduct
);
923 msi_free(szwusername
);
929 /******************************************************************
930 * MsiSourceListAddSourceExA (MSI.@)
932 UINT WINAPI
MsiSourceListAddSourceExA(LPCSTR szProduct
, LPCSTR szUserSid
,
933 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCSTR szSource
, DWORD dwIndex
)
936 LPWSTR product
, usersid
, source
;
938 product
= strdupAtoW(szProduct
);
939 usersid
= strdupAtoW(szUserSid
);
940 source
= strdupAtoW(szSource
);
942 ret
= MsiSourceListAddSourceExW(product
, usersid
, dwContext
,
943 dwOptions
, source
, dwIndex
);
952 static void free_source_list(struct list
*sourcelist
)
954 while (!list_empty(sourcelist
))
956 media_info
*info
= LIST_ENTRY(list_head(sourcelist
), media_info
, entry
);
957 list_remove(&info
->entry
);
958 msi_free(info
->path
);
963 static void add_source_to_list(struct list
*sourcelist
, media_info
*info
,
968 static const WCHAR fmt
[] = {'%','i',0};
970 if (index
) *index
= 0;
972 if (list_empty(sourcelist
))
974 list_add_head(sourcelist
, &info
->entry
);
978 LIST_FOR_EACH_ENTRY(iter
, sourcelist
, media_info
, entry
)
980 if (!found
&& info
->index
< iter
->index
)
983 list_add_before(&iter
->entry
, &info
->entry
);
986 /* update the rest of the list */
988 sprintfW(iter
->szIndex
, fmt
, ++iter
->index
);
994 list_add_after(&iter
->entry
, &info
->entry
);
997 static UINT
fill_source_list(struct list
*sourcelist
, HKEY sourcekey
, DWORD
*count
)
999 UINT r
= ERROR_SUCCESS
;
1002 DWORD size
, val_size
;
1007 while (r
== ERROR_SUCCESS
)
1009 size
= sizeof(name
) / sizeof(name
[0]);
1010 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
, NULL
, NULL
, &val_size
);
1011 if (r
!= ERROR_SUCCESS
)
1014 entry
= msi_alloc(sizeof(media_info
));
1018 entry
->path
= msi_alloc(val_size
);
1025 lstrcpyW(entry
->szIndex
, name
);
1026 entry
->index
= atoiW(name
);
1029 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
,
1030 NULL
, (LPBYTE
)entry
->path
, &val_size
);
1031 if (r
!= ERROR_SUCCESS
)
1033 msi_free(entry
->path
);
1039 add_source_to_list(sourcelist
, entry
, NULL
);
1044 free_source_list(sourcelist
);
1045 return ERROR_OUTOFMEMORY
;
1048 /******************************************************************
1049 * MsiSourceListAddSourceExW (MSI.@)
1051 UINT WINAPI
MsiSourceListAddSourceExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1052 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCWSTR szSource
,
1055 static const WCHAR fmt
[] = {'%','i',0};
1056 HKEY sourcekey
, typekey
;
1058 struct list sourcelist
;
1060 WCHAR
*source
, squashed_pc
[SQUASHED_GUID_SIZE
], name
[10];
1062 DWORD size
, count
, index
;
1064 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1065 dwContext
, dwOptions
, debugstr_w(szSource
), dwIndex
);
1067 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
1068 return ERROR_INVALID_PARAMETER
;
1070 if (!szSource
|| !*szSource
)
1071 return ERROR_INVALID_PARAMETER
;
1073 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
1074 return ERROR_INVALID_PARAMETER
;
1076 if (dwOptions
& MSICODE_PATCH
)
1078 FIXME("Unhandled options MSICODE_PATCH\n");
1079 return ERROR_FUNCTION_FAILED
;
1082 if (szUserSid
&& (dwContext
& MSIINSTALLCONTEXT_MACHINE
))
1083 return ERROR_INVALID_PARAMETER
;
1085 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1086 if (rc
!= ERROR_SUCCESS
)
1089 if (dwOptions
& MSISOURCETYPE_NETWORK
)
1090 rc
= OpenNetworkSubkey(sourcekey
, &typekey
, TRUE
);
1091 else if (dwOptions
& MSISOURCETYPE_URL
)
1092 rc
= OpenURLSubkey(sourcekey
, &typekey
, TRUE
);
1093 else if (dwOptions
& MSISOURCETYPE_MEDIA
)
1094 rc
= OpenMediaSubkey(sourcekey
, &typekey
, TRUE
);
1097 ERR("unknown media type: %08x\n", dwOptions
);
1098 RegCloseKey(sourcekey
);
1099 return ERROR_FUNCTION_FAILED
;
1101 if (rc
!= ERROR_SUCCESS
)
1103 ERR("can't open subkey %u\n", rc
);
1104 RegCloseKey(sourcekey
);
1108 postfix
= (dwOptions
& MSISOURCETYPE_NETWORK
) ? szBackSlash
: szForwardSlash
;
1109 if (szSource
[lstrlenW(szSource
) - 1] == *postfix
)
1110 source
= strdupW(szSource
);
1113 size
= lstrlenW(szSource
) + 2;
1114 source
= msi_alloc(size
* sizeof(WCHAR
));
1115 lstrcpyW(source
, szSource
);
1116 lstrcatW(source
, postfix
);
1119 list_init(&sourcelist
);
1120 rc
= fill_source_list(&sourcelist
, typekey
, &count
);
1121 if (rc
!= ERROR_NO_MORE_ITEMS
)
1124 size
= (lstrlenW(source
) + 1) * sizeof(WCHAR
);
1128 rc
= RegSetValueExW(typekey
, szOne
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1131 else if (dwIndex
> count
|| dwIndex
== 0)
1133 sprintfW(name
, fmt
, count
+ 1);
1134 rc
= RegSetValueExW(typekey
, name
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1139 sprintfW(name
, fmt
, dwIndex
);
1140 info
= msi_alloc(sizeof(media_info
));
1143 rc
= ERROR_OUTOFMEMORY
;
1147 info
->path
= strdupW(source
);
1148 lstrcpyW(info
->szIndex
, name
);
1149 info
->index
= dwIndex
;
1150 add_source_to_list(&sourcelist
, info
, &index
);
1152 LIST_FOR_EACH_ENTRY(info
, &sourcelist
, media_info
, entry
)
1154 if (info
->index
< index
)
1157 size
= (lstrlenW(info
->path
) + 1) * sizeof(WCHAR
);
1158 rc
= RegSetValueExW(typekey
, info
->szIndex
, 0,
1159 REG_EXPAND_SZ
, (LPBYTE
)info
->path
, size
);
1160 if (rc
!= ERROR_SUCCESS
)
1166 free_source_list(&sourcelist
);
1168 RegCloseKey(typekey
);
1169 RegCloseKey(sourcekey
);
1173 /******************************************************************
1174 * MsiSourceListAddMediaDiskA (MSI.@)
1176 UINT WINAPI
MsiSourceListAddMediaDiskA(LPCSTR szProduct
, LPCSTR szUserSid
,
1177 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1178 LPCSTR szVolumeLabel
, LPCSTR szDiskPrompt
)
1181 LPWSTR product
= NULL
;
1182 LPWSTR usersid
= NULL
;
1183 LPWSTR volume
= NULL
;
1184 LPWSTR prompt
= NULL
;
1186 if (szProduct
) product
= strdupAtoW(szProduct
);
1187 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1188 if (szVolumeLabel
) volume
= strdupAtoW(szVolumeLabel
);
1189 if (szDiskPrompt
) prompt
= strdupAtoW(szDiskPrompt
);
1191 r
= MsiSourceListAddMediaDiskW(product
, usersid
, dwContext
, dwOptions
,
1192 dwDiskId
, volume
, prompt
);
1202 /******************************************************************
1203 * MsiSourceListAddMediaDiskW (MSI.@)
1205 UINT WINAPI
MsiSourceListAddMediaDiskW(LPCWSTR szProduct
, LPCWSTR szUserSid
,
1206 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1207 LPCWSTR szVolumeLabel
, LPCWSTR szDiskPrompt
)
1209 static const WCHAR fmt
[] = {'%','i',0};
1210 HKEY sourcekey
, mediakey
;
1212 WCHAR
*buffer
, squashed_pc
[SQUASHED_GUID_SIZE
], szIndex
[10];
1215 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct
),
1216 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwDiskId
,
1217 debugstr_w(szVolumeLabel
), debugstr_w(szDiskPrompt
));
1219 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
1220 return ERROR_INVALID_PARAMETER
;
1222 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
1223 return ERROR_INVALID_PARAMETER
;
1225 if ((szVolumeLabel
&& !*szVolumeLabel
) || (szDiskPrompt
&& !*szDiskPrompt
))
1226 return ERROR_INVALID_PARAMETER
;
1228 if ((dwContext
& MSIINSTALLCONTEXT_MACHINE
) && szUserSid
)
1229 return ERROR_INVALID_PARAMETER
;
1231 if (dwOptions
& MSICODE_PATCH
)
1233 FIXME("Unhandled options MSICODE_PATCH\n");
1234 return ERROR_FUNCTION_FAILED
;
1237 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1238 if (rc
!= ERROR_SUCCESS
)
1241 OpenMediaSubkey(sourcekey
, &mediakey
, TRUE
);
1243 sprintfW(szIndex
, fmt
, dwDiskId
);
1246 if (szVolumeLabel
) size
+= lstrlenW(szVolumeLabel
);
1247 if (szDiskPrompt
) size
+= lstrlenW(szDiskPrompt
);
1249 size
*= sizeof(WCHAR
);
1250 buffer
= msi_alloc(size
);
1253 if (szVolumeLabel
) lstrcpyW(buffer
, szVolumeLabel
);
1254 lstrcatW(buffer
, szSemiColon
);
1255 if (szDiskPrompt
) lstrcatW(buffer
, szDiskPrompt
);
1257 RegSetValueExW(mediakey
, szIndex
, 0, REG_SZ
, (LPBYTE
)buffer
, size
);
1260 RegCloseKey(sourcekey
);
1261 RegCloseKey(mediakey
);
1263 return ERROR_SUCCESS
;
1266 /******************************************************************
1267 * MsiSourceListClearAllA (MSI.@)
1269 UINT WINAPI
MsiSourceListClearAllA( LPCSTR szProduct
, LPCSTR szUserName
, DWORD dwReserved
)
1271 FIXME("(%s %s %d)\n", debugstr_a(szProduct
), debugstr_a(szUserName
), dwReserved
);
1272 return ERROR_SUCCESS
;
1275 /******************************************************************
1276 * MsiSourceListClearAllW (MSI.@)
1278 UINT WINAPI
MsiSourceListClearAllW( LPCWSTR szProduct
, LPCWSTR szUserName
, DWORD dwReserved
)
1280 FIXME("(%s %s %d)\n", debugstr_w(szProduct
), debugstr_w(szUserName
), dwReserved
);
1281 return ERROR_SUCCESS
;
1284 /******************************************************************
1285 * MsiSourceListClearAllExA (MSI.@)
1287 UINT WINAPI
MsiSourceListClearAllExA( LPCSTR szProduct
, LPCSTR szUserSid
,
1288 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1290 FIXME("(%s %s %d %08x)\n", debugstr_a(szProduct
), debugstr_a(szUserSid
),
1291 dwContext
, dwOptions
);
1292 return ERROR_SUCCESS
;
1295 /******************************************************************
1296 * MsiSourceListClearAllExW (MSI.@)
1298 UINT WINAPI
MsiSourceListClearAllExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1299 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1301 FIXME("(%s %s %d %08x)\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1302 dwContext
, dwOptions
);
1303 return ERROR_SUCCESS
;
1306 /******************************************************************
1307 * MsiSourceListClearSourceA (MSI.@)
1309 UINT WINAPI
MsiSourceListClearSourceA(LPCSTR szProductCodeOrPatchCode
, LPCSTR szUserSid
,
1310 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1313 FIXME("(%s %s %x %x %s)\n", debugstr_a(szProductCodeOrPatchCode
), debugstr_a(szUserSid
),
1314 dwContext
, dwOptions
, debugstr_a(szSource
));
1315 return ERROR_SUCCESS
;
1318 /******************************************************************
1319 * MsiSourceListClearSourceW (MSI.@)
1321 UINT WINAPI
MsiSourceListClearSourceW(LPCWSTR szProductCodeOrPatchCode
, LPCWSTR szUserSid
,
1322 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1325 FIXME("(%s %s %x %x %s)\n", debugstr_w(szProductCodeOrPatchCode
), debugstr_w(szUserSid
),
1326 dwContext
, dwOptions
, debugstr_w(szSource
));
1327 return ERROR_SUCCESS
;