install.c 20.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
/*
 * 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
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* Msi top level apis directly related to installs */

#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "wine/debug.h"
#include "msi.h"
#include "msidefs.h"
#include "msipriv.h"
#include "winuser.h"
#include "wine/unicode.h"
#include "action.h"

WINE_DEFAULT_DEBUG_CHANNEL(msi);

/***********************************************************************
 * MsiDoActionA       (MSI.@)
 */
UINT WINAPI MsiDoActionA( MSIHANDLE hInstall, LPCSTR szAction )
{
    LPWSTR szwAction;
44
    UINT ret;
45

46
    TRACE("%s\n", debugstr_a(szAction));
47 48

    szwAction = strdupAtoW(szAction);
49
    if (szAction && !szwAction)
50 51
        return ERROR_FUNCTION_FAILED; 

52
    ret = MsiDoActionW( hInstall, szwAction );
53
    msi_free( szwAction );
54
    return ret;
55 56 57 58 59 60 61 62
}

/***********************************************************************
 * MsiDoActionW       (MSI.@)
 */
UINT WINAPI MsiDoActionW( MSIHANDLE hInstall, LPCWSTR szAction )
{
    MSIPACKAGE *package;
63 64 65 66 67 68
    UINT ret;

    TRACE("%s\n",debugstr_w(szAction));

    if (!szAction)
        return ERROR_INVALID_PARAMETER;
69

70 71 72 73 74 75
    package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
    if (!package)
        return ERROR_INVALID_HANDLE;
 
    ret = ACTION_PerformUIAction( package, szAction );
    msiobj_release( &package->hdr );
76 77 78 79

    return ret;
}

80 81 82
/***********************************************************************
 * MsiSequenceA       (MSI.@)
 */
83
UINT WINAPI MsiSequenceA( MSIHANDLE hInstall, LPCSTR szTable, INT iSequenceMode )
84
{
85 86 87 88 89 90 91 92 93 94 95 96
    LPWSTR szwTable;
    UINT ret;

    TRACE("%s\n", debugstr_a(szTable));

    szwTable = strdupAtoW(szTable);
    if (szTable && !szwTable)
        return ERROR_FUNCTION_FAILED; 

    ret = MsiSequenceW( hInstall, szwTable, iSequenceMode );
    msi_free( szwTable );
    return ret;
97 98 99 100 101
}

/***********************************************************************
 * MsiSequenceW       (MSI.@)
 */
102
UINT WINAPI MsiSequenceW( MSIHANDLE hInstall, LPCWSTR szTable, INT iSequenceMode )
103
{
104 105 106 107 108 109 110 111 112 113 114 115 116
    MSIPACKAGE *package;
    UINT ret;

    TRACE("%s\n", debugstr_w(szTable));

    package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
    if (!package)
        return ERROR_INVALID_HANDLE;

    ret = MSI_Sequence( package, szTable, iSequenceMode );
    msiobj_release( &package->hdr );
 
    return ret;
117 118
}

119
UINT msi_strcpy_to_awstring( LPCWSTR str, awstring *awbuf, DWORD *sz )
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
{
    UINT len, r = ERROR_SUCCESS;

    if (awbuf->str.w && !sz )
        return ERROR_INVALID_PARAMETER;

    if (!sz)
        return r;
 
    if (awbuf->unicode)
    {
        len = lstrlenW( str );
        if (awbuf->str.w) 
            lstrcpynW( awbuf->str.w, str, *sz );
    }
    else
    {
137 138 139 140 141 142
        len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
        if (len)
            len--;
        WideCharToMultiByte( CP_ACP, 0, str, -1, awbuf->str.a, *sz, NULL, NULL );
        if ( *sz && (len >= *sz) )
            awbuf->str.a[*sz - 1] = 0;
143 144
    }

145
    if (awbuf->str.w && len >= *sz)
146 147 148 149 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
        r = ERROR_MORE_DATA;
    *sz = len;
    return r;
}

/***********************************************************************
 * MsiGetTargetPath   (internal)
 */
