public void TestLoadMSLU() { Console.WriteLine("TestLoadUnicows"); if (File.Exists(dotNetInstallerExeUtils.RunOptions.DefaultLogFile)) File.Delete(dotNetInstallerExeUtils.RunOptions.DefaultLogFile); ConfigFile configFile = new ConfigFile(); SetupConfiguration setupConfiguration = new SetupConfiguration(); configFile.Children.Add(setupConfiguration); 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.loadMSLU = true; Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options)); File.Delete(configFilename); string[] logLines = File.ReadAllLines(dotNetInstallerExeUtils.RunOptions.DefaultLogFile); Console.WriteLine(logLines[0]); Assert.IsTrue(logLines[0].Contains("Loaded MSLU:")); string[] msluLine = logLines[0].Split(":".ToCharArray()); string msluAddress = msluLine[msluLine.Length - 1].Trim(); Console.WriteLine("MSLU loaded at: " + msluAddress); Assert.IsTrue(Int32.Parse(msluAddress, System.Globalization.NumberStyles.HexNumber) > 0); File.Delete(dotNetInstallerExeUtils.RunOptions.DefaultLogFile); }
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 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 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 TestGetResourcesNoFile() { string supportdir = @"C:\SupportFiles\SupportFile"; ConfigFile configFile = new ConfigFile(); ResourceFileCollection resources = configFile.GetResources(supportdir); Assert.AreEqual(0, resources.Count); }
public static int Main(string[] args) { int rc = 0; Console.WriteLine("InstallerConfig: dotNetInstaller configuration (re)writer ({0})", Assembly.GetExecutingAssembly().GetName().Version); Console.WriteLine(); InstallerConfigArguments i_args = new InstallerConfigArguments(); if (Parser.ParseArgumentsWithUsage(args, i_args)) { try { ConfigFile configFile = new ConfigFile(); configFile.Load(i_args.configfile); configFile.SaveAs(string.IsNullOrEmpty(i_args.outputfile) ? i_args.configfile : i_args.outputfile); } catch (Exception ex) { Console.Error.WriteLine("ERROR: {0}", ex.Message); #if DEBUG Console.Error.WriteLine(ex.StackTrace); #endif rc = -2; } } else { rc = -1; } return rc; }
public void TestLoadSaveSamples() { // \todo: don't use an embedded stream, this is a chicken/egg problem with rewriting sample xmls when configuration changes // make sure that every sample configuration loads and saves string[] manifestResourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames(); foreach (string manifestResourceName in manifestResourceNames) { if (! manifestResourceName.EndsWith(".Configuration.xml")) continue; // fetch the configuration from the resource Console.WriteLine(manifestResourceName); Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName); StreamReader r = new StreamReader(s); XmlDocument configXml = new XmlDocument(); configXml.LoadXml(r.ReadToEnd()); // load as a configuration ConfigFile configFile = new ConfigFile(); configFile.LoadXml(configXml); // compare trivial properties Assert.AreEqual("1.0.0.0", configFile.productversion, configFile.productversion); Assert.AreEqual(InstallUILevel.full, configFile.ui_level); // compare contents Assert.AreEqual(configFile.GetXml(null).OuterXml, configXml.OuterXml); } }
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 TestLogConfigSpecified() { Console.WriteLine("TestLogConfigSpecified"); if (File.Exists(dotNetInstallerExeUtils.RunOptions.DefaultLogFile)) File.Delete(dotNetInstallerExeUtils.RunOptions.DefaultLogFile); ConfigFile configFile = new ConfigFile(); configFile.log_enabled = true; configFile.log_file = Path.Combine(Path.GetTempPath(), "TestLogConfigSpecified.log"); if (File.Exists(configFile.log_file)) File.Delete(configFile.log_file); SetupConfiguration setupConfiguration = new SetupConfiguration(); configFile.Children.Add(setupConfiguration); 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.log = false; options.logfile = string.Empty; Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options)); File.Delete(configFilename); Assert.IsFalse(File.Exists(dotNetInstallerExeUtils.RunOptions.DefaultLogFile)); Assert.IsTrue(File.Exists(configFile.log_file)); File.Delete(configFile.log_file); }
public void TestConfigReadWrite() { // generate a configuration with as many changed values as possible, write/read and compare // ensures that all fields are property read and written to/from configuration files string configFilenameOriginal = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); string configFilenameLoaded = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); // original file ConfigFile configFileOriginal = new ConfigFile(); GenerateChildren(configFileOriginal); Console.WriteLine("Writing '{0}'", configFilenameOriginal); configFileOriginal.SaveAs(configFilenameOriginal); // loaded file ConfigFile configFileLoaded = new ConfigFile(); configFileLoaded.Load(configFilenameOriginal); Console.WriteLine("Writing '{0}'", configFilenameLoaded); configFileLoaded.SaveAs(configFilenameLoaded); // compare XmlDocument originalXml = new XmlDocument(); originalXml.Load(configFilenameOriginal); XmlDocument loadedXml = new XmlDocument(); loadedXml.Load(configFilenameLoaded); // compare contents Assert.AreEqual(originalXml.OuterXml, loadedXml.OuterXml); // delete files on success, otherwise keep for diff File.Delete(configFilenameOriginal); File.Delete(configFilenameLoaded); }
public void TestDisplayCab() { Console.WriteLine("TestDisplayCab"); // create a self-extracting bootstrapper ConfigFile configFile = new ConfigFile(); SetupConfiguration setupConfiguration = new SetupConfiguration(); configFile.Children.Add(setupConfiguration); InstallerLinkerArguments args = new InstallerLinkerArguments(); args.config = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); Console.WriteLine("Writing '{0}'", args.config); configFile.SaveAs(args.config); 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 Assert.AreEqual(0, dotNetInstallerExeUtils.Run(args.output, "/DisplayCab /qb")); File.Delete(args.config); File.Delete(args.output); }
public void TestLogAcceptsPathVariables() { Console.WriteLine("TestLogAcceptsPathVariables"); string resolved_logfile = Path.Combine(Path.GetTempPath(), "TestLogAcceptsPathVariables.log"); if (File.Exists(dotNetInstallerExeUtils.RunOptions.DefaultLogFile)) File.Delete(dotNetInstallerExeUtils.RunOptions.DefaultLogFile); if (File.Exists(resolved_logfile)) File.Delete(resolved_logfile); ConfigFile configFile = new ConfigFile(); configFile.log_enabled = true; configFile.log_file = @"#TEMPPATH\TestLogAcceptsPathVariables.log"; SetupConfiguration setupConfiguration = new SetupConfiguration(); configFile.Children.Add(setupConfiguration); 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.log = false; options.logfile = string.Empty; Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options)); File.Delete(configFilename); Assert.IsTrue(File.Exists(resolved_logfile), string.Format("Missing {0}", resolved_logfile)); Assert.IsFalse(File.Exists(dotNetInstallerExeUtils.RunOptions.DefaultLogFile)); File.Delete(resolved_logfile); }
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 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 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 TestRunFileConfiguration() { ConfigFile configFile = new ConfigFile(); SetupConfiguration setupConfiguration = new SetupConfiguration(); configFile.Children.Add(setupConfiguration); string configFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); Console.WriteLine("Writing '{0}'", configFileName); configFile.SaveAs(configFileName); try { ProcessStartInfo pi = new ProcessStartInfo(InstallerEditorExeUtils.Executable, "\"" + configFileName + "\""); using (Application installerEditor = Application.Launch(pi)) { string title = string.Format("Installer Editor - {0}", configFileName); Window mainWindow = installerEditor.GetWindow(title, InitializeOption.NoCache); Tree configurationTree = UIAutomation.Find<Tree>(mainWindow, "configurationTree"); Assert.AreEqual("Config File", configurationTree.SelectedNode.Name); StatusStrip statusStrip = UIAutomation.Find<StatusStrip>(mainWindow, "statusStrip"); WinFormTextBox statusLabel = (WinFormTextBox)statusStrip.Items[0]; Assert.AreEqual(string.Format("Loaded {0}", configFileName), statusLabel.Text); } } finally { File.Delete(configFileName); } }
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 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 = ""; cmd1.failed_exec_command_continue = ""; cmd1.failed_exec_command_continue = ""; cmd2.failed_exec_command_continue = ""; // 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 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 TestNoComponentsSuccess() { Console.WriteLine("TestNoComponentsSuccess"); // a configuration with no components ConfigFile configFile = new ConfigFile(); SetupConfiguration setupConfiguration = new SetupConfiguration(); configFile.Children.Add(setupConfiguration); // 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 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 TestControlLicenseResources() { InstallerLinkerArguments args = new InstallerLinkerArguments(); string licenseFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".txt"); 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); ControlLicense license = new ControlLicense(); license.LicenseFile = licenseFile; Console.WriteLine("Writing '{0}'", license.LicenseFile); File.WriteAllText(license.LicenseFile, "Lorem ipsum"); setupConfiguration.Children.Add(license); 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; 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_LICENSE", custom[2].Name.ToString()); } } finally { if (File.Exists(licenseFile)) File.Delete(licenseFile); if (File.Exists(args.config)) File.Delete(args.config); if (File.Exists(args.output)) File.Delete(args.output); } }
public void TestDisplayConfigSetupConfiguration() { // config file ConfigFile configFile = new ConfigFile(); string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); SetupConfiguration setupConfiguration = new SetupConfiguration(); configFile.Children.Add(setupConfiguration); Console.WriteLine("Writing '{0}'", configFilename); configFile.SaveAs(configFilename); // execute dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(configFilename); options.args = "/qb /DisplayConfig"; options.log = false; options.quiet = false; Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options)); // cleanup File.Delete(configFilename); }
public void TestInvalidVersionContinues() { Console.WriteLine("TestInvalidVersionContinues"); // a configuration with a mismatched version ConfigFile configFile = new ConfigFile(); SetupConfiguration setupConfiguration = new SetupConfiguration(); configFile.Children.Add(setupConfiguration); // save config file string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); Console.WriteLine("Writing '{0}'", configFilename); configFile.SaveAs(configFilename); XmlDocument configXml = new XmlDocument(); configXml.Load(configFilename); configXml.SelectSingleNode("/configurations/schema").Attributes["version"].Value = "bogus"; configXml.Save(configFilename); // execute dotNetInstaller Assert.AreEqual(0, dotNetInstallerExeUtils.Run(configFilename)); File.Delete(configFilename); }
public void TestCabPathAutoDeleteTrue() { Console.WriteLine("TestCabPathAutoDeleteTrue"); ConfigFile configFile = new ConfigFile(); SetupConfiguration setupConfiguration = new SetupConfiguration(); configFile.Children.Add(setupConfiguration); setupConfiguration.cab_path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); setupConfiguration.cab_path_autodelete = true; Console.WriteLine("Creating '{0}'", setupConfiguration.cab_path); Directory.CreateDirectory(setupConfiguration.cab_path); File.WriteAllText(Path.Combine(setupConfiguration.cab_path, Guid.NewGuid().ToString()), Guid.NewGuid().ToString()); 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(Directory.Exists(setupConfiguration.cab_path)); }
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 TestDontWaitForCompleteCommand() { Console.WriteLine("TestDontWaitForCompleteCommand"); ConfigFile configFile = new ConfigFile(); string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml"); SetupConfiguration setupConfiguration = new SetupConfiguration(); setupConfiguration.complete_command = TestTimerExeUtils.Executable; setupConfiguration.wait_for_complete_command = false; configFile.Children.Add(setupConfiguration); // save config file Console.WriteLine("Writing '{0}'", configFilename); configFile.SaveAs(configFilename); // execute dotNetInstaller DateTime ts = DateTime.UtcNow; Assert.AreEqual(0, dotNetInstallerExeUtils.Run(configFilename)); // test timer lives for 2 seconds before it closes Assert.IsTrue(DateTime.UtcNow.Subtract(ts).TotalSeconds < 2); File.Delete(configFilename); }
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); }