Exemple #1
0
        public bool Initialize(Session session, string resourcePath, ref InstallUIOptions internalUILevel)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            if ((internalUILevel & InstallUIOptions.Full) != InstallUIOptions.Full)
            {
                return(false);
            }

            if (string.Equals(session["REMOVE"], "All", StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            this._session           = session;
            this._installStartEvent = new ManualResetEvent(false);
            this._installExitEvent  = new ManualResetEvent(false);
            this._appThread         = new Thread(this.Run);
            this._appThread.SetApartmentState(ApartmentState.STA);
            this._appThread.Start();

            int waitResult = WaitHandle.WaitAny(new WaitHandle[] { this._installStartEvent, this._installExitEvent });

            if (waitResult == 1)
            {
                throw new InstallCanceledException();
            }
            internalUILevel = InstallUIOptions.NoChange | InstallUIOptions.SourceResolutionOnly;
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Sets up the user interface handlers.
        /// </summary>
        protected override void BeginProcessing()
        {
            // Set up the UI handlers.
            this.previousInternalUI = Installer.SetInternalUI(InstallUIOptions.Silent);
            this.previousExternalUI = Installer.SetExternalUI(this.OnMessage, InstallLogModes.FatalExit | InstallLogModes.Error | InstallLogModes.Warning | InstallLogModes.User);

            base.BeginProcessing();
        }
Exemple #3
0
        /// <summary>
        /// Initializes the embedded UI.
        /// </summary>
        /// <param name="session">Handle to the installer which can be used to get and set properties.
        /// The handle is only valid for the duration of this method call.</param>
        /// <param name="resourcePath">Path to the directory that contains all the files from the MsiEmbeddedUI table.</param>
        /// <param name="internalUILevel">On entry, contains the current UI level for the installation. After this
        /// method returns, the installer resets the UI level to the returned value of this parameter.</param>
        /// <returns>True if the embedded UI was successfully initialized; false if the installation
        /// should continue without the embedded UI.</returns>
        /// <exception cref="InstallCanceledException">The installation was canceled by the user.</exception>
        /// <exception cref="InstallerException">The embedded UI failed to initialize and
        /// causes the installation to fail.</exception>
        public bool Initialize(Session session, string resourcePath, ref InstallUIOptions internalUILevel)
        {
            if (session != null)
            {
                if ((internalUILevel & InstallUIOptions.Full) != InstallUIOptions.Full)
                {
                    // Don't show custom UI when the UI level is set to basic.
                    return(false);

                    // An embedded UI could display an alternate dialog sequence for reduced or
                    // basic modes, but it's not implemented here. We'll just fall back to the
                    // built-in MSI basic UI.
                }

                if (string.Equals(session["REMOVE"], "All", StringComparison.OrdinalIgnoreCase))
                {
                    // Don't show custom UI when uninstalling.
                    return(false);

                    // An embedded UI could display an uninstall wizard, it's just not imlemented here.
                }
            }

            this.session = session;

            // Start the setup wizard on a separate thread.
            installStartEvent = new ManualResetEvent(false);
            installExitEvent  = new ManualResetEvent(false);
            appThread         = new Thread(Run);
            appThread.SetApartmentState(ApartmentState.STA);
            appThread.Start();

            // Wait for the setup wizard to either kickoff the install or prematurely exit.
            var waitResult = WaitHandle.WaitAny(new WaitHandle[] { installStartEvent, installExitEvent });

            if (waitResult == 1)
            {
                // The setup wizard set the exit event instead of the start event. 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.
                internalUILevel = InstallUIOptions.NoChange | InstallUIOptions.SourceResolutionOnly;
                return(true);
            }
        }
Exemple #4
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;
            }
        }
Exemple #5
0
            internal UserInterfaceHandler(ExternalUIRecordHandler handler, bool force)
            {
                var internalUI = InstallUIOptions.Silent;

                if (force)
                {
                    internalUI |= InstallUIOptions.SourceResolutionOnly | InstallUIOptions.UacOnly;
                }

                var externalUI = InstallLogModes.ActionStart | InstallLogModes.ActionData | InstallLogModes.CommonData | InstallLogModes.Error
                                 | InstallLogModes.FatalExit | InstallLogModes.Info | InstallLogModes.Initialize | InstallLogModes.Progress
                                 | InstallLogModes.User | InstallLogModes.Verbose | InstallLogModes.Warning;

                // Set up the internal and external UI handling.
                this.previousInternalUI = Installer.SetInternalUI(internalUI);
                this.previousExternalUI = Installer.SetExternalUI(handler, externalUI);
            }
