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 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 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 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 TestLogCommandLineOverwritesConfigFile()
        {
            Console.WriteLine("TestLogCommandLineOverwritesConfigFile");

            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 = true;
            options.logfile = dotNetInstallerExeUtils.RunOptions.DefaultLogFile;
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options));
            File.Delete(configFilename);
            Assert.IsTrue(File.Exists(dotNetInstallerExeUtils.RunOptions.DefaultLogFile));
            Assert.IsFalse(File.Exists(configFile.log_file));
            File.Delete(configFile.log_file);
        }
        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 TestInvalidCommandLineArgument()
 {
     dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions();
     options.args = "/qb name=value"; // name=value doesn't follow a parameter
     options.log = false;
     options.quiet = false;
     Assert.AreEqual(-1, dotNetInstallerExeUtils.Run(options));
 }
 public void TestInvalidCommandLineParameter()
 {
     dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions();
     options.args = "/qb /qn"; // qn is an invalid parameter
     options.log = false;
     options.quiet = false;
     Assert.AreEqual(-1, dotNetInstallerExeUtils.Run(options));
 }
 public void TestHelp()
 {
     dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions();
     options.args = "/qb /?";
     options.log = false;
     options.quiet = false;
     Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options));
 }
        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 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 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 TestDisplayConfigWebConfiguration()
 {
     // config file with a web configuration (that will not be downloaded)
     ConfigFile configFile = new ConfigFile();
     string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
     WebConfiguration webConfiguration = new WebConfiguration();
     DownloadDialog downloadDialog = new DownloadDialog();
     downloadDialog.Children.Add(new Download());
     webConfiguration.Children.Add(downloadDialog);
     configFile.Children.Add(webConfiguration);
     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 TestSupportsUninstall()
        {
            Console.WriteLine("TestSupportsUninstall");

            // a configuration with no components
            ConfigFile configFile = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();
            configFile.Children.Add(setupConfiguration);
            setupConfiguration.supports_install = false;
            setupConfiguration.supports_uninstall = 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.AreNotEqual(0, dotNetInstallerExeUtils.Run(configFilename));
            // uninstall is not supported
            dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(configFilename);
            options.uninstall = true;
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options));
            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 TestSilentMode()
        {
            Console.WriteLine("TestSilentMode");

            InstallUILevel[] testUILevels = { InstallUILevel.basic, InstallUILevel.silent };
            foreach (InstallUILevel uilevel in testUILevels)
            {
                // a configuration with no components
                ConfigFile configFile = new ConfigFile();
                SetupConfiguration setupConfiguration = new SetupConfiguration();
                setupConfiguration.installation_none = "this message should never appear in silent mode and disappear in basic";
                configFile.Children.Add(setupConfiguration);
                // silent install, no dialog messages
                configFile.ui_level = uilevel;
                // save config file
                string configFilename = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
                Console.WriteLine("Writing '{0}'", configFilename);
                configFile.SaveAs(configFilename);
                // execute dotNetInstaller
                dotNetInstallerExeUtils.RunOptions options = new dotNetInstallerExeUtils.RunOptions(configFilename);
                Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options));
                File.Delete(configFilename);
            }
        }
        public void TestAutoClosesAfterInstallWhenComponentInstallSucceeds()
        {
            Console.WriteLine("TestAutoClosesAfterInstallWhenComponentInstallSucceeds");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            File.Delete(configFilename);
            File.Delete(markerFilename1);
            File.Delete(markerFilename2);
        }
        public void 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 TestNoLogging()
        {
            Console.WriteLine("TestNoLogging");

            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.log = false;
            options.logfile = string.Empty;
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(options));
            File.Delete(configFilename);
            Assert.IsFalse(File.Exists(dotNetInstallerExeUtils.RunOptions.DefaultLogFile));
        }
        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 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 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 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 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 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 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 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 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 TestUninstallMspSilentMode()
        {
            Console.WriteLine("TestUninstallMspSilentMode");

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