コード例 #1
0
ファイル: Form1.cs プロジェクト: Arcant1/TQVaultAE
        /// <summary>
        /// Handler for clicking on a treeView item
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="e">TreeViewEventArgs data</param>
        private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // Make sure we have selected the last child
            // otherwise this will be a directory.
            if (this.treeView1.SelectedNode.GetNodeCount(false) == 0)
            {
                this.destFile = this.treeView1.SelectedNode.FullPath;
                try
                {
                    List <string> recordText = new List <string>();
                    if (fileType == CompressedFileType.ArzFile)
                    {
                        this.record = arzFile.GetRecordNotCached(this.destFile);
                        foreach (Variable variable in this.record)
                        {
                            recordText.Add(variable.ToString());
                        }
                    }
                    else if (fileType == CompressedFileType.ArcFile)
                    {
                        string extension   = Path.GetExtension(this.destFile).ToUpper();
                        string arcDataPath = Path.Combine(Path.GetFileNameWithoutExtension(arcFile.FileName), this.destFile);
                        if (extension == ".TXT")
                        {
                            byte[] rawData = arcFile.GetData(arcDataPath);

                            if (rawData == null)
                            {
                                return;
                            }

                            // now read it like a text file
                            using (StreamReader reader = new StreamReader(new MemoryStream(rawData), Encoding.Default))
                            {
                                string line;
                                while ((line = reader.ReadLine()) != null)
                                {
                                    recordText.Add(line);
                                }
                            }
                        }
                        else if (extension == ".TEX")
                        {
                            byte[] rawData = arcFile.GetData(arcDataPath);

                            if (rawData == null)
                            {
                                return;
                            }

                            Bitmap bitmap = BitmapCode.LoadFromTexMemory(rawData, 0, rawData.Length);

                            if (bitmap != null)
                            {
                                this.pictureBox1.Visible = true;
                                this.pictureBox1.Image   = bitmap;
                            }
                        }
                        else
                        {
                            this.pictureBox1.Visible = false;
                        }
                    }
                    else
                    {
                        this.pictureBox1.Visible = false;
                        this.destFile            = null;
                        this.textBox1.Lines      = null;
                        return;
                    }

                    // Now display our results.
                    if (recordText.Count != 0)
                    {
                        this.pictureBox1.Visible = false;
                        string[] output = new string[recordText.Count];
                        recordText.CopyTo(output);
                        this.textBox1.Lines = output;
                    }
                    else
                    {
                        this.textBox1.Lines = null;
                    }
                }
                catch (Exception)
                {
                    // Eat the exception
                }
            }
            else
            {
                this.destFile       = null;
                this.textBox1.Lines = null;
            }
        }