UINT WINAPI MSI_GetTargetPath( MSIHANDLE hInstall, LPCWSTR szFolder,
                               awstring *szPathBuf, DWORD* pcchPathBuf )
{
    MSIPACKAGE *package;
    LPWSTR path;
    UINT r;

    if (!szFolder)
        return ERROR_INVALID_PARAMETER;

    package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
    if (!package)
        return ERROR_INVALID_HANDLE;

    path = resolve_folder( package, szFolder, FALSE, FALSE, NULL );
    msiobj_release( &package->hdr );

    if (!path)
        return ERROR_DIRECTORY;

    r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
175
    msi_free( path );
176 177 178
    return r;
}

179 180 181 182
/***********************************************************************
 * MsiGetTargetPathA        (MSI.@)
 */
UINT WINAPI MsiGetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder, 
183
                               LPSTR szPathBuf, DWORD* pcchPathBuf )
184 185
{
    LPWSTR szwFolder;
186 187
    awstring path;
    UINT r;
188

189
    TRACE("%s %p %p\n", debugstr_a(szFolder), szPathBuf, pcchPathBuf);
190 191

    szwFolder = strdupAtoW(szFolder);
192
    if (szFolder && !szwFolder)
193 194
        return ERROR_FUNCTION_FAILED; 

195 196
    path.unicode = FALSE;
    path.str.a = szPathBuf;
197

198
    r = MSI_GetTargetPath( hInstall, szwFolder, &path, pcchPathBuf );
199

200
    msi_free( szwFolder );
201

202
    return r;
203 204 205
}

/***********************************************************************
206 207 208 209
 * MsiGetTargetPathW        (MSI.@)
 */
UINT WINAPI MsiGetTargetPathW( MSIHANDLE hInstall, LPCWSTR szFolder,
                               LPWSTR szPathBuf, DWORD* pcchPathBuf )
210
{
211
    awstring path;
212

213
    TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf);
214

215 216
    path.unicode = TRUE;
    path.str.w = szPathBuf;
217

218
    return MSI_GetTargetPath( hInstall, szFolder, &path, pcchPathBuf );
219 220 221
}

/***********************************************************************
222 223 224 225
 * MsiGetSourcePath   (internal)
 */
static UINT MSI_GetSourcePath( MSIHANDLE hInstall, LPCWSTR szFolder,
                               awstring *szPathBuf, DWORD* pcchPathBuf )
226
{
227
    MSIPACKAGE *package;
228 229
    LPWSTR path;
    UINT r;
230

231
    TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );
232 233

    if (!szFolder)
234
        return ERROR_INVALID_PARAMETER;
235

236 237 238
    package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
    if (!package)
        return ERROR_INVALID_HANDLE;
239

240 241 242 243 244
    if (szPathBuf->str.w && !pcchPathBuf )
    {
        msiobj_release( &package->hdr );
        return ERROR_INVALID_PARAMETER;
    }
245

246 247
    path = resolve_folder(package, szFolder, TRUE, FALSE, NULL);
    msiobj_release( &package->hdr );
248

249 250 251
    TRACE("path = %s\n",debugstr_w(path));
    if (!path)
        return ERROR_DIRECTORY;
252

253
    r = msi_strcpy_to_awstring( path, szPathBuf, pcchPathBuf );
254
    msi_free( path );
255
    return r;
256 257 258
}

/***********************************************************************
259 260 261 262
 * MsiGetSourcePathA     (MSI.@)
 */
UINT WINAPI MsiGetSourcePathA( MSIHANDLE hInstall, LPCSTR szFolder, 
                               LPSTR szPathBuf, DWORD* pcchPathBuf )
263
{
264 265 266
    LPWSTR folder;
    awstring str;
    UINT r;
267

268
    TRACE("%s %p %p\n", szFolder, debugstr_a(szPathBuf), pcchPathBuf);
269

270 271
    str.unicode = FALSE;
    str.str.a = szPathBuf;
272

273 274
    folder = strdupAtoW( szFolder );
    r = MSI_GetSourcePath( hInstall, folder, &str, pcchPathBuf );
275
    msi_free( folder );
276 277

    return r;
278 279
}

280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
/***********************************************************************
 * MsiGetSourcePathW     (MSI.@)
 */
