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

            ConfigFile configFile = new ConfigFile();
            // setup configuration
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ComponentCmd component1 = new ComponentCmd();
            setupConfiguration.Children.Add(component1);
            component1.id = "cmd1";
            component1.display_name = "command 1";
            component1.command = "cmd.exe /C exit /b ";
            component1.required_install = true;
            ComponentCmd component2 = new ComponentCmd();
            setupConfiguration.Children.Add(component2);
            component2.id = "cmd2";
            component2.display_name = "command 2";
            component2.command = "cmd.exe /C exit /b ";
            component2.required_install = true;
            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.args = "/ComponentArgs *:\"23\"";
            Assert.AreEqual(23, dotNetInstallerExeUtils.Run(options));
            File.Delete(configFilename);
        }
        public void TestRebootExitCode()
        {
            Console.WriteLine("TestRebootExitCode");

            // reboot exit code doesn't override a previous error
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ComponentCmd cmd_error = new ComponentCmd();
            cmd_error.command = "cmd.exe /C exit /b 42";
            cmd_error.required_install = true;
            cmd_error.allow_continue_on_error = true;
            cmd_error.default_continue_on_error = true;
            setupConfiguration.Children.Add(cmd_error);
            ComponentCmd cmd_reboot = new ComponentCmd();
            cmd_reboot.command = "cmd.exe /C exit /b 3010";
            cmd_error.required_install = true;
            cmd_reboot.returncodes_reboot = "3010";
            setupConfiguration.Children.Add(cmd_reboot);
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            Assert.AreEqual(42, dotNetInstallerExeUtils.Run(configFilename));
            File.Delete(configFilename);
            dotNetInstallerExeUtils.DisableRunOnReboot();
        }
        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);
        }
        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 TestDefaultSelectionInstall()
        {
            Console.WriteLine("TestDefaultSelectionInstall");

            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.command = "cmd.exe /C exit /b 57";
            component1.required_install = true;
            component1.selected_install = false;
            // dummy component 2
            ComponentCmd component2 = new ComponentCmd();
            setupConfiguration.Children.Add(component2);
            component2.command = "cmd.exe /C exit /b 42";
            component2.required_install = true;
            component2.selected_install = true;
            // 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);
            Assert.AreEqual(42, dotNetInstallerExeUtils.Run(options));
            // first component is selected and runs
            component1.selected_install = true;
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            Assert.AreEqual(57, dotNetInstallerExeUtils.Run(options));
            File.Delete(configFilename);
        }
 public void TestComponentWithoutCheck()
 {
     // a configuration with an optional component, complete command is executed
     ConfigFile configFile = new ConfigFile();
     SetupConfiguration setupConfiguration = new SetupConfiguration();
     string markerFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
     setupConfiguration.supports_uninstall = false; // otherwise would automatically switch to uninstall
     setupConfiguration.complete_command = string.Format("cmd.exe /C dir > \"{0}.ui\"", markerFilename);
     setupConfiguration.complete_command_basic = string.Format("cmd.exe /C dir > \"{0}.basic\"", markerFilename);
     setupConfiguration.complete_command_silent = string.Format("cmd.exe /C dir > \"{0}.silent\"", markerFilename);
     configFile.Children.Add(setupConfiguration);
     // required component that will run, but has no installed check
     ComponentCmd cmd1 = new ComponentCmd();
     setupConfiguration.Children.Add(cmd1);
     cmd1.command = "cmd.exe /C exit /b 0";
     // save config file
     string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
     Console.WriteLine("Writing '{0}'", configFilename);
     configFile.SaveAs(configFilename);
     // execute dotNetInstaller
     Assert.AreEqual(0, dotNetInstallerExeUtils.Run(configFilename));
     File.Delete(configFilename);
     Assert.IsFalse(File.Exists(markerFilename + ".silent"));
     File.Delete(markerFilename);
 }
        public void TestFailingComponent()
        {
            Console.WriteLine("TestFailingComponent");

            // a configuration with a component that fails, complete command is not executed
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            string markerFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".tmp");
            setupConfiguration.complete_command = string.Format("cmd.exe /C dir > \"{0}\"", markerFilename);
            setupConfiguration.complete_command_basic = setupConfiguration.complete_command;
            setupConfiguration.complete_command_silent = setupConfiguration.complete_command;
            ComponentCmd component = new ComponentCmd();
            setupConfiguration.Children.Add(component);
            component.command = "cmd.exe /C exit /b 123";
            component.required_install = true;
            // save config file
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            // execute dotNetInstaller
            Assert.AreEqual(123, dotNetInstallerExeUtils.Run(configFilename));
            File.Delete(configFilename);
            Assert.IsFalse(File.Exists(markerFilename));
        }
        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 void TestEmbedSplashScreen()
        {
            InstallerLinkerArguments args = new InstallerLinkerArguments();
            try
            {
                Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
                string binPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath));
                ConfigFile configFile = new ConfigFile();
                SetupConfiguration setupConfiguration = new SetupConfiguration();
                configFile.Children.Add(setupConfiguration);
                ComponentCmd cmd = new ComponentCmd();
                cmd.command = "cmd.exe /C exit /b 0";
                setupConfiguration.Children.Add(cmd);
                args.config = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
                Console.WriteLine("Writing '{0}'", args.config);
                configFile.SaveAs(args.config);
                args.output = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".exe");
                Console.WriteLine("Linking '{0}'", args.output);
                args.template = dotNetInstallerExeUtils.Executable;

                string relativePathName = "res";
                bool usingHtmlInstaller = dotNetInstallerExeUtils.Executable.EndsWith("htmlInstaller.exe");
                if (usingHtmlInstaller)
                {
                    relativePathName = "Html";
                }

                args.splash = Path.Combine(dotNetInstallerExeUtils.Location, string.Format(@"..\{0}\banner.bmp", relativePathName));
                InstallerLib.InstallerLinker.CreateInstaller(args);
                // check that the linker generated output
                Assert.IsTrue(File.Exists(args.output));
                Assert.IsTrue(new FileInfo(args.output).Length > 0);
                using (ResourceInfo ri = new ResourceInfo())
                {
                    ri.Load(args.output);
                    Assert.IsTrue(ri.Resources.ContainsKey(new ResourceId("CUSTOM")));
                    List<Resource> custom = ri.Resources[new ResourceId("CUSTOM")];
                    Assert.AreEqual("RES_BANNER", custom[0].Name.Name);
                    Assert.AreEqual("RES_CONFIGURATION", custom[1].Name.ToString());
                    Assert.AreEqual("RES_SPLASH", custom[2].Name.ToString());
                }
                // execute with and without splash
                dotNetInstallerExeUtils.Run(args.output, "/qb");
                dotNetInstallerExeUtils.Run(args.output, "/qb /nosplash");
            }
            finally
            {
                if (File.Exists(args.config))
                    File.Delete(args.config);
                if (File.Exists(args.output))
                    File.Delete(args.output);
            }
        }
 public void TestConfigLangID()
 {
     ConfigFile configFile = new ConfigFile();
     SetupConfiguration configuration = new SetupConfiguration();
     configFile.Children.Add(configuration);
     ComponentCmd cmd = new ComponentCmd();
     cmd.command = "cmd.exe /C exit /b #LANGID";
     cmd.required_install = true;
     configuration.language_id = "1234";
     configuration.Children.Add(cmd);
     string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
     Console.WriteLine("Writing '{0}'", configFilename);
     configFile.SaveAs(configFilename);
     Assert.AreEqual(1234, dotNetInstallerExeUtils.Run(configFilename));
     File.Delete(configFilename);
 }
        public void TestContinueOnError()
        {
            Console.WriteLine("TestContinueOnError");

            ConfigFile configFile = new ConfigFile();
            string markerFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            string markerFilename1 = string.Format("{0}.1", markerFilename);
            string markerFilename2 = string.Format("{0}.2", markerFilename);
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ComponentCmd cmd1 = new ComponentCmd();
            setupConfiguration.Children.Add(cmd1);
            cmd1.command = string.Format("cmd.exe /C dir > \"{0}\" & exit /b 1", markerFilename1);
            cmd1.required_install = true;
            ComponentCmd cmd2 = new ComponentCmd();
            setupConfiguration.Children.Add(cmd2);
            cmd2.command = string.Format("cmd.exe /C dir > \"{0}\" & exit /b 2", markerFilename2);
            cmd2.required_install = true;
            // save config file
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            // execute dotNetInstaller
            Assert.AreEqual(1, dotNetInstallerExeUtils.Run(configFilename));
            Assert.IsTrue(File.Exists(markerFilename1));
            Assert.IsFalse(File.Exists(markerFilename2));
            File.Delete(markerFilename1);
            // allow continue on error (user prompted) -> no effect, this is a prompt that defaults to false in silent mode
            cmd1.allow_continue_on_error = true;
            cmd2.allow_continue_on_error = true;
            configFile.SaveAs(configFilename);
            Assert.AreEqual(1, dotNetInstallerExeUtils.Run(configFilename));
            Assert.IsTrue(File.Exists(markerFilename1));
            Assert.IsFalse(File.Exists(markerFilename2));
            File.Delete(markerFilename1);
            // continue on error by default -> continues on the first and the second component, returns the last error code
            cmd1.default_continue_on_error = true;
            cmd2.default_continue_on_error = true;
            configFile.SaveAs(configFilename);
            // the return code of the first failure is saved
            Assert.AreEqual(1, dotNetInstallerExeUtils.Run(configFilename));
            Assert.IsTrue(File.Exists(markerFilename1));
            Assert.IsTrue(File.Exists(markerFilename2));
            File.Delete(markerFilename1);
            File.Delete(markerFilename2);
            File.Delete(configFilename);
        }
 public void TestLoadClear()
 {
     ConfigFile configFile = new ConfigFile();
     SetupConfiguration setupConfiguration = new SetupConfiguration();
     ComponentCmd cmd = new ComponentCmd();
     setupConfiguration.Children.Add(cmd);
     setupConfiguration.Children.Add(cmd);
     configFile.Children.Add(setupConfiguration);
     string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
     configFile.SaveAs(configFilename);
     int previousConfigurationCount = configFile.ConfigurationCount;
     XmlDocument xmlConfigFile = new XmlDocument();
     xmlConfigFile.Load(configFilename);
     configFile.LoadXml(xmlConfigFile);
     Assert.AreEqual(previousConfigurationCount, configFile.ConfigurationCount);
     File.Delete(configFilename);
 }
        public void TestNoUserControl()
        {
            Console.WriteLine("TestNoUserControl");

            // a configuration wthout a user control, value is blank
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b [doesntexist]5[doesntexist]";
            cmd.required_install = true;
            setupConfiguration.Children.Add(cmd);
            // save config file
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            // execute dotNetInstaller
            Assert.AreEqual(5, dotNetInstallerExeUtils.Run(configFilename));
            File.Delete(configFilename);
        }
        public void TestNoRunOnReboot()
        {
            Console.WriteLine("TestNoRunOnReboot");

            //return reboot code 3010
            //simulate passing /noRunOnReboot to dotNetInstaller on command line
            //ensure RunOnReboot registry key is not written

            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ComponentCmd cmd_reboot = new ComponentCmd();
            cmd_reboot.command = "cmd.exe /C exit /b 3010";
            cmd_reboot.returncodes_reboot = "3010";
            setupConfiguration.Children.Add(cmd_reboot);

            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.noRunOnReboot = true;

            Assert.AreEqual(3010, dotNetInstallerExeUtils.Run(options));

            File.Delete(configFilename);

            try
            {
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"))
                {
                    Assert.AreEqual(null, key.GetValue(Path.GetFileName(dotNetInstallerExeUtils.Executable)));
                }
            }
            catch
            {
                //remove RunOnReboot registry value if AssertionException is thrown
                dotNetInstallerExeUtils.DisableRunOnReboot();
                throw;
            }
        }
 public void TestComponentLcid()
 {
     // a configuration with one component
     ConfigFile configFile = new ConfigFile();
     SetupConfiguration setupConfiguration = new SetupConfiguration();
     configFile.Children.Add(setupConfiguration);
     // current lcid
     string currentLcidFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
     ComponentCmd cmdCurrentLcid = new ComponentCmd();
     cmdCurrentLcid.os_filter_lcid = CultureInfo.CurrentUICulture.LCID.ToString();
     Console.WriteLine("Current lcid: {0}", cmdCurrentLcid.os_filter_lcid);
     cmdCurrentLcid.command = string.Format("cmd.exe /C dir > \"{0}\"", currentLcidFilename);
     cmdCurrentLcid.required_install = true;
     setupConfiguration.Children.Add(cmdCurrentLcid);
     // empty lcid
     string emptyLcidFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
     ComponentCmd cmdEmptyLcid = new ComponentCmd();
     cmdEmptyLcid.command = string.Format("cmd.exe /C dir > \"{0}\"", emptyLcidFilename);
     cmdEmptyLcid.required_install = true;
     setupConfiguration.Children.Add(cmdEmptyLcid);
     // another lcid
     string anotherLcidFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
     ComponentCmd cmdAnotherLcid = new ComponentCmd();
     cmdAnotherLcid.os_filter_lcid = (CultureInfo.CurrentCulture.LCID + 1).ToString();
     Console.WriteLine("Another lcid: {0}", cmdAnotherLcid.os_filter_lcid);
     cmdAnotherLcid.command = string.Format("cmd.exe /C dir > \"{0}\"", anotherLcidFilename);
     cmdAnotherLcid.required_install = true;
     setupConfiguration.Children.Add(cmdAnotherLcid);
     // save config file
     string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
     Console.WriteLine("Writing '{0}'", configFilename);
     configFile.SaveAs(configFilename);
     // execute dotNetInstaller
     Assert.AreEqual(0, dotNetInstallerExeUtils.Run(configFilename));
     Assert.IsTrue(File.Exists(currentLcidFilename));
     Assert.IsTrue(File.Exists(emptyLcidFilename));
     Assert.IsFalse(File.Exists(anotherLcidFilename));
     File.Delete(currentLcidFilename);
     File.Delete(emptyLcidFilename);
     File.Delete(configFilename);
 }
        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 TestUserControlBrowseBackslashStripped()
        {
            Console.WriteLine("TestUserControlBrowseBackslashStripped");

            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ControlBrowse browse = new ControlBrowse();
            browse.Text = @"42\";
            browse.Id = "browse1";
            setupConfiguration.Children.Add(browse);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C if \"[browse1]\"==\"42\" ( exit /b 0 ) else ( exit /b 1 )";
            setupConfiguration.Children.Add(cmd);
            // save config file
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            // execute dotNetInstaller
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(configFilename));
            File.Delete(configFilename);
        }
        public void TestDownloadConfiguration()
        {
            Console.WriteLine("TestDownloadConfiguration");

            // a configuration with a single component that contains two download components
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ComponentCmd component1 = new ComponentCmd();
            setupConfiguration.Children.Add(component1);
            component1.command = "cmd.exe /C exit /b 0";
            component1.required_install = true;
            DownloadDialog component1downloaddialog = new DownloadDialog(
                string.Format("{0} Download Dialog", component1.id));
            component1.Children.Add(component1downloaddialog);
            Download component1download1 = new Download();
            component1download1.componentname = "download 1";
            component1download1.sourceurl = Assembly.GetExecutingAssembly().Location;
            component1download1.destinationpath = Path.GetTempPath();
            component1download1.destinationfilename = Guid.NewGuid().ToString();
            component1downloaddialog.Children.Add(component1download1);
            Download component1download2 = new Download();
            component1download2.componentname = "download 2";
            component1download2.sourceurl = Assembly.GetExecutingAssembly().Location;
            component1download2.destinationpath = Path.GetTempPath();
            component1download2.destinationfilename = Guid.NewGuid().ToString();
            component1downloaddialog.Children.Add(component1download2);
            // save config file
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            // execute dotNetInstaller
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(configFilename));
            File.Delete(configFilename);
            Assert.IsTrue(File.Exists(Path.Combine(component1download1.destinationpath, component1download1.destinationfilename)));
            File.Delete(Path.Combine(component1download1.destinationpath, component1download1.destinationfilename));
            Assert.IsTrue(File.Exists(Path.Combine(component1download2.destinationpath, component1download2.destinationfilename)));
            File.Delete(Path.Combine(component1download2.destinationpath, component1download2.destinationfilename));
        }
        public void TestNoDownloadWhenSourceFileExsts()
        {
            Console.WriteLine("TestNoDownloadWhenSourceFileExsts");

            // a configuration where the source file exists, no download dialog should show
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ComponentCmd cmd = new ComponentCmd();
            setupConfiguration.Children.Add(cmd);
            cmd.command = "cmd.exe /C exit /b 0";
            cmd.required_install = true;
            DownloadDialog cmddownloaddialog = new DownloadDialog(
                string.Format("{0} Download Dialog", cmd.id));
            cmd.Children.Add(cmddownloaddialog);
            cmddownloaddialog.autostartdownload = false;
            Download download = new Download();
            download.componentname = "download 1";
            download.sourceurl = string.Format("http://{0}/dummy.exe", Guid.NewGuid());
            download.sourcepath = Assembly.GetExecutingAssembly().Location;
            download.destinationpath = Path.GetTempPath();
            download.destinationfilename = Guid.NewGuid().ToString();
            download.alwaysdownload = false;
            cmddownloaddialog.Children.Add(download);
            // 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();
            options.configFile = configFilename;
            options.args = "/qb";
            options.quiet = false;
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options));
            File.Delete(configFilename);
            Assert.IsTrue(File.Exists(Path.Combine(download.destinationpath, download.destinationfilename)));
            File.Delete(Path.Combine(download.destinationpath, download.destinationfilename));
        }
