private string GetFormatedValue(Cabwiz.RegistryValueTypes type, string value) { if (value == null) { throw new ArgumentNullException("value"); } switch (type) { case Cabwiz.RegistryValueTypes.SZ: case Cabwiz.RegistryValueTypes.MULTI_SZ: return value; case Cabwiz.RegistryValueTypes.DWORD: { int nValue; var invariant = System.Globalization.CultureInfo.InvariantCulture; var cultures = new System.IFormatProvider[] { System.Globalization.CultureInfo.CurrentUICulture, invariant }; foreach (var culture in cultures) { if (int.TryParse(value, System.Globalization.NumberStyles.Integer, culture, out nValue)) { return nValue.ToString(invariant); } } // If we have reached this point, no parse was successful. Whine a bit. throw new FormatException("The value could not a well-formatted 32-bit integer."); } case Cabwiz.RegistryValueTypes.BINARY: { throw new NotSupportedException("BINARY data types are not yet supported by the visual editor."); } default: { throw new ArgumentOutOfRangeException("type"); } } }
/// <summary> /// Builds the project according to the current profile. /// </summary> /// <param name="cabwiz">The cabwiz application reference</param> /// <param name="feedback">The build context.</param> /// <returns>A value indicating whether the build was successful.</returns> public bool Build(Cabwiz.CabwizApplication cabwiz, IBuildFeedback feedback) { var project = this.Profile.ProjectInfo; var profile = this.Profile; if (cabwiz == null) { throw new ArgumentNullException("cabwiz", "Missing reference to a CabwizApplication object."); } var output = project.GetOutput(profile); // Create the .INF file for Cabwiz to process. var inf = output.CreateCabwizInf(profile); // Set the output directory cabwiz.DestinationDirectory = project.GetOutputDirectory(profile); // add some feedback feedback.WriteLine(" > {0}", cabwiz.PreviewCommandLine(inf)); int exitCode = cabwiz.Run(inf); if (exitCode != 0) { feedback.WriteLine(" {0} returned {1}", System.IO.Path.GetFileName(cabwiz.FileName), exitCode); return false; } else { return true; } }
/// <summary> /// Add a file to a information file, using the specified build profile. /// </summary> /// <param name="inf">The information file to add the directory to.</param> /// <param name="profile">The build profile used.</param> /// <param name="file">The file to add.</param> /// <remarks> /// <para> /// The file will not be added to the information file if /// 1. <paramref name="profile"/> is null, and <see cref="OutputFileInfo.SourceFile"/> /// is excluded by the project's global exclude list or it's current selected build profile. /// 2. or, <paramref name="profile"/> is not null and <see cref="OutputFileInfo.SourceFile"/> /// is excluded by <paramref name="profile"/>. /// </para> /// </remarks> private void AddToCabwiz(Cabwiz.InformationFile inf, BuildProfile profile, OutputFileInfo file) { if (!this.ProjectInfo.IsExcluded(file.SourceFile, profile)) { var sourceFile = file.SourceFile; if (file.IncludeRule != null) { if (file.IncludeRule.XmlReplacementRules.Count > 0) { var tempFile = this.GetObjFileName(file, profile); var rewriter = new XmlFileRewriter(); foreach (var replacement in file.IncludeRule.XmlReplacementRules) { rewriter.AddTextPath(replacement.Tag, this.ProjectInfo.ParseVariables(profile, replacement.Value)); } rewriter.Rewrite(sourceFile, tempFile); sourceFile = tempFile; } else if (!string.IsNullOrWhiteSpace(file.IncludeRule.FileName)) { var tempFile = this.GetObjFileName(file, profile); System.IO.File.Copy(file.SourceFile, tempFile, true); sourceFile = tempFile; } if (!string.IsNullOrEmpty(file.IncludeRule.StartMenuShortcut)) { inf.AddStartMenuShortcutToFile( file.Name, System.IO.Path.GetFileName(file.IncludeRule.StartMenuShortcut), System.IO.Path.GetDirectoryName(file.IncludeRule.StartMenuShortcut)); } } inf.AddFile(sourceFile, file.Directory.FullName, file.Name); } }
/// <summary> /// Add a directory to a information file, using the specified build profile. /// </summary> /// <param name="inf">The information file to add the directory to.</param> /// <param name="profile">The build profile used.</param> /// <param name="directoryInfo">The directory to add.</param> /// <remarks> /// <para> /// See <see cref="AddToCabwiz(Cabwiz.InformationFile inf, BuildProfile profile, FileInfo file)"/> /// for information about what files are excluded. /// </para> /// </remarks> private void AddToCabwiz(Cabwiz.InformationFile inf, BuildProfile profile, OutputDirectoryInfo directoryInfo) { foreach (var subDirectory in directoryInfo.SubDirectories) { this.AddToCabwiz(inf, profile, subDirectory); } foreach (var file in directoryInfo.Files) { this.AddToCabwiz(inf, profile, file); } }
private void AddToCabwiz(Cabwiz.AddRegSection addRegSection, RegistryKey registryKey) { foreach (var registryValue in registryKey.Values) { addRegSection.RegistryKeys.Add(new Cabwiz.AddRegItem(registryKey.Name) { ValueName = registryValue.Name, Type = registryValue.Type, Value = registryValue.Value }); } }
private void AddToCabwiz(Cabwiz.InformationFile inf, BuildProfile profile, RegistryKeyCollection registryKeys) { if (inf == null) { throw new ArgumentNullException("inf"); } if (registryKeys != null) { foreach (var registryKey in registryKeys) { this.AddToCabwiz(inf.AddReg, registryKey); } } }