public static WixItem ResolveParentFolderMsiItem(Folder parentFolder, IDictionary <PackageItem, WixItem> msiItems)
        {
            WixItem item = null;

            while (parentFolder != null)
            {
                item = msiItems[parentFolder];
                if (item is WixFolderReference || item is WixFolder)
                {
                    if (!String.IsNullOrEmpty(item.MsiId))
                    {
                        break;
                    }
                }
                else
                {
                    // TODO: display error since a parent isn't what we expected?
                }

                parentFolder = parentFolder.ParentFolder;
                item         = null;
            }

            return(item);
        }
Esempio n. 2
0
        public override WixSection GenerateSection()
        {
            if (this.System || String.IsNullOrEmpty(this.MsiId))
            {
                return(null);
            }

            Folder  folder        = (Folder)this.Item;
            WixItem parentMsiItem = WixBackendCompilerServices.ResolveParentFolderMsiItem(folder.ParentFolder, this.Backend.WixItems);

            if (parentMsiItem == null)
            {
                return(null);
            }

            WixSection section = new WixSection(this.MsiId, "fragment", this.Item.LineNumber);

            string defaultDir = String.IsNullOrEmpty(folder.Name) ? "." : WixBackendCompilerServices.GenerateMsiFileName(false, folder.Name.TrimEnd(new char[] { '\\' }), "Directory", parentMsiItem.MsiId);

            WixBackendCompilerServices.GenerateRow(section, "Directory", this.Item.LineNumber,
                                                   this.MsiId,          // Id
                                                   parentMsiItem.MsiId, // Directory_Parent
                                                   defaultDir);         // DefaultDir

            WixBackendCompilerServices.GenerateSimpleReference(section, "Directory", this.Item.LineNumber, parentMsiItem.MsiId);

            return(section);
        }
        public static string GenerateMsiCondition(WixItem item)
        {
            HashSet <WixItem> processedItems = new HashSet <WixItem>();

            string[] conditions = WixBackendCompilerServices.GenerateMsiConditions(item, processedItems);
            return(conditions.Length == 0 ? null : String.Join(" AND ", conditions));
        }
        private static string[] GenerateMsiConditions(WixItem item, HashSet <WixItem> processedItems)
        {
            List <string> conditions = new List <string>();

            if (!processedItems.Contains(item))
            {
                processedItems.Add(item);

                if (item.Group != null)
                {
                    conditions.AddRange(WixBackendCompilerServices.GenerateMsiConditions(item.Group, processedItems));
                }

                if (item.Parent != null)
                {
                    conditions.AddRange(WixBackendCompilerServices.GenerateMsiConditions(item.Parent, processedItems));
                }

                string condition = Install.GetCondition(item.Item);
                if (!String.IsNullOrEmpty(condition))
                {
                    conditions.Add(condition);
                }
            }

            return(conditions.ToArray());
        }
