예제 #1
0
 public void Deserialise(ConfigElement[] elems, object instance)
 {
     for (int i = 0; i < Keys.Count; i++)
     {
         ConfigElement.Parse(elems, instance, Keys[i], (string)Values[i]);
     }
 }
예제 #2
0
    /** Parses the specified XML configuration file, and extracts all the elements. */
    public bool Parse(byte[] bytes)
    {
        TPTabletUIManager mgr = TPTabletUIManager.GetInstance();

        mgr.PutErrorMessage("ConfigFile::Parse");

        // Create the XmlReader instance for the specified file.
        XmlReaderSettings settings = new XmlReaderSettings();

        settings.ConformanceLevel = ConformanceLevel.Document;
        XmlReader reader = null;

        try {
            reader = XmlReader.Create(new MemoryStream(bytes), settings);
            while (reader.Read())
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                if (reader.Depth == 0)
                {
                    // Detected the root element.
                    m_root = new ConfigElement();
                    m_root.Parse(reader, null);
                }
            }
        }catch (Exception e) {
            mgr.PutErrorMessage(e.Message);
            return(false);
        }
        return(true);
    }
예제 #3
0
 static void ZSLineProcessor(string key, string value)
 {
     if (!ConfigElement.Parse(Server.zombieConfig, key, value, null))
     {
         Logger.Log(LogType.Warning, "\"{0}\" was not a recognised zombie survival property key.", key);
     }
 }
예제 #4
0
        static void ParseZone(Level lvl, ref byte[] buffer, Stream gs)
        {
            Zone z = new Zone();

            z.MinX = Read_U16(buffer, gs); z.MaxX = Read_U16(buffer, gs);
            z.MinY = Read_U16(buffer, gs); z.MaxY = Read_U16(buffer, gs);
            z.MinZ = Read_U16(buffer, gs); z.MaxZ = Read_U16(buffer, gs);

            int metaCount = TryRead_I32(buffer, gs);

            ConfigElement[] elems = Server.zoneConfig;

            for (int j = 0; j < metaCount; j++)
            {
                int size = Read_U16(buffer, gs);
                if (size > buffer.Length)
                {
                    buffer = new byte[size + 16];
                }
                gs.Read(buffer, 0, size);

                string line = Encoding.UTF8.GetString(buffer, 0, size), key, value;
                PropertiesFile.ParseLine(line, '=', out key, out value);
                if (key == null)
                {
                    continue;
                }

                value = value.Trim();
                ConfigElement.Parse(elems, z.Config, key, value);
            }
            z.AddTo(lvl);
        }
예제 #5
0
파일: JSON.cs 프로젝트: DireClanMC/MCGalaxy
 public void Deserialise(ConfigElement[] elems, object instance)
 {
     foreach (var kvp in this)
     {
         ConfigElement.Parse(elems, instance, kvp.Key, (string)kvp.Value);
     }
 }
예제 #6
0
        static void ReadZonesSection(Level lvl, Stream gs)
        {
            byte[] buffer = new byte[sizeof(int)];
            int    count  = TryRead_I32(buffer, gs);

            if (count == 0)
            {
                return;
            }

            for (int i = 0; i < count; i++)
            {
                Zone z = new Zone(lvl);
                if (!TryRead_U16(buffer, gs, ref z.MinX) || !TryRead_U16(buffer, gs, ref z.MaxX))
                {
                    return;
                }
                if (!TryRead_U16(buffer, gs, ref z.MinY) || !TryRead_U16(buffer, gs, ref z.MaxY))
                {
                    return;
                }
                if (!TryRead_U16(buffer, gs, ref z.MinZ) || !TryRead_U16(buffer, gs, ref z.MaxZ))
                {
                    return;
                }

                int             metaCount = TryRead_I32(buffer, gs);
                ConfigElement[] elems     = Server.zoneConfig;

                for (int j = 0; j < metaCount; j++)
                {
                    ushort size = 0;
                    if (!TryRead_U16(buffer, gs, ref size))
                    {
                        return;
                    }
                    if (size > buffer.Length)
                    {
                        buffer = new byte[size + 16];
                    }
                    gs.Read(buffer, 0, size);

                    string line = Encoding.UTF8.GetString(buffer, 0, size), key, value;
                    PropertiesFile.ParseLine(line, '=', out key, out value);
                    if (key == null)
                    {
                        continue;
                    }

                    value = value.Trim();
                    ConfigElement.Parse(elems, key, value, z.Config);
                }

                z.AddTo(lvl);
            }
        }
예제 #7
0
 void ProcessConfigLine(string key, string value)
 {
     // backwards compatibility
     if (key.CaselessEq("zombie-levels-list"))
     {
         Maps = new List <string>(value.SplitComma());
     }
     else
     {
         ConfigElement.Parse(cfg, this, key, value);
     }
 }
예제 #8
0
        static void PropLineProcessor(string key, string value, ref Level level)
        {
            switch (key.ToLower())
            {
            case "physics":
                level.setPhysics(int.Parse(value)); break;

            default:
                if (!ConfigElement.Parse(Server.levelConfig, key, value, level))
                {
                    Server.s.Log("\"" + key + "\" was not a recognised level property key.");
                }
                break;
            }
        }
예제 #9
0
        internal static List <BotProperties> ReadAll(string path)
        {
            List <BotProperties> props = new List <BotProperties>();

            if (elems == null)
            {
                elems = ConfigElement.GetAll(typeof(BotProperties));
            }
            string json = File.ReadAllText(path);

            JsonReader reader = new JsonReader(json);

            reader.OnMember = (obj, key, value) => {
                if (obj.Meta == null)
                {
                    obj.Meta = new BotProperties();
                }
                ConfigElement.Parse(elems, obj.Meta, key, (string)value);
            };

            JsonArray array = (JsonArray)reader.Parse();

            if (array == null)
            {
                return(props);
            }

            foreach (object raw in array)
            {
                JsonObject obj = (JsonObject)raw;
                if (obj == null || obj.Meta == null)
                {
                    continue;
                }

                BotProperties data = (BotProperties)obj.Meta;
                if (String.IsNullOrEmpty(data.DisplayName))
                {
                    data.DisplayName = data.Name;
                }
                props.Add(data);
            }
            return(props);
        }
예제 #10
0
    /** Parses the given XML element, and extracts all the attributes. */
    public void Parse(XmlReader reader, ConfigElement parent)
    {
        m_name       = reader.LocalName;
        m_depth      = reader.Depth;
        m_attributes = new Hashtable();
        m_children   = new ArrayList();
        m_parent     = parent;
        int i;

        for (i = 0; i < reader.AttributeCount; i++)
        {
            reader.MoveToAttribute(i);
            m_attributes[reader.Name] = reader.Value;
        }
        reader.MoveToElement();
        if (reader.Read())
        {
            while (true)
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    if (!reader.Read())
                    {
                        break;
                    }
                    continue;
                }
                if (reader.Depth > m_depth)
                {
                    // Detected a child element.
                    ConfigElement child = new ConfigElement();
                    child.Parse(reader, this);
                    m_children.Add(child);
                }
                else
                {
                    break;
                }
            }
        }
    }