//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); }
//We get the filled demo from the full raw information pulled from the demo public static Demo GetDemoFromRawInfo(RawInfo raw) { var file = new FileInfo(raw.demoPath); var frConfig = raw.getFriendlyInfo(); Demo demo = new Demo(); demo.rawInfo = raw; //file demo.file = file; if (frConfig.Count == 0 || !frConfig.ContainsKey(RawInfo.keyClient)) { demo.hasError = true; demo.isBroken = true; return(demo); } //config names var names = new DemoNames(); names.setNamesByPlayerInfo(Ext.GetOrNull(frConfig, RawInfo.keyPlayer)); //time from triggers if (raw.fin.HasValue) { demo.time = TimeSpan.FromMilliseconds(raw.fin.Value.Value.time); demo.hasTr = raw.fin.Value.Key > 1; demo.triggerTime = true; } var timestrings = raw.timeStrings; var fastestTimeString = getFastestTimeStringInfo(timestrings, names); if (demo.time.TotalMilliseconds > 0) { var date = timestrings.LastOrDefault(x => x.recordDate != null); demo.recordTime = date?.recordDate; } else { //time from commands if (fastestTimeString != null) { demo.time = fastestTimeString.time; demo.recordTime = fastestTimeString.recordDate; var user = raw.getPlayerInfoByPlayerName(fastestTimeString.oName); if (user != null) { names.setNamesByPlayerInfo(user); } } } if (fastestTimeString != null) { names.setOnlineName(fastestTimeString.oName); } var filename = demo.normalizedFileName; var countryAndName = getNameAndCountry(filename); if (Ext.ContainsAny(countryAndName, tasTriggers)) { demo.isTas = true; foreach (string tasFlag in tasTriggers) { countryAndName = removeSubstr(countryAndName, tasFlag); } } var countryNameParsed = tryGetNameAndCountry(countryAndName, names); //fle name names.setBracketsName(countryNameParsed.Key); //name from the filename demo.playerName = names.chooseNormalName(); //demo has not info about country, so take it from filename demo.country = countryNameParsed.Value; //at least some time (from name of demo) if (demo.time.TotalMilliseconds > 0) { demo.rawTime = true; } else { var demoNameTime = tryGetTimeFromFileName(filename); if (demoNameTime != null) { demo.time = demoNameTime.Value; } } //Map var mapInfo = raw.rawConfig.ContainsKey(Q3Const.Q3_DEMO_CFG_FIELD_MAP) ? raw.rawConfig[Q3Const.Q3_DEMO_CFG_FIELD_MAP] : ""; var mapName = Ext.GetOrNull(frConfig[RawInfo.keyClient], "mapname"); //If in mapInfo the name of the same map is written, then we take the name from there if (mapName.ToLowerInvariant().Equals(mapInfo.ToLowerInvariant())) { demo.mapName = mapInfo; } else { demo.mapName = mapName.ToLowerInvariant(); } //tas var modPhysic = getModPhysic(filename); if (modPhysic != null && Ext.ContainsAny(modPhysic, tasTriggers)) { demo.isTas = true; } //Gametype var gInfo = raw.gameInfo; if (gInfo.isDefrag) { if (!string.IsNullOrEmpty(gInfo.modType)) { demo.modphysic = string.Format("{0}.{1}.{2}", gInfo.gameTypeShort, gInfo.gameplayTypeShort, gInfo.modType); } else { demo.modphysic = string.Format("{0}.{1}", gInfo.gameTypeShort, gInfo.gameplayTypeShort); } } else { demo.modphysic = string.Format("{0}.{1}", gInfo.gameNameShort, gInfo.gameTypeShort); } if (demo.hasTr) { demo.modphysic = string.Format("{0}.{1}", demo.modphysic, "tr"); } if (demo.isTas) { demo.modphysic = string.Format("{0}.{1}", demo.modphysic, "tas"); } //If demo has cheats, write it demo.validDict = checkValidity(demo.time.TotalMilliseconds > 0, demo.rawTime, gInfo); if (demo.triggerTime) { demo.userId = tryGetUserIdFromFileName(file); } 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); }