private XmlNode GetResourcesNodeForSettings(BuildSettings settings, BuildResults results, ref int codepage)
        {
            CultureInfo ci = Util.GetCultureInfoFromString(settings.Culture);
            CultureInfo fallbackCI = Util.GetCultureInfoFromString(settings.FallbackCulture);
            XmlNode cultureNode = null;


            if (ci != null)
            {
                // Work through the progression of parent cultures (up until but excluding the invariant culture) -> fallback culture -> parent fallback culture -> default culture -> parent default culture -> any available culture
                cultureNode = GetResourcesNodeForSettings_Helper(ci, ci, results, ref codepage, false);
                if (cultureNode != null) return cultureNode;
                CultureInfo parentCulture = ci.Parent;

                // Keep going up the chain of parents, stopping at the invariant culture
                while (parentCulture != null && parentCulture != CultureInfo.InvariantCulture)
                {
                    cultureNode = GetResourcesNodeForSettings_Helper(ci, parentCulture, results, ref codepage, false);
                    if (cultureNode != null) return cultureNode;

                    parentCulture = parentCulture.Parent;
                }
            }

            if (fallbackCI != null)
            {
                cultureNode = GetResourcesNodeForSettings_Helper(ci, fallbackCI, results, ref codepage, true);
                if (cultureNode != null) return cultureNode;

                if (!fallbackCI.IsNeutralCulture)
                {
                    cultureNode = GetResourcesNodeForSettings_Helper(ci, fallbackCI.Parent, results, ref codepage, true);
                    if (cultureNode != null) return cultureNode;
                }
            }

            cultureNode = GetResourcesNodeForSettings_Helper(ci, Util.DefaultCultureInfo, results, ref codepage, true);
            if (cultureNode != null) return cultureNode;

            if (!Util.DefaultCultureInfo.IsNeutralCulture)
            {
                cultureNode = GetResourcesNodeForSettings_Helper(ci, Util.DefaultCultureInfo.Parent, results, ref codepage, true);
                if (cultureNode != null) return cultureNode;
            }

            IEnumerator keys = _cultures.Keys.GetEnumerator();
            keys.MoveNext();
            string altCulture = (string)keys.Current;
            if (ci != null && results != null)
                results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.UsingResourcesCulture", ci.Name, altCulture));
            GetCodePage(altCulture, ref codepage);
            return (XmlNode)_cultures[altCulture.ToLowerInvariant()];
        }
 private Package GetPackageForSettings(BuildSettings settings, ProductBuilder builder, BuildResults results)
 {
     CultureInfo cultureInfoFromString = Util.GetCultureInfoFromString(settings.Culture);
     CultureInfo altCulture = Util.GetCultureInfoFromString(settings.FallbackCulture);
     Package package = null;
     if (builder.Product.Packages.Count == 0)
     {
         if (results != null)
         {
             results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.ProductCultureNotFound", new object[] { builder.Name }));
         }
         return null;
     }
     if (cultureInfoFromString != null)
     {
         package = builder.Product.Packages.Package(cultureInfoFromString.Name);
         if (package != null)
         {
             return package;
         }
         for (CultureInfo info3 = cultureInfoFromString.Parent; (info3 != null) && (info3 != CultureInfo.InvariantCulture); info3 = info3.Parent)
         {
             package = this.GetPackageForSettings_Helper(cultureInfoFromString, info3, builder, results, false);
             if (package != null)
             {
                 return package;
             }
         }
     }
     if (altCulture != null)
     {
         package = this.GetPackageForSettings_Helper(cultureInfoFromString, altCulture, builder, results, true);
         if (package != null)
         {
             return package;
         }
         if (!altCulture.IsNeutralCulture)
         {
             package = this.GetPackageForSettings_Helper(cultureInfoFromString, altCulture.Parent, builder, results, true);
             if (package != null)
             {
                 return package;
             }
         }
     }
     package = this.GetPackageForSettings_Helper(cultureInfoFromString, Util.DefaultCultureInfo, builder, results, true);
     if (package != null)
     {
         return package;
     }
     if (!Util.DefaultCultureInfo.IsNeutralCulture)
     {
         package = this.GetPackageForSettings_Helper(cultureInfoFromString, Util.DefaultCultureInfo.Parent, builder, results, true);
         if (package != null)
         {
             return package;
         }
     }
     if ((results != null) && (cultureInfoFromString != null))
     {
         results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.UsingProductCulture", new object[] { cultureInfoFromString.Name, builder.Name, builder.Product.Packages.Item(0).Culture }));
     }
     return builder.Product.Packages.Item(0);
 }
        private bool BuildResources(BuildSettings settings, ResourceUpdater resourceUpdater)
        {
            if (_cultures.Count == 0)
            {
                if (_results != null)
                    _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.NoResources"));
                return false;
            }

            int codePage = -1;
            XmlNode resourcesNode = GetResourcesNodeForSettings(settings, _results, ref codePage);
            XmlNode stringsNode = resourcesNode.SelectSingleNode("Strings");
            XmlNode fontsNode = resourcesNode.SelectSingleNode("Fonts");

            if (stringsNode == null)
            {
                if (_results != null)
                    _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.NoStringsForCulture", resourcesNode.Attributes.GetNamedItem("Culture").Value));
                return false;
            }

            XmlNodeList stringNodes = stringsNode.SelectNodes("String");

            foreach (XmlNode stringNode in stringNodes)
            {
                XmlAttribute resourceIdAttribute = (XmlAttribute)stringNode.Attributes.GetNamedItem("Name");

                if (resourceIdAttribute != null)
                {
                    resourceUpdater.AddStringResource(MESSAGE_TABLE, resourceIdAttribute.Value.ToUpper(CultureInfo.InvariantCulture), stringNode.InnerText);
                }
            }

            if (fontsNode != null)
            {
                foreach (XmlNode fontNode in fontsNode.SelectNodes("Font"))
                {
                    ConvertChildsNodeToAttributes(fontNode);
                }
                string fontsConfig = XmlToConfigurationFile(fontsNode);
                resourceUpdater.AddStringResource(RESOURCE_TABLE, "SETUPRES", fontsConfig);
                DumpXmlToFile(fontsNode, "fonts.cfg.xml");
                DumpStringToFile(fontsConfig, "fonts.cfg", false);
                if (codePage != -1)
                    resourceUpdater.AddStringResource(RESOURCE_TABLE, "CODEPAGE", codePage.ToString(CultureInfo.InvariantCulture));
            }
            return true;
        }
