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 * MsiSourceListEnumSourcesA (MSI.@)
146 UINT WINAPI
MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch
, LPCSTR szUserSid
,
147 MSIINSTALLCONTEXT dwContext
,
148 DWORD dwOptions
, DWORD dwIndex
,
149 LPSTR szSource
, LPDWORD pcchSource
)
151 LPWSTR product
= NULL
;
152 LPWSTR usersid
= NULL
;
153 LPWSTR source
= NULL
;
155 UINT r
= ERROR_INVALID_PARAMETER
;
156 static int index
= 0;
158 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_a(szProductCodeOrPatch
),
159 debugstr_a(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
164 if (szSource
&& !pcchSource
)
167 if (dwIndex
!= index
)
170 if (szProductCodeOrPatch
) product
= strdupAtoW(szProductCodeOrPatch
);
171 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
173 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
174 dwIndex
, NULL
, &len
);
175 if (r
!= ERROR_SUCCESS
)
178 source
= msi_alloc(++len
* sizeof(WCHAR
));
181 r
= ERROR_OUTOFMEMORY
;
186 r
= MsiSourceListEnumSourcesW(product
, usersid
, dwContext
, dwOptions
,
187 dwIndex
, source
, &len
);
188 if (r
!= ERROR_SUCCESS
)
191 len
= WideCharToMultiByte(CP_ACP
, 0, source
, -1, NULL
, 0, NULL
, NULL
);
192 if (pcchSource
&& *pcchSource
>= len
)
193 WideCharToMultiByte(CP_ACP
, 0, source
, -1, szSource
, len
, NULL
, NULL
);
198 *pcchSource
= len
- 1;
205 if (r
== ERROR_SUCCESS
)
207 if (szSource
|| !pcchSource
) index
++;
209 else if (dwIndex
> index
)
215 /******************************************************************
216 * MsiSourceListEnumSourcesW (MSI.@)
218 UINT WINAPI
MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch
, LPCWSTR szUserSid
,
219 MSIINSTALLCONTEXT dwContext
,
220 DWORD dwOptions
, DWORD dwIndex
,
221 LPWSTR szSource
, LPDWORD pcchSource
)
223 WCHAR squished_pc
[GUID_SIZE
];
228 UINT r
= ERROR_INVALID_PARAMETER
;
229 static int index
= 0;
231 static const WCHAR format
[] = {'%','d',0};
233 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch
),
234 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwIndex
, szSource
, pcchSource
);
239 if (!szProductCodeOrPatch
|| !squash_guid(szProductCodeOrPatch
, squished_pc
))
242 if (szSource
&& !pcchSource
)
245 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
248 if ((dwOptions
& MSISOURCETYPE_NETWORK
) && (dwOptions
& MSISOURCETYPE_URL
))
251 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
254 if (dwIndex
!= index
)
257 r
= OpenSourceKey(szProductCodeOrPatch
, &source
,
258 dwOptions
, dwContext
, FALSE
);
259 if (r
!= ERROR_SUCCESS
)
262 if (dwOptions
& MSISOURCETYPE_NETWORK
)
263 r
= OpenNetworkSubkey(source
, &subkey
, FALSE
);
264 else if (dwOptions
& MSISOURCETYPE_URL
)
265 r
= OpenURLSubkey(source
, &subkey
, FALSE
);
267 if (r
!= ERROR_SUCCESS
)
269 r
= ERROR_NO_MORE_ITEMS
;
273 sprintfW(name
, format
, dwIndex
+ 1);
275 res
= RegQueryValueExW(subkey
, name
, 0, 0, (LPBYTE
)szSource
, pcchSource
);
276 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
277 r
= ERROR_NO_MORE_ITEMS
;
283 if (r
== ERROR_SUCCESS
)
285 if (szSource
|| !pcchSource
) index
++;
287 else if (dwIndex
> index
)
293 /******************************************************************
294 * MsiSourceListGetInfoA (MSI.@)
296 UINT WINAPI
MsiSourceListGetInfoA( LPCSTR szProduct
, LPCSTR szUserSid
,
297 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
298 LPCSTR szProperty
, LPSTR szValue
,
302 LPWSTR product
= NULL
;
303 LPWSTR usersid
= NULL
;
304 LPWSTR property
= NULL
;
308 if (szValue
&& !pcchValue
)
309 return ERROR_INVALID_PARAMETER
;
311 if (szProduct
) product
= strdupAtoW(szProduct
);
312 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
313 if (szProperty
) property
= strdupAtoW(szProperty
);
315 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
316 property
, NULL
, &len
);
317 if (ret
!= ERROR_SUCCESS
)
320 value
= msi_alloc(++len
* sizeof(WCHAR
));
322 return ERROR_OUTOFMEMORY
;
325 ret
= MsiSourceListGetInfoW(product
, usersid
, dwContext
, dwOptions
,
326 property
, value
, &len
);
327 if (ret
!= ERROR_SUCCESS
)
330 len
= WideCharToMultiByte(CP_ACP
, 0, value
, -1, NULL
, 0, NULL
, NULL
);
331 if (*pcchValue
>= len
)
332 WideCharToMultiByte(CP_ACP
, 0, value
, -1, szValue
, len
, NULL
, NULL
);
334 ret
= ERROR_MORE_DATA
;
336 *pcchValue
= len
- 1;
346 /******************************************************************
347 * MsiSourceListGetInfoW (MSI.@)
349 UINT WINAPI
MsiSourceListGetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
350 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
351 LPCWSTR szProperty
, LPWSTR szValue
,
354 WCHAR squished_pc
[GUID_SIZE
];
355 HKEY sourcekey
, media
;
360 static const WCHAR mediapack
[] = {
361 'M','e','d','i','a','P','a','c','k','a','g','e',0};
363 TRACE("%s %s\n", debugstr_w(szProduct
), debugstr_w(szProperty
));
365 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
366 return ERROR_INVALID_PARAMETER
;
368 if (szValue
&& !pcchValue
)
369 return ERROR_INVALID_PARAMETER
;
371 if (dwContext
!= MSIINSTALLCONTEXT_USERMANAGED
&&
372 dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
&&
373 dwContext
!= MSIINSTALLCONTEXT_MACHINE
)
374 return ERROR_INVALID_PARAMETER
;
377 return ERROR_INVALID_PARAMETER
;
380 FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid
));
382 if (dwContext
!= MSIINSTALLCONTEXT_USERUNMANAGED
)
383 FIXME("Unhandled context %d\n", dwContext
);
385 rc
= OpenSourceKey(szProduct
, &sourcekey
, dwOptions
, dwContext
, FALSE
);
386 if (rc
!= ERROR_SUCCESS
)
389 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
390 !lstrcmpW(szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
392 rc
= OpenMediaSubkey(sourcekey
, &media
, FALSE
);
393 if (rc
!= ERROR_SUCCESS
)
395 RegCloseKey(sourcekey
);
396 return ERROR_SUCCESS
;
399 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
400 szProperty
= mediapack
;
402 RegQueryValueExW(media
, szProperty
, 0, 0, (LPBYTE
)szValue
, pcchValue
);
405 else if (!lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) ||
406 !lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
408 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
410 if (rc
!= ERROR_SUCCESS
)
412 RegCloseKey(sourcekey
);
413 return ERROR_SUCCESS
;
416 source
= msi_alloc(size
);
417 RegQueryValueExW(sourcekey
, INSTALLPROPERTY_LASTUSEDSOURCEW
,
418 0, 0, (LPBYTE
)source
, &size
);
423 RegCloseKey(sourcekey
);
424 return ERROR_SUCCESS
;
427 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDTYPEW
))
429 if (*source
!= 'n' && *source
!= 'u' && *source
!= 'm')
432 RegCloseKey(sourcekey
);
433 return ERROR_SUCCESS
;
441 ptr
= strrchrW(source
, ';');
450 if (lstrlenW(ptr
) < *pcchValue
)
451 lstrcpyW(szValue
, ptr
);
453 rc
= ERROR_MORE_DATA
;
456 *pcchValue
= lstrlenW(ptr
);
459 else if (strcmpW(INSTALLPROPERTY_PACKAGENAMEW
, szProperty
)==0)
461 *pcchValue
= *pcchValue
* sizeof(WCHAR
);
462 rc
= RegQueryValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0, 0,
463 (LPBYTE
)szValue
, pcchValue
);
464 if (rc
!= ERROR_SUCCESS
&& rc
!= ERROR_MORE_DATA
)
472 *pcchValue
= (*pcchValue
- 1) / sizeof(WCHAR
);
474 szValue
[*pcchValue
] = '\0';
479 FIXME("Unknown property %s\n",debugstr_w(szProperty
));
480 rc
= ERROR_UNKNOWN_PROPERTY
;
483 RegCloseKey(sourcekey
);
487 /******************************************************************
488 * MsiSourceListSetInfoA (MSI.@)
490 UINT WINAPI
MsiSourceListSetInfoA(LPCSTR szProduct
, LPCSTR szUserSid
,
491 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
492 LPCSTR szProperty
, LPCSTR szValue
)
495 LPWSTR product
= NULL
;
496 LPWSTR usersid
= NULL
;
497 LPWSTR property
= NULL
;
500 if (szProduct
) product
= strdupAtoW(szProduct
);
501 if (szUserSid
) usersid
= strdupAtoW(szUserSid
);
502 if (szProperty
) property
= strdupAtoW(szProperty
);
503 if (szValue
) value
= strdupAtoW(szValue
);
505 ret
= MsiSourceListSetInfoW(product
, usersid
, dwContext
, dwOptions
,
516 static UINT
set_last_used_source(HKEY source
, LPCWSTR product
, LPCWSTR usersid
,
517 MSIINSTALLCONTEXT context
, DWORD options
,
526 static const WCHAR format
[] = {'%','c',';','%','i',';','%','s',0};
528 if (options
& MSISOURCETYPE_NETWORK
)
530 else if (options
& MSISOURCETYPE_URL
)
533 return ERROR_INVALID_PARAMETER
;
535 /* make sure the source is registered */
536 r
= MsiSourceListAddSourceExW(product
, usersid
, context
,
538 if (r
!= ERROR_SUCCESS
)
541 while ((r
= MsiSourceListEnumSourcesW(product
, usersid
, context
, options
,
542 index
, NULL
, NULL
)) == ERROR_SUCCESS
)
545 if (r
!= ERROR_NO_MORE_ITEMS
)
548 size
= (lstrlenW(format
) + lstrlenW(value
) + 7) * sizeof(WCHAR
);
549 buffer
= msi_alloc(size
);
551 return ERROR_OUTOFMEMORY
;
553 sprintfW(buffer
, format
, typechar
, index
, value
);
555 size
= (lstrlenW(buffer
) + 1) * sizeof(WCHAR
);
556 r
= RegSetValueExW(source
, INSTALLPROPERTY_LASTUSEDSOURCEW
, 0,
557 REG_SZ
, (LPBYTE
)buffer
, size
);
563 /******************************************************************
564 * MsiSourceListSetInfoW (MSI.@)
566 UINT WINAPI
MsiSourceListSetInfoW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
567 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
,
568 LPCWSTR szProperty
, LPCWSTR szValue
)
570 WCHAR squished_pc
[GUID_SIZE
];
571 HKEY sourcekey
, media
;
575 static const WCHAR media_package
[] = {
576 'M','e','d','i','a','P','a','c','k','a','g','e',0
579 TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
580 dwContext
, dwOptions
, debugstr_w(szProperty
), debugstr_w(szValue
));
582 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
583 return ERROR_INVALID_PARAMETER
;
586 return ERROR_INVALID_PARAMETER
;
589 return ERROR_UNKNOWN_PROPERTY
;
591 if (dwContext
== MSIINSTALLCONTEXT_MACHINE
&& szUserSid
)
592 return ERROR_INVALID_PARAMETER
;
594 if (dwOptions
& MSICODE_PATCH
)
596 FIXME("Unhandled options MSICODE_PATCH\n");
597 return ERROR_UNKNOWN_PATCH
;
600 property
= szProperty
;
601 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
))
602 property
= media_package
;
604 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
605 if (rc
!= ERROR_SUCCESS
)
608 if (lstrcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
) &&
609 dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
))
611 RegCloseKey(sourcekey
);
612 return ERROR_INVALID_PARAMETER
;
615 if (!lstrcmpW(szProperty
, INSTALLPROPERTY_MEDIAPACKAGEPATHW
) ||
616 !lstrcmpW(szProperty
, INSTALLPROPERTY_DISKPROMPTW
))
618 rc
= OpenMediaSubkey(sourcekey
, &media
, TRUE
);
619 if (rc
== ERROR_SUCCESS
)
621 rc
= msi_reg_set_val_str(media
, property
, szValue
);
625 else if (strcmpW(INSTALLPROPERTY_PACKAGENAMEW
, szProperty
)==0)
627 DWORD size
= lstrlenW(szValue
)*sizeof(WCHAR
);
628 rc
= RegSetValueExW(sourcekey
, INSTALLPROPERTY_PACKAGENAMEW
, 0,
629 REG_SZ
, (const BYTE
*)szValue
, size
);
630 if (rc
!= ERROR_SUCCESS
)
631 rc
= ERROR_UNKNOWN_PROPERTY
;
633 else if (strcmpW(szProperty
, INSTALLPROPERTY_LASTUSEDSOURCEW
)==0)
634 rc
= set_last_used_source(sourcekey
, szProduct
, szUserSid
, dwContext
,
637 rc
= ERROR_UNKNOWN_PROPERTY
;
639 RegCloseKey(sourcekey
);
644 /******************************************************************
645 * MsiSourceListAddSourceW (MSI.@)
647 UINT WINAPI
MsiSourceListAddSourceW( LPCWSTR szProduct
, LPCWSTR szUserName
,
648 DWORD dwReserved
, LPCWSTR szSource
)
651 LPWSTR sidstr
= NULL
;
655 TRACE("%s %s %s\n", debugstr_w(szProduct
), debugstr_w(szUserName
), debugstr_w(szSource
));
657 if (LookupAccountNameW(NULL
, szUserName
, NULL
, &sidsize
, NULL
, &domsize
, NULL
))
659 PSID psid
= msi_alloc(sidsize
);
661 if (LookupAccountNameW(NULL
, szUserName
, psid
, &sidsize
, NULL
, &domsize
, NULL
))
662 ConvertSidToStringSidW(psid
, &sidstr
);
667 ret
= MsiSourceListAddSourceExW(szProduct
, sidstr
,
668 MSIINSTALLCONTEXT_USERMANAGED
, MSISOURCETYPE_NETWORK
, szSource
, 0);
676 /******************************************************************
677 * MsiSourceListAddSourceA (MSI.@)
679 UINT WINAPI
MsiSourceListAddSourceA( LPCSTR szProduct
, LPCSTR szUserName
,
680 DWORD dwReserved
, LPCSTR szSource
)
687 szwproduct
= strdupAtoW( szProduct
);
688 szwusername
= strdupAtoW( szUserName
);
689 szwsource
= strdupAtoW( szSource
);
691 ret
= MsiSourceListAddSourceW(szwproduct
, szwusername
, 0, szwsource
);
693 msi_free(szwproduct
);
694 msi_free(szwusername
);
700 /******************************************************************
701 * MsiSourceListAddSourceExA (MSI.@)
703 UINT WINAPI
MsiSourceListAddSourceExA(LPCSTR szProduct
, LPCSTR szUserSid
,
704 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCSTR szSource
, DWORD dwIndex
)
707 LPWSTR product
, usersid
, source
;
709 product
= strdupAtoW(szProduct
);
710 usersid
= strdupAtoW(szUserSid
);
711 source
= strdupAtoW(szSource
);
713 ret
= MsiSourceListAddSourceExW(product
, usersid
, dwContext
,
714 dwOptions
, source
, dwIndex
);
723 static void free_source_list(struct list
*sourcelist
)
725 while (!list_empty(sourcelist
))
727 media_info
*info
= LIST_ENTRY(list_head(sourcelist
), media_info
, entry
);
728 list_remove(&info
->entry
);
729 msi_free(info
->path
);
734 static void add_source_to_list(struct list
*sourcelist
, media_info
*info
)
738 static const WCHAR fmt
[] = {'%','i',0};
740 if (list_empty(sourcelist
))
742 list_add_head(sourcelist
, &info
->entry
);
746 LIST_FOR_EACH_ENTRY(iter
, sourcelist
, media_info
, entry
)
748 if (!found
&& info
->index
< iter
->index
)
751 list_add_before(&iter
->entry
, &info
->entry
);
754 /* update the rest of the list */
756 sprintfW(iter
->szIndex
, fmt
, ++iter
->index
);
760 list_add_after(&iter
->entry
, &info
->entry
);
763 static UINT
fill_source_list(struct list
*sourcelist
, HKEY sourcekey
, DWORD
*count
)
765 UINT r
= ERROR_SUCCESS
;
768 DWORD size
, val_size
;
773 while (r
== ERROR_SUCCESS
)
775 size
= sizeof(name
) / sizeof(name
[0]);
776 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
, NULL
, NULL
, &val_size
);
777 if (r
!= ERROR_SUCCESS
)
780 entry
= msi_alloc(sizeof(media_info
));
784 entry
->path
= msi_alloc(val_size
);
791 lstrcpyW(entry
->szIndex
, name
);
792 entry
->index
= atoiW(name
);
795 r
= RegEnumValueW(sourcekey
, index
, name
, &size
, NULL
,
796 NULL
, (LPBYTE
)entry
->path
, &val_size
);
797 if (r
!= ERROR_SUCCESS
)
799 msi_free(entry
->path
);
805 add_source_to_list(sourcelist
, entry
);
810 free_source_list(sourcelist
);
811 return ERROR_OUTOFMEMORY
;
814 /******************************************************************
815 * MsiSourceListAddSourceExW (MSI.@)
817 UINT WINAPI
MsiSourceListAddSourceExW( LPCWSTR szProduct
, LPCWSTR szUserSid
,
818 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, LPCWSTR szSource
,
824 struct list sourcelist
;
826 WCHAR squished_pc
[GUID_SIZE
];
832 static const WCHAR fmt
[] = {'%','i',0};
833 static const WCHAR one
[] = {'1',0};
834 static const WCHAR backslash
[] = {'\\',0};
835 static const WCHAR forwardslash
[] = {'/',0};
837 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct
), debugstr_w(szUserSid
),
838 dwContext
, dwOptions
, debugstr_w(szSource
), dwIndex
);
840 if (!szProduct
|| !squash_guid(szProduct
, squished_pc
))
841 return ERROR_INVALID_PARAMETER
;
843 if (!szSource
|| !*szSource
)
844 return ERROR_INVALID_PARAMETER
;
846 if (!(dwOptions
& (MSISOURCETYPE_NETWORK
| MSISOURCETYPE_URL
)))
847 return ERROR_INVALID_PARAMETER
;
849 if (dwOptions
& MSICODE_PATCH
)
851 FIXME("Unhandled options MSICODE_PATCH\n");
852 return ERROR_FUNCTION_FAILED
;
855 if (szUserSid
&& (dwContext
& MSIINSTALLCONTEXT_MACHINE
))
856 return ERROR_INVALID_PARAMETER
;
858 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, FALSE
);
859 if (rc
!= ERROR_SUCCESS
)
862 if (dwOptions
& MSISOURCETYPE_NETWORK
)
863 rc
= OpenNetworkSubkey(sourcekey
, &typekey
, TRUE
);
864 else if (dwOptions
& MSISOURCETYPE_URL
)
865 rc
= OpenURLSubkey(sourcekey
, &typekey
, TRUE
);
866 else if (dwOptions
& MSISOURCETYPE_MEDIA
)
867 rc
= OpenMediaSubkey(sourcekey
, &typekey
, TRUE
);
870 ERR("unknown media type: %08x\n", dwOptions
);
871 RegCloseKey(sourcekey
);
872 return ERROR_FUNCTION_FAILED
;
875 postfix
= (dwOptions
& MSISOURCETYPE_NETWORK
) ? backslash
: forwardslash
;
876 if (szSource
[lstrlenW(szSource
) - 1] == *postfix
)
877 source
= strdupW(szSource
);
880 size
= lstrlenW(szSource
) + 2;
881 source
= msi_alloc(size
* sizeof(WCHAR
));
882 lstrcpyW(source
, szSource
);
883 lstrcatW(source
, postfix
);
886 list_init(&sourcelist
);
887 rc
= fill_source_list(&sourcelist
, typekey
, &count
);
888 if (rc
!= ERROR_NO_MORE_ITEMS
)
891 size
= (lstrlenW(source
) + 1) * sizeof(WCHAR
);
895 rc
= RegSetValueExW(typekey
, one
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
898 else if (dwIndex
> count
)
900 sprintfW(name
, fmt
, count
+ 1);
901 rc
= RegSetValueExW(typekey
, name
, 0, REG_EXPAND_SZ
, (LPBYTE
)source
, size
);
906 /* add to the end of the list */
910 sprintfW(name
, fmt
, dwIndex
);
911 info
= msi_alloc(sizeof(media_info
));
914 rc
= ERROR_OUTOFMEMORY
;
918 info
->path
= strdupW(source
);
919 lstrcpyW(info
->szIndex
, name
);
920 info
->index
= dwIndex
;
921 add_source_to_list(&sourcelist
, info
);
923 LIST_FOR_EACH_ENTRY(info
, &sourcelist
, media_info
, entry
)
925 size
= (lstrlenW(info
->path
) + 1) * sizeof(WCHAR
);
926 rc
= RegSetValueExW(typekey
, info
->szIndex
, 0,
927 REG_EXPAND_SZ
, (LPBYTE
)info
->path
, size
);
928 if (rc
!= ERROR_SUCCESS
)
934 free_source_list(&sourcelist
);
936 RegCloseKey(typekey
);
937 RegCloseKey(sourcekey
);
941 /******************************************************************
942 * MsiSourceListAddMediaDisk(MSI.@)
944 UINT WINAPI
MsiSourceListAddMediaDiskW(LPCWSTR szProduct
, LPCWSTR szUserSid
,
945 MSIINSTALLCONTEXT dwContext
, DWORD dwOptions
, DWORD dwDiskId
,
946 LPCWSTR szVolumeLabel
, LPCWSTR szDiskPrompt
)
952 static const WCHAR fmt
[] = {'%','i',0};
953 static const WCHAR disk_fmt
[] = {'%','s',';','%','s',0};
954 static const WCHAR empty
[1] = {0};
959 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct
),
960 debugstr_w(szUserSid
), dwContext
, dwOptions
, dwDiskId
,
961 debugstr_w(szVolumeLabel
), debugstr_w(szDiskPrompt
));
963 if (!szProduct
|| lstrlenW(szProduct
) > 39)
964 return ERROR_INVALID_PARAMETER
;
966 if (dwOptions
& MSICODE_PATCH
)
968 FIXME("Unhandled options MSICODE_PATCH\n");
969 return ERROR_FUNCTION_FAILED
;
973 FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid
));
975 if (dwContext
== MSIINSTALLCONTEXT_USERUNMANAGED
)
976 FIXME("Unknown context MSIINSTALLCONTEXT_USERUNMANAGED\n");
978 rc
= OpenSourceKey(szProduct
, &sourcekey
, MSICODE_PRODUCT
, dwContext
, TRUE
);
979 if (rc
!= ERROR_SUCCESS
)
980 return ERROR_UNKNOWN_PRODUCT
;
982 OpenMediaSubkey(sourcekey
,&mediakey
,TRUE
);
984 sprintfW(szIndex
,fmt
,dwDiskId
);
989 size
+=lstrlenW(szVolumeLabel
);
996 size
+=lstrlenW(szDiskPrompt
);
1002 size
*=sizeof(WCHAR
);
1004 buffer
= msi_alloc(size
);
1005 sprintfW(buffer
,disk_fmt
,pt1
,pt2
);
1007 RegSetValueExW(mediakey
, szIndex
, 0, REG_SZ
, (LPBYTE
)buffer
, size
);
1010 RegCloseKey(sourcekey
);
1011 RegCloseKey(mediakey
);
1013 return ERROR_SUCCESS
;
1016 /******************************************************************
1017 * MsiSourceListClearAllA (MSI.@)
1019 UINT WINAPI
MsiSourceListClearAllA( LPCSTR szProduct
, LPCSTR szUserName
, DWORD dwReserved
)
1021 FIXME("(%s %s %d)\n", debugstr_a(szProduct
), debugstr_a(szUserName
), dwReserved
);
1022 return ERROR_SUCCESS
;
1025 /******************************************************************
1026 * MsiSourceListClearAllW (MSI.@)
1028 UINT WINAPI
MsiSourceListClearAllW( LPCWSTR szProduct
, LPCWSTR szUserName
, DWORD dwReserved
)
1030 FIXME("(%s %s %d)\n", debugstr_w(szProduct
), debugstr_w(szUserName
), dwReserved
);
1031 return ERROR_SUCCESS
;