/// <summary> /// Copies or deletes the files. /// </summary> private static void InstallFiles(InstallationDataXml dataxml, RegistrationStage stage, Action <string> LogMessage, Func <SourceRootXml, DirectoryInfo> ResolveSourceDirRoot, Func <TargetRootXml, DirectoryInfo> ResolveTargetDirRoot) { dataxml.AssertValid(); foreach (FolderXml folderxml in dataxml.Files) { var diSource = new DirectoryInfo(Path.Combine(ResolveSourceDirRoot(folderxml.SourceRoot).FullName, folderxml.SourceDir)); var diTarget = new DirectoryInfo(Path.Combine(ResolveTargetDirRoot(folderxml.TargetRoot).FullName, folderxml.TargetDir)); diTarget.Create(); foreach (FileXml filexml in folderxml.Files) { FileInfo[] files = diSource.GetFiles(filexml.SourceName); if (files.Length == 0) { throw new InvalidOperationException(string.Format("There are no files matching the “{0}” mask in the source folder “{1}”.", filexml.SourceName, diSource.FullName)); } if ((files.Length > 1) && (filexml.TargetName.Length > 0)) { throw new InvalidOperationException(string.Format("There are {2} files matching the “{0}” mask in the source folder “{1}”, in which case it's illegal to specify a target name for the file.", filexml.SourceName, diSource.FullName, files.Length)); } foreach (FileInfo fiSource in files) { var fiTarget = new FileInfo(Path.Combine(diTarget.FullName, (filexml.TargetName.Length > 0 ? filexml.TargetName : fiSource.Name))); // Explicit target name, if present and if a single file; otherwise, use from source // Don't copy and, especially, don't delete the inplace files if (fiSource.FullName == fiTarget.FullName) { LogMessage(string.Format("Skipping “{0}” because source and target are the same file.", fiSource.FullName, fiTarget.FullName)); continue; } switch (stage) { case RegistrationStage.Register: LogMessage(string.Format("Installing “{0}” -> “{1}”.", fiSource.FullName, fiTarget.FullName)); fiSource.CopyTo(fiTarget.FullName, true); break; case RegistrationStage.Unregister: LogMessage(string.Format("Uninstalling “{0}”.", fiTarget.FullName)); fiTarget.Delete(); break; default: throw new InvalidOperationException(string.Format("Unexpected stage {0}.", stage)); } } } } }
public InstallationDataXml HarvestInstallationData() { var data = new InstallationDataXml(); // Run the attribute installers statically (each instance once) InvokeAttributeInstallersStatic(data); // Run the attribute installers per each attribute instance InvokeAttributeInstallersInstance(data); data.EnsureNotNull(); data.RemoveDuplicates(); data.AssertValid(); return(data); }
/// <summary> /// Actions under the resolver. /// </summary> protected override void ExecuteTaskResolved() { // Prepare the GUID cache myGuidCache = GuidCacheXml.Load(new FileInfo(Bag.GetString(AttributeName.GuidCacheFile)).OpenRead()); // Global structure of the WiX fragment file var wix = new Wix(); var wixFragmentComponents = new Fragment(); // Fragment with the payload wix.AddChild(wixFragmentComponents); var wixDirectoryRef = new DirectoryRef(); // Mount into the directories tree, defined externally wixFragmentComponents.AddChild(wixDirectoryRef); wixDirectoryRef.Id = Bag.GetString(AttributeName.WixDirectoryId); var wixFragmentGroup = new Fragment(); // Fragment with the component-group that collects the components wix.AddChild(wixFragmentGroup); var wixComponentGroup = new ComponentGroup(); // ComponentGroup that collects the components wixFragmentGroup.AddChild(wixComponentGroup); wixComponentGroup.Id = Bag.GetString(AttributeName.WixComponentGroupId); // Get the dump from the product InstallationDataXml dataxml = CreateInstaller().HarvestInstallationData(); IDictionary <string, string> macros = GetMacros(); // Nullref guards dataxml.AssertValid(); // Convert into WiX int nProducedFiles = ConvertFiles(wixDirectoryRef, wixComponentGroup, dataxml, macros); int nProducedKeys = ConvertRegistryKeys(wixDirectoryRef, wixComponentGroup, dataxml, macros); int nProducedValues = ConvertRegistryValues(wixDirectoryRef, wixComponentGroup, dataxml, macros); // Save to the output file using (var xw = new XmlTextWriter(new FileStream(Bag.GetString(AttributeName.OutputFile), FileMode.Create, FileAccess.Write, FileShare.Read), Encoding.UTF8)) { xw.Formatting = Formatting.Indented; wix.OutputXml(xw); } // Report (also to see the target in the build logs) Log.LogMessage(MessageImportance.Normal, "Generated {0} files, {1} Registry keys, and {2} Registry values.", nProducedFiles, nProducedKeys, nProducedValues); }