UINT WINAPI MsiGetSourcePathW( MSIHANDLE hInstall, LPCWSTR szFolder,
                               LPWSTR szPathBuf, DWORD* pcchPathBuf )
{
    awstring str;

    TRACE("%s %p %p\n", debugstr_w(szFolder), szPathBuf, pcchPathBuf );

    str.unicode = TRUE;
    str.str.w = szPathBuf;

    return MSI_GetSourcePath( hInstall, szFolder, &str, pcchPathBuf );
}
295 296 297 298

/***********************************************************************
 * MsiSetTargetPathA  (MSI.@)
 */
299 300
UINT WINAPI MsiSetTargetPathA( MSIHANDLE hInstall, LPCSTR szFolder,
                               LPCSTR szFolderPath )
301
{
302 303
    LPWSTR szwFolder = NULL, szwFolderPath = NULL;
    UINT rc = ERROR_OUTOFMEMORY;
304

305 306
    if ( !szFolder || !szFolderPath )
        return ERROR_INVALID_PARAMETER;
307 308 309

    szwFolder = strdupAtoW(szFolder);
    szwFolderPath = strdupAtoW(szFolderPath);
310 311
    if (!szwFolder || !szwFolderPath)
        goto end;
312

313
    rc = MsiSetTargetPathW( hInstall, szwFolder, szwFolderPath );
314

315
end:
316 317
    msi_free(szwFolder);
    msi_free(szwFolderPath);
318 319 320 321

    return rc;
}

322 323 324 325 326
/*
 * Ok my original interpretation of this was wrong. And it looks like msdn has
 * changed a bit also. The given folder path does not have to actually already
 * exist, it just cannot be read only and must be a legal folder path.
 */
327 328 329
UINT MSI_SetTargetPathW(MSIPACKAGE *package, LPCWSTR szFolder, 
                             LPCWSTR szFolderPath)
{
330
    DWORD attrib;
331 332 333 334 335 336
    LPWSTR path = NULL;
    LPWSTR path2 = NULL;
    MSIFOLDER *folder;

    TRACE("(%p %s %s)\n",package, debugstr_w(szFolder),debugstr_w(szFolderPath));

337 338 339 340 341
    attrib = GetFileAttributesW(szFolderPath);
    if ( attrib != INVALID_FILE_ATTRIBUTES &&
          (!(attrib & FILE_ATTRIBUTE_DIRECTORY) ||
           attrib & FILE_ATTRIBUTE_OFFLINE ||
           attrib & FILE_ATTRIBUTE_READONLY))
342 343 344 345
        return ERROR_FUNCTION_FAILED;

    path = resolve_folder(package,szFolder,FALSE,FALSE,&folder);
    if (!path)
346
        return ERROR_DIRECTORY;
347

348 349 350
    if (attrib == INVALID_FILE_ATTRIBUTES)
    {
        if (!CreateDirectoryW(szFolderPath,NULL))
Mike McCormack's avatar
Mike McCormack committed
351 352
        {
            msi_free( path );
353
            return ERROR_FUNCTION_FAILED;
Mike McCormack's avatar
Mike McCormack committed
354
        }
355 356 357
        RemoveDirectoryW(szFolderPath);
    }

358
    msi_free(folder->Property);
359 360 361 362 363 364 365 366
    folder->Property = build_directory_name(2, szFolderPath, NULL);

    if (lstrcmpiW(path, folder->Property) == 0)
    {
        /*
         *  Resolved Target has not really changed, so just 
         *  set this folder and do not recalculate everything.
         */
367
        msi_free(folder->ResolvedTarget);
368 369
        folder->ResolvedTarget = NULL;
        path2 = resolve_folder(package,szFolder,FALSE,TRUE,NULL);
370
        msi_free(path2);
371 372 373
    }
    else
    {
374 375 376
        MSIFOLDER *f;

        LIST_FOR_EACH_ENTRY( f, &package->folders, MSIFOLDER, entry )
377
        {
378
            msi_free(f->ResolvedTarget);
379
            f->ResolvedTarget=NULL;
380 381
        }

382
        LIST_FOR_EACH_ENTRY( f, &package->folders, MSIFOLDER, entry )
383
        {
384
            path2 = resolve_folder(package, f->Directory, FALSE, TRUE, NULL);
385
            msi_free(path2);
386 387
        }
    }
388
    msi_free(path);
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403

    return ERROR_SUCCESS;
}

