示例#1
0
        //Currently uses almost the same code as ParseHudElement. 
        //TODO: Derive SubElement from HudElement and share code.
        //TODO: Check if it's a .res file before parsing and return null if it's not as a flag to copy the file over when installing.
        //TODO: Set folder check to Hud's path + folder name, or whatever, so it ignores the parsing ONLY if we're in the root hud folder.
        static SubElement ParseSubElement(ref string s)
        {
            SubElement sb = new SubElement();

            string ss = s;

            ss = RefLib.GetLine(ref ss);
            sb.Name = ss;
            ss = s;
            ss = RefLib.GetLine(ref ss);
            int toRemove = 0;

            for(int i = 0; i < ss.Length; i++)
            {
                if(ss[i] == '\"')
                    toRemove++;
            }
            s = s.Remove(0,ss.Length + toRemove);
            RefLib.Seek(ref s);
            if(s.First() == '{')
            {
                s = s.Remove(0,1);
                while(true)
                {
                    RefLib.Seek(ref s);
                    SubElement ssb = new SubElement();
                    ss = s;
                    ss = RefLib.GetLines(2,ref ss);
                    if(ss.IndexOf('{') != -1)
                    {
                        ssb = ParseSubElement(ref s);
                        if(!ssb.IsNull)
                        {
                            sb.Add(ssb);
                            s = s.Remove(0,s.IndexOf('}') + 1);
                            continue;
                        }
                    }

                    RefLib.Seek(ref s);
                    KeyValue kv = new KeyValue();
                    if(s.First() != '}')
                    {
                        ss = GetKeyValuePair(s);
                        s = s.Remove(0,ss.Length);
                        kv = ParseKeyValue(ss);
                    }                    
                    if(!kv.IsNull)
                        sb.Add(kv);
                    else break; 
                }
            }
            return sb;
        }
示例#2
0
 static HudElement ParseHudElement(string s)
 {
     HudElement he = new HudElement();
     RefLib.Seek(ref s);
     string ss = s;
     ss = RefLib.GetLine(ref ss);
     if(ss.IndexOf('[') == -1)
         he.Name = RefLib.Condense(ss);
     else
     {
         if(s.First() == '[')
         {
             string result = "";                    
             for(int i = 0; i < s.Length; i++)
             {
                 result += ss[i];
                 if(ss[i] == ']')
                     break;
                 throw new Exception("Reached end of file before reaching end of platform tag");
             }
             s = s.Remove(0,ss.Length);
             he.Platform = ss;
             RefLib.Seek(ref s);
         }
     }
     s = s.Remove(ss.Length);
     RefLib.Seek(ref s);
     if(s.First() == '{')
     {
         while(s.First() != '}')
         {
             string temp = s;
             temp = RefLib.GetLines(2,ref temp);
             if(temp.IndexOf('{') != -1)
             {
                 SubElement sb = ParseSubElement(ref s);
                 if(!sb.IsNull)
                 {
                     he.Add(sb);
                     continue;
                 }
                 else throw new Exception("Parse sub element returned null. Don't try to parse if there isn't one");
             }
             RefLib.Seek(ref s);
             KeyValue kv = new KeyValue();
             string x = GetKeyValuePair(s);
             kv = ParseKeyValue(x);
             if(x != "")                    
                 s.Remove(0,x.Length);
             if(!kv.IsNull)
             {
                 he.Add(kv);
             }
             else break;                    
         }
     }
     return he;
 }
示例#3
0
 public void Remove(KeyValue kv)
 {
     m_ValueList.Remove(kv);
 }        
示例#4
0
 static KeyValue ParseKeyValue(string s)
 {            
     KeyValue kv = new KeyValue();
     if(s != "")
     {
         string name = "";
         string value = "";
         bool foundName = false;
         bool foundValue = false;
         bool openQuotes = false;
         int quotesToRemove = 0;
         for(int i = 0; i < s.Length; i++)
         {
             if((s[i] != '\t') && (s[i] != ' ') && (s[i] != '\r') && (s[i] != '\n'))
             {
                 if(s[i] == '\"')
                 {
                     if(!openQuotes)
                         openQuotes = true;
                     else
                         openQuotes = false;
                     quotesToRemove++;
                     continue;
                 }
                 if(!foundName)
                     name += s[i];
                 else
                 {
                     value += s[i];
                     foundValue = true;
                 }
             }
             else
             {
                 if(openQuotes)
                 {
                     if(!foundName)
                         name += s[i];
                     else
                         value += s[i];
                     continue;
                 }
                 foundName = true;
                 if(foundValue && foundName)
                     break;
             }
         }
         if(name != "")
         {
             s = s.Remove(0,name.Length);
             kv.Name = name;
             s = RefLib.Seek(ref s);
         }
         if(value != "")
         {
             s = s.Remove(0,value.Length);
             kv.Value = value;
             s = RefLib.Seek(ref s);
         }
         s = s.Remove(0,quotesToRemove);                             
         if(s != "")
             kv.Platform = Read(s,readModes.PlatformTag);           
     }
     return kv;
 }
示例#5
0
 public void Add(KeyValue kv)
 {                        
     m_ValueList.Add(kv);            
 }