source.c 38.4 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
                                         LPWSTR szVolumeLabel, LPDWORD pcchVolumeLabel,
                                         LPWSTR szDiskPrompt, LPDWORD pcchDiskPrompt)
{
211 212 213
    static const WCHAR fmt[] = {'#','%','d',0};
    WCHAR squashed_pc[SQUASHED_GUID_SIZE], convert[11];
    WCHAR *value = NULL, *data = NULL, *ptr, *ptr2;
214
    HKEY source, media;
215
    DWORD valuesz, datasz = 0, type, numvals, size;
216 217
    LONG res;
    UINT r;
218
    static DWORD index = 0;
219 220 221 222 223

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

224
    if (!szProductCodeOrPatchCode || !squash_guid( szProductCodeOrPatchCode, squashed_pc ))
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
        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;

242
    r = OpenSourceKey(szProductCodeOrPatchCode, &source, dwOptions, dwContext, FALSE);
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
    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);

277
    ptr2 = data;
278 279 280 281 282 283 284 285
    ptr = strchrW(data, ';');
    if (!ptr)
        ptr = data;
    else
        *ptr = '\0';

    if (pcchVolumeLabel)
    {
286 287 288 289 290 291 292 293 294
        if (type == REG_DWORD)
        {
            sprintfW(convert, fmt, *data);
            size = lstrlenW(convert);
            ptr2 = convert;
        }
        else
            size = lstrlenW(data);

295 296 297
        if (size >= *pcchVolumeLabel)
            r = ERROR_MORE_DATA;
        else if (szVolumeLabel)
298
            lstrcpyW(szVolumeLabel, ptr2);
299 300 301 302 303 304

        *pcchVolumeLabel = size;
    }

    if (pcchDiskPrompt)
    {
305 306
        if (!*ptr)
            ptr++;
307

308 309 310 311 312 313 314 315 316
        if (type == REG_DWORD)
        {
            sprintfW(convert, fmt, *ptr);
            size = lstrlenW(convert);
            ptr = convert;
        }
        else
            size = lstrlenW(ptr);

317 318 319
        if (size >= *pcchDiskPrompt)
            r = ERROR_MORE_DATA;
        else if (szDiskPrompt)
320
            lstrcpyW(szDiskPrompt, ptr);
321 322 323 324 325 326 327 328 329 330 331 332 333 334

        *pcchDiskPrompt = size;
    }

    index++;

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

    return r;
}

335 336 337 338 339 340 341 342
/******************************************************************
 *  MsiSourceListEnumSourcesA   (MSI.@)
 */
UINT WINAPI MsiSourceListEnumSourcesA(LPCSTR szProductCodeOrPatch, LPCSTR szUserSid,
                                      MSIINSTALLCONTEXT dwContext,
                                      DWORD dwOptions, DWORD dwIndex,
                                      LPSTR szSource, LPDWORD pcchSource)
{
343 344 345 346
    LPWSTR product = NULL;
    LPWSTR usersid = NULL;
    LPWSTR source = NULL;
    DWORD len = 0;
347
    UINT r = ERROR_INVALID_PARAMETER;
348
    static DWORD index = 0;
349 350 351 352

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

353 354 355
    if (dwIndex == 0)
        index = 0;

356
    if (szSource && !pcchSource)
357 358 359 360
        goto done;

    if (dwIndex != index)
        goto done;
361 362 363 364 365 366 367 368 369 370 371

    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)
372 373 374 375
    {
        r = ERROR_OUTOFMEMORY;
        goto done;
    }
376 377 378 379 380 381 382 383

    *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);
384
    if (pcchSource && *pcchSource >= len)
385 386 387 388
        WideCharToMultiByte(CP_ACP, 0, source, -1, szSource, len, NULL, NULL);
    else if (szSource)
        r = ERROR_MORE_DATA;

389 390
    if (pcchSource)
        *pcchSource = len - 1;
391 392 393 394 395 396

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