Exemple #6
0
        /// <summary>
        /// Sets up an external UI handler and runs the package.
        /// </summary>
        /// <param name="passes">Number of passing tests.</param>
        /// <param name="failures">Number of failing tests.</param>
        public void RunTests(out int passes, out int failures)
        {
            InstallUIOptions        previousUILevel   = Installer.SetInternalUI(InstallUIOptions.Silent);
            ExternalUIRecordHandler previousUIHandler = Installer.SetExternalUI(this.UIRecordHandler, InstallLogModes.FatalExit | InstallLogModes.Error | /*InstallLogModes.Info | */ InstallLogModes.User | InstallLogModes.ActionStart);

            try
            {
                foreach (string package in this.InputFiles)
                {
                    using (this.session = Installer.OpenPackage(package, false))
                    {
                        IList <string> mutations = this.session.Database.ExecuteStringQuery("SELECT DISTINCT `Mutation` FROM `WixUnitTest`");
                        foreach (string mutation in mutations)
                        {
                            if (!String.IsNullOrEmpty(mutation))
                            {
                                this.OnMessage(NitVerboses.RunningMutation(mutation));
                                this.session[Constants.LuxMutationRunningProperty] = mutation;
                            }

                            try
                            {
                                this.session.DoAction("INSTALL");
                            }
                            catch (InstallCanceledException)
                            {
                                ; // expected
                            }
                            catch (InstallerException ex)
                            {
                                this.OnMessage(NitErrors.PackageFailed(ex.Message));
                                ++this.failures;
                            }
                        }
                    }
                }
            }
            finally
            {
                Installer.SetExternalUI(previousUIHandler, InstallLogModes.None);
                Installer.SetInternalUI(previousUILevel);
            }

            passes   = this.passes;
            failures = this.failures;
        }
Exemple #7
0
        /// <summary>
        /// Initializes the embedded UI.
        /// </summary>
        /// <param name="session">Handle to the installer which can be used to get and set properties.
        /// The handle is only valid for the duration of this method call.</param>
        /// <param name="resourcePath">Path to the directory that contains all the files from the MsiEmbeddedUI table.</param>
        /// <param name="internalUILevel">On entry, contains the current UI level for the installation. After this
        /// method returns, the installer resets the UI level to the returned value of this parameter.</param>
        /// <returns>True if the embedded UI was successfully initialized; false if the installation
        /// should continue without the embedded UI.</returns>
        /// <exception cref="InstallCanceledException">The installation was canceled by the user.</exception>
        /// <exception cref="InstallerException">The embedded UI failed to initialize and
        /// causes the installation to fail.</exception>
        public bool Initialize(Session session, string resourcePath, ref InstallUIOptions internalUILevel)
        {
            if (session != null)
            {
                if ((internalUILevel & InstallUIOptions.Full) != InstallUIOptions.Full)
                {
                    // Don't show custom UI when the UI level is set to basic.
                    return false;

                    // An embedded UI could display an alternate dialog sequence for reduced or
                    // basic modes, but it's not implemented here. We'll just fall back to the
                    // built-in MSI basic UI.
                }

                if (String.Equals(session["REMOVE"], "All", StringComparison.OrdinalIgnoreCase))
                {
                    // Don't show custom UI when uninstalling.
                    return false;

                    // An embedded UI could display an uninstall wizard, it's just not imlemented here.
                }
            }

            // Start the setup wizard on a separate thread.
            this.installStartEvent = new ManualResetEvent(false);
            this.installExitEvent = new ManualResetEvent(false);
            this.appThread = new Thread(this.Run);
            this.appThread.SetApartmentState(ApartmentState.STA);
            this.appThread.Start();

            // Wait for the setup wizard to either kickoff the install or prematurely exit.
            int waitResult = WaitHandle.WaitAny(new WaitHandle[] { this.installStartEvent, this.installExitEvent });
            if (waitResult == 1)
            {
                // The setup wizard set the exit event instead of the start event. 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.
                internalUILevel = InstallUIOptions.NoChange | InstallUIOptions.SourceResolutionOnly;
                return true;
            }
        }
Exemple #8
0
        public bool Initialize(Session session, string resourcePath, ref InstallUIOptions uiLevel)
        {
            Debugger.Launch();
            if (session != null && (session.IsUninstalling() || uiLevel.IsBasic()))
                return false; //use built-in MSI basic UI

            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;
            }
        }
