Example #1
0
        public void RefreshManifest(List <string> ManifestText, FrmMainThree frmMain)
        {
            //Goes to top node to begin iteration.
            TreeNode tn = frmMain.FindRootNode(frmMain.TreeSource.SelectedNode);

            frmMain.TreeSource.SelectedNode = tn;

            List <TreeNode> Nodes = new List <TreeNode>();

            frmMain.AddChildren(Nodes, frmMain.TreeSource.SelectedNode);
            string Temp     = "";
            int    nowcount = 0;

            //Empties old manifest and fills it in with the current files inside the currently opened arc.
            Mainfrm.Manifest.Clear();
            foreach (TreeNode treno in Nodes)
            {
                if ((treno.Tag as string != null && treno.Tag as string == "Folder") || treno.Tag as string == "MaterialChildMaterial" || treno.Tag as string == "Model Material Reference" ||
                    treno.Tag as string == "Model Primitive Group" || treno.Tag is MaterialTextureReference || treno.Tag is LMTM3AEntry || treno.Tag is ModelBoneEntry ||
                    treno.Tag is MaterialMaterialEntry || treno.Tag is ModelGroupEntry || treno.Tag is Mission)
                {
                }
                else
                {
                    nowcount++;
                    ArcEntryWrapper File = treno as ArcEntryWrapper;
                    if (File != null)
                    {
                        Temp = File.FullPath + File.FileExt;
                        frmMain.Manifest.Add(Temp);
                    }
                }
            }


            txtManifest.Text = "";
            string Temstr = "";

            Mainfrm = frmMain;
            foreach (string str in Mainfrm.Manifest)
            {
                Temstr           = str.Substring(str.IndexOf("\\") + 1);
                txtManifest.Text = txtManifest.Text + Temstr + "\n";
            }
        }
Example #2
0
        public static ArcEntry InsertArcEntry(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ArcEntry arcentry = new ArcEntry();

            InsertEntry(tree, node, filename, arcentry);

            arcentry.DecompressedFileLength  = arcentry.UncompressedData.Length;
            arcentry._DecompressedFileLength = arcentry.UncompressedData.Length;
            arcentry.CompressedFileLength    = arcentry.CompressedData.Length;
            arcentry._CompressedFileLength   = arcentry.CompressedData.Length;
            arcentry._FileName = arcentry.TrueName;
            arcentry._FileType = arcentry.FileExt;
            arcentry.EntryName = arcentry.FileName;



            return(arcentry);
        }
Example #3
0
        public static ArcEntry ReplaceArcEntry(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ArcEntry arcentry = new ArcEntry();
            ArcEntry oldentry = new ArcEntry();

            tree.BeginUpdate();

            ReplaceEntry(tree, node, filename, arcentry, oldentry);

            arcentry.DecompressedFileLength  = arcentry.UncompressedData.Length;
            arcentry._DecompressedFileLength = arcentry.UncompressedData.Length;
            arcentry.CompressedFileLength    = arcentry.CompressedData.Length;
            arcentry._CompressedFileLength   = arcentry.CompressedData.Length;
            arcentry._FileName = arcentry.TrueName;
            arcentry._FileType = arcentry.FileExt;

            return(node.entryfile as ArcEntry);
        }