Example #4
0
		public BuildResults Build (BuildSettings settings)
		{
			throw new NotImplementedException ();
		}
        /// <summary>
        /// Generate the bootstrapper.
        /// </summary>
        /// <returns> Return true on success, false on failure.</returns>
        public override bool Execute()
        {
            if (_path == null)
            {
                _path = Util.GetDefaultPath(_visualStudioVersion);
            }

            BootstrapperBuilder bootstrapperBuilder = new BootstrapperBuilder();

            bootstrapperBuilder.Validate = this.Validate;
            bootstrapperBuilder.Path = this.Path;

            ProductCollection products = bootstrapperBuilder.Products;

            BuildSettings settings = new BuildSettings();

            settings.ApplicationFile = ApplicationFile;
            settings.ApplicationName = ApplicationName;
            settings.ApplicationRequiresElevation = ApplicationRequiresElevation;
            settings.ApplicationUrl = ApplicationUrl;
            settings.ComponentsLocation = ConvertStringToComponentsLocation(this.ComponentsLocation);
            settings.ComponentsUrl = ComponentsUrl;
            settings.CopyComponents = CopyComponents;
            settings.Culture = _culture;
            settings.FallbackCulture = _fallbackCulture;
            settings.OutputPath = this.OutputPath;
            settings.SupportUrl = this.SupportUrl;

            if (String.IsNullOrEmpty(settings.Culture) || settings.Culture == "*")
            {
                settings.Culture = settings.FallbackCulture;
            }

            if (this.BootstrapperItems != null)
            {
                // The bootstrapper items may not be in the correct order, because XMake saves 
                // items in alphabetical order.  So we will attempt to put items into the correct 
                // order, according to the Products order in the search.  To do this, we add all 
                // the items we are told to build into a hashtable, then go through our products 
                // in order, looking to see if the item is built.  If it is, remove the item from 
                // the hashtable.  All remaining items in the table can not be built, so errors 
                // will be issued.
                Hashtable items = new Hashtable(StringComparer.OrdinalIgnoreCase);

                foreach (ITaskItem bootstrapperItem in this.BootstrapperItems)
                {
                    string installAttribute = bootstrapperItem.GetMetadata("Install");
                    if (String.IsNullOrEmpty(installAttribute) || Shared.ConversionUtilities.ConvertStringToBool(installAttribute))
                    {
                        if (!items.Contains(bootstrapperItem.ItemSpec))
                        {
                            items.Add(bootstrapperItem.ItemSpec, bootstrapperItem);
                        }
                        else
                        {
                            Log.LogWarningWithCodeFromResources("GenerateBootstrapper.DuplicateItems", bootstrapperItem.ItemSpec);
                        }
                    }
                }

                foreach (Product product in products)
                {
                    if (items.Contains(product.ProductCode))
                    {
                        settings.ProductBuilders.Add(product.ProductBuilder);
                        items.Remove(product.ProductCode);
                    }
                }

                foreach (ITaskItem bootstrapperItem in items.Values)
                {
                    Log.LogWarningWithCodeFromResources("GenerateBootstrapper.ProductNotFound", bootstrapperItem.ItemSpec, bootstrapperBuilder.Path);
                }
            }

            BuildResults results = bootstrapperBuilder.Build(settings);
            BuildMessage[] messages = results.Messages;

            if (messages != null)
            {
                foreach (BuildMessage message in messages)
                {
                    if (message.Severity == BuildMessageSeverity.Error)
                        Log.LogError(null, message.HelpCode, message.HelpKeyword, null, 0, 0, 0, 0, message.Message);
                    else if (message.Severity == BuildMessageSeverity.Warning)
                        Log.LogWarning(null, message.HelpCode, message.HelpKeyword, null, 0, 0, 0, 0, message.Message);
                }
            }

            this.BootstrapperKeyFile = results.KeyFile;
            this.BootstrapperComponentFiles = results.ComponentFiles;

            return results.Succeeded;
        }
        private bool AddVerificationInformation(XmlNode packageFileNode, string fileSource, string fileName, ProductBuilder builder, BuildSettings settings, BuildResults results)
        {
            XmlAttribute hashAttribute = packageFileNode.Attributes[HASH_ATTRIBUTE];
            XmlAttribute publicKeyAttribute = packageFileNode.Attributes[PUBLICKEY_ATTRIBUTE];

            if (File.Exists(fileSource))
            {
                string publicKey = GetPublicKeyOfFile(fileSource);
                if (hashAttribute == null && publicKeyAttribute == null)
                {
                    // If neither the Hash nor PublicKey attributes were specified in the manifest, add it
                    if (publicKey != null)
                    {
                        AddAttribute(packageFileNode, PUBLICKEY_ATTRIBUTE, publicKey);
                    }
                    else
                    {
                        AddAttribute(packageFileNode, HASH_ATTRIBUTE, GetFileHash(fileSource));
                    }
                }
                if (publicKeyAttribute != null)
                {
                    // Always use the PublicKey of the file on disk
                    if (publicKey != null)
                        ReplaceAttribute(packageFileNode, PUBLICKEY_ATTRIBUTE, publicKey);
                    else
                    {
                        // File on disk is not signed.  Remove the public key info, and make sure the hash is written instead
                        packageFileNode.Attributes.RemoveNamedItem(PUBLICKEY_ATTRIBUTE);
                        if (hashAttribute == null)
                            AddAttribute(packageFileNode, HASH_ATTRIBUTE, GetFileHash(fileSource));
                    }

                    // If the public key in the file doesn't match the public key on disk, issue a build warning
                    if (publicKey == null || !publicKey.ToLowerInvariant().Equals(publicKeyAttribute.Value.ToLowerInvariant()))
                    {
                        if (results != null)
                            results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.DifferingPublicKeys", PUBLICKEY_ATTRIBUTE, builder.Name, fileSource));
                    }
                }
                if (hashAttribute != null)
                {
                    string fileHash = GetFileHash(fileSource);

                    // Always use the Hash of the file on disk
                    ReplaceAttribute(packageFileNode, HASH_ATTRIBUTE, fileHash);

                    // If the public key in the file doesn't match the public key on disk, issue a build warning
                    if (!fileHash.ToLowerInvariant().Equals(hashAttribute.Value.ToLowerInvariant()))
                    {
                        if (results != null)
                            results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.DifferingPublicKeys", "Hash", builder.Name, fileSource));
                    }
                }
            }
            else if (settings.ComponentsLocation == ComponentsLocation.HomeSite)
            {
                if (hashAttribute == null && publicKeyAttribute == null)
                {
                    if (results != null)
                    {
                        results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.MissingVerificationInformation", fileName, builder.Name));
                    }
                    return false;
                }
            }

            return true;
        }
        private bool CopySetupToOutputDirectory(BuildSettings settings, string strOutputExe)
        {
            string bootstrapperPath = BootstrapperPath;
            string setupSourceFile = System.IO.Path.Combine(bootstrapperPath, SETUP_BIN);

            if (!File.Exists(setupSourceFile))
            {
                _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.MissingSetupBin", SETUP_BIN, bootstrapperPath));
                return false;
            }

            try
            {
                EnsureFolderExists(settings.OutputPath);
                File.Copy(setupSourceFile, strOutputExe, true);
                ClearReadOnlyAttribute(strOutputExe);
            }
            catch (IOException ex)
            {
                _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyError", setupSourceFile, strOutputExe, ex.Message));
                return false;
            }
            catch (UnauthorizedAccessException ex)
            {
                _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyError", setupSourceFile, strOutputExe, ex.Message));
                return false;
            }
            catch (ArgumentException ex)
            {
                _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyError", setupSourceFile, strOutputExe, ex.Message));
                return false;
            }
            catch (NotSupportedException ex)
            {
                _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyError", setupSourceFile, strOutputExe, ex.Message));
                return false;
            }

            return true;
        }
 private bool BuildResources(BuildSettings settings, ResourceUpdater resourceUpdater)
 {
     if (this.cultures.Count == 0)
     {
         if (this.results != null)
         {
             this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.NoResources", new object[0]));
         }
         return false;
     }
     int codepage = -1;
     XmlNode node = this.GetResourcesNodeForSettings(settings, this.results, ref codepage);
     XmlNode node2 = node.SelectSingleNode("Strings");
     XmlNode input = node.SelectSingleNode("Fonts");
     if (node2 == null)
     {
         if (this.results != null)
         {
             this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.NoStringsForCulture", new object[] { node.Attributes.GetNamedItem("Culture").Value }));
         }
         return false;
     }
     foreach (XmlNode node4 in node2.SelectNodes("String"))
     {
         XmlAttribute namedItem = (XmlAttribute) node4.Attributes.GetNamedItem("Name");
         if (namedItem != null)
         {
             resourceUpdater.AddStringResource(0x2b, namedItem.Value.ToUpper(CultureInfo.InvariantCulture), node4.InnerText);
         }
     }
     if (input != null)
     {
         foreach (XmlNode node5 in input.SelectNodes("Font"))
         {
             this.ConvertChildsNodeToAttributes(node5);
         }
         string data = this.XmlToConfigurationFile(input);
         resourceUpdater.AddStringResource(0x2d, "SETUPRES", data);
         this.DumpXmlToFile(input, "fonts.cfg.xml");
         this.DumpStringToFile(data, "fonts.cfg", false);
         if (codepage != -1)
         {
             resourceUpdater.AddStringResource(0x2d, "CODEPAGE", codepage.ToString(CultureInfo.InvariantCulture));
         }
     }
     return true;
 }
 private void AddBuiltProducts(BuildSettings settings)
 {
     Dictionary<string, ProductBuilder> dictionary = new Dictionary<string, ProductBuilder>();
     Dictionary<string, Product> output = new Dictionary<string, Product>();
     if ((this.loopDependenciesWarnings != null) && (this.loopDependenciesWarnings.Messages != null))
     {
         foreach (BuildMessage message in this.loopDependenciesWarnings.Messages)
         {
             this.results.AddMessage(message);
         }
     }
     foreach (ProductBuilder builder in settings.ProductBuilders)
     {
         dictionary.Add(builder.Product.ProductCode.ToLowerInvariant(), builder);
         this.Merge(output, this.GetIncludedProducts(builder.Product));
         this.AddProduct(output, builder.Product);
     }
     foreach (ProductBuilder builder2 in settings.ProductBuilders)
     {
         foreach (Product product in this.GetIncludedProducts(builder2.Product).Values)
         {
             if (dictionary.ContainsKey(product.ProductCode.ToLowerInvariant()))
             {
                 this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.IncludedProductIncluded", new object[] { builder2.Name, product.Name }));
             }
         }
         foreach (List<Product> list in builder2.Product.Dependencies)
         {
             bool flag = false;
             foreach (Product product2 in list)
             {
                 if (output.ContainsKey(product2.ProductCode.ToLowerInvariant()))
                 {
                     flag = true;
                     break;
                 }
             }
             if (!flag)
             {
                 if (list.Count == 1)
                 {
                     this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.MissingDependency", new object[] { list[0].Name, builder2.Name }));
                 }
                 else
                 {
                     StringBuilder builder3 = new StringBuilder();
                     foreach (Product product3 in list)
                     {
                         builder3.Append(product3.Name);
                         builder3.Append(", ");
                     }
                     string str = builder3.ToString();
                     str = str.Substring(0, str.Length - 2);
                     this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.MissingDependencyMultiple", new object[] { str, builder2.Name }));
                 }
             }
         }
         foreach (ArrayList list2 in builder2.Product.MissingDependencies)
         {
             if (list2.Count == 1)
             {
                 this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.DependencyNotFound", new object[] { builder2.Name, list2[0] }));
             }
             else
             {
                 StringBuilder builder4 = new StringBuilder();
                 foreach (string str2 in list2)
                 {
                     builder4.Append(str2);
                     builder4.Append(", ");
                 }
                 string str3 = builder4.ToString();
                 str3 = str3.Substring(0, str3.Length - 2);
                 this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.MultipleDependeciesNotFound", new object[] { builder2.Name, str3 }));
             }
         }
     }
 }
 public BuildResults Build(BuildSettings settings)
 {
     this.results = new BuildResults();
     try
     {
         if ((settings.ApplicationFile == null) && ((settings.ProductBuilders == null) || (settings.ProductBuilders.Count == 0)))
         {
             this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.InvalidInput", new object[0]));
             return this.results;
         }
         if (string.IsNullOrEmpty(settings.OutputPath))
         {
             this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.NoOutputPath", new object[0]));
             return this.results;
         }
         if (!this.fInitialized)
         {
             this.Refresh();
         }
         if (string.IsNullOrEmpty(settings.Culture))
         {
             settings.Culture = this.MapLCIDToCultureName(settings.LCID);
         }
         if (string.IsNullOrEmpty(settings.FallbackCulture))
         {
             settings.FallbackCulture = this.MapLCIDToCultureName(settings.FallbackLCID);
         }
         this.AddBuiltProducts(settings);
         ArrayList filesCopied = new ArrayList();
         string strOutputExe = System.IO.Path.Combine(settings.OutputPath, "setup.exe");
         if (!this.CopySetupToOutputDirectory(settings, strOutputExe))
         {
             return this.results;
         }
         ResourceUpdater resourceUpdater = new ResourceUpdater();
         if (!this.BuildResources(settings, resourceUpdater))
         {
             return this.results;
         }
         this.AddStringResourceForUrl(resourceUpdater, "BASEURL", settings.ApplicationUrl, "ApplicationUrl");
         this.AddStringResourceForUrl(resourceUpdater, "COMPONENTSURL", settings.ComponentsUrl, "ComponentsUrl");
         this.AddStringResourceForUrl(resourceUpdater, "SUPPORTURL", settings.SupportUrl, "SupportUrl");
         if (settings.ComponentsLocation == ComponentsLocation.HomeSite)
         {
             resourceUpdater.AddStringResource(40, "HOMESITE", true.ToString());
         }
         XmlElement configElement = this.document.CreateElement("Configuration");
         XmlElement newChild = this.CreateApplicationElement(configElement, settings);
         if (newChild != null)
         {
             configElement.AppendChild(newChild);
         }
         Hashtable eulas = new Hashtable();
         if (!this.BuildPackages(settings, configElement, resourceUpdater, filesCopied, eulas))
         {
             return this.results;
         }
         this.DumpXmlToFile(configElement, "bootstrapper.cfg.xml");
         string data = this.XmlToConfigurationFile(configElement);
         resourceUpdater.AddStringResource(0x29, "SETUPCFG", data);
         this.DumpStringToFile(data, "bootstrapper.cfg", false);
         foreach (object obj2 in eulas.Values)
         {
             string str3;
             DictionaryEntry entry = (DictionaryEntry) obj2;
             FileInfo info = new FileInfo(entry.Value.ToString());
             using (FileStream stream = info.OpenRead())
             {
                 str3 = new StreamReader(stream).ReadToEnd();
             }
             resourceUpdater.AddStringResource(0x2c, entry.Key.ToString(), str3);
         }
         resourceUpdater.AddStringResource(0x2c, "COUNT", eulas.Count.ToString(CultureInfo.InvariantCulture));
         if (!resourceUpdater.UpdateResources(strOutputExe, this.results))
         {
             return this.results;
         }
         this.results.SetKeyFile(strOutputExe);
         string[] array = new string[filesCopied.Count];
         filesCopied.CopyTo(array);
         this.results.AddComponentFiles(array);
         this.results.BuildSucceeded();
     }
     catch (Exception exception)
     {
         this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.General", new object[] { exception.Message }));
     }
     return this.results;
 }
 private bool BuildPackages(BuildSettings settings, XmlElement configElement, ResourceUpdater resourceUpdater, ArrayList filesCopied, Hashtable eulas)
 {
     bool flag = true;
     foreach (ProductBuilder builder in settings.ProductBuilders)
     {
         if ((this.Validate && !builder.Product.ValidationPassed) && (this.results != null))
         {
             this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.ProductValidation", new object[] { builder.Name, builder.Product.ValidationResults.FilePath }));
             foreach (string str in builder.Product.ValidationResults.ValidationErrors)
             {
                 this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.ValidationError", new object[] { builder.Product.ValidationResults.FilePath, str }));
             }
             foreach (string str2 in builder.Product.ValidationResults.ValidationWarnings)
             {
                 this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.ValidationWarning", new object[] { builder.Product.ValidationResults.FilePath, str2 }));
             }
         }
         Package package = this.GetPackageForSettings(settings, builder, this.results);
         if (package != null)
         {
             if ((this.Validate && !package.ValidationPassed) && (this.results != null))
             {
                 this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.PackageValidation", new object[] { builder.Name, package.ValidationResults.FilePath }));
                 foreach (string str3 in package.ValidationResults.ValidationErrors)
                 {
                     this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.ValidationError", new object[] { package.ValidationResults.FilePath, str3 }));
                 }
                 foreach (string str4 in package.ValidationResults.ValidationWarnings)
                 {
                     this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.ValidationWarning", new object[] { package.ValidationResults.FilePath, str4 }));
                 }
             }
             XmlNode node = package.Node;
             XmlAttribute attribute = node.Attributes["LicenseAgreement"];
             XmlNodeList list = node.SelectNodes("bootstrapper:PackageFiles/bootstrapper:PackageFile", this.xmlNamespaceManager);
             XmlNode subNode = node.SelectSingleNode("bootstrapper:InstallChecks", this.xmlNamespaceManager);
             foreach (XmlNode node3 in list)
             {
                 XmlAttribute namedItem = (XmlAttribute) node3.Attributes.GetNamedItem("SourcePath");
                 XmlAttribute attribute3 = (XmlAttribute) node3.Attributes.GetNamedItem("TargetPath");
                 XmlAttribute attribute4 = (XmlAttribute) node3.Attributes.GetNamedItem("Name");
                 XmlAttribute attribute5 = (XmlAttribute) node3.Attributes.GetNamedItem("CopyOnBuild");
                 if (((namedItem != null) && (attribute != null)) && (!string.IsNullOrEmpty(attribute.Value) && (namedItem.Value == attribute.Value)))
                 {
                     node.SelectSingleNode("bootstrapper:PackageFiles", this.xmlNamespaceManager).RemoveChild(node3);
                 }
                 else
                 {
                     if (((namedItem != null) && (attribute3 != null)) && !this.AddVerificationInformation(node3, namedItem.Value, attribute4.Value, builder, settings, this.results))
                     {
                         flag = false;
                     }
                     if (((namedItem != null) && (attribute3 != null)) && ((attribute5 == null) || (string.Compare(attribute5.Value, "False", StringComparison.InvariantCulture) != 0)))
                     {
                         XmlNode node5 = null;
                         if ((subNode != null) && (attribute4 != null))
                         {
                             node5 = this.QueryForSubNode(subNode, "PackageFile", attribute4.Value);
                         }
                         if (node5 != null)
                         {
                             if (resourceUpdater != null)
                             {
                                 if (!File.Exists(namedItem.Value))
                                 {
                                     if (this.results != null)
                                     {
                                         this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.PackageResourceFileNotFound", new object[] { namedItem.Value, builder.Name }));
                                     }
                                     flag = false;
                                 }
                                 else
                                 {
                                     resourceUpdater.AddFileResource(namedItem.Value, attribute3.Value);
                                 }
                             }
                         }
                         else if ((settings.ComponentsLocation != ComponentsLocation.HomeSite) || !this.VerifyHomeSiteInformation(node3, builder, settings, this.results))
                         {
                             if (settings.CopyComponents)
                             {
                                 string path = System.IO.Path.Combine(settings.OutputPath, attribute3.Value);
                                 try
                                 {
                                     if (!File.Exists(namedItem.Value))
                                     {
                                         if (this.results != null)
                                         {
                                             this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.PackageFileNotFound", new object[] { attribute3.Value, builder.Name }));
                                         }
                                         flag = false;
                                         goto Label_06D6;
                                     }
                                     this.EnsureFolderExists(System.IO.Path.GetDirectoryName(path));
                                     File.Copy(namedItem.Value, path, true);
                                     this.ClearReadOnlyAttribute(path);
                                 }
                                 catch (UnauthorizedAccessException exception)
                                 {
                                     if (this.results != null)
                                     {
                                         this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyPackageError", new object[] { namedItem.Value, builder.Name, exception.Message }));
                                     }
                                     flag = false;
                                     goto Label_06D6;
                                 }
                                 catch (IOException exception2)
                                 {
                                     if (this.results != null)
                                     {
                                         this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyPackageError", new object[] { namedItem.Value, builder.Name, exception2.Message }));
                                     }
                                     flag = false;
                                     goto Label_06D6;
                                 }
                                 catch (ArgumentException exception3)
                                 {
                                     if (this.results != null)
                                     {
                                         this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyPackageError", new object[] { namedItem.Value, builder.Name, exception3.Message }));
                                     }
                                     flag = false;
                                     goto Label_06D6;
                                 }
                                 catch (NotSupportedException exception4)
                                 {
                                     if (this.results != null)
                                     {
                                         this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyPackageError", new object[] { namedItem.Value, builder.Name, exception4.Message }));
                                     }
                                     flag = false;
                                     goto Label_06D6;
                                 }
                                 filesCopied.Add(path);
                             }
                             else
                             {
                                 filesCopied.Add(namedItem.Value);
                             }
                             XmlAttribute attribute6 = node3.OwnerDocument.CreateAttribute("Size");
                             FileInfo info = new FileInfo(namedItem.Value);
                             attribute6.Value = info.Length.ToString(CultureInfo.InvariantCulture) ?? "";
                             this.MergeAttribute(node3, attribute6);
                         }
                     }
                 Label_06D6:;
                 }
             }
             if (((eulas != null) && (attribute != null)) && !string.IsNullOrEmpty(attribute.Value))
             {
                 if (File.Exists(attribute.Value))
                 {
                     string fileHash = this.GetFileHash(attribute.Value);
                     if (eulas.ContainsKey(fileHash))
                     {
                         DictionaryEntry entry2 = (DictionaryEntry) eulas[fileHash];
                         attribute.Value = entry2.Key.ToString();
                     }
                     else
                     {
                         string key = string.Format(CultureInfo.InvariantCulture, "EULA{0}", new object[] { eulas.Count });
                         DictionaryEntry entry = new DictionaryEntry(key, attribute.Value);
                         eulas[fileHash] = entry;
                         attribute.Value = key;
                     }
                 }
                 else
                 {
                     if (this.results != null)
                     {
                         this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.PackageResourceFileNotFound", new object[] { attribute.Value, builder.Name }));
                     }
                     flag = false;
                     continue;
                 }
             }
             if (configElement != null)
             {
                 configElement.AppendChild(configElement.OwnerDocument.ImportNode(node, true));
                 this.DumpXmlToFile(node, string.Format(CultureInfo.CurrentCulture, "{0}.{1}.xml", new object[] { package.Product.ProductCode, package.Culture }));
             }
         }
     }
     return flag;
 }
 private bool AddVerificationInformation(XmlNode packageFileNode, string fileSource, string fileName, ProductBuilder builder, BuildSettings settings, BuildResults results)
 {
     XmlAttribute attribute = packageFileNode.Attributes["Hash"];
     XmlAttribute attribute2 = packageFileNode.Attributes["PublicKey"];
     if (File.Exists(fileSource))
     {
         string publicKeyOfFile = this.GetPublicKeyOfFile(fileSource);
         if ((attribute == null) && (attribute2 == null))
         {
             if (publicKeyOfFile != null)
             {
                 this.AddAttribute(packageFileNode, "PublicKey", publicKeyOfFile);
             }
             else
             {
                 this.AddAttribute(packageFileNode, "Hash", this.GetFileHash(fileSource));
             }
         }
         if (attribute2 != null)
         {
             if (publicKeyOfFile != null)
             {
                 this.ReplaceAttribute(packageFileNode, "PublicKey", publicKeyOfFile);
             }
             else
             {
                 packageFileNode.Attributes.RemoveNamedItem("PublicKey");
                 if (attribute == null)
                 {
                     this.AddAttribute(packageFileNode, "Hash", this.GetFileHash(fileSource));
                 }
             }
             if (((publicKeyOfFile == null) || !publicKeyOfFile.ToLowerInvariant().Equals(attribute2.Value.ToLowerInvariant())) && (results != null))
             {
                 results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.DifferingPublicKeys", new object[] { "PublicKey", builder.Name, fileSource }));
             }
         }
         if (attribute != null)
         {
             string fileHash = this.GetFileHash(fileSource);
             this.ReplaceAttribute(packageFileNode, "Hash", fileHash);
             if (!fileHash.ToLowerInvariant().Equals(attribute.Value.ToLowerInvariant()) && (results != null))
             {
                 results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.DifferingPublicKeys", new object[] { "Hash", builder.Name, fileSource }));
             }
         }
     }
     else if (((settings.ComponentsLocation == ComponentsLocation.HomeSite) && (attribute == null)) && (attribute2 == null))
     {
         if (results != null)
         {
             results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.MissingVerificationInformation", new object[] { fileName, builder.Name }));
         }
         return false;
     }
     return true;
 }
 private bool VerifyHomeSiteInformation(XmlNode packageFileNode, ProductBuilder builder, BuildSettings settings, BuildResults results)
 {
     if (settings.ComponentsLocation != ComponentsLocation.HomeSite)
     {
         return true;
     }
     if ((packageFileNode.Attributes["HomeSite"] != null) || (builder.Product.CopyAllPackageFiles == CopyAllFilesType.CopyAllFilesIfNotHomeSite))
     {
         return true;
     }
     if (results != null)
     {
         results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.PackageHomeSiteMissing", new object[] { builder.Name }));
     }
     return false;
 }
 private XmlNode GetResourcesNodeForSettings(BuildSettings settings, BuildResults results, ref int codepage)
 {
     CultureInfo cultureInfoFromString = Util.GetCultureInfoFromString(settings.Culture);
     CultureInfo altCulture = Util.GetCultureInfoFromString(settings.FallbackCulture);
     XmlNode node = null;
     if (cultureInfoFromString != null)
     {
         node = this.GetResourcesNodeForSettings_Helper(cultureInfoFromString, cultureInfoFromString, results, ref codepage, false);
         if (node != null)
         {
             return node;
         }
         for (CultureInfo info3 = cultureInfoFromString.Parent; (info3 != null) && (info3 != CultureInfo.InvariantCulture); info3 = info3.Parent)
         {
             node = this.GetResourcesNodeForSettings_Helper(cultureInfoFromString, info3, results, ref codepage, false);
             if (node != null)
             {
                 return node;
             }
         }
     }
     if (altCulture != null)
     {
         node = this.GetResourcesNodeForSettings_Helper(cultureInfoFromString, altCulture, results, ref codepage, true);
         if (node != null)
         {
             return node;
         }
         if (!altCulture.IsNeutralCulture)
         {
             node = this.GetResourcesNodeForSettings_Helper(cultureInfoFromString, altCulture.Parent, results, ref codepage, true);
             if (node != null)
             {
                 return node;
             }
         }
     }
     node = this.GetResourcesNodeForSettings_Helper(cultureInfoFromString, Util.DefaultCultureInfo, results, ref codepage, true);
     if (node != null)
     {
         return node;
     }
     if (!Util.DefaultCultureInfo.IsNeutralCulture)
     {
         node = this.GetResourcesNodeForSettings_Helper(cultureInfoFromString, Util.DefaultCultureInfo.Parent, results, ref codepage, true);
         if (node != null)
         {
             return node;
         }
     }
     IEnumerator enumerator = this.cultures.Keys.GetEnumerator();
     enumerator.MoveNext();
     string current = (string) enumerator.Current;
     if ((cultureInfoFromString != null) && (results != null))
     {
         results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.UsingResourcesCulture", new object[] { cultureInfoFromString.Name, current }));
     }
     this.GetCodePage(current, ref codepage);
     return (XmlNode) this.cultures[current.ToLowerInvariant()];
 }
