Ejemplo n.º 1
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;
 }