Esempio n. 5
0
        public override WixSection GenerateSection()
        {
            if (this.System)
            {
                return(null);
            }

            File    file          = (File)this.Item;
            WixItem folderMsiItem = WixBackendCompilerServices.ResolveParentFolderMsiItem(file.ParentFolder, this.Backend.WixItems);

            if (folderMsiItem == null)
            {
                return(null);
            }

            string componentId = this.ComponentMsiId;
            int    attributes  = this.Backend.Architecture == PackageArchitecture.X64 ? 256 : 0;
            string condition   = WixBackendCompilerServices.GenerateMsiCondition(this);

            if (!String.IsNullOrEmpty(condition))
            {
                attributes |= 64; // mark Component transitive when there is a condition.
            }

            WixSection section = new WixSection(this.MsiId, "fragment", this.Item.LineNumber);

            WixBackendCompilerServices.GenerateRow(section, "Component", this.Item.LineNumber,
                                                   componentId,         // Id
                                                   "*",                 // Guid
                                                   folderMsiItem.MsiId, // Directory
                                                   attributes,          // Attributes
                                                   condition,           // Condition
                                                   this.MsiId);         // KeyPath

            this.GenerateSectionRowsForComponent(section, componentId);

            WixBackendCompilerServices.GenerateSimpleReference(section, "Directory", this.Item.LineNumber, folderMsiItem.MsiId);
            WixBackendCompilerServices.GenerateSimpleReference(section, "Media", this.Item.LineNumber, "1");

            foreach (ITargetFile targetFileItem in file.Items)
            {
                File childsFile = targetFileItem.GetTargetedFile();
                if (childsFile == file)
                {
                    WixItem item = this.Backend.WixItems[(PackageItem)targetFileItem];
                    item.GenerateSectionRowsForComponent(section, componentId);
                }
            }

            return(section);
        }
        public override WixSection GenerateSection()
        {
            if (this.System)
            {
                return(null);
            }

            InprocServer  inprocServer  = this.Item as InprocServer;
            OutprocServer outprocServer = this.Item as OutprocServer;

            File file = this.inproc ? inprocServer.File : outprocServer.File;

            if (file == this.Item.Parent)
            {
                return(null);
            }

            WixItem folderMsiItem = WixBackendCompilerServices.ResolveParentFolderMsiItem(file.ParentFolder, this.Backend.WixItems);

            if (folderMsiItem == null)
            {
                return(null);
            }

            string componentId = this.ComponentMsiId;
            int    attributes  = this.Backend.Architecture == PackageArchitecture.X64 ? 260 : 4;
            string condition   = WixBackendCompilerServices.GenerateMsiCondition(this);

            if (!String.IsNullOrEmpty(condition))
            {
                attributes |= 64; // mark Component transitive when there is a condition.
            }

            WixSection section = new WixSection(this.MsiId, "fragment", this.Item.LineNumber);

            WixBackendCompilerServices.GenerateRow(section, "Component", this.Item.LineNumber,
                                                   componentId,         // Id
                                                   "*",                 // Guid
                                                   folderMsiItem.MsiId, // Directory
                                                   attributes,          // Attributes
                                                   condition,           // Condition
                                                   this.MsiId);         // KeyPath

            this.GenerateSectionRowsForComponent(section, componentId);

            return(section);
        }
