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 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 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 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 TestNotAutoClosesAfterInstallWhenComponentInstallFails() { Console.WriteLine("TestNotAutoClosesAfterInstallWhenComponentInstallFails"); // configuration with a component that will run and fail and so dni will not auto close ConfigFile configFile = new ConfigFile(); SetupConfiguration setupConfiguration = new SetupConfiguration(); setupConfiguration.auto_start = true; setupConfiguration.auto_close_if_installed = true; setupConfiguration.installation_completed = null; setupConfiguration.failed_exec_command_continue = string.Empty; configFile.Children.Add(setupConfiguration); ComponentCmd cmd = new ComponentCmd(); cmd.command = "cmd.exe /C exit /b 1"; cmd.required_install = true; cmd.supports_install = true; setupConfiguration.Children.Add(cmd); InstalledCheckRegistry check = new InstalledCheckRegistry(); check.path = @"SOFTWARE\KeyDoesntExists"; check.comparison = installcheckregistry_comparison.exists; cmd.Children.Add(check); string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); Console.WriteLine("Writing '{0}'", configFilename); configFile.SaveAs(configFilename); // will not auto close since all required components failed to install Assert.AreNotEqual(0, dotNetInstallerExeUtils.Run(configFilename)); dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(configFilename); options.quiet = false; Process p = dotNetInstallerExeUtils.Detach(options); Assert.IsFalse(p.WaitForExit(3 * 1000)); p.Kill(); p.WaitForExit(); Assert.AreEqual(-1, p.ExitCode); File.Delete(configFilename); }