private Int32 ReplaceAll(IFFFile.IFFNode iffNode, ref Int32 replacements)
        {
            ByteCollection byteCollection = new ByteCollection(iffNode.Data);
              Int32 startIndex = this.Find(iffNode);
              Int32 lastStartIndex = -1;
              while (startIndex >= 0) {
            this.Replace(startIndex, byteCollection);
            replacements++;
            lastStartIndex = startIndex;
            startIndex = this.Find(iffNode, (startIndex + ((this.GetReplaceBytes() != null) ? this.GetReplaceBytes().Length : 0)));
              }
              iffNode.Data = byteCollection.ToArray();

              return lastStartIndex;
        }
 private Int32 Find(IFFFile.IFFNode iffNode)
 {
     return this.Find(iffNode, 0);
 }
 private Int32 Find(IFFFile.IFFNode iffNode, Int32 startIndex)
 {
     Int32 returnValue = -1;
       if ((iffNode == null) || (iffNode.ID.Contains("FORM")) || (iffNode.Data == null)) {
     returnValue = -1;
       } else if (this.tabControl.SelectedTab == this.tabPageString) {
     returnValue = this.m_FormIFFILFWSEditor.Find(this.GetFindString(), iffNode.Data, startIndex, !this.checkBoxMatchCase.Checked);
       } else if (this.tabControl.SelectedTab == this.tabPageHexadecimal) {
     returnValue = this.m_FormIFFILFWSEditor.Find(this.GetFindBytes(), iffNode.Data, startIndex);
       }
       return returnValue;
 }
        protected override void OnVisibleChanged(EventArgs e)
        {
            base.OnVisibleChanged(e);

              if (!this.Visible) {
            this.m_IFFFile = null;
            this.dataGridViewIff.DataSource = null;
            this.m_ILFFile = null;
            this.m_WSFile = null;
            if (this.m_DynamicByteProviderWS != null) {
              this.m_DynamicByteProviderWS = null;
            }
            if (this.m_DynamicByteProviderIFF != null) {
              this.m_DynamicByteProviderIFF = null;
            }
            this.treeViewIff.Nodes.Clear();
            this.toolStripButtonIffSave.Enabled = false;
            this.toolStripButtonIffSaveAs.Enabled = false;
              } else {
            this.hexBoxIff_Resize(this.hexBoxIff, new EventArgs());
              }
        }
 private TreeNode CreateIFFNode(IFFFile.IFFNode iffNode, TreeNode treeBranch)
 {
     TreeNode treeNode = new TreeNode(iffNode.ID);
       if (iffNode.ID.Contains("FORM")) {
     treeNode.ImageIndex = 1;
       } else {
     treeNode.ImageIndex = 0;
       }
       treeBranch.Nodes.Add(treeNode);
       return treeNode;
 }
        private void WSLoadFile(String filename)
        {
            this.treeViewIff.ContextMenuStrip = null;

              this.splitContainerIff.Visible = false;
              this.dataGridViewIff.Visible = false;
              this.panelIlf.Visible = false;
              this.hexBoxIff.Visible = false;
              this.m_IFFFile = null;
              this.m_ILFFile = null;

              this.m_WSFile = new WSFile(filename);

              try {
            this.HasChangesChanged -= new HasChangesChangedEvent(FormIFFILFWSEditor_HasChangesChanged);
              } catch {
              }

              if ((this.m_WSFile != null) && (this.m_WSFile.Filename != null) && (this.m_WSFile.Filename != String.Empty)) {
            if (!this.m_WSFile.Filename.Contains("\\")) {
              this.m_WSFile.Filename = Path.Combine(this.m_FormNotifyIcon.saveFileDialog.InitialDirectory, this.m_WSFile.Filename);
            } else if (this.m_WSFile.Filename.StartsWith(Path.GetTempPath())) {
              this.m_WSFile.Filename = Path.Combine(this.m_FormNotifyIcon.saveFileDialog.InitialDirectory, this.m_WSFile.Filename.Substring(Path.GetTempPath().Length));
            }
              }

              this.comboBoxWsObject.SuspendLayout();
              this.comboBoxWsObject.Items.Clear();
              this.comboBoxWsObject.Items.AddRange(this.m_WSFile.Types);
              this.comboBoxWsObject.ResumeLayout(false);

              this.treeViewIff.SuspendLayout();
              this.treeViewIff.Nodes.Clear();
              TreeNode treeNode = new TreeNode();
              treeNode.Name = "WSNPFORM";
              treeNode.Text = "WSNPFORM";
              treeNode.ImageIndex = 1;
              this.treeViewIff.Nodes.Add(treeNode);
              this.WSRecurseNode(m_WSFile.Nodes.ToArray(), this.treeViewIff.Nodes[0]);
              this.treeViewIff.ResumeLayout(false);
              this.splitContainerIff.Visible = true;
              this.panelWs.Visible = true;
              this.toolStripButtonIffManageItems.Visible = true;

              this.toolStripButtonIffSaveAs.Enabled = true;

              this.HasChanges = false;
              this.HasChangesChanged += new HasChangesChangedEvent(FormIFFILFWSEditor_HasChangesChanged);
        }
        internal void IFFLoadFile(String filename)
        {
            this.treeViewIff.ContextMenuStrip = null;

              if (filename.ToLower().EndsWith(".ilf")) {
            this.ILFLoadFile(filename);
            return;
              }

              if (filename.ToLower().EndsWith(".ws")) {
            this.WSLoadFile(filename);
            return;
              }

              this.m_ILFFile = null;
              this.m_WSFile = null;

              try {
            try {
              this.m_IFFFile = new IFFFile(filename);
            } catch (Exception exception) {
              MessageBox.Show(exception.Message, "TRE Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
              this.Visible = false;
              return;
            }

            try {
              this.HasChangesChanged -= new HasChangesChangedEvent(FormIFFILFWSEditor_HasChangesChanged);
            } catch {
            }

            if ((this.m_IFFFile != null) && (this.m_IFFFile.Filename != null) && (this.m_IFFFile.Filename != String.Empty)) {
              if (!this.m_IFFFile.Filename.Contains("\\")) {
            this.m_IFFFile.Filename = Path.Combine(this.m_FormNotifyIcon.saveFileDialog.InitialDirectory, this.m_IFFFile.Filename);
              } else if (this.m_IFFFile.Filename.StartsWith(Path.GetTempPath())) {
            this.m_IFFFile.Filename = Path.Combine(this.m_FormNotifyIcon.saveFileDialog.InitialDirectory, this.m_IFFFile.Filename.Substring(Path.GetTempPath().Length));
              }
            }

            this.splitContainerIff.Visible = false;
            this.dataGridViewIff.Visible = false;
            this.panelIlf.Visible = false;
            this.panelWs.Visible = false;
            this.hexBoxIff.Visible = false;
            this.m_ILFFile = null;
            this.hexBoxIff.ByteProvider = null;
            this.m_DynamicByteProviderIFF = null;
            this.toolStripSeparator3.Visible = false;
            this.toolStripTextBoxSearch.Visible = false;
            this.toolStripButtonSearch.Visible = false;

            if (this.m_IFFFile.IsDataTable) {
              this.dataGridViewIff.DataSource = this.m_IFFFile.DataTable;
              this.dataGridViewIff.Visible = true;
            } else {
              this.treeViewIff.ContextMenuStrip = this.contextMenuStripTreeViewIFF;

              this.treeViewIff.Nodes.Clear();
              IFFRecurseNode(this.m_IFFFile.Node, CreateIFFNode(this.m_IFFFile.Node));

              this.splitContainerIff.Visible = true;
              this.hexBoxIff.Visible = true;

              this.treeViewIff.SelectedNode = this.treeViewIff.Nodes[0];
            }

            this.toolStripButtonIffSaveAs.Enabled = true;

            this.HasChanges = false;
            this.HasChangesChanged += new HasChangesChangedEvent(FormIFFILFWSEditor_HasChangesChanged);

            this.Focus();
              } catch (Exception exception) {
            MessageBox.Show(exception.Message, "TRE Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
            this.Visible = false;
              }
        }
 private void IFFRecurseNode(IFFFile.IFFNode iffNode, TreeNode treeNode)
 {
     this.treeViewIff.AfterSelect -= new TreeViewEventHandler(treeViewIff_AfterSelect);
       this.treeViewIff.SuspendLayout();
       foreach (IFFFile.IFFNode iffChild in iffNode.Children) {
     if (iffChild.Children.Count > 0) {
       IFFRecurseNode(iffChild, CreateIFFNode(iffChild, treeNode));
     } else {
       CreateIFFNode(iffChild, treeNode);
     }
       }
       this.treeViewIff.ResumeLayout(false);
       this.treeViewIff.AfterSelect += new TreeViewEventHandler(treeViewIff_AfterSelect);
 }
        private void ILFLoadFile(String filename)
        {
            this.treeViewIff.ContextMenuStrip = null;

              try {
            this.HasChangesChanged -= new HasChangesChangedEvent(FormIFFILFWSEditor_HasChangesChanged);
              } catch {
              }

              this.splitContainerIff.Visible = false;
              this.dataGridViewIff.Visible = false;
              this.panelIlf.Visible = false;
              this.panelWs.Visible = false;
              this.hexBoxIff.Visible = false;
              this.m_IFFFile = null;
              this.m_WSFile = null;

              try {
            this.m_ILFFile = new ILFFile(filename);

            if ((this.m_ILFFile != null) && (this.m_ILFFile.Filename != null) && (this.m_ILFFile.Filename != String.Empty)) {
              if (!this.m_ILFFile.Filename.Contains("\\")) {
            this.m_ILFFile.Filename = Path.Combine(this.m_FormNotifyIcon.saveFileDialog.InitialDirectory, this.m_ILFFile.Filename);
              } else if (this.m_ILFFile.Filename.StartsWith(Path.GetTempPath())) {
            this.m_ILFFile.Filename = Path.Combine(this.m_FormNotifyIcon.saveFileDialog.InitialDirectory, this.m_ILFFile.Filename.Substring(Path.GetTempPath().Length));
              }
            }

            this.treeViewIff.SuspendLayout();
            this.treeViewIff.Nodes.Clear();
            this.treeViewIff.Nodes.Add("INLYFORM", "INLYFORM");
            this.treeViewIff.Nodes[0].ImageIndex = 1;

            foreach (ILFFile.ILFNode ilfChunk in this.m_ILFFile.Nodes) {
              TreeNode treeNode = new TreeNode(ilfChunk.Object);
              treeNode.Name = ilfChunk.Object;
              treeNode.Tag = ilfChunk.Object;
              this.treeViewIff.Nodes[0].Nodes.Add(treeNode);
            }
            this.treeViewIff.ResumeLayout(false);
            this.splitContainerIff.Visible = true;
            this.panelIlf.Visible = true;

            this.toolStripButtonIffSaveAs.Enabled = true;

            this.HasChanges = false;
            this.HasChangesChanged += new HasChangesChangedEvent(FormIFFILFWSEditor_HasChangesChanged);
              } catch {
              }
        }
Beispiel #10
0
            public IFFDataTable(IFFFile IFFFile)
            {
                this.m_IFFFile = IFFFile;

                MemoryStream memoryStream = new MemoryStream(this.m_IFFFile.Node.Data);
                BinaryReader binaryReader = new BinaryReader(memoryStream);

                // FORM
                /* String ID = new String(binaryReader.ReadChars(4));
                if (ID != "FORM") {
                  return null;
                }
                UInt32 formLength = Utilities.EndianFlip(binaryReader.ReadUInt32()); */

                // DTIIFORM
                String ID = new String(binaryReader.ReadChars(8));
                if (ID != "DTIIFORM") {
                  return;
                }
                UInt32 dtiiformLength = Utilities.EndianFlip(binaryReader.ReadUInt32());

                // 0001
                String t0001 = new String(binaryReader.ReadChars(4));

                // COLS
                ID = new String(binaryReader.ReadChars(4));
                if (ID != "COLS") {
                //  return;
                }
                UInt32 colsLength = Utilities.EndianFlip(binaryReader.ReadUInt32());
                Int32 colsCount = binaryReader.ReadInt32();
                Byte[] buffer = binaryReader.ReadBytes((Int32)colsLength - 4);
                String[] colsCaptions = Utilities.ReadStrings(buffer, colsCount);

                // TYPE
                ID = new String(binaryReader.ReadChars(4));
                if (ID != "TYPE") {
                 // return;
                }
                UInt32 typeLength = Utilities.EndianFlip(binaryReader.ReadUInt32());
                buffer = binaryReader.ReadBytes((Int32)typeLength);
                String[] types = Utilities.ReadStrings(buffer, colsCount);
                this.m_Types = types;

                // ROWS
                ID = new String(binaryReader.ReadChars(4));
                if (ID != "ROWS") {
                 // return;
                }
                UInt32 rowsLength = Utilities.EndianFlip(binaryReader.ReadUInt32());
                Int32 rowsCount = binaryReader.ReadInt32();

                // Determine column types and generate columns
                for (Int32 counter = 0; counter < colsCount; counter++) {
                  Type type = typeof(String);
                  String caption = colsCaptions[counter];
                  if (types[counter][0] == 's') {
                type = typeof(String);
                  }
                  else if (types[counter][0] == 'b')
                  {
                type = typeof(Boolean);
                  }
                  else if (types[counter][0] == 'i')
                  {
                type = typeof(Int32);
                  }
                  else if (types[counter][0] == 'I')
                  {
                type = typeof(Int32);
                  }
                  else if (types[counter][0] == 'f')
                  {
                type = typeof(Single);
                  }
                  else if (types[counter][0] == 'e')
                  { // enum, TBI
                type = typeof(Int32);
                caption = types[counter];
                  }
                  else if (types[counter][0] == 'h')
                  { // ?, TBI
                type = typeof(Int32);
                  }
                  else if (types[counter][0] == 'z')
                  { // z(other.iff),foreign key ?, TBI
                  type = typeof(Int32);
                  }
                  else
                  {
                  type = typeof(Int32);
                  }
                  // for enum type (IFF type = 'e') we return the enum definition in the Caption field of the columns
                  // todo: parse the enum definition instead and replace values with the enum members
                  this.Columns.Add(colsCaptions[counter], type).Caption = caption;
                }

                // Generate rows
                for (Int32 counter1 = 0; counter1 < rowsCount; counter1++) {
                  try {
                DataRow dataRow = this.NewRow();
                for (Int32 counter2 = 0; counter2 < colsCount; counter2++) {
                  if (types[counter2][0] == 's') {
                dataRow[counter2] = Utilities.ReadString(binaryReader);
                  }
                  else if (types[counter2][0] == 'b')
                  {
                Int32 b = binaryReader.ReadInt32();
                dataRow[counter2] = (b != 0);
                  }
                  else if (types[counter2][0] == 'i')
                  {
                dataRow[counter2] = binaryReader.ReadInt32();
                  }
                  else if (types[counter2][0] == 'I')
                  {
                dataRow[counter2] = binaryReader.ReadInt32();
                  }
                  else if (types[counter2][0] == 'f')
                  {
                dataRow[counter2] = binaryReader.ReadSingle();
                  }
                  else if (types[counter2][0] == 'e')
                  {
                dataRow[counter2] = binaryReader.ReadInt32();
                  }
                  else if (types[counter2][0] == 'h')
                  {
                dataRow[counter2] = binaryReader.ReadInt32();
                  }
                  else if (types[counter2][0] == 'z') {
                dataRow[counter2] = binaryReader.ReadInt32();
                  }
                  else
                  {
                  dataRow[counter2] = binaryReader.ReadInt32();
                  }
                }
                this.Rows.Add(dataRow);
                  } catch {
                // an exception has occurred
                  }
                }

                binaryReader.Close();
                memoryStream.Close();
            }
Beispiel #11
0
        private String[] FollowChain(String[] IFFFilenames)
        {
            List<String> returnValue = new List<String>();

            foreach (String IFFFilename in IFFFilenames)
            {
                if (m_EventStop.WaitOne(0, true))
                {
                    m_EventStopped.Set();

                    return null;
                }

                if ((IFFFilename != null) && (IFFFilename != String.Empty) && (!this.totalFilenames.Contains(IFFFilename)))
                {
                    this.totalFilenames.Add(IFFFilename);
                }

                if ((IFFFilename != null) && (IFFFilename != String.Empty) && (!this.parsedFilenames.Contains(IFFFilename)))
                {
                    this.parsedFilenames.Add(IFFFilename);

                    Int32 progress = (Int32)(((Single)this.parsedFilenames.Count / (Single)this.totalFilenames.Count) * 100F);
                    if (this.lastProgress != progress)
                    {
                        this.m_form.Invoke(this.m_form.delegateSetProgress, new Object[] { new Int32[] { progress, 0 } });
                        this.lastProgress = progress;
                    }

                    String caption = "Constructing File Chain - " + progress + "%";
                    if (this.lastCaption != caption)
                    {
                        this.m_form.Invoke(this.m_form.delegateSetCaption, new Object[] { caption });
                        this.lastCaption = caption;
                    }

                    String label = "Scanning " + IFFFilename + "…";
                    if (this.lastLabel != label)
                    {
                        this.m_form.Invoke(this.m_form.delegateSetLabel, new Object[] { label });
                        this.lastLabel = label;
                    }

                    DataRow[] dataRows = null;
                    try
                    {
                        dataRows = this.m_DataTable.Select("Name = '" + IFFFilename + "'");
                    }
                    catch
                    {
                        continue;
                    }
                    if ((dataRows == null) || (dataRows.Length <= 0))
                    {
                        continue;
                    }

                    this.ExtractTable.Rows.Add(dataRows[0].ItemArray);

                    Byte[] buffer = Utilities.InflateFile(dataRows[0]);
                    if ((buffer.Length < 4) || (buffer[0] != (Byte)'F') || (buffer[1] != (Byte)'O') || (buffer[2] != (Byte)'R') || (buffer[3] != (Byte)'M'))
                    {
                        continue;
                    }

                    IFFFile iffFile = null;
                    try
                    {
                        iffFile = new IFFFile(buffer);
                    }
                    catch
                    {
                        continue;
                    }

                    if ((iffFile == null) || (iffFile.IsDataTable))
                    {
                        continue;
                    }

                    String[] filenames = null;
                    try
                    {
                        this.parsedNodes = 0;
                        this.totalNodes = 0;
                        filenames = FollowChain(new IFFFile.IFFNode[] { iffFile.Node });
                    }
                    catch
                    {
                        continue;
                    }

                    if (filenames != null)
                    {
                        foreach (String filename in filenames)
                        {
                            if (m_EventStop.WaitOne(0, true))
                            {
                                m_EventStopped.Set();

                                return null;
                            }

                            if (!returnValue.Contains(filename))
                            {
                                returnValue.Add(filename);
                            }
                        }
                    }
                }
            }

            if (returnValue.Count > 0)
            {
                String[] tempFilenames = FollowChain(returnValue.ToArray());
                if (tempFilenames != null)
                {
                    foreach (String tempFilename in tempFilenames)
                    {
                        if (m_EventStop.WaitOne(0, true))
                        {
                            m_EventStopped.Set();

                            return null;
                        }

                        if ((!this.parsedFilenames.Contains(tempFilename)) && (!returnValue.Contains(tempFilename)))
                        {
                            returnValue.Add(tempFilename);
                        }
                    }
                }

                return returnValue.ToArray();
            }
            else
            {
                return null;
            }
        }
Beispiel #12
0
        private String[] FollowChain(IFFFile.IFFNode[] iffNodes)
        {
            List<String> returnValue = new List<String>();
            Int32 lastFileProgress = -1;
            this.totalNodes += iffNodes.Length;

            foreach (IFFFile.IFFNode iffNode in iffNodes)
            {
                if (m_EventStop.WaitOne(0, true))
                {
                    m_EventStopped.Set();

                    return null;
                }

                if ((!iffNode.ID.Contains("FORM")) && (iffNode.Data != null) && (iffNode.Data.Length > 4))
                {
                    List<Byte> byteList = new List<Byte>(iffNode.Data);
                    if ((!byteList.Contains((Byte)'\\')) && (!byteList.Contains((Byte)'/')))
                    {
                        continue;
                    }

                    StringBuilder stringBuilder = new StringBuilder();
                    Int32 totalBytes = iffNode.Data.Length;
                    Int32 parsedBytes = 0;
                    foreach (Byte character in iffNode.Data)
                    {
                        if (m_EventStop.WaitOne(0, true))
                        {
                            m_EventStopped.Set();

                            return null;
                        }

                        parsedBytes++;

                        if (this.VALID_CHARACTERS.Contains((Char)character))
                        {
                            stringBuilder.Append((Char)character);
                        }

                        if ((!this.VALID_CHARACTERS.Contains((Char)character)) || (parsedBytes == totalBytes))
                        {
                            if ((stringBuilder.Length > 3) && ((stringBuilder.ToString().Contains("/")) || (stringBuilder.ToString().Contains("\\"))))
                            {
                                String filename = stringBuilder.ToString().Replace('\\', '/');
                                Boolean found = false;

                                while (filename.Length > 0)
                                {
                                    if (m_EventStop.WaitOne(0, true))
                                    {
                                        m_EventStopped.Set();

                                        return null;
                                    }

                                    DataRow[] dataRows = null;
                                    try
                                    {
                                        dataRows = this.m_DataTable.Select("Name = '" + filename + "'");
                                    }
                                    catch
                                    {
                                        dataRows = null;
                                    }

                                    if ((dataRows != null) && (dataRows.Length > 0))
                                    {
                                        found = true;
                                        if (!returnValue.Contains(filename))
                                        {
                                            returnValue.Add(filename);
                                        }
                                        if (!this.totalFilenames.Contains(filename))
                                        {
                                            this.totalFilenames.Add(filename);
                                        }
                                        break;
                                    }
                                    else
                                    {
                                        filename = filename.Substring(1);
                                    }
                                }

                                if (!found)
                                {
                                    filename = stringBuilder.ToString().Replace('\\', '/');
                                    DataRow[] dataRows = null;
                                    try
                                    {
                                        dataRows = this.m_DataTable.Select("Name LIKE '%" + ((filename.StartsWith("/")) ? String.Empty : "/") + filename + "'");
                                    }
                                    catch
                                    {
                                        dataRows = null;
                                    }
                                    if ((dataRows != null) && (dataRows.Length > 0))
                                    {
                                        for (Int32 counter = 0; counter < dataRows.Length; counter++)
                                        {
                                            if ((String)dataRows[counter]["File_Type"] != "File Folder")
                                            {
                                                filename = (String)dataRows[counter]["Name"];
                                                if (!returnValue.Contains(filename))
                                                {
                                                    returnValue.Add(filename);
                                                }
                                                if (!this.totalFilenames.Contains(filename))
                                                {
                                                    this.totalFilenames.Add(filename);
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            stringBuilder = new StringBuilder();
                        }
                    }
                }
                else if (iffNode.Children.Count > 0)
                {
                    String[] tempFilenames = null;
                    try
                    {
                        tempFilenames = FollowChain(iffNode.Children.ToArray());
                    }
                    catch
                    {
                        tempFilenames = null;
                    }
                    if (tempFilenames != null)
                    {
                        foreach (String tempFilename in tempFilenames)
                        {
                            if (m_EventStop.WaitOne(0, true))
                            {
                                m_EventStopped.Set();

                                return null;
                            }

                            if (!returnValue.Contains(tempFilename))
                            {
                                returnValue.Add(tempFilename);
                            }
                            if (!this.totalFilenames.Contains(tempFilename))
                            {
                                this.totalFilenames.Add(tempFilename);
                            }
                        }
                    }
                }

                this.parsedNodes++;

                Int32 progress = (Int32)(((Single)this.parsedNodes / (Single)this.totalNodes) * 100F);
                if (progress != lastFileProgress)
                {
                    lastFileProgress = progress;
                    this.m_form.Invoke(this.m_form.delegateSetProgress, new Object[] { new Int32[] { this.lastProgress, progress } });
                }
            }

            return returnValue.ToArray();
        }
Beispiel #13
0
 private void PreviewOther(DataRow dataRow)
 {
     HidePreviewControls();
     this.toolStripButtonIffEditFile.Image = TRE_Explorer.Properties.Resources.Edit_IFF;
     Byte[] buffer = Utilities.InflateFile(dataRow);
     if ((buffer != null) && (buffer.Length > 0))
     {
         this.textBoxPreview.Visible = true;
         this.textBoxPreview.BringToFront();
         this.textBoxPreview.Text = this.ASCIIDump(buffer);
         if (this.textBoxPreview.Text.StartsWith("FORM"))
         {
             this.toolStripIffPreview.Visible = true;
             this.m_IFFFilePreview = new IFFFile(buffer);
         }
         else
         {
             this.toolStripIffPreview.Visible = false;
             this.m_IFFFilePreview = null;
         }
     }
 }
Beispiel #14
0
        private void listView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.m_DataViewListView != null)
            {
                if ((this.listView.SelectedIndices.Count > 0) && (this.listView.SelectedIndices[0] < this.m_DataViewListView.Count))
                {
                    DataRow dataRow = this.m_DataViewListView[this.listView.SelectedIndices[0]].Row;
                    String name = (String)dataRow["Name"];
                    this.toolStripButtonExport.Enabled = true;

                    if (this.listView.SelectedIndices.Count == 1)
                    {
                        if ((this.m_LastPreviewed != this.listView.SelectedIndices[0]) && ((String)dataRow["File_Type"] != "File Folder"))
                        {
                            this.m_IFFFilePreview = null;
                            this.m_PALFilePreview = null;
                            this.m_STFFilePreview = null;

                            this.m_LastPreviewed = this.listView.SelectedIndices[0];
                            if ((name.ToLower().EndsWith(".dds")) || (name.ToLower().EndsWith(".tga")))
                            {
                                this.PreviewDDS(dataRow);
                            }
                            else if (name.ToLower().EndsWith(".iff"))
                            {
                                this.PreviewIFF(dataRow);
                            }
                            else if (name.ToLower().EndsWith(".stf"))
                            {
                                this.PreviewSTF(dataRow);
                            }
                            else if ((name.ToLower().EndsWith(".wav")) || (name.ToLower().EndsWith(".mp3")))
                            {
                                this.PreviewMP3WAV();
                            }
                            else if (name.ToLower().EndsWith(".pal"))
                            {
                                this.PreviewPAL(dataRow);
                            }
                            else if ((name.ToLower().EndsWith(".inc")) || (name.ToLower().EndsWith(".qst")))
                            {
                                this.PreviewINCQST(dataRow);
                            }
                            else
                            {
                                this.PreviewOther(dataRow);
                            }
                        }

                        Int32 imageIndex = this.ImageIndex(dataRow["File_Type"].ToString());
                        if (imageIndex != -1)
                        {
                            this.pictureBoxDetails.Image = new Bitmap(this.imageListLarge.Images[imageIndex], this.pictureBoxDetails.Width, this.pictureBoxDetails.Height);
                            name = name.Trim(new Char[] { '/' });
                            if (name.Contains("/"))
                            {
                                name = name.Substring(name.LastIndexOf("/") + 1);
                            }
                            if (dataRow["File_Type"].ToString() == "File Folder")
                            {
                                this.webBrowserDetails.DocumentText = "<BODY BGCOLOR=\"#" + String.Format("{0:X}", SystemColors.Control.R) + String.Format("{0:X}", SystemColors.Control.G) + String.Format("{0:X}", SystemColors.Control.B) + "\"><FONT FACE=\"Microsoft Sans Serif\" SIZE=\"2\">" + ((TRE_Explorer.Properties.Settings.Default.DetailsDisplaysFullPath) ? ((String)dataRow["Name"]).Trim() : name).TrimStart(new Char[] { '/' }) + "<BR>" + dataRow["File_Type"].ToString() + "</FONT></BODY>";
                            }
                            else
                            {
                                this.webBrowserDetails.DocumentText = "<BODY BGCOLOR=\"#" + String.Format("{0:X}", SystemColors.Control.R) + String.Format("{0:X}", SystemColors.Control.G) + String.Format("{0:X}", SystemColors.Control.B) + "\"><TABLE HEIGHT=\"*\" WIDTH=\"*\" BORDER=\"0\" CELPADDING=\"1\" CELLSPACING=\"1\"><TR VALIGN=\"TOP\"><TD ALIGN=\"LEFT\" NOWRAP><FONT FACE=\"Microsoft Sans Serif\" SIZE=\"2\">" + ((TRE_Explorer.Properties.Settings.Default.DetailsDisplaysFullPath) ? ((String)dataRow["Name"]).Trim() : name) + "<BR>" + dataRow["File_Type"].ToString() + "</FONT></TD><TD ALIGN=\"RIGHT\" NOWRAP><FONT COLOR=\"#888888\" FACE=\"Microsoft Sans Serif\" SIZE=\"2\">Size: <BR>Container: <BR>Compressed Size: </FONT></TD><TD ALIGN=\"LEFT\" NOWRAP><FONT FACE=\"Microsoft Sans Serif\" SIZE=\"2\">" + Utilities.SizeToString((Int32)dataRow["Final_Size"]) + "<BR>" + ((String)dataRow["Filename"]).Substring(((String)dataRow["Filename"]).LastIndexOf("\\") + 1) + "<BR>" + Utilities.SizeToString((Int32)dataRow["Size"]) + "</FONT></TD></TR></TABLE></BODY>";
                            }
                        }
                    }
                    else if (this.listView.SelectedIndices.Count > 1)
                    {
                        HidePreviewControls();

                        try
                        {
                            /* this.pictureBoxDetails.Image = new Bitmap(this.pictureBoxDetails.Width, this.pictureBoxDetails.Height);
                            Graphics graphics = Graphics.FromImage(this.pictureBoxDetails.Image);
                            foreach (Int32 index in this.listView.SelectedIndices) {
                              Int32 imageIndex = this.ImageIndex(this.dataViewListView[index]["file_type"].ToString());
                              if (imageIndex != -1) {
                                graphics.DrawImage(this.imageListLarge.Images[imageIndex], 0, 0, this.pictureBoxDetails.Width, this.pictureBoxDetails.Height);
                              }
                            } */
                            this.pictureBoxDetails.Image = this.imageListLarge.Images[this.ImageIndex((String)dataRow["File_Type"])];
                        }
                        catch
                        {
                        }

                        this.webBrowserDetails.DocumentText = "<BODY BGCOLOR=\"#" + String.Format("{0:X}", SystemColors.Control.R) + String.Format("{0:X}", SystemColors.Control.G) + String.Format("{0:X}", SystemColors.Control.B) + "\"><FONT FACE=\"Microsoft Sans Serif\" SIZE=\"2\">" + String.Format("{0:n0}", this.listView.SelectedIndices.Count) + " item" + ((this.listView.SelectedIndices.Count == 1) ? "" : "s") + " selected</FONT></BODY>";
                    }
                }
                else
                {
                    HidePreviewControls();

                    this.pictureBoxDetails.Image = new Bitmap(this.imageListLarge.Images[0], this.pictureBoxDetails.Width, this.pictureBoxDetails.Height);
                    this.webBrowserDetails.DocumentText = "<BODY BGCOLOR=\"#" + String.Format("{0:X}", SystemColors.Control.R) + String.Format("{0:X}", SystemColors.Control.G) + String.Format("{0:X}", SystemColors.Control.B) + "\"><FONT FACE=\"Microsoft Sans Serif\" SIZE=\"2\">" + String.Format("{0:n0}", this.m_DataViewListView.Count) + " item" + ((this.m_DataViewListView.Count == 1) ? "" : "s") + "</FONT></BODY>";
                }
            }
            else
            {
                HidePreviewControls();

                this.pictureBoxDetails.Image = new Bitmap(this.pictureBoxDetails.Width, this.pictureBoxDetails.Height);
                this.webBrowserDetails.DocumentText = "<BODY BGCOLOR=\"#" + String.Format("{0:X}", SystemColors.Control.R) + String.Format("{0:X}", SystemColors.Control.G) + String.Format("{0:X}", SystemColors.Control.B) + "\"></BODY>";
            }

            this.toolStripButtonExport.Enabled = (this.listView.SelectedIndices.Count > 0);
            this.toolStripButtonExportFileChain.Enabled = ((this.listView.SelectedIndices.Count == 1) && (this.m_IFFFilePreview != null) && (!this.m_IFFFilePreview.IsDataTable));
        }