Example #1
0
        public static ResourcePathListEntry InsertRPL(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ResourcePathListEntry rplentry = new ResourcePathListEntry();

            try
            {
                using (BinaryReader bnr = new BinaryReader(File.OpenRead(filename)))
                {
                    InsertKnownEntry(tree, node, filename, rplentry, bnr);

                    //Specific file type work goes here!
                    ASCIIEncoding ascii = new ASCIIEncoding();

                    //Gets the Magic.
                    byte[] MTemp = new byte[4];
                    string STemp = " ";
                    Array.Copy(rplentry.UncompressedData, 0, MTemp, 0, 4);
                    rplentry.Magic = ByteUtilitarian.BytesToString(MTemp, rplentry.Magic);

                    Array.Copy(rplentry.UncompressedData, 12, MTemp, 0, 4);
                    Array.Reverse(MTemp);
                    STemp = ByteUtilitarian.BytesToString(MTemp, STemp);

                    int ECTemp = Convert.ToInt32(STemp, 16);
                    rplentry._EntryTotal = ECTemp;
                    rplentry.EntryCount  = ECTemp;

                    //Starts occupying the entry list via structs.
                    rplentry.EntryList = new List <PathEntries>();
                    byte[] PLName  = new byte[] { };
                    byte[] PTHName = new byte[] { };

                    int    p = 16;
                    string Teme;
                    string Hame;

                    for (int g = 0; g < rplentry.EntryCount; g++)
                    {
                        PathEntries pe = new PathEntries();
                        PLName = rplentry.UncompressedData.Skip(p).Take(64).Where(x => x != 0x00).ToArray();
                        Teme   = ascii.GetString(PLName);

                        pe.FullPath = Teme;
                        p           = p + 64;
                        PTHName     = rplentry.UncompressedData.Skip(p).Take(4).Where(x => x != 0x00).ToArray();
                        Array.Reverse(PTHName);

                        Teme        = ByteUtilitarian.BytesToString(PTHName, Teme);
                        pe.TypeHash = Teme;

                        try
                        {
                            using (var sr = new StreamReader("archive_filetypes.cfg"))
                            {
                                while (!sr.EndOfStream)
                                {
                                    var keyword = Console.ReadLine() ?? Teme;
                                    var line    = sr.ReadLine();
                                    if (String.IsNullOrEmpty(line))
                                    {
                                        continue;
                                    }
                                    if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                    {
                                        Hame         = line;
                                        Hame         = Hame.Split(' ')[1];
                                        pe.TotalName = pe.FullPath + Hame;
                                        pe.FileExt   = Hame;
                                        break;
                                    }
                                }
                            }
                        }
                        catch (FileNotFoundException)
                        {
                            MessageBox.Show("I cannot find 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 and thus cannot continue parsing.");
                            }
                            return(null);
                        }

                        rplentry.EntryList.Add(pe);
                        p = p + 4;
                    }

                    rplentry.TextBackup = new List <string>();
                }
            }
            catch (Exception ex)
            {
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Caught the exception:" + ex);
                }
            }

            return(rplentry);
        }
