public void read_dates(string file, ref int lock_day, ref Dictionary <int, int> allready_passed_dates) { try { XmlDocument doc = new XmlDocument(); doc.Load(file); XmlNode game_xn = doc.SelectSingleNode("game"); XML_Element lock_xe = new XML_Element((XmlElement)game_xn.SelectSingleNode("lock_date")); int lock_date = lock_xe.f_int("date"); XML_Element used_day_xe = new XML_Element((XmlElement)game_xn.SelectSingleNode("used_date")); List <int> used_days = used_day_xe.f_int_vector("dates"); if (lock_day == 0) { lock_day = lock_date; } lock_day = lock_day < lock_date ? lock_day : lock_date; for (int i = 0; i < used_days.Count(); i++) { allready_passed_dates[used_days[i]] = used_days[i]; } } catch {// } }
public void save_xml() {// 重新保存数据文件 XmlDocument doc = new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", null); doc.AppendChild(dec); //创建一个根节点(一级) XmlElement root = doc.CreateElement("game"); doc.AppendChild(root); //创建节点(二级) XML_Element lock_node_xe = new XML_Element(doc.CreateElement("lock_date")); XML_Element day_node_xe = new XML_Element(doc.CreateElement("used_date")); List <int> days = new List <int>(); foreach (int key in g_allready_passed_dates.Keys) { days.Add(key); } lock_node_xe.SetAttribute("date", g_lock_date); day_node_xe.SetAttribute("dates", days); root.AppendChild(lock_node_xe.m_xe); root.AppendChild(day_node_xe.m_xe); for (int i = 0; i < g_lock_files.Count(); i++) { doc.Save(g_lock_files[i]); } }
public bool test_leagle_file(string file) { bool file_exist = false; int today = get_day_str(0); XmlDocument doc = new XmlDocument(); try { doc.Load(file); file_exist = true; //print("------------------file ok"); } catch {// 不存在就创建一个 XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", null); doc.AppendChild(dec); //创建一个根节点(一级) XmlElement root = doc.CreateElement("game"); doc.AppendChild(root); //创建节点(二级) XmlElement lock_node = doc.CreateElement("lock_date"); XmlElement day_node = doc.CreateElement("used_date"); lock_node.SetAttribute("date", get_day_str(-10).ToString()); day_node.SetAttribute("dates", get_day_str(0).ToString()); root.AppendChild(lock_node); root.AppendChild(day_node); // 如果文件夹不存在 创建文件夹 Directory.CreateDirectory(file.Substring(0, file.LastIndexOf('/') + 1)); doc.Save(file); file_exist = false; //print("------------------file error and create a new one"); } XmlNode game_xn = doc.SelectSingleNode("game"); XML_Element lock_xe = new XML_Element((XmlElement)game_xn.SelectSingleNode("lock_date")); int lock_date = lock_xe.f_int("date"); XML_Element used_day_xe = new XML_Element((XmlElement)game_xn.SelectSingleNode("used_date")); List <int> used_days = used_day_xe.f_int_vector("dates"); bool today_is_leagle = true; for (int i = 0; i < used_days.Count(); i++) { if (today < used_days[i]) {// 这个日期比 当前日期要大 说明甲方改系统时间了 today_is_leagle = false; } } if (today < lock_date) { //print("------------------1:today<锁码日期, "); //return true; } if (today_is_leagle == true) { //print("------------------ 2:today的日期是没有修改过的 "); //return true; } if (file_exist == true) { //print("------------------ 3:文件是存在的"); //return true; } // true 的条件 1:today小于锁码日期, 2:today的日期是没有修改过的 3:文件是存在的 if (today < lock_date && today_is_leagle == true && file_exist == true) { //print("------------------1:today<锁码日期, 2:today的日期是没有修改过的 3:文件是存在的"); return(true); } else { //print("------------------ error"); return(false); } }
private XML_Element ReadElement(XmlReader reader,short version,string element_name = "") { XML_Element element = new XML_Element(); //reader.Read(); XmlReaderRead(reader); if (reader.ReadState == ReadState.EndOfFile) return null; if (reader.Name != element_name && element_name != "") { throw new NotImplementedException(); } element.Name = reader.Name; for (int i = 0;i<reader.AttributeCount; i++) { reader.MoveToAttribute(i); element.Attributes.Add(reader.Name, reader.Value); if (reader.Name == "id") element.guid = reader.Value; } if (element.Name == "Update") { element.IsForwardRef = true; element.fields = new List<XML_Element.Field_Value>(); int cnt = int.Parse(element.GetAttibute("ref_count")); for (int i = 0; i < cnt; i++) { XML_Element xelm = ReadElement(reader,version); element.fields.Add(new XML_Element.Field_Value { Field = xelm.GetAttibute("field"), Value = xelm.GetAttibute("value") }); } //reader.Read(); XmlReaderRead(reader); } //VersionUpdate_XmlElement_level(element,version); UpdateOnLoad.UpdateBeforeLoading(element, version); return element; }