Exemple #9
0
 /// <summary>
 /// Sets up the user interface handlers.
 /// </summary>
 protected override void BeginProcessing()
 {
     // Set up the UI handlers.
     this.previousInternalUI = Installer.SetInternalUI(InstallUIOptions.Silent);
     base.BeginProcessing();
 }
 /// <summary>
 /// Sets the internal user interface to be silent.
 /// </summary>
 protected override void BeginProcessing()
 {
     this.previousInternalUI = Installer.SetInternalUI(InstallUIOptions.Silent);
     base.BeginProcessing();
 }
 public static InstallUIOptions SetInternalUI(InstallUIOptions uiOptions, ref IntPtr windowHandle)
 {
     return (InstallUIOptions) NativeMethods.MsiSetInternalUI((uint) uiOptions, ref windowHandle);
 }
 /// <summary>
 /// Enables the installer's internal user interface. Then this user interface is used
 /// for all subsequent calls to user-interface-generating installer functions in this process.
 /// The owner of the user interface does not change.
 /// </summary>
 /// <param name="uiOptions">Specifies the level of complexity of the user interface</param>
 /// <returns>The previous user interface level</returns>
 /// <remarks><p>
 /// Win32 MSI API:
 /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msisetinternalui.asp">MsiSetInternalUI</a>
 /// </p></remarks>
 public static InstallUIOptions SetInternalUI(InstallUIOptions uiOptions)
 {
     return (InstallUIOptions) NativeMethods.MsiSetInternalUI((uint) uiOptions, IntPtr.Zero);
 }
Exemple #13
0
 /// <summary>
 /// Enables the installer's internal user interface. Then this user interface is used
 /// for all subsequent calls to user-interface-generating installer functions in this process.
 /// The owner of the user interface does not change.
 /// </summary>
 /// <param name="uiOptions">Specifies the level of complexity of the user interface</param>
 /// <returns>The previous user interface level</returns>
 /// <remarks><p>
 /// Win32 MSI API:
 /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msisetinternalui.asp">MsiSetInternalUI</a>
 /// </p></remarks>
 public static InstallUIOptions SetInternalUI(InstallUIOptions uiOptions)
 {
     return((InstallUIOptions)NativeMethods.MsiSetInternalUI((uint)uiOptions, IntPtr.Zero));
 }
Exemple #14
0
 public static InstallUIOptions SetInternalUI(InstallUIOptions uiOptions, ref IntPtr windowHandle)
 {
     return((InstallUIOptions)NativeMethods.MsiSetInternalUI((uint)uiOptions, ref windowHandle));
 }
Exemple #15
0
        /// <summary>
        /// Sets up the user interface handlers.
        /// </summary>
        protected override void BeginProcessing()
        {
            // Set up the UI handlers.
            this.previousInternalUI = Installer.SetInternalUI(InstallUIOptions.Silent);
            this.previousExternalUI = Installer.SetExternalUI(this.OnMessage, InstallLogModes.FatalExit | InstallLogModes.Error | InstallLogModes.Warning | InstallLogModes.User);

            base.BeginProcessing();
        }
Exemple #16
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;
                }
            }
        }
Exemple #17
0
        internal static int Initialize(int sessionHandle, string uiClass, int internalUILevel)
        {
            Session session = null;

            try
            {
                session = new Session((IntPtr)sessionHandle, false);

                if (String.IsNullOrEmpty(uiClass))
                {
                    throw new ArgumentNullException("uiClass");
                }

                EmbeddedUIProxy.uiInstance = EmbeddedUIProxy.InstantiateUI(session, uiClass);
            }
            catch (Exception ex)
            {
                if (session != null)
                {
                    try
                    {
                        session.Log("Exception while loading embedded UI:");
                        session.Log(ex.ToString());
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            if (EmbeddedUIProxy.uiInstance == null)
            {
                return((int)ActionResult.Failure);
            }

            try
            {
                string           resourcePath = Path.GetDirectoryName(EmbeddedUIProxy.uiInstance.GetType().Assembly.Location);
                InstallUIOptions uiOptions    = (InstallUIOptions)internalUILevel;
                if (EmbeddedUIProxy.DebugBreakEnabled("Initialize"))
                {
                    System.Diagnostics.Debugger.Launch();
                }

                if (EmbeddedUIProxy.uiInstance.Initialize(session, resourcePath, ref uiOptions))
                {
                    // The embedded UI initialized and the installation should continue
                    // with internal UI reset according to options.
                    return(((int)uiOptions) << 16);
                }
                else
                {
                    // The embedded UI did not initialize but the installation should still continue
                    // with internal UI reset according to options.
                    return((int)uiOptions);
                }
            }
            catch (InstallCanceledException)
            {
                // The installation was canceled by the user.
                return((int)ActionResult.UserExit);
            }
            catch (Exception ex)
            {
                // An unhandled exception causes the installation to fail immediately.
                session.Log("Exception thrown by embedded UI initialization:");
                session.Log(ex.ToString());
                return((int)ActionResult.Failure);
            }
        }