2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/debug.h"
37 #include "wine/unicode.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
43 * These apis are defined in MSI 3.0
46 typedef struct tagMediaInfo
54 static UINT
OpenSourceKey(LPCWSTR szProduct
, HKEY
* key
, DWORD dwOptions
,
55 MSIINSTALLCONTEXT context
, BOOL create
)
58 UINT rc
= ERROR_FUNCTION_FAILED
;
60 if (context
== MSIINSTALLCONTEXT_USERUNMANAGED
)
62 if (dwOptions
& MSICODE_PATCH
)
63 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
65 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
68 else if (context
== MSIINSTALLCONTEXT_USERMANAGED
)
70 if (dwOptions
& MSICODE_PATCH
)
71 rc
= MSIREG_OpenUserPatchesKey(szProduct
, &rootkey
, create
);
73 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
76 else if (context
== MSIINSTALLCONTEXT_MACHINE
)
78 if (dwOptions
& MSICODE_PATCH
)
79 rc
= MSIREG_OpenPatchesKey(szProduct
, &rootkey
, create
);
81 rc
= MSIREG_OpenProductKey(szProduct
, NULL
, context
,
85 if (rc
!= ERROR_SUCCESS
)
87 if (dwOptions
& MSICODE_PATCH
)
88 return ERROR_UNKNOWN_PATCH
;
90 return ERROR_UNKNOWN_PRODUCT
;
94 rc
= RegCreateKeyW(rootkey
, szSourceList
, key
);
97 rc
= RegOpenKeyW(rootkey
,szSourceList
, key
);
98 if (rc
!= ERROR_SUCCESS
)
99 rc
= ERROR_BAD_CONFIGURATION
;
105 static UINT
OpenMediaSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
108 static const WCHAR media
[] = {'M','e','d','i','a',0};
111 rc
= RegCreateKeyW(rootkey
, media
, key
);
113 rc
= RegOpenKeyW(rootkey
,media
, key
);
118 static UINT
OpenNetworkSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
121 static const WCHAR net
[] = {'N','e','t',0};
124 rc
= RegCreateKeyW(rootkey
, net
, key
);
126 rc
= RegOpenKeyW(rootkey
, net
, key
);
131 static UINT
OpenURLSubkey(HKEY rootkey
, HKEY
*key
, BOOL create
)
134 static const WCHAR URL
[] = {'U','R','L',0};
137 rc
= RegCreateKeyW(rootkey
, URL
, key
);
139 rc
= RegOpenKeyW(rootkey
, URL
, key
);
144 /******************************************************************
145 * MsiSourceListEnumMediaDisksA (MSI.@)
147 UINT WINAPI
MsiSourceListEnumMediaDisksA(LPCSTR szProductCodeOrPatchCode
,
148 LPCSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
149 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
150 LPSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
151 LPSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
153 LPWSTR product
= NULL
;
154 LPWSTR usersid
= NULL
;
155 LPWSTR volume
= NULL
;
156 LPWSTR prompt
= NULL
;
157 UINT r
= ERROR_INVALID_PARAMETER
;
159 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n", debugstr_a(szProductCodeOrPatchCode
),
160 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, pdwDiskId
,
161 szVolumeLabel
, pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
163 if (szDiskPrompt
&& !pcchDiskPrompt
)
164 return ERROR_INVALID_PARAMETER
;
166 if (szProductCodeOrPatchCode
) product
= strdupAtoW(szProductCodeOrPatchCode
);
167 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
169 /* FIXME: add tests for an invalid format */
172 volume
= msi_alloc(*pcchVolumeLabel
* sizeof(WCHAR
));
175 prompt
= msi_alloc(*pcchDiskPrompt
* sizeof(WCHAR
));
177 if (volume
) *volume
= '\0';
178 if (prompt
) *prompt
= '\0';
179 r
= MsiSourceListEnumMediaDisksW(product
, usersid
, dwContext
, dwOptions
,
180 dwIndex
, pdwDiskId
, volume
, pcchVolumeLabel
,
181 prompt
, pcchDiskPrompt
);
182 if (r
!= ERROR_SUCCESS
)
185 if (szVolumeLabel
&& pcchVolumeLabel
)
186 WideCharToMultiByte(CP_ACP
, 0, volume
, -1, szVolumeLabel
,
187 *pcchVolumeLabel
+ 1, NULL
, NULL
);
190 WideCharToMultiByte(CP_ACP
, 0, prompt
, -1, szDiskPrompt
,
191 *pcchDiskPrompt
+ 1, NULL
, NULL
);
202 /******************************************************************
203 * MsiSourceListEnumMediaDisksW (MSI.@)
205 UINT WINAPI
MsiSourceListEnumMediaDisksW(LPCWSTR szProductCodeOrPatchCode
,
206 LPCWSTR szUserSid
, MSIINSTALLCONTEXT dwContext
,
207 DWORD dwOptions
, DWORD dwIndex
, LPDWORD pdwDiskId
,
208 LPWSTR szVolumeLabel
, LPDWORD pcchVolumeLabel
,
209 LPWSTR szDiskPrompt
, LPDWORD pcchDiskPrompt
)
211 WCHAR squished_pc
[GUID_SIZE
];
217 DWORD valuesz
, datasz
= 0;
222 static DWORD index
= 0;
224 static const WCHAR fmt
[] = {'#','%','d',0};
226 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p)\n", debugstr_w(szProductCodeOrPatchCode
),
227 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szVolumeLabel
,
228 pcchVolumeLabel
, szDiskPrompt
, pcchDiskPrompt
);
230 if (!szProductCodeOrPatchCode
||
231 !squash_guid(szProductCodeOrPatchCode
, squished_pc
))
232 return ERROR_INVALID_PARAMETER
;
234 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
235 return ERROR_INVALID_PARAMETER
;
237 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
238 return ERROR_INVALID_PARAMETER
;
240 if (szDiskPrompt
&& !pcchDiskPrompt
)
241 return ERROR_INVALID_PARAMETER
;
246 if (dwIndex
!= index
)
247 return ERROR_INVALID_PARAMETER
;
249 r
= OpenSourceKey(szProductCodeOrPatchCode
, &source
,
250 dwOptions
, dwContext
, FALSE
);
251 if (r
!= ERROR_SUCCESS
)
254 r
= OpenMediaSubkey(source
, &media
, FALSE
);
255 if (r
!= ERROR_SUCCESS
)
258 return ERROR_NO_MORE_ITEMS
;
261 if (!pcchVolumeLabel
&& !pcchDiskPrompt
)
263 r
= RegEnumValueW(media
, dwIndex
, NULL
, NULL
, NULL
,
268 res
= RegQueryInfoKeyW(media
, NULL
, NULL
, NULL
, NULL
, NULL
,
269 NULL
, &numvals
, &valuesz
, &datasz
, NULL
, NULL
);
270 if (res
!= ERROR_SUCCESS
)
272 r
= ERROR_BAD_CONFIGURATION
;
276 value
= msi_alloc(++valuesz
* sizeof(WCHAR
));
277 data
= msi_alloc(++datasz
* sizeof(WCHAR
));
280 r
= ERROR_OUTOFMEMORY
;
284 r
= RegEnumValueW(media
, dwIndex
, value
, &valuesz
,
285 NULL
, &type
, (LPBYTE
)data
, &datasz
);
286 if (r
!= ERROR_SUCCESS
)
290 *pdwDiskId
= atolW(value
);
293 ptr
= strchrW(data
, ';');
301 if (type
== REG_DWORD
)
303 sprintfW(convert
, fmt
, *data
);
304 size
= lstrlenW(convert
);
308 size
= lstrlenW(data
);
310 if (size
>= *pcchVolumeLabel
)
312 else if (szVolumeLabel
)
313 lstrcpyW(szVolumeLabel
, ptr2
);
315 *pcchVolumeLabel
= size
;
323 if (type
== REG_DWORD
)
325 sprintfW(convert
, fmt
, *ptr
);
326 size
= lstrlenW(convert
);
330 size
= lstrlenW(ptr
);
332 if (size
>= *pcchDiskPrompt
)
334 else if (szDiskPrompt
)
335 lstrcpyW(szDiskPrompt
, ptr
);
337 *pcchDiskPrompt
= size
;
350 /******************************************************************
351 * MsiSourceListEnumSourcesA (MSI.@)
353 UINT WINAPI
MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch
, LPCSTR szUserSid
,
354 MSIINSTALLCONTEXT dwContext
,
355 DWORD dwOptions
, DWORD dwIndex
,
356 LPSTR szSource
, LPDWORD pcchSource
)
358 LPWSTR product
= NULL
;
359 LPWSTR usersid
= NULL
;
360 LPWSTR source
= NULL
;
362 UINT r
= ERROR_INVALID_PARAMETER
;
363 static DWORD index
= 0;
365 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_a(szProductCodeOrPatch
),
366 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
371 if (szSource
&& !pcchSource
)
374 if (dwIndex
!= index
)
377 if (szProductCodeOrPatch
) product
= strdupAtoW(szProductCodeOrPatch
);
378 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
380 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
381 dwIndex
, NULL
, &len
);
382 if (r
!= ERROR_SUCCESS
)
385 source
= msi_alloc(++len
* sizeof(WCHAR
));
388 r
= ERROR_OUTOFMEMORY
;
393 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
394 dwIndex
, source
, &len
);
395 if (r
!= ERROR_SUCCESS
)
398 len
= WideCharToMultiByte(CP_ACP
, 0, source
, -1, NULL
, 0, NULL
, NULL
);
399 if (pcchSource
&& *pcchSource
>= len
)
400 WideCharToMultiByte(CP_ACP
, 0, source
, -1, szSource
, len
, NULL
, NULL
);
405 *pcchSource
= len
- 1;
412 if (r
== ERROR_SUCCESS
)
414 if (szSource
|| !pcchSource
) index
++;
416 else if (dwIndex
> index
)
422 /******************************************************************
423 * MsiSourceListEnumSourcesW (MSI.@)
425 UINT WINAPI
MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch
, LPCWSTR szUserSid
,
426 MSIINSTALLCONTEXT dwContext
,
427 DWORD dwOptions
, DWORD dwIndex
,
428 LPWSTR szSource
, LPDWORD pcchSource
)
430 WCHAR squished_pc
[GUID_SIZE
];
435 UINT r
= ERROR_INVALID_PARAMETER
;
436 static DWORD index
= 0;
438 static const WCHAR format
[] = {'%','d',0};
440 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch
),
441 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
446 if (!szProductCodeOrPatch
|| !squash_guid(szProductCodeOrPatch
, squished_pc
))
449 if (szSource
&& !pcchSource
)
452 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
455 if ((dwOptions
& MSISOURCETYPE_NETWORK
) && (dwOptions
& MSISOURCETYPE_URL
))
458 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
461 if (dwIndex
!= index
)
464 r
= OpenSourceKey(szProductCodeOrPatch
, &source
,
465 dwOptions
, dwContext
, FALSE
);
466 if (r
!= ERROR_SUCCESS
)
469 if (dwOptions
& MSISOURCETYPE_NETWORK
)
470 r
= OpenNetworkSubkey(source
, &subkey
, FALSE
);
471 else if (dwOptions
& MSISOURCETYPE_URL
)
472 r
= OpenURLSubkey(source
, &subkey
, FALSE
);
474 if (r
!= ERROR_SUCCESS
)
476 r
= ERROR_NO_MORE_ITEMS
;
480 sprintfW(name
, format
, dwIndex
+ 1);
482 res
= RegQueryValueExW(subkey
, name
, 0, 0, (LPBYTE
)szSource
, pcchSource
);
483 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
484 r
= ERROR_NO_MORE_ITEMS
;
490 if (r
== ERROR_SUCCESS
)
492 if (szSource
|| !pcchSource
) index
++;
494 else if (dwIndex
> index
)
500 /******************************************************************
501 * MsiSourceListGetInfoA (MSI.@)
503 UINT WINAPI
MsiSourceListGetInfoA( LPCSTR szProduct
, LPCSTR szUserSid
,
504 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
505 LPCSTR szProperty
, LPSTR szValue
,
509 LPWSTR product
= NULL
;
510 LPWSTR usersid
= NULL
;
511 LPWSTR property
= NULL
;
515 if (szValue
&& !pcchValue
)
516 return ERROR_INVALID_PARAMETER
;
518 if (szProduct
) product
= strdupAtoW(szProduct
);
519 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
520 if (szProperty
) property
= strdupAtoW(szProperty
);
522 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
523 property
, NULL
, &len
);
524 if (ret
!= ERROR_SUCCESS
)
527 value
= msi_alloc(++len
* sizeof(WCHAR
));
529 return ERROR_OUTOFMEMORY
;
532 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
533 property
, value
, &len
);
534 if (ret
!= ERROR_SUCCESS
)
537 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
538 if (*pcchValue
>= len
)
539 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
541 ret
= ERROR_MORE_DATA
;
543 *pcchValue
= len
- 1;
553 /******************************************************************
554 * MsiSourceListGetInfoW (MSI.@)
556 UINT WINAPI
MsiSourceListGetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
557 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
558 LPCWSTR szProperty
, LPWSTR szValue
,
561 WCHAR squished_pc
[GUID_SIZE
];
562 HKEY sourcekey
, media
;
567 static const WCHAR mediapack
[] = {
568 'M','e','d','i','a','P','a','c','k','a','g','e',0};
570 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szProperty
));
572 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
573 return ERROR_INVALID_PARAMETER
;
575 if (szValue
&& !pcchValue
)
576 return ERROR_INVALID_PARAMETER
;
578 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
579 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
580 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
581 return ERROR_INVALID_PARAMETER
;
584 return ERROR_INVALID_PARAMETER
;
587 FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid
));
589 rc
= OpenSourceKey(szProduct
, &sourcekey
, dwOptions
, dwContext
, FALSE
);
590 if (rc
!= ERROR_SUCCESS
)
593 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
594 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
596 rc
= OpenMediaSubkey(sourcekey
, &media
, FALSE
);
597 if (rc
!= ERROR_SUCCESS
)
599 RegCloseKey(sourcekey
);
600 return ERROR_SUCCESS
;
603 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
604 szProperty
= mediapack
;
606 RegQueryValueExW(media
, szProperty
, 0, 0, (LPBYTE
)szValue
, pcchValue
);
609 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) ||
610 !strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
612 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
614 if (rc
!= ERROR_SUCCESS
)
616 RegCloseKey(sourcekey
);
617 return ERROR_SUCCESS
;
620 source
= msi_alloc(size
);
621 RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
622 0, 0, (LPBYTE
)source
, &size
);
627 RegCloseKey(sourcekey
);
628 return ERROR_SUCCESS
;
631 if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
633 if (*source
!= 'n' && *source
!= 'u' && *source
!= 'm')
636 RegCloseKey(sourcekey
);
637 return ERROR_SUCCESS
;
645 ptr
= strrchrW(source
, ';');
654 if (strlenW(ptr
) < *pcchValue
)
655 lstrcpyW(szValue
, ptr
);
657 rc
= ERROR_MORE_DATA
;
660 *pcchValue
= lstrlenW(ptr
);
663 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
665 *pcchValue
= *pcchValue
* sizeof(WCHAR
);
666 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0, 0,
667 (LPBYTE
)szValue
, pcchValue
);
668 if (rc
!= ERROR_SUCCESS
&& rc
!= ERROR_MORE_DATA
)
676 *pcchValue
= (*pcchValue
- 1) / sizeof(WCHAR
);
678 szValue
[*pcchValue
] = '\0';
683 FIXME("Unknown property %s\n",debugstr_w(szProperty
));
684 rc
= ERROR_UNKNOWN_PROPERTY
;
687 RegCloseKey(sourcekey
);
691 /******************************************************************
692 * MsiSourceListSetInfoA (MSI.@)
694 UINT WINAPI
MsiSourceListSetInfoA(LPCSTR szProduct
, LPCSTR szUserSid
,
695 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
696 LPCSTR szProperty
, LPCSTR szValue
)
699 LPWSTR product
= NULL
;
700 LPWSTR usersid
= NULL
;
701 LPWSTR property
= NULL
;
704 if (szProduct
) product
= strdupAtoW(szProduct
);
705 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
706 if (szProperty
) property
= strdupAtoW(szProperty
);
707 if (szValue
) value
= strdupAtoW(szValue
);
709 ret
= MsiSourceListSetInfoW(product
, usersid
, dwContext
, dwOptions
,
720 UINT
msi_set_last_used_source(LPCWSTR product
, LPCWSTR usersid
,
721 MSIINSTALLCONTEXT context
, DWORD options
,
731 static const WCHAR format
[] = {'%','c',';','%','i',';','%','s',0};
733 if (options
& MSISOURCETYPE_NETWORK
)
735 else if (options
& MSISOURCETYPE_URL
)
737 else if (options
& MSISOURCETYPE_MEDIA
)
740 return ERROR_INVALID_PARAMETER
;
742 if (!(options
& MSISOURCETYPE_MEDIA
))
744 r
= MsiSourceListAddSourceExW(product
, usersid
, context
,
746 if (r
!= ERROR_SUCCESS
)
750 while ((r
= MsiSourceListEnumSourcesW(product
, usersid
, context
, options
,
751 index
, NULL
, NULL
)) == ERROR_SUCCESS
)
754 if (r
!= ERROR_NO_MORE_ITEMS
)
758 size
= (lstrlenW(format
) + lstrlenW(value
) + 7) * sizeof(WCHAR
);
759 buffer
= msi_alloc(size
);
761 return ERROR_OUTOFMEMORY
;
763 r
= OpenSourceKey(product
, &source
, MSICODE_PRODUCT
, context
, FALSE
);
764 if (r
!= ERROR_SUCCESS
)
770 sprintfW(buffer
, format
, typechar
, index
, value
);
772 size
= (lstrlenW(buffer
) + 1) * sizeof(WCHAR
);
773 r
= RegSetValueExW(source
, INSTALLPROPERTY_LASTUSEDSOURCEW
, 0,
774 REG_SZ
, (LPBYTE
)buffer
, size
);
781 /******************************************************************
782 * MsiSourceListSetInfoW (MSI.@)
784 UINT WINAPI
MsiSourceListSetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
785 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
786 LPCWSTR szProperty
, LPCWSTR szValue
)
788 WCHAR squished_pc
[GUID_SIZE
];
789 HKEY sourcekey
, media
;
793 static const WCHAR media_package
[] = {
794 'M','e','d','i','a','P','a','c','k','a','g','e',0
797 TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
798 dwContext
, dwOptions
, debugstr_w(szProperty
), debugstr_w(szValue
));
800 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
801 return ERROR_INVALID_PARAMETER
;
804 return ERROR_INVALID_PARAMETER
;
807 return ERROR_UNKNOWN_PROPERTY
;
809 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
810 return ERROR_INVALID_PARAMETER
;
812 if (dwOptions
& MSICODE_PATCH
)
814 FIXME("Unhandled options MSICODE_PATCH\n");
815 return ERROR_UNKNOWN_PATCH
;
818 property
= szProperty
;
819 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
820 property
= media_package
;
822 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
823 if (rc
!= ERROR_SUCCESS
)
826 if (strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) &&
827 dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
))
829 RegCloseKey(sourcekey
);
830 return ERROR_INVALID_PARAMETER
;
833 if (!strcmpW( szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
834 !strcmpW( szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
836 rc
= OpenMediaSubkey(sourcekey
, &media
, TRUE
);
837 if (rc
== ERROR_SUCCESS
)
839 rc
= msi_reg_set_val_str(media
, property
, szValue
);
843 else if (!strcmpW( szProperty
, INSTALLPROPERTY_PACKAGENAMEW
))
845 DWORD size
= (lstrlenW(szValue
) + 1) * sizeof(WCHAR
);
846 rc
= RegSetValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0,
847 REG_SZ
, (const BYTE
*)szValue
, size
);
848 if (rc
!= ERROR_SUCCESS
)
849 rc
= ERROR_UNKNOWN_PROPERTY
;
851 else if (!strcmpW( szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
))
853 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
854 rc
= ERROR_INVALID_PARAMETER
;
856 rc
= msi_set_last_used_source(szProduct
, szUserSid
, dwContext
,
860 rc
= ERROR_UNKNOWN_PROPERTY
;
862 RegCloseKey(sourcekey
);
866 /******************************************************************
867 * MsiSourceListAddSourceW (MSI.@)
869 UINT WINAPI
MsiSourceListAddSourceW( LPCWSTR szProduct
, LPCWSTR szUserName
,
870 DWORD dwReserved
, LPCWSTR szSource
)
872 WCHAR squished_pc
[GUID_SIZE
];
874 LPWSTR sidstr
= NULL
;
881 TRACE("%s %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserName
), debugstr_w(szSource
));
883 if (!szSource
|| !*szSource
)
884 return ERROR_INVALID_PARAMETER
;
887 return ERROR_INVALID_PARAMETER
;
889 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
890 return ERROR_INVALID_PARAMETER
;
892 if (!szUserName
|| !*szUserName
)
893 context
= MSIINSTALLCONTEXT_MACHINE
;
896 if (LookupAccountNameW(NULL
, szUserName
, NULL
, &sidsize
, NULL
, &domsize
, NULL
))
898 PSID psid
= msi_alloc(sidsize
);
900 if (LookupAccountNameW(NULL
, szUserName
, psid
, &sidsize
, NULL
, &domsize
, NULL
))
901 ConvertSidToStringSidW(psid
, &sidstr
);
906 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
907 MSIINSTALLCONTEXT_USERMANAGED
, &hkey
, FALSE
);
908 if (r
== ERROR_SUCCESS
)
909 context
= MSIINSTALLCONTEXT_USERMANAGED
;
912 r
= MSIREG_OpenProductKey(szProduct
, NULL
,
913 MSIINSTALLCONTEXT_USERUNMANAGED
,
915 if (r
!= ERROR_SUCCESS
)
916 return ERROR_UNKNOWN_PRODUCT
;
918 context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
924 ret
= MsiSourceListAddSourceExW(szProduct
, sidstr
,
925 context
, MSISOURCETYPE_NETWORK
, szSource
, 0);
933 /******************************************************************
934 * MsiSourceListAddSourceA (MSI.@)
936 UINT WINAPI
MsiSourceListAddSourceA( LPCSTR szProduct
, LPCSTR szUserName
,
937 DWORD dwReserved
, LPCSTR szSource
)
944 szwproduct
= strdupAtoW( szProduct
);
945 szwusername
= strdupAtoW( szUserName
);
946 szwsource
= strdupAtoW( szSource
);
948 ret
= MsiSourceListAddSourceW(szwproduct
, szwusername
, dwReserved
, szwsource
);
950 msi_free(szwproduct
);
951 msi_free(szwusername
);
957 /******************************************************************
958 * MsiSourceListAddSourceExA (MSI.@)
960 UINT WINAPI
MsiSourceListAddSourceExA(LPCSTR szProduct
, LPCSTR szUserSid
,
961 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCSTR szSource
, DWORD dwIndex
)
964 LPWSTR product
, usersid
, source
;
966 product
= strdupAtoW(szProduct
);
967 usersid
= strdupAtoW(szUserSid
);
968 source
= strdupAtoW(szSource
);
970 ret
= MsiSourceListAddSourceExW(product
, usersid
, dwContext
,
971 dwOptions
, source
, dwIndex
);
980 static void free_source_list(struct list
*sourcelist
)
982 while (!list_empty(sourcelist
))
984 media_info
*info
= LIST_ENTRY(list_head(sourcelist
), media_info
, entry
);
985 list_remove(&info
->entry
);
986 msi_free(info
->path
);
991 static void add_source_to_list(struct list
*sourcelist
, media_info
*info
,
996 static const WCHAR fmt
[] = {'%','i',0};
998 if (index
) *index
= 0;
1000 if (list_empty(sourcelist
))
1002 list_add_head(sourcelist
, &info
->entry
);
1006 LIST_FOR_EACH_ENTRY(iter
, sourcelist
, media_info
, entry
)
1008 if (!found
&& info
->index
< iter
->index
)
1011 list_add_before(&iter
->entry
, &info
->entry
);
1014 /* update the rest of the list */
1016 sprintfW(iter
->szIndex
, fmt
, ++iter
->index
);
1022 list_add_after(&iter
->entry
, &info
->entry
);
1025 static UINT
fill_source_list(struct list
*sourcelist
, HKEY sourcekey
, DWORD
*count
)
1027 UINT r
= ERROR_SUCCESS
;
1030 DWORD size
, val_size
;
1035 while (r
== ERROR_SUCCESS
)
1037 size
= sizeof(name
) / sizeof(name
[0]);
1038 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
, NULL
, NULL
, &val_size
);
1039 if (r
!= ERROR_SUCCESS
)
1042 entry
= msi_alloc(sizeof(media_info
));
1046 entry
->path
= msi_alloc(val_size
);
1053 lstrcpyW(entry
->szIndex
, name
);
1054 entry
->index
= atoiW(name
);
1057 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
,
1058 NULL
, (LPBYTE
)entry
->path
, &val_size
);
1059 if (r
!= ERROR_SUCCESS
)
1061 msi_free(entry
->path
);
1067 add_source_to_list(sourcelist
, entry
, NULL
);
1072 free_source_list(sourcelist
);
1073 return ERROR_OUTOFMEMORY
;
1076 /******************************************************************
1077 * MsiSourceListAddSourceExW (MSI.@)
1079 UINT WINAPI
MsiSourceListAddSourceExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1080 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCWSTR szSource
,
1086 struct list sourcelist
;
1088 WCHAR squished_pc
[GUID_SIZE
];
1095 static const WCHAR fmt
[] = {'%','i',0};
1097 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1098 dwContext
, dwOptions
, debugstr_w(szSource
), dwIndex
);
1100 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1101 return ERROR_INVALID_PARAMETER
;
1103 if (!szSource
|| !*szSource
)
1104 return ERROR_INVALID_PARAMETER
;
1106 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
1107 return ERROR_INVALID_PARAMETER
;
1109 if (dwOptions
& MSICODE_PATCH
)
1111 FIXME("Unhandled options MSICODE_PATCH\n");
1112 return ERROR_FUNCTION_FAILED
;
1115 if (szUserSid
&& (dwContext
& MSIINSTALLCONTEXT_MACHINE
))
1116 return ERROR_INVALID_PARAMETER
;
1118 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1119 if (rc
!= ERROR_SUCCESS
)
1122 if (dwOptions
& MSISOURCETYPE_NETWORK
)
1123 rc
= OpenNetworkSubkey(sourcekey
, &typekey
, TRUE
);
1124 else if (dwOptions
& MSISOURCETYPE_URL
)
1125 rc
= OpenURLSubkey(sourcekey
, &typekey
, TRUE
);
1126 else if (dwOptions
& MSISOURCETYPE_MEDIA
)
1127 rc
= OpenMediaSubkey(sourcekey
, &typekey
, TRUE
);
1130 ERR("unknown media type: %08x\n", dwOptions
);
1131 RegCloseKey(sourcekey
);
1132 return ERROR_FUNCTION_FAILED
;
1134 if (rc
!= ERROR_SUCCESS
)
1136 ERR("can't open subkey %u\n", rc
);
1137 RegCloseKey(sourcekey
);
1141 postfix
= (dwOptions
& MSISOURCETYPE_NETWORK
) ? szBackSlash
: szForwardSlash
;
1142 if (szSource
[lstrlenW(szSource
) - 1] == *postfix
)
1143 source
= strdupW(szSource
);
1146 size
= lstrlenW(szSource
) + 2;
1147 source
= msi_alloc(size
* sizeof(WCHAR
));
1148 lstrcpyW(source
, szSource
);
1149 lstrcatW(source
, postfix
);
1152 list_init(&sourcelist
);
1153 rc
= fill_source_list(&sourcelist
, typekey
, &count
);
1154 if (rc
!= ERROR_NO_MORE_ITEMS
)
1157 size
= (lstrlenW(source
) + 1) * sizeof(WCHAR
);
1161 rc
= RegSetValueExW(typekey
, szOne
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1164 else if (dwIndex
> count
|| dwIndex
== 0)
1166 sprintfW(name
, fmt
, count
+ 1);
1167 rc
= RegSetValueExW(typekey
, name
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
1172 sprintfW(name
, fmt
, dwIndex
);
1173 info
= msi_alloc(sizeof(media_info
));
1176 rc
= ERROR_OUTOFMEMORY
;
1180 info
->path
= strdupW(source
);
1181 lstrcpyW(info
->szIndex
, name
);
1182 info
->index
= dwIndex
;
1183 add_source_to_list(&sourcelist
, info
, &index
);
1185 LIST_FOR_EACH_ENTRY(info
, &sourcelist
, media_info
, entry
)
1187 if (info
->index
< index
)
1190 size
= (lstrlenW(info
->path
) + 1) * sizeof(WCHAR
);
1191 rc
= RegSetValueExW(typekey
, info
->szIndex
, 0,
1192 REG_EXPAND_SZ
, (LPBYTE
)info
->path
, size
);
1193 if (rc
!= ERROR_SUCCESS
)
1199 free_source_list(&sourcelist
);
1201 RegCloseKey(typekey
);
1202 RegCloseKey(sourcekey
);
1206 /******************************************************************
1207 * MsiSourceListAddMediaDiskA (MSI.@)
1209 UINT WINAPI
MsiSourceListAddMediaDiskA(LPCSTR szProduct
, LPCSTR szUserSid
,
1210 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1211 LPCSTR szVolumeLabel
, LPCSTR szDiskPrompt
)
1214 LPWSTR product
= NULL
;
1215 LPWSTR usersid
= NULL
;
1216 LPWSTR volume
= NULL
;
1217 LPWSTR prompt
= NULL
;
1219 if (szProduct
) product
= strdupAtoW(szProduct
);
1220 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
1221 if (szVolumeLabel
) volume
= strdupAtoW(szVolumeLabel
);
1222 if (szDiskPrompt
) prompt
= strdupAtoW(szDiskPrompt
);
1224 r
= MsiSourceListAddMediaDiskW(product
, usersid
, dwContext
, dwOptions
,
1225 dwDiskId
, volume
, prompt
);
1235 /******************************************************************
1236 * MsiSourceListAddMediaDiskW (MSI.@)
1238 UINT WINAPI
MsiSourceListAddMediaDiskW(LPCWSTR szProduct
, LPCWSTR szUserSid
,
1239 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
1240 LPCWSTR szVolumeLabel
, LPCWSTR szDiskPrompt
)
1246 WCHAR squished_pc
[GUID_SIZE
];
1250 static const WCHAR fmt
[] = {'%','i',0};
1252 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct
),
1253 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwDiskId
,
1254 debugstr_w(szVolumeLabel
), debugstr_w(szDiskPrompt
));
1256 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
1257 return ERROR_INVALID_PARAMETER
;
1259 if (dwOptions
!= MSICODE_PRODUCT
&& dwOptions
!= MSICODE_PATCH
)
1260 return ERROR_INVALID_PARAMETER
;
1262 if ((szVolumeLabel
&& !*szVolumeLabel
) || (szDiskPrompt
&& !*szDiskPrompt
))
1263 return ERROR_INVALID_PARAMETER
;
1265 if ((dwContext
& MSIINSTALLCONTEXT_MACHINE
) && szUserSid
)
1266 return ERROR_INVALID_PARAMETER
;
1268 if (dwOptions
& MSICODE_PATCH
)
1270 FIXME("Unhandled options MSICODE_PATCH\n");
1271 return ERROR_FUNCTION_FAILED
;
1274 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
1275 if (rc
!= ERROR_SUCCESS
)
1278 OpenMediaSubkey(sourcekey
, &mediakey
, TRUE
);
1280 sprintfW(szIndex
, fmt
, dwDiskId
);
1283 if (szVolumeLabel
) size
+= lstrlenW(szVolumeLabel
);
1284 if (szDiskPrompt
) size
+= lstrlenW(szDiskPrompt
);
1286 size
*= sizeof(WCHAR
);
1287 buffer
= msi_alloc(size
);
1290 if (szVolumeLabel
) lstrcpyW(buffer
, szVolumeLabel
);
1291 lstrcatW(buffer
, szSemiColon
);
1292 if (szDiskPrompt
) lstrcatW(buffer
, szDiskPrompt
);
1294 RegSetValueExW(mediakey
, szIndex
, 0, REG_SZ
, (LPBYTE
)buffer
, size
);
1297 RegCloseKey(sourcekey
);
1298 RegCloseKey(mediakey
);
1300 return ERROR_SUCCESS
;
1303 /******************************************************************
1304 * MsiSourceListClearAllA (MSI.@)
1306 UINT WINAPI
MsiSourceListClearAllA( LPCSTR szProduct
, LPCSTR szUserName
, DWORD dwReserved
)
1308 FIXME("(%s %s %d)\n", debugstr_a(szProduct
), debugstr_a(szUserName
), dwReserved
);
1309 return ERROR_SUCCESS
;
1312 /******************************************************************
1313 * MsiSourceListClearAllW (MSI.@)
1315 UINT WINAPI
MsiSourceListClearAllW( LPCWSTR szProduct
, LPCWSTR szUserName
, DWORD dwReserved
)
1317 FIXME("(%s %s %d)\n", debugstr_w(szProduct
), debugstr_w(szUserName
), dwReserved
);
1318 return ERROR_SUCCESS
;
1321 /******************************************************************
1322 * MsiSourceListClearAllExA (MSI.@)
1324 UINT WINAPI
MsiSourceListClearAllExA( LPCSTR szProduct
, LPCSTR szUserSid
,
1325 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1327 FIXME("(%s %s %d %08x)\n", debugstr_a(szProduct
), debugstr_a(szUserSid
),
1328 dwContext
, dwOptions
);
1329 return ERROR_SUCCESS
;
1332 /******************************************************************
1333 * MsiSourceListClearAllExW (MSI.@)
1335 UINT WINAPI
MsiSourceListClearAllExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
1336 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
)
1338 FIXME("(%s %s %d %08x)\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
1339 dwContext
, dwOptions
);
1340 return ERROR_SUCCESS
;
1343 /******************************************************************
1344 * MsiSourceListClearSourceA (MSI.@)
1346 UINT WINAPI
MsiSourceListClearSourceA(LPCSTR szProductCodeOrPatchCode
, LPCSTR szUserSid
,
1347 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1350 FIXME("(%s %s %x %x %s)\n", debugstr_a(szProductCodeOrPatchCode
), debugstr_a(szUserSid
),
1351 dwContext
, dwOptions
, debugstr_a(szSource
));
1352 return ERROR_SUCCESS
;
1355 /******************************************************************
1356 * MsiSourceListClearSourceW (MSI.@)
1358 UINT WINAPI
MsiSourceListClearSourceW(LPCWSTR szProductCodeOrPatchCode
, LPCWSTR szUserSid
,
1359 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
1362 FIXME("(%s %s %x %x %s)\n", debugstr_w(szProductCodeOrPatchCode
), debugstr_w(szUserSid
),
1363 dwContext
, dwOptions
, debugstr_w(szSource
));
1364 return ERROR_SUCCESS
;