397 398
    if (r == ERROR_SUCCESS)
    {
399
        if (szSource || !pcchSource) index++;
400 401 402 403
    }
    else if (dwIndex > index)
        index = 0;

404 405 406 407
    return r;
}

/******************************************************************
408
 *  MsiSourceListEnumSourcesW   (MSI.@)
409 410 411 412 413 414
 */
UINT WINAPI MsiSourceListEnumSourcesW(LPCWSTR szProductCodeOrPatch, LPCWSTR szUserSid,
                                      MSIINSTALLCONTEXT dwContext,
                                      DWORD dwOptions, DWORD dwIndex,
                                      LPWSTR szSource, LPDWORD pcchSource)
{
415 416 417
    static const WCHAR format[] = {'%','d',0};
    WCHAR squashed_pc[SQUASHED_GUID_SIZE], name[32];
    HKEY source = NULL, subkey = NULL;
418 419
    LONG res;
    UINT r = ERROR_INVALID_PARAMETER;
420
    static DWORD index = 0;
421 422

    TRACE("(%s, %s, %d, %d, %d, %p, %p)\n", debugstr_w(szProductCodeOrPatch),
423
          debugstr_w(szUserSid), dwContext, dwOptions, dwIndex, szSource, pcchSource);
424 425 426 427

    if (dwIndex == 0)
        index = 0;

428
    if (!szProductCodeOrPatch || !squash_guid( szProductCodeOrPatch, squashed_pc ))
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
        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;

446
    r = OpenSourceKey( szProductCodeOrPatch, &source, dwOptions, dwContext, FALSE );
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
    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)
    {
473
        if (szSource || !pcchSource) index++;
474 475 476 477 478
    }
    else if (dwIndex > index)
        index = 0;

    return r;
479 480
}

481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
/******************************************************************
 *  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;

512
    *value = '\0';
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
    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;
}

534 535 536 537 538 539 540 541
/******************************************************************
 *  MsiSourceListGetInfoW   (MSI.@)
 */
