source.c 38.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Implementation of the Microsoft Installer (msi.dll)
 *
 * Copyright 2005 Aric Stewart for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
 */

#include <stdarg.h>

#define COBJMACROS

#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "winnls.h"
#include "shlwapi.h"
#include "wine/debug.h"
#include "msi.h"
#include "msiquery.h"
#include "msipriv.h"
#include "wincrypt.h"
#include "winver.h"
#include "winuser.h"
#include "wine/unicode.h"
38
#include "sddl.h"
39 40 41 42 43 44 45 46 47

WINE_DEFAULT_DEBUG_CHANNEL(msi);

/*
 * These apis are defined in MSI 3.0
 */

typedef struct tagMediaInfo
{
48
    struct list entry;
49 50
    LPWSTR  path;
    WCHAR   szIndex[10];
51
    DWORD   index;
52 53
} media_info;

54 55
static UINT OpenSourceKey(LPCWSTR szProduct, HKEY* key, DWORD dwOptions,
                          MSIINSTALLCONTEXT context, BOOL create)
56 57
{
    HKEY rootkey = 0; 
58
    UINT rc = ERROR_FUNCTION_FAILED;
59

60
    if (context == MSIINSTALLCONTEXT_USERUNMANAGED)
61
    {
62
        if (dwOptions & MSICODE_PATCH)
63 64
            rc = MSIREG_OpenUserPatchesKey(szProduct, &rootkey, create);
        else
65 66
            rc = MSIREG_OpenProductKey(szProduct, NULL, context,
                                       &rootkey, create);
67
    }
68 69
    else if (context == MSIINSTALLCONTEXT_USERMANAGED)
    {
70
        if (dwOptions & MSICODE_PATCH)
71 72
            rc = MSIREG_OpenUserPatchesKey(szProduct, &rootkey, create);
        else
73 74
            rc = MSIREG_OpenProductKey(szProduct, NULL, context,
                                       &rootkey, create);
75 76
    }
    else if (context == MSIINSTALLCONTEXT_MACHINE)
77
    {
78
        if (dwOptions & MSICODE_PATCH)
79 80
            rc = MSIREG_OpenPatchesKey(szProduct, &rootkey, create);
        else
81 82
            rc = MSIREG_OpenProductKey(szProduct, NULL, context,
                                       &rootkey, create);
83
    }
84

85
    if (rc != ERROR_SUCCESS)
86
    {
87
        if (dwOptions & MSICODE_PATCH)
88 89 90 91
            return ERROR_UNKNOWN_PATCH;
        else
            return ERROR_UNKNOWN_PRODUCT;
    }
92 93 94 95

    if (create)
        rc = RegCreateKeyW(rootkey, szSourceList, key);
    else
96 97 98 99 100
    {
        rc = RegOpenKeyW(rootkey,szSourceList, key);
        if (rc != ERROR_SUCCESS)
            rc = ERROR_BAD_CONFIGURATION;
    }
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

    return rc;
}

static UINT OpenMediaSubkey(HKEY rootkey, HKEY *key, BOOL create)
{
    UINT rc;
    static const WCHAR media[] = {'M','e','d','i','a',0};

    if (create)
        rc = RegCreateKeyW(rootkey, media, key);
    else
        rc = RegOpenKeyW(rootkey,media, key); 

    return rc;
}

static UINT OpenNetworkSubkey(HKEY rootkey, HKEY *key, BOOL create)
{
    UINT rc;
    static const WCHAR net[] = {'N','e','t',0};

    if (create)
        rc = RegCreateKeyW(rootkey, net, key);
    else
        rc = RegOpenKeyW(rootkey, net, key); 

    return rc;
}

static UINT OpenURLSubkey(HKEY rootkey, HKEY *key, BOOL create)
{
    UINT rc;
    static const WCHAR URL[] = {'U','R','L',0};

    if (create)
        rc = RegCreateKeyW(rootkey, URL, key);
    else
        rc = RegOpenKeyW(rootkey, URL, key); 

    return rc;
}

144 145 146 147 148
/******************************************************************
 *  MsiSourceListEnumMediaDisksA   (MSI.@)
 */
UINT WINAPI MsiSourceListEnumMediaDisksA(LPCSTR szProductCodeOrPatchCode,
                                         LPCSTR szUserSid, MSIINSTALLCONTEXT dwContext,
149
                                         DWORD dwOptions, DWORD dwIndex, LPDWORD pdwDiskId,
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
                                         LPSTR szVolumeLabel, LPDWORD pcchVolumeLabel,
                                         LPSTR szDiskPrompt, LPDWORD pcchDiskPrompt)
{
    LPWSTR product = NULL;
    LPWSTR usersid = NULL;
    LPWSTR volume = NULL;
    LPWSTR prompt = NULL;
    UINT r = ERROR_INVALID_PARAMETER;

    TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p, %p)\n", debugstr_a(szProductCodeOrPatchCode),
          debugstr_a(szUserSid), dwContext, dwOptions, dwIndex, pdwDiskId,
          szVolumeLabel, pcchVolumeLabel, szDiskPrompt, pcchDiskPrompt);

    if (szDiskPrompt && !pcchDiskPrompt)
        return ERROR_INVALID_PARAMETER;

    if (szProductCodeOrPatchCode) product = strdupAtoW(szProductCodeOrPatchCode);
    if (szUserSid) usersid = strdupAtoW(szUserSid);

    /* FIXME: add tests for an invalid format */

    if (pcchVolumeLabel)
        volume = msi_alloc(*pcchVolumeLabel * sizeof(WCHAR));

    if (pcchDiskPrompt)
        prompt = msi_alloc(*pcchDiskPrompt * sizeof(WCHAR));

    if (volume) *volume = '\0';
    if (prompt) *prompt = '\0';
    r = MsiSourceListEnumMediaDisksW(product, usersid, dwContext, dwOptions,
                                     dwIndex, pdwDiskId, volume, pcchVolumeLabel,
                                     prompt, pcchDiskPrompt);
    if (r != ERROR_SUCCESS)
        goto done;

    if (szVolumeLabel && pcchVolumeLabel)
186
        WideCharToMultiByte(CP_ACP, 0, volume, -1, szVolumeLabel,
187 188 189
                            *pcchVolumeLabel + 1, NULL, NULL);

    if (szDiskPrompt)
