Beispiel #1
0
using System.Text;
Beispiel #2
0
        public bool LoadFromBytes(byte[] data, TypeLoader loader)
        {
            PackageReader rdr = new PackageReader(data);

            // No support for external file refs yet.

            rdr.ReadInt32();             // tag
            rdr.ReadInt32();             // flags
            rdr.ReadInt32();             // hdr size
            rdr.ReadInt32();             // data size
            int numImports = rdr.ReadInt16();

            if (numImports != 0)
            {
                Console.WriteLine("Package has imports, unsupported now!");
                return(false);
            }

            int slots = rdr.ReadInt16();

            m_slots = new Slot[slots];

            for (int i = 0; i < slots; i++)
            {
                m_slots[i] = new Slot();

                m_slots[i].flags = rdr.ReadInt16();
                if ((m_slots[i].flags & FLAG_PATH) != 0)
                {
                    m_slots[i].path = rdr.ReadString(rdr.ReadInt16());
                }

                // external flag could be set
                if ((m_slots[i].flags & FLAG_EXTERNAL) != 0)
                {
                    Console.WriteLine("External resources not supported!");
                    return(false);
                }
                else if ((m_slots[i].flags & FLAG_INTERNAL) != 0)
                {
                    rdr.ReadInt32();                     // beg in data section
                    rdr.ReadInt32();                     // end in data section
                    m_slots[i].type = rdr.ReadInt16();
                }
            }

            // Now we assume they are all just lined up after this!
            for (int i = 0; i < slots; i++)
            {
                if ((m_slots[i].flags & FLAG_INTERNAL) != 0)
                {
                    Console.WriteLine("Loading slot " + i + " from " + rdr.GetPosition());
                    m_slots[i].inst = loader.LoadFromPackage(m_slots[i].type, rdr);
                }
            }

            // Now we assume they are all just lined up after this!
            for (int i = 0; i < slots; i++)
            {
                if ((m_slots[i].flags & FLAG_INTERNAL) != 0)
                {
                    m_slots[i].inst = loader.ResolveFromPackage(m_slots[i].type, m_slots[i].inst, this);
                }
            }

            m_paths = new Dictionary <object, string>();
            for (int i = 0; i < slots; i++)
            {
                if (m_slots[i].inst != null && m_slots[i].path != null)
                {
                    m_paths.Add(m_slots[i].inst, m_slots[i].path);
                }
            }

            return(!m_gotUnresolved);
        }