Exemplo n.º 1
0
        /// <summary>
        /// Opens a file and updates the tree view.
        /// </summary>
        /// <param name="filename">Name of the file we want to open.</param>
        private void OpenFile(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return;
            }

            this.sourceFile = filename;
            string fullSrcPath = null;

            if (string.IsNullOrEmpty(this.sourceFile))
            {
                MessageBox.Show("You must enter a valid source file path.");
                return;
            }

            // See if path exists and create it if necessary
            if (!string.IsNullOrEmpty(this.sourceFile))
            {
                fullSrcPath = Path.GetFullPath(this.sourceFile);
            }

            if (!File.Exists(fullSrcPath))
            {
                // they did not give us a file
                MessageBox.Show("You must specify a file!");
                return;
            }

            // Try to read it as an ARC file since those have a header.
            arcFile = new ArcFile(this.sourceFile);
            if (arcFile.Read())
            {
                fileType = CompressedFileType.ArcFile;
            }
            else
            {
                arcFile  = null;
                fileType = CompressedFileType.Unknown;
            }

            // Try reading the file as an ARZ file.
            if (fileType == CompressedFileType.Unknown)
            {
                // Read our ARZ file into memory.
                arzFile = new ArzFile(this.sourceFile);
                if (arzFile.Read())
                {
                    fileType = CompressedFileType.ArzFile;
                }
                else
                {
                    arzFile  = null;
                    fileType = CompressedFileType.Unknown;
                }
            }

            // We failed reading the file
            // so we just clear everything out.
            if (fileType == CompressedFileType.Unknown)
            {
                this.Text = this.titleText;
                this.treeView1.Nodes.Clear();
                this.selectedFileToolStripMenuItem.Enabled = false;
                this.allFilesToolStripMenuItem.Enabled     = false;
                this.textBox1.Lines = null;
                MessageBox.Show(string.Format("Error Reading {0}", this.sourceFile));
                return;
            }

            this.selectedFileToolStripMenuItem.Enabled = true;
            this.allFilesToolStripMenuItem.Enabled     = true;

            this.Text = string.Format("{0} - {1}", this.titleText, this.sourceFile);

            this.textBox1.Lines      = null;
            this.pictureBox1.Visible = false;

            this.BuildTreeView();
        }