190
        WideCharToMultiByte(CP_ACP, 0, prompt, -1, szDiskPrompt,
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
                            *pcchDiskPrompt + 1, NULL, NULL);

done:
    msi_free(product);
    msi_free(usersid);
    msi_free(volume);
    msi_free(prompt);

    return r;
}

/******************************************************************
 *  MsiSourceListEnumMediaDisksW   (MSI.@)
 */
UINT WINAPI MsiSourceListEnumMediaDisksW(LPCWSTR szProductCodeOrPatchCode,
                                         LPCWSTR szUserSid, MSIINSTALLCONTEXT dwContext,
207
                                         DWORD dwOptions, DWORD dwIndex, LPDWORD pdwDiskId,
208 209 210 211
                                         LPWSTR szVolumeLabel, LPDWORD pcchVolumeLabel,
                                         LPWSTR szDiskPrompt, LPDWORD pcchDiskPrompt)
{
    WCHAR squished_pc[GUID_SIZE];
212
    WCHAR convert[11];
213 214
    LPWSTR value = NULL;
    LPWSTR data = NULL;
215
    LPWSTR ptr, ptr2;
216 217 218 219 220 221
    HKEY source, media;
    DWORD valuesz, datasz = 0;
    DWORD type;
    DWORD numvals, size;
    LONG res;
    UINT r;
222
    static DWORD index = 0;
223

224 225
    static const WCHAR fmt[] = {'#','%','d',0};

226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
    TRACE("(%s, %s, %d, %d, %d, %p, %p, %p, %p)\n", debugstr_w(szProductCodeOrPatchCode),
          debugstr_w(szUserSid), dwContext, dwOptions, dwIndex, szVolumeLabel,
          pcchVolumeLabel, szDiskPrompt, pcchDiskPrompt);

    if (!szProductCodeOrPatchCode ||
        !squash_guid(szProductCodeOrPatchCode, squished_pc))
        return ERROR_INVALID_PARAMETER;

    if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
        return ERROR_INVALID_PARAMETER;

    if (dwOptions != MSICODE_PRODUCT && dwOptions != MSICODE_PATCH)
        return ERROR_INVALID_PARAMETER;

    if (szDiskPrompt && !pcchDiskPrompt)
        return ERROR_INVALID_PARAMETER;

    if (dwIndex == 0)
        index = 0;

    if (dwIndex != index)
        return ERROR_INVALID_PARAMETER;

    r = OpenSourceKey(szProductCodeOrPatchCode, &source,
                      dwOptions, dwContext, FALSE);
    if (r != ERROR_SUCCESS)
        return r;

    r = OpenMediaSubkey(source, &media, FALSE);
    if (r != ERROR_SUCCESS)
    {
        RegCloseKey(source);
        return ERROR_NO_MORE_ITEMS;
    }

    res = RegQueryInfoKeyW(media, NULL, NULL, NULL, NULL, NULL,
                           NULL, &numvals, &valuesz, &datasz, NULL, NULL);
    if (res != ERROR_SUCCESS)
    {
        r = ERROR_BAD_CONFIGURATION;
        goto done;
    }

    value = msi_alloc(++valuesz * sizeof(WCHAR));
    data = msi_alloc(++datasz * sizeof(WCHAR));
    if (!value || !data)
    {
        r = ERROR_OUTOFMEMORY;
        goto done;
    }

    r = RegEnumValueW(media, dwIndex, value, &valuesz,
                      NULL, &type, (LPBYTE)data, &datasz);
    if (r != ERROR_SUCCESS)
        goto done;

    if (pdwDiskId)
        *pdwDiskId = atolW(value);

285
    ptr2 = data;
286 287 288 289 290 291 292 293
    ptr = strchrW(data, ';');
    if (!ptr)
        ptr = data;
    else
        *ptr = '\0';

    if (pcchVolumeLabel)
    {
294 295 296 297 298 299 300 301 302
        if (type == REG_DWORD)
        {
            sprintfW(convert, fmt, *data);
            size = lstrlenW(convert);
            ptr2 = convert;
        }
        else
            size = lstrlenW(data);

303 304 305
        if (size >= *pcchVolumeLabel)
            r = ERROR_MORE_DATA;
        else if (szVolumeLabel)
306
            lstrcpyW(szVolumeLabel, ptr2);
307 308 309 310 311 312

        *pcchVolumeLabel = size;
    }

    if (pcchDiskPrompt)
    {
313 314
        if (!*ptr)
            ptr++;
315

316 317 318 319 320 321 322 323 324
        if (type == REG_DWORD)
        {
            sprintfW(convert, fmt, *ptr);
            size = lstrlenW(convert);
            ptr = convert;
        }
        else
            size = lstrlenW(ptr);

325 326 327
        if (size >= *pcchDiskPrompt)
            r = ERROR_MORE_DATA;
        else if (szDiskPrompt)
328
            lstrcpyW(szDiskPrompt, ptr);
329 330 331 332 333 334 335 336 337 338 339 340 341 342

        *pcchDiskPrompt = size;
    }

    index++;

done:
    msi_free(value);
    msi_free(data);
    RegCloseKey(source);

    return r;
}

343 344 345 346 347 348 349 350
/******************************************************************
 *  MsiSourceListEnumSourcesA   (MSI.@)
 */
UINT WINAPI MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch, LPCSTR szUserSid,
                                      MSIINSTALLCONTEXT dwContext,
                                      DWORD dwOptions, DWORD dwIndex,
                                      LPSTR szSource, LPDWORD pcchSource)
{
351 352 353 354
    LPWSTR product = NULL;
    LPWSTR usersid = NULL;
    LPWSTR source = NULL;
    DWORD len = 0;
355
    UINT r = ERROR_INVALID_PARAMETER;
356
    static DWORD index = 0;
357 358 359 360

    TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_a(szProductCodeOrPatch),
          debugstr_a(szUserSid), dwContext, dwOptions, dwIndex, szSource, pcchSource);

361 362 363
    if (dwIndex == 0)
        index = 0;

364
    if (szSource && !pcchSource)
365 366 367 368
        goto done;

    if (dwIndex != index)
        goto done;