Example #15
0
        private XmlElement CreateApplicationElement(XmlElement configElement, BuildSettings settings)
        {
            XmlElement applicationElement = null;

            if (!String.IsNullOrEmpty(settings.ApplicationName) || !String.IsNullOrEmpty(settings.ApplicationFile))
            {
                applicationElement = configElement.OwnerDocument.CreateElement("Application");
                if (!String.IsNullOrEmpty(settings.ApplicationName))
                {
                    AddAttribute(applicationElement, "Name", settings.ApplicationName);
                }
                AddAttribute(applicationElement, "RequiresElevation", settings.ApplicationRequiresElevation ? "true" : "false");

                if (!String.IsNullOrEmpty(settings.ApplicationFile))
                {
                    XmlElement filesNode = applicationElement.OwnerDocument.CreateElement("Files");
                    XmlElement fileNode = filesNode.OwnerDocument.CreateElement("File");
                    AddAttribute(fileNode, "Name", settings.ApplicationFile);
                    AddAttribute(fileNode, URLNAME_ATTRIBUTE, Uri.EscapeUriString(settings.ApplicationFile));
                    filesNode.AppendChild(fileNode);
                    applicationElement.AppendChild(filesNode);
                }
            }
            return applicationElement;
        }
 private bool CopySetupToOutputDirectory(BuildSettings settings, string strOutputExe)
 {
     string bootstrapperPath = this.BootstrapperPath;
     string path = System.IO.Path.Combine(bootstrapperPath, "setup.bin");
     if (!File.Exists(path))
     {
         this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.MissingSetupBin", new object[] { "setup.bin", bootstrapperPath }));
         return false;
     }
     try
     {
         this.EnsureFolderExists(settings.OutputPath);
         File.Copy(path, strOutputExe, true);
         this.ClearReadOnlyAttribute(strOutputExe);
     }
     catch (IOException exception)
     {
         this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyError", new object[] { path, strOutputExe, exception.Message }));
         return false;
     }
     catch (UnauthorizedAccessException exception2)
     {
         this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyError", new object[] { path, strOutputExe, exception2.Message }));
         return false;
     }
     catch (ArgumentException exception3)
     {
         this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyError", new object[] { path, strOutputExe, exception3.Message }));
         return false;
     }
     catch (NotSupportedException exception4)
     {
         this.results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyError", new object[] { path, strOutputExe, exception4.Message }));
         return false;
     }
     return true;
 }
