/// <summary>
        /// Unparses the given <see cref="IOptionTypeResolver"/>.
        /// </summary>
        /// <remarks>
        /// This method can be overidden to provide game-specific or newer-version unparsing.
        /// </remarks>
        /// <param name="p_otrOptionTypeResolver">The <see cref="IOptionTypeResolver"/> for which to generate XML.</param>
        /// <returns>The XML representation of the given <see cref="IOptionTypeResolver"/>.</returns>
        protected override XElement UnparseOptionTypeResolver(IOptionTypeResolver p_otrOptionTypeResolver)
        {
            XElement xelTypeDescriptor = new XElement("typeDescriptor");

            if (p_otrOptionTypeResolver is StaticOptionTypeResolver)
            {
                XElement xelPluginType = new XElement("type",
                                                      new XAttribute("name", UnparseOptionType(((StaticOptionTypeResolver)p_otrOptionTypeResolver).Type)));
                xelTypeDescriptor.Add(xelPluginType);
            }
            else if (p_otrOptionTypeResolver is ConditionalOptionTypeResolver)
            {
                XElement xelPluginType = new XElement("dependencyType");
                xelTypeDescriptor.Add(xelPluginType);
                XElement xelDefaultType = new XElement("defaultType",
                                                       new XAttribute("name", UnparseOptionType(((ConditionalOptionTypeResolver)p_otrOptionTypeResolver).DefaultType)));
                xelPluginType.Add(xelDefaultType);
                XElement xelPatterns = new XElement("patterns");
                xelPluginType.Add(xelPatterns);
                foreach (ConditionalOptionTypeResolver.ConditionalTypePattern ctpPattern in ((ConditionalOptionTypeResolver)p_otrOptionTypeResolver).ConditionalTypePatterns)
                {
                    xelPatterns.Add(UnparseConditionalTypePattern(ctpPattern));
                }
            }
            else
            {
                throw new UnsupportedScriptFeatureException("Unsupported Option Type Resolver: " + p_otrOptionTypeResolver.GetType().FullName);
            }
            return(xelTypeDescriptor);
        }
示例#2
0
 /// <summary>
 /// A simple constructor that initializes the values of the object.
 /// </summary>
 /// <param name="p_strName">The name of the option.</param>
 /// <param name="p_strDesc">The description of the option.</param>
 /// <param name="p_imgImage">The path to the option image.</param>
 /// <param name="p_ptpType">The <see cref="OptionType"/> of the option.</param>
 public Option(string p_strName, string p_strDesc, string p_strImagePath, IOptionTypeResolver p_ptpType)
 {
     m_strName         = p_strName;
     m_lstFiles        = new List <InstallableFile>();
     m_lstFlags        = new List <ConditionalFlag>();
     m_otrTypeResolver = p_ptpType ?? new StaticOptionTypeResolver(OptionType.NotUsable);
     m_strDesc         = p_strDesc;
     m_strImagePath    = p_strImagePath;
 }