369 370 371 372 373 374 375 376 377 378 379

    if (szProductCodeOrPatch) product = strdupAtoW(szProductCodeOrPatch);
    if (szUserSid) usersid = strdupAtoW(szUserSid);

    r = MsiSourceListEnumSourcesW(product, usersid, dwContext, dwOptions,
                                  dwIndex, NULL, &len);
    if (r != ERROR_SUCCESS)
        goto done;

    source = msi_alloc(++len * sizeof(WCHAR));
    if (!source)
380 381 382 383
    {
        r = ERROR_OUTOFMEMORY;
        goto done;
    }
384 385 386 387 388 389 390 391

    *source = '\0';
    r = MsiSourceListEnumSourcesW(product, usersid, dwContext, dwOptions,
                                  dwIndex, source, &len);
    if (r != ERROR_SUCCESS)
        goto done;

    len = WideCharToMultiByte(CP_ACP, 0, source, -1, NULL, 0, NULL, NULL);
392
    if (pcchSource && *pcchSource >= len)
393 394 395 396
        WideCharToMultiByte(CP_ACP, 0, source, -1, szSource, len, NULL, NULL);
    else if (szSource)
        r = ERROR_MORE_DATA;

397 398
    if (pcchSource)
        *pcchSource = len - 1;
399 400 401 402 403 404

done:
    msi_free(product);
    msi_free(usersid);
    msi_free(source);

405 406
    if (r == ERROR_SUCCESS)
    {
407
        if (szSource || !pcchSource) index++;
408 409 410 411
    }
    else if (dwIndex > index)
        index = 0;

412 413 414 415
    return r;
}

/******************************************************************
416
 *  MsiSourceListEnumSourcesW   (MSI.@)
417 418 419 420 421 422
 */
UINT WINAPI MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch, LPCWSTR szUserSid,
                                      MSIINSTALLCONTEXT dwContext,
                                      DWORD dwOptions, DWORD dwIndex,
                                      LPWSTR szSource, LPDWORD pcchSource)
{
423 424 425 426 427 428
    WCHAR squished_pc[GUID_SIZE];
    WCHAR name[32];
    HKEY source = NULL;
    HKEY subkey = NULL;
    LONG res;
    UINT r = ERROR_INVALID_PARAMETER;
429
    static DWORD index = 0;
430 431 432 433

    static const WCHAR format[] = {'%','d',0};

    TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch),
434
          debugstr_w(szUserSid), dwContext, dwOptions, dwIndex, szSource, pcchSource);
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484

    if (dwIndex == 0)
        index = 0;

    if (!szProductCodeOrPatch || !squash_guid(szProductCodeOrPatch, squished_pc))
        goto done;

    if (szSource && !pcchSource)
        goto done;

    if (!(dwOptions & (MSISOURCETYPE_NETWORK | MSISOURCETYPE_URL)))
        goto done;

    if ((dwOptions & MSISOURCETYPE_NETWORK) && (dwOptions & MSISOURCETYPE_URL))
        goto done;

    if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
        goto done;

    if (dwIndex != index)
        goto done;

    r = OpenSourceKey(szProductCodeOrPatch, &source,
                      dwOptions, dwContext, FALSE);
    if (r != ERROR_SUCCESS)
        goto done;

    if (dwOptions & MSISOURCETYPE_NETWORK)
        r = OpenNetworkSubkey(source, &subkey, FALSE);
    else if (dwOptions & MSISOURCETYPE_URL)
        r = OpenURLSubkey(source, &subkey, FALSE);

    if (r != ERROR_SUCCESS)
    {
        r = ERROR_NO_MORE_ITEMS;
        goto done;
    }

    sprintfW(name, format, dwIndex + 1);

    res = RegQueryValueExW(subkey, name, 0, 0, (LPBYTE)szSource, pcchSource);
    if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
        r = ERROR_NO_MORE_ITEMS;

done:
    RegCloseKey(subkey);
    RegCloseKey(source);

    if (r == ERROR_SUCCESS)
    {
485
        if (szSource || !pcchSource) index++;
486 487 488 489 490
    }
    else if (dwIndex > index)
        index = 0;

    return r;
491 492
}

493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
/******************************************************************
 *  MsiSourceListGetInfoA   (MSI.@)
 */
UINT WINAPI MsiSourceListGetInfoA( LPCSTR szProduct, LPCSTR szUserSid,
                                   MSIINSTALLCONTEXT dwContext, DWORD dwOptions,
                                   LPCSTR szProperty, LPSTR szValue,
                                   LPDWORD pcchValue)
{
    UINT ret;
    LPWSTR product = NULL;
    LPWSTR usersid = NULL;
    LPWSTR property = NULL;
    LPWSTR value = NULL;
    DWORD len = 0;

    if (szValue && !pcchValue)
        return ERROR_INVALID_PARAMETER;

    if (szProduct) product = strdupAtoW(szProduct);
    if (szUserSid) usersid = strdupAtoW(szUserSid);
    if (szProperty) property = strdupAtoW(szProperty);

    ret = MsiSourceListGetInfoW(product, usersid, dwContext, dwOptions,
                                property, NULL, &len);
    if (ret != ERROR_SUCCESS)
        goto done;

    value = msi_alloc(++len * sizeof(WCHAR));
    if (!value)
        return ERROR_OUTOFMEMORY;

524
    *value = '\0';
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
    ret = MsiSourceListGetInfoW(product, usersid, dwContext, dwOptions,
                                property, value, &len);
    if (ret != ERROR_SUCCESS)
        goto done;

    len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
    if (*pcchValue >= len)
        WideCharToMultiByte(CP_ACP, 0, value, -1, szValue, len, NULL, NULL);
    else if (szValue)
        ret = ERROR_MORE_DATA;

    *pcchValue = len - 1;

done:
    msi_free(product);
    msi_free(usersid);
    msi_free(property);
    msi_free(value);
    return ret;
}

546 547 548 549 550 551 552 553
/******************************************************************
 *  MsiSourceListGetInfoW   (MSI.@)
 */
UINT WINAPI MsiSourceListGetInfoW( LPCWSTR szProduct, LPCWSTR szUserSid,
                                   MSIINSTALLCONTEXT dwContext, DWORD dwOptions,
                                   LPCWSTR szProperty, LPWSTR szValue, 
                                   LPDWORD pcchValue) 
{
554
    WCHAR squished_pc[GUID_SIZE];
555
    HKEY sourcekey, media;
556 557
    LPWSTR source, ptr;
    DWORD size;
558 559
    UINT rc;

560 561 562
    static const WCHAR mediapack[] = {
        'M','e','d','i','a','P','a','c','k','a','g','e',0};

563 564
    TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szProperty));

