Ejemplo n.º 1
0
        public byte[] getFileData(PackFile file)
        {
            byte[] ret = new byte[file.length];

            //Get index
            int i = 0;

            while (i < FileList.Length)
            {
                if (FileList[i].name == file.name)
                {
                    break;
                }
                i++;
            }

            long filePosition = CalculateFilePosition(i);

            using (Stream fileStream = File.OpenRead(path))
            {
                fileStream.Position = filePosition;
                fileStream.Read(ret, 0, ret.Length);
            }
            return(ret);
        }
Ejemplo n.º 2
0
        private void fileTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            Console.WriteLine("Selected " + e.Node.FullPath);
            foreach (PackFile file in CurrentPACK.FileList)
            {
                if (file.name == e.Node.FullPath)
                {
                    CurrentPreviewFile = file;
                    //Load preview
                    splitContainerMainForm.Panel2.Controls.Clear();
                    KnownFileTypes.Types fileType = KnownFileTypes.IdentifyFile(file.name);
                    Console.WriteLine(fileType);
                    switch (fileType)
                    {
                    case KnownFileTypes.Types.PNG:
                        PictureBox prev = new PictureBox();
                        prev.Dock = DockStyle.Fill;
                        byte[] data = CurrentPACK.getFileData(file);
                        Image  tempIMG;
                        using (MemoryStream stream = new MemoryStream(data))
                        {
                            tempIMG = Image.FromStream(stream);
                        }
                        prev.Image    = tempIMG;
                        prev.SizeMode = PictureBoxSizeMode.Zoom;
                        splitContainerMainForm.Panel2.Controls.Add(prev);
                        break;

                    case KnownFileTypes.Types.TXT:
                        RichTextBox textprev = new RichTextBox();
                        textprev.Dock = DockStyle.Fill;
                        byte[] textdata = CurrentPACK.getFileData(file);
                        splitContainerMainForm.Panel2.Controls.Add(textprev);
                        textprev.Text = encodConf.GetString(textdata);
                        break;

                    case KnownFileTypes.Types.XML:
                        RichTextBox xmlprev = new RichTextBox();
                        xmlprev.Dock = DockStyle.Fill;
                        byte[] xmldata = CurrentPACK.getFileData(file);
                        splitContainerMainForm.Panel2.Controls.Add(xmlprev);
                        xmlprev.Text = encodConf.GetString(xmldata);

                        break;

                    default:
                        break;
                    }
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public PACK(string FilePath)
        {
            path = FilePath;
            Stream fileStream = File.OpenRead(path);

            byte[] intBuff = new byte[4];
            fileStream.Read(intBuff, 0, intBuff.Length);

            //Check magic number
            if (BitConverter.ToInt32(intBuff, 0) != 893929040)
            {
                Console.WriteLine("Magic number check failed");
                return;
            }

            //Skip because UNK
            fileStream.Read(intBuff, 0, intBuff.Length);

            bool isPartOf = false;

            Array.Clear(intBuff, 0, intBuff.Length);
            fileStream.Read(intBuff, 0, intBuff.Length);
            if (BitConverter.ToInt32(intBuff, 0) == 1)
            {
                isPartOf = true;
                Console.WriteLine("This file is part of another file");
            }
            else if (BitConverter.ToInt32(intBuff, 0) > 1)
            {
                Console.WriteLine("Exception while reading header...");
                return;
            }

            //If the file is part of another the first entry in the file directory will be a string with this length
            Array.Clear(intBuff, 0, intBuff.Length);
            fileStream.Read(intBuff, 0, intBuff.Length);
            int PartOfNameLength = BitConverter.ToInt32(intBuff, 0);

            Console.WriteLine("PartOfNameLength:" + PartOfNameLength);

            //Number of files in this .pack file
            Array.Clear(intBuff, 0, intBuff.Length);
            fileStream.Read(intBuff, 0, intBuff.Length);
            int FileNum = BitConverter.ToInt32(intBuff, 0);

            Console.WriteLine("FileNum:" + FileNum);

            //Size of FileDirectory
            Array.Clear(intBuff, 0, intBuff.Length);
            fileStream.Read(intBuff, 0, intBuff.Length);
            int FileDirectorySize = BitConverter.ToInt32(intBuff, 0);

            Console.WriteLine("FileDirectorySize:" + FileDirectorySize);

            //Skip because UNK
            fileStream.Read(intBuff, 0, intBuff.Length);

            if (isPartOf)
            {
                byte[] partOfName = new byte[PartOfNameLength];
                fileStream.Read(partOfName, 0, partOfName.Length);
                Console.WriteLine("Part of " + System.Text.Encoding.Default.GetString(partOfName));
            }

            //Console.WriteLine("Done reading header. Press any key to continue");
            //Console.ReadKey();

            //read directory
            FileList = new PackFile[FileNum];
            int i = 0;

            while (i < FileNum)
            {
                Array.Clear(intBuff, 0, intBuff.Length);
                fileStream.Read(intBuff, 0, intBuff.Length);
                fileStream.ReadByte();
                string temp     = "";
                char   tempChar = (char)fileStream.ReadByte();
                while (tempChar != 0)
                {
                    temp     = temp + tempChar;
                    tempChar = (char)fileStream.ReadByte();
                }
                Console.WriteLine("Name:" + temp + " Length:" + BitConverter.ToInt32(intBuff, 0));
                FileList[i] = new PackFile(temp, BitConverter.ToInt32(intBuff, 0));
                i++;
            }

            //Saving end of directory
            EndOfDirectory = fileStream.Position;
            Console.WriteLine("Done loading");
            //Releasing stream reader
            fileStream.Flush();
        }