Example #4
0
        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();
                }
            }
        }
 public static void UpdateForRenamedFolder(TreeView tree, ArcEntryWrapper node, string filename, DefaultWrapper entrytoupdate)
 {
     //Ensures existing subdirectories are cleared so the directories for files are displayed correctly.
     List <string> subnames = new List <string>();
 }
        public static void ReplaceKnownEntry(TreeView tree, ArcEntryWrapper node, string filename, DefaultWrapper entrytobuild, DefaultWrapper entrytoreplace, Type filetype = null)
        {
            tree.BeginUpdate();


            //We build the entrytobuild starting from the uncompressed data.
            entrytobuild.UncompressedData = System.IO.File.ReadAllBytes(filename);

            //Then Compress.
            entrytobuild.CompressedData = Zlibber.Compressor(entrytobuild.UncompressedData);

            entrytobuild.DSize = entrytobuild.UncompressedData.Length;
            entrytobuild.CSize = entrytobuild.CompressedData.Length;

            //Gets the filename of the file to inject without the directory.
            string trname = filename;

            while (trname.Contains("\\"))
            {
                trname = trname.Substring(trname.IndexOf("\\") + 1);
            }



            //Code that replaces the name with the new node's name.

            //Enters name related parameters of the entrytobuild.
            entrytobuild.TrueName = trname;
            entrytobuild.TrueName = Path.GetFileNameWithoutExtension(trname);
            entrytobuild.FileExt  = trname.Substring(trname.LastIndexOf("."));

            string TypeHash = "";

            //Looks through the archive_filetypes.cfg file to find the typehash associated with the extension.
            try
            {
                using (var sr2 = new StreamReader("archive_filetypes.cfg"))
                {
                    while (!sr2.EndOfStream)
                    {
                        var keyword = Console.ReadLine() ?? entrytobuild.FileExt;
                        var line    = sr2.ReadLine();
                        if (String.IsNullOrEmpty(line))
                        {
                            continue;
                        }
                        if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                        {
                            TypeHash = line;
                            TypeHash = TypeHash.Split(' ')[0];
                            entrytobuild.TypeHash = TypeHash;
                            break;
                        }
                    }
                }
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Cannot find archive_filetypes.cfg so I cannot continue parsing this file.\n Find archive_filetypes.cfg and then restart this program.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Cannot find archive_filetypes.cfg so I cannot continue parsing the file.");
                }
                Process.GetCurrentProcess().Kill();
                return;
            }

            var tag = node.Tag;

            if (tag is DefaultWrapper)
            {
                entrytoreplace = tag as DefaultWrapper;
            }

            string path  = "";
            int    index = entrytoreplace.EntryName.LastIndexOf("\\");

            if (index > 0)
            {
                path = entrytoreplace.EntryName.Substring(0, index);
            }

            entrytobuild.EntryName = path + "\\" + entrytobuild.TrueName;

            //Enters name related parameters of the entrytobuild. Meant to preserve the orignal filename.
            entrytobuild.TrueName  = entrytoreplace.TrueName;
            entrytobuild.FileExt   = entrytoreplace.FileExt;
            entrytobuild.EntryName = entrytoreplace.EntryName;

            tag = entrytobuild;

            if (node.Tag is DefaultWrapper)
            {
                node.Tag  = entrytobuild;
                node.Name = Path.GetFileNameWithoutExtension(entrytobuild.EntryName);
                node.Text = Path.GetFileNameWithoutExtension(entrytobuild.EntryName);
            }

            var aew = node as ArcEntryWrapper;

            string type = node.GetType().ToString();

            if (type == "ThreeWorkTool.Resources.Wrappers.ArcEntryWrapper")
            {
                aew.entryfile = entrytobuild;
            }

            node           = aew;
            node.entryfile = entrytobuild;
        }
        public static void InsertKnownEntry(TreeView tree, ArcEntryWrapper node, string filename, DefaultWrapper entrytobuild, BinaryReader bnr, Type filetype = null)
        {
            //We build the entrytobuild starting from the uncompressed data.
            entrytobuild.UncompressedData = System.IO.File.ReadAllBytes(filename);
            entrytobuild.DSize            = entrytobuild.UncompressedData.Length;

            //Then Compress.
            entrytobuild.CompressedData = Zlibber.Compressor(entrytobuild.UncompressedData);
            entrytobuild.CSize          = entrytobuild.CompressedData.Length;

            //Gets the filename of the file to inject without the directory.
            string trname = filename;

            while (trname.Contains("\\"))
            {
                trname = trname.Substring(trname.IndexOf("\\") + 1);
            }

            entrytobuild.TrueName = trname;
            entrytobuild.TrueName = Path.GetFileNameWithoutExtension(trname);
            entrytobuild.FileExt  = trname.Substring(trname.LastIndexOf("."));

            //Gets the path of the selected node to inject here.
            string nodepath = tree.SelectedNode.FullPath;

            nodepath = nodepath.Substring(nodepath.IndexOf("\\") + 1);

            string[] sepstr = { "\\" };
            entrytobuild.EntryDirs = nodepath.Split(sepstr, StringSplitOptions.RemoveEmptyEntries);

            //Looks through the archive_filetypes.cfg file to find the typehash associated with the extension.
            try
            {
                using (var sr2 = new StreamReader("archive_filetypes.cfg"))
                {
                    while (!sr2.EndOfStream)
                    {
                        var keyword = Console.ReadLine() ?? entrytobuild.FileExt;
                        var line    = sr2.ReadLine();
                        if (String.IsNullOrEmpty(line))
                        {
                            continue;
                        }
                        if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                        {
                            entrytobuild.TypeHash = line;
                            entrytobuild.TypeHash = entrytobuild.TypeHash.Split(' ')[0];

                            break;
                        }
                    }
                }
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Cannot find archive_filetypes.cfg so I cannot continue parsing this file.\n Find archive_filetypes.cfg and then restart this program.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Cannot find archive_filetypes.cfg so I cannot continue parsing the file.");
                }
                Process.GetCurrentProcess().Kill();
            }
        }