Example #17
0
        private bool VerifyHomeSiteInformation(XmlNode packageFileNode, ProductBuilder builder, BuildSettings settings, BuildResults results)
        {
            if (settings.ComponentsLocation != ComponentsLocation.HomeSite)
            {
                return true;
            }

            XmlAttribute homesiteAttribute = packageFileNode.Attributes[HOMESITE_ATTRIBUTE];

            if (homesiteAttribute == null && builder.Product.CopyAllPackageFiles != CopyAllFilesType.CopyAllFilesIfNotHomeSite)
            {
                if (results != null)
                    results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.PackageHomeSiteMissing", builder.Name));
                return false;
            }

            return true;
        }
 private XmlElement CreateApplicationElement(XmlElement configElement, BuildSettings settings)
 {
     XmlElement node = null;
     if (!string.IsNullOrEmpty(settings.ApplicationName) || !string.IsNullOrEmpty(settings.ApplicationFile))
     {
         node = configElement.OwnerDocument.CreateElement("Application");
         if (!string.IsNullOrEmpty(settings.ApplicationName))
         {
             this.AddAttribute(node, "Name", settings.ApplicationName);
         }
         this.AddAttribute(node, "RequiresElevation", settings.ApplicationRequiresElevation ? "true" : "false");
         if (!string.IsNullOrEmpty(settings.ApplicationFile))
         {
             XmlElement newChild = node.OwnerDocument.CreateElement("Files");
             XmlElement element3 = newChild.OwnerDocument.CreateElement("File");
             this.AddAttribute(element3, "Name", settings.ApplicationFile);
             this.AddAttribute(element3, "UrlName", Uri.EscapeUriString(settings.ApplicationFile));
             newChild.AppendChild(element3);
             node.AppendChild(newChild);
         }
     }
     return node;
 }