/***********************************************************************
 * MsiSetTargetPathW  (MSI.@)
 */
UINT WINAPI MsiSetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder, 
                             LPCWSTR szFolderPath)
{
    MSIPACKAGE *package;
    UINT ret;

    TRACE("(%s %s)\n",debugstr_w(szFolder),debugstr_w(szFolderPath));

404 405 406
    if ( !szFolder || !szFolderPath )
        return ERROR_INVALID_PARAMETER;

407
    package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
408 409 410
    if (!package)
        return ERROR_INVALID_HANDLE;

411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
    ret = MSI_SetTargetPathW( package, szFolder, szFolderPath );
    msiobj_release( &package->hdr );
    return ret;
}

/***********************************************************************
 *           MsiGetMode    (MSI.@)
 *
 * Returns an internal installer state (if it is running in a mode iRunMode)
 *
 * PARAMS
 *   hInstall    [I]  Handle to the installation
 *   hRunMode    [I]  Checking run mode
 *        MSIRUNMODE_ADMIN             Administrative mode
 *        MSIRUNMODE_ADVERTISE         Advertisement mode
 *        MSIRUNMODE_MAINTENANCE       Maintenance mode
 *        MSIRUNMODE_ROLLBACKENABLED   Rollback is enabled
 *        MSIRUNMODE_LOGENABLED        Log file is writing
 *        MSIRUNMODE_OPERATIONS        Operations in progress??
 *        MSIRUNMODE_REBOOTATEND       We need to reboot after installation completed
 *        MSIRUNMODE_REBOOTNOW         We need to reboot to continue the installation
 *        MSIRUNMODE_CABINET           Files from cabinet are installed
 *        MSIRUNMODE_SOURCESHORTNAMES  Long names in source files is suppressed
 *        MSIRUNMODE_TARGETSHORTNAMES  Long names in destination files is suppressed
 *        MSIRUNMODE_RESERVED11        Reserved
 *        MSIRUNMODE_WINDOWS9X         Running under Windows95/98
 *        MSIRUNMODE_ZAWENABLED        Demand installation is supported
 *        MSIRUNMODE_RESERVED14        Reserved
 *        MSIRUNMODE_RESERVED15        Reserved
 *        MSIRUNMODE_SCHEDULED         called from install script
 *        MSIRUNMODE_ROLLBACK          called from rollback script
 *        MSIRUNMODE_COMMIT            called from commit script
 *
 * RETURNS
 *    In the state: TRUE
 *    Not in the state: FALSE
 *
 */

BOOL WINAPI MsiGetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode)
{
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
    BOOL r = FALSE;

    switch (iRunMode)
    {
    case MSIRUNMODE_WINDOWS9X:
        if (GetVersion() & 0x80000000)
            r = TRUE;
        break;

    case MSIRUNMODE_RESERVED11:
    case MSIRUNMODE_RESERVED14:
    case MSIRUNMODE_RESERVED15:
        break;

    case MSIRUNMODE_SCHEDULED:
    case MSIRUNMODE_ROLLBACK:
    case MSIRUNMODE_COMMIT:
        break;

    default:
        FIXME("%ld %d\n", hInstall, iRunMode);
        r = TRUE;
    }

    return r;
477 478
}

479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
/***********************************************************************
 *           MsiSetMode    (MSI.@)
 */
BOOL WINAPI MsiSetMode(MSIHANDLE hInstall, MSIRUNMODE iRunMode, BOOL fState)
{
    switch (iRunMode)
    {
    case MSIRUNMODE_RESERVED11:
    case MSIRUNMODE_WINDOWS9X:
    case MSIRUNMODE_RESERVED14:
    case MSIRUNMODE_RESERVED15:
        return FALSE;
    default:
        FIXME("%ld %d %d\n", hInstall, iRunMode, fState);
    }
    return TRUE;
}

497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
/***********************************************************************
 * MsiSetFeatureStateA (MSI.@)
 *
 * According to the docs, when this is called it immediately recalculates
 * all the component states as well
 */