565
    if (!szProduct || !squash_guid(szProduct, squished_pc))
566 567 568 569
        return ERROR_INVALID_PARAMETER;

    if (szValue && !pcchValue)
        return ERROR_INVALID_PARAMETER;
570 571 572 573 574 575 576 577

    if (dwContext != MSIINSTALLCONTEXT_USERMANAGED &&
        dwContext != MSIINSTALLCONTEXT_USERUNMANAGED &&
        dwContext != MSIINSTALLCONTEXT_MACHINE)
        return ERROR_INVALID_PARAMETER;

    if (!szProperty)
        return ERROR_INVALID_PARAMETER;
578

579 580 581
    if (szUserSid)
        FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid));

582
    rc = OpenSourceKey(szProduct, &sourcekey, dwOptions, dwContext, FALSE);
583
    if (rc != ERROR_SUCCESS)
584
        return rc;
585

586 587
    if (!strcmpW( szProperty, INSTALLPROPERTY_MEDIAPACKAGEPATHW ) ||
        !strcmpW( szProperty, INSTALLPROPERTY_DISKPROMPTW ))
588
    {
589 590 591 592 593 594 595
        rc = OpenMediaSubkey(sourcekey, &media, FALSE);
        if (rc != ERROR_SUCCESS)
        {
            RegCloseKey(sourcekey);
            return ERROR_SUCCESS;
        }

596
        if (!strcmpW( szProperty, INSTALLPROPERTY_MEDIAPACKAGEPATHW ))
597 598 599 600
            szProperty = mediapack;

        RegQueryValueExW(media, szProperty, 0, 0, (LPBYTE)szValue, pcchValue);
        RegCloseKey(media);
601
    }
602 603
    else if (!strcmpW( szProperty, INSTALLPROPERTY_LASTUSEDSOURCEW ) ||
             !strcmpW( szProperty, INSTALLPROPERTY_LASTUSEDTYPEW ))
604
    {
605 606 607 608 609 610 611
        rc = RegQueryValueExW(sourcekey, INSTALLPROPERTY_LASTUSEDSOURCEW,
                              0, 0, NULL, &size);
        if (rc != ERROR_SUCCESS)
        {
            RegCloseKey(sourcekey);
            return ERROR_SUCCESS;
        }
612

613 614 615 616 617 618 619 620 621 622 623
        source = msi_alloc(size);
        RegQueryValueExW(sourcekey, INSTALLPROPERTY_LASTUSEDSOURCEW,
                         0, 0, (LPBYTE)source, &size);

        if (!*source)
        {
            msi_free(source);
            RegCloseKey(sourcekey);
            return ERROR_SUCCESS;
        }

624
        if (!strcmpW( szProperty, INSTALLPROPERTY_LASTUSEDTYPEW ))
625 626 627 628 629 630 631 632
        {
            if (*source != 'n' && *source != 'u' && *source != 'm')
            {
                msi_free(source);
                RegCloseKey(sourcekey);
                return ERROR_SUCCESS;
            }

633
            ptr = source;
634 635
            source[1] = '\0';
        }
636
        else
637 638 639 640 641 642 643
        {
            ptr = strrchrW(source, ';');
            if (!ptr)
                ptr = source;
            else
                ptr++;
        }
644 645

        if (szValue)
646
        {
647
            if (strlenW(ptr) < *pcchValue)
648
                lstrcpyW(szValue, ptr);
649
            else
650
                rc = ERROR_MORE_DATA;
651
        }
652 653 654

        *pcchValue = lstrlenW(ptr);
        msi_free(source);
655
    }
656
    else if (!strcmpW( szProperty, INSTALLPROPERTY_PACKAGENAMEW ))
657
    {
658 659 660
        *pcchValue = *pcchValue * sizeof(WCHAR);
        rc = RegQueryValueExW(sourcekey, INSTALLPROPERTY_PACKAGENAMEW, 0, 0,
                              (LPBYTE)szValue, pcchValue);
661
        if (rc != ERROR_SUCCESS && rc != ERROR_MORE_DATA)
662 663
        {
            *pcchValue = 0;
664
            rc = ERROR_SUCCESS;
665 666 667 668 669 670 671 672
        }
        else
        {
            if (*pcchValue)
                *pcchValue = (*pcchValue - 1) / sizeof(WCHAR);
            if (szValue)
                szValue[*pcchValue] = '\0';
        }
673 674 675 676 677 678 679 680 681 682 683
    }
    else
    {
        FIXME("Unknown property %s\n",debugstr_w(szProperty));
        rc = ERROR_UNKNOWN_PROPERTY;
    }

    RegCloseKey(sourcekey);
    return rc;
}

684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
/******************************************************************
 *  MsiSourceListSetInfoA   (MSI.@)
 */
UINT WINAPI MsiSourceListSetInfoA(LPCSTR szProduct, LPCSTR szUserSid,
                                  MSIINSTALLCONTEXT dwContext, DWORD dwOptions,
                                  LPCSTR szProperty, LPCSTR szValue)
{
    UINT ret;
    LPWSTR product = NULL;
    LPWSTR usersid = NULL;
    LPWSTR property = NULL;
    LPWSTR value = NULL;

    if (szProduct) product = strdupAtoW(szProduct);
    if (szUserSid) usersid = strdupAtoW(szUserSid);
    if (szProperty) property = strdupAtoW(szProperty);
    if (szValue) value = strdupAtoW(szValue);

    ret = MsiSourceListSetInfoW(product, usersid, dwContext, dwOptions,
                                property, value);

    msi_free(product);
    msi_free(usersid);
    msi_free(property);
    msi_free(value);

    return ret;
}

713 714 715
UINT msi_set_last_used_source(LPCWSTR product, LPCWSTR usersid,
                              MSIINSTALLCONTEXT context, DWORD options,
                              LPCWSTR value)