Example #19
0
        private void AddBuiltProducts(BuildSettings settings)
        {
            Dictionary<string, ProductBuilder> builtProducts = new Dictionary<string, ProductBuilder>();
            Dictionary<string, Product> productsAndIncludes = new Dictionary<string, Product>();

            if (_loopDependenciesWarnings != null && _loopDependenciesWarnings.Messages != null)
            {
                foreach (BuildMessage message in _loopDependenciesWarnings.Messages)
                {
                    _results.AddMessage(message);
                }
            }

            foreach (ProductBuilder builder in settings.ProductBuilders)
            {
                builtProducts.Add(builder.Product.ProductCode.ToLowerInvariant(), builder);
                Merge(productsAndIncludes, GetIncludedProducts(builder.Product));
                AddProduct(productsAndIncludes, builder.Product);
            }

            foreach (ProductBuilder builder in settings.ProductBuilders)
            {
                Dictionary<string, Product> includes = GetIncludedProducts(builder.Product);
                foreach (Product p in includes.Values)
                {
                    if (builtProducts.ContainsKey(p.ProductCode.ToLowerInvariant()))
                    {
                        _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.IncludedProductIncluded", builder.Name, p.Name));
                    }
                }

                foreach (List<Product> productDependency in builder.Product.Dependencies)
                {
                    bool foundDependency = false;
                    foreach (Product p in productDependency)
                    {
                        if (productsAndIncludes.ContainsKey(p.ProductCode.ToLowerInvariant()))
                        {
                            foundDependency = true;
                            break;
                        }
                    }

                    if (!foundDependency)
                    {
                        if (productDependency.Count == 1)
                        {
                            _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.MissingDependency", productDependency[0].Name, builder.Name));
                        }
                        else
                        {
                            StringBuilder missingProductCodes = new StringBuilder();
                            foreach (Product product in productDependency)
                            {
                                missingProductCodes.Append(product.Name);
                                missingProductCodes.Append(", ");
                            }

                            string productCodes = missingProductCodes.ToString();
                            productCodes = productCodes.Substring(0, productCodes.Length - 2);
                            _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.MissingDependencyMultiple", productCodes, builder.Name));
                        }
                    }
                }

                foreach (ArrayList missingDependecies in builder.Product.MissingDependencies)
                {
                    if (missingDependecies.Count == 1)
                    {
                        _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.DependencyNotFound", builder.Name, missingDependecies[0]));
                    }
                    else
                    {
                        StringBuilder missingProductCodes = new StringBuilder();
                        foreach (string productCode in missingDependecies)
                        {
                            missingProductCodes.Append(productCode);
                            missingProductCodes.Append(", ");
                        }

                        string productCodes = missingProductCodes.ToString();
                        productCodes = productCodes.Substring(0, productCodes.Length - 2);
                        _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.MultipleDependeciesNotFound", builder.Name, productCodes));
                    }
                }
            }
        }
