public void TestAutoStart()
        {
            Console.WriteLine("TestAutoStart");

            ConfigFile configFile = new ConfigFile();
            // setup configuration
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            setupConfiguration.auto_start = true;
            setupConfiguration.auto_close_if_installed = true;
            setupConfiguration.installation_completed = string.Empty;
            setupConfiguration.installation_none = string.Empty;
            configFile.Children.Add(setupConfiguration);
            // marker that makes installed check succeeed after installation
            string markerFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            // dummy component
            ComponentCmd component = new ComponentCmd();
            setupConfiguration.Children.Add(component);
            component.command = string.Format("cmd.exe /C dir > \"{0}\"", markerFilename);
            InstalledCheckFile check = new InstalledCheckFile();
            check.filename = markerFilename;
            check.comparison = installcheckfile_comparison.exists;
            component.Children.Add(check);
            // configuration
            component.installcompletemessage = string.Empty;
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(configFilename);
            options.quiet = false;
            options.reboot = false;
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options));
            Assert.IsTrue(File.Exists(markerFilename));
            File.Delete(configFilename);
            File.Delete(markerFilename);
        }
Esempio n. 2
0
        public static InstalledCheck CreateFromXml(XmlElement element)
        {
            if (element.Attributes["type"] == null)
            {
                throw new Exception("Missing installcheck type");
            }

            InstalledCheck l_check;

            if (element.Attributes["type"].InnerText == "check_file")
            {
                l_check = new InstalledCheckFile();
            }
            else if (element.Attributes["type"].InnerText == "check_directory")
            {
                l_check = new InstalledCheckDirectory();
            }
            else if (element.Attributes["type"].InnerText == "check_registry_value")
            {
                l_check = new InstalledCheckRegistry();
            }
            else if (element.Attributes["type"].InnerText == "check_product")
            {
                l_check = new InstalledCheckProduct();
            }
            else
            {
                throw new Exception(string.Format(
                                        "Invalid installcheck type: {0}", element.Attributes["type"].InnerText));
            }

            l_check.FromXml(element);
            return(l_check);
        }