UINT WINAPI MsiSourceListGetInfoW( LPCWSTR szProduct, LPCWSTR szUserSid,
                                   MSIINSTALLCONTEXT dwContext, DWORD dwOptions,
                                   LPCWSTR szProperty, LPWSTR szValue, 
                                   LPDWORD pcchValue) 
{
542 543
    static const WCHAR mediapack[] = {'M','e','d','i','a','P','a','c','k','a','g','e',0};
    WCHAR *source, *ptr, squashed_pc[SQUASHED_GUID_SIZE];
544
    HKEY sourcekey, media;
545
    DWORD size;
546 547 548 549
    UINT rc;

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

550
    if (!szProduct || !squash_guid( szProduct, squashed_pc ))
551 552 553 554
        return ERROR_INVALID_PARAMETER;

    if (szValue && !pcchValue)
        return ERROR_INVALID_PARAMETER;
555 556 557 558 559 560 561 562

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

    if (!szProperty)
        return ERROR_INVALID_PARAMETER;
563

564 565 566
    if (szUserSid)
        FIXME("Unhandled UserSid %s\n",debugstr_w(szUserSid));

567
    rc = OpenSourceKey(szProduct, &sourcekey, dwOptions, dwContext, FALSE);
568
    if (rc != ERROR_SUCCESS)
569
        return rc;
570

571 572
    if (!strcmpW( szProperty, INSTALLPROPERTY_MEDIAPACKAGEPATHW ) ||
        !strcmpW( szProperty, INSTALLPROPERTY_DISKPROMPTW ))
573
    {
574 575 576 577 578 579 580
        rc = OpenMediaSubkey(sourcekey, &media, FALSE);
        if (rc != ERROR_SUCCESS)
        {
            RegCloseKey(sourcekey);
            return ERROR_SUCCESS;
        }

581
        if (!strcmpW( szProperty, INSTALLPROPERTY_MEDIAPACKAGEPATHW ))
582 583 584 585
            szProperty = mediapack;

        RegQueryValueExW(media, szProperty, 0, 0, (LPBYTE)szValue, pcchValue);
        RegCloseKey(media);
586
    }
587 588
    else if (!strcmpW( szProperty, INSTALLPROPERTY_LASTUSEDSOURCEW ) ||
             !strcmpW( szProperty, INSTALLPROPERTY_LASTUSEDTYPEW ))
589
    {
590 591 592 593 594 595 596
        rc = RegQueryValueExW(sourcekey, INSTALLPROPERTY_LASTUSEDSOURCEW,
                              0, 0, NULL, &size);
        if (rc != ERROR_SUCCESS)
        {
            RegCloseKey(sourcekey);
            return ERROR_SUCCESS;
        }
597

598 599 600 601 602 603 604 605 606 607 608
        source = msi_alloc(size);
        RegQueryValueExW(sourcekey, INSTALLPROPERTY_LASTUSEDSOURCEW,
                         0, 0, (LPBYTE)source, &size);

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

609
        if (!strcmpW( szProperty, INSTALLPROPERTY_LASTUSEDTYPEW ))
610 611 612 613 614 615 616 617
        {
            if (*source != 'n' && *source != 'u' && *source != 'm')
            {
                msi_free(source);
                RegCloseKey(sourcekey);
                return ERROR_SUCCESS;
            }

618
            ptr = source;
619 620
            source[1] = '\0';
        }
621
        else
622 623 624 625 626 627 628
        {
            ptr = strrchrW(source, ';');
            if (!ptr)
                ptr = source;
            else
                ptr++;
        }
629 630

        if (szValue)
631
        {
632
            if (strlenW(ptr) < *pcchValue)
633
                lstrcpyW(szValue, ptr);
634
            else
635
                rc = ERROR_MORE_DATA;
636
        }
637 638 639

        *pcchValue = lstrlenW(ptr);
        msi_free(source);
640
    }
641
    else if (!strcmpW( szProperty, INSTALLPROPERTY_PACKAGENAMEW ))
642
    {
643 644 645
        *pcchValue = *pcchValue * sizeof(WCHAR);
        rc = RegQueryValueExW(sourcekey, INSTALLPROPERTY_PACKAGENAMEW, 0, 0,
                              (LPBYTE)szValue, pcchValue);
646
        if (rc != ERROR_SUCCESS && rc != ERROR_MORE_DATA)
647 648
        {
            *pcchValue = 0;
649
            rc = ERROR_SUCCESS;
650 651 652 653 654 655 656 657
        }
        else
        {
            if (*pcchValue)
                *pcchValue = (*pcchValue - 1) / sizeof(WCHAR);
            if (szValue)
                szValue[*pcchValue] = '\0';
        }
658 659 660 661 662 663 664 665 666 667 668
    }
    else
    {
        FIXME("Unknown property %s\n",debugstr_w(szProperty));
        rc = ERROR_UNKNOWN_PROPERTY;
    }

    RegCloseKey(sourcekey);
    return rc;
}

669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
/******************************************************************
 *  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;
}

698 699 700
UINT msi_set_last_used_source(LPCWSTR product, LPCWSTR usersid,
                              MSIINSTALLCONTEXT context, DWORD options,
                              LPCWSTR value)
701
{
702
    HKEY source;
703 704 705 706
    LPWSTR buffer;
    WCHAR typechar;
    DWORD size;
    UINT r;
707
    int index = 1;
708 709 710 711 712 713 714

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

    if (options & MSISOURCETYPE_NETWORK)
        typechar = 'n';
    else if (options & MSISOURCETYPE_URL)
        typechar = 'u';
715 716
    else if (options & MSISOURCETYPE_MEDIA)
        typechar = 'm';
717 718 719
    else
        return ERROR_INVALID_PARAMETER;

720 721 722 723 724 725
    if (!(options & MSISOURCETYPE_MEDIA))
    {
        r = MsiSourceListAddSourceExW(product, usersid, context,
                                      options, value, 0);
        if (r != ERROR_SUCCESS)
            return r;
726

727 728 729 730
        index = 0;
        while ((r = MsiSourceListEnumSourcesW(product, usersid, context, options,
                                              index, NULL, NULL)) == ERROR_SUCCESS)
            index++;
731

732 733 734
        if (r != ERROR_NO_MORE_ITEMS)
            return r;
    }
735 736 737 738 739 740

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

741 742
    r = OpenSourceKey(product, &source, MSICODE_PRODUCT, context, FALSE);
    if (r != ERROR_SUCCESS)
743 744
    {
        msi_free(buffer);
745
        return r;
746
    }
747

748 749
    sprintfW(buffer, format, typechar, index, value);

750
    size = (lstrlenW(buffer) + 1) * sizeof(WCHAR);
751 752 753 754
    r = RegSetValueExW(source, INSTALLPROPERTY_LASTUSEDSOURCEW, 0,
                       REG_SZ, (LPBYTE)buffer, size);
    msi_free(buffer);

755
    RegCloseKey(source);
756 757 758
    return r;
}

759 760 761 762 763 764 765
/******************************************************************
 *  MsiSourceListSetInfoW   (MSI.@)
 */
