public static List <NoIntroObject> Parse(string dat, int systemId) { List <NoIntroObject> list = new List <NoIntroObject>(); // replace illegal characters dat = dat.Replace(" & ", " & ").Replace(" and ", " & "); // parse into an xml document XDocument xmlDoc = XDocument.Parse(dat); //var games = xmlDoc.Descendants("game"); // iterate through each game foreach (XElement element in xmlDoc.Root.Elements("game")) { string nameString = (string)element.Attribute("name"); NoIntroObject no = StringConverterNoIntro.ParseString(nameString); no.SystemId = systemId; no.CloneOf = (string)element.Attribute("cloneof"); //no.Description = (string)element.Element("description"); IEnumerable <XElement> roms = element.Elements("rom"); foreach (XElement rom in roms) { NoIntroObject n = new NoIntroObject { Name = no.Name, CloneOf = no.CloneOf, Copyright = no.Copyright, Country = no.Country, CRC = (string)rom.Attribute("crc"), Size = (string)rom.Attribute("size"), MD5 = (string)rom.Attribute("md5"), SHA1 = (string)rom.Attribute("sha1"), DevelopmentStatus = no.DevelopmentStatus, Language = no.Language, RomName = (string)rom.Attribute("name"), SystemId = no.SystemId, OtherFlags = no.OtherFlags, Publisher = no.Publisher, Description = no.Description, Year = no.Year }; list.Add(n); } } return(list); }
public static NoIntroObject ParseString(string nameString) { NoIntroObject no = new NoIntroObject(); // get name without any options (integrating demo flag if available) //no.Name = nameString.Split(new string[] { " ) " }, StringSplitOptions.RemoveEmptyEntries)[0].Trim() + ")"; // remove any unwanted options from string string a = RemoveUnneededOptions(nameString); // process data contained in () string[] d = a.ToString().Split('(', ')'); if (d.Length > 0) { no.Name = d[0].Trim(); } if (d.Length > 1) { if (d[1].Length > 3) { no.Country = d[1].Trim(); } } if (d.Length > 2) { // iterate through remaining array of () data and determine values for (int i = 2; i < d.Length; i++) { string f = d[i].Trim(); // check for language if (IsLanguageFlag(f) == true) { no.Language = f; continue; } // check version if (IsVersion(f) == true) { no.OtherFlags = f; } // check development status if (IsDevelopmenttStatus(f) == true) { no.DevelopmentStatus = f; continue; } // check copyright status if (IsCopyrightStatus(f) == true) { no.Copyright = f; continue; } // Media Type - ignore for now // Media Label - ignore for now } if (no.Copyright == null) { no.Copyright = "Commercial"; } if (no.Copyright == "Unl") { no.Copyright = "Unlicensed"; } if (no.DevelopmentStatus == null) { no.DevelopmentStatus = "Release"; } if (no.Language == null) { no.Language = "en"; } } // process other flags /* * // process dump info flags and other info contained in [] * if (nameString.Contains("[") && nameString.Contains("]")) * { * List<string> e = nameString.ToString().Split('[', ']').ToList(); * if (e.Count > 0) * { * StringBuilder sb = new StringBuilder(); * int count = 0; * foreach (string s in e) * { * if (count == 0 || s == "") * { * count++; * continue; * } * * * sb.Append("["); * sb.Append(s); * sb.Append("]"); * count++; * } * * no.OtherFlags = sb.ToString().Trim(); * } * } */ return(no); }