コード例 #1
0
 private void AddStringResourceForUrl(ResourceUpdater resourceUpdater, string name, string url, string nameToUseInLog)
 {
     if (!String.IsNullOrEmpty(url))
     {
         resourceUpdater.AddStringResource(40, name, url);
         if (!Util.IsWebUrl(url) && !Util.IsUncPath(url))
         {
             _results.AddMessage(BuildMessage.CreateMessage(BuildMessageSeverity.Warning, "GenerateBootstrapper.InvalidUrl", nameToUseInLog, url));
         }
     }
 }
コード例 #2
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;
        }
 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;
 }
コード例 #4
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;
        }
 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;
 }