예제 #1
0
        /// <summary>
        /// Initializes the specified session.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="resourcePath">The resource path.</param>
        /// <param name="uiLevel">The UI level.</param>
        /// <returns></returns>
        /// <exception cref="Microsoft.Deployment.WindowsInstaller.InstallCanceledException"></exception>
        public bool Initialize(Session session, string resourcePath, ref InstallUIOptions uiLevel)
        {
            //System.Diagnostics.Debugger.Launch();
            if (session != null && (session.IsUninstalling() || uiLevel.IsBasic()))
            {
                return(false); //use built-in MSI basic UI
            }
            try
            {
                ReadDialogs(session);

                var startEvent = new ManualResetEvent(false);

                var uiThread = new Thread(() =>
                {
                    shell = new UIShell(); //important to create the instance in the same thread that call ShowModal
                    shell.ShowModal(new MsiRuntime(session)
                    {
                        StartExecute = () => startEvent.Set()
                    }, this);
                    uiExitEvent.Set();
                });

                uiThread.SetApartmentState(ApartmentState.STA);
                uiThread.Start();

                int waitResult = WaitHandle.WaitAny(new[] { startEvent, uiExitEvent });
                if (waitResult == 1)
                {
                    //UI exited without starting the install. Cancel the installation.
                    throw new InstallCanceledException();
                }
                else
                {
                    // Start the installation with a silenced internal UI.
                    // This "embedded external UI" will handle message types except for source resolution.
                    uiLevel = InstallUIOptions.NoChange | InstallUIOptions.SourceResolutionOnly;
                    shell.OnExecuteStarted();
                    return(true);
                }
            }
            catch (Exception e)
            {
                session.Log("Cannot attach ManagedUI: " + e);
                throw;
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes the specified session.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="resourcePath">The resource path.</param>
        /// <param name="uiLevel">The UI level.</param>
        /// <returns></returns>
        /// <exception cref="Microsoft.Deployment.WindowsInstaller.InstallCanceledException"></exception>
        public bool Initialize(Session session, string resourcePath, ref InstallUIOptions uiLevel)
        {
            //System.Diagnostics.Debugger.Launch();
            if (session != null && (session.IsUninstalling() || uiLevel.IsBasic()))
            {
                return(false); //use built-in MSI basic UI
            }
            string upgradeCode = session["UpgradeCode"];

            using (cancelRequest)
            {
                try
                {
                    ReadDialogs(session);

                    var startEvent = new ManualResetEvent(false);

                    var uiThread = new Thread(() =>
                    {
                        session["WIXSHARP_MANAGED_UI"] = System.Reflection.Assembly.GetExecutingAssembly().ToString();
                        shell = new UIShell(); //important to create the instance in the same thread that call ShowModal
                        shell.ShowModal(new MsiRuntime(session)
                        {
                            StartExecute  = () => startEvent.Set(),
                            CancelExecute = () =>
                            {
                                // NOTE: IEmbeddedUI interface has no way to cancel the installation, which has been started
                                // (e.g. ProgressDialog is displayed). What is even worse is that UI can pass back to here
                                // a signal the user pressed 'Cancel' but nothing we can do with it. Install is already started
                                // and session object is now invalid.
                                // To solve this we use this work around - set a unique "cancel request mutex" form here
                                // and ManagedProjectActions.CancelRequestHandler built-in CA will pick the request and yield
                                // return code UserExit.
                                cancelRequest = new Mutex(true, "WIXSHARP_UI_CANCEL_REQUEST." + upgradeCode);
                            }
                        },
                                        this);
                        uiExitEvent.Set();
                    });

                    uiThread.SetApartmentState(ApartmentState.STA);
                    uiThread.Start();

                    int waitResult = WaitHandle.WaitAny(new[] { startEvent, uiExitEvent });
                    if (waitResult == 1)
                    {
                        //UI exited without starting the install. Cancel the installation.
                        throw new InstallCanceledException();
                    }
                    else
                    {
                        // Start the installation with a silenced internal UI.
                        // This "embedded external UI" will handle message types except for source resolution.
                        uiLevel = InstallUIOptions.NoChange | InstallUIOptions.SourceResolutionOnly;
                        shell.OnExecuteStarted();
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    session.Log("Cannot attach ManagedUI: " + e);
                    throw;
                }
            }
        }
예제 #3
0
파일: ManagedUI.cs 프로젝트: Eun/WixSharp
        /// <summary>
        /// Initializes the specified session.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="resourcePath">The resource path.</param>
        /// <param name="uiLevel">The UI level.</param>
        /// <returns></returns>
        /// <exception cref="Microsoft.Deployment.WindowsInstaller.InstallCanceledException"></exception>
        public bool Initialize(Session session, string resourcePath, ref InstallUIOptions uiLevel)
        {
            //System.Diagnostics.Debugger.Launch();
            if (session != null && (session.IsUninstalling() || uiLevel.IsBasic()))
                return false; //use built-in MSI basic UI

            try
            {
                ReadDialogs(session);

                var startEvent = new ManualResetEvent(false);

                var uiThread = new Thread(() =>
                {
                    shell = new UIShell(); //important to create the instance in the same thread that call ShowModal
                    shell.ShowModal(new MsiRuntime(session) { StartExecute = () => startEvent.Set() }, this);
                    uiExitEvent.Set();
                });

                uiThread.SetApartmentState(ApartmentState.STA);
                uiThread.Start();

                int waitResult = WaitHandle.WaitAny(new[] { startEvent, uiExitEvent });
                if (waitResult == 1)
                {
                    //UI exited without starting the install. Cancel the installation.
                    throw new InstallCanceledException();
                }
                else
                {
                    // Start the installation with a silenced internal UI.
                    // This "embedded external UI" will handle message types except for source resolution.
                    uiLevel = InstallUIOptions.NoChange | InstallUIOptions.SourceResolutionOnly;
                    shell.OnExecuteStarted();
                    return true;
                }
            }
            catch (Exception e)
            {
                session.Log("Cannot attach ManagedUI: " + e);
                throw;
            }
        }