コード例 #1
0
        /// <summary>
        /// Reads data from an ARC file and puts it into a Byte array
        /// </summary>
        /// <param name="arcFileName">Name of the arc file.</param>
        /// <param name="dataId">Id of data which we are getting from the arc file</param>
        /// <returns>Byte array of the data from the arc file.</returns>
        private byte[] ReadARCFile(string arcFileName, string dataId)
        {
            // See if we have this arcfile already and if not create it.
            try
            {
                if (TQDebug.DatabaseDebugLevel > 0)
                {
                    Log.LogDebug("Database.ReadARCFile('{0}', '{1}')", arcFileName, dataId);
                }

                ArcFile arcFile = this.arcFiles.GetOrAddAtomic(arcFileName, k =>
                {
                    var file = new ArcFile(k);
                    arcProv.ReadARCToC(file);                    // Heavy lifting in GetOrAddAtomic
                    return(file);
                });

                // Now retrieve the data
                byte[] ans = arcProv.GetData(arcFile, dataId);

                if (TQDebug.DatabaseDebugLevel > 0)
                {
                    Log.LogDebug("Exiting Database.ReadARCFile()");
                }

                return(ans);
            }
            catch (Exception e)
            {
                Log.LogError(e, "Exception occurred");
                throw;
            }
        }
コード例 #2
0
ファイル: Database.cs プロジェクト: odd-sky/TQVaultAE
        /// <summary>
        /// Reads data from an ARC file and puts it into a Byte array
        /// </summary>
        /// <param name="arcFileName">Name of the arc file.</param>
        /// <param name="dataId">Id of data which we are getting from the arc file</param>
        /// <returns>Byte array of the data from the arc file.</returns>
        private byte[] ReadARCFile(string arcFileName, string dataId)
        {
            // See if we have this arcfile already and if not create it.
            try
            {
                if (TQDebug.DatabaseDebugLevel > 0)
                {
                    Log.DebugFormat(CultureInfo.InvariantCulture, "Database.ReadARCFile('{0}', '{1}')", arcFileName, dataId);
                }

                ArcFile arcFile;

                if (arcFiles.ContainsKey(arcFileName))
                {
                    arcFile = this.arcFiles[arcFileName];
                }
                else
                {
                    arcFile = new ArcFile(arcFileName);
                    this.arcFiles.Add(arcFileName, arcFile);
                }

                // Now retrieve the data
                byte[] ans = arcProv.GetData(arcFile, dataId);

                if (TQDebug.DatabaseDebugLevel > 0)
                {
                    Log.Debug("Exiting Database.ReadARCFile()");
                }

                return(ans);
            }
            catch (Exception e)
            {
                Log.Error("Exception occurred", e);
                throw;
            }
        }
コード例 #3
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;
            }
        }