Example #2
0
        public static ResourcePathListEntry ReplaceRPL(TreeView tree, ArcEntryWrapper node, string filename, Type filetype = null)
        {
            ResourcePathListEntry rpathentry = new ResourcePathListEntry();
            ResourcePathListEntry rpoldentry = new ResourcePathListEntry();

            tree.BeginUpdate();

            //Gotta Fix this up then test insert and replacing.
            try
            {
                using (BinaryReader br = new BinaryReader(File.OpenRead(filename)))
                {
                    ReplaceKnownEntry(tree, node, filename, rpathentry, rpoldentry);

                    ASCIIEncoding ascii = new ASCIIEncoding();

                    //Gets the Magic.
                    byte[] MTemp = new byte[4];
                    string STemp = " ";
                    Array.Copy(rpathentry.UncompressedData, 0, MTemp, 0, 4);
                    rpathentry.Magic = ByteUtilitarian.BytesToString(MTemp, rpathentry.Magic);

                    Array.Copy(rpathentry.UncompressedData, 12, MTemp, 0, 4);
                    Array.Reverse(MTemp);
                    STemp = ByteUtilitarian.BytesToString(MTemp, STemp);

                    int ECTemp = Convert.ToInt32(STemp, 16);
                    rpathentry._EntryTotal = ECTemp;
                    rpathentry.EntryCount  = ECTemp;

                    //Starts occupying the entry list via structs.
                    rpathentry.EntryList = new List <PathEntries>();
                    byte[] PLName  = new byte[] { };
                    byte[] PTHName = new byte[] { };

                    int    p = 16;
                    string Teme;
                    string Hame;

                    for (int g = 0; g < rpathentry.EntryCount; g++)
                    {
                        PathEntries pe = new PathEntries();
                        PLName = rpathentry.UncompressedData.Skip(p).Take(64).Where(x => x != 0x00).ToArray();
                        Teme   = ascii.GetString(PLName);

                        pe.FullPath = Teme;
                        p           = p + 64;
                        PTHName     = rpathentry.UncompressedData.Skip(p).Take(4).Where(x => x != 0x00).ToArray();
                        Array.Reverse(PTHName);

                        Teme        = ByteUtilitarian.BytesToString(PTHName, Teme);
                        pe.TypeHash = Teme;

                        try
                        {
                            using (var sr = new StreamReader("archive_filetypes.cfg"))
                            {
                                while (!sr.EndOfStream)
                                {
                                    var keyword = Console.ReadLine() ?? Teme;
                                    var line    = sr.ReadLine();
                                    if (String.IsNullOrEmpty(line))
                                    {
                                        continue;
                                    }
                                    if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                                    {
                                        Hame         = line;
                                        Hame         = Hame.Split(' ')[1];
                                        pe.TotalName = pe.FullPath + Hame;
                                        pe.FileExt   = Hame;
                                        break;
                                    }
                                }
                            }
                        }
                        catch (FileNotFoundException)
                        {
                            MessageBox.Show("I cannot find archive_filetypes.cfg so I cannot finish parsing the arc.", "Oh Boy");
                            br.Close();
                        }

                        rpathentry.EntryList.Add(pe);
                        p = p + 4;
                    }

                    rpathentry.TextBackup  = new List <string>();
                    rpathentry._FileLength = rpathentry.UncompressedData.Length;

                    //Hmmm.

                    var tag = node.Tag;
                    if (tag is ResourcePathListEntry)
                    {
                        rpoldentry = tag as ResourcePathListEntry;
                    }
                    string path  = "";
                    int    index = rpoldentry.EntryName.LastIndexOf("\\");
                    if (index > 0)
                    {
                        path = rpoldentry.EntryName.Substring(0, index);
                    }

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

                    tag = rpathentry;

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

                    var aew = node as ArcEntryWrapper;

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

                    node           = aew;
                    node.entryfile = rpathentry;
                    tree.EndUpdate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Read error. Is the file readable?");
                using (StreamWriter sw = File.AppendText("Log.txt"))
                {
                    sw.WriteLine("Read error. Cannot access the file:" + filename + "\n" + ex);
                }
            }



            return(node.entryfile as ResourcePathListEntry);
        }
Example #3
0
        public static ResourcePathListEntry FillRPLEntry(string filename, List <string> subnames, TreeView tree, BinaryReader br, int c, int ID, Type filetype = null)
        {
            ResourcePathListEntry RPLentry = new ResourcePathListEntry();

            FillEntry(filename, subnames, tree, br, c, ID, RPLentry, filetype);

            RPLentry._FileName   = RPLentry.TrueName;
            RPLentry._FileType   = RPLentry.FileExt;
            RPLentry._FileLength = RPLentry.DSize;

            ASCIIEncoding ascii = new ASCIIEncoding();

            //Specific file type work goes here!

            //Gets the Magic.
            RPLentry.Magic       = BitConverter.ToString(RPLentry.UncompressedData, 0, 4).Replace("-", string.Empty);
            RPLentry._EntryTotal = BitConverter.ToInt32(RPLentry.UncompressedData, 12);
            RPLentry.EntryCount  = RPLentry._EntryTotal;

            //If the entry count is too high then it means the lrp file is likely corrupted or malinformed, meaning we put out an error message and force a close lest we hang.
            if (RPLentry.EntryCount > 76310)
            {
                string errorpath = "";
                foreach (string s in subnames)
                {
                    errorpath = errorpath + s + "\\";
                }
                errorpath = errorpath + RPLentry._FileName + ".lrp";
                MessageBox.Show("The file located at \n" + errorpath + "\nis malinformed and has way too many entries.\nFor this reason, I cannot continue reading this arc file and must close. Sorry.", "ATTENTION", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Process.GetCurrentProcess().Kill();
            }


            //Starts occupying the entry list via structs.
            RPLentry.EntryList = new List <PathEntries>();
            byte[] PLName  = new byte[] { };
            byte[] PTHName = new byte[] { };

            int    p = 16;
            string Teme;
            string Hame;

            for (int g = 0; g < RPLentry.EntryCount; g++)
            {
                PathEntries pe = new PathEntries();
                PLName = RPLentry.UncompressedData.Skip(p).Take(64).Where(x => x != 0x00).ToArray();
                Teme   = ascii.GetString(PLName);

                pe.FullPath = Teme;
                p           = p + 64;
                PTHName     = RPLentry.UncompressedData.Skip(p).Take(4).Where(x => x != 0x00).ToArray();
                Array.Reverse(PTHName);

                Teme        = ByteUtilitarian.BytesToString(PTHName, Teme);
                pe.TypeHash = Teme;

                try
                {
                    using (var sr = new StreamReader("archive_filetypes.cfg"))
                    {
                        while (!sr.EndOfStream)
                        {
                            var keyword = Console.ReadLine() ?? Teme;
                            var line    = sr.ReadLine();
                            if (String.IsNullOrEmpty(line))
                            {
                                continue;
                            }
                            if (line.IndexOf(keyword, StringComparison.CurrentCultureIgnoreCase) >= 0)
                            {
                                Hame         = line;
                                Hame         = Hame.Split(' ')[1];
                                pe.TotalName = pe.FullPath + Hame;
                                pe.FileExt   = Hame;
                                break;
                            }
                        }
                    }
                }
                catch (FileNotFoundException)
                {
                    MessageBox.Show("I cannot find 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 and thus cannot continue parsing.");
                    }
                    return(null);
                }

                RPLentry.EntryList.Add(pe);
                p = p + 4;
            }

            RPLentry.TextBackup = new List <string>();

            return(RPLentry);
        }