public static TemplateAboutInfo GetTemplateAboutInfo(string xmlPath) { TemplateAboutInfo templateAboutInfo = new TemplateAboutInfo(); if (!File.Exists(xmlPath + "\\about.xml")) { return(templateAboutInfo); } XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(xmlPath + "\\about.xml"); try { XmlNode xmlNode = xmlDocument.SelectSingleNode("about"); foreach (XmlNode xmlNode2 in xmlNode.ChildNodes) { if (xmlNode2.NodeType != XmlNodeType.Comment && xmlNode2.Name.ToLower() == "template") { templateAboutInfo.name = ((xmlNode2.Attributes["name"] != null) ? xmlNode2.Attributes["name"].Value.ToString() : ""); templateAboutInfo.author = ((xmlNode2.Attributes["author"] != null) ? xmlNode2.Attributes["author"].Value.ToString() : ""); templateAboutInfo.createdate = ((xmlNode2.Attributes["createdate"] != null) ? xmlNode2.Attributes["createdate"].Value.ToString() : ""); templateAboutInfo.ver = ((xmlNode2.Attributes["ver"] != null) ? xmlNode2.Attributes["ver"].Value.ToString() : ""); templateAboutInfo.fordntver = ((xmlNode2.Attributes["fordntver"] != null) ? xmlNode2.Attributes["fordntver"].Value.ToString() : ""); templateAboutInfo.copyright = ((xmlNode2.Attributes["copyright"] != null) ? xmlNode2.Attributes["copyright"].Value.ToString() : ""); templateAboutInfo.width = ((xmlNode2.Attributes["width"] != null) ? xmlNode2.Attributes["width"].Value.ToString() : "600"); } } } catch { templateAboutInfo = new TemplateAboutInfo(); } return(templateAboutInfo); }
public static DataTable GetAllTemplateList(string templatePath) { DirectoryInfo directoryInfo = new DirectoryInfo(templatePath); DataTable allTemplateList = Discuz.Data.Templates.GetAllTemplateList(); allTemplateList.Columns.Add("valid", typeof(Int16)); string text = ","; foreach (DataRow dataRow in allTemplateList.Rows) { TemplateAboutInfo templateAboutInfo = Templates.GetTemplateAboutInfo(templatePath + dataRow["directory"].ToString()); dataRow["valid"] = 1; AdminTemplates.SetTemplateDataRow(dataRow, templateAboutInfo); text = text + dataRow["directory"].ToString() + ","; } int num = TypeConverter.ObjectToInt(Discuz.Data.Templates.GetValidTemplateList().Compute("Max(templateid)", "")) + 1; DirectoryInfo[] directories = directoryInfo.GetDirectories(); for (int i = 0; i < directories.Length; i++) { DirectoryInfo directoryInfo2 = directories[i]; if (directoryInfo2 != null && text.IndexOf("," + directoryInfo2 + ",") < 0) { TemplateAboutInfo templateAboutInfo2 = Templates.GetTemplateAboutInfo(directoryInfo2.FullName); DataRow dataRow2 = allTemplateList.NewRow(); dataRow2["templateid"] = num++; dataRow2["directory"] = directoryInfo2.Name; dataRow2["valid"] = 0; AdminTemplates.SetTemplateDataRow(dataRow2, templateAboutInfo2); allTemplateList.Rows.Add(dataRow2); } } allTemplateList.AcceptChanges(); return(allTemplateList); }
/// <summary> /// 获得所有在模板目录下的模板列表(即:子目录名称) /// </summary> /// <param name="templatePath">模板所在路径</param> /// <example>GetAllTemplateList(Utils.GetMapPath(@"..\..\templates\"))</example> /// <returns>模板列表</returns> public static DataTable GetAllTemplateList(string templatePath) { DirectoryInfo dirInfo = new DirectoryInfo(templatePath); DataTable dt = Data.Templates.GetAllTemplateList(); dt.Columns.Add("valid", Type.GetType("System.Int16")); string directorylist = ","; foreach (DataRow dr in dt.Rows) { TemplateAboutInfo aboutInfo = GetTemplateAboutInfo(templatePath + dr["directory"].ToString()); dr["valid"] = 1;// 是否是前台有效模板 SetTemplateDataRow(dr, aboutInfo); directorylist += dr["directory"].ToString() + ","; } int count = TypeConverter.ObjectToInt(Data.Templates.GetValidTemplateList().Compute("Max(templateid)", "")) + 1; foreach (DirectoryInfo dir in dirInfo.GetDirectories()) { if (dir != null && directorylist.IndexOf("," + dir + ",") < 0) { TemplateAboutInfo aboutInfo = GetTemplateAboutInfo(dir.FullName); DataRow dr = dt.NewRow(); dr["templateid"] = count++; dr["directory"] = dir.Name; // 子目录名 dr["valid"] = 0; // 是否是前台有效模板 SetTemplateDataRow(dr, aboutInfo); dt.Rows.Add(dr); } } dt.AcceptChanges(); return(dt); }
private static void SetTemplateDataRow(DataRow dr, TemplateAboutInfo aboutInfo) { dr["name"] = aboutInfo.name; dr["author"] = aboutInfo.author; dr["createdate"] = aboutInfo.createdate; dr["ver"] = aboutInfo.ver; dr["fordntver"] = aboutInfo.fordntver; dr["copyright"] = aboutInfo.copyright; }
private static void SetTemplateDataRow(DataRow dr, TemplateAboutInfo aboutInfo) { dr["name"] = aboutInfo.name; // 模板名称 dr["author"] = aboutInfo.author; // 作者 dr["createdate"] = aboutInfo.createdate; // 创建日期 dr["ver"] = aboutInfo.ver; // 模板版本 dr["fordntver"] = aboutInfo.fordntver; // 适用的论坛版本 dr["copyright"] = aboutInfo.copyright; // 版权 }
/// <summary> /// 获得所有在模板目录下的模板列表(即:子目录名称) /// </summary> /// <param name="templatePath">模板所在路径</param> /// <example>GetAllTemplateList(Utils.GetMapPath(@"..\..\templates\"))</example> /// <returns>模板列表</returns> public static DataTable GetAllTemplateList(string templatePath) { DataTable dt = Discuz.Data.Templates.GetAllTemplateList(); dt.Columns.Add("valid", Type.GetType("System.Int16")); foreach (DataRow dr in dt.Rows) { dr["valid"] = 1; } DirectoryInfo dirInfo = new DirectoryInfo(templatePath); int count = TypeConverter.ObjectToInt(Data.Templates.GetValidTemplateList().Compute("Max(templateid)", "")) + 1; foreach (DirectoryInfo dir in dirInfo.GetDirectories()) { if (dir != null) { bool itemexist = false; foreach (DataRow dr in dt.Rows) { if (dr["directory"].ToString() == dir.Name) { itemexist = true; break; } } if (!itemexist) { DataRow dr = dt.NewRow(); dr["templateid"] = count.ToString(); dr["directory"] = dir.Name; // 子目录名 dr["valid"] = 0; // 是否是前台有效模板 TemplateAboutInfo aboutInfo = GetTemplateAboutInfo(dir.FullName); dr["name"] = aboutInfo.name; // 模板名称 dr["author"] = aboutInfo.author; // 作者 dr["createdate"] = aboutInfo.createdate; // 创建日期 dr["ver"] = aboutInfo.ver; // 模板版本 dr["fordntver"] = aboutInfo.fordntver; // 适用的论坛版本 dr["copyright"] = aboutInfo.copyright; // 版权 dt.Rows.Add(dr); count++; } } } dt.AcceptChanges(); return(dt); }
/// <summary> /// 从模板说明文件中获得模板说明信息 /// </summary> /// <param name="xmlPath">模板路径(不包含文件名)</param> /// <returns>模板说明信息</returns> public static TemplateAboutInfo GetTemplateAboutInfo(string xmlPath) { TemplateAboutInfo aboutInfo = new TemplateAboutInfo(); ///存放关于信息的文件 about.xml是否存在,不存在返回空串 if (!System.IO.File.Exists(xmlPath + @"\about.xml")) { return(aboutInfo); } XmlDocument xml = new XmlDocument(); xml.Load(xmlPath + @"\about.xml"); try { XmlNode root = xml.SelectSingleNode("about"); foreach (XmlNode n in root.ChildNodes) { if (n.NodeType != XmlNodeType.Comment && n.Name.ToLower() == "template") { aboutInfo.name = n.Attributes["name"] != null ? n.Attributes["name"].Value.ToString() : ""; aboutInfo.author = n.Attributes["author"] != null ? n.Attributes["author"].Value.ToString() : ""; aboutInfo.createdate = n.Attributes["createdate"] != null ? n.Attributes["createdate"].Value.ToString() : ""; aboutInfo.ver = n.Attributes["ver"] != null ? n.Attributes["ver"].Value.ToString() : ""; aboutInfo.fordntver = n.Attributes["fordntver"] != null ? n.Attributes["fordntver"].Value.ToString() : ""; aboutInfo.copyright = n.Attributes["copyright"] != null ? n.Attributes["copyright"].Value.ToString() : ""; aboutInfo.width = n.Attributes["width"] != null ? n.Attributes["width"].Value.ToString() : "600"; } } } catch { aboutInfo = new TemplateAboutInfo(); } return(aboutInfo); }
/// <summary> /// 从模板说明文件中获得模板说明信息 /// </summary> /// <param name="xmlPath">模板路径(不包含文件名)</param> /// <returns>模板说明信息</returns> public static TemplateAboutInfo GetTemplateAboutInfo(string xmlPath) { TemplateAboutInfo __aboutinfo = new TemplateAboutInfo(); __aboutinfo.name = ""; __aboutinfo.author = ""; __aboutinfo.createdate = ""; __aboutinfo.ver = ""; __aboutinfo.fordntver = ""; __aboutinfo.copyright = ""; ///存放关于信息的文件 about.xml是否存在,不存在返回空串 if (!System.IO.File.Exists(xmlPath + @"\about.xml")) { return(__aboutinfo); } XmlDocument xml = new XmlDocument(); xml.Load(xmlPath + @"\about.xml"); try { XmlNode root = xml.SelectSingleNode("about"); foreach (XmlNode n in root.ChildNodes) { if (n.NodeType != XmlNodeType.Comment && n.Name.ToLower() == "template") { XmlAttribute name = n.Attributes["name"]; XmlAttribute author = n.Attributes["author"]; XmlAttribute createdate = n.Attributes["createdate"]; XmlAttribute ver = n.Attributes["ver"]; XmlAttribute fordntver = n.Attributes["fordntver"]; XmlAttribute copyright = n.Attributes["copyright"]; if (name != null) { __aboutinfo.name = name.Value.ToString(); } if (author != null) { __aboutinfo.author = author.Value.ToString(); } if (createdate != null) { __aboutinfo.createdate = createdate.Value.ToString(); } if (ver != null) { __aboutinfo.ver = ver.Value.ToString(); } if (fordntver != null) { __aboutinfo.fordntver = fordntver.Value.ToString(); } if (copyright != null) { __aboutinfo.copyright = copyright.Value.ToString(); } } } } catch { __aboutinfo = new TemplateAboutInfo(); } return(__aboutinfo); }
/// <summary> /// 获得所有在模板目录下的模板列表(即:子目录名称) /// </summary> /// <param name="templatePath">模板所在路径</param> /// <example>GetAllTemplateList(Utils.GetMapPath(@"..\..\templates\"))</example> /// <returns>模板列表</returns> public static DataTable GetAllTemplateList(string templatePath) { DataTable dt = DatabaseProvider.GetInstance().GetAllTemplateList(templatePath); dt.Columns.Add("valid", Type.GetType("System.Int16")); foreach (DataRow dr in dt.Rows) { dr["valid"] = 1; } DirectoryInfo dirinfo = new DirectoryInfo(templatePath); int count = DatabaseProvider.GetInstance().GetMaxTemplateId() + 1; foreach (DirectoryInfo dir in dirinfo.GetDirectories()) { if (dir != null) { if (dir.FullName.IndexOf(".svn") > 0) { continue; } bool itemexist = false; foreach (DataRow dr in dt.Rows) { if (dr["directory"].ToString() == dir.Name) { itemexist = true; break; } } if (!itemexist) { DataRow dr = dt.NewRow(); // 子目录名 dr["templateid"] = count.ToString(); dr["directory"] = dir.Name; // 是否是前台有效模板 dr["valid"] = 0; TemplateAboutInfo __aboutinfo = GetTemplateAboutInfo(dir.FullName); // 模板名称 dr["name"] = __aboutinfo.name; // 作者 dr["author"] = __aboutinfo.author; // 创建日期 dr["createdate"] = __aboutinfo.createdate; // 模板版本 dr["ver"] = __aboutinfo.ver; // 适用的论坛版本 dr["fordntver"] = __aboutinfo.fordntver; // 版权 dr["copyright"] = __aboutinfo.copyright; dt.Rows.Add(dr); count++; } } } dt.AcceptChanges(); return(dt); }