Exemplo n.º 1
0
        private void LoadNode(TreeNode Subnode)
        {
            DirectoryNode d_node = (DirectoryNode)Subnode.Tag;

            if (d_node.Node == null || d_node.IsLoaded)
            {
                return;
            }
            foreach (PiggNode entry in d_node.Node.Subnodes)
            {
                TreeNode new_node = new TreeNode(entry.Name);
                new_node.Tag                = new DirectoryNode(entry);
                new_node.ImageIndex         = 1;
                new_node.SelectedImageIndex = 1;
                Subnode.Nodes.Add(new_node);
            }
            foreach (PiggLeaf entry in d_node.Node.Leafs)
            {
                TreeNode new_node = new TreeNode(entry.Name);
                new_node.Tag = new DirectoryNode(entry);
                int    index     = entry.Name.LastIndexOf('.');
                string extension = "";
                if (index >= 0)
                {
                    extension = entry.Name.Substring(index);
                }
                switch (extension)
                {
                case ".texture":
                case ".jpg":
                case ".bmp":
                case ".png":
                    new_node.ImageIndex         = 4;
                    new_node.SelectedImageIndex = 4;
                    break;

                case ".bin":
                    new_node.ImageIndex         = 5;
                    new_node.SelectedImageIndex = 5;
                    break;

                case ".geo":
                    new_node.ImageIndex         = 6;
                    new_node.SelectedImageIndex = 6;
                    break;

                case ".txt":
                    new_node.ImageIndex         = 7;
                    new_node.SelectedImageIndex = 7;
                    break;

                case ".cfg":
                    new_node.ImageIndex         = 8;
                    new_node.SelectedImageIndex = 8;
                    break;

                case ".ogg":
                case ".mp3":
                case ".wav":
                    new_node.ImageIndex         = 9;
                    new_node.SelectedImageIndex = 9;
                    break;

                default:
                    new_node.ImageIndex         = 3;
                    new_node.SelectedImageIndex = 3;
                    break;
                }
                Subnode.Nodes.Add(new_node);
            }
            d_node.IsLoaded = true;
        }
Exemplo n.º 2
0
        private void tvwFilelistNormal_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            // Check for right-click
            if (e.Button == MouseButtons.Right)
            {
                tvwFilelistNormal.SelectedNode = e.Node;
                DirectoryNode d_node = (DirectoryNode)e.Node.Tag;
                if (d_node.Leaf != null)
                {
                    FileInfo fi  = new FileInfo(d_node.Leaf.Name);
                    string   ext = fi.Extension;
                    mnuContextNodeSeparator.Visible       = false;
                    mnuContextNodeExtractOriginal.Visible = false;
                    mnuContextNodeExtractBmp.Visible      = false;
                    mnuContextNodeExtractJpg.Visible      = false;
                    mnuContextNodeExtractPng.Visible      = false;
                    mnuContextNodeExtractWav.Visible      = false;
                    switch (ext.ToLower())
                    {
                    case ".texture":
                        int          last = d_node.Leaf.PiggReferences.Count - 1;
                        PiggLeafInfo info = d_node.Leaf.PiggReferences[last];
                        PiggTexture  tex  = new PiggTexture(info);
                        ext = Path.GetExtension(tex.Filename).ToLower();
                        if (ext[0] == '.')
                        {
                            ext = ext.Substring(1);
                        }

                        mnuContextNodeExtract.Image         = imlImages.Images[5];
                        mnuContextNodeExtractOriginal.Image = imlImages.Images[4];
                        mnuContextNodeExtractOriginal.Text  =
                            string.Format("Extract as original format ({0})...", ext);
                        mnuContextNodeSeparator.Visible       = true;
                        mnuContextNodeExtractOriginal.Visible = true;
                        mnuContextNodeExtractBmp.Visible      = true;
                        mnuContextNodeExtractJpg.Visible      = true;
                        mnuContextNodeExtractPng.Visible      = true;
                        break;

                    case ".bmp":
                    case ".jpg":
                    case ".png":
                        mnuContextNodeExtract.Image = imlImages.Images[4];
                        break;

                    case ".bin":
                        mnuContextNodeExtract.Image = imlImages.Images[5];
                        break;

                    case ".geo":
                        mnuContextNodeExtract.Image = imlImages.Images[6];
                        break;

                    case ".txt":
                        mnuContextNodeExtract.Image = imlImages.Images[7];
                        break;

                    case ".cfg":
                        mnuContextNodeExtract.Image = imlImages.Images[8];
                        break;

                    case ".ogg":
                    case ".mp3":
                    case ".wav":
                        mnuContextNodeExtract.Image = imlImages.Images[9];
                        //mnuContextNodeExtractOriginal.Image = imlImages.Images[9];
                        //mnuContextNodeSeparator.Visible = true;
                        //mnuContextNodeExtractOriginal.Visible = true;
                        //mnuContextNodeExtractWav.Visible = true;
                        break;

                    default:
                        mnuContextNodeExtract.Image = imlImages.Images[3];
                        break;
                    }
                }
                mnuContext.Show(tvwFilelistNormal, e.Location);
            }
        }
