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
;
101 RegCloseKey(rootkey
);
106 static UINT
OpenMediaSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
109 static const WCHAR media
[] = {'M','e','d','i','a',0};
112 rc
= RegCreateKeyW(rootkey
, media
, key
);
114 rc
= RegOpenKeyW(rootkey
,media
, key
);
119 static UINT
OpenNetworkSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
122 static const WCHAR net
[] = {'N','e','t',0};
125 rc
= RegCreateKeyW(rootkey
, net
, key
);
127 rc
= RegOpenKeyW(rootkey
, net
, key
);
132 static UINT
OpenURLSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
135 static const WCHAR URL
[] = {'U','R','L',0};
138 rc
= RegCreateKeyW(rootkey
, URL
, key
);
140 rc
= RegOpenKeyW(rootkey
, URL
, key
);
145 /******************************************************************
146 * MsiSourceListEnumMediaDisksA (MSI.@)
148 UINT WINAPI
MsiSourceListEnumMediaDisksA(LPCSTR szProductCodeOrPatchCode
,
149 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
150 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
151 LPSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
152 LPSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
154 LPWSTR product
= NULL
;
155 LPWSTR usersid
= NULL
;
156 LPWSTR volume
= NULL
;
157 LPWSTR prompt
= NULL
;
158 UINT r
= ERROR_INVALID_PARAMETER
;
160 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n", debugstr_a(szProductCodeOrPatchCode
),
161 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, pdwDiskId
,
162 szVolumeLabel
, pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
164 if (szDiskPrompt
&& !pcchDiskPrompt
)
165 return ERROR_INVALID_PARAMETER
;
167 if (szProductCodeOrPatchCode
) product
= strdupAtoW(szProductCodeOrPatchCode
);
168 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
170 /* FIXME: add tests for an invalid format */
173 volume
= msi_alloc(*pcchVolumeLabel
* sizeof(WCHAR
));
176 prompt
= msi_alloc(*pcchDiskPrompt
* sizeof(WCHAR
));
178 if (volume
) *volume
= '\0';
179 if (prompt
) *prompt
= '\0';
180 r
= MsiSourceListEnumMediaDisksW(product
, usersid
, dwContext
, dwOptions
,
181 dwIndex
, pdwDiskId
, volume
, pcchVolumeLabel
,
182 prompt
, pcchDiskPrompt
);
183 if (r
!= ERROR_SUCCESS
)
186 if (szVolumeLabel
&& pcchVolumeLabel
)
187 WideCharToMultiByte(CP_ACP
, 0, volume
, -1, szVolumeLabel
,
188 *pcchVolumeLabel
+ 1, NULL
, NULL
);
191 WideCharToMultiByte(CP_ACP
, 0, prompt
, -1, szDiskPrompt
,
192 *pcchDiskPrompt
+ 1, NULL
, NULL
);
203 /******************************************************************
204 * MsiSourceListEnumMediaDisksW (MSI.@)
206 UINT WINAPI
MsiSourceListEnumMediaDisksW(LPCWSTR szProductCodeOrPatchCode
,
207 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
208 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
209 LPWSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
210 LPWSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
212 static const WCHAR fmt
[] = {'#','%','d',0};
213 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
], convert
[11];
214 WCHAR
*value
= NULL
, *data
= NULL
, *ptr
, *ptr2
;
216 DWORD valuesz
, datasz
= 0, type
, numvals
, size
;
219 static DWORD index
= 0;
221 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p)\n", debugstr_w(szProductCodeOrPatchCode
),
222 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szVolumeLabel
,
223 pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
225 if (!szProductCodeOrPatchCode
|| !squash_guid( szProductCodeOrPatchCode
, squashed_pc
))
226 return ERROR_INVALID_PARAMETER
;
228 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
229 return ERROR_INVALID_PARAMETER
;
231 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
232 return ERROR_INVALID_PARAMETER
;
234 if (szDiskPrompt
&& !pcchDiskPrompt
)
235 return ERROR_INVALID_PARAMETER
;
240 if (dwIndex
!= index
)
241 return ERROR_INVALID_PARAMETER
;
243 r
= OpenSourceKey(szProductCodeOrPatchCode
, &source
, dwOptions
, dwContext
, FALSE
);
244 if (r
!= ERROR_SUCCESS
)
247 r
= OpenMediaSubkey(source
, &media
, FALSE
);
248 if (r
!= ERROR_SUCCESS
)
251 return ERROR_NO_MORE_ITEMS
;
254 res
= RegQueryInfoKeyW(media
, NULL
, NULL
, NULL
, NULL
, NULL
,
255 NULL
, &numvals
, &valuesz
, &datasz
, NULL
, NULL
);
256 if (res
!= ERROR_SUCCESS
)
258 r
= ERROR_BAD_CONFIGURATION
;
262 value
= msi_alloc(++valuesz
* sizeof(WCHAR
));
263 data
= msi_alloc(++datasz
* sizeof(WCHAR
));
266 r
= ERROR_OUTOFMEMORY
;
270 r
= RegEnumValueW(media
, dwIndex
, value
, &valuesz
,
271 NULL
, &type
, (LPBYTE
)data
, &datasz
);
272 if (r
!= ERROR_SUCCESS
)
276 *pdwDiskId
= atolW(value
);
279 ptr
= strchrW(data
, ';');
287 if (type
== REG_DWORD
)
289 sprintfW(convert
, fmt
, *data
);
290 size
= lstrlenW(convert
);
294 size
= lstrlenW(data
);
296 if (size
>= *pcchVolumeLabel
)
298 else if (szVolumeLabel
)
299 lstrcpyW(szVolumeLabel
, ptr2
);
301 *pcchVolumeLabel
= size
;
309 if (type
== REG_DWORD
)
311 sprintfW(convert
, fmt
, *ptr
);
312 size
= lstrlenW(convert
);
316 size
= lstrlenW(ptr
);
318 if (size
>= *pcchDiskPrompt
)
320 else if (szDiskPrompt
)
321 lstrcpyW(szDiskPrompt
, ptr
);
323 *pcchDiskPrompt
= size
;
336 /******************************************************************
337 * MsiSourceListEnumSourcesA (MSI.@)
339 UINT WINAPI
MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch
, LPCSTR szUserSid
,
340 MSIINSTALLCONTEXT dwContext
,
341 DWORD dwOptions
, DWORD dwIndex
,
342 LPSTR szSource
, LPDWORD pcchSource
)
344 LPWSTR product
= NULL
;
345 LPWSTR usersid
= NULL
;
346 LPWSTR source
= NULL
;
348 UINT r
= ERROR_INVALID_PARAMETER
;
349 static DWORD index
= 0;
351 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_a(szProductCodeOrPatch
),
352 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
357 if (szSource
&& !pcchSource
)
360 if (dwIndex
!= index
)
363 if (szProductCodeOrPatch
) product
= strdupAtoW(szProductCodeOrPatch
);
364 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
366 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
367 dwIndex
, NULL
, &len
);
368 if (r
!= ERROR_SUCCESS
)
371 source
= msi_alloc(++len
* sizeof(WCHAR
));
374 r
= ERROR_OUTOFMEMORY
;
379 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
380 dwIndex
, source
, &len
);
381 if (r
!= ERROR_SUCCESS
)
384 len
= WideCharToMultiByte(CP_ACP
, 0, source
, -1, NULL
, 0, NULL
, NULL
);
385 if (pcchSource
&& *pcchSource
>= len
)
386 WideCharToMultiByte(CP_ACP
, 0, source
, -1, szSource
, len
, NULL
, NULL
);
391 *pcchSource
= len
- 1;
398 if (r
== ERROR_SUCCESS
)
400 if (szSource
|| !pcchSource
) index
++;
402 else if (dwIndex
> index
)
408 /******************************************************************
409 * MsiSourceListEnumSourcesW (MSI.@)
411 UINT WINAPI
MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch
, LPCWSTR szUserSid
,
412 MSIINSTALLCONTEXT dwContext
,
413 DWORD dwOptions
, DWORD dwIndex
,
414 LPWSTR szSource
, LPDWORD pcchSource
)
416 static const WCHAR format
[] = {'%','d',0};
417 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
], name
[32];
418 HKEY source
= NULL
, subkey
= NULL
;
420 UINT r
= ERROR_INVALID_PARAMETER
;
421 static DWORD index
= 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
, squashed_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
, dwOptions
, dwContext
, FALSE
);
448 if (r
!= ERROR_SUCCESS
)
451 if (dwOptions
& MSISOURCETYPE_NETWORK
)
452 r
= OpenNetworkSubkey(source
, &subkey
, FALSE
);
453 else if (dwOptions
& MSISOURCETYPE_URL
)
454 r
= OpenURLSubkey(source
, &subkey
, FALSE
);
456 if (r
!= ERROR_SUCCESS
)
458 r
= ERROR_NO_MORE_ITEMS
;
462 sprintfW(name
, format
, dwIndex
+ 1);
464 res
= RegQueryValueExW(subkey
, name
, 0, 0, (LPBYTE
)szSource
, pcchSource
);
465 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
466 r
= ERROR_NO_MORE_ITEMS
;
472 if (r
== ERROR_SUCCESS
)
474 if (szSource
|| !pcchSource
) index
++;
476 else if (dwIndex
> index
)
482 /******************************************************************
483 * MsiSourceListGetInfoA (MSI.@)
485 UINT WINAPI
MsiSourceListGetInfoA( LPCSTR szProduct
, LPCSTR szUserSid
,
486 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
487 LPCSTR szProperty
, LPSTR szValue
,
491 LPWSTR product
= NULL
;
492 LPWSTR usersid
= NULL
;
493 LPWSTR property
= NULL
;
497 if (szValue
&& !pcchValue
)
498 return ERROR_INVALID_PARAMETER
;
500 if (szProduct
) product
= strdupAtoW(szProduct
);
501 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
502 if (szProperty
) property
= strdupAtoW(szProperty
);
504 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
505 property
, NULL
, &len
);
506 if (ret
!= ERROR_SUCCESS
)
509 value
= msi_alloc(++len
* sizeof(WCHAR
));
511 return ERROR_OUTOFMEMORY
;
514 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
515 property
, value
, &len
);
516 if (ret
!= ERROR_SUCCESS
)
519 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
520 if (*pcchValue
>= len
)
521 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
523 ret
= ERROR_MORE_DATA
;
525 *pcchValue
= len
- 1;
535 /******************************************************************
536 * MsiSourceListGetInfoW (MSI.@)
538 UINT WINAPI
MsiSourceListGetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
539 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
540 LPCWSTR szProperty
, LPWSTR szValue
,
543 static const WCHAR mediapack
[] = {'M','e','d','i','a','P','a','c','k','a','g','e',0};
544 WCHAR
*source
, *ptr
, squashed_pc
[SQUASHED_GUID_SIZE
];
545 HKEY sourcekey
, media
;
549 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szProperty
));
551 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
552 return ERROR_INVALID_PARAMETER
;
554 if (szValue
&& !pcchValue
)
555 return ERROR_INVALID_PARAMETER
;
557 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
558 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
559 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
560 return ERROR_INVALID_PARAMETER
;
563 return ERROR_INVALID_PARAMETER
;
566 FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid
));
568 rc
= OpenSourceKey(szProduct
, &sourcekey
, dwOptions
, dwContext
, FALSE
);
569 if (rc
!= ERROR_SUCCESS
)
572 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
573 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
575 rc
= OpenMediaSubkey(sourcekey
, &media
, FALSE
);
576 if (rc
!= ERROR_SUCCESS
)
578 RegCloseKey(sourcekey
);
579 return ERROR_SUCCESS
;
582 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
583 szProperty
= mediapack
;
585 RegQueryValueExW(media
, szProperty
, 0, 0, (LPBYTE
)szValue
, pcchValue
);
588 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) ||
589 !strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
591 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
593 if (rc
!= ERROR_SUCCESS
)
595 static WCHAR szEmpty
[1] = { '\0' };
602 source
= msi_alloc(size
);
603 RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
604 0, 0, (LPBYTE
)source
, &size
);
609 RegCloseKey(sourcekey
);
610 return ERROR_SUCCESS
;
613 if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
615 if (*source
!= 'n' && *source
!= 'u' && *source
!= 'm')
618 RegCloseKey(sourcekey
);
619 return ERROR_SUCCESS
;
627 ptr
= strrchrW(source
, ';');
636 if (strlenW(ptr
) < *pcchValue
)
637 lstrcpyW(szValue
, ptr
);
639 rc
= ERROR_MORE_DATA
;
642 *pcchValue
= lstrlenW(ptr
);
645 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
647 *pcchValue
= *pcchValue
* sizeof(WCHAR
);
648 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0, 0,
649 (LPBYTE
)szValue
, pcchValue
);
650 if (rc
!= ERROR_SUCCESS
&& rc
!= ERROR_MORE_DATA
)
658 *pcchValue
= (*pcchValue
- 1) / sizeof(WCHAR
);
660 szValue
[*pcchValue
] = '\0';
665 FIXME("Unknown property %s\n",debugstr_w(szProperty
));
666 rc
= ERROR_UNKNOWN_PROPERTY
;
669 RegCloseKey(sourcekey
);
673 /******************************************************************
674 * MsiSourceListSetInfoA (MSI.@)
676 UINT WINAPI
MsiSourceListSetInfoA(LPCSTR szProduct
, LPCSTR szUserSid
,
677 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
678 LPCSTR szProperty
, LPCSTR szValue
)
681 LPWSTR product
= NULL
;
682 LPWSTR usersid
= NULL
;
683 LPWSTR property
= NULL
;
686 if (szProduct
) product
= strdupAtoW(szProduct
);
687 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
688 if (szProperty
) property
= strdupAtoW(szProperty
);
689 if (szValue
) value
= strdupAtoW(szValue
);
691 ret
= MsiSourceListSetInfoW(product
, usersid
, dwContext
, dwOptions
,
702 UINT
msi_set_last_used_source(LPCWSTR product
, LPCWSTR usersid
,
703 MSIINSTALLCONTEXT context
, DWORD options
,
713 static const WCHAR format
[] = {'%','c',';','%','i',';','%','s',0};
715 if (options
& MSISOURCETYPE_NETWORK
)
717 else if (options
& MSISOURCETYPE_URL
)
719 else if (options
& MSISOURCETYPE_MEDIA
)
722 return ERROR_INVALID_PARAMETER
;
724 if (!(options
& MSISOURCETYPE_MEDIA
))
726 r
= MsiSourceListAddSourceExW(product
, usersid
, context
,
728 if (r
!= ERROR_SUCCESS
)
732 while ((r
= MsiSourceListEnumSourcesW(product
, usersid
, context
, options
,
733 index
, NULL
, NULL
)) == ERROR_SUCCESS
)
736 if (r
!= ERROR_NO_MORE_ITEMS
)
740 size
= (lstrlenW(format
) + lstrlenW(value
) + 7) * sizeof(WCHAR
);
741 buffer
= msi_alloc(size
);
743 return ERROR_OUTOFMEMORY
;
745 r
= OpenSourceKey(product
, &source
, MSICODE_PRODUCT
, context
, FALSE
);
746 if (r
!= ERROR_SUCCESS
)
752 sprintfW(buffer
, format
, typechar
, index
, value
);
754 size
= (lstrlenW(buffer
) + 1) * sizeof(WCHAR
);
755 r
= RegSetValueExW(source
, INSTALLPROPERTY_LASTUSEDSOURCEW
, 0,
756 REG_SZ
, (LPBYTE
)buffer
, size
);
763 /******************************************************************
764 * MsiSourceListSetInfoW (MSI.@)
766 UINT WINAPI
MsiSourceListSetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
767 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
768 LPCWSTR szProperty
, LPCWSTR szValue
)
770 static const WCHAR media_package
[] = {'M','e','d','i','a','P','a','c','k','a','g','e',0};
771 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
];
772 HKEY sourcekey
, media
;
776 TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
777 dwContext
, dwOptions
, debugstr_w(szProperty
), debugstr_w(szValue
));
779 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
780 return ERROR_INVALID_PARAMETER
;
783 return ERROR_INVALID_PARAMETER
;
786 return ERROR_UNKNOWN_PROPERTY
;
788 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
789 return ERROR_INVALID_PARAMETER
;
791 if (dwOptions
& MSICODE_PATCH
)
793 FIXME("Unhandled options MSICODE_PATCH\n");
794 return ERROR_UNKNOWN_PATCH
;
797 property
= szProperty
;
798 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
799 property
= media_package
;
801 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
802 if (rc
!= ERROR_SUCCESS
)
805 if (strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) &&
806 dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
))
808 RegCloseKey(sourcekey
);
809 return ERROR_INVALID_PARAMETER
;
812 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
813 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
815 rc
= OpenMediaSubkey(sourcekey
, &media
, TRUE
);
816 if (rc
== ERROR_SUCCESS
)
818 rc
= msi_reg_set_val_str(media
, property
, szValue
);
822 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
824 DWORD size
= (lstrlenW(szValue
) + 1) * sizeof(WCHAR
);
825 rc
= RegSetValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0,
826 REG_SZ
, (const BYTE
*)szValue
, size
);
827 if (rc
!= ERROR_SUCCESS
)
828 rc
= ERROR_UNKNOWN_PROPERTY
;
830 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
832 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
833 rc
= ERROR_INVALID_PARAMETER
;
835 rc
= msi_set_last_used_source(szProduct
, szUserSid
, dwContext
,
839 rc
= ERROR_UNKNOWN_PROPERTY
;
841 RegCloseKey(sourcekey
);
845 /******************************************************************
846 * MsiSourceListAddSourceW (MSI.@)
848 UINT WINAPI
MsiSourceListAddSourceW( LPCWSTR szProduct
, LPCWSTR szUserName
,
849 DWORD dwReserved
, LPCWSTR szSource
)
851 WCHAR
*sidstr
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
];
853 DWORD sidsize
= 0, domsize
= 0, context
;
857 TRACE("%s %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserName
), debugstr_w(szSource
));
859 if (!szSource
|| !*szSource
)
860 return ERROR_INVALID_PARAMETER
;
863 return ERROR_INVALID_PARAMETER
;
865 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
866 return ERROR_INVALID_PARAMETER
;
868 if (!szUserName
|| !*szUserName
)
869 context
= MSIINSTALLCONTEXT_MACHINE
;
872 if (LookupAccountNameW(NULL
, szUserName
, NULL
, &sidsize
, NULL
, &domsize
, NULL
))
874 PSID psid
= msi_alloc(sidsize
);
876 if (LookupAccountNameW(NULL
, szUserName
, psid
, &sidsize
, NULL
, &domsize
, NULL
))
877 ConvertSidToStringSidW(psid
, &sidstr
);
882 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
883 MSIINSTALLCONTEXT_USERMANAGED
, &hkey
, FALSE
);
884 if (r
== ERROR_SUCCESS
)
885 context
= MSIINSTALLCONTEXT_USERMANAGED
;
888 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
889 MSIINSTALLCONTEXT_USERUNMANAGED
,
891 if (r
!= ERROR_SUCCESS
)
892 return ERROR_UNKNOWN_PRODUCT
;
894 context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
900 ret
= MsiSourceListAddSourceExW(szProduct
, sidstr
,
901 context
, MSISOURCETYPE_NETWORK
, szSource
, 0);
909 /******************************************************************
910 * MsiSourceListAddSourceA (MSI.@)
912 UINT WINAPI
MsiSourceListAddSourceA( LPCSTR szProduct
, LPCSTR szUserName
,
913 DWORD dwReserved
, LPCSTR szSource
)
920 szwproduct
= strdupAtoW( szProduct
);
921 szwusername
= strdupAtoW( szUserName
);
922 szwsource
= strdupAtoW( szSource
);
924 ret
= MsiSourceListAddSourceW(szwproduct
, szwusername
, dwReserved
, szwsource
);
926 msi_free(szwproduct
);
927 msi_free(szwusername
);
933 /******************************************************************
934 * MsiSourceListAddSourceExA (MSI.@)
936 UINT WINAPI
MsiSourceListAddSourceExA(LPCSTR szProduct
, LPCSTR szUserSid
,
937 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCSTR szSource
, DWORD dwIndex
)
940 LPWSTR product
, usersid
, source
;
942 product
= strdupAtoW(szProduct
);
943 usersid
= strdupAtoW(szUserSid
);
944 source
= strdupAtoW(szSource
);
946 ret
= MsiSourceListAddSourceExW(product
, usersid
, dwContext
,
947 dwOptions
, source
, dwIndex
);
956 static void free_source_list(struct list
*sourcelist
)
958 while (!list_empty(sourcelist
))
960 media_info
*info
= LIST_ENTRY(list_head(sourcelist
), media_info
, entry
);
961 list_remove(&info
->entry
);
962 msi_free(info
->path
);
967 static void add_source_to_list(struct list
*sourcelist
, media_info
*info
,
972 static const WCHAR fmt
[] = {'%','i',0};
974 if (index
) *index
= 0;
976 if (list_empty(sourcelist
))
978 list_add_head(sourcelist
, &info
->entry
);
982 LIST_FOR_EACH_ENTRY(iter
, sourcelist
, media_info
, entry
)
984 if (!found
&& info
->index
< iter
->index
)
987 list_add_before(&iter
->entry
, &info
->entry
);
990 /* update the rest of the list */
992 sprintfW(iter
->szIndex
, fmt
, ++iter
->index
);
998 list_add_after(&iter
->entry
, &info
->entry
);
1001 static UINT
fill_source_list(struct list
*sourcelist
, HKEY sourcekey
, DWORD
*count
)
1003 UINT r
= ERROR_SUCCESS
;
1006 DWORD size
, val_size
;
1011 while (r
== ERROR_SUCCESS
)
1013 size
= sizeof(name
) / sizeof(name
[0]);
1014 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
, NULL
, NULL
, &val_size
);
1015 if (r
!= ERROR_SUCCESS
)
1018 entry
= msi_alloc(sizeof(media_info
));
1022 entry
->path
= msi_alloc(val_size
);
1029 lstrcpyW(entry
->szIndex
, name
);
1030 entry
->index
= atoiW(name
);
1033 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
,
1034 NULL
, (LPBYTE
)entry
->path
, &val_size
);
1035 if (r
!= ERROR_SUCCESS
)
1037 msi_free(entry
->path
);
1043 add_source_to_list(sourcelist
, entry
, NULL
);
1048 free_source_list(sourcelist
);
1049 return ERROR_OUTOFMEMORY
;
1052 /******************************************************************
1053 * MsiSourceListAddSourceExW (MSI.@)
1055 UINT WINAPI
MsiSourceListAddSourceExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1056 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCWSTR szSource
,
1059 static const WCHAR fmt
[] = {'%','i',0};
1060 HKEY sourcekey
, typekey
;
1062 struct list sourcelist
;
1064 WCHAR
*source
, squashed_pc
[SQUASHED_GUID_SIZE
], name
[10];
1066 DWORD size
, count
, index
;
1068 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1069 dwContext
, dwOptions
, debugstr_w(szSource
), dwIndex
);
1071 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
1072 return ERROR_INVALID_PARAMETER
;
1074 if (!szSource
|| !*szSource
)
1075 return ERROR_INVALID_PARAMETER
;
1077 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
1078 return ERROR_INVALID_PARAMETER
;
1080 if (dwOptions
& MSICODE_PATCH
)
1082 FIXME("Unhandled options MSICODE_PATCH\n");
1083 return ERROR_FUNCTION_FAILED
;
1086 if (szUserSid
&& (dwContext
& MSIINSTALLCONTEXT_MACHINE
))
1087 return ERROR_INVALID_PARAMETER
;
1089 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1090 if (rc
!= ERROR_SUCCESS
)
1093 if (dwOptions
& MSISOURCETYPE_NETWORK
)
1094 rc
= OpenNetworkSubkey(sourcekey
, &typekey
, TRUE
);
1095 else if (dwOptions
& MSISOURCETYPE_URL
)
1096 rc
= OpenURLSubkey(sourcekey
, &typekey
, TRUE
);
1097 else if (dwOptions
& MSISOURCETYPE_MEDIA
)
1098 rc
= OpenMediaSubkey(sourcekey
, &typekey
, TRUE
);
1101 ERR("unknown media type: %08x\n", dwOptions
);
1102 RegCloseKey(sourcekey
);
1103 return ERROR_FUNCTION_FAILED
;
1105 if (rc
!= ERROR_SUCCESS
)
1107 ERR("can't open subkey %u\n", rc
);
1108 RegCloseKey(sourcekey
);
1112 postfix
= (dwOptions
& MSISOURCETYPE_NETWORK
) ? szBackSlash
: szForwardSlash
;
1113 if (szSource
[lstrlenW(szSource
) - 1] == *postfix
)
1114 source
= strdupW(szSource
);
1117 size
= lstrlenW(szSource
) + 2;
1118 source
= msi_alloc(size
* sizeof(WCHAR
));
1119 lstrcpyW(source
, szSource
);
1120 lstrcatW(source
, postfix
);
1123 list_init(&sourcelist
);
1124 rc
= fill_source_list(&sourcelist
, typekey
, &count
);
1125 if (rc
!= ERROR_NO_MORE_ITEMS
)
1128 size
= (lstrlenW(source
) + 1) * sizeof(WCHAR
);
1132 rc
= RegSetValueExW(typekey
, szOne
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1135 else if (dwIndex
> count
|| dwIndex
== 0)
1137 sprintfW(name
, fmt
, count
+ 1);
1138 rc
= RegSetValueExW(typekey
, name
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1143 sprintfW(name
, fmt
, dwIndex
);
1144 info
= msi_alloc(sizeof(media_info
));
1147 rc
= ERROR_OUTOFMEMORY
;
1151 info
->path
= strdupW(source
);
1152 lstrcpyW(info
->szIndex
, name
);
1153 info
->index
= dwIndex
;
1154 add_source_to_list(&sourcelist
, info
, &index
);
1156 LIST_FOR_EACH_ENTRY(info
, &sourcelist
, media_info
, entry
)
1158 if (info
->index
< index
)
1161 size
= (lstrlenW(info
->path
) + 1) * sizeof(WCHAR
);
1162 rc
= RegSetValueExW(typekey
, info
->szIndex
, 0,
1163 REG_EXPAND_SZ
, (LPBYTE
)info
->path
, size
);
1164 if (rc
!= ERROR_SUCCESS
)
1170 free_source_list(&sourcelist
);
1172 RegCloseKey(typekey
);
1173 RegCloseKey(sourcekey
);
1177 /******************************************************************
1178 * MsiSourceListAddMediaDiskA (MSI.@)
1180 UINT WINAPI
MsiSourceListAddMediaDiskA(LPCSTR szProduct
, LPCSTR szUserSid
,
1181 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1182 LPCSTR szVolumeLabel
, LPCSTR szDiskPrompt
)
1185 LPWSTR product
= NULL
;
1186 LPWSTR usersid
= NULL
;
1187 LPWSTR volume
= NULL
;
1188 LPWSTR prompt
= NULL
;
1190 if (szProduct
) product
= strdupAtoW(szProduct
);
1191 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1192 if (szVolumeLabel
) volume
= strdupAtoW(szVolumeLabel
);
1193 if (szDiskPrompt
) prompt
= strdupAtoW(szDiskPrompt
);
1195 r
= MsiSourceListAddMediaDiskW(product
, usersid
, dwContext
, dwOptions
,
1196 dwDiskId
, volume
, prompt
);
1206 /******************************************************************
1207 * MsiSourceListAddMediaDiskW (MSI.@)
1209 UINT WINAPI
MsiSourceListAddMediaDiskW(LPCWSTR szProduct
, LPCWSTR szUserSid
,
1210 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1211 LPCWSTR szVolumeLabel
, LPCWSTR szDiskPrompt
)
1213 static const WCHAR fmt
[] = {'%','i',0};
1214 HKEY sourcekey
, mediakey
;
1216 WCHAR
*buffer
, squashed_pc
[SQUASHED_GUID_SIZE
], szIndex
[10];
1219 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct
),
1220 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwDiskId
,
1221 debugstr_w(szVolumeLabel
), debugstr_w(szDiskPrompt
));
1223 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
1224 return ERROR_INVALID_PARAMETER
;
1226 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
1227 return ERROR_INVALID_PARAMETER
;
1229 if ((szVolumeLabel
&& !*szVolumeLabel
) || (szDiskPrompt
&& !*szDiskPrompt
))
1230 return ERROR_INVALID_PARAMETER
;
1232 if ((dwContext
& MSIINSTALLCONTEXT_MACHINE
) && szUserSid
)
1233 return ERROR_INVALID_PARAMETER
;
1235 if (dwOptions
& MSICODE_PATCH
)
1237 FIXME("Unhandled options MSICODE_PATCH\n");
1238 return ERROR_FUNCTION_FAILED
;
1241 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1242 if (rc
!= ERROR_SUCCESS
)
1245 OpenMediaSubkey(sourcekey
, &mediakey
, TRUE
);
1247 sprintfW(szIndex
, fmt
, dwDiskId
);
1250 if (szVolumeLabel
) size
+= lstrlenW(szVolumeLabel
);
1251 if (szDiskPrompt
) size
+= lstrlenW(szDiskPrompt
);
1253 size
*= sizeof(WCHAR
);
1254 buffer
= msi_alloc(size
);
1257 if (szVolumeLabel
) lstrcpyW(buffer
, szVolumeLabel
);
1258 lstrcatW(buffer
, szSemiColon
);
1259 if (szDiskPrompt
) lstrcatW(buffer
, szDiskPrompt
);
1261 RegSetValueExW(mediakey
, szIndex
, 0, REG_SZ
, (LPBYTE
)buffer
, size
);
1264 RegCloseKey(sourcekey
);
1265 RegCloseKey(mediakey
);
1267 return ERROR_SUCCESS
;
1270 /******************************************************************
1271 * MsiSourceListClearAllA (MSI.@)
1273 UINT WINAPI
MsiSourceListClearAllA( LPCSTR szProduct
, LPCSTR szUserName
, DWORD dwReserved
)
1275 FIXME("(%s %s %d)\n", debugstr_a(szProduct
), debugstr_a(szUserName
), dwReserved
);
1276 return ERROR_SUCCESS
;
1279 /******************************************************************
1280 * MsiSourceListClearAllW (MSI.@)
1282 UINT WINAPI
MsiSourceListClearAllW( LPCWSTR szProduct
, LPCWSTR szUserName
, DWORD dwReserved
)
1284 FIXME("(%s %s %d)\n", debugstr_w(szProduct
), debugstr_w(szUserName
), dwReserved
);
1285 return ERROR_SUCCESS
;
1288 /******************************************************************
1289 * MsiSourceListClearAllExA (MSI.@)
1291 UINT WINAPI
MsiSourceListClearAllExA( LPCSTR szProduct
, LPCSTR szUserSid
,
1292 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1294 FIXME("(%s %s %d %08x)\n", debugstr_a(szProduct
), debugstr_a(szUserSid
),
1295 dwContext
, dwOptions
);
1296 return ERROR_SUCCESS
;
1299 /******************************************************************
1300 * MsiSourceListClearAllExW (MSI.@)
1302 UINT WINAPI
MsiSourceListClearAllExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1303 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1305 FIXME("(%s %s %d %08x)\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1306 dwContext
, dwOptions
);
1307 return ERROR_SUCCESS
;
1310 /******************************************************************
1311 * MsiSourceListClearSourceA (MSI.@)
1313 UINT WINAPI
MsiSourceListClearSourceA(LPCSTR szProductCodeOrPatchCode
, LPCSTR szUserSid
,
1314 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1317 FIXME("(%s %s %x %x %s)\n", debugstr_a(szProductCodeOrPatchCode
), debugstr_a(szUserSid
),
1318 dwContext
, dwOptions
, debugstr_a(szSource
));
1319 return ERROR_SUCCESS
;
1322 /******************************************************************
1323 * MsiSourceListClearSourceW (MSI.@)
1325 UINT WINAPI
MsiSourceListClearSourceW(LPCWSTR szProductCodeOrPatchCode
, LPCWSTR szUserSid
,
1326 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1329 FIXME("(%s %s %x %x %s)\n", debugstr_w(szProductCodeOrPatchCode
), debugstr_w(szUserSid
),
1330 dwContext
, dwOptions
, debugstr_w(szSource
));
1331 return ERROR_SUCCESS
;