public static TruRipObject ParseString(string nameString) { TruRipObject no = new TruRipObject(); // 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('(', ')')).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); int i = 0; if (d.Length > i) { no.Name = d[i].Trim(); i++; } // might be year - but might also be part of title if (d.Length > i) { if (d[i].Length > 3) { // is it a year? char firstChar = d[i][0]; bool digit = char.IsDigit(firstChar); if (digit == true) { no.Year = d[1].Substring(0, 4); // take only the year (first 4 characters) } else { i++; firstChar = d[i][0]; digit = char.IsDigit(firstChar); if (digit == true) { no.Year = d[i].Substring(0, 4); // take only the year (first 4 characters) } } } } i++; if (d.Length > i) { no.Publisher = d[i].Trim(); } i++; if (d.Length > i) { // 4th array element is the Country no.Country = d[i].Trim(); if (no.Copyright == null) { no.Copyright = "Commercial"; } if (no.DevelopmentStatus == null) { no.DevelopmentStatus = "Release"; } if (no.Language == null) { no.Language = no.Country; } if (no.Language == "EU") { no.Language = "En"; } } // 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); }
public static List <TruRipObject> Parse(string dat, int systemId) { List <TruRipObject> list = new List <TruRipObject>(); // 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.Element("description"); TruRipObject no = StringConverterTruRip.ParseString(nameString); no.SystemId = systemId; // no.Description = (string)element.Element("description"); // laguage XElement tr = element.Element("trurip"); string lang = (string)tr.Element("language"); if (lang == null || lang == "" || lang == " ") { // do nothing } else { no.Language = lang; } IEnumerable <XElement> roms = element.Elements("rom"); foreach (XElement rom in roms) { string rName = (string)rom.Attribute("name"); if (rName.EndsWith(".pdf") || rName.EndsWith(".tiff") || rName.EndsWith(".tif") || rName.EndsWith(".jpg") || rName.EndsWith(".png")) { continue; } TruRipObject n = new TruRipObject { 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 = rName.Replace(@"Media (CD-ROM)\", "").Replace(@"Media (ROM)\", ""), SystemId = no.SystemId, OtherFlags = no.OtherFlags, Publisher = no.Publisher, Description = no.Description, Year = no.Year }; list.Add(n); } } return(list); }