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, 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);
        }
        private void buttonReplaceAll_Click(object sender, EventArgs e)
        {
            if ((GetFindBytes() != null) && (GetFindBytes().Length > 0))
            {
                this.m_FormIFFILFWSEditor.m_FindBufferIFF = this.GetFindBytes();
                this.m_FormIFFILFWSEditor.m_FindStringIFF = this.GetFindString();

                this.m_FormIFFILFWSEditor.m_CaseInsensitive = ((this.tabControl.SelectedTab == this.tabPageString) ? !this.checkBoxMatchCase.Checked : false);
                this.m_FormIFFILFWSEditor.m_SearchAllNodes  = (this.comboBoxSearchIn.Text == "All Nodes");
                this.m_FormIFFILFWSEditor.m_StringSearch    = (this.tabControl.SelectedTab == this.tabPageString);

                TreeNode treeNode = null;
                try {
                    treeNode = ((this.m_FormIFFILFWSEditor.m_SearchAllNodes) ? this.m_FormIFFILFWSEditor.treeViewIff.Nodes[0] : this.m_FormIFFILFWSEditor.treeViewIff.SelectedNode);
                } catch {
                    MessageBox.Show("You must first load a file.", "TRE Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                IFFFile.IFFNode iffNode        = this.m_FormIFFILFWSEditor.FindIFFNode(treeNode);
                Int32           startIndex     = this.Find(iffNode);
                Int32           lastStartIndex = -1;
                Int32           replacements   = 0;

                if ((!(startIndex >= 0)) && (!this.m_FormIFFILFWSEditor.m_SearchAllNodes))
                {
                    MessageBox.Show("Value not found.", "TRE Explorer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (!this.m_FormIFFILFWSEditor.m_SearchAllNodes)
                {
                    lastStartIndex = this.ReplaceAll(iffNode, ref replacements);

                    this.m_FormIFFILFWSEditor.m_DynamicByteProviderIFF = new DynamicByteProvider(iffNode.Data);
                    this.m_FormIFFILFWSEditor.hexBoxIff.ByteProvider   = this.m_FormIFFILFWSEditor.m_DynamicByteProviderIFF;

                    if ((this.GetReplaceBytes() != null) && (this.GetReplaceBytes().Length > 0))
                    {
                        this.m_FormIFFILFWSEditor.hexBoxIff.Find(this.GetReplaceBytes(), lastStartIndex);
                    }
                    else
                    {
                        this.m_FormIFFILFWSEditor.hexBoxIff.SelectionStart  = lastStartIndex;
                        this.m_FormIFFILFWSEditor.hexBoxIff.SelectionLength = 0;
                    }
                    MessageBox.Show(replacements + " replacement" + ((replacements == 1) ? String.Empty : "s") + " made.", "TRE Explorer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (this.m_FormIFFILFWSEditor.m_SearchAllNodes)
                {
                    TreeNode lastTreeNode = null;
                    while (treeNode != null)
                    {
                        iffNode    = this.m_FormIFFILFWSEditor.FindIFFNode(treeNode);
                        startIndex = this.Find(iffNode);
                        if (startIndex >= 0)
                        {
                            lastStartIndex = this.ReplaceAll(iffNode, ref replacements);
                            lastTreeNode   = treeNode;
                        }
                        treeNode = this.m_FormIFFILFWSEditor.NextNode(treeNode, false);
                    }
                    if (lastTreeNode != null)
                    {
                        if (this.m_FormIFFILFWSEditor.treeViewIff.SelectedNode != lastTreeNode)
                        {
                            this.m_FormIFFILFWSEditor.treeViewIff.SelectedNode = lastTreeNode;
                        }
                        else
                        {
                            this.m_FormIFFILFWSEditor.m_DynamicByteProviderIFF = new DynamicByteProvider(this.m_FormIFFILFWSEditor.FindIFFNode(lastTreeNode).Data);
                            this.m_FormIFFILFWSEditor.hexBoxIff.ByteProvider   = this.m_FormIFFILFWSEditor.m_DynamicByteProviderIFF;
                        }
                        if ((this.GetReplaceBytes() != null) && (this.GetReplaceBytes().Length > 0))
                        {
                            this.m_FormIFFILFWSEditor.hexBoxIff.Find(this.GetReplaceBytes(), lastStartIndex);
                        }
                        else
                        {
                            this.m_FormIFFILFWSEditor.hexBoxIff.SelectionStart  = lastStartIndex;
                            this.m_FormIFFILFWSEditor.hexBoxIff.SelectionLength = 0;
                        }
                        MessageBox.Show(replacements + " replacement" + ((replacements == 1) ? String.Empty : "s") + " made.", "TRE Explorer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Value not found.", "TRE Explorer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            else
            {
                MessageBox.Show("You must first enter a value to find.", "TRE Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private Int32 Find(IFFFile.IFFNode iffNode)
 {
     return(this.Find(iffNode, 0));
 }