2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
31 #include "wine/debug.h"
38 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi);
44 * These apis are defined in MSI 3.0
47 typedef struct tagMediaInfo
55 static UINT OpenSourceKey(LPCWSTR szProduct, HKEY* key, DWORD dwOptions,
56 MSIINSTALLCONTEXT context, BOOL create)
59 UINT rc = ERROR_FUNCTION_FAILED;
60 static const WCHAR szSourceList[] = {'S','o','u','r','c','e','L','i','s','t',0};
62 if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
64 if (dwOptions & MSICODE_PATCH)
65 rc = MSIREG_OpenUserPatchesKey(szProduct, &rootkey, create);
67 rc = MSIREG_OpenUserProductsKey(szProduct, &rootkey, create);
69 else if (context == MSIINSTALLCONTEXT_USERMANAGED)
71 if (dwOptions & MSICODE_PATCH)
72 rc = MSIREG_OpenUserPatchesKey(szProduct, &rootkey, create);
74 rc = MSIREG_OpenLocalManagedProductKey(szProduct, &rootkey, create);
76 else if (context == MSIINSTALLCONTEXT_MACHINE)
78 if (dwOptions & MSICODE_PATCH)
79 rc = MSIREG_OpenPatchesKey(szProduct, &rootkey, create);
81 rc = MSIREG_OpenLocalClassesProductKey(szProduct, &rootkey, create);
84 if (rc != ERROR_SUCCESS)
86 if (dwOptions & MSICODE_PATCH)
87 return ERROR_UNKNOWN_PATCH;
89 return ERROR_UNKNOWN_PRODUCT;
93 rc = RegCreateKeyW(rootkey, szSourceList, key);
96 rc = RegOpenKeyW(rootkey,szSourceList, key);
97 if (rc != ERROR_SUCCESS)
98 rc = ERROR_BAD_CONFIGURATION;
104 static UINT OpenMediaSubkey(HKEY rootkey, HKEY *key, BOOL create)
107 static const WCHAR media[] = {'M','e','d','i','a',0};
110 rc = RegCreateKeyW(rootkey, media, key);
112 rc = RegOpenKeyW(rootkey,media, key);
117 static UINT OpenNetworkSubkey(HKEY rootkey, HKEY *key, BOOL create)
120 static const WCHAR net[] = {'N','e','t',0};
123 rc = RegCreateKeyW(rootkey, net, key);
125 rc = RegOpenKeyW(rootkey, net, key);
130 static UINT OpenURLSubkey(HKEY rootkey, HKEY *key, BOOL create)
133 static const WCHAR URL[] = {'U','R','L',0};
136 rc = RegCreateKeyW(rootkey, URL, key);
138 rc = RegOpenKeyW(rootkey, URL, key);
143 /******************************************************************
144 * MsiSourceListEnumMediaDisksA (MSI.@)
146 UINT WINAPI MsiSourceListEnumMediaDisksA(LPCSTR szProductCodeOrPatchCode,
147 LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
148 DWORD dwOptions, DWORD dwIndex, LPWORD pdwDiskId,
149 LPSTR szVolumeLabel, LPDWORD pcchVolumeLabel,
150 LPSTR szDiskPrompt, LPDWORD pcchDiskPrompt)
152 LPWSTR product = NULL;
153 LPWSTR usersid = NULL;
154 LPWSTR volume = NULL;
155 LPWSTR prompt = NULL;
156 DWORD volumesz, promptsz;
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 volumesz = WideCharToMultiByte(CP_ACP, 0, volume, -1, szVolumeLabel,
187 *pcchVolumeLabel + 1, NULL, NULL);
190 promptsz = 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, LPWORD pdwDiskId,
208 LPWSTR szVolumeLabel, LPDWORD pcchVolumeLabel,
209 LPWSTR szDiskPrompt, LPDWORD pcchDiskPrompt)
211 WCHAR squished_pc[GUID_SIZE];
216 DWORD valuesz, datasz = 0;
221 static int index = 0;
223 TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p)\n", debugstr_w(szProductCodeOrPatchCode),
224 debugstr_w(szUserSid), dwContext, dwOptions, dwIndex, szVolumeLabel,
225 pcchVolumeLabel, szDiskPrompt, pcchDiskPrompt);
227 if (!szProductCodeOrPatchCode ||
228 !squash_guid(szProductCodeOrPatchCode, squished_pc))
229 return ERROR_INVALID_PARAMETER;
231 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
232 return ERROR_INVALID_PARAMETER;
234 if (dwOptions != MSICODE_PRODUCT && dwOptions != MSICODE_PATCH)
235 return ERROR_INVALID_PARAMETER;
237 if (szDiskPrompt && !pcchDiskPrompt)
238 return ERROR_INVALID_PARAMETER;
243 if (dwIndex != index)
244 return ERROR_INVALID_PARAMETER;
246 r = OpenSourceKey(szProductCodeOrPatchCode, &source,
247 dwOptions, dwContext, FALSE);
248 if (r != ERROR_SUCCESS)
251 r = OpenMediaSubkey(source, &media, FALSE);
252 if (r != ERROR_SUCCESS)
255 return ERROR_NO_MORE_ITEMS;
258 if (!pcchVolumeLabel && !pcchDiskPrompt)
260 r = RegEnumValueW(media, dwIndex, NULL, NULL, NULL,
265 res = RegQueryInfoKeyW(media, NULL, NULL, NULL, NULL, NULL,
266 NULL, &numvals, &valuesz, &datasz, NULL, NULL);
267 if (res != ERROR_SUCCESS)
269 r = ERROR_BAD_CONFIGURATION;
273 value = msi_alloc(++valuesz * sizeof(WCHAR));
274 data = msi_alloc(++datasz * sizeof(WCHAR));
277 r = ERROR_OUTOFMEMORY;
281 r = RegEnumValueW(media, dwIndex, value, &valuesz,
282 NULL, &type, (LPBYTE)data, &datasz);
283 if (r != ERROR_SUCCESS)
287 *pdwDiskId = atolW(value);
289 ptr = strchrW(data, ';');
297 size = lstrlenW(data);
298 if (size >= *pcchVolumeLabel)
300 else if (szVolumeLabel)
301 lstrcpyW(szVolumeLabel, data);
303 *pcchVolumeLabel = size;
312 size = lstrlenW(data);
313 if (size >= *pcchDiskPrompt)
315 else if (szDiskPrompt)
316 lstrcpyW(szDiskPrompt, data);
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 int 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 squished_pc[GUID_SIZE];
416 UINT r = ERROR_INVALID_PARAMETER;
417 static int index = 0;
419 static const WCHAR format[] = {'%','d',0};
421 TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch),
422 debugstr_w(szUserSid), dwContext, dwOptions, dwIndex, szSource, pcchSource);
427 if (!szProductCodeOrPatch || !squash_guid(szProductCodeOrPatch, squished_pc))
430 if (szSource && !pcchSource)
433 if (!(dwOptions & (MSISOURCETYPE_NETWORK | MSISOURCETYPE_URL)))
436 if ((dwOptions & MSISOURCETYPE_NETWORK) && (dwOptions & MSISOURCETYPE_URL))
439 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
442 if (dwIndex != index)
445 r = OpenSourceKey(szProductCodeOrPatch, &source,
446 dwOptions, dwContext, FALSE);
447 if (r != ERROR_SUCCESS)
450 if (dwOptions & MSISOURCETYPE_NETWORK)
451 r = OpenNetworkSubkey(source, &subkey, FALSE);
452 else if (dwOptions & MSISOURCETYPE_URL)
453 r = OpenURLSubkey(source, &subkey, FALSE);
455 if (r != ERROR_SUCCESS)
457 r = ERROR_NO_MORE_ITEMS;
461 sprintfW(name, format, dwIndex + 1);
463 res = RegQueryValueExW(subkey, name, 0, 0, (LPBYTE)szSource, pcchSource);
464 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
465 r = ERROR_NO_MORE_ITEMS;
471 if (r == ERROR_SUCCESS)
473 if (szSource || !pcchSource) index++;
475 else if (dwIndex > index)
481 /******************************************************************
482 * MsiSourceListGetInfoA (MSI.@)
484 UINT WINAPI MsiSourceListGetInfoA( LPCSTR szProduct, LPCSTR szUserSid,
485 MSIINSTALLCONTEXT dwContext, DWORD dwOptions,
486 LPCSTR szProperty, LPSTR szValue,
490 LPWSTR product = NULL;
491 LPWSTR usersid = NULL;
492 LPWSTR property = NULL;
496 if (szValue && !pcchValue)
497 return ERROR_INVALID_PARAMETER;
499 if (szProduct) product = strdupAtoW(szProduct);
500 if (szUserSid) usersid = strdupAtoW(szUserSid);
501 if (szProperty) property = strdupAtoW(szProperty);
503 ret = MsiSourceListGetInfoW(product, usersid, dwContext, dwOptions,
504 property, NULL, &len);
505 if (ret != ERROR_SUCCESS)
508 value = msi_alloc(++len * sizeof(WCHAR));
510 return ERROR_OUTOFMEMORY;
513 ret = MsiSourceListGetInfoW(product, usersid, dwContext, dwOptions,
514 property, value, &len);
515 if (ret != ERROR_SUCCESS)
518 len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
519 if (*pcchValue >= len)
520 WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
522 ret = ERROR_MORE_DATA;
524 *pcchValue = len - 1;
534 /******************************************************************
535 * MsiSourceListGetInfoW (MSI.@)
537 UINT WINAPI MsiSourceListGetInfoW( LPCWSTR szProduct, LPCWSTR szUserSid,
538 MSIINSTALLCONTEXT dwContext, DWORD dwOptions,
539 LPCWSTR szProperty, LPWSTR szValue,
542 WCHAR squished_pc[GUID_SIZE];
543 HKEY sourcekey, media;
548 static const WCHAR mediapack[] = {
549 'M','e','d','i','a','P','a','c','k','a','g','e',0};
551 TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szProperty));
553 if (!szProduct || !squash_guid(szProduct, squished_pc))
554 return ERROR_INVALID_PARAMETER;
556 if (szValue && !pcchValue)
557 return ERROR_INVALID_PARAMETER;
559 if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
560 dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
561 dwContext != MSIINSTALLCONTEXT_MACHINE)
562 return ERROR_INVALID_PARAMETER;
565 return ERROR_INVALID_PARAMETER;
568 FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid));
570 if (dwContext != MSIINSTALLCONTEXT_USERUNMANAGED)
571 FIXME("Unhandled context %d\n", dwContext);
573 rc = OpenSourceKey(szProduct, &sourcekey, dwOptions, dwContext, FALSE);
574 if (rc != ERROR_SUCCESS)
577 if (!lstrcmpW(szProperty, INSTALLPROPERTY_MEDIAPACKAGEPATHW) ||
578 !lstrcmpW(szProperty, INSTALLPROPERTY_DISKPROMPTW))
580 rc = OpenMediaSubkey(sourcekey, &media, FALSE);
581 if (rc != ERROR_SUCCESS)
583 RegCloseKey(sourcekey);
584 return ERROR_SUCCESS;
587 if (!lstrcmpW(szProperty, INSTALLPROPERTY_MEDIAPACKAGEPATHW))
588 szProperty = mediapack;
590 RegQueryValueExW(media, szProperty, 0, 0, (LPBYTE)szValue, pcchValue);
593 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_LASTUSEDSOURCEW) ||
594 !lstrcmpW(szProperty, INSTALLPROPERTY_LASTUSEDTYPEW))
596 rc = RegQueryValueExW(sourcekey, INSTALLPROPERTY_LASTUSEDSOURCEW,
598 if (rc != ERROR_SUCCESS)
600 RegCloseKey(sourcekey);
601 return ERROR_SUCCESS;
604 source = msi_alloc(size);
605 RegQueryValueExW(sourcekey, INSTALLPROPERTY_LASTUSEDSOURCEW,
606 0, 0, (LPBYTE)source, &size);
611 RegCloseKey(sourcekey);
612 return ERROR_SUCCESS;
615 if (!lstrcmpW(szProperty, INSTALLPROPERTY_LASTUSEDTYPEW))
617 if (*source != 'n' && *source != 'u' && *source != 'm')
620 RegCloseKey(sourcekey);
621 return ERROR_SUCCESS;
629 ptr = strrchrW(source, ';');
638 if (lstrlenW(ptr) < *pcchValue)
639 lstrcpyW(szValue, ptr);
641 rc = ERROR_MORE_DATA;
644 *pcchValue = lstrlenW(ptr);
647 else if (strcmpW(INSTALLPROPERTY_PACKAGENAMEW, szProperty)==0)
649 *pcchValue = *pcchValue * sizeof(WCHAR);
650 rc = RegQueryValueExW(sourcekey, INSTALLPROPERTY_PACKAGENAMEW, 0, 0,
651 (LPBYTE)szValue, pcchValue);
652 if (rc != ERROR_SUCCESS && rc != ERROR_MORE_DATA)
660 *pcchValue = (*pcchValue - 1) / sizeof(WCHAR);
662 szValue[*pcchValue] = '\0';
667 FIXME("Unknown property %s\n",debugstr_w(szProperty));
668 rc = ERROR_UNKNOWN_PROPERTY;
671 RegCloseKey(sourcekey);
675 /******************************************************************
676 * MsiSourceListSetInfoA (MSI.@)
678 UINT WINAPI MsiSourceListSetInfoA(LPCSTR szProduct, LPCSTR szUserSid,
679 MSIINSTALLCONTEXT dwContext, DWORD dwOptions,
680 LPCSTR szProperty, LPCSTR szValue)
683 LPWSTR product = NULL;
684 LPWSTR usersid = NULL;
685 LPWSTR property = NULL;
688 if (szProduct) product = strdupAtoW(szProduct);
689 if (szUserSid) usersid = strdupAtoW(szUserSid);
690 if (szProperty) property = strdupAtoW(szProperty);
691 if (szValue) value = strdupAtoW(szValue);
693 ret = MsiSourceListSetInfoW(product, usersid, dwContext, dwOptions,
704 UINT msi_set_last_used_source(LPCWSTR product, LPCWSTR usersid,
705 MSIINSTALLCONTEXT context, DWORD options,
715 static const WCHAR format[] = {'%','c',';','%','i',';','%','s',0};
717 if (options & MSISOURCETYPE_NETWORK)
719 else if (options & MSISOURCETYPE_URL)
721 else if (options & MSISOURCETYPE_MEDIA)
724 return ERROR_INVALID_PARAMETER;
726 if (!(options & MSISOURCETYPE_MEDIA))
728 r = MsiSourceListAddSourceExW(product, usersid, context,
730 if (r != ERROR_SUCCESS)
734 while ((r = MsiSourceListEnumSourcesW(product, usersid, context, options,
735 index, NULL, NULL)) == ERROR_SUCCESS)
738 if (r != ERROR_NO_MORE_ITEMS)
742 size = (lstrlenW(format) + lstrlenW(value) + 7) * sizeof(WCHAR);
743 buffer = msi_alloc(size);
745 return ERROR_OUTOFMEMORY;
747 r = OpenSourceKey(product, &source, MSICODE_PRODUCT, context, FALSE);
748 if (r != ERROR_SUCCESS)
751 sprintfW(buffer, format, typechar, index, value);
753 size = (lstrlenW(buffer) + 1) * sizeof(WCHAR);
754 r = RegSetValueExW(source, INSTALLPROPERTY_LASTUSEDSOURCEW, 0,
755 REG_SZ, (LPBYTE)buffer, size);
762 /******************************************************************
763 * MsiSourceListSetInfoW (MSI.@)
765 UINT WINAPI MsiSourceListSetInfoW( LPCWSTR szProduct, LPCWSTR szUserSid,
766 MSIINSTALLCONTEXT dwContext, DWORD dwOptions,
767 LPCWSTR szProperty, LPCWSTR szValue)
769 WCHAR squished_pc[GUID_SIZE];
770 HKEY sourcekey, media;
774 static const WCHAR media_package[] = {
775 'M','e','d','i','a','P','a','c','k','a','g','e',0
778 TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct), debugstr_w(szUserSid),
779 dwContext, dwOptions, debugstr_w(szProperty), debugstr_w(szValue));
781 if (!szProduct || !squash_guid(szProduct, squished_pc))
782 return ERROR_INVALID_PARAMETER;
785 return ERROR_INVALID_PARAMETER;
788 return ERROR_UNKNOWN_PROPERTY;
790 if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
791 return ERROR_INVALID_PARAMETER;
793 if (dwOptions & MSICODE_PATCH)
795 FIXME("Unhandled options MSICODE_PATCH\n");
796 return ERROR_UNKNOWN_PATCH;
799 property = szProperty;
800 if (!lstrcmpW(szProperty, INSTALLPROPERTY_MEDIAPACKAGEPATHW))
801 property = media_package;
803 rc = OpenSourceKey(szProduct, &sourcekey, MSICODE_PRODUCT, dwContext, FALSE);
804 if (rc != ERROR_SUCCESS)
807 if (lstrcmpW(szProperty, INSTALLPROPERTY_LASTUSEDSOURCEW) &&
808 dwOptions & (MSISOURCETYPE_NETWORK | MSISOURCETYPE_URL))
810 RegCloseKey(sourcekey);
811 return ERROR_INVALID_PARAMETER;
814 if (!lstrcmpW(szProperty, INSTALLPROPERTY_MEDIAPACKAGEPATHW) ||
815 !lstrcmpW(szProperty, INSTALLPROPERTY_DISKPROMPTW))
817 rc = OpenMediaSubkey(sourcekey, &media, TRUE);
818 if (rc == ERROR_SUCCESS)
820 rc = msi_reg_set_val_str(media, property, szValue);
824 else if (strcmpW(INSTALLPROPERTY_PACKAGENAMEW, szProperty)==0)
826 DWORD size = lstrlenW(szValue)*sizeof(WCHAR);
827 rc = RegSetValueExW(sourcekey, INSTALLPROPERTY_PACKAGENAMEW, 0,
828 REG_SZ, (const BYTE *)szValue, size);
829 if (rc != ERROR_SUCCESS)
830 rc = ERROR_UNKNOWN_PROPERTY;
832 else if (!lstrcmpW(szProperty, INSTALLPROPERTY_LASTUSEDSOURCEW))
834 if (!(dwOptions & (MSISOURCETYPE_NETWORK | MSISOURCETYPE_URL)))
835 rc = ERROR_INVALID_PARAMETER;
837 rc = msi_set_last_used_source(szProduct, szUserSid, dwContext,
841 rc = ERROR_UNKNOWN_PROPERTY;
843 RegCloseKey(sourcekey);
847 /******************************************************************
848 * MsiSourceListAddSourceW (MSI.@)
850 UINT WINAPI MsiSourceListAddSourceW( LPCWSTR szProduct, LPCWSTR szUserName,
851 DWORD dwReserved, LPCWSTR szSource)
853 WCHAR squished_pc[GUID_SIZE];
855 LPWSTR sidstr = NULL;
862 TRACE("%s %s %s\n", debugstr_w(szProduct), debugstr_w(szUserName), debugstr_w(szSource));
864 if (!szSource || !*szSource)
865 return ERROR_INVALID_PARAMETER;
868 return ERROR_INVALID_PARAMETER;
870 if (!szProduct || !squash_guid(szProduct, squished_pc))
871 return ERROR_INVALID_PARAMETER;
873 if (!szUserName || !*szUserName)
874 context = MSIINSTALLCONTEXT_MACHINE;
877 if (LookupAccountNameW(NULL, szUserName, NULL, &sidsize, NULL, &domsize, NULL))
879 PSID psid = msi_alloc(sidsize);
881 if (LookupAccountNameW(NULL, szUserName, psid, &sidsize, NULL, &domsize, NULL))
882 ConvertSidToStringSidW(psid, &sidstr);
887 r = MSIREG_OpenLocalManagedProductKey(szProduct, &hkey, FALSE);
888 if (r == ERROR_SUCCESS)
889 context = MSIINSTALLCONTEXT_USERMANAGED;
892 r = MSIREG_OpenUserProductsKey(szProduct, &hkey, FALSE);
893 if (r != ERROR_SUCCESS)
894 return ERROR_UNKNOWN_PRODUCT;
896 context = MSIINSTALLCONTEXT_USERUNMANAGED;
902 ret = MsiSourceListAddSourceExW(szProduct, sidstr,
903 context, MSISOURCETYPE_NETWORK, szSource, 0);
911 /******************************************************************
912 * MsiSourceListAddSourceA (MSI.@)
914 UINT WINAPI MsiSourceListAddSourceA( LPCSTR szProduct, LPCSTR szUserName,
915 DWORD dwReserved, LPCSTR szSource)
922 szwproduct = strdupAtoW( szProduct );
923 szwusername = strdupAtoW( szUserName );
924 szwsource = strdupAtoW( szSource );
926 ret = MsiSourceListAddSourceW(szwproduct, szwusername, dwReserved, szwsource);
928 msi_free(szwproduct);
929 msi_free(szwusername);
935 /******************************************************************
936 * MsiSourceListAddSourceExA (MSI.@)
938 UINT WINAPI MsiSourceListAddSourceExA(LPCSTR szProduct, LPCSTR szUserSid,
939 MSIINSTALLCONTEXT dwContext, DWORD dwOptions, LPCSTR szSource, DWORD dwIndex)
942 LPWSTR product, usersid, source;
944 product = strdupAtoW(szProduct);
945 usersid = strdupAtoW(szUserSid);
946 source = strdupAtoW(szSource);
948 ret = MsiSourceListAddSourceExW(product, usersid, dwContext,
949 dwOptions, source, dwIndex);
958 static void free_source_list(struct list *sourcelist)
960 while (!list_empty(sourcelist))
962 media_info *info = LIST_ENTRY(list_head(sourcelist), media_info, entry);
963 list_remove(&info->entry);
964 msi_free(info->path);
969 static void add_source_to_list(struct list *sourcelist, media_info *info,
974 static const WCHAR fmt[] = {'%','i',0};
976 if (index) *index = 0;
978 if (list_empty(sourcelist))
980 list_add_head(sourcelist, &info->entry);
984 LIST_FOR_EACH_ENTRY(iter, sourcelist, media_info, entry)
986 if (!found && info->index < iter->index)
989 list_add_before(&iter->entry, &info->entry);
992 /* update the rest of the list */
994 sprintfW(iter->szIndex, fmt, ++iter->index);
1000 list_add_after(&iter->entry, &info->entry);
1003 static UINT fill_source_list(struct list *sourcelist, HKEY sourcekey, DWORD *count)
1005 UINT r = ERROR_SUCCESS;
1008 DWORD size, val_size;
1013 while (r == ERROR_SUCCESS)
1015 size = sizeof(name) / sizeof(name[0]);
1016 r = RegEnumValueW(sourcekey, index, name, &size, NULL, NULL, NULL, &val_size);
1017 if (r != ERROR_SUCCESS)
1020 entry = msi_alloc(sizeof(media_info));
1024 entry->path = msi_alloc(val_size);
1031 lstrcpyW(entry->szIndex, name);
1032 entry->index = atoiW(name);
1035 r = RegEnumValueW(sourcekey, index, name, &size, NULL,
1036 NULL, (LPBYTE)entry->path, &val_size);
1037 if (r != ERROR_SUCCESS)
1039 msi_free(entry->path);
1045 add_source_to_list(sourcelist, entry, NULL);
1050 free_source_list(sourcelist);
1051 return ERROR_OUTOFMEMORY;
1054 /******************************************************************
1055 * MsiSourceListAddSourceExW (MSI.@)
1057 UINT WINAPI MsiSourceListAddSourceExW( LPCWSTR szProduct, LPCWSTR szUserSid,
1058 MSIINSTALLCONTEXT dwContext, DWORD dwOptions, LPCWSTR szSource,
1064 struct list sourcelist;
1066 WCHAR squished_pc[GUID_SIZE];
1073 static const WCHAR fmt[] = {'%','i',0};
1074 static const WCHAR one[] = {'1',0};
1075 static const WCHAR backslash[] = {'\\',0};
1076 static const WCHAR forwardslash[] = {'/',0};
1078 TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct), debugstr_w(szUserSid),
1079 dwContext, dwOptions, debugstr_w(szSource), dwIndex);
1081 if (!szProduct || !squash_guid(szProduct, squished_pc))
1082 return ERROR_INVALID_PARAMETER;
1084 if (!szSource || !*szSource)
1085 return ERROR_INVALID_PARAMETER;
1087 if (!(dwOptions & (MSISOURCETYPE_NETWORK | MSISOURCETYPE_URL)))
1088 return ERROR_INVALID_PARAMETER;
1090 if (dwOptions & MSICODE_PATCH)
1092 FIXME("Unhandled options MSICODE_PATCH\n");
1093 return ERROR_FUNCTION_FAILED;
1096 if (szUserSid && (dwContext & MSIINSTALLCONTEXT_MACHINE))
1097 return ERROR_INVALID_PARAMETER;
1099 rc = OpenSourceKey(szProduct, &sourcekey, MSICODE_PRODUCT, dwContext, FALSE);
1100 if (rc != ERROR_SUCCESS)
1103 if (dwOptions & MSISOURCETYPE_NETWORK)
1104 rc = OpenNetworkSubkey(sourcekey, &typekey, TRUE);
1105 else if (dwOptions & MSISOURCETYPE_URL)
1106 rc = OpenURLSubkey(sourcekey, &typekey, TRUE);
1107 else if (dwOptions & MSISOURCETYPE_MEDIA)
1108 rc = OpenMediaSubkey(sourcekey, &typekey, TRUE);
1111 ERR("unknown media type: %08x\n", dwOptions);
1112 RegCloseKey(sourcekey);
1113 return ERROR_FUNCTION_FAILED;
1116 postfix = (dwOptions & MSISOURCETYPE_NETWORK) ? backslash : forwardslash;
1117 if (szSource[lstrlenW(szSource) - 1] == *postfix)
1118 source = strdupW(szSource);
1121 size = lstrlenW(szSource) + 2;
1122 source = msi_alloc(size * sizeof(WCHAR));
1123 lstrcpyW(source, szSource);
1124 lstrcatW(source, postfix);
1127 list_init(&sourcelist);
1128 rc = fill_source_list(&sourcelist, typekey, &count);
1129 if (rc != ERROR_NO_MORE_ITEMS)
1132 size = (lstrlenW(source) + 1) * sizeof(WCHAR);
1136 rc = RegSetValueExW(typekey, one, 0, REG_EXPAND_SZ, (LPBYTE)source, size);
1139 else if (dwIndex > count || dwIndex == 0)
1141 sprintfW(name, fmt, count + 1);
1142 rc = RegSetValueExW(typekey, name, 0, REG_EXPAND_SZ, (LPBYTE)source, size);
1147 sprintfW(name, fmt, dwIndex);
1148 info = msi_alloc(sizeof(media_info));
1151 rc = ERROR_OUTOFMEMORY;
1155 info->path = strdupW(source);
1156 lstrcpyW(info->szIndex, name);
1157 info->index = dwIndex;
1158 add_source_to_list(&sourcelist, info, &index);
1160 LIST_FOR_EACH_ENTRY(info, &sourcelist, media_info, entry)
1162 if (info->index < index)
1165 size = (lstrlenW(info->path) + 1) * sizeof(WCHAR);
1166 rc = RegSetValueExW(typekey, info->szIndex, 0,
1167 REG_EXPAND_SZ, (LPBYTE)info->path, size);
1168 if (rc != ERROR_SUCCESS)
1174 free_source_list(&sourcelist);
1176 RegCloseKey(typekey);
1177 RegCloseKey(sourcekey);
1181 /******************************************************************
1182 * MsiSourceListAddMediaDiskA (MSI.@)
1184 UINT WINAPI MsiSourceListAddMediaDiskA(LPCSTR szProduct, LPCSTR szUserSid,
1185 MSIINSTALLCONTEXT dwContext, DWORD dwOptions, DWORD dwDiskId,
1186 LPCSTR szVolumeLabel, LPCSTR szDiskPrompt)
1189 LPWSTR product = NULL;
1190 LPWSTR usersid = NULL;
1191 LPWSTR volume = NULL;
1192 LPWSTR prompt = NULL;
1194 if (szProduct) product = strdupAtoW(szProduct);
1195 if (szUserSid) usersid = strdupAtoW(szUserSid);
1196 if (szVolumeLabel) volume = strdupAtoW(szVolumeLabel);
1197 if (szDiskPrompt) prompt = strdupAtoW(szDiskPrompt);
1199 r = MsiSourceListAddMediaDiskW(product, usersid, dwContext, dwOptions,
1200 dwDiskId, volume, prompt);
1210 /******************************************************************
1211 * MsiSourceListAddMediaDiskW (MSI.@)
1213 UINT WINAPI MsiSourceListAddMediaDiskW(LPCWSTR szProduct, LPCWSTR szUserSid,
1214 MSIINSTALLCONTEXT dwContext, DWORD dwOptions, DWORD dwDiskId,
1215 LPCWSTR szVolumeLabel, LPCWSTR szDiskPrompt)
1221 WCHAR squished_pc[GUID_SIZE];
1225 static const WCHAR fmt[] = {'%','i',0};
1226 static const WCHAR semicolon[] = {';',0};
1228 TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct),
1229 debugstr_w(szUserSid), dwContext, dwOptions, dwDiskId,
1230 debugstr_w(szVolumeLabel), debugstr_w(szDiskPrompt));
1232 if (!szProduct || !squash_guid(szProduct, squished_pc))
1233 return ERROR_INVALID_PARAMETER;
1235 if (dwOptions != MSICODE_PRODUCT && dwOptions != MSICODE_PATCH)
1236 return ERROR_INVALID_PARAMETER;
1238 if ((szVolumeLabel && !*szVolumeLabel) || (szDiskPrompt && !*szDiskPrompt))
1239 return ERROR_INVALID_PARAMETER;
1241 if ((dwContext & MSIINSTALLCONTEXT_MACHINE) && szUserSid)
1242 return ERROR_INVALID_PARAMETER;
1244 if (dwOptions & MSICODE_PATCH)
1246 FIXME("Unhandled options MSICODE_PATCH\n");
1247 return ERROR_FUNCTION_FAILED;
1250 rc = OpenSourceKey(szProduct, &sourcekey, MSICODE_PRODUCT, dwContext, FALSE);
1251 if (rc != ERROR_SUCCESS)
1254 OpenMediaSubkey(sourcekey, &mediakey, TRUE);
1256 sprintfW(szIndex, fmt, dwDiskId);
1259 if (szVolumeLabel) size += lstrlenW(szVolumeLabel);
1260 if (szDiskPrompt) size += lstrlenW(szDiskPrompt);
1262 size *= sizeof(WCHAR);
1263 buffer = msi_alloc(size);
1266 if (szVolumeLabel) lstrcpyW(buffer, szVolumeLabel);
1267 lstrcatW(buffer, semicolon);
1268 if (szDiskPrompt) lstrcatW(buffer, szDiskPrompt);
1270 RegSetValueExW(mediakey, szIndex, 0, REG_SZ, (LPBYTE)buffer, size);
1273 RegCloseKey(sourcekey);
1274 RegCloseKey(mediakey);
1276 return ERROR_SUCCESS;
1279 /******************************************************************
1280 * MsiSourceListClearAllA (MSI.@)
1282 UINT WINAPI MsiSourceListClearAllA( LPCSTR szProduct, LPCSTR szUserName, DWORD dwReserved )
1284 FIXME("(%s %s %d)\n", debugstr_a(szProduct), debugstr_a(szUserName), dwReserved);
1285 return ERROR_SUCCESS;
1288 /******************************************************************
1289 * MsiSourceListClearAllW (MSI.@)
1291 UINT WINAPI MsiSourceListClearAllW( LPCWSTR szProduct, LPCWSTR szUserName, DWORD dwReserved )
1293 FIXME("(%s %s %d)\n", debugstr_w(szProduct), debugstr_w(szUserName), dwReserved);
1294 return ERROR_SUCCESS;