Exemplo n.º 1
0
        public void LoadDefinitions(string path)
        {
            bool result = false;
            MyObjectBuilder_Definitions builder = null;

            using (var fileStream = MyFileSystem.OpenRead(path))
            {
                if (fileStream != null)
                {
                    using (var readStream = fileStream.UnwrapGZip())
                    {
                        if (readStream != null)
                        {
                            MyObjectBuilder_Base obj;
                            result  = MyObjectBuilderSerializer.DeserializeXML(readStream, out obj, typeof(MyObjectBuilder_Definitions), m_overrideMap);
                            builder = obj as MyObjectBuilder_Definitions;
                        }
                    }
                }
            }

            if (!result)
            {
                throw new Exception("Error while reading \"" + path + "\"");
            }

            if (builder.Definitions != null)
            {
                foreach (MyObjectBuilder_DefinitionBase definitionBuilder in builder.Definitions)
                {
                    MyObjectBuilderType.RemapType(ref definitionBuilder.Id, m_overrideMap);
                    MyDefinitionBase definition = GetObjectFactory().CreateInstance(definitionBuilder.TypeId);
                    definition.Init(builder.Definitions[0], new MyModContext());
                    m_definitions.AddDefinition(definition);
                }
            }
        }