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
;
61 if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
63 if (dwOptions
& MSICODE_PATCH
)
64 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
66 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
69 else if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
71 if (dwOptions
& MSICODE_PATCH
)
72 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
74 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
77 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
79 if (dwOptions
& MSICODE_PATCH
)
80 rc
= MSIREG_OpenPatchesKey(szProduct
, &rootkey
, create
);
82 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
86 if (rc
!= ERROR_SUCCESS
)
88 if (dwOptions
& MSICODE_PATCH
)
89 return ERROR_UNKNOWN_PATCH
;
91 return ERROR_UNKNOWN_PRODUCT
;
95 rc
= RegCreateKeyW(rootkey
, szSourceList
, key
);
98 rc
= RegOpenKeyW(rootkey
,szSourceList
, key
);
99 if (rc
!= ERROR_SUCCESS
)
100 rc
= ERROR_BAD_CONFIGURATION
;
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 WCHAR squished_pc
[GUID_SIZE
];
218 DWORD valuesz
, datasz
= 0;
223 static DWORD index
= 0;
225 static const WCHAR fmt
[] = {'#','%','d',0};
227 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p)\n", debugstr_w(szProductCodeOrPatchCode
),
228 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szVolumeLabel
,
229 pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
231 if (!szProductCodeOrPatchCode
||
232 !squash_guid(szProductCodeOrPatchCode
, squished_pc
))
233 return ERROR_INVALID_PARAMETER
;
235 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
236 return ERROR_INVALID_PARAMETER
;
238 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
239 return ERROR_INVALID_PARAMETER
;
241 if (szDiskPrompt
&& !pcchDiskPrompt
)
242 return ERROR_INVALID_PARAMETER
;
247 if (dwIndex
!= index
)
248 return ERROR_INVALID_PARAMETER
;
250 r
= OpenSourceKey(szProductCodeOrPatchCode
, &source
,
251 dwOptions
, dwContext
, FALSE
);
252 if (r
!= ERROR_SUCCESS
)
255 r
= OpenMediaSubkey(source
, &media
, FALSE
);
256 if (r
!= ERROR_SUCCESS
)
259 return ERROR_NO_MORE_ITEMS
;
262 if (!pcchVolumeLabel
&& !pcchDiskPrompt
)
264 r
= RegEnumValueW(media
, dwIndex
, NULL
, NULL
, NULL
,
269 res
= RegQueryInfoKeyW(media
, NULL
, NULL
, NULL
, NULL
, NULL
,
270 NULL
, &numvals
, &valuesz
, &datasz
, NULL
, NULL
);
271 if (res
!= ERROR_SUCCESS
)
273 r
= ERROR_BAD_CONFIGURATION
;
277 value
= msi_alloc(++valuesz
* sizeof(WCHAR
));
278 data
= msi_alloc(++datasz
* sizeof(WCHAR
));
281 r
= ERROR_OUTOFMEMORY
;
285 r
= RegEnumValueW(media
, dwIndex
, value
, &valuesz
,
286 NULL
, &type
, (LPBYTE
)data
, &datasz
);
287 if (r
!= ERROR_SUCCESS
)
291 *pdwDiskId
= atolW(value
);
294 ptr
= strchrW(data
, ';');
302 if (type
== REG_DWORD
)
304 sprintfW(convert
, fmt
, *data
);
305 size
= lstrlenW(convert
);
309 size
= lstrlenW(data
);
311 if (size
>= *pcchVolumeLabel
)
313 else if (szVolumeLabel
)
314 lstrcpyW(szVolumeLabel
, ptr2
);
316 *pcchVolumeLabel
= size
;
324 if (type
== REG_DWORD
)
326 sprintfW(convert
, fmt
, *ptr
);
327 size
= lstrlenW(convert
);
331 size
= lstrlenW(ptr
);
333 if (size
>= *pcchDiskPrompt
)
335 else if (szDiskPrompt
)
336 lstrcpyW(szDiskPrompt
, ptr
);
338 *pcchDiskPrompt
= size
;
351 /******************************************************************
352 * MsiSourceListEnumSourcesA (MSI.@)
354 UINT WINAPI
MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch
, LPCSTR szUserSid
,
355 MSIINSTALLCONTEXT dwContext
,
356 DWORD dwOptions
, DWORD dwIndex
,
357 LPSTR szSource
, LPDWORD pcchSource
)
359 LPWSTR product
= NULL
;
360 LPWSTR usersid
= NULL
;
361 LPWSTR source
= NULL
;
363 UINT r
= ERROR_INVALID_PARAMETER
;
364 static DWORD index
= 0;
366 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_a(szProductCodeOrPatch
),
367 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
372 if (szSource
&& !pcchSource
)
375 if (dwIndex
!= index
)
378 if (szProductCodeOrPatch
) product
= strdupAtoW(szProductCodeOrPatch
);
379 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
381 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
382 dwIndex
, NULL
, &len
);
383 if (r
!= ERROR_SUCCESS
)
386 source
= msi_alloc(++len
* sizeof(WCHAR
));
389 r
= ERROR_OUTOFMEMORY
;
394 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
395 dwIndex
, source
, &len
);
396 if (r
!= ERROR_SUCCESS
)
399 len
= WideCharToMultiByte(CP_ACP
, 0, source
, -1, NULL
, 0, NULL
, NULL
);
400 if (pcchSource
&& *pcchSource
>= len
)
401 WideCharToMultiByte(CP_ACP
, 0, source
, -1, szSource
, len
, NULL
, NULL
);
406 *pcchSource
= len
- 1;
413 if (r
== ERROR_SUCCESS
)
415 if (szSource
|| !pcchSource
) index
++;
417 else if (dwIndex
> index
)
423 /******************************************************************
424 * MsiSourceListEnumSourcesW (MSI.@)
426 UINT WINAPI
MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch
, LPCWSTR szUserSid
,
427 MSIINSTALLCONTEXT dwContext
,
428 DWORD dwOptions
, DWORD dwIndex
,
429 LPWSTR szSource
, LPDWORD pcchSource
)
431 WCHAR squished_pc
[GUID_SIZE
];
436 UINT r
= ERROR_INVALID_PARAMETER
;
437 static DWORD index
= 0;
439 static const WCHAR format
[] = {'%','d',0};
441 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch
),
442 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
447 if (!szProductCodeOrPatch
|| !squash_guid(szProductCodeOrPatch
, squished_pc
))
450 if (szSource
&& !pcchSource
)
453 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
456 if ((dwOptions
& MSISOURCETYPE_NETWORK
) && (dwOptions
& MSISOURCETYPE_URL
))
459 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
462 if (dwIndex
!= index
)
465 r
= OpenSourceKey(szProductCodeOrPatch
, &source
,
466 dwOptions
, dwContext
, FALSE
);
467 if (r
!= ERROR_SUCCESS
)
470 if (dwOptions
& MSISOURCETYPE_NETWORK
)
471 r
= OpenNetworkSubkey(source
, &subkey
, FALSE
);
472 else if (dwOptions
& MSISOURCETYPE_URL
)
473 r
= OpenURLSubkey(source
, &subkey
, FALSE
);
475 if (r
!= ERROR_SUCCESS
)
477 r
= ERROR_NO_MORE_ITEMS
;
481 sprintfW(name
, format
, dwIndex
+ 1);
483 res
= RegQueryValueExW(subkey
, name
, 0, 0, (LPBYTE
)szSource
, pcchSource
);
484 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
485 r
= ERROR_NO_MORE_ITEMS
;
491 if (r
== ERROR_SUCCESS
)
493 if (szSource
|| !pcchSource
) index
++;
495 else if (dwIndex
> index
)
501 /******************************************************************
502 * MsiSourceListGetInfoA (MSI.@)
504 UINT WINAPI
MsiSourceListGetInfoA( LPCSTR szProduct
, LPCSTR szUserSid
,
505 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
506 LPCSTR szProperty
, LPSTR szValue
,
510 LPWSTR product
= NULL
;
511 LPWSTR usersid
= NULL
;
512 LPWSTR property
= NULL
;
516 if (szValue
&& !pcchValue
)
517 return ERROR_INVALID_PARAMETER
;
519 if (szProduct
) product
= strdupAtoW(szProduct
);
520 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
521 if (szProperty
) property
= strdupAtoW(szProperty
);
523 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
524 property
, NULL
, &len
);
525 if (ret
!= ERROR_SUCCESS
)
528 value
= msi_alloc(++len
* sizeof(WCHAR
));
530 return ERROR_OUTOFMEMORY
;
533 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
534 property
, value
, &len
);
535 if (ret
!= ERROR_SUCCESS
)
538 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
539 if (*pcchValue
>= len
)
540 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
542 ret
= ERROR_MORE_DATA
;
544 *pcchValue
= len
- 1;
554 /******************************************************************
555 * MsiSourceListGetInfoW (MSI.@)
557 UINT WINAPI
MsiSourceListGetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
558 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
559 LPCWSTR szProperty
, LPWSTR szValue
,
562 WCHAR squished_pc
[GUID_SIZE
];
563 HKEY sourcekey
, media
;
568 static const WCHAR mediapack
[] = {
569 'M','e','d','i','a','P','a','c','k','a','g','e',0};
571 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szProperty
));
573 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
574 return ERROR_INVALID_PARAMETER
;
576 if (szValue
&& !pcchValue
)
577 return ERROR_INVALID_PARAMETER
;
579 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
580 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
581 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
582 return ERROR_INVALID_PARAMETER
;
585 return ERROR_INVALID_PARAMETER
;
588 FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid
));
590 rc
= OpenSourceKey(szProduct
, &sourcekey
, dwOptions
, dwContext
, FALSE
);
591 if (rc
!= ERROR_SUCCESS
)
594 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
595 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
597 rc
= OpenMediaSubkey(sourcekey
, &media
, FALSE
);
598 if (rc
!= ERROR_SUCCESS
)
600 RegCloseKey(sourcekey
);
601 return ERROR_SUCCESS
;
604 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
605 szProperty
= mediapack
;
607 RegQueryValueExW(media
, szProperty
, 0, 0, (LPBYTE
)szValue
, pcchValue
);
610 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) ||
611 !strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
613 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
615 if (rc
!= ERROR_SUCCESS
)
617 RegCloseKey(sourcekey
);
618 return ERROR_SUCCESS
;
621 source
= msi_alloc(size
);
622 RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
623 0, 0, (LPBYTE
)source
, &size
);
628 RegCloseKey(sourcekey
);
629 return ERROR_SUCCESS
;
632 if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
634 if (*source
!= 'n' && *source
!= 'u' && *source
!= 'm')
637 RegCloseKey(sourcekey
);
638 return ERROR_SUCCESS
;
646 ptr
= strrchrW(source
, ';');
655 if (strlenW(ptr
) < *pcchValue
)
656 lstrcpyW(szValue
, ptr
);
658 rc
= ERROR_MORE_DATA
;
661 *pcchValue
= lstrlenW(ptr
);
664 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
666 *pcchValue
= *pcchValue
* sizeof(WCHAR
);
667 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0, 0,
668 (LPBYTE
)szValue
, pcchValue
);
669 if (rc
!= ERROR_SUCCESS
&& rc
!= ERROR_MORE_DATA
)
677 *pcchValue
= (*pcchValue
- 1) / sizeof(WCHAR
);
679 szValue
[*pcchValue
] = '\0';
684 FIXME("Unknown property %s\n",debugstr_w(szProperty
));
685 rc
= ERROR_UNKNOWN_PROPERTY
;
688 RegCloseKey(sourcekey
);
692 /******************************************************************
693 * MsiSourceListSetInfoA (MSI.@)
695 UINT WINAPI
MsiSourceListSetInfoA(LPCSTR szProduct
, LPCSTR szUserSid
,
696 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
697 LPCSTR szProperty
, LPCSTR szValue
)
700 LPWSTR product
= NULL
;
701 LPWSTR usersid
= NULL
;
702 LPWSTR property
= NULL
;
705 if (szProduct
) product
= strdupAtoW(szProduct
);
706 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
707 if (szProperty
) property
= strdupAtoW(szProperty
);
708 if (szValue
) value
= strdupAtoW(szValue
);
710 ret
= MsiSourceListSetInfoW(product
, usersid
, dwContext
, dwOptions
,
721 UINT
msi_set_last_used_source(LPCWSTR product
, LPCWSTR usersid
,
722 MSIINSTALLCONTEXT context
, DWORD options
,
732 static const WCHAR format
[] = {'%','c',';','%','i',';','%','s',0};
734 if (options
& MSISOURCETYPE_NETWORK
)
736 else if (options
& MSISOURCETYPE_URL
)
738 else if (options
& MSISOURCETYPE_MEDIA
)
741 return ERROR_INVALID_PARAMETER
;
743 if (!(options
& MSISOURCETYPE_MEDIA
))
745 r
= MsiSourceListAddSourceExW(product
, usersid
, context
,
747 if (r
!= ERROR_SUCCESS
)
751 while ((r
= MsiSourceListEnumSourcesW(product
, usersid
, context
, options
,
752 index
, NULL
, NULL
)) == ERROR_SUCCESS
)
755 if (r
!= ERROR_NO_MORE_ITEMS
)
759 size
= (lstrlenW(format
) + lstrlenW(value
) + 7) * sizeof(WCHAR
);
760 buffer
= msi_alloc(size
);
762 return ERROR_OUTOFMEMORY
;
764 r
= OpenSourceKey(product
, &source
, MSICODE_PRODUCT
, context
, FALSE
);
765 if (r
!= ERROR_SUCCESS
)
771 sprintfW(buffer
, format
, typechar
, index
, value
);
773 size
= (lstrlenW(buffer
) + 1) * sizeof(WCHAR
);
774 r
= RegSetValueExW(source
, INSTALLPROPERTY_LASTUSEDSOURCEW
, 0,
775 REG_SZ
, (LPBYTE
)buffer
, size
);
782 /******************************************************************
783 * MsiSourceListSetInfoW (MSI.@)
785 UINT WINAPI
MsiSourceListSetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
786 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
787 LPCWSTR szProperty
, LPCWSTR szValue
)
789 WCHAR squished_pc
[GUID_SIZE
];
790 HKEY sourcekey
, media
;
794 static const WCHAR media_package
[] = {
795 'M','e','d','i','a','P','a','c','k','a','g','e',0
798 TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
799 dwContext
, dwOptions
, debugstr_w(szProperty
), debugstr_w(szValue
));
801 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
802 return ERROR_INVALID_PARAMETER
;
805 return ERROR_INVALID_PARAMETER
;
808 return ERROR_UNKNOWN_PROPERTY
;
810 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
811 return ERROR_INVALID_PARAMETER
;
813 if (dwOptions
& MSICODE_PATCH
)
815 FIXME("Unhandled options MSICODE_PATCH\n");
816 return ERROR_UNKNOWN_PATCH
;
819 property
= szProperty
;
820 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
821 property
= media_package
;
823 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
824 if (rc
!= ERROR_SUCCESS
)
827 if (strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) &&
828 dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
))
830 RegCloseKey(sourcekey
);
831 return ERROR_INVALID_PARAMETER
;
834 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
835 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
837 rc
= OpenMediaSubkey(sourcekey
, &media
, TRUE
);
838 if (rc
== ERROR_SUCCESS
)
840 rc
= msi_reg_set_val_str(media
, property
, szValue
);
844 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
846 DWORD size
= (lstrlenW(szValue
) + 1) * sizeof(WCHAR
);
847 rc
= RegSetValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0,
848 REG_SZ
, (const BYTE
*)szValue
, size
);
849 if (rc
!= ERROR_SUCCESS
)
850 rc
= ERROR_UNKNOWN_PROPERTY
;
852 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
854 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
855 rc
= ERROR_INVALID_PARAMETER
;
857 rc
= msi_set_last_used_source(szProduct
, szUserSid
, dwContext
,
861 rc
= ERROR_UNKNOWN_PROPERTY
;
863 RegCloseKey(sourcekey
);
867 /******************************************************************
868 * MsiSourceListAddSourceW (MSI.@)
870 UINT WINAPI
MsiSourceListAddSourceW( LPCWSTR szProduct
, LPCWSTR szUserName
,
871 DWORD dwReserved
, LPCWSTR szSource
)
873 WCHAR squished_pc
[GUID_SIZE
];
875 LPWSTR sidstr
= NULL
;
882 TRACE("%s %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserName
), debugstr_w(szSource
));
884 if (!szSource
|| !*szSource
)
885 return ERROR_INVALID_PARAMETER
;
888 return ERROR_INVALID_PARAMETER
;
890 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
891 return ERROR_INVALID_PARAMETER
;
893 if (!szUserName
|| !*szUserName
)
894 context
= MSIINSTALLCONTEXT_MACHINE
;
897 if (LookupAccountNameW(NULL
, szUserName
, NULL
, &sidsize
, NULL
, &domsize
, NULL
))
899 PSID psid
= msi_alloc(sidsize
);
901 if (LookupAccountNameW(NULL
, szUserName
, psid
, &sidsize
, NULL
, &domsize
, NULL
))
902 ConvertSidToStringSidW(psid
, &sidstr
);
907 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
908 MSIINSTALLCONTEXT_USERMANAGED
, &hkey
, FALSE
);
909 if (r
== ERROR_SUCCESS
)
910 context
= MSIINSTALLCONTEXT_USERMANAGED
;
913 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
914 MSIINSTALLCONTEXT_USERUNMANAGED
,
916 if (r
!= ERROR_SUCCESS
)
917 return ERROR_UNKNOWN_PRODUCT
;
919 context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
925 ret
= MsiSourceListAddSourceExW(szProduct
, sidstr
,
926 context
, MSISOURCETYPE_NETWORK
, szSource
, 0);
934 /******************************************************************
935 * MsiSourceListAddSourceA (MSI.@)
937 UINT WINAPI
MsiSourceListAddSourceA( LPCSTR szProduct
, LPCSTR szUserName
,
938 DWORD dwReserved
, LPCSTR szSource
)
945 szwproduct
= strdupAtoW( szProduct
);
946 szwusername
= strdupAtoW( szUserName
);
947 szwsource
= strdupAtoW( szSource
);
949 ret
= MsiSourceListAddSourceW(szwproduct
, szwusername
, dwReserved
, szwsource
);
951 msi_free(szwproduct
);
952 msi_free(szwusername
);
958 /******************************************************************
959 * MsiSourceListAddSourceExA (MSI.@)
961 UINT WINAPI
MsiSourceListAddSourceExA(LPCSTR szProduct
, LPCSTR szUserSid
,
962 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCSTR szSource
, DWORD dwIndex
)
965 LPWSTR product
, usersid
, source
;
967 product
= strdupAtoW(szProduct
);
968 usersid
= strdupAtoW(szUserSid
);
969 source
= strdupAtoW(szSource
);
971 ret
= MsiSourceListAddSourceExW(product
, usersid
, dwContext
,
972 dwOptions
, source
, dwIndex
);
981 static void free_source_list(struct list
*sourcelist
)
983 while (!list_empty(sourcelist
))
985 media_info
*info
= LIST_ENTRY(list_head(sourcelist
), media_info
, entry
);
986 list_remove(&info
->entry
);
987 msi_free(info
->path
);
992 static void add_source_to_list(struct list
*sourcelist
, media_info
*info
,
997 static const WCHAR fmt
[] = {'%','i',0};
999 if (index
) *index
= 0;
1001 if (list_empty(sourcelist
))
1003 list_add_head(sourcelist
, &info
->entry
);
1007 LIST_FOR_EACH_ENTRY(iter
, sourcelist
, media_info
, entry
)
1009 if (!found
&& info
->index
< iter
->index
)
1012 list_add_before(&iter
->entry
, &info
->entry
);
1015 /* update the rest of the list */
1017 sprintfW(iter
->szIndex
, fmt
, ++iter
->index
);
1023 list_add_after(&iter
->entry
, &info
->entry
);
1026 static UINT
fill_source_list(struct list
*sourcelist
, HKEY sourcekey
, DWORD
*count
)
1028 UINT r
= ERROR_SUCCESS
;
1031 DWORD size
, val_size
;
1036 while (r
== ERROR_SUCCESS
)
1038 size
= sizeof(name
) / sizeof(name
[0]);
1039 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
, NULL
, NULL
, &val_size
);
1040 if (r
!= ERROR_SUCCESS
)
1043 entry
= msi_alloc(sizeof(media_info
));
1047 entry
->path
= msi_alloc(val_size
);
1054 lstrcpyW(entry
->szIndex
, name
);
1055 entry
->index
= atoiW(name
);
1058 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
,
1059 NULL
, (LPBYTE
)entry
->path
, &val_size
);
1060 if (r
!= ERROR_SUCCESS
)
1062 msi_free(entry
->path
);
1068 add_source_to_list(sourcelist
, entry
, NULL
);
1073 free_source_list(sourcelist
);
1074 return ERROR_OUTOFMEMORY
;
1077 /******************************************************************
1078 * MsiSourceListAddSourceExW (MSI.@)
1080 UINT WINAPI
MsiSourceListAddSourceExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1081 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCWSTR szSource
,
1087 struct list sourcelist
;
1089 WCHAR squished_pc
[GUID_SIZE
];
1096 static const WCHAR fmt
[] = {'%','i',0};
1098 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1099 dwContext
, dwOptions
, debugstr_w(szSource
), dwIndex
);
1101 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1102 return ERROR_INVALID_PARAMETER
;
1104 if (!szSource
|| !*szSource
)
1105 return ERROR_INVALID_PARAMETER
;
1107 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
1108 return ERROR_INVALID_PARAMETER
;
1110 if (dwOptions
& MSICODE_PATCH
)
1112 FIXME("Unhandled options MSICODE_PATCH\n");
1113 return ERROR_FUNCTION_FAILED
;
1116 if (szUserSid
&& (dwContext
& MSIINSTALLCONTEXT_MACHINE
))
1117 return ERROR_INVALID_PARAMETER
;
1119 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1120 if (rc
!= ERROR_SUCCESS
)
1123 if (dwOptions
& MSISOURCETYPE_NETWORK
)
1124 rc
= OpenNetworkSubkey(sourcekey
, &typekey
, TRUE
);
1125 else if (dwOptions
& MSISOURCETYPE_URL
)
1126 rc
= OpenURLSubkey(sourcekey
, &typekey
, TRUE
);
1127 else if (dwOptions
& MSISOURCETYPE_MEDIA
)
1128 rc
= OpenMediaSubkey(sourcekey
, &typekey
, TRUE
);
1131 ERR("unknown media type: %08x\n", dwOptions
);
1132 RegCloseKey(sourcekey
);
1133 return ERROR_FUNCTION_FAILED
;
1135 if (rc
!= ERROR_SUCCESS
)
1137 ERR("can't open subkey %u\n", rc
);
1138 RegCloseKey(sourcekey
);
1142 postfix
= (dwOptions
& MSISOURCETYPE_NETWORK
) ? szBackSlash
: szForwardSlash
;
1143 if (szSource
[lstrlenW(szSource
) - 1] == *postfix
)
1144 source
= strdupW(szSource
);
1147 size
= lstrlenW(szSource
) + 2;
1148 source
= msi_alloc(size
* sizeof(WCHAR
));
1149 lstrcpyW(source
, szSource
);
1150 lstrcatW(source
, postfix
);
1153 list_init(&sourcelist
);
1154 rc
= fill_source_list(&sourcelist
, typekey
, &count
);
1155 if (rc
!= ERROR_NO_MORE_ITEMS
)
1158 size
= (lstrlenW(source
) + 1) * sizeof(WCHAR
);
1162 rc
= RegSetValueExW(typekey
, szOne
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1165 else if (dwIndex
> count
|| dwIndex
== 0)
1167 sprintfW(name
, fmt
, count
+ 1);
1168 rc
= RegSetValueExW(typekey
, name
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1173 sprintfW(name
, fmt
, dwIndex
);
1174 info
= msi_alloc(sizeof(media_info
));
1177 rc
= ERROR_OUTOFMEMORY
;
1181 info
->path
= strdupW(source
);
1182 lstrcpyW(info
->szIndex
, name
);
1183 info
->index
= dwIndex
;
1184 add_source_to_list(&sourcelist
, info
, &index
);
1186 LIST_FOR_EACH_ENTRY(info
, &sourcelist
, media_info
, entry
)
1188 if (info
->index
< index
)
1191 size
= (lstrlenW(info
->path
) + 1) * sizeof(WCHAR
);
1192 rc
= RegSetValueExW(typekey
, info
->szIndex
, 0,
1193 REG_EXPAND_SZ
, (LPBYTE
)info
->path
, size
);
1194 if (rc
!= ERROR_SUCCESS
)
1200 free_source_list(&sourcelist
);
1202 RegCloseKey(typekey
);
1203 RegCloseKey(sourcekey
);
1207 /******************************************************************
1208 * MsiSourceListAddMediaDiskA (MSI.@)
1210 UINT WINAPI
MsiSourceListAddMediaDiskA(LPCSTR szProduct
, LPCSTR szUserSid
,
1211 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1212 LPCSTR szVolumeLabel
, LPCSTR szDiskPrompt
)
1215 LPWSTR product
= NULL
;
1216 LPWSTR usersid
= NULL
;
1217 LPWSTR volume
= NULL
;
1218 LPWSTR prompt
= NULL
;
1220 if (szProduct
) product
= strdupAtoW(szProduct
);
1221 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1222 if (szVolumeLabel
) volume
= strdupAtoW(szVolumeLabel
);
1223 if (szDiskPrompt
) prompt
= strdupAtoW(szDiskPrompt
);
1225 r
= MsiSourceListAddMediaDiskW(product
, usersid
, dwContext
, dwOptions
,
1226 dwDiskId
, volume
, prompt
);
1236 /******************************************************************
1237 * MsiSourceListAddMediaDiskW (MSI.@)
1239 UINT WINAPI
MsiSourceListAddMediaDiskW(LPCWSTR szProduct
, LPCWSTR szUserSid
,
1240 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1241 LPCWSTR szVolumeLabel
, LPCWSTR szDiskPrompt
)
1247 WCHAR squished_pc
[GUID_SIZE
];
1251 static const WCHAR fmt
[] = {'%','i',0};
1253 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct
),
1254 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwDiskId
,
1255 debugstr_w(szVolumeLabel
), debugstr_w(szDiskPrompt
));
1257 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1258 return ERROR_INVALID_PARAMETER
;
1260 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
1261 return ERROR_INVALID_PARAMETER
;
1263 if ((szVolumeLabel
&& !*szVolumeLabel
) || (szDiskPrompt
&& !*szDiskPrompt
))
1264 return ERROR_INVALID_PARAMETER
;
1266 if ((dwContext
& MSIINSTALLCONTEXT_MACHINE
) && szUserSid
)
1267 return ERROR_INVALID_PARAMETER
;
1269 if (dwOptions
& MSICODE_PATCH
)
1271 FIXME("Unhandled options MSICODE_PATCH\n");
1272 return ERROR_FUNCTION_FAILED
;
1275 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1276 if (rc
!= ERROR_SUCCESS
)
1279 OpenMediaSubkey(sourcekey
, &mediakey
, TRUE
);
1281 sprintfW(szIndex
, fmt
, dwDiskId
);
1284 if (szVolumeLabel
) size
+= lstrlenW(szVolumeLabel
);
1285 if (szDiskPrompt
) size
+= lstrlenW(szDiskPrompt
);
1287 size
*= sizeof(WCHAR
);
1288 buffer
= msi_alloc(size
);
1291 if (szVolumeLabel
) lstrcpyW(buffer
, szVolumeLabel
);
1292 lstrcatW(buffer
, szSemiColon
);
1293 if (szDiskPrompt
) lstrcatW(buffer
, szDiskPrompt
);
1295 RegSetValueExW(mediakey
, szIndex
, 0, REG_SZ
, (LPBYTE
)buffer
, size
);
1298 RegCloseKey(sourcekey
);
1299 RegCloseKey(mediakey
);
1301 return ERROR_SUCCESS
;
1304 /******************************************************************
1305 * MsiSourceListClearAllA (MSI.@)
1307 UINT WINAPI
MsiSourceListClearAllA( LPCSTR szProduct
, LPCSTR szUserName
, DWORD dwReserved
)
1309 FIXME("(%s %s %d)\n", debugstr_a(szProduct
), debugstr_a(szUserName
), dwReserved
);
1310 return ERROR_SUCCESS
;
1313 /******************************************************************
1314 * MsiSourceListClearAllW (MSI.@)
1316 UINT WINAPI
MsiSourceListClearAllW( LPCWSTR szProduct
, LPCWSTR szUserName
, DWORD dwReserved
)
1318 FIXME("(%s %s %d)\n", debugstr_w(szProduct
), debugstr_w(szUserName
), dwReserved
);
1319 return ERROR_SUCCESS
;
1322 /******************************************************************
1323 * MsiSourceListClearAllExA (MSI.@)
1325 UINT WINAPI
MsiSourceListClearAllExA( LPCSTR szProduct
, LPCSTR szUserSid
,
1326 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1328 FIXME("(%s %s %d %08x)\n", debugstr_a(szProduct
), debugstr_a(szUserSid
),
1329 dwContext
, dwOptions
);
1330 return ERROR_SUCCESS
;
1333 /******************************************************************
1334 * MsiSourceListClearAllExW (MSI.@)
1336 UINT WINAPI
MsiSourceListClearAllExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1337 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1339 FIXME("(%s %s %d %08x)\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1340 dwContext
, dwOptions
);
1341 return ERROR_SUCCESS
;
1344 /******************************************************************
1345 * MsiSourceListClearSourceA (MSI.@)
1347 UINT WINAPI
MsiSourceListClearSourceA(LPCSTR szProductCodeOrPatchCode
, LPCSTR szUserSid
,
1348 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1351 FIXME("(%s %s %x %x %s)\n", debugstr_a(szProductCodeOrPatchCode
), debugstr_a(szUserSid
),
1352 dwContext
, dwOptions
, debugstr_a(szSource
));
1353 return ERROR_SUCCESS
;
1356 /******************************************************************
1357 * MsiSourceListClearSourceW (MSI.@)
1359 UINT WINAPI
MsiSourceListClearSourceW(LPCWSTR szProductCodeOrPatchCode
, LPCWSTR szUserSid
,
1360 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1363 FIXME("(%s %s %x %x %s)\n", debugstr_w(szProductCodeOrPatchCode
), debugstr_w(szUserSid
),
1364 dwContext
, dwOptions
, debugstr_w(szSource
));
1365 return ERROR_SUCCESS
;