UINT WINAPI MsiSetFeatureStateA(MSIHANDLE hInstall, LPCSTR szFeature,
                                INSTALLSTATE iState)
{
    LPWSTR szwFeature = NULL;
    UINT rc;

    szwFeature = strdupAtoW(szFeature);

    if (!szwFeature)
        return ERROR_FUNCTION_FAILED;
   
    rc = MsiSetFeatureStateW(hInstall,szwFeature, iState); 

516
    msi_free(szwFeature);
517 518 519 520 521 522 523 524 525 526

    return rc;
}



UINT WINAPI MSI_SetFeatureStateW(MSIPACKAGE* package, LPCWSTR szFeature,
                                INSTALLSTATE iState)
{
    UINT rc = ERROR_SUCCESS;
527
    MSIFEATURE *feature, *child;
528 529 530

    TRACE(" %s to %i\n",debugstr_w(szFeature), iState);

531 532
    feature = get_loaded_feature(package,szFeature);
    if (!feature)
533 534 535
        return ERROR_UNKNOWN_FEATURE;

    if (iState == INSTALLSTATE_ADVERTISED && 
536
        feature->Attributes & msidbFeatureAttributesDisallowAdvertise)
537 538
        return ERROR_FUNCTION_FAILED;

539 540
    feature->ActionRequest = iState;
    feature->Action = iState;
541 542 543 544

    ACTION_UpdateComponentStates(package,szFeature);

    /* update all the features that are children of this feature */
545
    LIST_FOR_EACH_ENTRY( child, &package->features, MSIFEATURE, entry )
546
    {
547 548
        if (lstrcmpW(szFeature, child->Feature_Parent) == 0)
            MSI_SetFeatureStateW(package, child->Feature, iState);
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
    }
    
    return rc;
}

/***********************************************************************
 * MsiSetFeatureStateW (MSI.@)
 */
UINT WINAPI MsiSetFeatureStateW(MSIHANDLE hInstall, LPCWSTR szFeature,
                                INSTALLSTATE iState)
{
    MSIPACKAGE* package;
    UINT rc = ERROR_SUCCESS;

    TRACE(" %s to %i\n",debugstr_w(szFeature), iState);

    package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
    if (!package)
        return ERROR_INVALID_HANDLE;

    rc = MSI_SetFeatureStateW(package,szFeature,iState);

    msiobj_release( &package->hdr );
    return rc;
}