UINT WINAPI MsiSourceListSetInfoW( LPCWSTR szProduct, LPCWSTR szUserSid,
                                   MSIINSTALLCONTEXT dwContext, DWORD dwOptions,
                                   LPCWSTR szProperty, LPCWSTR szValue)
{
766 767
    static const WCHAR media_package[] = {'M','e','d','i','a','P','a','c','k','a','g','e',0};
    WCHAR squashed_pc[SQUASHED_GUID_SIZE];
768 769
    HKEY sourcekey, media;
    LPCWSTR property;
770 771
    UINT rc;

772
    TRACE("%s %s %x %x %s %s\n", debugstr_w(szProduct), debugstr_w(szUserSid),
773 774
            dwContext, dwOptions, debugstr_w(szProperty), debugstr_w(szValue));

775
    if (!szProduct || !squash_guid( szProduct, squashed_pc ))
776 777
        return ERROR_INVALID_PARAMETER;

778 779 780 781 782 783
    if (!szProperty)
        return ERROR_INVALID_PARAMETER;

    if (!szValue)
        return ERROR_UNKNOWN_PROPERTY;

784 785 786
    if (dwContext == MSIINSTALLCONTEXT_MACHINE && szUserSid)
        return ERROR_INVALID_PARAMETER;

787 788 789
    if (dwOptions & MSICODE_PATCH)
    {
        FIXME("Unhandled options MSICODE_PATCH\n");
790
        return ERROR_UNKNOWN_PATCH;
791
    }
792 793

    property = szProperty;
794
    if (!strcmpW( szProperty, INSTALLPROPERTY_MEDIAPACKAGEPATHW ))
795 796
        property = media_package;

797
    rc = OpenSourceKey(szProduct, &sourcekey, MSICODE_PRODUCT, dwContext, FALSE);
798
    if (rc != ERROR_SUCCESS)
799
        return rc;
800

801
    if (strcmpW( szProperty, INSTALLPROPERTY_LASTUSEDSOURCEW ) &&
802 803 804 805 806 807
        dwOptions & (MSISOURCETYPE_NETWORK | MSISOURCETYPE_URL))
    {
        RegCloseKey(sourcekey);
        return ERROR_INVALID_PARAMETER;
    }

808 809
    if (!strcmpW( szProperty, INSTALLPROPERTY_MEDIAPACKAGEPATHW ) ||
        !strcmpW( szProperty, INSTALLPROPERTY_DISKPROMPTW ))
810
    {
811
        rc = OpenMediaSubkey(sourcekey, &media, TRUE);
812
        if (rc == ERROR_SUCCESS)
813 814 815 816
        {
            rc = msi_reg_set_val_str(media, property, szValue);
            RegCloseKey(media);
        }
817
    }
818
    else if (!strcmpW( szProperty, INSTALLPROPERTY_PACKAGENAMEW ))
819
    {
820
        DWORD size = (lstrlenW(szValue) + 1) * sizeof(WCHAR);
821
        rc = RegSetValueExW(sourcekey, INSTALLPROPERTY_PACKAGENAMEW, 0,
822
                REG_SZ, (const BYTE *)szValue, size);
823 824 825
        if (rc != ERROR_SUCCESS)
            rc = ERROR_UNKNOWN_PROPERTY;
    }
826
    else if (!strcmpW( szProperty, INSTALLPROPERTY_LASTUSEDSOURCEW ))
827 828 829 830 831 832 833
    {
        if (!(dwOptions & (MSISOURCETYPE_NETWORK | MSISOURCETYPE_URL)))
            rc = ERROR_INVALID_PARAMETER;
        else
            rc = msi_set_last_used_source(szProduct, szUserSid, dwContext,
                                          dwOptions, szValue);
    }
834 835 836 837 838 839 840
    else
        rc = ERROR_UNKNOWN_PROPERTY;

    RegCloseKey(sourcekey);
    return rc;
}

