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
;
310 size
= lstrlenW(ptr
);
311 if (size
>= *pcchDiskPrompt
)
313 else if (szDiskPrompt
)
314 lstrcpyW(szDiskPrompt
, ptr
);
316 *pcchDiskPrompt
= size
;
329 /******************************************************************
330 * MsiSourceListEnumSourcesA (MSI.@)
332 UINT WINAPI
MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch
, LPCSTR szUserSid
,
333 MSIINSTALLCONTEXT dwContext
,
334 DWORD dwOptions
, DWORD dwIndex
,
335 LPSTR szSource
, LPDWORD pcchSource
)
337 LPWSTR product
= NULL
;
338 LPWSTR usersid
= NULL
;
339 LPWSTR source
= NULL
;
341 UINT r
= ERROR_INVALID_PARAMETER
;
342 static int index
= 0;
344 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_a(szProductCodeOrPatch
),
345 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
350 if (szSource
&& !pcchSource
)
353 if (dwIndex
!= index
)
356 if (szProductCodeOrPatch
) product
= strdupAtoW(szProductCodeOrPatch
);
357 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
359 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
360 dwIndex
, NULL
, &len
);
361 if (r
!= ERROR_SUCCESS
)
364 source
= msi_alloc(++len
* sizeof(WCHAR
));
367 r
= ERROR_OUTOFMEMORY
;
372 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
373 dwIndex
, source
, &len
);
374 if (r
!= ERROR_SUCCESS
)
377 len
= WideCharToMultiByte(CP_ACP
, 0, source
, -1, NULL
, 0, NULL
, NULL
);
378 if (pcchSource
&& *pcchSource
>= len
)
379 WideCharToMultiByte(CP_ACP
, 0, source
, -1, szSource
, len
, NULL
, NULL
);
384 *pcchSource
= len
- 1;
391 if (r
== ERROR_SUCCESS
)
393 if (szSource
|| !pcchSource
) index
++;
395 else if (dwIndex
> index
)
401 /******************************************************************
402 * MsiSourceListEnumSourcesW (MSI.@)
404 UINT WINAPI
MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch
, LPCWSTR szUserSid
,
405 MSIINSTALLCONTEXT dwContext
,
406 DWORD dwOptions
, DWORD dwIndex
,
407 LPWSTR szSource
, LPDWORD pcchSource
)
409 WCHAR squished_pc
[GUID_SIZE
];
414 UINT r
= ERROR_INVALID_PARAMETER
;
415 static int index
= 0;
417 static const WCHAR format
[] = {'%','d',0};
419 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch
),
420 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
425 if (!szProductCodeOrPatch
|| !squash_guid(szProductCodeOrPatch
, squished_pc
))
428 if (szSource
&& !pcchSource
)
431 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
434 if ((dwOptions
& MSISOURCETYPE_NETWORK
) && (dwOptions
& MSISOURCETYPE_URL
))
437 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
440 if (dwIndex
!= index
)
443 r
= OpenSourceKey(szProductCodeOrPatch
, &source
,
444 dwOptions
, dwContext
, FALSE
);
445 if (r
!= ERROR_SUCCESS
)
448 if (dwOptions
& MSISOURCETYPE_NETWORK
)
449 r
= OpenNetworkSubkey(source
, &subkey
, FALSE
);
450 else if (dwOptions
& MSISOURCETYPE_URL
)
451 r
= OpenURLSubkey(source
, &subkey
, FALSE
);
453 if (r
!= ERROR_SUCCESS
)
455 r
= ERROR_NO_MORE_ITEMS
;
459 sprintfW(name
, format
, dwIndex
+ 1);
461 res
= RegQueryValueExW(subkey
, name
, 0, 0, (LPBYTE
)szSource
, pcchSource
);
462 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
463 r
= ERROR_NO_MORE_ITEMS
;
469 if (r
== ERROR_SUCCESS
)
471 if (szSource
|| !pcchSource
) index
++;
473 else if (dwIndex
> index
)
479 /******************************************************************
480 * MsiSourceListGetInfoA (MSI.@)
482 UINT WINAPI
MsiSourceListGetInfoA( LPCSTR szProduct
, LPCSTR szUserSid
,
483 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
484 LPCSTR szProperty
, LPSTR szValue
,
488 LPWSTR product
= NULL
;
489 LPWSTR usersid
= NULL
;
490 LPWSTR property
= NULL
;
494 if (szValue
&& !pcchValue
)
495 return ERROR_INVALID_PARAMETER
;
497 if (szProduct
) product
= strdupAtoW(szProduct
);
498 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
499 if (szProperty
) property
= strdupAtoW(szProperty
);
501 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
502 property
, NULL
, &len
);
503 if (ret
!= ERROR_SUCCESS
)
506 value
= msi_alloc(++len
* sizeof(WCHAR
));
508 return ERROR_OUTOFMEMORY
;
511 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
512 property
, value
, &len
);
513 if (ret
!= ERROR_SUCCESS
)
516 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
517 if (*pcchValue
>= len
)
518 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
520 ret
= ERROR_MORE_DATA
;
522 *pcchValue
= len
- 1;
532 /******************************************************************
533 * MsiSourceListGetInfoW (MSI.@)
535 UINT WINAPI
MsiSourceListGetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
536 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
537 LPCWSTR szProperty
, LPWSTR szValue
,
540 WCHAR squished_pc
[GUID_SIZE
];
541 HKEY sourcekey
, media
;
546 static const WCHAR mediapack
[] = {
547 'M','e','d','i','a','P','a','c','k','a','g','e',0};
549 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szProperty
));
551 if (!szProduct
|| !squash_guid(szProduct
, squished_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 if (dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
)
569 FIXME("Unhandled context %d\n", dwContext
);
571 rc
= OpenSourceKey(szProduct
, &sourcekey
, dwOptions
, dwContext
, FALSE
);
572 if (rc
!= ERROR_SUCCESS
)
575 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
576 !lstrcmpW(szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
578 rc
= OpenMediaSubkey(sourcekey
, &media
, FALSE
);
579 if (rc
!= ERROR_SUCCESS
)
581 RegCloseKey(sourcekey
);
582 return ERROR_SUCCESS
;
585 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
586 szProperty
= mediapack
;
588 RegQueryValueExW(media
, szProperty
, 0, 0, (LPBYTE
)szValue
, pcchValue
);
591 else if (!lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) ||
592 !lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
594 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
596 if (rc
!= ERROR_SUCCESS
)
598 RegCloseKey(sourcekey
);
599 return ERROR_SUCCESS
;
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 (!lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
615 if (*source
!= 'n' && *source
!= 'u' && *source
!= 'm')
618 RegCloseKey(sourcekey
);
619 return ERROR_SUCCESS
;
627 ptr
= strrchrW(source
, ';');
636 if (lstrlenW(ptr
) < *pcchValue
)
637 lstrcpyW(szValue
, ptr
);
639 rc
= ERROR_MORE_DATA
;
642 *pcchValue
= lstrlenW(ptr
);
645 else if (strcmpW(INSTALLPROPERTY_PACKAGENAMEW
, szProperty
)==0)
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
)
749 sprintfW(buffer
, format
, typechar
, index
, value
);
751 size
= (lstrlenW(buffer
) + 1) * sizeof(WCHAR
);
752 r
= RegSetValueExW(source
, INSTALLPROPERTY_LASTUSEDSOURCEW
, 0,
753 REG_SZ
, (LPBYTE
)buffer
, size
);
760 /******************************************************************
761 * MsiSourceListSetInfoW (MSI.@)
763 UINT WINAPI
MsiSourceListSetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
764 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
765 LPCWSTR szProperty
, LPCWSTR szValue
)
767 WCHAR squished_pc
[GUID_SIZE
];
768 HKEY sourcekey
, media
;
772 static const WCHAR media_package
[] = {
773 'M','e','d','i','a','P','a','c','k','a','g','e',0
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
, squished_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 (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
799 property
= media_package
;
801 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
802 if (rc
!= ERROR_SUCCESS
)
805 if (lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) &&
806 dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
))
808 RegCloseKey(sourcekey
);
809 return ERROR_INVALID_PARAMETER
;
812 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
813 !lstrcmpW(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(INSTALLPROPERTY_PACKAGENAMEW
, szProperty
)==0)
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 (!lstrcmpW(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 squished_pc
[GUID_SIZE
];
853 LPWSTR sidstr
= NULL
;
860 TRACE("%s %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserName
), debugstr_w(szSource
));
862 if (!szSource
|| !*szSource
)
863 return ERROR_INVALID_PARAMETER
;
866 return ERROR_INVALID_PARAMETER
;
868 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
869 return ERROR_INVALID_PARAMETER
;
871 if (!szUserName
|| !*szUserName
)
872 context
= MSIINSTALLCONTEXT_MACHINE
;
875 if (LookupAccountNameW(NULL
, szUserName
, NULL
, &sidsize
, NULL
, &domsize
, NULL
))
877 PSID psid
= msi_alloc(sidsize
);
879 if (LookupAccountNameW(NULL
, szUserName
, psid
, &sidsize
, NULL
, &domsize
, NULL
))
880 ConvertSidToStringSidW(psid
, &sidstr
);
885 r
= MSIREG_OpenLocalManagedProductKey(szProduct
, &hkey
, FALSE
);
886 if (r
== ERROR_SUCCESS
)
887 context
= MSIINSTALLCONTEXT_USERMANAGED
;
890 r
= MSIREG_OpenUserProductsKey(szProduct
, &hkey
, FALSE
);
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
,
1062 struct list sourcelist
;
1064 WCHAR squished_pc
[GUID_SIZE
];
1071 static const WCHAR fmt
[] = {'%','i',0};
1072 static const WCHAR one
[] = {'1',0};
1073 static const WCHAR backslash
[] = {'\\',0};
1074 static const WCHAR forwardslash
[] = {'/',0};
1076 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1077 dwContext
, dwOptions
, debugstr_w(szSource
), dwIndex
);
1079 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1080 return ERROR_INVALID_PARAMETER
;
1082 if (!szSource
|| !*szSource
)
1083 return ERROR_INVALID_PARAMETER
;
1085 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
1086 return ERROR_INVALID_PARAMETER
;
1088 if (dwOptions
& MSICODE_PATCH
)
1090 FIXME("Unhandled options MSICODE_PATCH\n");
1091 return ERROR_FUNCTION_FAILED
;
1094 if (szUserSid
&& (dwContext
& MSIINSTALLCONTEXT_MACHINE
))
1095 return ERROR_INVALID_PARAMETER
;
1097 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1098 if (rc
!= ERROR_SUCCESS
)
1101 if (dwOptions
& MSISOURCETYPE_NETWORK
)
1102 rc
= OpenNetworkSubkey(sourcekey
, &typekey
, TRUE
);
1103 else if (dwOptions
& MSISOURCETYPE_URL
)
1104 rc
= OpenURLSubkey(sourcekey
, &typekey
, TRUE
);
1105 else if (dwOptions
& MSISOURCETYPE_MEDIA
)
1106 rc
= OpenMediaSubkey(sourcekey
, &typekey
, TRUE
);
1109 ERR("unknown media type: %08x\n", dwOptions
);
1110 RegCloseKey(sourcekey
);
1111 return ERROR_FUNCTION_FAILED
;
1114 postfix
= (dwOptions
& MSISOURCETYPE_NETWORK
) ? backslash
: forwardslash
;
1115 if (szSource
[lstrlenW(szSource
) - 1] == *postfix
)
1116 source
= strdupW(szSource
);
1119 size
= lstrlenW(szSource
) + 2;
1120 source
= msi_alloc(size
* sizeof(WCHAR
));
1121 lstrcpyW(source
, szSource
);
1122 lstrcatW(source
, postfix
);
1125 list_init(&sourcelist
);
1126 rc
= fill_source_list(&sourcelist
, typekey
, &count
);
1127 if (rc
!= ERROR_NO_MORE_ITEMS
)
1130 size
= (lstrlenW(source
) + 1) * sizeof(WCHAR
);
1134 rc
= RegSetValueExW(typekey
, one
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1137 else if (dwIndex
> count
|| dwIndex
== 0)
1139 sprintfW(name
, fmt
, count
+ 1);
1140 rc
= RegSetValueExW(typekey
, name
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1145 sprintfW(name
, fmt
, dwIndex
);
1146 info
= msi_alloc(sizeof(media_info
));
1149 rc
= ERROR_OUTOFMEMORY
;
1153 info
->path
= strdupW(source
);
1154 lstrcpyW(info
->szIndex
, name
);
1155 info
->index
= dwIndex
;
1156 add_source_to_list(&sourcelist
, info
, &index
);
1158 LIST_FOR_EACH_ENTRY(info
, &sourcelist
, media_info
, entry
)
1160 if (info
->index
< index
)
1163 size
= (lstrlenW(info
->path
) + 1) * sizeof(WCHAR
);
1164 rc
= RegSetValueExW(typekey
, info
->szIndex
, 0,
1165 REG_EXPAND_SZ
, (LPBYTE
)info
->path
, size
);
1166 if (rc
!= ERROR_SUCCESS
)
1172 free_source_list(&sourcelist
);
1174 RegCloseKey(typekey
);
1175 RegCloseKey(sourcekey
);
1179 /******************************************************************
1180 * MsiSourceListAddMediaDiskA (MSI.@)
1182 UINT WINAPI
MsiSourceListAddMediaDiskA(LPCSTR szProduct
, LPCSTR szUserSid
,
1183 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1184 LPCSTR szVolumeLabel
, LPCSTR szDiskPrompt
)
1187 LPWSTR product
= NULL
;
1188 LPWSTR usersid
= NULL
;
1189 LPWSTR volume
= NULL
;
1190 LPWSTR prompt
= NULL
;
1192 if (szProduct
) product
= strdupAtoW(szProduct
);
1193 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1194 if (szVolumeLabel
) volume
= strdupAtoW(szVolumeLabel
);
1195 if (szDiskPrompt
) prompt
= strdupAtoW(szDiskPrompt
);
1197 r
= MsiSourceListAddMediaDiskW(product
, usersid
, dwContext
, dwOptions
,
1198 dwDiskId
, volume
, prompt
);
1208 /******************************************************************
1209 * MsiSourceListAddMediaDiskW (MSI.@)
1211 UINT WINAPI
MsiSourceListAddMediaDiskW(LPCWSTR szProduct
, LPCWSTR szUserSid
,
1212 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1213 LPCWSTR szVolumeLabel
, LPCWSTR szDiskPrompt
)
1219 WCHAR squished_pc
[GUID_SIZE
];
1223 static const WCHAR fmt
[] = {'%','i',0};
1224 static const WCHAR semicolon
[] = {';',0};
1226 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct
),
1227 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwDiskId
,
1228 debugstr_w(szVolumeLabel
), debugstr_w(szDiskPrompt
));
1230 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1231 return ERROR_INVALID_PARAMETER
;
1233 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
1234 return ERROR_INVALID_PARAMETER
;
1236 if ((szVolumeLabel
&& !*szVolumeLabel
) || (szDiskPrompt
&& !*szDiskPrompt
))
1237 return ERROR_INVALID_PARAMETER
;
1239 if ((dwContext
& MSIINSTALLCONTEXT_MACHINE
) && szUserSid
)
1240 return ERROR_INVALID_PARAMETER
;
1242 if (dwOptions
& MSICODE_PATCH
)
1244 FIXME("Unhandled options MSICODE_PATCH\n");
1245 return ERROR_FUNCTION_FAILED
;
1248 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1249 if (rc
!= ERROR_SUCCESS
)
1252 OpenMediaSubkey(sourcekey
, &mediakey
, TRUE
);
1254 sprintfW(szIndex
, fmt
, dwDiskId
);
1257 if (szVolumeLabel
) size
+= lstrlenW(szVolumeLabel
);
1258 if (szDiskPrompt
) size
+= lstrlenW(szDiskPrompt
);
1260 size
*= sizeof(WCHAR
);
1261 buffer
= msi_alloc(size
);
1264 if (szVolumeLabel
) lstrcpyW(buffer
, szVolumeLabel
);
1265 lstrcatW(buffer
, semicolon
);
1266 if (szDiskPrompt
) lstrcatW(buffer
, szDiskPrompt
);
1268 RegSetValueExW(mediakey
, szIndex
, 0, REG_SZ
, (LPBYTE
)buffer
, size
);
1271 RegCloseKey(sourcekey
);
1272 RegCloseKey(mediakey
);
1274 return ERROR_SUCCESS
;
1277 /******************************************************************
1278 * MsiSourceListClearAllA (MSI.@)
1280 UINT WINAPI
MsiSourceListClearAllA( LPCSTR szProduct
, LPCSTR szUserName
, DWORD dwReserved
)
1282 FIXME("(%s %s %d)\n", debugstr_a(szProduct
), debugstr_a(szUserName
), dwReserved
);
1283 return ERROR_SUCCESS
;
1286 /******************************************************************
1287 * MsiSourceListClearAllW (MSI.@)
1289 UINT WINAPI
MsiSourceListClearAllW( LPCWSTR szProduct
, LPCWSTR szUserName
, DWORD dwReserved
)
1291 FIXME("(%s %s %d)\n", debugstr_w(szProduct
), debugstr_w(szUserName
), dwReserved
);
1292 return ERROR_SUCCESS
;