//We are trying to split name and country static Pair tryGetNameAndCountry(string partname, DemoNames names) { var country = ""; if (names != null && (partname == names.dfName || partname == names.uName || partname == names.oName)) { //name can contains dots so if username from parameters equals part in brackets, no country here return(new Pair(partname, country)); } int i = partname.LastIndexOf('.'); if (i < 0) { i = partname.LastIndexOf(','); } if (i > 0 && i + 1 < partname.Length) { country = partname.Substring(i + 1, partname.Length - i - 1).Trim(); country = RawInfo.removeColors(country); if (country.Where(c => char.IsNumber(c)).Count() == 0) { return(new Pair(partname.Substring(0, i), country)); } } return(new Pair(partname, "")); }
public string fName = null; //name from the filename public void setNamesByPlayerInfo(Dictionary <string, string> playerInfo) { if (playerInfo != null) { dfName = Ext.GetOrNull(playerInfo, "df_name"); uName = normalizeName(RawInfo.removeColors(Ext.GetOrNull(playerInfo, "name"))); } }
public void setConsoleName(string onlineName, bool isOnline) { if (isOnline) { oName = normalizeName(RawInfo.removeColors(onlineName)); } else { cName = normalizeName(RawInfo.removeColors(onlineName)); } }
//Normalization of demo filenames in case they broken by discord or net static string getNormalizedFileName(FileInfo file) { string filename = file.Name; //rm_n2%5Bmdf.vq3%5D00.33.984%28h%40des.CountryHere%29.dm_68 if (filename.Contains("%")) { filename = Uri.UnescapeDataString(filename); } string filenameNoExt = filename.Substring(0, filename.Length - file.Extension.Length); if (filenameNoExt.ToLowerInvariant().Contains(" — копия")) { filenameNoExt = Regex.Replace(filenameNoExt, "( — [к|К]опия( \\(\\d+\\))?)+", ""); } if (filenameNoExt.ToLowerInvariant().Contains(" — copy")) { filenameNoExt = Regex.Replace(filenameNoExt, "( — [c|C]opy( \\(\\d+\\))?)+", ""); } if (filenameNoExt.Contains("^")) { filenameNoExt = RawInfo.removeColors(filenameNoExt); } Match match; if (!Ext.ContainsAny(filenameNoExt, "(", ")")) { if (Ext.CountOf(filenameNoExt, '_') >= 2) { //tamb10_df.vq3_00.11.304_nL_HaZarD.Russia_ if (Ext.CountOf(filenameNoExt, '_') >= 4) { match = Regex.Match(filenameNoExt, "([.][vV][qQ][3]|[.][cC][pP][mM]).*[_](\\d+[.]\\d{2}[.]\\d{3}|\\d{1,2}[.]\\d{3})"); if (match.Success && match.Groups.Count == 3) { try { //group 0 = .vq3_00.11.304 //group 1 = .vq3 //group 2 = 00.11.304 var indexBracket1 = filenameNoExt.Substring(0, match.Index).LastIndexOf('_'); var indexBracket2 = match.Groups[2].Index - 1; var indexBracket3 = match.Groups[2].Index + match.Groups[2].Length; var indexBracket4 = filenameNoExt.Length - 1; var chars = filenameNoExt.ToCharArray(); chars[indexBracket1] = '['; chars[indexBracket2] = ']'; chars[indexBracket3] = '('; chars[indexBracket4] = ')'; return(new string(chars) + file.Extension.ToLowerInvariant()); } catch (Exception ex) { } } } //runmikrob-4[df.vq3]00.14.488_JL.Ua_.dm_68 match = Regex.Match(filenameNoExt, "^.+[\\[].+[\\]](\\d+[.]\\d{2}[.]\\d{3}|\\d{1,2}[.]\\d{3})[_].+[_]$"); if (match.Success) { //group 0 = runmikrob-4[df.vq3]00.14.488_JL.Ua_ //group 1 = 00.14.488 var indexBracket1 = match.Groups[1].Index + match.Groups[1].Length; var indexBracket2 = filenameNoExt.Length - 1; var chars = filenameNoExt.ToCharArray(); chars[indexBracket1] = '('; chars[indexBracket2] = ')'; return(new string(chars) + file.Extension.ToLowerInvariant()); } } //dfcomp009_3.792_VipeR_Russia.dm_68 //dmp02a_jinx_13.880_t0t3r_germany.dm_68 //fdcj2_3.408_[kzii]f_china.dm_66 if (Ext.CountOf(filenameNoExt, '_') >= 3) { match = Regex.Match(filenameNoExt, ".*[_](\\d+[.]\\d{2}[.]\\d{3}|\\d{1,2}[.]\\d{3})[_]"); if (match.Success && match.Groups.Count == 2) { try { //group 0 = dfcomp009_3.792_ //group 1 = 3.792 var mapnametime = match.Groups[0].Value.Substring(0, match.Groups[0].Value.Length - 1); var playerCountry = filenameNoExt.Substring(match.Groups[0].Length); var split = playerCountry.LastIndexOf('_'); if (split > 0) { var pa = playerCountry.ToCharArray(); pa[split] = '.'; playerCountry = new string(pa); } return(mapnametime + "(" + playerCountry + ")" + file.Extension.ToLowerInvariant()); } catch (Exception ex) { } } } //r7-falkydf.cpm00.09.960xas.China.dm_68 int index = Math.Max(filenameNoExt.IndexOf(".cpm"), filenameNoExt.IndexOf(".vq3")); if (index > 0) { try { int i1 = filenameNoExt[index - 3] == 'm' ? index - 3 : index - 2; int i2 = filenameNoExt[index + 4] == '.' ? index + 6 : index + 4; int i3 = i2 + 9; string mapname = filenameNoExt.Substring(0, i1); string physic = filenameNoExt.Substring(i1, i2 - i1); string time = filenameNoExt.Substring(i2, i3 - i2); string name = filenameNoExt.Substring(i3); if (isDigits(time[0], time[1], time[3], time[4], time[7], time[8])) { return(string.Format("{0}[{1}]{2}({3}){4}", mapname, physic, time, name, file.Extension)); } } catch (Exception ex) { } } } //DraeliPowa1-[VQ3]-{InT33!Stormer}-{01.09.560}-[Russia].dm_68 match = Regex.Match(filenameNoExt, "^.*-[[].{3,}]-{(.*)}-{(\\d+[.]\\d{2}[.]\\d{3}|\\d{1,2}[.]\\d{3})}-[[](.*)[]]$"); if (match.Success && match.Groups.Count == 4) { //group 0 = DraeliPowa1-[VQ3]-{InT33!Stormer}-{01.09.560}-[Russia] //group 1 = InT33!Stormer //group 2 = 01.09.560 //group 3 = Russia var p1 = filenameNoExt.Substring(0, match.Groups[1].Index - 2); return(p1 + match.Groups[2].Value + "(" + match.Groups[1].Value + "." + match.Groups[3].Value + ")" + file.Extension.ToLowerInvariant()); } return(filename); }
public void setOnlineName(string onlineName) { oName = normalizeName(RawInfo.removeColors(onlineName)); }