Ejemplo n.º 1
0
        /// <summary>
        /// Performs the extraction of an ARZ file.
        /// </summary>
        private void DoArzExtraction()
        {
            try
            {
                bool canceled = false;
                foreach (string recordID in arzProv.GetKeyTable(MainForm.ARZFile))
                {
                    if (canceled)
                    {
                        break;
                    }

                    // update label with recordID
                    this.recordIdBeingProcessed = recordID;
                    this.Invoke(new MethodInvoker(this.UpdateLabel));

                    // Write the record
                    var dbc = arzProv.GetRecordNotCached(MainForm.ARZFile, recordID);
                    DBRecordCollectionProvider.Write(dbc, this.BaseFolder);

                    // Update progressbar
                    this.Invoke(new MethodInvoker(this.IncrementProgress));

                    // see if we need to cancel
                    Monitor.Enter(this);
                    canceled = this.cancel;
                    Monitor.Exit(this);
                }

                // notify complete.
                this.Invoke(new MethodInvoker(this.ExtractComplete));
            }
            catch (Exception err)
            {
                // notify failure
                this.exception = err;
                this.Invoke(new MethodInvoker(this.ExtractFailed));
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <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.treeViewTOC.SelectedNode.GetNodeCount(false) == 0)
            {
                this.destFile = this.treeViewTOC.SelectedNode.FullPath;
                try
                {
                    List <string> recordText = new List <string>();
                    if (fileType == CompressedFileType.ArzFile)
                    {
                        this.dataGridView1.Visible  = true;
                        this.textBoxDetails.Visible = false;
                        this.record = arzProv.GetRecordNotCached(arzFile, this.destFile);
                        foreach (Variable variable in this.record)
                        {
                            if (variable.IsValueNonZero() || !hideZeroValuesToolStripMenuItem.Checked)
                            {
                                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 = arcProv.GetData(arcFile, 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);
                                }
                            }

                            this.dataGridView1.Visible  = false;
                            this.textBoxDetails.Visible = true;
                        }
                        else if (extension == ".TEX")
                        {
                            byte[] rawData = arcProv.GetData(arcFile, arcDataPath);

                            if (rawData == null)
                            {
                                return;
                            }

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

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

                    // Now display our results.
                    if (recordText.Count != 0)
                    {
                        this.pictureBoxItem.Visible = false;
                        if (fileType == CompressedFileType.ArzFile)
                        {
                            this.textBoxDetails.Visible = false;
                            this.dataGridView1.Visible  = true;
                            PopulateGridView(recordText);
                        }
                        else
                        {
                            this.dataGridView1.Visible  = false;
                            this.textBoxDetails.Visible = true;
                            string[] output = new string[recordText.Count];
                            recordText.CopyTo(output);
                            this.textBoxDetails.Lines = output;
                        }
                    }
                    else
                    {
                        this.textBoxDetails.Lines = null;
                    }
                }
                catch (Exception ex)
                {
                    this.Log.ErrorException(ex);
                }
            }
            else
            {
                this.destFile             = null;
                this.textBoxDetails.Lines = null;
            }
        }