Example #20
0
        /// <summary>
        /// Generates a bootstrapper based on the specified settings.
        /// </summary>
        /// <param name="settings">The properties used to build this bootstrapper.</param>
        /// <returns>The results of the bootstrapper generation</returns>
        public BuildResults Build(BuildSettings settings)
        {
            _results = new BuildResults();
            try
            {
                if (settings.ApplicationFile == null && (settings.ProductBuilders == null || settings.ProductBuilders.Count == 0))
                {
                    _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.InvalidInput"));
                    return _results;
                }

                if (String.IsNullOrEmpty(settings.OutputPath))
                {
                    _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.NoOutputPath"));
                    return _results;
                }

                if (!_fInitialized)
                    Refresh();

                if (String.IsNullOrEmpty(settings.Culture))
                    settings.Culture = MapLCIDToCultureName(settings.LCID);
                if (String.IsNullOrEmpty(settings.FallbackCulture))
                    settings.FallbackCulture = MapLCIDToCultureName(settings.FallbackLCID);

                if (String.IsNullOrEmpty(settings.Culture) || settings.Culture == "*")
                {
                    settings.Culture = settings.FallbackCulture;
                }

                AddBuiltProducts(settings);

                ArrayList componentFilesCopied = new ArrayList();

                // Copy setup.bin to the output directory
                string strOutputExe = System.IO.Path.Combine(settings.OutputPath, SETUP_EXE);
                if (!CopySetupToOutputDirectory(settings, strOutputExe))
                {
                    // Appropriate messages should have been stuffed into the results already
                    return _results;
                }

                ResourceUpdater resourceUpdater = new ResourceUpdater();

                // Build up the String table for setup.exe
                if (!BuildResources(settings, resourceUpdater))
                {
                    // Appropriate messages should have been stuffed into the results already
                    return _results;
                }

                AddStringResourceForUrl(resourceUpdater, "BASEURL", settings.ApplicationUrl, "ApplicationUrl");
                AddStringResourceForUrl(resourceUpdater, "COMPONENTSURL", settings.ComponentsUrl, "ComponentsUrl");
                AddStringResourceForUrl(resourceUpdater, "SUPPORTURL", settings.SupportUrl, "SupportUrl");
                if (settings.ComponentsLocation == ComponentsLocation.HomeSite)
                {
                    resourceUpdater.AddStringResource(40, "HOMESITE", true.ToString());
                }

                XmlElement configElement = _document.CreateElement("Configuration");
                XmlElement applicationElement = CreateApplicationElement(configElement, settings);
                if (applicationElement != null)
                {
                    configElement.AppendChild(applicationElement);
                }

                // Key: File hash, Value: A DictionaryEntry whose Key is "EULAx" and value is a 
                // fully qualified path to a eula. It can be any eula that matches the hash.
                Hashtable eulas = new Hashtable();

                // Copy package files, add each Package config info to the config file
                if (!BuildPackages(settings, configElement, resourceUpdater, componentFilesCopied, eulas))
                    return _results;

                // Transform the configuration xml into something the bootstrapper will understand
                DumpXmlToFile(configElement, "bootstrapper.cfg.xml");
                string config = XmlToConfigurationFile(configElement);
                resourceUpdater.AddStringResource(41, "SETUPCFG", config);
                DumpStringToFile(config, "bootstrapper.cfg", false);

                // Put eulas in the resource stream
                foreach (object obj in eulas.Values)
                {
                    DictionaryEntry de = (DictionaryEntry)obj;
                    string data;
                    FileInfo fi = new System.IO.FileInfo(de.Value.ToString());
                    using (FileStream fs = fi.OpenRead())
                    {
                        data = new StreamReader(fs).ReadToEnd();
                    }

                    resourceUpdater.AddStringResource(44, de.Key.ToString(), data);
                }

                resourceUpdater.AddStringResource(44, "COUNT", eulas.Count.ToString(CultureInfo.InvariantCulture));
                if (!resourceUpdater.UpdateResources(strOutputExe, _results))
                {
                    return _results;
                }

                _results.SetKeyFile(strOutputExe);
                string[] componentFiles = new string[componentFilesCopied.Count];
                componentFilesCopied.CopyTo(componentFiles);
                _results.AddComponentFiles(componentFiles);
                _results.BuildSucceeded();
            }
            catch (Exception ex)
            {
                _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.General", ex.Message));
            }
            return _results;
        }
Example #21
0
        /// <summary>
        /// Returns the directories bootstrapper component files would be copied to when built given the specified settings
        /// </summary>
        /// <param name="productCodes">The productCodes of the selected components</param>
        /// <param name="culture">The culture used to build the bootstrapper</param>
        /// <param name="fallbackCulture">The fallback culture used to build the bootstrapper</param>
        /// <param name="componentsLocation">How the bootstrapper would package the selected components</param>
        /// <returns></returns>
        public string[] GetOutputFolders(string[] productCodes, string culture, string fallbackCulture, ComponentsLocation componentsLocation)
        {
            if (!_fInitialized)
            {
                Refresh();
            }

            Hashtable folders = new Hashtable();
            BuildSettings settings = new BuildSettings();
            string invariantPath = PackagePath.ToLowerInvariant();
            invariantPath = Util.AddTrailingChar(invariantPath, System.IO.Path.DirectorySeparatorChar);
            settings.CopyComponents = false;
            settings.Culture = culture;
            settings.FallbackCulture = fallbackCulture;
            settings.ComponentsLocation = componentsLocation;
            if (String.IsNullOrEmpty(settings.Culture) || settings.Culture == "*")
            {
                settings.Culture = settings.FallbackCulture;
            }

            foreach (string productCode in productCodes)
            {
                Product product = Products.Product(productCode);
                if (product == null)
                    continue;
                settings.ProductBuilders.Add(product.ProductBuilder);
            }
            ArrayList files = new ArrayList();

            BuildPackages(settings, null, null, files, null);

            foreach (string file in files)
            {
                string folder = System.IO.Path.GetDirectoryName(file);
                if (folder.Substring(0, invariantPath.Length).ToLowerInvariant().CompareTo(invariantPath) == 0)
                {
                    string relPath = folder.Substring(invariantPath.Length).ToLowerInvariant();
                    if (!folders.Contains(relPath))
                        folders.Add(relPath, relPath);
                }
            }

            ArrayList list = new ArrayList(folders.Values);
            string[] a = new string[list.Count];
            list.CopyTo(a, 0);
            return a;
        }
