Beispiel #1
0
        public static ResourceNode FromFile(ResourceNode parent, string path, FileOptions options)
        {
            ResourceNode node = null;
            FileMap      map  = FileMap.FromFile(path, FileMapProtect.Read, 0, 0, options);

            try
            {
                DataSource source = new DataSource(map);
                if ((node = FromSource(parent, source)) == null)
                {
                    string ext = path.Substring(path.LastIndexOf('.') + 1).ToUpper(CultureInfo.InvariantCulture);

                    if (Forced.ContainsKey(ext) &&
                        (node = Activator.CreateInstance(Forced[ext]) as ResourceNode) != null)
                    {
                        FileMap uncompressedMap = Compressor.TryExpand(ref source, false);
                        if (uncompressedMap != null)
                        {
                            node.Initialize(parent, source, new DataSource(uncompressedMap));
                        }
                        else
                        {
                            node.Initialize(parent, source);
                        }
                    }
#if DEBUG
                    else
                    {
                        node = new RawDataNode(Path.GetFileNameWithoutExtension(path));
                        node.Initialize(parent, source);
                    }
#endif
                }
            }
            finally
            {
                if (node == null)
                {
                    map.Dispose();
                }
            }

            return(node);
        }
Beispiel #2
0
        public static ResourceNode FromFile(ResourceNode parent, string path, FileOptions options, Type t)
        {
            ResourceNode node = null;
            FileMap      map  = FileMap.FromFile(path, FileMapProtect.Read, 0, 0, options);

            try
            {
                DataSource source = new DataSource(map);

                bool supportsCompression = true;
                if (!(t is null))
                {
                    ResourceNode n = Activator.CreateInstance(t) as ResourceNode;
                    supportsCompression = n?.supportsCompression ?? true;
                }

                if ((node = FromSource(parent, source, t, supportsCompression)) == null)
                {
                    string ext = path.Substring(path.LastIndexOf('.') + 1).ToUpper(CultureInfo.InvariantCulture);

                    if (!(t is null) && (node = Activator.CreateInstance(t) as ResourceNode) != null ||
                        ForcedExtensions.ContainsKey(ext) &&
                        (node = Activator.CreateInstance(ForcedExtensions[ext]) as ResourceNode) != null)
                    {
                        FileMap uncompressedMap = Compressor.TryExpand(ref source, false);
                        if (uncompressedMap != null)
                        {
                            node.Initialize(parent, source, new DataSource(uncompressedMap));
                        }
                        else
                        {
                            node.Initialize(parent, source);
                        }
                    }
                    else
                    {
                        node = new RawDataNode(Path.GetFileName(path));
                        node.Initialize(parent, source);
                    }
                }
            }
Beispiel #3
0
        //Parser commands must initialize the node before returning.
        public unsafe static ResourceNode FromFile(ResourceNode parent, string path, FileOptions options = FileOptions.RandomAccess)
        {
            ResourceNode node = null;
            FileMap      map  = FileMap.FromFile(path, FileMapProtect.Read, 0, 0, options);

            try
            {
                DataSource source = new DataSource(map);
                if ((node = FromSource(parent, source)) == null)
                {
                    string ext = path.Substring(path.LastIndexOf('.') + 1).ToUpper();
                    if (Forced.ContainsKey(ext))
                    {
                        node = Activator.CreateInstance(Forced[ext]) as ResourceNode;
                        FileMap uncomp = Compressor.TryExpand(ref source, false);
                        if (uncomp != null)
                        {
                            node.Initialize(parent, source, new DataSource(uncomp));
                        }
                        else
                        {
                            node.Initialize(parent, source);
                        }
                    }
                    else if (UseRawDataNode)
                    {
                        (node = new RawDataNode(Path.GetFileNameWithoutExtension(path))).Initialize(parent, source);
                    }
                }
            }
            finally
            {
                if (node == null)
                {
                    map.Dispose();
                }
            }
            return(node);
        }
Beispiel #4
0
        public override void OnPopulate()
        {
            for (int i = 0; i < Header->_entries; i++)
            {
                int length;
                if (i < Header->_entries - 1)
                {
                    length = (int)((*Header)[i + 1].UInt - (*Header)[i].UInt);
                }
                else
                {
                    length = (int)(Header->_dataOffset - (*Header)[i].UInt);
                }

                string name = Header->GetEntryName(i);

                ResourceNode node;

                switch (name)
                {
                case "tySealList":
                    node = new TySealList();
                    break;

                case "tySealVertData":
                    node = new TySealVertDataNode();
                    break;

                default:
                    node = new RawDataNode();
                    break;
                }
                node._name = name;
                node.Initialize(this, Header->GetEntry(i), length);
            }
        }