示例#3
0
        /// <summary>
        /// Reads a option's information from the script file.
        /// </summary>
        /// <param name="p_xelOption">The script file node corresponding to the option to read.</param>
        /// <returns>The option information.</returns>
        protected override Option ParseOption(XElement p_xelOption)
        {
            string strName = p_xelOption.Attribute("name").Value;
            string strDesc = p_xelOption.Element("description").Value.Trim();
            IOptionTypeResolver iptType           = null;
            XElement            xelTypeDescriptor = p_xelOption.Element("typeDescriptor").Elements().First();

            switch (xelTypeDescriptor.Name.LocalName)
            {
            case "type":
                iptType = new StaticOptionTypeResolver((OptionType)Enum.Parse(typeof(OptionType), xelTypeDescriptor.Attribute("name").Value));
                break;

            case "dependencyType":
                OptionType ptpDefaultType = (OptionType)Enum.Parse(typeof(OptionType), xelTypeDescriptor.Element("defaultType").Attribute("name").Value);
                iptType = new ConditionalOptionTypeResolver(ptpDefaultType);
                ConditionalOptionTypeResolver cotConditionalType = (ConditionalOptionTypeResolver)iptType;

                IEnumerable <XElement> xeePatterns = xelTypeDescriptor.XPathSelectElements("patterns/*");
                foreach (XElement xelPattern in xeePatterns)
                {
                    OptionType ptpType      = (OptionType)Enum.Parse(typeof(OptionType), xelPattern.Element("type").Attribute("name").Value);
                    ICondition cpcCondition = LoadCondition(xelPattern.Element("dependencies"));
                    cotConditionalType.AddPattern(ptpType, cpcCondition);
                }
                break;

            default:
                throw new ParserException("Invalid option type descriptor node: " + xelTypeDescriptor.Name + ". At this point the config file has been validated against the schema, so there's something wrong with the parser.");
            }
            XElement xelImage         = p_xelOption.Element("image");
            string   strImageFilePath = null;

            if (xelImage != null)
            {
                strImageFilePath = xelImage.Attribute("path").Value;
            }
            Option optOption = new Option(strName, strDesc, strImageFilePath, iptType);

            IEnumerable <XElement> xeeOptionFiles = p_xelOption.XPathSelectElements("files/*");

            optOption.Files.AddRange(ReadFileInfo(xeeOptionFiles));

            IEnumerable <XElement> xeePluginFlags = p_xelOption.XPathSelectElements("conditionFlags/*");

            optOption.Flags.AddRange(ReadFlagInfo(xeePluginFlags));

            return(optOption);
        }
		/// <summary>
		/// Unparses the given <see cref="IOptionTypeResolver"/>.
		/// </summary>
		/// <remarks>
		/// This method can be overidden to provide game-specific or newer-version unparsing.
		/// </remarks>
		/// <param name="p_otrOptionTypeResolver">The <see cref="IOptionTypeResolver"/> for which to generate XML.</param>
		/// <returns>The XML representation of the given <see cref="IOptionTypeResolver"/>.</returns>
		protected virtual XElement UnparseOptionTypeResolver(IOptionTypeResolver p_otrOptionTypeResolver)
		{
			XElement xelTypeDescriptor = new XElement("typeDescriptor");
			if (p_otrOptionTypeResolver is StaticOptionTypeResolver)
			{
				XElement xelPluginType = new XElement("type",
														new XAttribute("name", UnparseOptionType(((StaticOptionTypeResolver)p_otrOptionTypeResolver).Type)));
				xelTypeDescriptor.Add(xelPluginType);
			}
			else if (p_otrOptionTypeResolver is ConditionalOptionTypeResolver)
			{
				XElement xelPluginType = new XElement("dependancyType");
				xelTypeDescriptor.Add(xelPluginType);
				XElement xelDefaultType =new XElement("defaultType",
														new XAttribute("name", UnparseOptionType(((ConditionalOptionTypeResolver)p_otrOptionTypeResolver).DefaultType)));
				xelPluginType.Add(xelDefaultType);
				XElement xelPatterns = new XElement("patterns");
				xelPluginType.Add(xelPatterns);
				foreach (ConditionalOptionTypeResolver.ConditionalTypePattern ctpPattern in ((ConditionalOptionTypeResolver)p_otrOptionTypeResolver).ConditionalTypePatterns)
					xelPatterns.Add(UnparseConditionalTypePattern(ctpPattern));
			}
			else
				throw new UnsupportedScriptFeatureException("Unsupported Option Type Resolver: " + p_otrOptionTypeResolver.GetType().FullName);
			return xelTypeDescriptor;
		}
示例#5
0
		/// <summary>
		/// A simple constructor that initializes the values of the object.
		/// </summary>
		/// <param name="p_strName">The name of the option.</param>
		/// <param name="p_strDesc">The description of the option.</param>
		/// <param name="p_imgImage">The path to the option image.</param>
		/// <param name="p_ptpType">The <see cref="OptionType"/> of the option.</param>
		public Option(string p_strName, string p_strDesc, string p_strImagePath, IOptionTypeResolver p_ptpType)
		{
			m_strName = p_strName;
			m_lstFiles = new List<InstallableFile>();
			m_lstFlags = new List<ConditionalFlag>();
			m_otrTypeResolver = p_ptpType ?? new StaticOptionTypeResolver(OptionType.NotUsable);
			m_strDesc = p_strDesc;
			m_strImagePath = p_strImagePath;
		}