Esempio n. 3
0
        public void HideComponentIfInstalled_WithComponentAlreadyInstalledDuringInstallSequence_HidesComponent()
        {
            string dotNetInstallerExeFilePath = dotNetInstallerExeUtils.Executable;

            bool usingHtmlInstaller = dotNetInstallerExeFilePath.EndsWith("htmlInstaller.exe");

            // create configuration file
            ConfigFile configFile = new ConfigFile();

            // add a setup configuration
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);

            // add a component that is hidden if it's already installed
            ComponentCmd componentAlreadyInstalled = new ComponentCmd();
            componentAlreadyInstalled.hide_component_if_installed = true;
            setupConfiguration.Children.Add(componentAlreadyInstalled);

            // make the component appear to be already installed
            InstalledCheckFile existsCheck = new InstalledCheckFile();
            existsCheck.filename = dotNetInstallerExeUtils.Executable;
            existsCheck.comparison = installcheckfile_comparison.exists;
            componentAlreadyInstalled.Children.Add(existsCheck);

            // add another component that is not already installed
            ComponentCmd componentNotInstalled = new ComponentCmd();
            setupConfiguration.Children.Add(componentNotInstalled);

            // save the configuration file
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            configFile.SaveAs(configFilename);

            // execute dotNetInstaller
            string arguments = string.Format("/ConfigFile {0}", configFilename);
            using (Application dotNetInstaller = Application.Launch(new ProcessStartInfo(dotNetInstallerExeFilePath, arguments)))
            {
                // get the main install window
                Window mainWindow = dotNetInstaller.GetWindow("APPLICATION_NAME Installer", InitializeOption.NoCache);

                if (usingHtmlInstaller)
                {
                    // get all the checkboxes in the window
                    IUIItem[] checkBoxes = mainWindow.GetMultiple(SearchCriteria.ByControlType(typeof(CheckBox)));

                    // assert that there's only one checkbox
                    Assert.AreEqual(1, checkBoxes.Length);
                    Assert.AreEqual("command1 ", checkBoxes[0].Name);
                }
                else
                {
                    // using dotNetInstaller
                    // get the components list box
                    ListBox componentsList = mainWindow.Get<ListBox>();

                    // assert that only one component is in the list
                    Assert.AreEqual(1, componentsList.Items.Count);
                    Assert.AreEqual("command1 ", componentsList.Items[0].Name);
                }
            }
        }
        public void TestPromptForOptionalNotSet()
        {
            Console.WriteLine("TestPromptForOptionalNotSet");

            // configuration with a required and optional component that will auto-start
            // and won't prompt or execute the optional component

            string markerFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            ConfigFile configFile = new ConfigFile();

            SetupConfiguration setupConfiguration = new SetupConfiguration();
            setupConfiguration.auto_start = true;
            setupConfiguration.auto_close_if_installed = true;
            setupConfiguration.prompt_for_optional_components = false;
            setupConfiguration.installation_completed = "";
            setupConfiguration.installation_none = "";
            configFile.Children.Add(setupConfiguration);

            // dummy required component
            ComponentCmd component_required = new ComponentCmd();
            setupConfiguration.Children.Add(component_required);
            component_required.required_install = true;
            component_required.supports_install = true;
            component_required.command = "dummy";

            InstalledCheckRegistry check_required = new InstalledCheckRegistry();
            check_required.fieldname = "";
            check_required.path = "SOFTWARE";
            check_required.comparison = installcheckregistry_comparison.exists;
            component_required.Children.Add(check_required);

            // dummy optional component
            ComponentCmd component_optional = new ComponentCmd();
            setupConfiguration.Children.Add(component_optional);
            component_optional.required_install = false;
            component_optional.supports_install = true;
            component_optional.command = string.Format("cmd.exe /C dir > \"{0}\"", markerFilename);

            InstalledCheckFile check_optional = new InstalledCheckFile();
            check_optional.filename = markerFilename;
            check_optional.comparison = installcheckfile_comparison.exists;
            component_optional.Children.Add(check_optional);

            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);

            // will not auto close since all components installed successfully
            dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(configFilename);
            options.quiet = false;
            options.autostart = true;
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options));

            Assert.IsFalse(File.Exists(markerFilename));

            File.Delete(configFilename);
        }
        public static InstalledCheck CreateFromXml(XmlElement element)
        {
            if (element.Attributes["type"] == null)
                throw new Exception("Missing installcheck type");

            InstalledCheck l_check;
            if (element.Attributes["type"].InnerText == "check_file")
                l_check = new InstalledCheckFile();
            else if (element.Attributes["type"].InnerText == "check_directory")
                l_check = new InstalledCheckDirectory();
            else if (element.Attributes["type"].InnerText == "check_registry_value")
                l_check = new InstalledCheckRegistry();
            else if (element.Attributes["type"].InnerText == "check_product")
                l_check = new InstalledCheckProduct();
            else
                throw new Exception(string.Format(
                    "Invalid installcheck type: {0}", element.Attributes["type"].InnerText));

            l_check.FromXml(element);
            return l_check;
        }
        public void TestDefaultSelectionUninstall()
        {
            Console.WriteLine("TestDefaultSelectionUninstall");

            InstalledCheckFile existsCheck = new InstalledCheckFile();
            existsCheck.filename = dotNetInstallerExeUtils.Executable;
            existsCheck.comparison = installcheckfile_comparison.exists;
            ConfigFile configFile = new ConfigFile();
            // setup configuration
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            // dummy component 1
            ComponentCmd component1 = new ComponentCmd();
            setupConfiguration.Children.Add(component1);
            component1.uninstall_command = "cmd.exe /C exit /b 57";
            component1.selected_uninstall = true;
            component1.supports_uninstall = true;
            component1.Children.Add(existsCheck);
            // dummy component 2
            ComponentCmd component2 = new ComponentCmd();
            setupConfiguration.Children.Add(component2);
            component2.uninstall_command = "cmd.exe /C exit /b 42";
            component2.selected_uninstall = false ;
            component2.supports_uninstall = true;
            component2.Children.Add(existsCheck);
            // second component is selected and runs, not the first one
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(configFilename);
            options.uninstall = true;
            Assert.AreEqual(57, dotNetInstallerExeUtils.Run(options));
            // first component is selected and runs
            component2.selected_uninstall = true;
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            Assert.AreEqual(42, dotNetInstallerExeUtils.Run(options));
            File.Delete(configFilename);
        }
        public void TestAutoClosesAfterInstallWhenComponentInstallSucceeds()
        {
            Console.WriteLine("TestAutoClosesAfterInstallWhenComponentInstallSucceeds");

            // configuration with a component that will run and succeed and so dni will auto close

            // marker that makes installed check succeed after installation
            string markerFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            setupConfiguration.auto_start = true;
            setupConfiguration.auto_close_if_installed = true;
            setupConfiguration.installation_completed = null;
            configFile.Children.Add(setupConfiguration);

            // dummy component
            ComponentCmd component = new ComponentCmd();
            setupConfiguration.Children.Add(component);
            component.required_install = true;
            component.supports_install = true;
            component.command = string.Format("cmd.exe /C dir > \"{0}\"", markerFilename);

            InstalledCheckFile check = new InstalledCheckFile();
            check.filename = markerFilename;
            check.comparison = installcheckfile_comparison.exists;
            component.Children.Add(check);

            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);

            dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(configFilename);
            options.quiet = false;

            // will auto close since all components installed successfully
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options, TimeSpan.FromSeconds(3)));

            File.Delete(configFilename);
            File.Delete(markerFilename);
        }
        public void TestAutoClosesAfterInstallWhenCheckedComponentsInstallSucceeds()
        {
            Console.WriteLine("TestAutoClosesAfterInstallWhenCheckedComponentsInstallSucceeds");

            // configuration with two selected components and one unselected component
            // selected components will run and succeed, and so dni will auto close

            // marker that makes installed check succeed after installation
            string markerFilename1 = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            string markerFilename2 = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            setupConfiguration.auto_start = true;
            setupConfiguration.auto_close_if_installed = true;
            setupConfiguration.installation_completed = null;
            configFile.Children.Add(setupConfiguration);

            // required and selected component
            ComponentCmd component1 = new ComponentCmd();
            setupConfiguration.Children.Add(component1);
            component1.required_install = true;
            component1.selected_install = true;
            component1.supports_install = true;
            component1.command = string.Format("cmd.exe /C dir > \"{0}\"", markerFilename1);

            InstalledCheckFile check1 = new InstalledCheckFile();
            check1.filename = markerFilename1;
            check1.comparison = installcheckfile_comparison.exists;
            component1.Children.Add(check1);

            // optional and selected component
            ComponentCmd component2 = new ComponentCmd();
            setupConfiguration.Children.Add(component2);
            component2.required_install = false;
            component2.selected_install = true;
            component2.supports_install = true;
            component2.command = string.Format("cmd.exe /C dir > \"{0}\"", markerFilename2);

            InstalledCheckFile check2 = new InstalledCheckFile();
            check2.filename = markerFilename2;
            check2.comparison = installcheckfile_comparison.exists;
            component2.Children.Add(check2);

            // optional and unselected component
            ComponentCmd component3 = new ComponentCmd();
            setupConfiguration.Children.Add(component3);
            component3.required_install = false;
            component3.selected_install = false;
            component3.supports_install = true;
            component3.command = "cmd.exe /C exit /b 1";

            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);

            dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(configFilename);
            options.quiet = false;

            // will auto close since all checked components were installed
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options, TimeSpan.FromSeconds(6)));

            File.Delete(configFilename);
            File.Delete(markerFilename1);
            File.Delete(markerFilename2);
        }
        public void TestUninstallAuto()
        {
            Console.WriteLine("TestUninstallAuto");

            // a component that's already installed
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ComponentCmd cmd = new ComponentCmd();
            setupConfiguration.Children.Add(cmd);
            cmd.id = "cmd1";
            cmd.command = "cmd.exe /C exit /b 1"; // would fail if ran
            cmd.uninstall_command = "cmd.exe /C exit /b 0";
            cmd.supports_install = true;
            cmd.supports_uninstall = true;
            InstalledCheckFile check = new InstalledCheckFile();
            cmd.Children.Add(check);
            check.comparison = installcheckfile_comparison.exists;
            check.filename = dotNetInstallerExeUtils.Executable;
            // a second component that doesn't support uninstall
            ComponentCmd cmd2 = new ComponentCmd();
            setupConfiguration.Children.Add(cmd2);
            cmd2.id = "cmd2";
            cmd2.command = "cmd.exe /C exit /b 1"; // would fail if ran
            cmd2.uninstall_command = "cmd.exe /C exit /b 1"; // would fail if ran
            cmd2.supports_install = true;
            cmd2.supports_uninstall = false;
            cmd2.Children.Add(check);
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            // will fallback to uninstall since all components are installed
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(configFilename));
            File.Delete(configFilename);
        }
        public void TestUninstallMspSilentMode()
        {
            Console.WriteLine("TestUninstallMspSilentMode");

            InstallUILevel[] testUILevels = { InstallUILevel.basic, InstallUILevel.silent };
            foreach (InstallUILevel uilevel in testUILevels)
            {
                // a configuration with no components
                ConfigFile configFile = new ConfigFile();
                SetupConfiguration setupConfiguration = new SetupConfiguration();
                configFile.Children.Add(setupConfiguration);
                ComponentMsp msp = new ComponentMsp();
                msp.package = "mspdoesntexist.msp";
                msp.uninstall_cmdparameters = "";
                msp.uninstall_cmdparameters_basic = "/qb-";
                msp.uninstall_cmdparameters_silent = "/qb-";
                InstalledCheckFile self = new InstalledCheckFile();
                self.filename = dotNetInstallerExeUtils.Executable;
                self.comparison = installcheckfile_comparison.exists;
                msp.Children.Add(self);
                setupConfiguration.Children.Add(msp);
                // silent install, no dialog messages
                configFile.ui_level = uilevel;
                // save config file
                string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
                Console.WriteLine("Writing '{0}'", configFilename);
                configFile.SaveAs(configFilename);
                // execute dotNetInstaller
                dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(configFilename);
                options.uninstall = true;
                Assert.AreEqual(1619, dotNetInstallerExeUtils.Run(options));
                File.Delete(configFilename);
            }
        }