本文整理汇总了C#中InstallerLib.ConfigFile类的典型用法代码示例。如果您正苦于以下问题:C# ConfigFile类的具体用法?C# ConfigFile怎么用?C# ConfigFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigFile类属于InstallerLib命名空间,在下文中一共展示了ConfigFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestLoadMSLU
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);
}
示例2: TestAutoStart
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);
}
示例3: TestAllArgCmd
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);
}
示例4: TestDefaultSelectionInstall
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);
}
示例5: TestGetResourcesNoFile
public void TestGetResourcesNoFile()
{
string supportdir = @"C:\SupportFiles\SupportFile";
ConfigFile configFile = new ConfigFile();
ResourceFileCollection resources = configFile.GetResources(supportdir);
Assert.AreEqual(0, resources.Count);
}
示例6: Main
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;
}
示例7: TestLoadSaveSamples
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);
}
}
示例8: TestComponentWithoutCheck
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);
}
示例9: TestLogConfigSpecified
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);
}
示例10: TestConfigReadWrite
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);
}
示例11: TestDisplayCab
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);
}
示例12: TestLogAcceptsPathVariables
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);
}
示例13: TestRebootExitCode
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();
}
示例14: TestFailingComponent
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));
}
示例15: HideComponentIfInstalled_WithComponentAlreadyInstalledDuringInstallSequence_HidesComponent
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);
}
}
}