コード例 #1
0
        public ConfigReader(Stream ins0)
        {
            TextReader reader = null;

            try
            {
                reader = new StreamReader(ins0, System.Text.Encoding.UTF8);
                string        record    = null;
                StringBuilder mapBuffer = new StringBuilder();
                bool          mapFlag   = false;
                string        mapName   = null;
                for (; (record = reader.ReadLine()) != null;)
                {
                    record = record.Trim();
                    if (record.Length > 0 && !record.StartsWith(FLAG_L_TAG) &&
                        !record.StartsWith(FLAG_C_TAG) &&
                        !record.StartsWith(FLAG_I_TAG))
                    {
                        if (record.StartsWith("begin"))
                        {
                            mapBuffer.Remove(0, mapBuffer.Length - (0));
                            string mes = record.Substring(5, (record.Length) - (5))
                                         .Trim();
                            if (mes.StartsWith("name"))
                            {
                                mapName = LoadItem(mes, false);
                            }
                            mapFlag = true;
                        }
                        else if (record.StartsWith("end"))
                        {
                            mapFlag = false;
                            if (mapName != null)
                            {
                                CollectionUtils.Put(pConfigItems, mapName, mapBuffer.ToString());
                            }
                        }
                        else if (mapFlag)
                        {
                            mapBuffer.Append(record);
                        }
                        else
                        {
                            LoadItem(record, true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new IOException(ex.Message);
            }
            finally
            {
                LSystem.Close(ins0);
                if (reader != null)
                {
                    try
                    {
                        reader.Close();
                        reader = null;
                    }
                    catch (IOException e)
                    {
                        Loon.Utils.Debug.Log.Exception(e);
                    }
                }
            }
        }