716
{
717
    HKEY source;
718 719 720 721
    LPWSTR buffer;
    WCHAR typechar;
    DWORD size;
    UINT r;
722
    int index = 1;
723 724 725 726 727 728 729

    static const WCHAR format[] = {'%','c',';','%','i',';','%','s',0};

    if (options & MSISOURCETYPE_NETWORK)
        typechar = 'n';
    else if (options & MSISOURCETYPE_URL)
        typechar = 'u';
730 731
    else if (options & MSISOURCETYPE_MEDIA)
        typechar = 'm';
732 733 734
    else
        return ERROR_INVALID_PARAMETER;

735 736 737 738 739 740
    if (!(options & MSISOURCETYPE_MEDIA))
    {
        r = MsiSourceListAddSourceExW(product, usersid, context,
                                      options, value, 0);
        if (r != ERROR_SUCCESS)
            return r;
741

742 743 744 745
        index = 0;
        while ((r = MsiSourceListEnumSourcesW(product, usersid, context, options,
                                              index, NULL, NULL)) == ERROR_SUCCESS)
            index++;
746

747 748 749
        if (r != ERROR_NO_MORE_ITEMS)
            return r;
    }
750 751 752 753 754 755

    size = (lstrlenW(format) + lstrlenW(value) + 7) * sizeof(WCHAR);
    buffer = msi_alloc(size);
    if (!buffer)
        return ERROR_OUTOFMEMORY;

756 757
    r = OpenSourceKey(product, &source, MSICODE_PRODUCT, context, FALSE);
    if (r != ERROR_SUCCESS)
758 759
    {
        msi_free(buffer);
760
        return r;
761
    }
762

763 764
    sprintfW(buffer, format, typechar, index, value);

765
    size = (lstrlenW(buffer) + 1) * sizeof(WCHAR);
766 767 768 769
    r = RegSetValueExW(source, INSTALLPROPERTY_LASTUSEDSOURCEW, 0,
                       REG_SZ, (LPBYTE)buffer, size);
    msi_free(buffer);

770
    RegCloseKey(source);
771 772 773
    return r;
}

774 775 776 777 778 779 780
/******************************************************************
 *  MsiSourceListSetInfoW   (MSI.@)
 */
UINT WINAPI MsiSourceListSetInfoW( LPCWSTR szProduct, LPCWSTR szUserSid,
                                   MSIINSTALLCONTEXT dwContext, DWORD dwOptions,
                                   LPCWSTR szProperty, LPCWSTR szValue)
{
781
    WCHAR squished_pc[GUID_SIZE];
782 783
    HKEY sourcekey, media;
    LPCWSTR property;
784 785
    UINT rc;

786 787 788 789
    static const WCHAR media_package[] = {
        'M','e','d','i','a','P','a','c','k','a','g','e',0
    };

790
    TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct), debugstr_w(szUserSid),
791 792
            dwContext, dwOptions, debugstr_w(szProperty), debugstr_w(szValue));

793
    if (!szProduct || !squash_guid(szProduct, squished_pc))
794 795
        return ERROR_INVALID_PARAMETER;

796 797 798 799 800 801
    if (!szProperty)
        return ERROR_INVALID_PARAMETER;

    if (!szValue)
        return ERROR_UNKNOWN_PROPERTY;

802 803 804
    if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
        return ERROR_INVALID_PARAMETER;

805 806 807
    if (dwOptions & MSICODE_PATCH)
    {
        FIXME("Unhandled options MSICODE_PATCH\n");
808
        return ERROR_UNKNOWN_PATCH;
809
    }
810 811

    property = szProperty;
812
    if (!strcmpW( szProperty, INSTALLPROPERTY_MEDIAPACKAGEPATHW ))
813 814
        property = media_package;

815
    rc = OpenSourceKey(szProduct, &sourcekey, MSICODE_PRODUCT, dwContext, FALSE);
816
    if (rc != ERROR_SUCCESS)
817
        return rc;
818

819
    if (strcmpW( szProperty, INSTALLPROPERTY_LASTUSEDSOURCEW ) &&
820 821 822 823 824 825
        dwOptions & (MSISOURCETYPE_NETWORK | MSISOURCETYPE_URL))
    {
        RegCloseKey(sourcekey);
        return ERROR_INVALID_PARAMETER;
    }

826 827
    if (!strcmpW( szProperty, INSTALLPROPERTY_MEDIAPACKAGEPATHW ) ||
        !strcmpW( szProperty, INSTALLPROPERTY_DISKPROMPTW ))
828
    {
829
        rc = OpenMediaSubkey(sourcekey, &media, TRUE);
830
        if (rc == ERROR_SUCCESS)
831 832 833 834
        {
            rc = msi_reg_set_val_str(media, property, szValue);
            RegCloseKey(media);
        }
835
    }
836
    else if (!strcmpW( szProperty, INSTALLPROPERTY_PACKAGENAMEW ))
837
    {
838
        DWORD size = (lstrlenW(szValue) + 1) * sizeof(WCHAR);
839
        rc = RegSetValueExW(sourcekey, INSTALLPROPERTY_PACKAGENAMEW, 0,
840
                REG_SZ, (const BYTE *)szValue, size);
841 842 843
        if (rc != ERROR_SUCCESS)
            rc = ERROR_UNKNOWN_PROPERTY;
    }
844
    else if (!strcmpW( szProperty, INSTALLPROPERTY_LASTUSEDSOURCEW ))
845 846 847 848 849 850 851
    {
        if (!(dwOptions & (MSISOURCETYPE_NETWORK | MSISOURCETYPE_URL)))
            rc = ERROR_INVALID_PARAMETER;
        else
            rc = msi_set_last_used_source(szProduct, szUserSid, dwContext,
                                          dwOptions, szValue);
    }
852 853 854 855 856 857 858
    else
        rc = ERROR_UNKNOWN_PROPERTY;

    RegCloseKey(sourcekey);
    return rc;
}

859 860 861 862 863 864
/******************************************************************
 *  MsiSourceListAddSourceW (MSI.@)
 */
