/// <summary>
        /// Parses a PlayTask element for Game Explorer task registration.
        /// </summary>
        /// <param name="node">The element to parse.</param>
        /// <param name="gameId">The game's instance identifier.</param>
        /// <param name="fileId">The file identifier of the game executable.</param>
        /// <param name="componentId">The component identifier of the game executable.</param>
        /// <param name="taskOrder">The order this play task should appear in Game Explorer.</param>
        private void ParsePlayTaskElement(Intermediate intermediate, IntermediateSection section, XElement node, string gameId, string fileId, string componentId, int taskOrder, string componentDirectoryId)
        {
            var    sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node);
            string name      = null;
            string arguments = null;

            foreach (var attrib in node.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "Name":
                        name = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);
                        break;

                    case "Arguments":
                        arguments = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);
                        break;

                    default:
                        this.ParseHelper.UnexpectedAttribute(node, attrib);
                        break;
                    }
                }
                else
                {
                    this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, node, attrib);
                }
            }

            this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, node);

            if (null == name)
            {
                this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Name"));
            }

            if (!this.Messaging.EncounteredError)
            {
                // create Shortcut rows pointing to the parent File
                var directoryId = this.CreateTaskDirectoryRow(section, sourceLineNumbers, componentId, TaskType.Play, taskOrder);
                var shortName   = this.ParseHelper.IsValidShortFilename(name, false) ? name : this.ParseHelper.CreateShortName(name, true, false, directoryId, name);
                section.AddTuple(new ShortcutTuple(sourceLineNumbers, new Identifier(AccessModifier.Private, directoryId))
                {
                    DirectoryRef     = directoryId,
                    Name             = name,
                    ShortName        = shortName,
                    ComponentRef     = componentId,
                    Target           = String.Format(CultureInfo.InvariantCulture, "[#{0}]", fileId),
                    Arguments        = arguments,
                    WorkingDirectory = componentDirectoryId,
                });
            }
        }
        /// <summary>
        /// Creates and schedules custom actions to set the root directories for this game's play and support tasks.
        /// </summary>
        /// <param name="sourceLineNumbers">Source line number for the parent element.</param>
        /// <param name="gameId">The game's instance identifier.</param>
        /// <param name="componentId">The component identifier of the game executable.</param>
        private void CreateTaskRootDirectoryCustomActions(IntermediateSection section, SourceLineNumber sourceLineNumbers, string gameId, string componentId)
        {
            var access                          = AccessModifier.Private;
            var sequence                        = SequenceTable.InstallExecuteSequence;
            var playTasksDirectoryId            = this.GetTaskDirectoryId(sourceLineNumbers, "WixPlayTasksRoot", componentId);
            var playTasksDirectoryIdentifier    = new Identifier(access, playTasksDirectoryId);
            var supportTasksDirectoryId         = this.GetTaskDirectoryId(sourceLineNumbers, "WixSupportTasksRoot", componentId);
            var supportTasksDirectoryIdentifier = new Identifier(access, supportTasksDirectoryId);
            var rootDirectoryPath               = String.Format(CultureInfo.InvariantCulture, @"[CommonAppDataFolder]Microsoft\Windows\GameExplorer\{0}\", gameId);

            // create placeholder directories for this game's tasks
            this.ParseHelper.CreateDirectoryTuple(section, sourceLineNumbers, playTasksDirectoryIdentifier, "TARGETDIR", ".", null);
            this.ParseHelper.CreateDirectoryTuple(section, sourceLineNumbers, supportTasksDirectoryIdentifier, "TARGETDIR", ".", null);

            // set the PlayTasks path and schedule it
            section.AddTuple(new CustomActionTuple(sourceLineNumbers, playTasksDirectoryIdentifier)
            {
                ExecutionType = CustomActionExecutionType.Immediate,
                SourceType    = CustomActionSourceType.Property,
                TargetType    = CustomActionTargetType.TextData,
                Source        = playTasksDirectoryId,
                Target        = String.Concat(rootDirectoryPath, "PlayTasks\\"),
            });
            this.ParseHelper.ScheduleActionTuple(section, sourceLineNumbers, access, sequence, playTasksDirectoryId, null, null, "CostFinalize");

            // set the SupportTasks path and schedule it
            section.AddTuple(new CustomActionTuple(sourceLineNumbers, supportTasksDirectoryIdentifier)
            {
                ExecutionType = CustomActionExecutionType.Immediate,
                SourceType    = CustomActionSourceType.Property,
                TargetType    = CustomActionTargetType.TextData,
                Source        = supportTasksDirectoryId,
                Target        = String.Concat(rootDirectoryPath, "SupportTasks\\"),
            });
            this.ParseHelper.ScheduleActionTuple(section, sourceLineNumbers, access, sequence, supportTasksDirectoryId, null, null, "CostFinalize");
        }
Beispiel #3
0
        /// <summary>
        /// Parses a NativeImage element.
        /// </summary>
        /// <param name="element">The element to parse.</param>
        /// <param name="fileId">The file identifier of the parent element.</param>
        private void ParseNativeImageElement(Intermediate intermediate, IntermediateSection section, XElement element, string fileId)
        {
            var        sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
            Identifier id = null;
            string     appBaseDirectory    = null;
            string     assemblyApplication = null;
            int        attributes          = 0x8; // 32bit is on by default
            int        priority            = 3;

            foreach (var attrib in element.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "Id":
                        id = this.ParseHelper.GetAttributeIdentifier(sourceLineNumbers, attrib);
                        break;

                    case "AppBaseDirectory":
                        appBaseDirectory = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);

                        // See if a formatted value is specified.
                        if (-1 == appBaseDirectory.IndexOf("[", StringComparison.Ordinal))
                        {
                            this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.Directory, appBaseDirectory);
                        }
                        break;

                    case "AssemblyApplication":
                        assemblyApplication = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);

                        // See if a formatted value is specified.
                        if (-1 == assemblyApplication.IndexOf("[", StringComparison.Ordinal))
                        {
                            this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.File, assemblyApplication);
                        }
                        break;

                    case "Debug":
                        if (YesNoType.Yes == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            attributes |= 0x1;
                        }
                        break;

                    case "Dependencies":
                        if (YesNoType.No == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            attributes |= 0x2;
                        }
                        break;

                    case "Platform":
                        string platformValue = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);
                        if (0 < platformValue.Length)
                        {
                            switch (platformValue)
                            {
                            case "32bit":
                                // 0x8 is already on by default
                                break;

                            case "64bit":
                                attributes &= ~0x8;
                                attributes |= 0x10;
                                break;

                            case "all":
                                attributes |= 0x10;
                                break;
                            }
                        }
                        break;

                    case "Priority":
                        priority = this.ParseHelper.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, 3);
                        break;

                    case "Profile":
                        if (YesNoType.Yes == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            attributes |= 0x4;
                        }
                        break;

                    default:
                        this.ParseHelper.UnexpectedAttribute(element, attrib);
                        break;
                    }
                }
                else
                {
                    this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib);
                }
            }

            if (null == id)
            {
                id = this.ParseHelper.CreateIdentifier("nni", fileId);
            }

            this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element);

            this.ParseHelper.CreateCustomActionReference(sourceLineNumbers, section, "NetFxScheduleNativeImage", this.Context.Platform, CustomActionPlatforms.X86);

            if (!this.Messaging.EncounteredError)
            {
                section.AddTuple(new NetFxNativeImageTuple(sourceLineNumbers, id)
                {
                    FileRef                     = fileId,
                    Priority                    = priority,
                    Attributes                  = attributes,
                    ApplicationFileRef          = assemblyApplication,
                    ApplicationBaseDirectoryRef = appBaseDirectory,
                });
            }
        }
        /// <summary>
        /// Parses a Game element for Game Explorer registration.
        /// </summary>
        /// <param name="node">The element to parse.</param>
        /// <param name="fileId">The file identifier of the parent element.</param>
        /// <param name="componentId">The component identifier of the game executable.</param>
        private void ParseGameElement(Intermediate intermediate, IntermediateSection section, XElement node, string fileId, string componentId, string componentDirectoryId)
        {
            var    sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node);
            string id = null;
            var    gdfResourceFileId = fileId;
            var    executableFileId  = fileId;
            int    playTaskOrder     = 0;
            int    supportTaskOrder  = 0;

            foreach (var attrib in node.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "Id":
                        id = this.ParseHelper.GetAttributeGuidValue(sourceLineNumbers, attrib, false);
                        break;

                    case "GdfResourceFile":
                        gdfResourceFileId = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
                        break;

                    case "ExecutableFile":
                        executableFileId = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
                        break;

                    default:
                        this.ParseHelper.UnexpectedAttribute(node, attrib);
                        break;
                    }
                }
                else
                {
                    this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, node, attrib);
                }
            }

            foreach (var child in node.Elements())
            {
                if (this.Namespace == child.Name.Namespace)
                {
                    switch (child.Name.LocalName)
                    {
                    case "PlayTask":
                        if (0 == playTaskOrder && 0 == supportTaskOrder)
                        {
                            this.CreateTaskRootDirectoryCustomActions(section, sourceLineNumbers, id, componentId);
                        }
                        this.ParsePlayTaskElement(intermediate, section, child, id, executableFileId, componentId, playTaskOrder, componentDirectoryId);
                        ++playTaskOrder;
                        break;

                    case "SupportTask":
                        if (0 == playTaskOrder && 0 == supportTaskOrder)
                        {
                            this.CreateTaskRootDirectoryCustomActions(section, sourceLineNumbers, id, componentId);
                        }
                        this.ParseSupportTaskElement(intermediate, section, child, id, componentId, supportTaskOrder);
                        ++supportTaskOrder;
                        break;

                    default:
                        this.ParseHelper.UnexpectedElement(node, child);
                        break;
                    }
                }
                else
                {
                    this.ParseHelper.ParseExtensionElement(this.Context.Extensions, intermediate, section, node, child);
                }
            }

            if (null == id)
            {
                this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id"));
            }

            if (!String.Equals(fileId, gdfResourceFileId, StringComparison.Ordinal))
            {
                this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.File, gdfResourceFileId);
            }

            if (!String.Equals(fileId, executableFileId, StringComparison.Ordinal))
            {
                this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.File, executableFileId);
            }

            if (!this.Messaging.EncounteredError)
            {
                section.AddTuple(new WixGameExplorerTuple(sourceLineNumbers)
                {
                    InstanceId = id,
                    FileRef    = gdfResourceFileId,
                });
                this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "WixSchedGameExplorer");
            }
        }