Example #22
0
        private bool BuildPackages(BuildSettings settings, XmlElement configElement, ResourceUpdater resourceUpdater, ArrayList filesCopied, Hashtable eulas)
        {
            bool fSucceeded = true;

            foreach (ProductBuilder builder in settings.ProductBuilders)
            {
                if (Validate && !builder.Product.ValidationPassed)
                {
                    if (_results != null)
                    {
                        _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.ProductValidation", builder.Name, builder.Product.ValidationResults.FilePath));
                        foreach (string validationMessage in builder.Product.ValidationResults.ValidationErrors)
                        {
                            _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.ValidationError", builder.Product.ValidationResults.FilePath, validationMessage));
                        }
                        foreach (string validationMessage in builder.Product.ValidationResults.ValidationWarnings)
                        {
                            _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.ValidationWarning", builder.Product.ValidationResults.FilePath, validationMessage));
                        }
                    }
                }
                Package package = GetPackageForSettings(settings, builder, _results);
                if (package == null)
                {
                    // GetPackage should have already added the correct message info
                    continue;
                }

                if (Validate && !package.ValidationPassed)
                {
                    if (_results != null)
                    {
                        _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.PackageValidation", builder.Name, package.ValidationResults.FilePath));
                        foreach (string validationMessage in package.ValidationResults.ValidationErrors)
                        {
                            _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.ValidationError", package.ValidationResults.FilePath, validationMessage));
                        }
                        foreach (string validationMessage in package.ValidationResults.ValidationWarnings)
                        {
                            _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.ValidationWarning", package.ValidationResults.FilePath, validationMessage));
                        }
                    }
                }

                XmlNode node = package.Node;
                // Copy the files for this package to the output directory
                XmlAttribute eulaAttribute = node.Attributes[EULA_ATTRIBUTE];
                XmlNodeList packageFileNodes = node.SelectNodes(BOOTSTRAPPER_PREFIX + ":PackageFiles/" + BOOTSTRAPPER_PREFIX + ":PackageFile", _xmlNamespaceManager);
                XmlNode installChecksNode = node.SelectSingleNode(BOOTSTRAPPER_PREFIX + ":InstallChecks", _xmlNamespaceManager);
                foreach (XmlNode packageFileNode in packageFileNodes)
                {
                    XmlAttribute packageFileSource = (XmlAttribute)(packageFileNode.Attributes.GetNamedItem("SourcePath"));
                    XmlAttribute packageFileDestination = (XmlAttribute)(packageFileNode.Attributes.GetNamedItem("TargetPath"));
                    XmlAttribute packageFileName = (XmlAttribute)(packageFileNode.Attributes.GetNamedItem("Name"));
                    XmlAttribute packageFileCopy = (XmlAttribute)(packageFileNode.Attributes.GetNamedItem("CopyOnBuild"));
                    if (packageFileSource != null && eulaAttribute != null && !String.IsNullOrEmpty(eulaAttribute.Value) && packageFileSource.Value == eulaAttribute.Value)
                    {
                        // need to remove EULA from the package file list
                        XmlNode packageFilesNode = node.SelectSingleNode(BOOTSTRAPPER_PREFIX + ":PackageFiles", _xmlNamespaceManager);
                        packageFilesNode.RemoveChild(packageFileNode);
                        continue;
                    }

                    if ((packageFileSource != null) && (packageFileDestination != null))
                    {
                        // Calculate the hash of this file and add it to the PackageFileNode
                        if (!AddVerificationInformation(packageFileNode, packageFileSource.Value, packageFileName.Value, builder, settings, _results))
                            fSucceeded = false;
                    }

                    if ((packageFileSource != null) && (packageFileDestination != null) &&
                        ((packageFileCopy == null) || (String.Compare(packageFileCopy.Value, "False", StringComparison.InvariantCulture) != 0)))
                    {
                        // if this is the key for an external check, we will add it to the Resource Updater instead of copying the file
                        XmlNode subNode = null;
                        if ((installChecksNode != null) && (packageFileName != null))
                        {
                            subNode = QueryForSubNode(installChecksNode, "PackageFile", packageFileName.Value);
                        }
                        if (subNode != null)
                        {
                            if (resourceUpdater != null)
                            {
                                if (!File.Exists(packageFileSource.Value))
                                {
                                    if (_results != null)
                                        _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.PackageResourceFileNotFound", packageFileSource.Value, builder.Name));
                                    fSucceeded = false;
                                    continue;
                                }
                                resourceUpdater.AddFileResource(packageFileSource.Value, packageFileDestination.Value);
                            }
                        }
                        else
                        {
                            if (settings.ComponentsLocation != ComponentsLocation.HomeSite || !VerifyHomeSiteInformation(packageFileNode, builder, settings, _results))
                            {
                                if (settings.CopyComponents)
                                {
                                    string strDestinationFileName = System.IO.Path.Combine(settings.OutputPath, packageFileDestination.Value);
                                    try
                                    {
                                        if (!File.Exists(packageFileSource.Value))
                                        {
                                            if (_results != null)
                                                _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.PackageFileNotFound", packageFileDestination.Value, builder.Name));
                                            fSucceeded = false;
                                            continue;
                                        }
                                        EnsureFolderExists(System.IO.Path.GetDirectoryName(strDestinationFileName));
                                        File.Copy(packageFileSource.Value, strDestinationFileName, true);
                                        ClearReadOnlyAttribute(strDestinationFileName);
                                    }
                                    catch (UnauthorizedAccessException ex)
                                    {
                                        if (_results != null)
                                            _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyPackageError", packageFileSource.Value, builder.Name, ex.Message));
                                        fSucceeded = false;
                                        continue;
                                    }
                                    catch (IOException ex)
                                    {
                                        if (_results != null)
                                            _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyPackageError", packageFileSource.Value, builder.Name, ex.Message));
                                        fSucceeded = false;
                                        continue;
                                    }
                                    catch (ArgumentException ex)
                                    {
                                        if (_results != null)
                                            _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyPackageError", packageFileSource.Value, builder.Name, ex.Message));
                                        fSucceeded = false;
                                        continue;
                                    }
                                    catch (NotSupportedException ex)
                                    {
                                        if (_results != null)
                                            _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.CopyPackageError", packageFileSource.Value, builder.Name, ex.Message));
                                        fSucceeded = false;
                                        continue;
                                    }
                                    filesCopied.Add(strDestinationFileName);
                                }
                                else
                                {
                                    filesCopied.Add(packageFileSource.Value);
                                }

                                // Add the file size to the PackageFileNode
                                XmlAttribute sizeAttribute = packageFileNode.OwnerDocument.CreateAttribute("Size");
                                FileInfo fi = new FileInfo(packageFileSource.Value);
                                sizeAttribute.Value = "" + (fi.Length.ToString(CultureInfo.InvariantCulture));
                                MergeAttribute(packageFileNode, sizeAttribute);
                            }
                        }
                    }
                }
                // Add the Eula attribute correctly
                if (eulas != null && eulaAttribute != null && !String.IsNullOrEmpty(eulaAttribute.Value))
                {
                    if (File.Exists(eulaAttribute.Value))
                    {
                        // eulas[GetFileHash(eulaAttribute.Value)] = eulaAttribute.Value;
                        string key = GetFileHash(eulaAttribute.Value);
                        if (eulas.ContainsKey(key))
                            eulaAttribute.Value = ((DictionaryEntry)eulas[key]).Key.ToString();
                        else
                        {
                            string configFileKey = string.Format(CultureInfo.InvariantCulture, "EULA{0}", eulas.Count);
                            DictionaryEntry de = new DictionaryEntry(configFileKey, eulaAttribute.Value);
                            eulas[key] = de;
                            eulaAttribute.Value = configFileKey;
                        }
                    }
                    else
                    {
                        if (_results != null)
                            _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.PackageResourceFileNotFound", eulaAttribute.Value, builder.Name));
                        fSucceeded = false;
                        continue;
                    }
                }
                // Write the package node
                if (configElement != null)
                {
                    configElement.AppendChild(configElement.OwnerDocument.ImportNode(node, true));
                    DumpXmlToFile(node, string.Format(CultureInfo.CurrentCulture, "{0}.{1}.xml", package.Product.ProductCode, package.Culture));
                }
            }

            return fSucceeded;
        }
 public override bool Execute()
 {
     BootstrapperBuilder builder = new BootstrapperBuilder {
         Validate = this.Validate,
         Path = this.Path
     };
     ProductCollection products = builder.Products;
     BuildSettings settings = new BuildSettings {
         ApplicationFile = this.ApplicationFile,
         ApplicationName = this.ApplicationName,
         ApplicationRequiresElevation = this.ApplicationRequiresElevation,
         ApplicationUrl = this.ApplicationUrl,
         ComponentsLocation = this.ConvertStringToComponentsLocation(this.ComponentsLocation),
         ComponentsUrl = this.ComponentsUrl,
         CopyComponents = this.CopyComponents,
         Culture = this.culture,
         FallbackCulture = this.fallbackCulture,
         OutputPath = this.OutputPath,
         SupportUrl = this.SupportUrl
     };
     if (this.BootstrapperItems != null)
     {
         Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase);
         foreach (ITaskItem item in this.BootstrapperItems)
         {
             string metadata = item.GetMetadata("Install");
             if (string.IsNullOrEmpty(metadata) || ConversionUtilities.ConvertStringToBool(metadata))
             {
                 if (!hashtable.Contains(item.ItemSpec))
                 {
                     hashtable.Add(item.ItemSpec, item);
                 }
                 else
                 {
                     base.Log.LogWarningWithCodeFromResources("GenerateBootstrapper.DuplicateItems", new object[] { item.ItemSpec });
                 }
             }
         }
         foreach (Product product in products)
         {
             if (hashtable.Contains(product.ProductCode))
             {
                 settings.ProductBuilders.Add(product.ProductBuilder);
                 hashtable.Remove(product.ProductCode);
             }
         }
         foreach (ITaskItem item2 in hashtable.Values)
         {
             base.Log.LogWarningWithCodeFromResources("GenerateBootstrapper.ProductNotFound", new object[] { item2.ItemSpec, builder.Path });
         }
     }
     BuildResults results = builder.Build(settings);
     BuildMessage[] messages = results.Messages;
     if (messages != null)
     {
         foreach (BuildMessage message in messages)
         {
             if (message.Severity == BuildMessageSeverity.Error)
             {
                 base.Log.LogError(null, message.HelpCode, message.HelpKeyword, null, 0, 0, 0, 0, message.Message, new object[0]);
             }
             else if (message.Severity == BuildMessageSeverity.Warning)
             {
                 base.Log.LogWarning(null, message.HelpCode, message.HelpKeyword, null, 0, 0, 0, 0, message.Message, new object[0]);
             }
         }
     }
     this.BootstrapperKeyFile = results.KeyFile;
     this.BootstrapperComponentFiles = results.ComponentFiles;
     return results.Succeeded;
 }
