/// /// Copyright © 2003-2008 JetBrains s.r.o. /// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder). /// using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using JetBrains.Build.InstallationData; using JetBrains.Build.Omea.Infra; using JetBrains.Build.Omea.Resolved.Infra; using JetBrains.Build.Omea.Util; using JetBrains.Omea.Base.Install; using Microsoft.Build.Framework; namespace JetBrains.Build.Omea.Resolved.Tasks { /// /// Base for the registry-data installation and uninstallation tasks. /// public class LocalInstallDataResolved : TaskResolved { #region Operations /// /// Root -> file system path. /// public static string ResolveSourceDirRoot(SourceRootXml root, Bag bag) { switch(root) { case SourceRootXml.ProductBinariesDir: return bag.GetString(AttributeName.ProductBinariesDir); case SourceRootXml.ProductHomeDir: return bag.GetString(AttributeName.ProductHomeDir); default: throw new InvalidOperationException(string.Format("Unsupported installation data file source root “{0}”.", root)); } } #endregion #region Implementation /// /// Root -> file system path. /// private static string ResolveTargetDirRoot(TargetRootXml root, Bag bag) { switch(root) { case TargetRootXml.InstallDir: return bag.GetString(AttributeName.ProductBinariesDir); default: throw new InvalidOperationException(string.Format("Unsupported installation data file target root “{0}”.", root)); } } /// /// Defines the macros that could be used in the Registry dumps. /// will subst them. /// protected IDictionary GetMacros() { var macros = new Dictionary(); macros.Add(MacroNameXml.SystemDir.ToString(), Environment.GetFolderPath(Environment.SpecialFolder.System)); macros.Add(MacroNameXml.ProductBinariesDir.ToString(), Path.GetFullPath(Bag.GetString(AttributeName.ProductBinariesDir))); macros.Add(MacroNameXml.DateTime.ToString(), DateTime.Now.ToString("s")); return macros; } #endregion #region Overrides /// /// Actions under the resolver. /// protected override void ExecuteTaskResolved() { // Get the stage var stage = (RegistrationStage)TypeDescriptor.GetConverter(typeof(RegistrationStage)).ConvertFromString(Bag.GetString(AttributeName.Stage)); // Collect the installation data and install it LocalInstaller.Install(CreateInstaller().HarvestInstallationData(), stage, GetMacros(), root => new DirectoryInfo(ResolveSourceDirRoot(root, Bag)), root => new DirectoryInfo(ResolveTargetDirRoot(root, Bag)), text => { Log.LogMessage(MessageImportance.Low, text); }); } #endregion } }