Exemplo n.º 1
0
        /// <summary>
        /// Create a new PiggStream object.
        /// </summary>
        /// <param name="LeafInfo">PiggLeafInfo object that describes the file
        /// that will be read or written.</param>
        public PiggStream(PiggLeafInfo LeafInfo)
        {
            this.LeafInfo = LeafInfo;

            // Only open the file for reading when we need to.
            this.FileSource     = null;
            this.DeflateSource  = null;
            this.Cache          = null;
            this.StreamPosition = 0;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Extract a node and all of its subnodes and children.
        /// </summary>
        /// <param name="RootPath">Path to which to extract node.</param>
        /// <param name="TextureType">How textures are to be extracted.</param>
        /// <param name="NodeType">Whether to recreate the full root path.</param>
        /// <param name="OnlyTextures">Indicates whether only textures or to be
        /// extracted or all files.</param>
        /// <param name="Callback">Callback function to update the caller that a
        /// leaf is about to be extracted.</param>
        public void Extract(string RootPath, TextureExtractType TextureType,
                            NodeExtractType NodeType, bool OnlyTextures, ExtractProgress Callback)
        {
            // Create the path to extract the nodes.
            string dir_path = RootPath;

            switch (NodeType)
            {
            case NodeExtractType.Relative:
                dir_path += Path.DirectorySeparatorChar + this.Name;
                break;

            case NodeExtractType.FullPath:
                dir_path += Path.DirectorySeparatorChar + this.FullPath;
                break;

            default:
                throw new NotSupportedException("NodeExtractType not supported.");
            }
            DirectoryInfo new_dir = Directory.CreateDirectory(dir_path);

            // Extract all child nodes
            foreach (PiggNode node in this.Subnodes)
            {
                node.Extract(dir_path, TextureType, NodeExtractType.Relative,
                             OnlyTextures, Callback);
            }

            // Extract all files
            foreach (PiggLeaf leaf in this.Leafs)
            {
                if (Callback != null)
                {
                    Callback(leaf);
                }
                int          last      = leaf.PiggReferences.Count - 1;
                PiggLeafInfo leaf_info = leaf.PiggReferences[last];

                if (Path.GetExtension(leaf.Name).ToLower() != ".texture" ||
                    TextureType == TextureExtractType.Texture)
                {
                    // Check to see if we only want textures.
                    if (TextureType == TextureExtractType.Texture || !OnlyTextures)
                    {
                        // Extract the file as-is.
                        FileStream fs = new FileStream(dir_path +
                                                       Path.DirectorySeparatorChar + leaf.Name,
                                                       FileMode.Create, FileAccess.Write, FileShare.Write);
                        if (fs != null)
                        {
                            leaf_info.Extract(fs);
                        }
                        fs.Close();
                    }
                }
                else
                {
                    PiggTexture tex = new PiggTexture(leaf_info);
                    string      ext = "";
                    switch (TextureType)
                    {
                    case TextureExtractType.Bmp:
                        ext += ".bmp";
                        break;

                    case TextureExtractType.Gif:
                        ext += ".gif";
                        break;

                    case TextureExtractType.Jpeg:
                        ext += ".jpg";
                        break;

                    case TextureExtractType.Original:
                        ext += Path.GetExtension(tex.Filename).ToLower();
                        break;

                    case TextureExtractType.Png:
                        ext += ".png";
                        break;

                    case TextureExtractType.Tiff:
                        ext += ".tif";
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                    FileStream fs = new FileStream(dir_path +
                                                   Path.DirectorySeparatorChar +
                                                   Path.GetFileNameWithoutExtension(leaf.Name) + ext,
                                                   FileMode.Create, FileAccess.Write, FileShare.Write);
                    tex.Extract(fs, TextureType);
                    fs.Close();
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new PiggTexture object.
 /// </summary>
 /// <param name="LeafInfo"><typeparamref name="PiggLeafInfo"/> object from
 /// which to read the PiggTextureHeader object.</param>
 public PiggTexture(PiggLeafInfo LeafInfo)
 {
     this.LeafInfo = LeafInfo;
 }