/***********************************************************************
* MsiGetFeatureStateA   (MSI.@)
*/
UINT WINAPI MsiGetFeatureStateA(MSIHANDLE hInstall, LPSTR szFeature,
                  INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
{
    LPWSTR szwFeature = NULL;
    UINT rc;
    
    szwFeature = strdupAtoW(szFeature);

    rc = MsiGetFeatureStateW(hInstall,szwFeature,piInstalled, piAction);

588
    msi_free( szwFeature);
589 590 591 592 593 594 595

    return rc;
}

UINT MSI_GetFeatureStateW(MSIPACKAGE *package, LPWSTR szFeature,
                  INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
{
596
    MSIFEATURE *feature;
597

598 599
    feature = get_loaded_feature(package,szFeature);
    if (!feature)
600 601 602
        return ERROR_UNKNOWN_FEATURE;

    if (piInstalled)
603
        *piInstalled = feature->Installed;
604 605

    if (piAction)
606
        *piAction = feature->Action;
607

608
    TRACE("returning %i %i\n", feature->Installed, feature->Action);
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632

    return ERROR_SUCCESS;
}

/***********************************************************************
* MsiGetFeatureStateW   (MSI.@)
*/
UINT WINAPI MsiGetFeatureStateW(MSIHANDLE hInstall, LPWSTR szFeature,
                  INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
{
    MSIPACKAGE* package;
    UINT ret;

    TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szFeature), piInstalled,
piAction);

    package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
    if (!package)
        return ERROR_INVALID_HANDLE;
    ret = MSI_GetFeatureStateW(package, szFeature, piInstalled, piAction);
    msiobj_release( &package->hdr );
    return ret;
}

633 634 635 636 637 638
/***********************************************************************
 * MsiSetComponentStateA (MSI.@)
 */
UINT WINAPI MsiSetComponentStateA(MSIHANDLE hInstall, LPCSTR szComponent,
                                  INSTALLSTATE iState)
{
639 640 641 642 643
    UINT rc;
    LPWSTR szwComponent = strdupAtoW(szComponent);

    rc = MsiSetComponentStateW(hInstall, szwComponent, iState);

644
    msi_free(szwComponent);
645 646

    return rc;
647 648
}

649 650 651 652 653 654 655 656 657 658 659 660 661
/***********************************************************************
 * MsiGetComponentStateA (MSI.@)
 */
UINT WINAPI MsiGetComponentStateA(MSIHANDLE hInstall, LPSTR szComponent,
                  INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
{
    LPWSTR szwComponent= NULL;
    UINT rc;
    
    szwComponent= strdupAtoW(szComponent);

    rc = MsiGetComponentStateW(hInstall,szwComponent,piInstalled, piAction);

662
    msi_free( szwComponent);
663 664 665 666

    return rc;
}

667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
static UINT MSI_SetComponentStateW(MSIPACKAGE *package, LPCWSTR szComponent,
                                   INSTALLSTATE iState)
{
    MSICOMPONENT *comp;

    TRACE("%p %s %d\n", package, debugstr_w(szComponent), iState);

    comp = get_loaded_component(package, szComponent);
    if (!comp)
        return ERROR_UNKNOWN_COMPONENT;

    comp->Installed = iState;

    return ERROR_SUCCESS;
}

683 684 685
UINT MSI_GetComponentStateW(MSIPACKAGE *package, LPWSTR szComponent,
                  INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
{
686
    MSICOMPONENT *comp;
687

688 689
    TRACE("%p %s %p %p\n", package, debugstr_w(szComponent),
           piInstalled, piAction);
690

691 692
    comp = get_loaded_component(package,szComponent);
    if (!comp)
693 694 695
        return ERROR_UNKNOWN_COMPONENT;

    if (piInstalled)
696
        *piInstalled = comp->Installed;
697 698

    if (piAction)
699
        *piAction = comp->Action;
700

701
    TRACE("states (%i, %i)\n", comp->Installed, comp->Action );
702 703 704 705

    return ERROR_SUCCESS;
}

706 707 708 709 710 711
/***********************************************************************
 * MsiSetComponentStateW (MSI.@)
 */
UINT WINAPI MsiSetComponentStateW(MSIHANDLE hInstall, LPCWSTR szComponent,
                                  INSTALLSTATE iState)
{
712 713 714 715 716 717 718 719 720
    MSIPACKAGE* package;
    UINT ret;

    package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
    if (!package)
        return ERROR_INVALID_HANDLE;
    ret = MSI_SetComponentStateW(package, szComponent, iState);
    msiobj_release(&package->hdr);
    return ret;
721 722
}

723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
/***********************************************************************
 * MsiGetComponentStateW (MSI.@)
 */
UINT WINAPI MsiGetComponentStateW(MSIHANDLE hInstall, LPWSTR szComponent,
                  INSTALLSTATE *piInstalled, INSTALLSTATE *piAction)
{
    MSIPACKAGE* package;
    UINT ret;

    TRACE("%ld %s %p %p\n", hInstall, debugstr_w(szComponent),
           piInstalled, piAction);

    package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
    if (!package)
        return ERROR_INVALID_HANDLE;
    ret = MSI_GetComponentStateW( package, szComponent, piInstalled, piAction);
    msiobj_release( &package->hdr );
    return ret;
}
Aric Stewart's avatar
Aric Stewart committed
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757

/***********************************************************************
 * MsiGetLanguage (MSI.@)
 */
LANGID WINAPI MsiGetLanguage(MSIHANDLE hInstall)
{
    MSIPACKAGE* package;
    LANGID langid;
    LPWSTR buffer;
    static const WCHAR szProductLanguage[] =
        {'P','r','o','d','u','c','t','L','a','n','g','u','a','g','e',0};
    
    package = msihandle2msiinfo(hInstall, MSIHANDLETYPE_PACKAGE);
    if (!package)
        return ERROR_INVALID_HANDLE;

758
    buffer = msi_dup_property( package, szProductLanguage );
Aric Stewart's avatar
Aric Stewart committed
759 760
    langid = atoiW(buffer);

761
    msi_free(buffer);
Aric Stewart's avatar
Aric Stewart committed
762 763 764
    msiobj_release (&package->hdr);
    return langid;
}