private void btnReplaceReplace_Click(object sender, EventArgs e)
        {
            if (AllFiles == true)
            {
                //Checks All filenames for searched term. Gets to the parent node, checks all the children nodes, their tags, filenames, etc. for the term.

                //Goes to top node to begin iteration.
                TreeNode tn = Mainfrm.FindRootNode(Mainfrm.TreeSource.SelectedNode);
                Mainfrm.TreeSource.SelectedNode = tn;

                List <TreeNode> Nodes = new List <TreeNode>();
                Mainfrm.AddChildren(Nodes, Mainfrm.TreeSource.SelectedNode);

                Mainfrm.TreeSource.BeginUpdate();

                int RenameCount = 0;

                foreach (TreeNode tno in Nodes)
                {
                    //Gets the node as a ArcEntryWrapper to allow access to all the variables and data.
                    ArcEntryWrapper awrapper = tno as ArcEntryWrapper;

                    if (awrapper != null)
                    {
                        if (awrapper.Tag as MaterialTextureReference == null || awrapper.Tag as LMTM3AEntry == null || awrapper.Tag as ModelBoneEntry == null ||
                            awrapper.Tag as MaterialMaterialEntry == null || awrapper.Tag as ModelGroupEntry == null || awrapper.Tag as Mission == null ||
                            awrapper.Tag as EffectNode == null)
                        {
                            {
                                if (awrapper.Tag as string != null)
                                {
                                    //Replaces the Term in the folder.
                                    string FolderName = awrapper.Tag as string;
                                    FolderName = FolderName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    tno.Text   = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    tno.Name   = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    RenameCount++;
                                }
                                else
                                {
                                    //Goes through the treenode to replace all the names of the node.
                                    ArcEntry              enty     = new ArcEntry();
                                    TextureEntry          tenty    = new TextureEntry();
                                    ResourcePathListEntry lrpenty  = new ResourcePathListEntry();
                                    MSDEntry              msdenty  = new MSDEntry();
                                    MaterialEntry         matent   = new MaterialEntry();
                                    LMTEntry              lmtenty  = new LMTEntry();
                                    ChainListEntry        cstenty  = new ChainListEntry();
                                    ChainEntry            chnenty  = new ChainEntry();
                                    ChainCollisionEntry   cclentry = new ChainCollisionEntry();
                                    ModelEntry            mdlentry = new ModelEntry();
                                    MissionEntry          misenty  = new MissionEntry();
                                    GemEntry              gementy  = new GemEntry();
                                    EffectListEntry       eflenty  = new EffectListEntry();

                                    if (tno.Tag as ArcEntry != null)
                                    {
                                        enty           = tno.Tag as ArcEntry;
                                        enty.EntryName = enty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        enty.TrueName  = enty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        enty.FileName  = enty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag        = enty;
                                        tno.Text       = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name       = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as TextureEntry != null)
                                    {
                                        tenty           = tno.Tag as TextureEntry;
                                        tenty.EntryName = tenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tenty.TrueName  = tenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tenty.FileName  = tenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag         = tenty;
                                        tno.Text        = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name        = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as ResourcePathListEntry != null)
                                    {
                                        lrpenty           = tno.Tag as ResourcePathListEntry;
                                        lrpenty.EntryName = lrpenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        lrpenty.TrueName  = lrpenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        lrpenty.FileName  = lrpenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = lrpenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as LMTEntry != null)
                                    {
                                        lmtenty           = tno.Tag as LMTEntry;
                                        lmtenty.EntryName = lmtenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        lmtenty.TrueName  = lmtenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        lmtenty.FileName  = lmtenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = lmtenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as MaterialEntry != null)
                                    {
                                        matent           = tno.Tag as MaterialEntry;
                                        matent.EntryName = matent.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        matent.TrueName  = matent.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        matent.FileName  = matent.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag          = matent;
                                        tno.Text         = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name         = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as MSDEntry != null)
                                    {
                                        msdenty           = tno.Tag as MSDEntry;
                                        msdenty.EntryName = msdenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        msdenty.TrueName  = msdenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        msdenty.FileName  = msdenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = msdenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as ChainListEntry != null)
                                    {
                                        cstenty           = tno.Tag as ChainListEntry;
                                        cstenty.EntryName = cstenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        cstenty.TrueName  = cstenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        cstenty.FileName  = cstenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = cstenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as ChainEntry != null)
                                    {
                                        chnenty           = tno.Tag as ChainEntry;
                                        chnenty.EntryName = chnenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        chnenty.TrueName  = chnenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        chnenty.FileName  = chnenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = chnenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as ChainCollisionEntry != null)
                                    {
                                        cclentry           = tno.Tag as ChainCollisionEntry;
                                        cclentry.EntryName = cclentry.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        cclentry.TrueName  = cclentry.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        cclentry.FileName  = cclentry.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag            = cclentry;
                                        tno.Text           = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name           = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as ModelEntry != null)
                                    {
                                        mdlentry           = tno.Tag as ModelEntry;
                                        mdlentry.EntryName = mdlentry.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        mdlentry.TrueName  = mdlentry.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        mdlentry.FileName  = mdlentry.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag            = mdlentry;
                                        tno.Text           = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name           = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as MissionEntry != null)
                                    {
                                        misenty           = tno.Tag as MissionEntry;
                                        misenty.EntryName = misenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        misenty.TrueName  = misenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        misenty.FileName  = misenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = misenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as GemEntry != null)
                                    {
                                        gementy           = tno.Tag as GemEntry;
                                        gementy.EntryName = gementy.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        gementy.TrueName  = gementy.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        gementy.FileName  = gementy.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = gementy;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }
                                    else if (tno.Tag as EffectListEntry != null)
                                    {
                                        eflenty           = tno.Tag as EffectListEntry;
                                        eflenty.EntryName = eflenty.EntryName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        eflenty.TrueName  = eflenty.TrueName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        eflenty.FileName  = eflenty.FileName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Tag           = eflenty;
                                        tno.Text          = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                        tno.Name          = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                                    }

                                    RenameCount++;
                                }
                            }
                        }
                    }

                    if (tno.Tag as string != null && tno.Tag as string == "Folder")
                    {
                        //Replaces the Term in the folder.
                        string FolderName = tno.Text as string;
                        FolderName = FolderName.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                        tno.Text   = tno.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                        tno.Name   = tno.Name.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                        RenameCount++;
                    }
                }

                Mainfrm.TreeSource.Update();

                Mainfrm.TreeSource.EndUpdate();

                MessageBox.Show("Replaced " + txtReplaceFind.Text + " with " + txtReplaceReplace.Text + " in " + RenameCount + " file and folder names.");

                Mainfrm.OpenFileModified = true;
                RenameCount = 0;
            }
            else
            {
                if (Mainfrm.TreeSource.SelectedNode.Tag is ResourcePathListEntry)
                {
                    //Gets the text, then replaces every instance of the search term with the new term.
                    string text = Mainfrm.txtRPList.Text;
                    text = text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                    Mainfrm.txtRPList.Text = text;
                }
                else if (Mainfrm.TreeSource.SelectedNode.Tag is MaterialEntry)
                {
                    TreeNodeCollection TNoCollection = Mainfrm.TreeSource.SelectedNode.Nodes;

                    foreach (TreeNode node in TNoCollection)
                    {
                        if (node.Tag as string != null)
                        {
                            if (node.Text as string == "Textures")
                            {
                                Mainfrm.TreeSource.SelectedNode = node;
                                break;
                            }
                        }
                    }

                    TNoCollection = Mainfrm.TreeSource.SelectedNode.Nodes;
                    Mainfrm.TreeSource.BeginUpdate();

                    foreach (TreeNode node in TNoCollection)
                    {
                        string Namer = node.Name as string;
                        node.Text = node.Text.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                        Namer     = Namer.Replace(txtReplaceFind.Text, txtReplaceReplace.Text);
                        node.Name = Namer;
                    }

                    Mainfrm.TreeSource.SelectedNode = Mainfrm.TreeSource.SelectedNode.Parent;

                    //Now to update the Material file with all these, Whether they're changed or not.
                    TreeNode                 Parentnode    = Mainfrm.TreeSource.SelectedNode;
                    MaterialEntry            ParentMateial = Parentnode.Tag as MaterialEntry;
                    MaterialTextureReference texref        = new MaterialTextureReference();
                    string TermToInject = "";
                    //int count = 0;

                    for (int i = 0; i < TNoCollection.Count; i++)
                    {
                        texref = TNoCollection[i].Tag as MaterialTextureReference;

                        TermToInject = TNoCollection[i].Text;

                        //Now for the actual file update.
                        List <byte> NameToInject = new List <byte>();
                        NameToInject.AddRange(Encoding.ASCII.GetBytes(TermToInject));
                        int OffsetToUse;
                        OffsetToUse = 64 + (88 * (texref.Index - 1));
                        byte[] NewName = new byte[64];
                        Array.Copy(NameToInject.ToArray(), 0, NewName, 0, NameToInject.ToArray().Length);
                        Array.Copy(NewName, 0, ParentMateial.UncompressedData, OffsetToUse, NewName.Length);
                        ParentMateial.CompressedData = Zlibber.Compressor(ParentMateial.UncompressedData);
                    }

                    Mainfrm.TreeSource.SelectedNode.Tag = ParentMateial;

                    Mainfrm.OpenFileModified = true;
                    Mainfrm.TreeSource.Update();
                    Mainfrm.TreeSource.EndUpdate();
                }
            }
        }
