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"
39 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
42 * These apis are defined in MSI 3.0
45 typedef struct tagMediaInfo
53 static UINT
OpenSourceKey(LPCWSTR szProduct
, HKEY
* key
, DWORD dwOptions
,
54 MSIINSTALLCONTEXT context
, BOOL create
)
57 UINT rc
= ERROR_FUNCTION_FAILED
;
59 if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
61 if (dwOptions
& MSICODE_PATCH
)
62 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
64 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
67 else if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
69 if (dwOptions
& MSICODE_PATCH
)
70 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
72 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
75 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
77 if (dwOptions
& MSICODE_PATCH
)
78 rc
= MSIREG_OpenPatchesKey(szProduct
, &rootkey
, create
);
80 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
84 if (rc
!= ERROR_SUCCESS
)
86 if (dwOptions
& MSICODE_PATCH
)
87 return ERROR_UNKNOWN_PATCH
;
89 return ERROR_UNKNOWN_PRODUCT
;
93 rc
= RegCreateKeyW(rootkey
, L
"SourceList", key
);
96 rc
= RegOpenKeyW(rootkey
, L
"SourceList", key
);
97 if (rc
!= ERROR_SUCCESS
)
98 rc
= ERROR_BAD_CONFIGURATION
;
100 RegCloseKey(rootkey
);
105 static UINT
OpenMediaSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
110 rc
= RegCreateKeyW(rootkey
, L
"Media", key
);
112 rc
= RegOpenKeyW(rootkey
, L
"Media", key
);
117 static UINT
OpenNetworkSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
122 rc
= RegCreateKeyW(rootkey
, L
"Net", key
);
124 rc
= RegOpenKeyW(rootkey
, L
"Net", key
);
129 static UINT
OpenURLSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
134 rc
= RegCreateKeyW(rootkey
, L
"URL", key
);
136 rc
= RegOpenKeyW(rootkey
, L
"URL", key
);
141 /******************************************************************
142 * MsiSourceListEnumMediaDisksA (MSI.@)
144 UINT WINAPI
MsiSourceListEnumMediaDisksA(LPCSTR szProductCodeOrPatchCode
,
145 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
146 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
147 LPSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
148 LPSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
150 LPWSTR product
= NULL
;
151 LPWSTR usersid
= NULL
;
152 LPWSTR volume
= NULL
;
153 LPWSTR prompt
= NULL
;
154 UINT r
= ERROR_INVALID_PARAMETER
;
156 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n", debugstr_a(szProductCodeOrPatchCode
),
157 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, pdwDiskId
,
158 szVolumeLabel
, pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
160 if (szDiskPrompt
&& !pcchDiskPrompt
)
161 return ERROR_INVALID_PARAMETER
;
163 if (szProductCodeOrPatchCode
) product
= strdupAtoW(szProductCodeOrPatchCode
);
164 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
166 /* FIXME: add tests for an invalid format */
169 volume
= msi_alloc(*pcchVolumeLabel
* sizeof(WCHAR
));
172 prompt
= msi_alloc(*pcchDiskPrompt
* sizeof(WCHAR
));
174 if (volume
) *volume
= '\0';
175 if (prompt
) *prompt
= '\0';
176 r
= MsiSourceListEnumMediaDisksW(product
, usersid
, dwContext
, dwOptions
,
177 dwIndex
, pdwDiskId
, volume
, pcchVolumeLabel
,
178 prompt
, pcchDiskPrompt
);
179 if (r
!= ERROR_SUCCESS
)
182 if (szVolumeLabel
&& pcchVolumeLabel
)
183 WideCharToMultiByte(CP_ACP
, 0, volume
, -1, szVolumeLabel
,
184 *pcchVolumeLabel
+ 1, NULL
, NULL
);
187 WideCharToMultiByte(CP_ACP
, 0, prompt
, -1, szDiskPrompt
,
188 *pcchDiskPrompt
+ 1, NULL
, NULL
);
199 /******************************************************************
200 * MsiSourceListEnumMediaDisksW (MSI.@)
202 UINT WINAPI
MsiSourceListEnumMediaDisksW(LPCWSTR szProductCodeOrPatchCode
,
203 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
204 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
205 LPWSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
206 LPWSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
208 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
], convert
[11];
209 WCHAR
*value
= NULL
, *data
= NULL
, *ptr
, *ptr2
;
211 DWORD valuesz
, datasz
= 0, type
, numvals
, size
;
214 static DWORD index
= 0;
216 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p)\n", debugstr_w(szProductCodeOrPatchCode
),
217 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szVolumeLabel
,
218 pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
220 if (!szProductCodeOrPatchCode
|| !squash_guid( szProductCodeOrPatchCode
, squashed_pc
))
221 return ERROR_INVALID_PARAMETER
;
223 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
224 return ERROR_INVALID_PARAMETER
;
226 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
227 return ERROR_INVALID_PARAMETER
;
229 if (szDiskPrompt
&& !pcchDiskPrompt
)
230 return ERROR_INVALID_PARAMETER
;
235 if (dwIndex
!= index
)
236 return ERROR_INVALID_PARAMETER
;
238 r
= OpenSourceKey(szProductCodeOrPatchCode
, &source
, dwOptions
, dwContext
, FALSE
);
239 if (r
!= ERROR_SUCCESS
)
242 r
= OpenMediaSubkey(source
, &media
, FALSE
);
243 if (r
!= ERROR_SUCCESS
)
246 return ERROR_NO_MORE_ITEMS
;
249 res
= RegQueryInfoKeyW(media
, NULL
, NULL
, NULL
, NULL
, NULL
,
250 NULL
, &numvals
, &valuesz
, &datasz
, NULL
, NULL
);
251 if (res
!= ERROR_SUCCESS
)
253 r
= ERROR_BAD_CONFIGURATION
;
257 value
= msi_alloc(++valuesz
* sizeof(WCHAR
));
258 data
= msi_alloc(++datasz
* sizeof(WCHAR
));
261 r
= ERROR_OUTOFMEMORY
;
265 r
= RegEnumValueW(media
, dwIndex
, value
, &valuesz
,
266 NULL
, &type
, (LPBYTE
)data
, &datasz
);
267 if (r
!= ERROR_SUCCESS
)
271 *pdwDiskId
= wcstol(value
, NULL
, 10);
274 ptr
= wcschr(data
, ';');
282 if (type
== REG_DWORD
)
284 swprintf(convert
, ARRAY_SIZE(convert
), L
"#%d", *data
);
285 size
= lstrlenW(convert
);
289 size
= lstrlenW(data
);
291 if (size
>= *pcchVolumeLabel
)
293 else if (szVolumeLabel
)
294 lstrcpyW(szVolumeLabel
, ptr2
);
296 *pcchVolumeLabel
= size
;
304 if (type
== REG_DWORD
)
306 swprintf(convert
, ARRAY_SIZE(convert
), L
"#%d", *ptr
);
307 size
= lstrlenW(convert
);
311 size
= lstrlenW(ptr
);
313 if (size
>= *pcchDiskPrompt
)
315 else if (szDiskPrompt
)
316 lstrcpyW(szDiskPrompt
, ptr
);
318 *pcchDiskPrompt
= size
;
331 /******************************************************************
332 * MsiSourceListEnumSourcesA (MSI.@)
334 UINT WINAPI
MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch
, LPCSTR szUserSid
,
335 MSIINSTALLCONTEXT dwContext
,
336 DWORD dwOptions
, DWORD dwIndex
,
337 LPSTR szSource
, LPDWORD pcchSource
)
339 LPWSTR product
= NULL
;
340 LPWSTR usersid
= NULL
;
341 LPWSTR source
= NULL
;
343 UINT r
= ERROR_INVALID_PARAMETER
;
344 static DWORD index
= 0;
346 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_a(szProductCodeOrPatch
),
347 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
352 if (szSource
&& !pcchSource
)
355 if (dwIndex
!= index
)
358 if (szProductCodeOrPatch
) product
= strdupAtoW(szProductCodeOrPatch
);
359 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
361 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
362 dwIndex
, NULL
, &len
);
363 if (r
!= ERROR_SUCCESS
)
366 source
= msi_alloc(++len
* sizeof(WCHAR
));
369 r
= ERROR_OUTOFMEMORY
;
374 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
375 dwIndex
, source
, &len
);
376 if (r
!= ERROR_SUCCESS
)
379 len
= WideCharToMultiByte(CP_ACP
, 0, source
, -1, NULL
, 0, NULL
, NULL
);
380 if (pcchSource
&& *pcchSource
>= len
)
381 WideCharToMultiByte(CP_ACP
, 0, source
, -1, szSource
, len
, NULL
, NULL
);
386 *pcchSource
= len
- 1;
393 if (r
== ERROR_SUCCESS
)
395 if (szSource
|| !pcchSource
) index
++;
397 else if (dwIndex
> index
)
403 /******************************************************************
404 * MsiSourceListEnumSourcesW (MSI.@)
406 UINT WINAPI
MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch
, LPCWSTR szUserSid
,
407 MSIINSTALLCONTEXT dwContext
,
408 DWORD dwOptions
, DWORD dwIndex
,
409 LPWSTR szSource
, LPDWORD pcchSource
)
411 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
], name
[32];
412 HKEY source
= NULL
, subkey
= NULL
;
414 UINT r
= ERROR_INVALID_PARAMETER
;
415 static DWORD index
= 0;
417 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch
),
418 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
423 if (!szProductCodeOrPatch
|| !squash_guid( szProductCodeOrPatch
, squashed_pc
))
426 if (szSource
&& !pcchSource
)
429 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
432 if ((dwOptions
& MSISOURCETYPE_NETWORK
) && (dwOptions
& MSISOURCETYPE_URL
))
435 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
438 if (dwIndex
!= index
)
441 r
= OpenSourceKey( szProductCodeOrPatch
, &source
, dwOptions
, dwContext
, FALSE
);
442 if (r
!= ERROR_SUCCESS
)
445 if (dwOptions
& MSISOURCETYPE_NETWORK
)
446 r
= OpenNetworkSubkey(source
, &subkey
, FALSE
);
447 else if (dwOptions
& MSISOURCETYPE_URL
)
448 r
= OpenURLSubkey(source
, &subkey
, FALSE
);
450 if (r
!= ERROR_SUCCESS
)
452 r
= ERROR_NO_MORE_ITEMS
;
456 swprintf(name
, ARRAY_SIZE(name
), L
"%d", dwIndex
+ 1);
458 res
= RegQueryValueExW(subkey
, name
, 0, 0, (LPBYTE
)szSource
, pcchSource
);
459 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
460 r
= ERROR_NO_MORE_ITEMS
;
466 if (r
== ERROR_SUCCESS
)
468 if (szSource
|| !pcchSource
) index
++;
470 else if (dwIndex
> index
)
476 /******************************************************************
477 * MsiSourceListGetInfoA (MSI.@)
479 UINT WINAPI
MsiSourceListGetInfoA( LPCSTR szProduct
, LPCSTR szUserSid
,
480 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
481 LPCSTR szProperty
, LPSTR szValue
,
485 LPWSTR product
= NULL
;
486 LPWSTR usersid
= NULL
;
487 LPWSTR property
= NULL
;
491 if (szValue
&& !pcchValue
)
492 return ERROR_INVALID_PARAMETER
;
494 if (szProduct
) product
= strdupAtoW(szProduct
);
495 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
496 if (szProperty
) property
= strdupAtoW(szProperty
);
498 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
499 property
, NULL
, &len
);
500 if (ret
!= ERROR_SUCCESS
)
503 value
= msi_alloc(++len
* sizeof(WCHAR
));
505 return ERROR_OUTOFMEMORY
;
508 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
509 property
, value
, &len
);
510 if (ret
!= ERROR_SUCCESS
)
513 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
514 if (*pcchValue
>= len
)
515 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
517 ret
= ERROR_MORE_DATA
;
519 *pcchValue
= len
- 1;
529 /******************************************************************
530 * MsiSourceListGetInfoW (MSI.@)
532 UINT WINAPI
MsiSourceListGetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
533 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
534 LPCWSTR szProperty
, LPWSTR szValue
,
537 WCHAR
*source
, *ptr
, squashed_pc
[SQUASHED_GUID_SIZE
];
538 HKEY sourcekey
, media
;
542 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szProperty
));
544 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
545 return ERROR_INVALID_PARAMETER
;
547 if (szValue
&& !pcchValue
)
548 return ERROR_INVALID_PARAMETER
;
550 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
551 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
552 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
553 return ERROR_INVALID_PARAMETER
;
556 return ERROR_INVALID_PARAMETER
;
559 FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid
));
561 rc
= OpenSourceKey(szProduct
, &sourcekey
, dwOptions
, dwContext
, FALSE
);
562 if (rc
!= ERROR_SUCCESS
)
565 if (!wcscmp( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
566 !wcscmp( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
568 rc
= OpenMediaSubkey(sourcekey
, &media
, FALSE
);
569 if (rc
!= ERROR_SUCCESS
)
571 RegCloseKey(sourcekey
);
572 return ERROR_SUCCESS
;
575 if (!wcscmp( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
576 szProperty
= L
"MediaPackage";
578 RegQueryValueExW(media
, szProperty
, 0, 0, (LPBYTE
)szValue
, pcchValue
);
581 else if (!wcscmp( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) ||
582 !wcscmp( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
584 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
586 if (rc
!= ERROR_SUCCESS
)
588 static WCHAR szEmpty
[] = {0};
595 source
= msi_alloc(size
);
596 RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
597 0, 0, (LPBYTE
)source
, &size
);
602 RegCloseKey(sourcekey
);
603 return ERROR_SUCCESS
;
606 if (!wcscmp( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
608 if (*source
!= 'n' && *source
!= 'u' && *source
!= 'm')
611 RegCloseKey(sourcekey
);
612 return ERROR_SUCCESS
;
620 ptr
= wcsrchr(source
, ';');
629 if (lstrlenW(ptr
) < *pcchValue
)
630 lstrcpyW(szValue
, ptr
);
632 rc
= ERROR_MORE_DATA
;
635 *pcchValue
= lstrlenW(ptr
);
638 else if (!wcscmp( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
640 *pcchValue
= *pcchValue
* sizeof(WCHAR
);
641 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0, 0,
642 (LPBYTE
)szValue
, pcchValue
);
643 if (rc
!= ERROR_SUCCESS
&& rc
!= ERROR_MORE_DATA
)
651 *pcchValue
= (*pcchValue
- 1) / sizeof(WCHAR
);
653 szValue
[*pcchValue
] = '\0';
658 FIXME("Unknown property %s\n",debugstr_w(szProperty
));
659 rc
= ERROR_UNKNOWN_PROPERTY
;
662 RegCloseKey(sourcekey
);
666 /******************************************************************
667 * MsiSourceListSetInfoA (MSI.@)
669 UINT WINAPI
MsiSourceListSetInfoA(LPCSTR szProduct
, LPCSTR szUserSid
,
670 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
671 LPCSTR szProperty
, LPCSTR szValue
)
674 LPWSTR product
= NULL
;
675 LPWSTR usersid
= NULL
;
676 LPWSTR property
= NULL
;
679 if (szProduct
) product
= strdupAtoW(szProduct
);
680 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
681 if (szProperty
) property
= strdupAtoW(szProperty
);
682 if (szValue
) value
= strdupAtoW(szValue
);
684 ret
= MsiSourceListSetInfoW(product
, usersid
, dwContext
, dwOptions
,
695 UINT
msi_set_last_used_source(LPCWSTR product
, LPCWSTR usersid
,
696 MSIINSTALLCONTEXT context
, DWORD options
,
706 if (options
& MSISOURCETYPE_NETWORK
)
708 else if (options
& MSISOURCETYPE_URL
)
710 else if (options
& MSISOURCETYPE_MEDIA
)
713 return ERROR_INVALID_PARAMETER
;
715 if (!(options
& MSISOURCETYPE_MEDIA
))
717 r
= MsiSourceListAddSourceExW(product
, usersid
, context
,
719 if (r
!= ERROR_SUCCESS
)
723 while ((r
= MsiSourceListEnumSourcesW(product
, usersid
, context
, options
,
724 index
, NULL
, NULL
)) == ERROR_SUCCESS
)
727 if (r
!= ERROR_NO_MORE_ITEMS
)
731 size
= lstrlenW(L
"%c;%d;%s") + lstrlenW(value
) + 7;
732 buffer
= msi_alloc(size
* sizeof(WCHAR
));
734 return ERROR_OUTOFMEMORY
;
736 r
= OpenSourceKey(product
, &source
, MSICODE_PRODUCT
, context
, FALSE
);
737 if (r
!= ERROR_SUCCESS
)
743 swprintf(buffer
, size
, L
"%c;%d;%s", typechar
, index
, value
);
745 size
= (lstrlenW(buffer
) + 1) * sizeof(WCHAR
);
746 r
= RegSetValueExW(source
, INSTALLPROPERTY_LASTUSEDSOURCEW
, 0,
747 REG_SZ
, (LPBYTE
)buffer
, size
);
754 /******************************************************************
755 * MsiSourceListSetInfoW (MSI.@)
757 UINT WINAPI
MsiSourceListSetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
758 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
759 LPCWSTR szProperty
, LPCWSTR szValue
)
761 WCHAR squashed_pc
[SQUASHED_GUID_SIZE
];
762 HKEY sourcekey
, media
;
766 TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
767 dwContext
, dwOptions
, debugstr_w(szProperty
), debugstr_w(szValue
));
769 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
770 return ERROR_INVALID_PARAMETER
;
773 return ERROR_INVALID_PARAMETER
;
776 return ERROR_UNKNOWN_PROPERTY
;
778 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
779 return ERROR_INVALID_PARAMETER
;
781 if (dwOptions
& MSICODE_PATCH
)
783 FIXME("Unhandled options MSICODE_PATCH\n");
784 return ERROR_UNKNOWN_PATCH
;
787 property
= szProperty
;
788 if (!wcscmp( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
789 property
= L
"MediaPackage";
791 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
792 if (rc
!= ERROR_SUCCESS
)
795 if (wcscmp( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) &&
796 dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
))
798 RegCloseKey(sourcekey
);
799 return ERROR_INVALID_PARAMETER
;
802 if (!wcscmp( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
803 !wcscmp( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
805 rc
= OpenMediaSubkey(sourcekey
, &media
, TRUE
);
806 if (rc
== ERROR_SUCCESS
)
808 rc
= msi_reg_set_val_str(media
, property
, szValue
);
812 else if (!wcscmp( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
814 DWORD size
= (lstrlenW(szValue
) + 1) * sizeof(WCHAR
);
815 rc
= RegSetValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0,
816 REG_SZ
, (const BYTE
*)szValue
, size
);
817 if (rc
!= ERROR_SUCCESS
)
818 rc
= ERROR_UNKNOWN_PROPERTY
;
820 else if (!wcscmp( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
822 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
823 rc
= ERROR_INVALID_PARAMETER
;
825 rc
= msi_set_last_used_source(szProduct
, szUserSid
, dwContext
,
829 rc
= ERROR_UNKNOWN_PROPERTY
;
831 RegCloseKey(sourcekey
);
835 /******************************************************************
836 * MsiSourceListAddSourceW (MSI.@)
838 UINT WINAPI
MsiSourceListAddSourceW( LPCWSTR szProduct
, LPCWSTR szUserName
,
839 DWORD dwReserved
, LPCWSTR szSource
)
841 WCHAR
*sidstr
= NULL
, squashed_pc
[SQUASHED_GUID_SIZE
];
843 DWORD sidsize
= 0, domsize
= 0, context
;
847 TRACE("%s %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserName
), debugstr_w(szSource
));
849 if (!szSource
|| !*szSource
)
850 return ERROR_INVALID_PARAMETER
;
853 return ERROR_INVALID_PARAMETER
;
855 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
856 return ERROR_INVALID_PARAMETER
;
858 if (!szUserName
|| !*szUserName
)
859 context
= MSIINSTALLCONTEXT_MACHINE
;
862 if (LookupAccountNameW(NULL
, szUserName
, NULL
, &sidsize
, NULL
, &domsize
, NULL
))
864 PSID psid
= msi_alloc(sidsize
);
866 if (LookupAccountNameW(NULL
, szUserName
, psid
, &sidsize
, NULL
, &domsize
, NULL
))
867 ConvertSidToStringSidW(psid
, &sidstr
);
872 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
873 MSIINSTALLCONTEXT_USERMANAGED
, &hkey
, FALSE
);
874 if (r
== ERROR_SUCCESS
)
875 context
= MSIINSTALLCONTEXT_USERMANAGED
;
878 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
879 MSIINSTALLCONTEXT_USERUNMANAGED
,
881 if (r
!= ERROR_SUCCESS
)
882 return ERROR_UNKNOWN_PRODUCT
;
884 context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
890 ret
= MsiSourceListAddSourceExW(szProduct
, sidstr
,
891 context
, MSISOURCETYPE_NETWORK
, szSource
, 0);
899 /******************************************************************
900 * MsiSourceListAddSourceA (MSI.@)
902 UINT WINAPI
MsiSourceListAddSourceA( LPCSTR szProduct
, LPCSTR szUserName
,
903 DWORD dwReserved
, LPCSTR szSource
)
910 szwproduct
= strdupAtoW( szProduct
);
911 szwusername
= strdupAtoW( szUserName
);
912 szwsource
= strdupAtoW( szSource
);
914 ret
= MsiSourceListAddSourceW(szwproduct
, szwusername
, dwReserved
, szwsource
);
916 msi_free(szwproduct
);
917 msi_free(szwusername
);
923 /******************************************************************
924 * MsiSourceListAddSourceExA (MSI.@)
926 UINT WINAPI
MsiSourceListAddSourceExA(LPCSTR szProduct
, LPCSTR szUserSid
,
927 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCSTR szSource
, DWORD dwIndex
)
930 LPWSTR product
, usersid
, source
;
932 product
= strdupAtoW(szProduct
);
933 usersid
= strdupAtoW(szUserSid
);
934 source
= strdupAtoW(szSource
);
936 ret
= MsiSourceListAddSourceExW(product
, usersid
, dwContext
,
937 dwOptions
, source
, dwIndex
);
946 static void free_source_list(struct list
*sourcelist
)
948 while (!list_empty(sourcelist
))
950 media_info
*info
= LIST_ENTRY(list_head(sourcelist
), media_info
, entry
);
951 list_remove(&info
->entry
);
952 msi_free(info
->path
);
957 static void add_source_to_list(struct list
*sourcelist
, media_info
*info
,
963 if (index
) *index
= 0;
965 if (list_empty(sourcelist
))
967 list_add_head(sourcelist
, &info
->entry
);
971 LIST_FOR_EACH_ENTRY(iter
, sourcelist
, media_info
, entry
)
973 if (!found
&& info
->index
< iter
->index
)
976 list_add_before(&iter
->entry
, &info
->entry
);
979 /* update the rest of the list */
981 swprintf(iter
->szIndex
, ARRAY_SIZE(iter
->szIndex
), L
"%d", ++iter
->index
);
987 list_add_after(&iter
->entry
, &info
->entry
);
990 static UINT
fill_source_list(struct list
*sourcelist
, HKEY sourcekey
, DWORD
*count
)
992 UINT r
= ERROR_SUCCESS
;
995 DWORD size
, val_size
;
1000 while (r
== ERROR_SUCCESS
)
1002 size
= ARRAY_SIZE(name
);
1003 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
, NULL
, NULL
, &val_size
);
1004 if (r
!= ERROR_SUCCESS
)
1007 entry
= msi_alloc(sizeof(media_info
));
1011 entry
->path
= msi_alloc(val_size
);
1018 lstrcpyW(entry
->szIndex
, name
);
1019 entry
->index
= wcstol(name
, NULL
, 10);
1022 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
,
1023 NULL
, (LPBYTE
)entry
->path
, &val_size
);
1024 if (r
!= ERROR_SUCCESS
)
1026 msi_free(entry
->path
);
1032 add_source_to_list(sourcelist
, entry
, NULL
);
1037 free_source_list(sourcelist
);
1038 return ERROR_OUTOFMEMORY
;
1041 /******************************************************************
1042 * MsiSourceListAddSourceExW (MSI.@)
1044 UINT WINAPI
MsiSourceListAddSourceExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1045 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCWSTR szSource
,
1048 HKEY sourcekey
, typekey
;
1050 struct list sourcelist
;
1052 WCHAR
*source
, squashed_pc
[SQUASHED_GUID_SIZE
], name
[10];
1054 DWORD size
, count
, index
;
1056 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1057 dwContext
, dwOptions
, debugstr_w(szSource
), dwIndex
);
1059 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
1060 return ERROR_INVALID_PARAMETER
;
1062 if (!szSource
|| !*szSource
)
1063 return ERROR_INVALID_PARAMETER
;
1065 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
1066 return ERROR_INVALID_PARAMETER
;
1068 if (dwOptions
& MSICODE_PATCH
)
1070 FIXME("Unhandled options MSICODE_PATCH\n");
1071 return ERROR_FUNCTION_FAILED
;
1074 if (szUserSid
&& (dwContext
& MSIINSTALLCONTEXT_MACHINE
))
1075 return ERROR_INVALID_PARAMETER
;
1077 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1078 if (rc
!= ERROR_SUCCESS
)
1081 if (dwOptions
& MSISOURCETYPE_NETWORK
)
1082 rc
= OpenNetworkSubkey(sourcekey
, &typekey
, TRUE
);
1083 else if (dwOptions
& MSISOURCETYPE_URL
)
1084 rc
= OpenURLSubkey(sourcekey
, &typekey
, TRUE
);
1085 else if (dwOptions
& MSISOURCETYPE_MEDIA
)
1086 rc
= OpenMediaSubkey(sourcekey
, &typekey
, TRUE
);
1089 ERR("unknown media type: %08x\n", dwOptions
);
1090 RegCloseKey(sourcekey
);
1091 return ERROR_FUNCTION_FAILED
;
1093 if (rc
!= ERROR_SUCCESS
)
1095 ERR("can't open subkey %u\n", rc
);
1096 RegCloseKey(sourcekey
);
1100 postfix
= (dwOptions
& MSISOURCETYPE_NETWORK
) ? L
"\\" : L
"/";
1101 if (szSource
[lstrlenW(szSource
) - 1] == *postfix
)
1102 source
= strdupW(szSource
);
1105 size
= lstrlenW(szSource
) + 2;
1106 source
= msi_alloc(size
* sizeof(WCHAR
));
1107 lstrcpyW(source
, szSource
);
1108 lstrcatW(source
, postfix
);
1111 list_init(&sourcelist
);
1112 rc
= fill_source_list(&sourcelist
, typekey
, &count
);
1113 if (rc
!= ERROR_NO_MORE_ITEMS
)
1116 size
= (lstrlenW(source
) + 1) * sizeof(WCHAR
);
1120 rc
= RegSetValueExW(typekey
, L
"1", 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1123 else if (dwIndex
> count
|| dwIndex
== 0)
1125 swprintf(name
, ARRAY_SIZE(name
), L
"%d", count
+ 1);
1126 rc
= RegSetValueExW(typekey
, name
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1131 swprintf(name
, ARRAY_SIZE(name
), L
"%d", dwIndex
);
1132 info
= msi_alloc(sizeof(media_info
));
1135 rc
= ERROR_OUTOFMEMORY
;
1139 info
->path
= strdupW(source
);
1140 lstrcpyW(info
->szIndex
, name
);
1141 info
->index
= dwIndex
;
1142 add_source_to_list(&sourcelist
, info
, &index
);
1144 LIST_FOR_EACH_ENTRY(info
, &sourcelist
, media_info
, entry
)
1146 if (info
->index
< index
)
1149 size
= (lstrlenW(info
->path
) + 1) * sizeof(WCHAR
);
1150 rc
= RegSetValueExW(typekey
, info
->szIndex
, 0,
1151 REG_EXPAND_SZ
, (LPBYTE
)info
->path
, size
);
1152 if (rc
!= ERROR_SUCCESS
)
1158 free_source_list(&sourcelist
);
1160 RegCloseKey(typekey
);
1161 RegCloseKey(sourcekey
);
1165 /******************************************************************
1166 * MsiSourceListAddMediaDiskA (MSI.@)
1168 UINT WINAPI
MsiSourceListAddMediaDiskA(LPCSTR szProduct
, LPCSTR szUserSid
,
1169 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1170 LPCSTR szVolumeLabel
, LPCSTR szDiskPrompt
)
1173 LPWSTR product
= NULL
;
1174 LPWSTR usersid
= NULL
;
1175 LPWSTR volume
= NULL
;
1176 LPWSTR prompt
= NULL
;
1178 if (szProduct
) product
= strdupAtoW(szProduct
);
1179 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1180 if (szVolumeLabel
) volume
= strdupAtoW(szVolumeLabel
);
1181 if (szDiskPrompt
) prompt
= strdupAtoW(szDiskPrompt
);
1183 r
= MsiSourceListAddMediaDiskW(product
, usersid
, dwContext
, dwOptions
,
1184 dwDiskId
, volume
, prompt
);
1194 /******************************************************************
1195 * MsiSourceListAddMediaDiskW (MSI.@)
1197 UINT WINAPI
MsiSourceListAddMediaDiskW(LPCWSTR szProduct
, LPCWSTR szUserSid
,
1198 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1199 LPCWSTR szVolumeLabel
, LPCWSTR szDiskPrompt
)
1201 HKEY sourcekey
, mediakey
;
1203 WCHAR
*buffer
, squashed_pc
[SQUASHED_GUID_SIZE
], szIndex
[10];
1206 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct
),
1207 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwDiskId
,
1208 debugstr_w(szVolumeLabel
), debugstr_w(szDiskPrompt
));
1210 if (!szProduct
|| !squash_guid( szProduct
, squashed_pc
))
1211 return ERROR_INVALID_PARAMETER
;
1213 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
1214 return ERROR_INVALID_PARAMETER
;
1216 if ((szVolumeLabel
&& !*szVolumeLabel
) || (szDiskPrompt
&& !*szDiskPrompt
))
1217 return ERROR_INVALID_PARAMETER
;
1219 if ((dwContext
& MSIINSTALLCONTEXT_MACHINE
) && szUserSid
)
1220 return ERROR_INVALID_PARAMETER
;
1222 if (dwOptions
& MSICODE_PATCH
)
1224 FIXME("Unhandled options MSICODE_PATCH\n");
1225 return ERROR_FUNCTION_FAILED
;
1228 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1229 if (rc
!= ERROR_SUCCESS
)
1232 OpenMediaSubkey(sourcekey
, &mediakey
, TRUE
);
1234 swprintf(szIndex
, ARRAY_SIZE(szIndex
), L
"%d", dwDiskId
);
1237 if (szVolumeLabel
) size
+= lstrlenW(szVolumeLabel
);
1238 if (szDiskPrompt
) size
+= lstrlenW(szDiskPrompt
);
1240 size
*= sizeof(WCHAR
);
1241 buffer
= msi_alloc(size
);
1244 if (szVolumeLabel
) lstrcpyW(buffer
, szVolumeLabel
);
1245 lstrcatW(buffer
, L
";");
1246 if (szDiskPrompt
) lstrcatW(buffer
, szDiskPrompt
);
1248 RegSetValueExW(mediakey
, szIndex
, 0, REG_SZ
, (LPBYTE
)buffer
, size
);
1251 RegCloseKey(sourcekey
);
1252 RegCloseKey(mediakey
);
1254 return ERROR_SUCCESS
;
1257 /******************************************************************
1258 * MsiSourceListClearAllA (MSI.@)
1260 UINT WINAPI
MsiSourceListClearAllA( LPCSTR szProduct
, LPCSTR szUserName
, DWORD dwReserved
)
1262 FIXME("(%s %s %d)\n", debugstr_a(szProduct
), debugstr_a(szUserName
), dwReserved
);
1263 return ERROR_SUCCESS
;
1266 /******************************************************************
1267 * MsiSourceListClearAllW (MSI.@)
1269 UINT WINAPI
MsiSourceListClearAllW( LPCWSTR szProduct
, LPCWSTR szUserName
, DWORD dwReserved
)
1271 FIXME("(%s %s %d)\n", debugstr_w(szProduct
), debugstr_w(szUserName
), dwReserved
);
1272 return ERROR_SUCCESS
;
1275 /******************************************************************
1276 * MsiSourceListClearAllExA (MSI.@)
1278 UINT WINAPI
MsiSourceListClearAllExA( LPCSTR szProduct
, LPCSTR szUserSid
,
1279 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1281 FIXME("(%s %s %d %08x)\n", debugstr_a(szProduct
), debugstr_a(szUserSid
),
1282 dwContext
, dwOptions
);
1283 return ERROR_SUCCESS
;
1286 /******************************************************************
1287 * MsiSourceListClearAllExW (MSI.@)
1289 UINT WINAPI
MsiSourceListClearAllExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1290 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1292 FIXME("(%s %s %d %08x)\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1293 dwContext
, dwOptions
);
1294 return ERROR_SUCCESS
;
1297 /******************************************************************
1298 * MsiSourceListClearSourceA (MSI.@)
1300 UINT WINAPI
MsiSourceListClearSourceA(LPCSTR szProductCodeOrPatchCode
, LPCSTR szUserSid
,
1301 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1304 FIXME("(%s %s %x %x %s)\n", debugstr_a(szProductCodeOrPatchCode
), debugstr_a(szUserSid
),
1305 dwContext
, dwOptions
, debugstr_a(szSource
));
1306 return ERROR_SUCCESS
;
1309 /******************************************************************
1310 * MsiSourceListClearSourceW (MSI.@)
1312 UINT WINAPI
MsiSourceListClearSourceW(LPCWSTR szProductCodeOrPatchCode
, LPCWSTR szUserSid
,
1313 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1316 FIXME("(%s %s %x %x %s)\n", debugstr_w(szProductCodeOrPatchCode
), debugstr_w(szUserSid
),
1317 dwContext
, dwOptions
, debugstr_w(szSource
));
1318 return ERROR_SUCCESS
;
1321 /******************************************************************
1322 * MsiSourceListForceResolutionA (MSI.@)
1324 UINT WINAPI
MsiSourceListForceResolutionA(const CHAR
*product
, const CHAR
*user
, DWORD reserved
)
1326 FIXME("(%s %s %x)\n", debugstr_a(product
), debugstr_a(user
), reserved
);
1327 return ERROR_SUCCESS
;
1330 /******************************************************************
1331 * MsiSourceListForceResolutionW (MSI.@)
1333 UINT WINAPI
MsiSourceListForceResolutionW(const WCHAR
*product
, const WCHAR
*user
, DWORD reserved
)
1335 FIXME("(%s %s %x)\n", debugstr_w(product
), debugstr_w(user
), reserved
);
1336 return ERROR_SUCCESS
;