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 TestUserControlEditInstalledCheckDisplay() { Console.WriteLine("TestUserControlEditInstalledCheckDisplay"); // 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.display; 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(5, dotNetInstallerExeUtils.Run(configFilename)); File.Delete(configFilename); }
public void TestUninstallSwitch() { Console.WriteLine("TestUninstallSwitch"); 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 1"; // would fail if ran cmd.required_install = true; cmd.uninstall_command = "cmd.exe /C exit /b 0"; cmd.supports_install = true; cmd.supports_uninstall = true; string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); Console.WriteLine("Writing '{0}'", configFilename); configFile.SaveAs(configFilename); // execute uninstall dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(configFilename); options.uninstall = false; Assert.AreNotEqual(0, dotNetInstallerExeUtils.Run(options)); options.uninstall = true; Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options)); File.Delete(configFilename); }
public void TestNoAutoStart() { Console.WriteLine("TestNoAutoStart"); ConfigFile configFile = new ConfigFile(); // setup configuration SetupConfiguration setupConfiguration = new SetupConfiguration(); setupConfiguration.auto_start = false; setupConfiguration.installation_completed = string.Empty; configFile.Children.Add(setupConfiguration); // dummy component ComponentCmd component = new ComponentCmd(); setupConfiguration.Children.Add(component); 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.quiet = false; Process p = dotNetInstallerExeUtils.Detach(options); Assert.IsFalse(p.WaitForExit(2 * 1000)); p.Kill(); p.WaitForExit(); Assert.AreEqual(-1, p.ExitCode); File.Delete(configFilename); }
public void TestUserControlEdit() { Console.WriteLine("TestUserControlEdit"); // 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 Assert.AreEqual(4, dotNetInstallerExeUtils.Run(configFilename)); 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 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 TestOptionalComponentWithoutCheck() { // 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.required_install = false; 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.IsTrue(File.Exists(markerFilename + ".silent")); File.Delete(markerFilename); }
public void TestUserControlBrowseDrive() { Console.WriteLine("TestUserControlBrowseDrive"); ConfigFile configFile = new ConfigFile(); SetupConfiguration setupConfiguration = new SetupConfiguration(); configFile.Children.Add(setupConfiguration); ControlBrowse browse = new ControlBrowse(); browse.Text = @"C:\"; browse.Id = "browse1"; setupConfiguration.Children.Add(browse); ComponentCmd cmd = new ComponentCmd(); cmd.command = "cmd.exe /C if \"[browse1]\"==\"C:\\\" ( 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 TestUserControlBrowseControlArgs() { Console.WriteLine("TestUserControlBrowseControlArgs"); // a configuration with a checkbox control 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 dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(); options.configFile = configFilename; options.args = "/controlArgs browse1:4"; Assert.AreEqual(4, dotNetInstallerExeUtils.Run(options)); File.Delete(configFilename); }
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 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 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 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 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 TestContinueOnErrorNoMessage() { Console.WriteLine("TestContinueOnErrorNoMessage"); // test that with all failed_exec_command_continue blanked, // user is never asked a question in full UI mode (not blocked) 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); // running in full UI mode, auto-start setupConfiguration.auto_start = true; // running in full UI mode, installation is expected to fail, auto-close setupConfiguration.auto_close_on_error = true; setupConfiguration.installation_none = string.Empty; setupConfiguration.installation_completed = string.Empty; 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; // 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; // remove all continue or stop error messages setupConfiguration.failed_exec_command_continue = string.Empty; cmd1.failed_exec_command_continue = string.Empty; cmd1.failed_exec_command_continue = string.Empty; cmd2.failed_exec_command_continue = string.Empty; // save config file string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); Console.WriteLine("Writing '{0}'", configFilename); configFile.SaveAs(configFilename); // the return code of the first failure is saved dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(configFilename); // all continue error messages are blank, nothing should popup to block the test options.quiet = false; Assert.AreEqual(1, dotNetInstallerExeUtils.Run(options)); Assert.IsTrue(File.Exists(markerFilename1)); Assert.IsTrue(File.Exists(markerFilename2)); File.Delete(markerFilename1); File.Delete(markerFilename2); 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 TestConfigurationLcid() { // a configuration with one component ConfigFile configFile = new ConfigFile(); // current lcid setup configuration SetupConfiguration currentLcidConfiguration = new SetupConfiguration(); currentLcidConfiguration.lcid_filter = CultureInfo.CurrentUICulture.LCID.ToString(); configFile.Children.Add(currentLcidConfiguration); string currentLcidFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); ComponentCmd cmdCurrentLcid = new ComponentCmd(); Console.WriteLine("Current lcid: {0}", currentLcidConfiguration.lcid_filter); cmdCurrentLcid.command = string.Format("cmd.exe /C dir > \"{0}\" & exit /b 0", currentLcidFilename); cmdCurrentLcid.required_install = true; currentLcidConfiguration.Children.Add(cmdCurrentLcid); // empty lcid setup configuration SetupConfiguration emptyLcidConfiguration = new SetupConfiguration(); configFile.Children.Add(emptyLcidConfiguration); string emptyLcidFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); ComponentCmd cmdEmptyLcid = new ComponentCmd(); cmdEmptyLcid.command = string.Format("cmd.exe /C dir > \"{0}\" & exit /b 0", emptyLcidFilename); cmdEmptyLcid.required_install = true; emptyLcidConfiguration.Children.Add(cmdEmptyLcid); // another lcid setup configuration SetupConfiguration anotherLcidConfiguration = new SetupConfiguration(); anotherLcidConfiguration.lcid_filter = (CultureInfo.CurrentCulture.LCID + 1).ToString(); configFile.Children.Add(anotherLcidConfiguration); string anotherLcidFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); ComponentCmd cmdAnotherLcid = new ComponentCmd(); Console.WriteLine("Another lcid: {0}", anotherLcidConfiguration.lcid_filter); cmdAnotherLcid.command = string.Format("cmd.exe /C dir > \"{0}\" & exit /b 0", anotherLcidFilename); cmdAnotherLcid.required_install = true; anotherLcidConfiguration.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 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 TestExtractAndRunCabPerComponent() { Console.WriteLine("TestExtractAndRunCabPerComponent"); InstallerLinkerArguments args = new InstallerLinkerArguments(); args.config = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); Console.WriteLine("Writing '{0}'", args.config); args.embed = true; args.apppath = Path.GetTempPath(); args.output = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".exe"); args.template = dotNetInstallerExeUtils.Executable; // create a self-extracting bootstrapper ConfigFile configFile = new ConfigFile(); SetupConfiguration setupConfiguration = new SetupConfiguration(); setupConfiguration.cab_path = Path.Combine(Path.GetTempPath(), "testExtractAndRunCabPerComponent"); setupConfiguration.cab_path_autodelete = false; configFile.Children.Add(setupConfiguration); ComponentCmd component = new ComponentCmd(); component.command = "cmd.exe /C copy \"#CABPATH\\component\\before.xml\" \"#CABPATH\\component\\after.xml\""; component.required_install = true; setupConfiguration.Children.Add(component); EmbedFile embedfile = new EmbedFile(); embedfile.sourcefilepath = args.config; embedfile.targetfilepath = @"component\before.xml"; component.Children.Add(embedfile); configFile.SaveAs(args.config); Console.WriteLine("Linking '{0}'", args.output); InstallerLinkerExeUtils.CreateInstaller(args); Assert.IsTrue(File.Exists(args.output)); // execute dotNetInstaller string logfile = Path.Combine(Path.GetTempPath(), "testExtractAndRunCabPerComponent.log"); Console.WriteLine("Log: {0}", logfile); Assert.AreEqual(0, dotNetInstallerExeUtils.Run(args.output, string.Format("/qb /log /logfile \"{0}\"", logfile))); string extractedComponentPath = Path.Combine(setupConfiguration.cab_path, "component"); Console.WriteLine("Checking {0}", extractedComponentPath); Assert.IsTrue(Directory.Exists(extractedComponentPath), string.Format("Missing {0}", extractedComponentPath)); Assert.IsTrue(File.Exists(Path.Combine(Path.GetTempPath(), @"testExtractAndRunCabPerComponent\component\before.xml"))); Assert.IsTrue(File.Exists(Path.Combine(Path.GetTempPath(), @"testExtractAndRunCabPerComponent\component\after.xml"))); File.Delete(args.config); File.Delete(args.output); Directory.Delete(setupConfiguration.cab_path, true); File.Delete(logfile); }
public void TestExtractCabTwoComponentsSameName() { Console.WriteLine("TestExtractCabTwoComponentsSameName"); InstallerLinkerArguments args = new InstallerLinkerArguments(); args.config = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); Console.WriteLine("Writing '{0}'", args.config); args.embed = true; args.apppath = Path.GetTempPath(); args.output = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".exe"); args.template = dotNetInstallerExeUtils.Executable; // create a self-extracting bootstrapper ConfigFile configFile = new ConfigFile(); SetupConfiguration setupConfiguration = new SetupConfiguration(); configFile.Children.Add(setupConfiguration); for (int i = 0; i < 2; i++) { ComponentCmd component = new ComponentCmd(); component.id = "component"; setupConfiguration.Children.Add(component); EmbedFile embedfile = new EmbedFile(); embedfile.sourcefilepath = args.config; embedfile.targetfilepath = string.Format("component{0}\\file.xml", i); component.Children.Add(embedfile); } configFile.SaveAs(args.config); Console.WriteLine("Linking '{0}'", args.output); InstallerLinkerExeUtils.CreateInstaller(args); Assert.IsTrue(File.Exists(args.output)); // execute dotNetInstaller Assert.AreEqual(0, dotNetInstallerExeUtils.Run(args.output, "/ExtractCab")); // this should have created a directory called SupportFiles in the current directory string supportFilesPath = Path.Combine(Path.GetDirectoryName(args.output), "SupportFiles"); Console.WriteLine("Checking {0}", supportFilesPath); Assert.IsTrue(Directory.Exists(supportFilesPath), string.Format("Missing {0}", supportFilesPath)); Assert.IsTrue(Directory.Exists(supportFilesPath + @"\component0")); Assert.IsTrue(File.Exists(supportFilesPath + @"\component0\file.xml")); Assert.IsTrue(Directory.Exists(supportFilesPath + @"\component1")); Assert.IsTrue(File.Exists(supportFilesPath + @"\component1\file.xml")); File.Delete(args.config); File.Delete(args.output); Directory.Delete(supportFilesPath, true); }
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 TestAutoClosesBeforeInstallWhenComponentIsAlreadyInstalled() { Console.WriteLine("TestAutoClosesBeforeInstallWhenComponentIsAlreadyInstalled"); // configuration with a component that is already installed and so dni will auto close // marker that makes installed check succeed before installation string markerFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); File.Create(markerFilename).Close(); ConfigFile configFile = new ConfigFile(); SetupConfiguration setupConfiguration = new SetupConfiguration(); setupConfiguration.auto_start = true; setupConfiguration.auto_close_if_installed = true; setupConfiguration.installation_completed = null; setupConfiguration.installation_none = null; setupConfiguration.supports_uninstall = false; // prevent switching to uninstall 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 are already installed Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options, TimeSpan.FromSeconds(3))); File.Delete(configFilename); File.Delete(markerFilename); }
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 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); }
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 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); }
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)); }
public void TestConfigNoLangID() { 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.Children.Add(cmd); string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); Console.WriteLine("Writing '{0}'", configFilename); configFile.SaveAs(configFilename); Assert.AreEqual(CultureInfo.CurrentUICulture.LCID, dotNetInstallerExeUtils.Run(configFilename)); File.Delete(configFilename); }
public void TestAutoStartCmdLine() { Console.WriteLine("TestAutoStartCmdLine"); ConfigFile configFile = new ConfigFile(); // setup configuration SetupConfiguration setupConfiguration = new SetupConfiguration(); setupConfiguration.auto_start = false; 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; options.autostart = true; Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options)); Assert.IsTrue(File.Exists(markerFilename)); File.Delete(configFilename); File.Delete(markerFilename); }