Beispiel #2
0
        private void btnROK_Click(object sender, EventArgs e)
        {
            string newname = txtRename.Text;

            //Checks for blank/null names.
            if (newname == null || newname == "")
            {
                MessageBox.Show("This must have a name and cannot be null!", "Ahem");
                return;
            }

            if (OriginalName == txtRename.Text)
            {
                DialogResult = DialogResult.OK;
                Hide();
                return;
            }

            //Checks for existing name in directory.
            foreach (TreeNode c in node_.Parent.Nodes)
            {
                ArcEntry ae = new ArcEntry();
                ArcEntry se = new ArcEntry();
                if (node_.Tag is ArcEntry)
                {
                    ae = node_.Tag as ArcEntry;
                }

                if (c.Tag is ArcEntry)
                {
                    se = c.Tag as ArcEntry;
                }

                /*
                 * //Checks the nodes in the same directory for existing name AND extension and will stop if there's a node with the same type in the same directory.
                 * if (c.Text == txtRename.Text && c.Tag as string != "MaterialChildTexture")
                 * {
                 *  if (ae != se && ae.FileExt == se.FileExt)
                 *  {
                 *      MessageBox.Show("That name already exists on a resource of the same type on the same level. \nTry a different name.", "Oh Boy");
                 *      return;
                 *  }
                 * }
                 */
            }

            //Changes the name to what was chosen. Should reflect on the Treeview.
            treeview.SelectedNode.Text = txtRename.Text;
            treeview.SelectedNode.Name = txtRename.Text;

            //Ensures the TrueName gets change so it gets reflected in the save.
            ArcEntry aey = new ArcEntry();

            if (treeview.SelectedNode.Tag is ArcEntry)
            {
                aey          = treeview.SelectedNode.Tag as ArcEntry;
                aey.TrueName = txtRename.Text;
            }
            else if (treeview.SelectedNode.Tag != null && treeview.SelectedNode.Tag as string == "Folder")
            {
            }
            else if (treeview.SelectedNode.Tag != null && treeview.SelectedNode.Tag is MaterialTextureReference)
            {
                //Goes about accessing and updating the data inside the material in a roundabout way.
                MaterialTextureReference texref = treeview.SelectedNode.Tag as MaterialTextureReference;
                MaterialEntry            mentry = new MaterialEntry();
                TreeNode parent = treeview.SelectedNode.Parent;
                TreeNode child  = treeview.SelectedNode;
                treeview.SelectedNode = parent;
                parent = treeview.SelectedNode.Parent;
                treeview.SelectedNode = parent;
                mentry = treeview.SelectedNode.Tag as MaterialEntry;
                if (mentry != null)
                {
                    //Now for the actual file update.
                    List <byte> NameToInject = new List <byte>();
                    NameToInject.AddRange(Encoding.ASCII.GetBytes(txtRename.Text));
                    int OffsetToUse;
                    OffsetToUse = 64 + (88 * (texref.Index - 1));
                    byte[] NewName = new byte[64];
                    Array.Copy(NameToInject.ToArray(), 0, NewName, 0, NameToInject.ToArray().Length);
                    Array.Copy(NewName, 0, mentry.UncompressedData, OffsetToUse, NewName.Length);
                    mentry.CompressedData     = Zlibber.Compressor(mentry.UncompressedData);
                    treeview.SelectedNode.Tag = mentry;
                }
                treeview.SelectedNode = child;
            }

            Mainfrm.OpenFileModified = true;

            //Closes form with changes made above.
            DialogResult = DialogResult.OK;
            Hide();
        }