Exemplo n.º 3
0
        private void mnuNodeExtract_Click(object sender, EventArgs e)
        {
            TreeNode n = tvwFilelistNormal.SelectedNode;

            if (n != null)
            {
                DirectoryNode d_node = (DirectoryNode)n.Tag;
                if (d_node.Leaf != null)
                {
                    string filetype = Path.GetExtension(d_node.Leaf.Name).ToLower();
                    string filter   = "";
                    filter += Utility.ExtToDescriptive(filetype) + " files " +
                              "(*" + filetype + ")|*" + filetype;
                    if (filter != "")
                    {
                        filter += "|";
                    }
                    filter                 += "All files (*.*)|*.*";
                    dlgSave.Filter          = filter;
                    dlgSave.FilterIndex     = 1;
                    dlgSave.FileName        = d_node.Leaf.Name;
                    dlgSave.OverwritePrompt = true;

                    DialogResult dlg_result = dlgSave.ShowDialog();
                    if (dlg_result == DialogResult.OK)
                    {
                        FileStream fs = new FileStream(dlgSave.FileName, FileMode.Create,
                                                       FileAccess.Write, FileShare.Write);
                        int last = d_node.Leaf.PiggReferences.Count - 1;
                        d_node.Leaf.PiggReferences[last].Extract(fs);
                        fs.Close();
                    }
                }
                else if (d_node.Node != null) // A directory was clicked
                {
                    dlgExtractOptions options = new dlgExtractOptions();
                    if (d_node.Node.TotalCapacity > 0x10000000) // 200 MB
                    {
                        options.SetWarningSize(d_node.Node.TotalCapacity);
                    }
                    if (options.ShowDialog() == DialogResult.OK)
                    {
                        dlgDirectory.Description = "Select a directory where files in " +
                                                   "this directory are to be extracted.";
                        dlgDirectory.RootFolder          = Environment.SpecialFolder.MyDocuments;
                        dlgDirectory.ShowNewFolderButton = true;
                        if (dlgDirectory.ShowDialog(this) == DialogResult.OK)
                        {
                            // Set up the progress bar
                            m_extract_progress         = new ToolStripProgressBar();
                            m_extract_progress.Maximum = (int)d_node.Node.TotalLeafCount;
                            staStatus.Items.Add(m_extract_progress);
                            m_extract_label = new ToolStripLabel();
                            staStatus.Items.Add(m_extract_label);
                            m_extract_leaf_total = d_node.Node.TotalLeafCount;

                            d_node.Node.Extract(dlgDirectory.SelectedPath,
                                                options.TextureType, NodeExtractType.Relative,
                                                options.TexturesOnly, this.UpdateExtractProgress);

                            staStatus.Items.Remove(m_extract_progress);
                            staStatus.Items.Remove(m_extract_label);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void tvwFilelistNormal_AfterSelect(object sender, TreeViewEventArgs e)
        {
            DirectoryNode d_node = (DirectoryNode)e.Node.Tag;

            if (d_node.Leaf != null)
            {
                PiggLeafInfo leaf_info =
                    d_node.Leaf.PiggReferences[d_node.Leaf.PiggReferences.Count - 1];
                int    index     = d_node.Leaf.Name.LastIndexOf('.');
                string extension = "";
                if (index >= 0)
                {
                    extension = d_node.Leaf.Name.Substring(index);
                }
                switch (extension)
                {
                case ".texture":
                    PiggTexture tex = new PiggTexture(leaf_info);
                    imgViewer.Picture = tex.Image;
                    picImage.Image    = tex.Image;
                    picImage.Height   = tex.Image.Height;
                    picImage.Width    = tex.Image.Width;

                    break;
                }

                // Fill in properties
                txtProperties.Clear();
                string properties = "";
                properties += string.Format("Source: {0}\r\n",
                                            leaf_info.File.FullPath);
                properties += string.Format("File size: {0}\r\n",
                                            Utility.FriendlyBytes(leaf_info.UncompressedSize));
                properties += string.Format("Timestamp: {0}\r\n",
                                            leaf_info.Timestamp);
                properties += string.Format("Filename: {0}\r\n",
                                            leaf_info.File.FullPath);
                properties += string.Format("File start: 0x{0:x8}\r\n",
                                            leaf_info.Offset);
                properties += string.Format("Compressend length: 0x{0:x8}\r\n",
                                            leaf_info.CompressedSize);
                properties += string.Format("Uncompressed length: 0x{0:x8}\r\n",
                                            leaf_info.UncompressedSize);
                txtProperties.Text = properties;
            }
            else
            {
                txtProperties.Clear();
                string properties = "";
                properties += string.Format("Full Path: {0}\r\n", d_node.Node.FullPath);
                properties += string.Format("Size of child leafs: {0:x16} ({1})\r\n",
                                            d_node.Node.Capacity, Utility.FriendlyBytes(d_node.Node.Capacity));
                properties += string.Format("Total Size: {0:x16} ({1})\r\n",
                                            d_node.Node.TotalCapacity, Utility.FriendlyBytes(d_node.Node.TotalCapacity));
                foreach (PiggFile reference in d_node.Node.PiggFileRefs)
                {
                    properties += string.Format("Reference: {0}", reference.FullPath);
                }
                txtProperties.Text = properties;
            }
        }