841 842 843 844 845 846
/******************************************************************
 *  MsiSourceListAddSourceW (MSI.@)
 */
UINT WINAPI MsiSourceListAddSourceW( LPCWSTR szProduct, LPCWSTR szUserName,
        DWORD dwReserved, LPCWSTR szSource)
{
847
    WCHAR *sidstr = NULL, squashed_pc[SQUASHED_GUID_SIZE];
848
    INT ret;
849
    DWORD sidsize = 0, domsize = 0, context;
850 851
    HKEY hkey = 0;
    UINT r;
852 853 854

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

855 856 857 858 859 860
    if (!szSource || !*szSource)
        return ERROR_INVALID_PARAMETER;

    if (dwReserved != 0)
        return ERROR_INVALID_PARAMETER;

861
    if (!szProduct || !squash_guid( szProduct, squashed_pc ))
862 863 864 865 866
        return ERROR_INVALID_PARAMETER;

    if (!szUserName || !*szUserName)
        context = MSIINSTALLCONTEXT_MACHINE;
    else
867
    {
868 869 870 871 872 873 874 875 876
        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);
        }
877

878 879
        r = MSIREG_OpenProductKey(szProduct, NULL,
                                  MSIINSTALLCONTEXT_USERMANAGED, &hkey, FALSE);
880 881 882 883
        if (r == ERROR_SUCCESS)
            context = MSIINSTALLCONTEXT_USERMANAGED;
        else
        {
884 885
            r = MSIREG_OpenProductKey(szProduct, NULL,
                                      MSIINSTALLCONTEXT_USERUNMANAGED,
886
                                      &hkey, FALSE);
887 888 889 890 891
            if (r != ERROR_SUCCESS)
                return ERROR_UNKNOWN_PRODUCT;

            context = MSIINSTALLCONTEXT_USERUNMANAGED;
        }
892

893
        RegCloseKey(hkey);
894 895 896
    }

    ret = MsiSourceListAddSourceExW(szProduct, sidstr, 
897
        context, MSISOURCETYPE_NETWORK, szSource, 0);
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919

    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 );

920
    ret = MsiSourceListAddSourceW(szwproduct, szwusername, dwReserved, szwsource);
921 922 923 924 925 926 927 928

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

    return ret;
}

929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
/******************************************************************
 *  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;
}

952 953 954 955 956 957 958 959 960 961 962
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);
    }
}

963 964
static void add_source_to_list(struct list *sourcelist, media_info *info,
                               DWORD *index)
965 966 967 968 969
{
    media_info *iter;
    BOOL found = FALSE;
    static const WCHAR fmt[] = {'%','i',0};

970 971
    if (index) *index = 0;

972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988
    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);
989 990
        else if (index)
            (*index)++;
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
    }

    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)
1020 1021
        {
            msi_free(entry);
1022
            goto error;
1023
        }
1024 1025 1026 1027 1028 1029 1030 1031

        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)
1032 1033 1034
        {
            msi_free(entry->path);
            msi_free(entry);
1035
            goto error;
1036
        }
1037 1038

        index = ++(*count);
1039
        add_source_to_list(sourcelist, entry, NULL);
1040 1041 1042 1043 1044 1045 1046 1047
    }

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

1048 1049 1050 1051 1052 1053 1054
/******************************************************************
 *  MsiSourceListAddSourceExW (MSI.@)
 */
