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 WCHAR squished_pc
[GUID_SIZE
];
217 DWORD valuesz
, datasz
= 0;
222 static DWORD index
= 0;
224 static const WCHAR fmt
[] = {'#','%','d',0};
226 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p)\n", debugstr_w(szProductCodeOrPatchCode
),
227 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szVolumeLabel
,
228 pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
230 if (!szProductCodeOrPatchCode
||
231 !squash_guid(szProductCodeOrPatchCode
, squished_pc
))
232 return ERROR_INVALID_PARAMETER
;
234 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
235 return ERROR_INVALID_PARAMETER
;
237 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
238 return ERROR_INVALID_PARAMETER
;
240 if (szDiskPrompt
&& !pcchDiskPrompt
)
241 return ERROR_INVALID_PARAMETER
;
246 if (dwIndex
!= index
)
247 return ERROR_INVALID_PARAMETER
;
249 r
= OpenSourceKey(szProductCodeOrPatchCode
, &source
,
250 dwOptions
, dwContext
, FALSE
);
251 if (r
!= ERROR_SUCCESS
)
254 r
= OpenMediaSubkey(source
, &media
, FALSE
);
255 if (r
!= ERROR_SUCCESS
)
258 return ERROR_NO_MORE_ITEMS
;
261 res
= RegQueryInfoKeyW(media
, NULL
, NULL
, NULL
, NULL
, NULL
,
262 NULL
, &numvals
, &valuesz
, &datasz
, NULL
, NULL
);
263 if (res
!= ERROR_SUCCESS
)
265 r
= ERROR_BAD_CONFIGURATION
;
269 value
= msi_alloc(++valuesz
* sizeof(WCHAR
));
270 data
= msi_alloc(++datasz
* sizeof(WCHAR
));
273 r
= ERROR_OUTOFMEMORY
;
277 r
= RegEnumValueW(media
, dwIndex
, value
, &valuesz
,
278 NULL
, &type
, (LPBYTE
)data
, &datasz
);
279 if (r
!= ERROR_SUCCESS
)
283 *pdwDiskId
= atolW(value
);
286 ptr
= strchrW(data
, ';');
294 if (type
== REG_DWORD
)
296 sprintfW(convert
, fmt
, *data
);
297 size
= lstrlenW(convert
);
301 size
= lstrlenW(data
);
303 if (size
>= *pcchVolumeLabel
)
305 else if (szVolumeLabel
)
306 lstrcpyW(szVolumeLabel
, ptr2
);
308 *pcchVolumeLabel
= size
;
316 if (type
== REG_DWORD
)
318 sprintfW(convert
, fmt
, *ptr
);
319 size
= lstrlenW(convert
);
323 size
= lstrlenW(ptr
);
325 if (size
>= *pcchDiskPrompt
)
327 else if (szDiskPrompt
)
328 lstrcpyW(szDiskPrompt
, ptr
);
330 *pcchDiskPrompt
= size
;
343 /******************************************************************
344 * MsiSourceListEnumSourcesA (MSI.@)
346 UINT WINAPI
MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch
, LPCSTR szUserSid
,
347 MSIINSTALLCONTEXT dwContext
,
348 DWORD dwOptions
, DWORD dwIndex
,
349 LPSTR szSource
, LPDWORD pcchSource
)
351 LPWSTR product
= NULL
;
352 LPWSTR usersid
= NULL
;
353 LPWSTR source
= NULL
;
355 UINT r
= ERROR_INVALID_PARAMETER
;
356 static DWORD index
= 0;
358 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_a(szProductCodeOrPatch
),
359 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
364 if (szSource
&& !pcchSource
)
367 if (dwIndex
!= index
)
370 if (szProductCodeOrPatch
) product
= strdupAtoW(szProductCodeOrPatch
);
371 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
373 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
374 dwIndex
, NULL
, &len
);
375 if (r
!= ERROR_SUCCESS
)
378 source
= msi_alloc(++len
* sizeof(WCHAR
));
381 r
= ERROR_OUTOFMEMORY
;
386 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
387 dwIndex
, source
, &len
);
388 if (r
!= ERROR_SUCCESS
)
391 len
= WideCharToMultiByte(CP_ACP
, 0, source
, -1, NULL
, 0, NULL
, NULL
);
392 if (pcchSource
&& *pcchSource
>= len
)
393 WideCharToMultiByte(CP_ACP
, 0, source
, -1, szSource
, len
, NULL
, NULL
);
398 *pcchSource
= len
- 1;
405 if (r
== ERROR_SUCCESS
)
407 if (szSource
|| !pcchSource
) index
++;
409 else if (dwIndex
> index
)
415 /******************************************************************
416 * MsiSourceListEnumSourcesW (MSI.@)
418 UINT WINAPI
MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch
, LPCWSTR szUserSid
,
419 MSIINSTALLCONTEXT dwContext
,
420 DWORD dwOptions
, DWORD dwIndex
,
421 LPWSTR szSource
, LPDWORD pcchSource
)
423 WCHAR squished_pc
[GUID_SIZE
];
428 UINT r
= ERROR_INVALID_PARAMETER
;
429 static DWORD index
= 0;
431 static const WCHAR format
[] = {'%','d',0};
433 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch
),
434 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
439 if (!szProductCodeOrPatch
|| !squash_guid(szProductCodeOrPatch
, squished_pc
))
442 if (szSource
&& !pcchSource
)
445 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
448 if ((dwOptions
& MSISOURCETYPE_NETWORK
) && (dwOptions
& MSISOURCETYPE_URL
))
451 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
454 if (dwIndex
!= index
)
457 r
= OpenSourceKey(szProductCodeOrPatch
, &source
,
458 dwOptions
, dwContext
, FALSE
);
459 if (r
!= ERROR_SUCCESS
)
462 if (dwOptions
& MSISOURCETYPE_NETWORK
)
463 r
= OpenNetworkSubkey(source
, &subkey
, FALSE
);
464 else if (dwOptions
& MSISOURCETYPE_URL
)
465 r
= OpenURLSubkey(source
, &subkey
, FALSE
);
467 if (r
!= ERROR_SUCCESS
)
469 r
= ERROR_NO_MORE_ITEMS
;
473 sprintfW(name
, format
, dwIndex
+ 1);
475 res
= RegQueryValueExW(subkey
, name
, 0, 0, (LPBYTE
)szSource
, pcchSource
);
476 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
477 r
= ERROR_NO_MORE_ITEMS
;
483 if (r
== ERROR_SUCCESS
)
485 if (szSource
|| !pcchSource
) index
++;
487 else if (dwIndex
> index
)
493 /******************************************************************
494 * MsiSourceListGetInfoA (MSI.@)
496 UINT WINAPI
MsiSourceListGetInfoA( LPCSTR szProduct
, LPCSTR szUserSid
,
497 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
498 LPCSTR szProperty
, LPSTR szValue
,
502 LPWSTR product
= NULL
;
503 LPWSTR usersid
= NULL
;
504 LPWSTR property
= NULL
;
508 if (szValue
&& !pcchValue
)
509 return ERROR_INVALID_PARAMETER
;
511 if (szProduct
) product
= strdupAtoW(szProduct
);
512 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
513 if (szProperty
) property
= strdupAtoW(szProperty
);
515 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
516 property
, NULL
, &len
);
517 if (ret
!= ERROR_SUCCESS
)
520 value
= msi_alloc(++len
* sizeof(WCHAR
));
522 return ERROR_OUTOFMEMORY
;
525 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
526 property
, value
, &len
);
527 if (ret
!= ERROR_SUCCESS
)
530 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
531 if (*pcchValue
>= len
)
532 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
534 ret
= ERROR_MORE_DATA
;
536 *pcchValue
= len
- 1;
546 /******************************************************************
547 * MsiSourceListGetInfoW (MSI.@)
549 UINT WINAPI
MsiSourceListGetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
550 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
551 LPCWSTR szProperty
, LPWSTR szValue
,
554 WCHAR squished_pc
[GUID_SIZE
];
555 HKEY sourcekey
, media
;
560 static const WCHAR mediapack
[] = {
561 'M','e','d','i','a','P','a','c','k','a','g','e',0};
563 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szProperty
));
565 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
566 return ERROR_INVALID_PARAMETER
;
568 if (szValue
&& !pcchValue
)
569 return ERROR_INVALID_PARAMETER
;
571 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
572 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
573 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
574 return ERROR_INVALID_PARAMETER
;
577 return ERROR_INVALID_PARAMETER
;
580 FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid
));
582 rc
= OpenSourceKey(szProduct
, &sourcekey
, dwOptions
, dwContext
, FALSE
);
583 if (rc
!= ERROR_SUCCESS
)
586 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
587 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
589 rc
= OpenMediaSubkey(sourcekey
, &media
, FALSE
);
590 if (rc
!= ERROR_SUCCESS
)
592 RegCloseKey(sourcekey
);
593 return ERROR_SUCCESS
;
596 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
597 szProperty
= mediapack
;
599 RegQueryValueExW(media
, szProperty
, 0, 0, (LPBYTE
)szValue
, pcchValue
);
602 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) ||
603 !strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
605 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
607 if (rc
!= ERROR_SUCCESS
)
609 RegCloseKey(sourcekey
);
610 return ERROR_SUCCESS
;
613 source
= msi_alloc(size
);
614 RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
615 0, 0, (LPBYTE
)source
, &size
);
620 RegCloseKey(sourcekey
);
621 return ERROR_SUCCESS
;
624 if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
626 if (*source
!= 'n' && *source
!= 'u' && *source
!= 'm')
629 RegCloseKey(sourcekey
);
630 return ERROR_SUCCESS
;
638 ptr
= strrchrW(source
, ';');
647 if (strlenW(ptr
) < *pcchValue
)
648 lstrcpyW(szValue
, ptr
);
650 rc
= ERROR_MORE_DATA
;
653 *pcchValue
= lstrlenW(ptr
);
656 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
658 *pcchValue
= *pcchValue
* sizeof(WCHAR
);
659 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0, 0,
660 (LPBYTE
)szValue
, pcchValue
);
661 if (rc
!= ERROR_SUCCESS
&& rc
!= ERROR_MORE_DATA
)
669 *pcchValue
= (*pcchValue
- 1) / sizeof(WCHAR
);
671 szValue
[*pcchValue
] = '\0';
676 FIXME("Unknown property %s\n",debugstr_w(szProperty
));
677 rc
= ERROR_UNKNOWN_PROPERTY
;
680 RegCloseKey(sourcekey
);
684 /******************************************************************
685 * MsiSourceListSetInfoA (MSI.@)
687 UINT WINAPI
MsiSourceListSetInfoA(LPCSTR szProduct
, LPCSTR szUserSid
,
688 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
689 LPCSTR szProperty
, LPCSTR szValue
)
692 LPWSTR product
= NULL
;
693 LPWSTR usersid
= NULL
;
694 LPWSTR property
= NULL
;
697 if (szProduct
) product
= strdupAtoW(szProduct
);
698 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
699 if (szProperty
) property
= strdupAtoW(szProperty
);
700 if (szValue
) value
= strdupAtoW(szValue
);
702 ret
= MsiSourceListSetInfoW(product
, usersid
, dwContext
, dwOptions
,
713 UINT
msi_set_last_used_source(LPCWSTR product
, LPCWSTR usersid
,
714 MSIINSTALLCONTEXT context
, DWORD options
,
724 static const WCHAR format
[] = {'%','c',';','%','i',';','%','s',0};
726 if (options
& MSISOURCETYPE_NETWORK
)
728 else if (options
& MSISOURCETYPE_URL
)
730 else if (options
& MSISOURCETYPE_MEDIA
)
733 return ERROR_INVALID_PARAMETER
;
735 if (!(options
& MSISOURCETYPE_MEDIA
))
737 r
= MsiSourceListAddSourceExW(product
, usersid
, context
,
739 if (r
!= ERROR_SUCCESS
)
743 while ((r
= MsiSourceListEnumSourcesW(product
, usersid
, context
, options
,
744 index
, NULL
, NULL
)) == ERROR_SUCCESS
)
747 if (r
!= ERROR_NO_MORE_ITEMS
)
751 size
= (lstrlenW(format
) + lstrlenW(value
) + 7) * sizeof(WCHAR
);
752 buffer
= msi_alloc(size
);
754 return ERROR_OUTOFMEMORY
;
756 r
= OpenSourceKey(product
, &source
, MSICODE_PRODUCT
, context
, FALSE
);
757 if (r
!= ERROR_SUCCESS
)
763 sprintfW(buffer
, format
, typechar
, index
, value
);
765 size
= (lstrlenW(buffer
) + 1) * sizeof(WCHAR
);
766 r
= RegSetValueExW(source
, INSTALLPROPERTY_LASTUSEDSOURCEW
, 0,
767 REG_SZ
, (LPBYTE
)buffer
, size
);
774 /******************************************************************
775 * MsiSourceListSetInfoW (MSI.@)
777 UINT WINAPI
MsiSourceListSetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
778 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
779 LPCWSTR szProperty
, LPCWSTR szValue
)
781 WCHAR squished_pc
[GUID_SIZE
];
782 HKEY sourcekey
, media
;
786 static const WCHAR media_package
[] = {
787 'M','e','d','i','a','P','a','c','k','a','g','e',0
790 TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
791 dwContext
, dwOptions
, debugstr_w(szProperty
), debugstr_w(szValue
));
793 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
794 return ERROR_INVALID_PARAMETER
;
797 return ERROR_INVALID_PARAMETER
;
800 return ERROR_UNKNOWN_PROPERTY
;
802 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
803 return ERROR_INVALID_PARAMETER
;
805 if (dwOptions
& MSICODE_PATCH
)
807 FIXME("Unhandled options MSICODE_PATCH\n");
808 return ERROR_UNKNOWN_PATCH
;
811 property
= szProperty
;
812 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
813 property
= media_package
;
815 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
816 if (rc
!= ERROR_SUCCESS
)
819 if (strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) &&
820 dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
))
822 RegCloseKey(sourcekey
);
823 return ERROR_INVALID_PARAMETER
;
826 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
827 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
829 rc
= OpenMediaSubkey(sourcekey
, &media
, TRUE
);
830 if (rc
== ERROR_SUCCESS
)
832 rc
= msi_reg_set_val_str(media
, property
, szValue
);
836 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
838 DWORD size
= (lstrlenW(szValue
) + 1) * sizeof(WCHAR
);
839 rc
= RegSetValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0,
840 REG_SZ
, (const BYTE
*)szValue
, size
);
841 if (rc
!= ERROR_SUCCESS
)
842 rc
= ERROR_UNKNOWN_PROPERTY
;
844 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
846 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
847 rc
= ERROR_INVALID_PARAMETER
;
849 rc
= msi_set_last_used_source(szProduct
, szUserSid
, dwContext
,
853 rc
= ERROR_UNKNOWN_PROPERTY
;
855 RegCloseKey(sourcekey
);
859 /******************************************************************
860 * MsiSourceListAddSourceW (MSI.@)
862 UINT WINAPI
MsiSourceListAddSourceW( LPCWSTR szProduct
, LPCWSTR szUserName
,
863 DWORD dwReserved
, LPCWSTR szSource
)
865 WCHAR squished_pc
[GUID_SIZE
];
867 LPWSTR sidstr
= NULL
;
874 TRACE("%s %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserName
), debugstr_w(szSource
));
876 if (!szSource
|| !*szSource
)
877 return ERROR_INVALID_PARAMETER
;
880 return ERROR_INVALID_PARAMETER
;
882 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
883 return ERROR_INVALID_PARAMETER
;
885 if (!szUserName
|| !*szUserName
)
886 context
= MSIINSTALLCONTEXT_MACHINE
;
889 if (LookupAccountNameW(NULL
, szUserName
, NULL
, &sidsize
, NULL
, &domsize
, NULL
))
891 PSID psid
= msi_alloc(sidsize
);
893 if (LookupAccountNameW(NULL
, szUserName
, psid
, &sidsize
, NULL
, &domsize
, NULL
))
894 ConvertSidToStringSidW(psid
, &sidstr
);
899 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
900 MSIINSTALLCONTEXT_USERMANAGED
, &hkey
, FALSE
);
901 if (r
== ERROR_SUCCESS
)
902 context
= MSIINSTALLCONTEXT_USERMANAGED
;
905 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
906 MSIINSTALLCONTEXT_USERUNMANAGED
,
908 if (r
!= ERROR_SUCCESS
)
909 return ERROR_UNKNOWN_PRODUCT
;
911 context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
917 ret
= MsiSourceListAddSourceExW(szProduct
, sidstr
,
918 context
, MSISOURCETYPE_NETWORK
, szSource
, 0);
926 /******************************************************************
927 * MsiSourceListAddSourceA (MSI.@)
929 UINT WINAPI
MsiSourceListAddSourceA( LPCSTR szProduct
, LPCSTR szUserName
,
930 DWORD dwReserved
, LPCSTR szSource
)
937 szwproduct
= strdupAtoW( szProduct
);
938 szwusername
= strdupAtoW( szUserName
);
939 szwsource
= strdupAtoW( szSource
);
941 ret
= MsiSourceListAddSourceW(szwproduct
, szwusername
, dwReserved
, szwsource
);
943 msi_free(szwproduct
);
944 msi_free(szwusername
);
950 /******************************************************************
951 * MsiSourceListAddSourceExA (MSI.@)
953 UINT WINAPI
MsiSourceListAddSourceExA(LPCSTR szProduct
, LPCSTR szUserSid
,
954 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCSTR szSource
, DWORD dwIndex
)
957 LPWSTR product
, usersid
, source
;
959 product
= strdupAtoW(szProduct
);
960 usersid
= strdupAtoW(szUserSid
);
961 source
= strdupAtoW(szSource
);
963 ret
= MsiSourceListAddSourceExW(product
, usersid
, dwContext
,
964 dwOptions
, source
, dwIndex
);
973 static void free_source_list(struct list
*sourcelist
)
975 while (!list_empty(sourcelist
))
977 media_info
*info
= LIST_ENTRY(list_head(sourcelist
), media_info
, entry
);
978 list_remove(&info
->entry
);
979 msi_free(info
->path
);
984 static void add_source_to_list(struct list
*sourcelist
, media_info
*info
,
989 static const WCHAR fmt
[] = {'%','i',0};
991 if (index
) *index
= 0;
993 if (list_empty(sourcelist
))
995 list_add_head(sourcelist
, &info
->entry
);
999 LIST_FOR_EACH_ENTRY(iter
, sourcelist
, media_info
, entry
)
1001 if (!found
&& info
->index
< iter
->index
)
1004 list_add_before(&iter
->entry
, &info
->entry
);
1007 /* update the rest of the list */
1009 sprintfW(iter
->szIndex
, fmt
, ++iter
->index
);
1015 list_add_after(&iter
->entry
, &info
->entry
);
1018 static UINT
fill_source_list(struct list
*sourcelist
, HKEY sourcekey
, DWORD
*count
)
1020 UINT r
= ERROR_SUCCESS
;
1023 DWORD size
, val_size
;
1028 while (r
== ERROR_SUCCESS
)
1030 size
= sizeof(name
) / sizeof(name
[0]);
1031 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
, NULL
, NULL
, &val_size
);
1032 if (r
!= ERROR_SUCCESS
)
1035 entry
= msi_alloc(sizeof(media_info
));
1039 entry
->path
= msi_alloc(val_size
);
1046 lstrcpyW(entry
->szIndex
, name
);
1047 entry
->index
= atoiW(name
);
1050 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
,
1051 NULL
, (LPBYTE
)entry
->path
, &val_size
);
1052 if (r
!= ERROR_SUCCESS
)
1054 msi_free(entry
->path
);
1060 add_source_to_list(sourcelist
, entry
, NULL
);
1065 free_source_list(sourcelist
);
1066 return ERROR_OUTOFMEMORY
;
1069 /******************************************************************
1070 * MsiSourceListAddSourceExW (MSI.@)
1072 UINT WINAPI
MsiSourceListAddSourceExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1073 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCWSTR szSource
,
1079 struct list sourcelist
;
1081 WCHAR squished_pc
[GUID_SIZE
];
1088 static const WCHAR fmt
[] = {'%','i',0};
1090 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1091 dwContext
, dwOptions
, debugstr_w(szSource
), dwIndex
);
1093 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1094 return ERROR_INVALID_PARAMETER
;
1096 if (!szSource
|| !*szSource
)
1097 return ERROR_INVALID_PARAMETER
;
1099 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
1100 return ERROR_INVALID_PARAMETER
;
1102 if (dwOptions
& MSICODE_PATCH
)
1104 FIXME("Unhandled options MSICODE_PATCH\n");
1105 return ERROR_FUNCTION_FAILED
;
1108 if (szUserSid
&& (dwContext
& MSIINSTALLCONTEXT_MACHINE
))
1109 return ERROR_INVALID_PARAMETER
;
1111 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1112 if (rc
!= ERROR_SUCCESS
)
1115 if (dwOptions
& MSISOURCETYPE_NETWORK
)
1116 rc
= OpenNetworkSubkey(sourcekey
, &typekey
, TRUE
);
1117 else if (dwOptions
& MSISOURCETYPE_URL
)
1118 rc
= OpenURLSubkey(sourcekey
, &typekey
, TRUE
);
1119 else if (dwOptions
& MSISOURCETYPE_MEDIA
)
1120 rc
= OpenMediaSubkey(sourcekey
, &typekey
, TRUE
);
1123 ERR("unknown media type: %08x\n", dwOptions
);
1124 RegCloseKey(sourcekey
);
1125 return ERROR_FUNCTION_FAILED
;
1127 if (rc
!= ERROR_SUCCESS
)
1129 ERR("can't open subkey %u\n", rc
);
1130 RegCloseKey(sourcekey
);
1134 postfix
= (dwOptions
& MSISOURCETYPE_NETWORK
) ? szBackSlash
: szForwardSlash
;
1135 if (szSource
[lstrlenW(szSource
) - 1] == *postfix
)
1136 source
= strdupW(szSource
);
1139 size
= lstrlenW(szSource
) + 2;
1140 source
= msi_alloc(size
* sizeof(WCHAR
));
1141 lstrcpyW(source
, szSource
);
1142 lstrcatW(source
, postfix
);
1145 list_init(&sourcelist
);
1146 rc
= fill_source_list(&sourcelist
, typekey
, &count
);
1147 if (rc
!= ERROR_NO_MORE_ITEMS
)
1150 size
= (lstrlenW(source
) + 1) * sizeof(WCHAR
);
1154 rc
= RegSetValueExW(typekey
, szOne
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1157 else if (dwIndex
> count
|| dwIndex
== 0)
1159 sprintfW(name
, fmt
, count
+ 1);
1160 rc
= RegSetValueExW(typekey
, name
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1165 sprintfW(name
, fmt
, dwIndex
);
1166 info
= msi_alloc(sizeof(media_info
));
1169 rc
= ERROR_OUTOFMEMORY
;
1173 info
->path
= strdupW(source
);
1174 lstrcpyW(info
->szIndex
, name
);
1175 info
->index
= dwIndex
;
1176 add_source_to_list(&sourcelist
, info
, &index
);
1178 LIST_FOR_EACH_ENTRY(info
, &sourcelist
, media_info
, entry
)
1180 if (info
->index
< index
)
1183 size
= (lstrlenW(info
->path
) + 1) * sizeof(WCHAR
);
1184 rc
= RegSetValueExW(typekey
, info
->szIndex
, 0,
1185 REG_EXPAND_SZ
, (LPBYTE
)info
->path
, size
);
1186 if (rc
!= ERROR_SUCCESS
)
1192 free_source_list(&sourcelist
);
1194 RegCloseKey(typekey
);
1195 RegCloseKey(sourcekey
);
1199 /******************************************************************
1200 * MsiSourceListAddMediaDiskA (MSI.@)
1202 UINT WINAPI
MsiSourceListAddMediaDiskA(LPCSTR szProduct
, LPCSTR szUserSid
,
1203 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1204 LPCSTR szVolumeLabel
, LPCSTR szDiskPrompt
)
1207 LPWSTR product
= NULL
;
1208 LPWSTR usersid
= NULL
;
1209 LPWSTR volume
= NULL
;
1210 LPWSTR prompt
= NULL
;
1212 if (szProduct
) product
= strdupAtoW(szProduct
);
1213 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1214 if (szVolumeLabel
) volume
= strdupAtoW(szVolumeLabel
);
1215 if (szDiskPrompt
) prompt
= strdupAtoW(szDiskPrompt
);
1217 r
= MsiSourceListAddMediaDiskW(product
, usersid
, dwContext
, dwOptions
,
1218 dwDiskId
, volume
, prompt
);
1228 /******************************************************************
1229 * MsiSourceListAddMediaDiskW (MSI.@)
1231 UINT WINAPI
MsiSourceListAddMediaDiskW(LPCWSTR szProduct
, LPCWSTR szUserSid
,
1232 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1233 LPCWSTR szVolumeLabel
, LPCWSTR szDiskPrompt
)
1239 WCHAR squished_pc
[GUID_SIZE
];
1243 static const WCHAR fmt
[] = {'%','i',0};
1245 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct
),
1246 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwDiskId
,
1247 debugstr_w(szVolumeLabel
), debugstr_w(szDiskPrompt
));
1249 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1250 return ERROR_INVALID_PARAMETER
;
1252 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
1253 return ERROR_INVALID_PARAMETER
;
1255 if ((szVolumeLabel
&& !*szVolumeLabel
) || (szDiskPrompt
&& !*szDiskPrompt
))
1256 return ERROR_INVALID_PARAMETER
;
1258 if ((dwContext
& MSIINSTALLCONTEXT_MACHINE
) && szUserSid
)
1259 return ERROR_INVALID_PARAMETER
;
1261 if (dwOptions
& MSICODE_PATCH
)
1263 FIXME("Unhandled options MSICODE_PATCH\n");
1264 return ERROR_FUNCTION_FAILED
;
1267 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1268 if (rc
!= ERROR_SUCCESS
)
1271 OpenMediaSubkey(sourcekey
, &mediakey
, TRUE
);
1273 sprintfW(szIndex
, fmt
, dwDiskId
);
1276 if (szVolumeLabel
) size
+= lstrlenW(szVolumeLabel
);
1277 if (szDiskPrompt
) size
+= lstrlenW(szDiskPrompt
);
1279 size
*= sizeof(WCHAR
);
1280 buffer
= msi_alloc(size
);
1283 if (szVolumeLabel
) lstrcpyW(buffer
, szVolumeLabel
);
1284 lstrcatW(buffer
, szSemiColon
);
1285 if (szDiskPrompt
) lstrcatW(buffer
, szDiskPrompt
);
1287 RegSetValueExW(mediakey
, szIndex
, 0, REG_SZ
, (LPBYTE
)buffer
, size
);
1290 RegCloseKey(sourcekey
);
1291 RegCloseKey(mediakey
);
1293 return ERROR_SUCCESS
;
1296 /******************************************************************
1297 * MsiSourceListClearAllA (MSI.@)
1299 UINT WINAPI
MsiSourceListClearAllA( LPCSTR szProduct
, LPCSTR szUserName
, DWORD dwReserved
)
1301 FIXME("(%s %s %d)\n", debugstr_a(szProduct
), debugstr_a(szUserName
), dwReserved
);
1302 return ERROR_SUCCESS
;
1305 /******************************************************************
1306 * MsiSourceListClearAllW (MSI.@)
1308 UINT WINAPI
MsiSourceListClearAllW( LPCWSTR szProduct
, LPCWSTR szUserName
, DWORD dwReserved
)
1310 FIXME("(%s %s %d)\n", debugstr_w(szProduct
), debugstr_w(szUserName
), dwReserved
);
1311 return ERROR_SUCCESS
;
1314 /******************************************************************
1315 * MsiSourceListClearAllExA (MSI.@)
1317 UINT WINAPI
MsiSourceListClearAllExA( LPCSTR szProduct
, LPCSTR szUserSid
,
1318 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1320 FIXME("(%s %s %d %08x)\n", debugstr_a(szProduct
), debugstr_a(szUserSid
),
1321 dwContext
, dwOptions
);
1322 return ERROR_SUCCESS
;
1325 /******************************************************************
1326 * MsiSourceListClearAllExW (MSI.@)
1328 UINT WINAPI
MsiSourceListClearAllExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1329 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1331 FIXME("(%s %s %d %08x)\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1332 dwContext
, dwOptions
);
1333 return ERROR_SUCCESS
;
1336 /******************************************************************
1337 * MsiSourceListClearSourceA (MSI.@)
1339 UINT WINAPI
MsiSourceListClearSourceA(LPCSTR szProductCodeOrPatchCode
, LPCSTR szUserSid
,
1340 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1343 FIXME("(%s %s %x %x %s)\n", debugstr_a(szProductCodeOrPatchCode
), debugstr_a(szUserSid
),
1344 dwContext
, dwOptions
, debugstr_a(szSource
));
1345 return ERROR_SUCCESS
;
1348 /******************************************************************
1349 * MsiSourceListClearSourceW (MSI.@)
1351 UINT WINAPI
MsiSourceListClearSourceW(LPCWSTR szProductCodeOrPatchCode
, LPCWSTR szUserSid
,
1352 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1355 FIXME("(%s %s %x %x %s)\n", debugstr_w(szProductCodeOrPatchCode
), debugstr_w(szUserSid
),
1356 dwContext
, dwOptions
, debugstr_w(szSource
));
1357 return ERROR_SUCCESS
;