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
24 #define NONAMELESSUNION
31 #include "wine/debug.h"
38 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
44 * These apis are defined in MSI 3.0
47 typedef struct tagMediaInfo
55 static UINT
OpenSourceKey(LPCWSTR szProduct
, HKEY
* key
, DWORD dwOptions
,
56 MSIINSTALLCONTEXT context
, BOOL create
)
59 UINT rc
= ERROR_FUNCTION_FAILED
;
60 static const WCHAR szSourceList
[] = {'S','o','u','r','c','e','L','i','s','t',0};
62 if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
64 if (dwOptions
& MSICODE_PATCH
)
65 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
67 rc
= MSIREG_OpenUserProductsKey(szProduct
, &rootkey
, create
);
69 else if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
71 if (dwOptions
& MSICODE_PATCH
)
72 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
74 rc
= MSIREG_OpenLocalManagedProductKey(szProduct
, &rootkey
, create
);
76 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
78 if (dwOptions
& MSICODE_PATCH
)
79 rc
= MSIREG_OpenPatchesKey(szProduct
, &rootkey
, create
);
81 rc
= MSIREG_OpenLocalClassesProductKey(szProduct
, &rootkey
, create
);
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
;
104 static UINT
OpenMediaSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
107 static const WCHAR media
[] = {'M','e','d','i','a',0};
110 rc
= RegCreateKeyW(rootkey
, media
, key
);
112 rc
= RegOpenKeyW(rootkey
,media
, key
);
117 static UINT
OpenNetworkSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
120 static const WCHAR net
[] = {'N','e','t',0};
123 rc
= RegCreateKeyW(rootkey
, net
, key
);
125 rc
= RegOpenKeyW(rootkey
, net
, key
);
130 static UINT
OpenURLSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
133 static const WCHAR URL
[] = {'U','R','L',0};
136 rc
= RegCreateKeyW(rootkey
, URL
, key
);
138 rc
= RegOpenKeyW(rootkey
, URL
, key
);
143 /******************************************************************
144 * MsiSourceListEnumMediaDisksA (MSI.@)
146 UINT WINAPI
MsiSourceListEnumMediaDisksA(LPCSTR szProductCodeOrPatchCode
,
147 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
148 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
149 LPSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
150 LPSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
152 LPWSTR product
= NULL
;
153 LPWSTR usersid
= NULL
;
154 LPWSTR volume
= NULL
;
155 LPWSTR prompt
= NULL
;
156 UINT r
= ERROR_INVALID_PARAMETER
;
158 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n", debugstr_a(szProductCodeOrPatchCode
),
159 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, pdwDiskId
,
160 szVolumeLabel
, pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
162 if (szDiskPrompt
&& !pcchDiskPrompt
)
163 return ERROR_INVALID_PARAMETER
;
165 if (szProductCodeOrPatchCode
) product
= strdupAtoW(szProductCodeOrPatchCode
);
166 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
168 /* FIXME: add tests for an invalid format */
171 volume
= msi_alloc(*pcchVolumeLabel
* sizeof(WCHAR
));
174 prompt
= msi_alloc(*pcchDiskPrompt
* sizeof(WCHAR
));
176 if (volume
) *volume
= '\0';
177 if (prompt
) *prompt
= '\0';
178 r
= MsiSourceListEnumMediaDisksW(product
, usersid
, dwContext
, dwOptions
,
179 dwIndex
, pdwDiskId
, volume
, pcchVolumeLabel
,
180 prompt
, pcchDiskPrompt
);
181 if (r
!= ERROR_SUCCESS
)
184 if (szVolumeLabel
&& pcchVolumeLabel
)
185 WideCharToMultiByte(CP_ACP
, 0, volume
, -1, szVolumeLabel
,
186 *pcchVolumeLabel
+ 1, NULL
, NULL
);
189 WideCharToMultiByte(CP_ACP
, 0, prompt
, -1, szDiskPrompt
,
190 *pcchDiskPrompt
+ 1, NULL
, NULL
);
201 /******************************************************************
202 * MsiSourceListEnumMediaDisksW (MSI.@)
204 UINT WINAPI
MsiSourceListEnumMediaDisksW(LPCWSTR szProductCodeOrPatchCode
,
205 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
206 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
207 LPWSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
208 LPWSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
210 WCHAR squished_pc
[GUID_SIZE
];
215 DWORD valuesz
, datasz
= 0;
220 static int index
= 0;
222 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p)\n", debugstr_w(szProductCodeOrPatchCode
),
223 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szVolumeLabel
,
224 pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
226 if (!szProductCodeOrPatchCode
||
227 !squash_guid(szProductCodeOrPatchCode
, squished_pc
))
228 return ERROR_INVALID_PARAMETER
;
230 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
231 return ERROR_INVALID_PARAMETER
;
233 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
234 return ERROR_INVALID_PARAMETER
;
236 if (szDiskPrompt
&& !pcchDiskPrompt
)
237 return ERROR_INVALID_PARAMETER
;
242 if (dwIndex
!= index
)
243 return ERROR_INVALID_PARAMETER
;
245 r
= OpenSourceKey(szProductCodeOrPatchCode
, &source
,
246 dwOptions
, dwContext
, FALSE
);
247 if (r
!= ERROR_SUCCESS
)
250 r
= OpenMediaSubkey(source
, &media
, FALSE
);
251 if (r
!= ERROR_SUCCESS
)
254 return ERROR_NO_MORE_ITEMS
;
257 if (!pcchVolumeLabel
&& !pcchDiskPrompt
)
259 r
= RegEnumValueW(media
, dwIndex
, NULL
, NULL
, NULL
,
264 res
= RegQueryInfoKeyW(media
, NULL
, NULL
, NULL
, NULL
, NULL
,
265 NULL
, &numvals
, &valuesz
, &datasz
, NULL
, NULL
);
266 if (res
!= ERROR_SUCCESS
)
268 r
= ERROR_BAD_CONFIGURATION
;
272 value
= msi_alloc(++valuesz
* sizeof(WCHAR
));
273 data
= msi_alloc(++datasz
* sizeof(WCHAR
));
276 r
= ERROR_OUTOFMEMORY
;
280 r
= RegEnumValueW(media
, dwIndex
, value
, &valuesz
,
281 NULL
, &type
, (LPBYTE
)data
, &datasz
);
282 if (r
!= ERROR_SUCCESS
)
286 *pdwDiskId
= atolW(value
);
288 ptr
= strchrW(data
, ';');
296 size
= lstrlenW(data
);
297 if (size
>= *pcchVolumeLabel
)
299 else if (szVolumeLabel
)
300 lstrcpyW(szVolumeLabel
, data
);
302 *pcchVolumeLabel
= size
;
311 size
= lstrlenW(data
);
312 if (size
>= *pcchDiskPrompt
)
314 else if (szDiskPrompt
)
315 lstrcpyW(szDiskPrompt
, data
);
317 *pcchDiskPrompt
= size
;
330 /******************************************************************
331 * MsiSourceListEnumSourcesA (MSI.@)
333 UINT WINAPI
MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch
, LPCSTR szUserSid
,
334 MSIINSTALLCONTEXT dwContext
,
335 DWORD dwOptions
, DWORD dwIndex
,
336 LPSTR szSource
, LPDWORD pcchSource
)
338 LPWSTR product
= NULL
;
339 LPWSTR usersid
= NULL
;
340 LPWSTR source
= NULL
;
342 UINT r
= ERROR_INVALID_PARAMETER
;
343 static int index
= 0;
345 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_a(szProductCodeOrPatch
),
346 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
351 if (szSource
&& !pcchSource
)
354 if (dwIndex
!= index
)
357 if (szProductCodeOrPatch
) product
= strdupAtoW(szProductCodeOrPatch
);
358 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
360 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
361 dwIndex
, NULL
, &len
);
362 if (r
!= ERROR_SUCCESS
)
365 source
= msi_alloc(++len
* sizeof(WCHAR
));
368 r
= ERROR_OUTOFMEMORY
;
373 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
374 dwIndex
, source
, &len
);
375 if (r
!= ERROR_SUCCESS
)
378 len
= WideCharToMultiByte(CP_ACP
, 0, source
, -1, NULL
, 0, NULL
, NULL
);
379 if (pcchSource
&& *pcchSource
>= len
)
380 WideCharToMultiByte(CP_ACP
, 0, source
, -1, szSource
, len
, NULL
, NULL
);
385 *pcchSource
= len
- 1;
392 if (r
== ERROR_SUCCESS
)
394 if (szSource
|| !pcchSource
) index
++;
396 else if (dwIndex
> index
)
402 /******************************************************************
403 * MsiSourceListEnumSourcesW (MSI.@)
405 UINT WINAPI
MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch
, LPCWSTR szUserSid
,
406 MSIINSTALLCONTEXT dwContext
,
407 DWORD dwOptions
, DWORD dwIndex
,
408 LPWSTR szSource
, LPDWORD pcchSource
)
410 WCHAR squished_pc
[GUID_SIZE
];
415 UINT r
= ERROR_INVALID_PARAMETER
;
416 static int index
= 0;
418 static const WCHAR format
[] = {'%','d',0};
420 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch
),
421 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
426 if (!szProductCodeOrPatch
|| !squash_guid(szProductCodeOrPatch
, squished_pc
))
429 if (szSource
&& !pcchSource
)
432 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
435 if ((dwOptions
& MSISOURCETYPE_NETWORK
) && (dwOptions
& MSISOURCETYPE_URL
))
438 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
441 if (dwIndex
!= index
)
444 r
= OpenSourceKey(szProductCodeOrPatch
, &source
,
445 dwOptions
, dwContext
, FALSE
);
446 if (r
!= ERROR_SUCCESS
)
449 if (dwOptions
& MSISOURCETYPE_NETWORK
)
450 r
= OpenNetworkSubkey(source
, &subkey
, FALSE
);
451 else if (dwOptions
& MSISOURCETYPE_URL
)
452 r
= OpenURLSubkey(source
, &subkey
, FALSE
);
454 if (r
!= ERROR_SUCCESS
)
456 r
= ERROR_NO_MORE_ITEMS
;
460 sprintfW(name
, format
, dwIndex
+ 1);
462 res
= RegQueryValueExW(subkey
, name
, 0, 0, (LPBYTE
)szSource
, pcchSource
);
463 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
464 r
= ERROR_NO_MORE_ITEMS
;
470 if (r
== ERROR_SUCCESS
)
472 if (szSource
|| !pcchSource
) index
++;
474 else if (dwIndex
> index
)
480 /******************************************************************
481 * MsiSourceListGetInfoA (MSI.@)
483 UINT WINAPI
MsiSourceListGetInfoA( LPCSTR szProduct
, LPCSTR szUserSid
,
484 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
485 LPCSTR szProperty
, LPSTR szValue
,
489 LPWSTR product
= NULL
;
490 LPWSTR usersid
= NULL
;
491 LPWSTR property
= NULL
;
495 if (szValue
&& !pcchValue
)
496 return ERROR_INVALID_PARAMETER
;
498 if (szProduct
) product
= strdupAtoW(szProduct
);
499 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
500 if (szProperty
) property
= strdupAtoW(szProperty
);
502 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
503 property
, NULL
, &len
);
504 if (ret
!= ERROR_SUCCESS
)
507 value
= msi_alloc(++len
* sizeof(WCHAR
));
509 return ERROR_OUTOFMEMORY
;
512 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
513 property
, value
, &len
);
514 if (ret
!= ERROR_SUCCESS
)
517 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
518 if (*pcchValue
>= len
)
519 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
521 ret
= ERROR_MORE_DATA
;
523 *pcchValue
= len
- 1;
533 /******************************************************************
534 * MsiSourceListGetInfoW (MSI.@)
536 UINT WINAPI
MsiSourceListGetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
537 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
538 LPCWSTR szProperty
, LPWSTR szValue
,
541 WCHAR squished_pc
[GUID_SIZE
];
542 HKEY sourcekey
, media
;
547 static const WCHAR mediapack
[] = {
548 'M','e','d','i','a','P','a','c','k','a','g','e',0};
550 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szProperty
));
552 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
553 return ERROR_INVALID_PARAMETER
;
555 if (szValue
&& !pcchValue
)
556 return ERROR_INVALID_PARAMETER
;
558 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
559 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
560 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
561 return ERROR_INVALID_PARAMETER
;
564 return ERROR_INVALID_PARAMETER
;
567 FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid
));
569 if (dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
)
570 FIXME("Unhandled context %d\n", dwContext
);
572 rc
= OpenSourceKey(szProduct
, &sourcekey
, dwOptions
, dwContext
, FALSE
);
573 if (rc
!= ERROR_SUCCESS
)
576 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
577 !lstrcmpW(szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
579 rc
= OpenMediaSubkey(sourcekey
, &media
, FALSE
);
580 if (rc
!= ERROR_SUCCESS
)
582 RegCloseKey(sourcekey
);
583 return ERROR_SUCCESS
;
586 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
587 szProperty
= mediapack
;
589 RegQueryValueExW(media
, szProperty
, 0, 0, (LPBYTE
)szValue
, pcchValue
);
592 else if (!lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) ||
593 !lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
595 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
597 if (rc
!= ERROR_SUCCESS
)
599 RegCloseKey(sourcekey
);
600 return ERROR_SUCCESS
;
603 source
= msi_alloc(size
);
604 RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
605 0, 0, (LPBYTE
)source
, &size
);
610 RegCloseKey(sourcekey
);
611 return ERROR_SUCCESS
;
614 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
616 if (*source
!= 'n' && *source
!= 'u' && *source
!= 'm')
619 RegCloseKey(sourcekey
);
620 return ERROR_SUCCESS
;
628 ptr
= strrchrW(source
, ';');
637 if (lstrlenW(ptr
) < *pcchValue
)
638 lstrcpyW(szValue
, ptr
);
640 rc
= ERROR_MORE_DATA
;
643 *pcchValue
= lstrlenW(ptr
);
646 else if (strcmpW(INSTALLPROPERTY_PACKAGENAMEW
, szProperty
)==0)
648 *pcchValue
= *pcchValue
* sizeof(WCHAR
);
649 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0, 0,
650 (LPBYTE
)szValue
, pcchValue
);
651 if (rc
!= ERROR_SUCCESS
&& rc
!= ERROR_MORE_DATA
)
659 *pcchValue
= (*pcchValue
- 1) / sizeof(WCHAR
);
661 szValue
[*pcchValue
] = '\0';
666 FIXME("Unknown property %s\n",debugstr_w(szProperty
));
667 rc
= ERROR_UNKNOWN_PROPERTY
;
670 RegCloseKey(sourcekey
);
674 /******************************************************************
675 * MsiSourceListSetInfoA (MSI.@)
677 UINT WINAPI
MsiSourceListSetInfoA(LPCSTR szProduct
, LPCSTR szUserSid
,
678 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
679 LPCSTR szProperty
, LPCSTR szValue
)
682 LPWSTR product
= NULL
;
683 LPWSTR usersid
= NULL
;
684 LPWSTR property
= NULL
;
687 if (szProduct
) product
= strdupAtoW(szProduct
);
688 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
689 if (szProperty
) property
= strdupAtoW(szProperty
);
690 if (szValue
) value
= strdupAtoW(szValue
);
692 ret
= MsiSourceListSetInfoW(product
, usersid
, dwContext
, dwOptions
,
703 UINT
msi_set_last_used_source(LPCWSTR product
, LPCWSTR usersid
,
704 MSIINSTALLCONTEXT context
, DWORD options
,
714 static const WCHAR format
[] = {'%','c',';','%','i',';','%','s',0};
716 if (options
& MSISOURCETYPE_NETWORK
)
718 else if (options
& MSISOURCETYPE_URL
)
720 else if (options
& MSISOURCETYPE_MEDIA
)
723 return ERROR_INVALID_PARAMETER
;
725 if (!(options
& MSISOURCETYPE_MEDIA
))
727 r
= MsiSourceListAddSourceExW(product
, usersid
, context
,
729 if (r
!= ERROR_SUCCESS
)
733 while ((r
= MsiSourceListEnumSourcesW(product
, usersid
, context
, options
,
734 index
, NULL
, NULL
)) == ERROR_SUCCESS
)
737 if (r
!= ERROR_NO_MORE_ITEMS
)
741 size
= (lstrlenW(format
) + lstrlenW(value
) + 7) * sizeof(WCHAR
);
742 buffer
= msi_alloc(size
);
744 return ERROR_OUTOFMEMORY
;
746 r
= OpenSourceKey(product
, &source
, MSICODE_PRODUCT
, context
, FALSE
);
747 if (r
!= ERROR_SUCCESS
)
750 sprintfW(buffer
, format
, typechar
, index
, value
);
752 size
= (lstrlenW(buffer
) + 1) * sizeof(WCHAR
);
753 r
= RegSetValueExW(source
, INSTALLPROPERTY_LASTUSEDSOURCEW
, 0,
754 REG_SZ
, (LPBYTE
)buffer
, size
);
761 /******************************************************************
762 * MsiSourceListSetInfoW (MSI.@)
764 UINT WINAPI
MsiSourceListSetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
765 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
766 LPCWSTR szProperty
, LPCWSTR szValue
)
768 WCHAR squished_pc
[GUID_SIZE
];
769 HKEY sourcekey
, media
;
773 static const WCHAR media_package
[] = {
774 'M','e','d','i','a','P','a','c','k','a','g','e',0
777 TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
778 dwContext
, dwOptions
, debugstr_w(szProperty
), debugstr_w(szValue
));
780 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
781 return ERROR_INVALID_PARAMETER
;
784 return ERROR_INVALID_PARAMETER
;
787 return ERROR_UNKNOWN_PROPERTY
;
789 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
790 return ERROR_INVALID_PARAMETER
;
792 if (dwOptions
& MSICODE_PATCH
)
794 FIXME("Unhandled options MSICODE_PATCH\n");
795 return ERROR_UNKNOWN_PATCH
;
798 property
= szProperty
;
799 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
800 property
= media_package
;
802 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
803 if (rc
!= ERROR_SUCCESS
)
806 if (lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) &&
807 dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
))
809 RegCloseKey(sourcekey
);
810 return ERROR_INVALID_PARAMETER
;
813 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
814 !lstrcmpW(szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
816 rc
= OpenMediaSubkey(sourcekey
, &media
, TRUE
);
817 if (rc
== ERROR_SUCCESS
)
819 rc
= msi_reg_set_val_str(media
, property
, szValue
);
823 else if (strcmpW(INSTALLPROPERTY_PACKAGENAMEW
, szProperty
)==0)
825 DWORD size
= (lstrlenW(szValue
) + 1) * sizeof(WCHAR
);
826 rc
= RegSetValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0,
827 REG_SZ
, (const BYTE
*)szValue
, size
);
828 if (rc
!= ERROR_SUCCESS
)
829 rc
= ERROR_UNKNOWN_PROPERTY
;
831 else if (!lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
833 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
834 rc
= ERROR_INVALID_PARAMETER
;
836 rc
= msi_set_last_used_source(szProduct
, szUserSid
, dwContext
,
840 rc
= ERROR_UNKNOWN_PROPERTY
;
842 RegCloseKey(sourcekey
);
846 /******************************************************************
847 * MsiSourceListAddSourceW (MSI.@)
849 UINT WINAPI
MsiSourceListAddSourceW( LPCWSTR szProduct
, LPCWSTR szUserName
,
850 DWORD dwReserved
, LPCWSTR szSource
)
852 WCHAR squished_pc
[GUID_SIZE
];
854 LPWSTR sidstr
= NULL
;
861 TRACE("%s %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserName
), debugstr_w(szSource
));
863 if (!szSource
|| !*szSource
)
864 return ERROR_INVALID_PARAMETER
;
867 return ERROR_INVALID_PARAMETER
;
869 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
870 return ERROR_INVALID_PARAMETER
;
872 if (!szUserName
|| !*szUserName
)
873 context
= MSIINSTALLCONTEXT_MACHINE
;
876 if (LookupAccountNameW(NULL
, szUserName
, NULL
, &sidsize
, NULL
, &domsize
, NULL
))
878 PSID psid
= msi_alloc(sidsize
);
880 if (LookupAccountNameW(NULL
, szUserName
, psid
, &sidsize
, NULL
, &domsize
, NULL
))
881 ConvertSidToStringSidW(psid
, &sidstr
);
886 r
= MSIREG_OpenLocalManagedProductKey(szProduct
, &hkey
, FALSE
);
887 if (r
== ERROR_SUCCESS
)
888 context
= MSIINSTALLCONTEXT_USERMANAGED
;
891 r
= MSIREG_OpenUserProductsKey(szProduct
, &hkey
, FALSE
);
892 if (r
!= ERROR_SUCCESS
)
893 return ERROR_UNKNOWN_PRODUCT
;
895 context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
901 ret
= MsiSourceListAddSourceExW(szProduct
, sidstr
,
902 context
, MSISOURCETYPE_NETWORK
, szSource
, 0);
910 /******************************************************************
911 * MsiSourceListAddSourceA (MSI.@)
913 UINT WINAPI
MsiSourceListAddSourceA( LPCSTR szProduct
, LPCSTR szUserName
,
914 DWORD dwReserved
, LPCSTR szSource
)
921 szwproduct
= strdupAtoW( szProduct
);
922 szwusername
= strdupAtoW( szUserName
);
923 szwsource
= strdupAtoW( szSource
);
925 ret
= MsiSourceListAddSourceW(szwproduct
, szwusername
, dwReserved
, szwsource
);
927 msi_free(szwproduct
);
928 msi_free(szwusername
);
934 /******************************************************************
935 * MsiSourceListAddSourceExA (MSI.@)
937 UINT WINAPI
MsiSourceListAddSourceExA(LPCSTR szProduct
, LPCSTR szUserSid
,
938 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCSTR szSource
, DWORD dwIndex
)
941 LPWSTR product
, usersid
, source
;
943 product
= strdupAtoW(szProduct
);
944 usersid
= strdupAtoW(szUserSid
);
945 source
= strdupAtoW(szSource
);
947 ret
= MsiSourceListAddSourceExW(product
, usersid
, dwContext
,
948 dwOptions
, source
, dwIndex
);
957 static void free_source_list(struct list
*sourcelist
)
959 while (!list_empty(sourcelist
))
961 media_info
*info
= LIST_ENTRY(list_head(sourcelist
), media_info
, entry
);
962 list_remove(&info
->entry
);
963 msi_free(info
->path
);
968 static void add_source_to_list(struct list
*sourcelist
, media_info
*info
,
973 static const WCHAR fmt
[] = {'%','i',0};
975 if (index
) *index
= 0;
977 if (list_empty(sourcelist
))
979 list_add_head(sourcelist
, &info
->entry
);
983 LIST_FOR_EACH_ENTRY(iter
, sourcelist
, media_info
, entry
)
985 if (!found
&& info
->index
< iter
->index
)
988 list_add_before(&iter
->entry
, &info
->entry
);
991 /* update the rest of the list */
993 sprintfW(iter
->szIndex
, fmt
, ++iter
->index
);
999 list_add_after(&iter
->entry
, &info
->entry
);
1002 static UINT
fill_source_list(struct list
*sourcelist
, HKEY sourcekey
, DWORD
*count
)
1004 UINT r
= ERROR_SUCCESS
;
1007 DWORD size
, val_size
;
1012 while (r
== ERROR_SUCCESS
)
1014 size
= sizeof(name
) / sizeof(name
[0]);
1015 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
, NULL
, NULL
, &val_size
);
1016 if (r
!= ERROR_SUCCESS
)
1019 entry
= msi_alloc(sizeof(media_info
));
1023 entry
->path
= msi_alloc(val_size
);
1030 lstrcpyW(entry
->szIndex
, name
);
1031 entry
->index
= atoiW(name
);
1034 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
,
1035 NULL
, (LPBYTE
)entry
->path
, &val_size
);
1036 if (r
!= ERROR_SUCCESS
)
1038 msi_free(entry
->path
);
1044 add_source_to_list(sourcelist
, entry
, NULL
);
1049 free_source_list(sourcelist
);
1050 return ERROR_OUTOFMEMORY
;
1053 /******************************************************************
1054 * MsiSourceListAddSourceExW (MSI.@)
1056 UINT WINAPI
MsiSourceListAddSourceExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1057 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCWSTR szSource
,
1063 struct list sourcelist
;
1065 WCHAR squished_pc
[GUID_SIZE
];
1072 static const WCHAR fmt
[] = {'%','i',0};
1073 static const WCHAR one
[] = {'1',0};
1074 static const WCHAR backslash
[] = {'\\',0};
1075 static const WCHAR forwardslash
[] = {'/',0};
1077 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1078 dwContext
, dwOptions
, debugstr_w(szSource
), dwIndex
);
1080 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1081 return ERROR_INVALID_PARAMETER
;
1083 if (!szSource
|| !*szSource
)
1084 return ERROR_INVALID_PARAMETER
;
1086 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
1087 return ERROR_INVALID_PARAMETER
;
1089 if (dwOptions
& MSICODE_PATCH
)
1091 FIXME("Unhandled options MSICODE_PATCH\n");
1092 return ERROR_FUNCTION_FAILED
;
1095 if (szUserSid
&& (dwContext
& MSIINSTALLCONTEXT_MACHINE
))
1096 return ERROR_INVALID_PARAMETER
;
1098 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1099 if (rc
!= ERROR_SUCCESS
)
1102 if (dwOptions
& MSISOURCETYPE_NETWORK
)
1103 rc
= OpenNetworkSubkey(sourcekey
, &typekey
, TRUE
);
1104 else if (dwOptions
& MSISOURCETYPE_URL
)
1105 rc
= OpenURLSubkey(sourcekey
, &typekey
, TRUE
);
1106 else if (dwOptions
& MSISOURCETYPE_MEDIA
)
1107 rc
= OpenMediaSubkey(sourcekey
, &typekey
, TRUE
);
1110 ERR("unknown media type: %08x\n", dwOptions
);
1111 RegCloseKey(sourcekey
);
1112 return ERROR_FUNCTION_FAILED
;
1115 postfix
= (dwOptions
& MSISOURCETYPE_NETWORK
) ? backslash
: forwardslash
;
1116 if (szSource
[lstrlenW(szSource
) - 1] == *postfix
)
1117 source
= strdupW(szSource
);
1120 size
= lstrlenW(szSource
) + 2;
1121 source
= msi_alloc(size
* sizeof(WCHAR
));
1122 lstrcpyW(source
, szSource
);
1123 lstrcatW(source
, postfix
);
1126 list_init(&sourcelist
);
1127 rc
= fill_source_list(&sourcelist
, typekey
, &count
);
1128 if (rc
!= ERROR_NO_MORE_ITEMS
)
1131 size
= (lstrlenW(source
) + 1) * sizeof(WCHAR
);
1135 rc
= RegSetValueExW(typekey
, one
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1138 else if (dwIndex
> count
|| dwIndex
== 0)
1140 sprintfW(name
, fmt
, count
+ 1);
1141 rc
= RegSetValueExW(typekey
, name
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1146 sprintfW(name
, fmt
, dwIndex
);
1147 info
= msi_alloc(sizeof(media_info
));
1150 rc
= ERROR_OUTOFMEMORY
;
1154 info
->path
= strdupW(source
);
1155 lstrcpyW(info
->szIndex
, name
);
1156 info
->index
= dwIndex
;
1157 add_source_to_list(&sourcelist
, info
, &index
);
1159 LIST_FOR_EACH_ENTRY(info
, &sourcelist
, media_info
, entry
)
1161 if (info
->index
< index
)
1164 size
= (lstrlenW(info
->path
) + 1) * sizeof(WCHAR
);
1165 rc
= RegSetValueExW(typekey
, info
->szIndex
, 0,
1166 REG_EXPAND_SZ
, (LPBYTE
)info
->path
, size
);
1167 if (rc
!= ERROR_SUCCESS
)
1173 free_source_list(&sourcelist
);
1175 RegCloseKey(typekey
);
1176 RegCloseKey(sourcekey
);
1180 /******************************************************************
1181 * MsiSourceListAddMediaDiskA (MSI.@)
1183 UINT WINAPI
MsiSourceListAddMediaDiskA(LPCSTR szProduct
, LPCSTR szUserSid
,
1184 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1185 LPCSTR szVolumeLabel
, LPCSTR szDiskPrompt
)
1188 LPWSTR product
= NULL
;
1189 LPWSTR usersid
= NULL
;
1190 LPWSTR volume
= NULL
;
1191 LPWSTR prompt
= NULL
;
1193 if (szProduct
) product
= strdupAtoW(szProduct
);
1194 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1195 if (szVolumeLabel
) volume
= strdupAtoW(szVolumeLabel
);
1196 if (szDiskPrompt
) prompt
= strdupAtoW(szDiskPrompt
);
1198 r
= MsiSourceListAddMediaDiskW(product
, usersid
, dwContext
, dwOptions
,
1199 dwDiskId
, volume
, prompt
);
1209 /******************************************************************
1210 * MsiSourceListAddMediaDiskW (MSI.@)
1212 UINT WINAPI
MsiSourceListAddMediaDiskW(LPCWSTR szProduct
, LPCWSTR szUserSid
,
1213 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1214 LPCWSTR szVolumeLabel
, LPCWSTR szDiskPrompt
)
1220 WCHAR squished_pc
[GUID_SIZE
];
1224 static const WCHAR fmt
[] = {'%','i',0};
1225 static const WCHAR semicolon
[] = {';',0};
1227 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct
),
1228 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwDiskId
,
1229 debugstr_w(szVolumeLabel
), debugstr_w(szDiskPrompt
));
1231 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1232 return ERROR_INVALID_PARAMETER
;
1234 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
1235 return ERROR_INVALID_PARAMETER
;
1237 if ((szVolumeLabel
&& !*szVolumeLabel
) || (szDiskPrompt
&& !*szDiskPrompt
))
1238 return ERROR_INVALID_PARAMETER
;
1240 if ((dwContext
& MSIINSTALLCONTEXT_MACHINE
) && szUserSid
)
1241 return ERROR_INVALID_PARAMETER
;
1243 if (dwOptions
& MSICODE_PATCH
)
1245 FIXME("Unhandled options MSICODE_PATCH\n");
1246 return ERROR_FUNCTION_FAILED
;
1249 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1250 if (rc
!= ERROR_SUCCESS
)
1253 OpenMediaSubkey(sourcekey
, &mediakey
, TRUE
);
1255 sprintfW(szIndex
, fmt
, dwDiskId
);
1258 if (szVolumeLabel
) size
+= lstrlenW(szVolumeLabel
);
1259 if (szDiskPrompt
) size
+= lstrlenW(szDiskPrompt
);
1261 size
*= sizeof(WCHAR
);
1262 buffer
= msi_alloc(size
);
1265 if (szVolumeLabel
) lstrcpyW(buffer
, szVolumeLabel
);
1266 lstrcatW(buffer
, semicolon
);
1267 if (szDiskPrompt
) lstrcatW(buffer
, szDiskPrompt
);
1269 RegSetValueExW(mediakey
, szIndex
, 0, REG_SZ
, (LPBYTE
)buffer
, size
);
1272 RegCloseKey(sourcekey
);
1273 RegCloseKey(mediakey
);
1275 return ERROR_SUCCESS
;
1278 /******************************************************************
1279 * MsiSourceListClearAllA (MSI.@)
1281 UINT WINAPI
MsiSourceListClearAllA( LPCSTR szProduct
, LPCSTR szUserName
, DWORD dwReserved
)
1283 FIXME("(%s %s %d)\n", debugstr_a(szProduct
), debugstr_a(szUserName
), dwReserved
);
1284 return ERROR_SUCCESS
;
1287 /******************************************************************
1288 * MsiSourceListClearAllW (MSI.@)
1290 UINT WINAPI
MsiSourceListClearAllW( LPCWSTR szProduct
, LPCWSTR szUserName
, DWORD dwReserved
)
1292 FIXME("(%s %s %d)\n", debugstr_w(szProduct
), debugstr_w(szUserName
), dwReserved
);
1293 return ERROR_SUCCESS
;