UINT WINAPI MsiSourceListAddSourceExW( LPCWSTR szProduct, LPCWSTR szUserSid,
        MSIINSTALLCONTEXT dwContext, DWORD dwOptions, LPCWSTR szSource, 
        DWORD dwIndex)
{
1055 1056
    static const WCHAR fmt[] = {'%','i',0};
    HKEY sourcekey, typekey;
1057
    UINT rc;
1058 1059
    struct list sourcelist;
    media_info *info;
1060
    WCHAR *source, squashed_pc[SQUASHED_GUID_SIZE], name[10];
1061
    LPCWSTR postfix;
1062
    DWORD size, count, index;
1063 1064 1065 1066

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

1067
    if (!szProduct || !squash_guid( szProduct, squashed_pc ))
1068 1069
        return ERROR_INVALID_PARAMETER;

1070
    if (!szSource || !*szSource)
1071 1072
        return ERROR_INVALID_PARAMETER;

1073 1074 1075
    if (!(dwOptions & (MSISOURCETYPE_NETWORK | MSISOURCETYPE_URL)))
        return ERROR_INVALID_PARAMETER;

1076 1077 1078 1079 1080 1081
    if (dwOptions & MSICODE_PATCH)
    {
        FIXME("Unhandled options MSICODE_PATCH\n");
        return ERROR_FUNCTION_FAILED;
    }

1082 1083
    if (szUserSid && (dwContext & MSIINSTALLCONTEXT_MACHINE))
        return ERROR_INVALID_PARAMETER;
1084

1085
    rc = OpenSourceKey(szProduct, &sourcekey, MSICODE_PRODUCT, dwContext, FALSE);
1086
    if (rc != ERROR_SUCCESS)
1087
        return rc;
1088 1089 1090 1091 1092

    if (dwOptions & MSISOURCETYPE_NETWORK)
        rc = OpenNetworkSubkey(sourcekey, &typekey, TRUE);
    else if (dwOptions & MSISOURCETYPE_URL)
        rc = OpenURLSubkey(sourcekey, &typekey, TRUE);
1093 1094
    else if (dwOptions & MSISOURCETYPE_MEDIA)
        rc = OpenMediaSubkey(sourcekey, &typekey, TRUE);
1095 1096
    else
    {
1097
        ERR("unknown media type: %08x\n", dwOptions);
1098 1099 1100
        RegCloseKey(sourcekey);
        return ERROR_FUNCTION_FAILED;
    }
1101 1102 1103 1104 1105 1106
    if (rc != ERROR_SUCCESS)
    {
        ERR("can't open subkey %u\n", rc);
        RegCloseKey(sourcekey);
        return rc;
    }
1107

1108
    postfix = (dwOptions & MSISOURCETYPE_NETWORK) ? szBackSlash : szForwardSlash;
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
    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);
    }

1119 1120 1121
    list_init(&sourcelist);
    rc = fill_source_list(&sourcelist, typekey, &count);
    if (rc != ERROR_NO_MORE_ITEMS)
1122
        goto done;
1123 1124 1125 1126 1127

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

    if (count == 0)
    {
1128
        rc = RegSetValueExW(typekey, szOne, 0, REG_EXPAND_SZ, (LPBYTE)source, size);
1129 1130
        goto done;
    }
1131
    else if (dwIndex > count || dwIndex == 0)
1132
    {
1133 1134 1135
        sprintfW(name, fmt, count + 1);
        rc = RegSetValueExW(typekey, name, 0, REG_EXPAND_SZ, (LPBYTE)source, size);
        goto done;
1136 1137 1138
    }
    else
    {
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
        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;
1150
        add_source_to_list(&sourcelist, info, &index);
1151 1152 1153

        LIST_FOR_EACH_ENTRY(info, &sourcelist, media_info, entry)
        {
1154 1155 1156
            if (info->index < index)
                continue;

1157 1158 1159 1160 1161 1162
            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;
        }
1163 1164
    }