UINT WINAPI MsiSourceListAddSourceW( LPCWSTR szProduct, LPCWSTR szUserName,
        DWORD dwReserved, LPCWSTR szSource)
{
865
    WCHAR squished_pc[GUID_SIZE];
866 867 868
    INT ret;
    LPWSTR sidstr = NULL;
    DWORD sidsize = 0;
869
    DWORD domsize = 0;
870 871 872
    DWORD context;
    HKEY hkey = 0;
    UINT r;
873 874 875

    TRACE("%s %s %s\n", debugstr_w(szProduct), debugstr_w(szUserName), debugstr_w(szSource));

876 877 878 879 880 881 882 883 884 885 886 887
    if (!szSource || !*szSource)
        return ERROR_INVALID_PARAMETER;

    if (dwReserved != 0)
        return ERROR_INVALID_PARAMETER;

    if (!szProduct || !squash_guid(szProduct, squished_pc))
        return ERROR_INVALID_PARAMETER;

    if (!szUserName || !*szUserName)
        context = MSIINSTALLCONTEXT_MACHINE;
    else
888
    {
889 890 891 892 893 894 895 896 897
        if (LookupAccountNameW(NULL, szUserName, NULL, &sidsize, NULL, &domsize, NULL))
        {
            PSID psid = msi_alloc(sidsize);

            if (LookupAccountNameW(NULL, szUserName, psid, &sidsize, NULL, &domsize, NULL))
                ConvertSidToStringSidW(psid, &sidstr);

            msi_free(psid);
        }
898

899 900
        r = MSIREG_OpenProductKey(szProduct, NULL,
                                  MSIINSTALLCONTEXT_USERMANAGED, &hkey, FALSE);
901 902 903 904
        if (r == ERROR_SUCCESS)
            context = MSIINSTALLCONTEXT_USERMANAGED;
        else
        {
905 906
            r = MSIREG_OpenProductKey(szProduct, NULL,
                                      MSIINSTALLCONTEXT_USERUNMANAGED,
907
                                      &hkey, FALSE);
908 909 910 911 912
            if (r != ERROR_SUCCESS)
                return ERROR_UNKNOWN_PRODUCT;

            context = MSIINSTALLCONTEXT_USERUNMANAGED;
        }
913

914
        RegCloseKey(hkey);
915 916 917
    }

    ret = MsiSourceListAddSourceExW(szProduct, sidstr, 
918
        context, MSISOURCETYPE_NETWORK, szSource, 0);
919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940

    if (sidstr)
        LocalFree(sidstr);

    return ret;
}

/******************************************************************
 *  MsiSourceListAddSourceA (MSI.@)
 */
UINT WINAPI MsiSourceListAddSourceA( LPCSTR szProduct, LPCSTR szUserName,
        DWORD dwReserved, LPCSTR szSource)
{
    INT ret;
    LPWSTR szwproduct;
    LPWSTR szwusername;
    LPWSTR szwsource;

    szwproduct = strdupAtoW( szProduct );
    szwusername = strdupAtoW( szUserName );
    szwsource = strdupAtoW( szSource );

941
    ret = MsiSourceListAddSourceW(szwproduct, szwusername, dwReserved, szwsource);
942 943 944 945 946 947 948 949

    msi_free(szwproduct);
    msi_free(szwusername);
    msi_free(szwsource);

    return ret;
}

950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
/******************************************************************
 *  MsiSourceListAddSourceExA (MSI.@)
 */
UINT WINAPI MsiSourceListAddSourceExA(LPCSTR szProduct, LPCSTR szUserSid,
        MSIINSTALLCONTEXT dwContext, DWORD dwOptions, LPCSTR szSource, DWORD dwIndex)
{
    UINT ret;
    LPWSTR product, usersid, source;

    product = strdupAtoW(szProduct);
    usersid = strdupAtoW(szUserSid);
    source = strdupAtoW(szSource);

    ret = MsiSourceListAddSourceExW(product, usersid, dwContext,
                                    dwOptions, source, dwIndex);

    msi_free(product);
    msi_free(usersid);
    msi_free(source);

    return ret;
}

973 974 975 976 977 978 979 980 981 982 983
static void free_source_list(struct list *sourcelist)
{
    while (!list_empty(sourcelist))
    {
        media_info *info = LIST_ENTRY(list_head(sourcelist), media_info, entry);
        list_remove(&info->entry);
        msi_free(info->path);
        msi_free(info);
    }
}

984 985
static void add_source_to_list(struct list *sourcelist, media_info *info,
                               DWORD *index)
986 987 988 989 990
{
    media_info *iter;
    BOOL found = FALSE;
    static const WCHAR fmt[] = {'%','i',0};

991 992
    if (index) *index = 0;

993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
    if (list_empty(sourcelist))
    {
        list_add_head(sourcelist, &info->entry);
        return;
    }

    LIST_FOR_EACH_ENTRY(iter, sourcelist, media_info, entry)
    {
        if (!found && info->index < iter->index)
        {
            found = TRUE;
            list_add_before(&iter->entry, &info->entry);
        }

        /* update the rest of the list */
        if (found)
            sprintfW(iter->szIndex, fmt, ++iter->index);
1010 1011
        else if (index)
            (*index)++;
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
    }

    if (!found)
        list_add_after(&iter->entry, &info->entry);
}

static UINT fill_source_list(struct list *sourcelist, HKEY sourcekey, DWORD *count)
{
    UINT r = ERROR_SUCCESS;
    DWORD index = 0;
    WCHAR name[10];
    DWORD size, val_size;
    media_info *entry;

    *count = 0;

    while (r == ERROR_SUCCESS)
    {
        size = sizeof(name) / sizeof(name[0]);
        r = RegEnumValueW(sourcekey, index, name, &size, NULL, NULL, NULL, &val_size);
        if (r != ERROR_SUCCESS)
            return r;

        entry = msi_alloc(sizeof(media_info));
        if (!entry)
            goto error;

        entry->path = msi_alloc(val_size);
        if (!entry->path)
1041 1042
        {
            msi_free(entry);
1043
            goto error;
1044
        }
1045 1046 1047 1048 1049 1050 1051 1052

        lstrcpyW(entry->szIndex, name);
        entry->index = atoiW(name);

        size++;
        r = RegEnumValueW(sourcekey, index, name, &size, NULL,
                          NULL, (LPBYTE)entry->path, &val_size);
        if (r != ERROR_SUCCESS)
1053 1054 1055
        {
            msi_free(entry->path);
            msi_free(entry);
1056
            goto error;
1057
        }
1058 1059

        index = ++(*count);
1060
        add_source_to_list(sourcelist, entry, NULL);
1061 1062 1063 1064 1065 1066 1067 1068
    }

error:
    *count = -1;
    free_source_list(sourcelist);
    return ERROR_OUTOFMEMORY;
}

1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
/******************************************************************
 *  MsiSourceListAddSourceExW (MSI.@)
 */