Esempio n. 7
0
        public override void GenerateSectionRowsForComponent(WixSection section, string componentId)
        {
            File    file          = (File)this.Item;
            WixItem folderMsiItem = WixBackendCompilerServices.ResolveParentFolderMsiItem(file.ParentFolder, this.Backend.WixItems);

            string fileId   = this.MsiId;
            string fileName = WixBackendCompilerServices.GenerateMsiFileName(true, file.Name, "File", fileId);
            bool   gac      = (folderMsiItem is WixFolderReference && folderMsiItem.System && folderMsiItem.Item.Id.Equals("GacFolder"));

            WixBackendCompilerServices.GenerateRow(section, "File", this.Item.LineNumber,
                                                   fileId,                                              // Id
                                                   componentId,                                         // Component
                                                   fileName,                                            // FileName
                                                   0,                                                   // Size
                                                   null,                                                // Version
                                                   null,                                                // Language
                                                   WixBackendCompilerServices.MsidbFileAttributesVital, // Attributes
                                                   null);                                               // Sequence

            WixBackendCompilerServices.GenerateRow(section, "WixFile", this.Item.LineNumber,
                                                   fileId,                                                                         // Id
                                                   gac ? "0" : null,                                                               // AssemblyAttributes
                                                   null,                                                                           // AssemblyManifest
                                                   null,                                                                           // AssemblyAssemblyApplication
                                                   folderMsiItem.MsiId,                                                            // Directory
                                                   1,                                                                              // DiskId
                                                   file.Source,                                                                    // Source
                                                   null /*file.Architecture*/,                                                     // TODO: make this right
                                                   -1,
                                                   String.Equals(file.Name, fileName, StringComparison.OrdinalIgnoreCase) ? 0 : 1, // GeneratedShortName
                                                   0,
                                                   null,
                                                   null,
                                                   null,
                                                   null);

            if (gac)
            {
                WixBackendCompilerServices.GenerateRow(section, "MsiAssembly", this.Item.LineNumber,
                                                       componentId,              // ComponentId
                                                       Guid.Empty.ToString("B"), // Feature (complex reference)
                                                       null,                     // AssemblyManifest
                                                       null,                     // AssemblyApplication
                                                       0);                       // AssemblyAttributes
            }
        }
        public static string GenerateMsiIdForFileReference(WixBackendCompiler backend, IFileReference fs)
        {
            string id = null;

            WixItem item = backend.WixItems[fs.GetPackageItem()];

            if (item.Item is Lexicon.File)
            {
                id = String.Concat("[#", item.MsiId, "]");
            }
            else if (item.Item is Lexicon.Msi.Property)
            {
                id = String.Concat("[", item.MsiId, "]");
            }
            else if (item.Item is Lexicon.Msi.FileSearch)
            {
                id = String.Concat("[", item.MsiId, "]");
            }

            return(id);
        }
        public override void GenerateSectionRowsForComponent(WixSection section, string componentId)
        {
            NgenPackageItem ngen = (NgenPackageItem)this.Item;

            int priority = 3;

            switch (ngen.Execute)
            {
            case NgenExecuteType.asynchronous:
                priority = 1;
                break;

            case NgenExecuteType.idle:
                priority = 3;
                break;

            case NgenExecuteType.immediate:
                priority = 0;
                break;
            }

            int attributes = 0x2; // dependencies are not processed automatically.

            switch (this.Backend.Architecture)
            {
            case PackageArchitecture.Arm:
            case PackageArchitecture.X86:
                attributes |= 0x8;     // 32-bit
                break;

            case PackageArchitecture.X64:
                attributes |= 0x10;     // 64-bit
                break;

            case PackageArchitecture.Unknown:
            case PackageArchitecture.Neutral:
                attributes |= 0x18;     // both
                break;
            }

            WixItem msiFileItem = this.Backend.WixItems[ngen.File];
            string  refTable    = null;
            string  refId       = null;

            string applicationFile = null;

            if (ngen.Application != null)
            {
                WixItem item = this.Backend.WixItems[ngen.Application.GetPackageItem()];
                if (item.Item is Lexicon.File)
                {
                    applicationFile = item.MsiId;
                    refTable        = "File";
                    refId           = item.MsiId;
                }
                else if (item.Item is Lexicon.Msi.Property || item.Item is Lexicon.Msi.FileSearch)
                {
                    applicationFile = String.Concat("[", item.MsiId, "]");
                    refTable        = "Property";
                    refId           = item.MsiId;
                }
                else
                {
                    // TODO: display error.
                }
            }

            string applicationFolder = null;

            if (ngen.Folder != null)
            {
                WixItem item = this.Backend.WixItems[ngen.Folder];
                applicationFolder = item.MsiId;
                refTable          = "Directory";
                refId             = item.MsiId;
            }

            if (!String.IsNullOrEmpty(refTable))
            {
                WixBackendCompilerServices.GenerateSimpleReference(section, refTable, this.Item.LineNumber, refId);
            }

            WixBackendCompilerServices.GenerateRow(section, "NetFxNativeImage", this.Item.LineNumber,
                                                   msiFileItem.MsiId,  // Id
                                                   msiFileItem.MsiId,  // File_
                                                   priority,           // Priority
                                                   attributes,         // Attributes
                                                   applicationFile,    // File_Application
                                                   applicationFolder); // Directory_ApplicationBase

            WixBackendCompilerServices.GenerateSimpleReference(section, "CustomAction", this.Item.LineNumber, "NetFxScheduleNativeImage");
        }
        private Dictionary <PackageItem, WixItem> ProcessIntermediates(IEnumerable <Intermediate> intermediates)
        {
            Dictionary <PackageItem, WixItem> wixItems = new Dictionary <PackageItem, WixItem>();

            foreach (Intermediate intermediate in intermediates)
            {
                foreach (PackageItem item in intermediate.Items)
                {
                    File file = item as File;
                    if (file != null)
                    {
                        WixFile msiFile = new WixFile(this, file);
                        wixItems.Add(file, msiFile);

                        NgenPackageItem ngen;
                        if (Ngen.TryGetPackageItem(file, out ngen))
                        {
                            ngen.LineNumber = file.LineNumber;
                            file.Items.Add(ngen);

                            WixNativeImage nativeImage = new WixNativeImage(this, ngen);
                            wixItems.Add(ngen, nativeImage);
                        }
                    }
                    else
                    {
                        Folder folder = item as Folder;
                        if (folder != null)
                        {
                            if (folder.External)
                            {
                                WixFolderReference msiFolderRef = new WixFolderReference(this, folder);
                                wixItems.Add(folder, msiFolderRef);
                            }
                            else
                            {
                                WixFolder msiFolder = new WixFolder(this, folder);
                                wixItems.Add(folder, msiFolder);
                            }
                        }
                        else
                        {
                            InprocServer inprocServer = item as InprocServer;
                            if (null != inprocServer)
                            {
                                WixClassId classId = new WixClassId(this, inprocServer);
                                wixItems.Add(inprocServer, classId);
                            }
                            else
                            {
                                OutprocServer outprocServer = item as OutprocServer;
                                if (null != outprocServer)
                                {
                                    WixClassId classId = new WixClassId(this, outprocServer);
                                    wixItems.Add(outprocServer, classId);
                                }
                                else
                                {
                                    Property property = item as Property;
                                    if (property != null)
                                    {
                                        WixProperty prop = new WixProperty(this, property);
                                        wixItems.Add(property, prop);
                                    }
                                    else
                                    {
                                        FileSearch fileSearch = item as FileSearch;
                                        if (fileSearch != null)
                                        {
                                            WixFileSearch fs = new WixFileSearch(this, fileSearch);
                                            wixItems.Add(fileSearch, fs);
                                        }
                                        else
                                        {
                                            Group group = item as Group;
                                            if (group != null)
                                            {
                                                WixGroup msiGroup = new WixGroup(this, group);
                                                wixItems.Add(group, msiGroup);
                                            }
                                            else if (item is Package)
                                            {
                                                // TODO: send an error message since library files cannot process Package elements.
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Fix up all the item parents and groups now that we have them
            // all processed into a single look up dictionary.
            foreach (var kv in wixItems)
            {
                PackageItem pi = kv.Key;
                WixItem     wi = kv.Value;
                if (pi.Parent != null)
                {
                    wi.Parent = wixItems[pi.Parent];
                }

                if (pi.Group != null)
                {
                    wi.Group = (WixGroup)wixItems[pi.Group];
                    wi.Group.ContainedWixItems.Add(wi);
                }
            }

            return(wixItems);
        }
        public override void GenerateSectionRowsForComponent(WixSection section, string componentId)
        {
            InprocServer  inprocServer  = this.Item as InprocServer;
            OutprocServer outprocServer = this.Item as OutprocServer;

            IEnumerable <Class> classes = this.inproc ? inprocServer.Classes : outprocServer.Classes;

            foreach (Class classId in classes)
            {
                File    fileItem    = this.inproc ? inprocServer.File : outprocServer.File;
                WixItem msiFileItem = this.Backend.WixItems[fileItem];

                string guidClassId = new Guid(classId.Id).ToString("B").ToUpperInvariant();
                string key         = this.GetKey(guidClassId);

                string value = String.Concat("[#", msiFileItem.MsiId, "]");
                if (!this.inproc && !String.IsNullOrWhiteSpace(outprocServer.Arguments))
                {
                    value = String.Concat("\"", value, "\" ", outprocServer.Arguments);
                }

                string msiId = WixBackendCompilerServices.GenerateIdForRegKey(this.Backend, null, 0, key, null);
                WixBackendCompilerServices.GenerateRow(section, "Registry", this.Item.LineNumber,
                                                       msiId,        // Id
                                                       0,            // HKCR
                                                       key,          // Key
                                                       null,         // Name
                                                       value,        // Value
                                                       componentId); // Component

                string threadingModel = ConvertThreadingModel(classId.ThreadingModel);

                msiId = WixBackendCompilerServices.GenerateIdForRegKey(this.Backend, null, 0, key, "ThreadingModel");
                WixBackendCompilerServices.GenerateRow(section, "Registry", this.Item.LineNumber,
                                                       msiId,            // Id
                                                       0,                // HKCR
                                                       key,              // Key
                                                       "ThreadingModel", // Name
                                                       threadingModel,   // Value
                                                       componentId);     // Component

                if (!String.IsNullOrEmpty(classId.Implementation))
                {
                    key   = String.Concat("CLSID\\", guidClassId, "\\ProgID");
                    msiId = WixBackendCompilerServices.GenerateIdForRegKey(this.Backend, null, 0, key, null);
                    WixBackendCompilerServices.GenerateRow(section, "Registry", this.Item.LineNumber,
                                                           msiId,                  // Id
                                                           0,                      // HKCR
                                                           key,                    // Key
                                                           null,                   // Name
                                                           classId.Implementation, // Value
                                                           componentId);           // Component

                    key   = String.Concat(classId.Implementation, "\\CLSID");
                    msiId = WixBackendCompilerServices.GenerateIdForRegKey(this.Backend, null, 0, key, null);
                    WixBackendCompilerServices.GenerateRow(section, "Registry", this.Item.LineNumber,
                                                           msiId,        // Id
                                                           0,            // HKCR
                                                           key,          // Key
                                                           null,         // Name
                                                           guidClassId,  // Value
                                                           componentId); // Component
                }
            }
        }