示例#20
0
        public static Component CreateFromXml(XmlElement element)
        {
            Component l_Comp;
            string    xmltype = element.Attributes["type"].InnerText;

            if (xmltype == "msi")
            {
                l_Comp = new ComponentMsi();
            }
            else if (xmltype == "msu")
            {
                l_Comp = new ComponentMsu();
            }
            else if (xmltype == "msp")
            {
                l_Comp = new ComponentMsp();
            }
            else if (xmltype == "cmd")
            {
                l_Comp = new ComponentCmd();
            }
            else if (xmltype == "openfile")
            {
                l_Comp = new ComponentOpenFile();
            }
            else if (xmltype == "exe")
            {
                l_Comp = new ComponentExe();
            }
            else
            {
                throw new Exception(string.Format("Invalid type: {0}", xmltype));
            }

            l_Comp.FromXml(element);

            return(l_Comp);
        }
        public void TestUserControlBrowse()
        {
            Console.WriteLine("TestUserControlBrowse");

            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ControlBrowse browse = new ControlBrowse();
            browse.Text = "4";
            browse.Id = "browse1";
            setupConfiguration.Children.Add(browse);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b [browse1]";
            cmd.required_install = true;
            setupConfiguration.Children.Add(cmd);
            // save config file
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            // execute dotNetInstaller
            Assert.AreEqual(4, dotNetInstallerExeUtils.Run(configFilename));
            File.Delete(configFilename);
        }
        public void TestComponentNameArgQuotes()
        {
            Console.WriteLine("TestComponentNameArgQuotes");

            ConfigFile configFile = new ConfigFile();
            // setup configuration
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ComponentCmd component = new ComponentCmd();
            setupConfiguration.Children.Add(component);
            component.id = "cmd1";
            component.display_name = "command 1";
            component.command = "cmd.exe /C dir";
            component.required_install = true;
            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.args = "/ComponentArgs \"command 1\":\"INSTALLLOCATION=\"\"C:\\Program Files\\FooBar\"\" & exit /b 123\"";
            Assert.AreEqual(123, dotNetInstallerExeUtils.Run(options));
            File.Delete(configFilename);
        }
        public void TestUserControlLicense()
        {
            Console.WriteLine("TestUserControlLicense");

            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            // a configuration with a license agreement control
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ControlLicense license = new ControlLicense();
            license.Accepted = true;
            license.ResourceId = "MY_RES_LICENSE";
            license.LicenseFile = configFilename;
            setupConfiguration.Children.Add(license);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b [MY_RES_LICENSE]";
            cmd.required_install = true;
            setupConfiguration.Children.Add(cmd);
            // save config file
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            // create a setup with the license file
            InstallerLinkerArguments args = new InstallerLinkerArguments();
            args.config = configFilename;
            args.output = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".exe");
            args.template = dotNetInstallerExeUtils.Executable;
            Console.WriteLine("Linking '{0}'", args.output);
            InstallerLinkerExeUtils.CreateInstaller(args);
            Assert.IsTrue(File.Exists(args.output));
            // execute dotNetInstaller
            Assert.AreEqual(1, dotNetInstallerExeUtils.Run(args.output, "/q"));
            File.Delete(args.config);
            File.Delete(args.output);
        }
        public void TestUserControlImage()
        {
            Console.WriteLine("TestUserControlImage");

            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ControlImage image = new ControlImage();
            image.ResourceId = "RES_BANNER_DOESNTEXIST";
            setupConfiguration.Children.Add(image);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b 0";
            setupConfiguration.Children.Add(cmd);
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            Assert.AreEqual(-1, dotNetInstallerExeUtils.Run(configFilename));
            image.ResourceId = "RES_BANNER";
            configFile.SaveAs(configFilename);
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(configFilename));
            File.Delete(configFilename);
        }
        public void TestUserControlHyperlink()
        {
            Console.WriteLine("TestUserControlHyperlink");

            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ControlHyperlink hyperlink = new ControlHyperlink();
            hyperlink.Text = "url";
            hyperlink.Uri = "http://dotnetinstaller.codeplex.com";
            setupConfiguration.Children.Add(hyperlink);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b 0";
            setupConfiguration.Children.Add(cmd);
            // save config file
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            // execute dotNetInstaller
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(configFilename));
            File.Delete(configFilename);
        }
        public void TestUserControlEditInstalledCheckHasValueDisabled()
        {
            Console.WriteLine("TestUserControlEditInstalledCheckHasValueDisabled");

            // a configuration with a checkbox control
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ControlEdit edit = new ControlEdit();
            edit.Text = "4";
            edit.Id = "edit1";
            edit.Check = ControlCheckType.enabled; // control will be disabled, but has a value when disabled
            edit.HasValueDisabled = true;
            setupConfiguration.Children.Add(edit);
            // an installed check that is always false
            InstalledCheckRegistry check = new InstalledCheckRegistry();
            check.path = @"SOFTWARE\KeyDoesntExist";
            check.comparison = installcheckregistry_comparison.exists;
            edit.Children.Add(check);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b [edit1]5";
            cmd.required_install = true;
            setupConfiguration.Children.Add(cmd);
            // save config file
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            // execute dotNetInstaller
            Assert.AreEqual(45, dotNetInstallerExeUtils.Run(configFilename));
            File.Delete(configFilename);
        }
        public void TestUserControlEditHtmlValues()
        {
            Console.WriteLine("TestUserControlEditHtmlValues");

            bool usingHtmlInstaller = dotNetInstallerExeUtils.Executable.EndsWith("htmlInstaller.exe");
            if (!usingHtmlInstaller) return;

            // a configuration with a checkbox control
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            setupConfiguration.auto_start = true;
            setupConfiguration.failed_exec_command_continue = "";
            setupConfiguration.auto_close_on_error = true;
            configFile.Children.Add(setupConfiguration);
            ControlEdit edit = new ControlEdit();
            edit.Text = "3";
            edit.Id = "edit1";
            setupConfiguration.Children.Add(edit);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b [edit1]1";
            cmd.required_install = true;
            setupConfiguration.Children.Add(cmd);
            // save config file
            InstallerLinkerArguments args = new InstallerLinkerArguments();
            args.config = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", args.config);
            configFile.SaveAs(args.config);
            // create HTML directory
            string htmlPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            Directory.CreateDirectory(htmlPath);
            string htmlIndexFilename = Path.Combine(htmlPath, "index.html");
            File.WriteAllText(htmlIndexFilename,
                              @"<html><head><title></title></head><body>
                                <input type=""text"" id=""edit1"" value=""4"" />
                                <input id=""button_install"" type=""button"" value=""Install"" />
                                </body></html>");
            // link the install executable
            args.htmlFiles = new string[] { htmlPath };
            args.embed = true;
            args.apppath = Path.GetTempPath();
            args.embedFiles = new string[] { Path.GetFileName(args.config) };
            args.output = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".exe");
            args.template = dotNetInstallerExeUtils.Executable;
            Console.WriteLine("Linking '{0}'", args.output);
            InstallerLinkerExeUtils.CreateInstaller(args);
            Assert.IsTrue(File.Exists(args.output));
            // execute dotNetInstaller
            dotNetInstallerExeUtils.RunOptions runOptions = new dotNetInstallerExeUtils.RunOptions();
            runOptions.autostart = true;
            runOptions.quiet = false;
            Assert.AreEqual(41, dotNetInstallerExeUtils.Run(args.output, runOptions.CommandLineArgs));
            File.Delete(args.config);
            Directory.Delete(args.htmlFiles[0], true);
        }
        public void TestUserControlEditControlArgs()
        {
            Console.WriteLine("TestUserControlEditControlArgs");

            // a configuration with a checkbox control
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ControlEdit edit = new ControlEdit();
            edit.Text = "4";
            edit.Id = "edit1";
            setupConfiguration.Children.Add(edit);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b [edit1]";
            cmd.required_install = true;
            setupConfiguration.Children.Add(cmd);
            // 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();
            options.configFile = configFilename;
            // edit value
            options.args = "/controlArgs edit1:4";
            Assert.AreEqual(4, dotNetInstallerExeUtils.Run(options));
            File.Delete(configFilename);
        }
        public void TestUserControlCheckboxInstallCheck()
        {
            Console.WriteLine("TestUserControlCheckboxInstallCheck");

            // a configuration with a checkbox control which has an installed check that disables it
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            // a checkbox that changes are return value
            ControlCheckBox checkbox = new ControlCheckBox();
            checkbox.UncheckedValue = "3";
            checkbox.CheckedValue = "4";
            checkbox.Checked = true;
            checkbox.Id = "checkbox1";
            setupConfiguration.Children.Add(checkbox);
            // an installed check that is always false
            InstalledCheckRegistry check = new InstalledCheckRegistry();
            check.path = @"SOFTWARE\KeyDoesntExist";
            check.comparison = installcheckregistry_comparison.exists;
            checkbox.Children.Add(check);
            // command that depends on the value of checkbox1
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b [checkbox1]5";
            cmd.required_install = true;
            setupConfiguration.Children.Add(cmd);
            // save config file
            string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", configFilename);
            configFile.SaveAs(configFilename);
            // execute dotNetInstaller, this checkbox is disabled, so all runs ignore checkbox1 value
            Assert.AreEqual(5, dotNetInstallerExeUtils.Run(configFilename));
            checkbox.Checked = false;
            configFile.SaveAs(configFilename);
            Assert.AreEqual(5, dotNetInstallerExeUtils.Run(configFilename));
            checkbox.Checked = true;
            checkbox.CheckedValue = "0";
            configFile.SaveAs(configFilename);
            Assert.AreEqual(5, dotNetInstallerExeUtils.Run(configFilename));
            File.Delete(configFilename);
        }
        public void TestComponentArgIgnored()
        {
            Console.WriteLine("TestComponentArgIgnored");

            ConfigFile configFile = new ConfigFile();
            // setup configuration
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            ComponentCmd component = new ComponentCmd();
            setupConfiguration.Children.Add(component);
            component.id = "cmd1";
            component.display_name = "command 1";
            component.command = "cmd.exe /C exit /b 0";
            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.args = "/ComponentArgs cmddoesntexist:\"& exit /b 123\"";
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options));
            File.Delete(configFilename);
        }
        public void TestUserControlCheckboxControlArgs()
        {
            Console.WriteLine("TestUserControlCheckboxControlArgs");

            // a configuration with a checkbox control
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            // a checkbox that changes are return value
            ControlCheckBox checkbox = new ControlCheckBox();
            checkbox.UncheckedValue = "3";
            checkbox.CheckedValue = "4";
            checkbox.Checked = true;
            checkbox.Id = "checkbox1";
            setupConfiguration.Children.Add(checkbox);
            ComponentCmd cmd = new ComponentCmd();
            cmd.command = "cmd.exe /C exit /b [checkbox1]";
            cmd.required_install = true;
            setupConfiguration.Children.Add(cmd);
            // 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();
            options.configFile = configFilename;
            // unchecked value
            options.args = "/controlArgs checkbox1:3";
            Assert.AreEqual(3, dotNetInstallerExeUtils.Run(options));
            // checked value
            options.args = "/controlArgs checkbox1:4";
            Assert.AreEqual(4, dotNetInstallerExeUtils.Run(options));
            // invalid value
            options.args = "/controlArgs checkbox1:5";
            Assert.AreEqual(-1, dotNetInstallerExeUtils.Run(options));
            File.Delete(configFilename);
        }