UINT WINAPI MsiSourceListAddSourceExW( LPCWSTR szProduct, LPCWSTR szUserSid,
        MSIINSTALLCONTEXT dwContext, DWORD dwOptions, LPCWSTR szSource, 
        DWORD dwIndex)
{
    HKEY sourcekey;
    HKEY typekey;
    UINT rc;
1079 1080
    struct list sourcelist;
    media_info *info;
1081
    WCHAR squished_pc[GUID_SIZE];
1082
    WCHAR name[10];
1083 1084
    LPWSTR source;
    LPCWSTR postfix;
1085
    DWORD size, count;
1086
    DWORD index;
1087

1088
    static const WCHAR fmt[] = {'%','i',0};
1089 1090 1091 1092

    TRACE("%s %s %x %x %s %i\n", debugstr_w(szProduct), debugstr_w(szUserSid),
          dwContext, dwOptions, debugstr_w(szSource), dwIndex);

1093
    if (!szProduct || !squash_guid(szProduct, squished_pc))
1094 1095
        return ERROR_INVALID_PARAMETER;

1096
    if (!szSource || !*szSource)
1097 1098
        return ERROR_INVALID_PARAMETER;

1099 1100 1101
    if (!(dwOptions & (MSISOURCETYPE_NETWORK | MSISOURCETYPE_URL)))
        return ERROR_INVALID_PARAMETER;

1102 1103 1104 1105 1106 1107
    if (dwOptions & MSICODE_PATCH)
    {
        FIXME("Unhandled options MSICODE_PATCH\n");
        return ERROR_FUNCTION_FAILED;
    }

1108 1109
    if (szUserSid && (dwContext & MSIINSTALLCONTEXT_MACHINE))
        return ERROR_INVALID_PARAMETER;
1110

1111
    rc = OpenSourceKey(szProduct, &sourcekey, MSICODE_PRODUCT, dwContext, FALSE);
1112
    if (rc != ERROR_SUCCESS)
1113
        return rc;
1114 1115 1116 1117 1118

    if (dwOptions & MSISOURCETYPE_NETWORK)
        rc = OpenNetworkSubkey(sourcekey, &typekey, TRUE);
    else if (dwOptions & MSISOURCETYPE_URL)
        rc = OpenURLSubkey(sourcekey, &typekey, TRUE);
1119 1120
    else if (dwOptions & MSISOURCETYPE_MEDIA)
        rc = OpenMediaSubkey(sourcekey, &typekey, TRUE);
1121 1122
    else
    {
1123
        ERR("unknown media type: %08x\n", dwOptions);
1124 1125 1126
        RegCloseKey(sourcekey);
        return ERROR_FUNCTION_FAILED;
    }
1127 1128 1129 1130 1131 1132
    if (rc != ERROR_SUCCESS)
    {
        ERR("can't open subkey %u\n", rc);
        RegCloseKey(sourcekey);
        return rc;
    }
1133

1134
    postfix = (dwOptions & MSISOURCETYPE_NETWORK) ? szBackSlash : szForwardSlash;
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
    if (szSource[lstrlenW(szSource) - 1] == *postfix)
        source = strdupW(szSource);
    else
    {
        size = lstrlenW(szSource) + 2;
        source = msi_alloc(size * sizeof(WCHAR));
        lstrcpyW(source, szSource);
        lstrcatW(source, postfix);
    }

1145 1146 1147
    list_init(&sourcelist);
    rc = fill_source_list(&sourcelist, typekey, &count);
    if (rc != ERROR_NO_MORE_ITEMS)
1148
        goto done;
1149 1150 1151 1152 1153

    size = (lstrlenW(source) + 1) * sizeof(WCHAR);

    if (count == 0)
    {
1154
        rc = RegSetValueExW(typekey, szOne, 0, REG_EXPAND_SZ, (LPBYTE)source, size);
1155 1156
        goto done;
    }
1157
    else if (dwIndex > count || dwIndex == 0)
1158
    {
1159 1160 1161
        sprintfW(name, fmt, count + 1);
        rc = RegSetValueExW(typekey, name, 0, REG_EXPAND_SZ, (LPBYTE)source, size);
        goto done;
1162 1163 1164
    }
    else
    {
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
        sprintfW(name, fmt, dwIndex);
        info = msi_alloc(sizeof(media_info));
        if (!info)
        {
            rc = ERROR_OUTOFMEMORY;
            goto done;
        }

        info->path = strdupW(source);
        lstrcpyW(info->szIndex, name);
        info->index = dwIndex;
1176
        add_source_to_list(&sourcelist, info, &index);
1177 1178 1179

        LIST_FOR_EACH_ENTRY(info, &sourcelist, media_info, entry)
        {
1180 1181 1182
            if (info->index < index)
                continue;

1183 1184 1185 1186 1187 1188
            size = (lstrlenW(info->path) + 1) * sizeof(WCHAR);
            rc = RegSetValueExW(typekey, info->szIndex, 0,
                                REG_EXPAND_SZ, (LPBYTE)info->path, size);
            if (rc != ERROR_SUCCESS)
                goto done;
        }
1189 1190
    }

1191 1192
done:
    free_source_list(&sourcelist);
1193
    msi_free(source);
1194 1195 1196 1197 1198 1199
    RegCloseKey(typekey);
    RegCloseKey(sourcekey);
    return rc;
}

/******************************************************************
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
 *  MsiSourceListAddMediaDiskA (MSI.@)
 */
UINT WINAPI MsiSourceListAddMediaDiskA(LPCSTR szProduct, LPCSTR szUserSid,
        MSIINSTALLCONTEXT dwContext, DWORD dwOptions, DWORD dwDiskId,
        LPCSTR szVolumeLabel, LPCSTR szDiskPrompt)
{
    UINT r;
    LPWSTR product = NULL;
    LPWSTR usersid = NULL;
    LPWSTR volume = NULL;
    LPWSTR prompt = NULL;

    if (szProduct) product = strdupAtoW(szProduct);
    if (szUserSid) usersid = strdupAtoW(szUserSid);
    if (szVolumeLabel) volume = strdupAtoW(szVolumeLabel);
    if (szDiskPrompt) prompt = strdupAtoW(szDiskPrompt);

    r = MsiSourceListAddMediaDiskW(product, usersid, dwContext, dwOptions,
                                     dwDiskId, volume, prompt);

    msi_free(product);
    msi_free(usersid);
    msi_free(volume);
    msi_free(prompt);

    return r;
}