1165 1166
done:
    free_source_list(&sourcelist);
1167
    msi_free(source);
1168 1169 1170 1171 1172 1173
    RegCloseKey(typekey);
    RegCloseKey(sourcekey);
    return rc;
}

/******************************************************************
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
 *  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.@)
1204 1205 1206 1207 1208
 */
UINT WINAPI MsiSourceListAddMediaDiskW(LPCWSTR szProduct, LPCWSTR szUserSid, 
        MSIINSTALLCONTEXT dwContext, DWORD dwOptions, DWORD dwDiskId, 
        LPCWSTR szVolumeLabel, LPCWSTR szDiskPrompt)
{
1209 1210
    static const WCHAR fmt[] = {'%','i',0};
    HKEY sourcekey, mediakey;
1211
    UINT rc;
1212
    WCHAR *buffer, squashed_pc[SQUASHED_GUID_SIZE], szIndex[10];
1213 1214
    DWORD size;

1215 1216 1217
    TRACE("%s %s %x %x %i %s %s\n", debugstr_w(szProduct),
            debugstr_w(szUserSid), dwContext, dwOptions, dwDiskId,
            debugstr_w(szVolumeLabel), debugstr_w(szDiskPrompt));
1218

1219
    if (!szProduct || !squash_guid( szProduct, squashed_pc ))
1220 1221 1222 1223 1224 1225 1226 1227 1228
        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)
1229 1230 1231 1232 1233 1234 1235 1236
        return ERROR_INVALID_PARAMETER;

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

1237
    rc = OpenSourceKey(szProduct, &sourcekey, MSICODE_PRODUCT, dwContext, FALSE);
1238
    if (rc != ERROR_SUCCESS)
1239
        return rc;
1240

1241
    OpenMediaSubkey(sourcekey, &mediakey, TRUE);
1242

1243
    sprintfW(szIndex, fmt, dwDiskId);
1244 1245

    size = 2;
1246 1247
    if (szVolumeLabel) size += lstrlenW(szVolumeLabel);
    if (szDiskPrompt) size += lstrlenW(szDiskPrompt);
1248

1249
    size *= sizeof(WCHAR);
1250
    buffer = msi_alloc(size);
1251 1252 1253
    *buffer = '\0';

    if (szVolumeLabel) lstrcpyW(buffer, szVolumeLabel);
1254
    lstrcatW(buffer, szSemiColon);
1255
    if (szDiskPrompt) lstrcatW(buffer, szDiskPrompt);
1256 1257

    RegSetValueExW(mediakey, szIndex, 0, REG_SZ, (LPBYTE)buffer, size);
1258
    msi_free(buffer);
1259 1260 1261 1262 1263 1264

    RegCloseKey(sourcekey);
    RegCloseKey(mediakey);

    return ERROR_SUCCESS;
}
1265 1266

/******************************************************************
1267
 *  MsiSourceListClearAllA (MSI.@)
1268 1269 1270
 */
UINT WINAPI MsiSourceListClearAllA( LPCSTR szProduct, LPCSTR szUserName, DWORD dwReserved )
{
1271
    FIXME("(%s %s %d)\n", debugstr_a(szProduct), debugstr_a(szUserName), dwReserved);
1272 1273 1274 1275
    return ERROR_SUCCESS;
}

/******************************************************************
1276
 *  MsiSourceListClearAllW (MSI.@)
1277 1278 1279
 */
UINT WINAPI MsiSourceListClearAllW( LPCWSTR szProduct, LPCWSTR szUserName, DWORD dwReserved )
{
1280
    FIXME("(%s %s %d)\n", debugstr_w(szProduct), debugstr_w(szUserName), dwReserved);
1281 1282
    return ERROR_SUCCESS;
}
1283

1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305
/******************************************************************
 *  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;
}

1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328
/******************************************************************
 *  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;
}