/// <summary> /// 获取特定Mod信息 /// </summary> /// <param name="name">欲获取Mod的名称</param> /// <param name="shouldHave">应该存在,若为真则产生报错信息</param> /// <returns>返回ModInformation</returns> public ModInformation GetModInformation(string name, bool shouldHave) { try { XmlDocument xml = new XmlDocument(); xml.Load(PathOperation.GetModsIndexPath()); string time = xml.SelectSingleNode("mods/mod_" + name + "/time").InnerText; string size = xml.SelectSingleNode("mods/mod_" + name + "/size").InnerText; List <string> contain = new List <string>(); XmlNodeList fileNodes = xml.SelectNodes("mods/mod_" + name + "/files/file"); foreach (XmlNode node in fileNodes) { contain.Add(node.InnerText); } ModInformation information = new ModInformation(name, time, size, contain); return(information); } catch (Exception e) { if (shouldHave) { ExceptionHandler.ShowError(e, "获取 " + name + " 信息出错"); } return(null); } }
/// <summary> /// 获取全部Mod信息 /// </summary> /// <returns>返回ModInformationList</returns> public List <ModInformation> GetAllModsInformation() { List <ModInformation> list = new List <ModInformation>(); try { foreach (string path in Directory.GetFiles(PathOperation.GetModsStorePath(), "*.mod", SearchOption.TopDirectoryOnly)) { ModInformation information = GetModInformation(Path.GetFileNameWithoutExtension(path), true); if (information != null) { list.Add(information); } } return(list); } catch (Exception e) { ExceptionHandler.ShowError(e, "检索全部Mod信息出错"); return(list); } }