/// <seealso cref="Parser.GetHeaderInfo()" /> public override HeaderInfo GetHeaderInfo() { var xndTitle = XmlConfig.SelectSingleNode("/config/moduleName"); var strTitle = xndTitle.InnerText; var clrColour = Color.FromArgb( (Int32)(UInt32.Parse(xndTitle.Attributes["colour"].Value, NumberStyles.HexNumber, null) | 0xff000000)); var tpsPosition = (TextPosition)Enum.Parse(typeof(TextPosition), xndTitle.Attributes["position"].Value); var xndImage = XmlConfig.SelectSingleNode("/config/moduleImage"); if (xndImage != null) { var strImagePath = xndImage.Attributes["path"].Value; var imgImage = String.IsNullOrEmpty(strImagePath) ? Fomod.GetScreenshotImage() : new Bitmap(Fomod.GetImage(strImagePath)); var booShowImage = Boolean.Parse(xndImage.Attributes["showImage"].Value) && (imgImage != null); var booShowFade = Boolean.Parse(xndImage.Attributes["showFade"].Value); var intHeight = Int32.Parse(xndImage.Attributes["height"].Value); if ((intHeight == -1) && booShowImage) { intHeight = 75; } return(new HeaderInfo(strTitle, clrColour, tpsPosition, imgImage, booShowImage, booShowFade, intHeight)); } var imgScreenshot = Fomod.GetScreenshotImage(); return(new HeaderInfo(strTitle, clrColour, tpsPosition, imgScreenshot, imgScreenshot != null, true, (imgScreenshot != null) ? 75 : -1)); }
/// <summary> /// Reads a plugin's information from the configuration file. /// </summary> /// <param name="p_xndPlugin">The configuration file node corresponding to the plugin to read.</param> /// <returns>The plugin information.</returns> protected override PluginInfo parsePlugin(XmlNode p_xndPlugin) { var strName = p_xndPlugin.Attributes["name"].InnerText; var strDesc = p_xndPlugin.SelectSingleNode("description").InnerText.Trim(); IPluginType iptType; var xndTypeDescriptor = p_xndPlugin.SelectSingleNode("typeDescriptor").FirstChild; switch (xndTypeDescriptor.Name) { case "type": iptType = new StaticPluginType( (PluginType)Enum.Parse(typeof(PluginType), xndTypeDescriptor.Attributes["name"].InnerText)); break; case "dependencyType": var ptpDefaultType = (PluginType) Enum.Parse(typeof(PluginType), xndTypeDescriptor.SelectSingleNode("defaultType").Attributes["name"].InnerText); iptType = new DependencyPluginType(ptpDefaultType); var dptDependentType = (DependencyPluginType)iptType; var xnlPatterns = xndTypeDescriptor.SelectNodes("patterns/*"); foreach (XmlNode xndPattern in xnlPatterns) { var ptpType = (PluginType) Enum.Parse(typeof(PluginType), xndPattern.SelectSingleNode("type").Attributes["name"].InnerText); var cdpDependency = loadDependency(xndPattern.SelectSingleNode("dependencies")); dptDependentType.AddPattern(ptpType, cdpDependency); } break; default: throw new ParserException("Invalid plaug type descriptor node: " + xndTypeDescriptor.Name + ". At this point the config file has been validated against the schema, so there's something wrong with the parser."); } var xndImage = p_xndPlugin.SelectSingleNode("image"); Image imgImage = null; if (xndImage != null) { var strImageFilePath = xndImage.Attributes["path"].InnerText; imgImage = Fomod.GetImage(strImageFilePath); } var pifPlugin = new PluginInfo(strName, strDesc, imgImage, iptType); var xnlPluginFiles = p_xndPlugin.SelectNodes("files/*"); pifPlugin.Files.AddRange(readFileInfo(xnlPluginFiles)); var xnlPluginFlags = p_xndPlugin.SelectNodes("conditionFlags/*"); pifPlugin.Flags.AddRange(readFlagInfo(xnlPluginFlags)); return(pifPlugin); }
/// <summary> /// Reads a plugin's information from the configuration file. /// </summary> /// <param name="p_xndPlugin">The configuration file node corresponding to the plugin to read.</param> /// <returns>The plugin information.</returns> protected virtual PluginInfo parsePlugin(XmlNode p_xndPlugin) { var strName = p_xndPlugin.Attributes["name"].InnerText; var strDesc = p_xndPlugin.SelectSingleNode("description").InnerText.Trim(); IPluginType iptType = null; var xndTypeDescriptor = p_xndPlugin.SelectSingleNode("typeDescriptor").FirstChild; switch (xndTypeDescriptor.Name) { case "type": iptType = new StaticPluginType( (PluginType)Enum.Parse(typeof(PluginType), xndTypeDescriptor.Attributes["name"].InnerText)); break; case "dependancyType": var ptpDefaultType = (PluginType) Enum.Parse(typeof(PluginType), xndTypeDescriptor.SelectSingleNode("defaultType").Attributes["name"].InnerText); iptType = new DependencyPluginType(ptpDefaultType); var dptDependentType = (DependencyPluginType)iptType; var xnlPatterns = xndTypeDescriptor.SelectNodes("patterns/*"); foreach (XmlNode xndPattern in xnlPatterns) { var ptpType = (PluginType) Enum.Parse(typeof(PluginType), xndPattern.SelectSingleNode("type").Attributes["name"].InnerText); var cdpDependency = loadDependency(xndPattern.SelectSingleNode("dependancies")); dptDependentType.AddPattern(ptpType, cdpDependency); } break; } var xndImage = p_xndPlugin.SelectSingleNode("image"); Image imgImage = null; if (xndImage != null) { var strImageFilePath = xndImage.Attributes["path"].InnerText; imgImage = Fomod.GetImage(strImageFilePath); } var pifPlugin = new PluginInfo(strName, strDesc, imgImage, iptType); var xnlPluginFiles = p_xndPlugin.SelectNodes("files/*"); pifPlugin.Files.AddRange(readFileInfo(xnlPluginFiles)); return(pifPlugin); }
/// <summary> /// Displays a selection form to the user. /// </summary> /// <remarks> /// The items, previews, and descriptions are repectively ordered. In other words, /// the i-th item in <paramref name="p_strItems" /> uses the i-th preview in /// <paramref name="p_strPreviews" /> and the i-th description in <paramref name="p_strDescriptions" />. /// Similarly, the idices return as results correspond to the indices of the items in /// <paramref name="p_strItems" />. /// </remarks> /// <param name="p_strItems">The items from which to select.</param> /// <param name="p_strPreviews">The preview image file names for the items.</param> /// <param name="p_strDescriptions">The descriptions of the items.</param> /// <param name="p_strTitle">The title of the selection form.</param> /// <param name="p_booSelectMany">Whether more than one item can be selected.</param> /// <returns>The indices of the selected items.</returns> public int[] Select(string[] p_strItems, string[] p_strPreviews, string[] p_strDescriptions, string p_strTitle, bool p_booSelectMany) { PermissionsManager.CurrentPermissions.Assert(); Image[] imgPreviews = null; if (p_strPreviews != null) { imgPreviews = new Image[p_strPreviews.Length]; for (var i = 0; i < p_strPreviews.Length; i++) { if (p_strPreviews[i] == null) { continue; } try { imgPreviews[i] = Fomod.GetImage(p_strPreviews[i]); } catch (Exception e) { if (!((e is FileNotFoundException) || (e is DecompressionException))) { throw e; } } } //for now I don't think the user needs to be able to detect this. // i don't think it is severe enough to be an exception, as it may be // intentional, and if it is a bug it should be readily apparent // during testing. /*if (intMissingImages > 0) * { * m_strLastError = "There were " + intMissingImages + " filenames specified for preview images which could not be loaded"; * }*/ } var sfmSelectForm = new SelectForm(p_strItems, p_booSelectMany, imgPreviews, p_strDescriptions); sfmSelectForm.Text = p_strTitle; sfmSelectForm.ShowDialog(); var intResults = new int[sfmSelectForm.SelectedIndex.Length]; for (var i = 0; i < sfmSelectForm.SelectedIndex.Length; i++) { intResults[i] = sfmSelectForm.SelectedIndex[i]; } return(intResults); }