Example #24
0
        private Package GetPackageForSettings(BuildSettings settings, ProductBuilder builder, BuildResults results)
        {
            CultureInfo ci = Util.GetCultureInfoFromString(settings.Culture);
            CultureInfo fallbackCI = Util.GetCultureInfoFromString(settings.FallbackCulture);
            Package package = null;

            if (builder.Product.Packages.Count == 0)
            {
                if (results != null)
                    results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Error, "GenerateBootstrapper.ProductCultureNotFound", builder.Name));
                return null;
            }

            if (ci != null)
            {
                package = builder.Product.Packages.Package(ci.Name);
                if (package != null) return package;

                // Target culture not found?  Go through the progression of parent cultures (up until but excluding the invariant culture) -> fallback culture -> parent fallback culture -> default culture -> parent default culture -> any culture available
                // Note: there is no warning if the parent culture of the requested culture is found
                CultureInfo parentCulture = ci.Parent;

                // Keep going up the chain of parents, stopping at the invariant culture
                while (parentCulture != null && parentCulture != CultureInfo.InvariantCulture)
                {
                    package = GetPackageForSettings_Helper(ci, parentCulture, builder, results, false);
                    if (package != null) return package;

                    parentCulture = parentCulture.Parent;
                }
            }


            if (fallbackCI != null)
            {
                package = GetPackageForSettings_Helper(ci, fallbackCI, builder, results, true);
                if (package != null) return package;

                if (!fallbackCI.IsNeutralCulture)
                {
                    package = GetPackageForSettings_Helper(ci, fallbackCI.Parent, builder, results, true);
                    if (package != null) return package;
                }
            }

            package = GetPackageForSettings_Helper(ci, Util.DefaultCultureInfo, builder, results, true);
            if (package != null) return package;

            if (!Util.DefaultCultureInfo.IsNeutralCulture)
            {
                package = GetPackageForSettings_Helper(ci, Util.DefaultCultureInfo.Parent, builder, results, true);
                if (package != null) return package;
            }

            if (results != null && ci != null)
                results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.UsingProductCulture", ci.Name, builder.Name, builder.Product.Packages.Item(0).Culture));
            return builder.Product.Packages.Item(0);
        }
 public BuildResults Build(BuildSettings settings)
 {
     throw new NotImplementedException();
 }
 public string[] GetOutputFolders(string[] productCodes, string culture, string fallbackCulture, ComponentsLocation componentsLocation)
 {
     if (!this.fInitialized)
     {
         this.Refresh();
     }
     Hashtable hashtable = new Hashtable();
     BuildSettings settings = new BuildSettings();
     string strB = Util.AddTrailingChar(this.PackagePath.ToLowerInvariant(), System.IO.Path.DirectorySeparatorChar);
     settings.CopyComponents = false;
     settings.Culture = culture;
     settings.FallbackCulture = fallbackCulture;
     settings.ComponentsLocation = componentsLocation;
     foreach (string str2 in productCodes)
     {
         Product product = this.Products.Product(str2);
         if (product != null)
         {
             settings.ProductBuilders.Add(product.ProductBuilder);
         }
     }
     ArrayList filesCopied = new ArrayList();
     this.BuildPackages(settings, null, null, filesCopied, null);
     foreach (string str3 in filesCopied)
     {
         string directoryName = System.IO.Path.GetDirectoryName(str3);
         if (directoryName.Substring(0, strB.Length).ToLowerInvariant().CompareTo(strB) == 0)
         {
             string key = directoryName.Substring(strB.Length).ToLowerInvariant();
             if (!hashtable.Contains(key))
             {
                 hashtable.Add(key, key);
             }
         }
     }
     ArrayList list2 = new ArrayList(hashtable.Values);
     string[] array = new string[list2.Count];
     list2.CopyTo(array, 0);
     return array;
 }