/******************************************************************
 *  MsiSourceListAddMediaDiskW (MSI.@)
1230 1231 1232 1233 1234 1235 1236 1237 1238
 */
UINT WINAPI MsiSourceListAddMediaDiskW(LPCWSTR szProduct, LPCWSTR szUserSid, 
        MSIINSTALLCONTEXT dwContext, DWORD dwOptions, DWORD dwDiskId, 
        LPCWSTR szVolumeLabel, LPCWSTR szDiskPrompt)
{
    HKEY sourcekey;
    HKEY mediakey;
    UINT rc;
    WCHAR szIndex[10];
1239
    WCHAR squished_pc[GUID_SIZE];
1240 1241 1242
    LPWSTR buffer;
    DWORD size;

1243 1244
    static const WCHAR fmt[] = {'%','i',0};

1245 1246 1247
    TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct),
            debugstr_w(szUserSid), dwContext, dwOptions, dwDiskId,
            debugstr_w(szVolumeLabel), debugstr_w(szDiskPrompt));
1248

1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
    if (!szProduct || !squash_guid(szProduct, squished_pc))
        return ERROR_INVALID_PARAMETER;

    if (dwOptions != MSICODE_PRODUCT && dwOptions != MSICODE_PATCH)
        return ERROR_INVALID_PARAMETER;

    if ((szVolumeLabel && !*szVolumeLabel) || (szDiskPrompt && !*szDiskPrompt))
        return ERROR_INVALID_PARAMETER;

    if ((dwContext & MSIINSTALLCONTEXT_MACHINE) && szUserSid)
1259 1260 1261 1262 1263 1264 1265 1266
        return ERROR_INVALID_PARAMETER;

    if (dwOptions & MSICODE_PATCH)
    {
        FIXME("Unhandled options MSICODE_PATCH\n");
        return ERROR_FUNCTION_FAILED;
    }

1267
    rc = OpenSourceKey(szProduct, &sourcekey, MSICODE_PRODUCT, dwContext, FALSE);
1268
    if (rc != ERROR_SUCCESS)
1269
        return rc;
1270

1271
    OpenMediaSubkey(sourcekey, &mediakey, TRUE);
1272

1273
    sprintfW(szIndex, fmt, dwDiskId);
1274 1275

    size = 2;
1276 1277
    if (szVolumeLabel) size += lstrlenW(szVolumeLabel);
    if (szDiskPrompt) size += lstrlenW(szDiskPrompt);
1278

1279
    size *= sizeof(WCHAR);
1280
    buffer = msi_alloc(size);
1281 1282 1283
    *buffer = '\0';

    if (szVolumeLabel) lstrcpyW(buffer, szVolumeLabel);
1284
    lstrcatW(buffer, szSemiColon);
1285
    if (szDiskPrompt) lstrcatW(buffer, szDiskPrompt);
1286 1287

    RegSetValueExW(mediakey, szIndex, 0, REG_SZ, (LPBYTE)buffer, size);
1288
    msi_free(buffer);
1289 1290 1291 1292 1293 1294

    RegCloseKey(sourcekey);
    RegCloseKey(mediakey);

    return ERROR_SUCCESS;
}
1295 1296

/******************************************************************
1297
 *  MsiSourceListClearAllA (MSI.@)
1298 1299 1300
 */
UINT WINAPI MsiSourceListClearAllA( LPCSTR szProduct, LPCSTR szUserName, DWORD dwReserved )
{
1301
    FIXME("(%s %s %d)\n", debugstr_a(szProduct), debugstr_a(szUserName), dwReserved);
1302 1303 1304 1305
    return ERROR_SUCCESS;
}

/******************************************************************
1306
 *  MsiSourceListClearAllW (MSI.@)
1307 1308 1309
 */
UINT WINAPI MsiSourceListClearAllW( LPCWSTR szProduct, LPCWSTR szUserName, DWORD dwReserved )
{
1310
    FIXME("(%s %s %d)\n", debugstr_w(szProduct), debugstr_w(szUserName), dwReserved);
1311 1312
    return ERROR_SUCCESS;
}
1313

1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
/******************************************************************
 *  MsiSourceListClearAllExA (MSI.@)
 */
UINT WINAPI MsiSourceListClearAllExA( LPCSTR szProduct, LPCSTR szUserSid,
    MSIINSTALLCONTEXT dwContext, DWORD dwOptions )
{
    FIXME("(%s %s %d %08x)\n", debugstr_a(szProduct), debugstr_a(szUserSid),
          dwContext, dwOptions);
    return ERROR_SUCCESS;
}

/******************************************************************
 *  MsiSourceListClearAllExW (MSI.@)
 */
UINT WINAPI MsiSourceListClearAllExW( LPCWSTR szProduct, LPCWSTR szUserSid,
    MSIINSTALLCONTEXT dwContext, DWORD dwOptions )
{
    FIXME("(%s %s %d %08x)\n", debugstr_w(szProduct), debugstr_w(szUserSid),
          dwContext, dwOptions);
    return ERROR_SUCCESS;
}

1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
/******************************************************************
 *  MsiSourceListClearSourceA (MSI.@)
 */
UINT WINAPI MsiSourceListClearSourceA(LPCSTR szProductCodeOrPatchCode, LPCSTR szUserSid,
                                      MSIINSTALLCONTEXT dwContext, DWORD dwOptions,
                                      LPCSTR szSource)
{
    FIXME("(%s %s %x %x %s)\n", debugstr_a(szProductCodeOrPatchCode), debugstr_a(szUserSid),
          dwContext, dwOptions, debugstr_a(szSource));
    return ERROR_SUCCESS;
}

/******************************************************************
 *  MsiSourceListClearSourceW (MSI.@)
 */
UINT WINAPI MsiSourceListClearSourceW(LPCWSTR szProductCodeOrPatchCode, LPCWSTR szUserSid,
                                      MSIINSTALLCONTEXT dwContext, DWORD dwOptions,
                                      LPCWSTR szSource)
{
    FIXME("(%s %s %x %x %s)\n", debugstr_w(szProductCodeOrPatchCode), debugstr_w(szUserSid),
          dwContext, dwOptions, debugstr_w(szSource));
    return ERROR_SUCCESS;
}