Example #8
0
        public static void ReplaceEntry(TreeView tree, ArcEntryWrapper node, string filename, DefaultWrapper entrytobuild, DefaultWrapper entrytoreplace, Type filetype = null)
        {
            tree.BeginUpdate();

            try
            {
                using (BinaryReader bnr = new BinaryReader(File.OpenRead(filename)))
                {
                    //We build the entrytobuild starting from the uncompressed data.
                    entrytobuild.UncompressedData = System.IO.File.ReadAllBytes(filename);

                    //Then Compress.
                    entrytobuild.CompressedData = Zlibber.Compressor(entrytobuild.UncompressedData);


                    //Gets the filename of the file to inject without the directory.
                    string trname = filename;
                    while (trname.Contains("\\"))
                    {
                        trname = trname.Substring(trname.IndexOf("\\") + 1);
                    }

                    //Enters name related parameters of the entrytobuild.
                    entrytobuild.TrueName = trname;
                    entrytobuild.TrueName = Path.GetFileNameWithoutExtension(trname);
                    entrytobuild.FileExt  = trname.Substring(trname.LastIndexOf("."));

                    string TypeHash = "";

                    //Looks through the archive_filetypes.cfg file to find the typehash associated with the extension.
                    try
                    {
                        using (var sr2 = new StreamReader("archive_filetypes.cfg"))
                        {
                            while (!sr2.EndOfStream)
                            {
                                var keyword = Console.ReadLine() ?? entrytobuild.FileExt;
                                var line    = sr2.ReadLine();
                                if (String.IsNullOrEmpty(line))
                                {
                                    continue;
                                }
                                if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                {
                                    TypeHash = line;
                                    TypeHash = TypeHash.Split(' ')[0];
                                    entrytobuild.TypeHash = TypeHash;
                                    break;
                                }
                            }
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        MessageBox.Show("I cannot find and/or access archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                        using (StreamWriter sw = File.AppendText("Log.txt"))
                        {
                            sw.WriteLine("Cannot find archive_filetypes.cfg so I cannot continue parsing the file.");
                        }
                        return;
                    }



                    var tag = node.Tag;
                    if (tag is DefaultWrapper)
                    {
                        entrytoreplace = tag as DefaultWrapper;
                    }

                    string path  = "";
                    int    index = entrytoreplace.EntryName.LastIndexOf("\\");
                    if (index > 0)
                    {
                        path = entrytoreplace.EntryName.Substring(0, index);
                    }

                    entrytobuild.EntryName = path + "\\" + entrytobuild.TrueName;

                    tag = entrytobuild;

                    if (node.Tag is DefaultWrapper)
                    {
                        node.Tag  = entrytobuild;
                        node.Name = Path.GetFileNameWithoutExtension(entrytobuild.EntryName);
                        node.Text = Path.GetFileNameWithoutExtension(entrytobuild.EntryName);
                    }

                    var aew = node as ArcEntryWrapper;

                    string type = node.GetType().ToString();
                    if (type == "ThreeWorkTool.Resources.Wrappers.ArcEntryWrapper")
                    {
                        aew.entryfile = entrytobuild;
                    }

                    node           = aew;
                    node.entryfile = entrytobuild;

                    /*
                     * //ArcEntryWrapper aew = new ArcEntryWrapper();
                     * if (node is ArcEntryWrapper)
                     * {
                     *  node.entryfile as ArcEntryWrapper = node.Tag;
                     * }
                     */
                    tree.EndUpdate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Read error. Is the file readable?");
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Read Error! Here's the exception info:\n" + ex);
                }
            }



            //return node.entryfile as ArcEntry;
        }