aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Msi/Session.cs
blob: d3a19711f268c259023659bc430f4cea9106c212 (plain)
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
44
45
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixToolset.Msi
{
    using System;
    using System.ComponentModel;
    using System.Globalization;
    using WixToolset.Core.Native;

    /// <summary>
    /// Controls the installation process.
    /// </summary>
    internal sealed class Session : MsiHandle
    {
        /// <summary>
        /// Instantiate a new Session.
        /// </summary>
        /// <param name="database">The database to open.</param>
        public Session(Database database)
        {
            string packagePath = String.Format(CultureInfo.InvariantCulture, "#{0}", (uint)database.Handle);

            uint handle = 0;
            int error = MsiInterop.MsiOpenPackage(packagePath, out handle);
            if (0 != error)
            {
                throw new MsiException(error);
            }
            this.Handle = handle;
        }

        /// <summary>
        /// Executes a built-in action, custom action, or user-interface wizard action.
        /// </summary>
        /// <param name="action">Specifies the action to execute.</param>
        public void DoAction(string action)
        {
            int error = MsiInterop.MsiDoAction(this.Handle, action);
            if (0 != error)
            {
                throw new MsiException(error);
            }
        }
    }
}