Esempio n. 1
0
        private void SaveIR(WixOutput wixout)
        {
            using (var writer = new StreamWriter(wixout.CreateDataStream(WixOutputStreamName)))
            {
                var jsonObject = new JsonObject
                {
                    { "id", this.Id },
                    { "level", this.Level },
                    { "version", Intermediate.CurrentVersion.ToString() }
                };

                var sectionsJson = new JsonArray(this.Sections.Count);
                foreach (var section in this.Sections)
                {
                    var sectionJson = section.Serialize();
                    sectionsJson.Add(sectionJson);
                }

                jsonObject.Add("sections", sectionsJson);

                var customDefinitions = this.GetCustomDefinitionsInSections();

                if (customDefinitions.Count > 0)
                {
                    var customDefinitionsJson = new JsonArray(customDefinitions.Count);

                    foreach (var kvp in customDefinitions.OrderBy(d => d.Key))
                    {
                        var customDefinitionJson = kvp.Value.Serialize();
                        customDefinitionsJson.Add(customDefinitionJson);
                    }

                    jsonObject.Add("definitions", customDefinitionsJson);
                }

                if (this.Localizations.Any())
                {
                    var localizationsJson = new JsonArray();
                    foreach (var localization in this.Localizations)
                    {
                        var localizationJson = localization.Serialize();
                        localizationsJson.Add(localizationJson);
                    }

                    jsonObject.Add("localizations", localizationsJson);
                }

                var json = SimpleJson.SerializeObject(jsonObject);
                writer.Write(json);
            }
        }
Esempio n. 2
0
        private void SaveEmbedFiles(WixOutput wixout)
        {
            var embeddedFields = this.Sections.SelectMany(s => s.Symbols)
                                 .SelectMany(t => t.Fields)
                                 .Where(f => f?.Type == IntermediateFieldType.Path)
                                 .Select(f => f.AsPath())
                                 .Where(f => f.Embed)
                                 .ToList();

            var savedEmbedFields = new Dictionary <string, IntermediateFieldPathValue>(StringComparer.OrdinalIgnoreCase);
            var uniqueEntryNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var embeddedField in embeddedFields)
            {
                var key = String.Concat(embeddedField.BaseUri?.AbsoluteUri, "?", embeddedField.Path);

                if (savedEmbedFields.TryGetValue(key, out var existing))
                {
                    embeddedField.Path = existing.Path;
                }
                else
                {
                    var entryName = CalculateUniqueEntryName(uniqueEntryNames, embeddedField.Path);

                    if (embeddedField.BaseUri == null)
                    {
                        wixout.ImportDataStream(entryName, embeddedField.Path);
                    }
                    else // open the container specified in baseUri and copy the correct stream out of it.
                    {
                        using (var otherWixout = WixOutput.Read(embeddedField.BaseUri))
                            using (var stream = otherWixout.GetDataStream(embeddedField.Path))
                                using (var target = wixout.CreateDataStream(entryName))
                                {
                                    stream.CopyTo(target);
                                }
                    }

                    embeddedField.Path = entryName;

                    savedEmbedFields.Add(key, embeddedField);
                }
            }
        }