//Trying to get time from part of demo filename. static TimeSpan?tryGetTimeFromBrackets(string partname) { var parts = partname.Split("-".ToArray()); if (parts.Length < 2 || parts.Length > 3) { parts = partname.Split(".".ToArray()); if (parts.Length < 2 || parts.Length > 3) { return(null); } } foreach (string part in parts) { if (part.Length == 0) { return(null); } foreach (char c in part) { if (!char.IsDigit(c)) { return(null); } } } return(RawInfo.getTimeSpan(partname)); }
//Get the details of the demo from the file name public static Demo GetDemoFromFile(FileInfo file) { Demo demo = new Demo(); demo.file = file; var filename = file.Name; demo.recordTime = demo.file.CreationTime; int index = Math.Max(filename.IndexOf(".cpm"), filename.IndexOf(".vq3")); if (index <= 0) { demo.hasError = true; return(demo); } int firstSquareIndex = filename.Substring(0, index).LastIndexOf('['); if (firstSquareIndex <= 0) { demo.hasError = true; return(demo); } string mapname = filename.Substring(0, firstSquareIndex); string others = filename.Substring(firstSquareIndex); var sub = others.Split("[]()".ToArray()); if (sub.Length >= 4) { //Map demo.mapName = mapname; //Physic demo.modphysic = sub[1]; if (demo.modphysic.Length < 3) { demo.hasError = true; } //Time demo.timeString = sub[2]; var times = demo.timeString.Split('-', '.'); try { demo.time = RawInfo.getTimeSpan(demo.timeString); } catch (Exception) { demo.hasError = true; } if (demo.time.TotalMilliseconds <= 0) { demo.hasError = true; } //Name + country var countryName = sub[3]; var countryNameParsed = tryGetNameAndCountry(countryName, null); demo.playerName = countryNameParsed.Key; demo.country = countryNameParsed.Value; var c1 = filename.LastIndexOf(')'); var b1 = filename.LastIndexOf('{'); var b2 = filename.LastIndexOf('}'); if (b2 > b1 && b1 > c1 && c1 > 0) { var vstr = filename.Substring(b1 + 1, b2 - b1 - 1); var v = vstr.Split('='); if (v.Length > 1) { demo.validDict = new Dictionary <string, string>(); demo.validDict.Add(v[0], v[1]); } } } else { demo.hasError = true; } return(demo); }
//Get the details of the demo from the file name public static Demo GetDemoFromFile(FileInfo file) { Demo demo = new Demo(); demo.file = file; var filename = file.Name; demo.recordTime = demo.file.CreationTime; string fileNameNoExt = filename.Substring(0, filename.Length - file.Extension.Length); var match = Regex.Match(fileNameNoExt, "(.+)\\[(.+)\\](\\d+\\.\\d{2}\\.\\d{3})\\((.+)\\)(\\{(.+)\\})?(\\[(.+)\\])?"); if (match.Success && match.Groups.Count >= 5) { //Map demo.mapName = match.Groups[1].Value; //Physic demo.modphysic = match.Groups[2].Value; var physic = demo.modphysic.ToLowerInvariant(); int index = Math.Max(physic.IndexOf(".cpm"), physic.IndexOf(".vq3")); if (index <= 0) { demo.hasError = true; } if (physic.Length < 3) { demo.hasError = true; } if (physic.Contains(".tr")) { demo.hasTr = true; } //Time demo.timeString = match.Groups[3].Value; try { demo.time = RawInfo.getTimeSpan(demo.timeString); } catch (Exception) { demo.hasError = true; } if (demo.time.TotalMilliseconds <= 0) { demo.hasError = true; } //Name + country var countryName = match.Groups[4].Value; var countryNameParsed = tryGetNameAndCountry(countryName, null); demo.playerName = countryNameParsed.Key; demo.country = countryNameParsed.Value; //Validity if (match.Groups.Count >= 7) { var validString = match.Groups[6].Value; var v = validString.Split('='); if (v.Length > 1) { demo.validDict = new Dictionary <string, string>(); demo.validDict.Add(v[0], v[1]); } } //tas check if (filename.ToLowerInvariant().Contains("tool_assisted=true")) { demo.isTas = true; } //userId if (match.Groups.Count >= 9) { var idString = match.Groups[8].Value; if (!string.IsNullOrEmpty(idString)) { if (isDigits(idString.ToCharArray())) { long id = -1; long.TryParse(idString, out id); if (id >= 0) { demo.userId = id; } } else { if (idString == "spect") { demo.isSpectator = true; } } } } } else { demo.hasError = true; } return(demo); }