public void Add(HudFile file) { m_FileList.Add(file); }
static HudFile ParseHudFile(string path) { HudFile hf = new HudFile(); string s; if(File.Exists(path)) { StreamReader sr = new StreamReader(path); s = sr.ReadToEnd(); RefLib.CleanUp(ref s,RefLib.cleanupModes.Comments); sr.Close(); } else throw new Exception("Can't parse file, it doesn't exist."); RefLib.Seek(ref s); string ss = s; ss = RefLib.GetLine(ref ss); hf.FullName = ReadName(ss); s = s.Remove(0,ss.Length); RefLib.Seek(ref s); if(s.First() == '{') { s = s.Remove(0,1); while(true) { HudElement he = new HudElement(); RefLib.Seek(ref s); ss = ReadName(s); if(ss != "") { he.Name = ss; s = s.Remove(0,ss.Length); RefLib.Seek(ref s); } ss = s; ss = RefLib.GetLine(ref ss); if(ss.First() == '[') { if(ss.IndexOf(']') != -1) { he.Platform = Read(s,readModes.PlatformTag); } else throw new Exception("Expected platform tag (ex. [$WIN32]) in element " + he.Name + ". In file " + hf.FullName + " got: " + ss); s = s.Remove(0,ss.Length); RefLib.Seek(ref s); } if(s.First() == '{') { s = s.Remove(0,1); while(true) { RefLib.Seek(ref s); ss = s; ss = RefLib.GetLines(2,ref ss); if(ss.IndexOf('{') != -1) { SubElement sb = ParseSubElement(ref s); if(!sb.IsNull) { he.Add(sb); s = s.Remove(0,s.IndexOf('}')+1); } continue; } if(s.First() != '}') { ss = s; ss = GetKeyValuePair(ss); s = s.Remove(0,ss.Length); KeyValue kv = ParseKeyValue(ss); if(!kv.IsNull) { he.Add(kv); continue; } } break; } if(!he.IsNull) { hf.Add(he); RefLib.Seek(ref s); if(s.First() == '}') { s = s.Remove(0,1); RefLib.Seek(ref s); } } else break; } else if(s.First() == '}') { s = s.Remove(0,1); RefLib.Seek(ref s); if(s != "") throw new Exception("Error while parsing file " + hf.FullName + ". String should be empty by now but isn't"); else break; } } } return hf; }
/// <summary> /// Strips keyvalues containing "_minmode" off all elements and their subelements. /// </summary> /// <param name="hf">HudFile to strip.</param> /// <returns>Returns a HudFile without any minimal values.</returns> static HudFile StripMinimal(HudFile hf) { foreach(HudElement he in hf.m_ElementList) { foreach(KeyValue kv in he.m_ValueList) { if(kv.Name.IndexOf("_minmode") != -1) he.Remove(kv); } foreach(SubElement sb in he.m_SubList) { foreach(KeyValue kv in sb.m_ValueList) { if(kv.Name.IndexOf("_minmode") != -1) he.Remove(kv); } foreach(SubElement ssb in sb.m_SubValueList) { foreach(KeyValue kv in ssb.m_ValueList) { if(kv.Name.IndexOf("_minmode") != -1) he.Remove(kv); } } } } return hf; }
/// <summary> /// Takes a HudFile and makes minimal values override default values, then removes the minimal ones. /// For example: It finds a pair like: /// "xpos" "10" /// "xpos_minmode" "20" /// After which it sets "xpos" to 20 and deletes "xpos_minmode" so you're left with only: /// "xpos" "20" /// </summary> /// <param name="hf">HudFile to use.</param> /// <returns>Returns the new HudFile.</returns> static HudFile MakeMinimalDefault(HudFile hf) { foreach(HudElement he in hf.m_ElementList) { foreach(KeyValue kv in he.m_ValueList) { string newValue; string name; if(kv.Name.Contains("_minmode")) { newValue = kv.Value; name = kv.Name.Replace("_minmode",""); foreach(KeyValue kv2 in he.m_ValueList) { if(kv2.Name.ToLower() == name.ToLower()) { kv2.Value = newValue; he.m_ValueList.Remove(kv); break; } } } } foreach(SubElement sb in he.m_SubList) { foreach(KeyValue kv in he.m_ValueList) { string newValue; string name; if(kv.Name.Contains("_minmode")) { newValue = kv.Value; name = kv.Name.Replace("_minmode",""); foreach(KeyValue kv2 in he.m_ValueList) { if(kv2.Name.ToLower() == name.ToLower()) { kv2.Value = newValue; he.m_ValueList.Remove(kv); break; } } } } foreach(SubElement ssb in sb.m_SubValueList) { foreach(KeyValue kv in he.m_ValueList) { string newValue; string name; if(kv.Name.Contains("_minmode")) { newValue = kv.Value; name = kv.Name.Replace("_minmode",""); foreach(KeyValue kv2 in he.m_ValueList) { if(kv2.Name.ToLower() == name.ToLower()) { kv2.Value = newValue; he.m_ValueList.Remove(kv); break; } } } } } } } return hf; }
static HudFolder ParseHudFolder(string path) { HudFolder folder = new HudFolder(); folder.FullName = path; var hudFiles = Directory.GetFiles(path, "*.res"); var folders = Directory.GetDirectories(path); for(int i = 0; i < folders.Length; i++) { HudFolder subFolder = new HudFolder(); subFolder.FullName = folders[i]; if(!subFolder.CopyNoParse) subFolder = ParseHudFolder(subFolder.FullName); folder.Add(subFolder); } if(hudFiles.Length > 0) { for(int i = 0; i < hudFiles.Length; i++) { HudFile file = new HudFile(); file.FullName = hudFiles[i]; file = ParseHudFile(file.FullName); if(!file.IsNull) folder.Add(file); } } return folder; }