public static byte[] ToMem(string pkrFilePath, PTR.PTRFile ptrfile)
        {
            byte[] ret           = new byte[1];
            Stream pkrFileHandle = File.OpenRead(pkrFilePath);

            byte[] buff = new byte[ptrfile.sizeZipped];
            pkrFileHandle.Position = ptrfile.pkrOffset;
            pkrFileHandle.Read(buff, 0, buff.Length);
            pkrFileHandle.Close();
            MemoryStream memoryStream = new MemoryStream(buff);
            MemoryStream returnStream = new MemoryStream();

            //Check if the file needs to be deflated
            if (buff[buff.Length - 1] == 0xFF && buff[buff.Length - 2] == 0xFF && buff[buff.Length - 3] == 0x00 && buff[buff.Length - 4] == 0x00)
            {
                DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionMode.Decompress);
                deflateStream.CopyTo(returnStream);
                deflateStream.Close();
                ret = returnStream.ToArray();
            }
            else
            {
                ret = memoryStream.ToArray();
            }
            returnStream.Close();
            memoryStream.Close();
            return(ret);
        }
        public static void ToDisk(string targetDirectory, string pkrFilePath, PTR.PTRFile ptrfile)
        {
            Stream pkrFileHandle = File.OpenRead(pkrFilePath);

            byte[] buff = new byte[ptrfile.sizeZipped];
            pkrFileHandle.Position = ptrfile.pkrOffset;
            pkrFileHandle.Read(buff, 0, buff.Length);
            pkrFileHandle.Close();
            string path = targetDirectory + '\\' + Path.GetDirectoryName(ptrfile.path.Replace('/', '\\'));

            Directory.CreateDirectory(path);
            Stream       fileStream   = File.Create(path + '\\' + Path.GetFileName(ptrfile.path));
            MemoryStream memoryStream = new MemoryStream(buff);

            //Check if the file needs to be deflated
            if (buff[buff.Length - 1] == 0xFF && buff[buff.Length - 2] == 0xFF && buff[buff.Length - 3] == 0x00 && buff[buff.Length - 4] == 0x00)
            {
                DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionMode.Decompress);
                deflateStream.CopyTo(fileStream);
                deflateStream.Close();
            }
            else
            {
                memoryStream.CopyTo(fileStream);
            }
            fileStream.Close();
            memoryStream.Close();
        }
Exemplo n.º 3
0
        public static Control GetControl(PTR.PTRFile ptrfile, string pkrPath)
        {
            string fileExtension = Path.GetExtension(ptrfile.path);

            switch (fileExtension)
            {
            case ".png":
                PictureBox picboxprev = new PictureBox();
                picboxprev.Dock = DockStyle.Fill;
                byte[] pngdata = Extract.ToMem(pkrPath, ptrfile);
                Image  tempIMG;
                using (MemoryStream stream = new MemoryStream(pngdata))
                {
                    tempIMG = Image.FromStream(stream);
                }
                picboxprev.Image    = tempIMG;
                picboxprev.SizeMode = PictureBoxSizeMode.Zoom;
                return(picboxprev);

            case ".lanb":
                RichTextBox lanbprev = new RichTextBox();
                lanbprev.Dock = DockStyle.Fill;
                byte[] lanbdata = Extract.ToMem(pkrPath, ptrfile);
                LANB   tempLANB;
                using (MemoryStream stream = new MemoryStream(lanbdata))
                {
                    tempLANB = new LANB(stream);
                }
                foreach (var entry in tempLANB.entrys)
                {
                    lanbprev.Text = lanbprev.Text + "NAME:" + entry.name + " TEXT:" + entry.text + '\n';
                }
                return(lanbprev);

            case ".decl":
                RichTextBox declprev = new RichTextBox();
                declprev.Dock = DockStyle.Fill;
                byte[] decldata = Extract.ToMem(pkrPath, ptrfile);
                declprev.Text       = Encoding.Default.GetString(decldata); //formatting would be nice probably
                declprev.ScrollBars = RichTextBoxScrollBars.Both;
                return(declprev);

            case ".bdecl":
                RichTextBox bdeclprev = new RichTextBox();
                bdeclprev.Dock = DockStyle.Fill;
                byte[] bdecldata = Extract.ToMem(pkrPath, ptrfile);
                BDECL  tempBDECL;
                using (MemoryStream stream = new MemoryStream(bdecldata))
                {
                    tempBDECL = new BDECL(stream);
                }
                bdeclprev.Text       = tempBDECL.data;
                bdeclprev.ScrollBars = RichTextBoxScrollBars.Both;
                return(bdeclprev);

            default:
                return(null);
            }
        }
Exemplo n.º 4
0
        private void extractAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (loadedPTR == null)
            {
                Console.WriteLine("No file loaded. Please load a file before extraction.");
                return;
            }

            Console.WriteLine("Extracting selected file or directory...");
            FolderBrowserDialog folderbrowserdialog = new FolderBrowserDialog();

            if (folderbrowserdialog.ShowDialog() != DialogResult.OK)
            {
                Console.WriteLine("No folder chosen.");
                return;
            }
            Console.WriteLine("folder:" + folderbrowserdialog.SelectedPath);
            Console.WriteLine("start extracting all...");
            List <string> extractedFiles = new List <string>();

            foreach (var file in loadedPTR.index)
            {
                Console.WriteLine("Extracting " + file.path);
                if (!extractedFiles.Contains(file.path))
                {
                    Extract.ToDisk(folderbrowserdialog.SelectedPath, pkrPath, file);
                    extractedFiles.Add(file.path);
                }
                else
                {
                    int         fileCount = 0;
                    PTR.PTRFile temp      = file;
                    while (extractedFiles.Contains(temp.path + fileCount))
                    {
                        fileCount++;
                    }
                    temp.path = temp.path + fileCount;
                    Extract.ToDisk(folderbrowserdialog.SelectedPath, pkrPath, temp);
                    extractedFiles.Add(temp.path);
                }
            }
            Console.WriteLine("Done");
        }
Exemplo n.º 5
0
        private void extractToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (loadedPTR == null)
            {
                Console.WriteLine("No file loaded. Please load a file before extraction.");
                return;
            }


            Console.WriteLine("Extracting selected file or directory...");
            FolderBrowserDialog folderbrowserdialog = new FolderBrowserDialog();

            if (folderbrowserdialog.ShowDialog() != DialogResult.OK)
            {
                Console.WriteLine("No folder chosen.");
                return;
            }

            string[] path = fileTreeView.SelectedNode.FullPath.Split('\\');
            Console.WriteLine("folder:" + folderbrowserdialog.SelectedPath);
            Console.WriteLine("start extracting " + path);
            List <string> extractedFiles = new List <string>();

            foreach (var file in loadedPTR.index)
            {
                string[] filePath = file.path.Split('/');
                if (filePath.Length >= path.Length)
                {
                    bool isExtractionTarget = true;
                    int  i = 0;
                    while (i < path.Length)
                    {
                        if (path[i] != filePath[i])
                        {
                            isExtractionTarget = false;
                            break;
                        }
                        i++;
                    }
                    if (isExtractionTarget)
                    {
                        Console.WriteLine("Extracting " + file.path);
                        if (!extractedFiles.Contains(file.path))
                        {
                            Extract.ToDisk(folderbrowserdialog.SelectedPath, pkrPath, file);
                            extractedFiles.Add(file.path);
                        }
                        else
                        {
                            int         fileCount = 0;
                            PTR.PTRFile temp      = file;
                            while (extractedFiles.Contains(temp.path + fileCount))
                            {
                                fileCount++;
                            }
                            temp.path = temp.path + fileCount;
                            Extract.ToDisk(folderbrowserdialog.SelectedPath, pkrPath, temp);
                            extractedFiles.Add(temp.path);
                        }
                    }
                }
            }
            Console.WriteLine("Done extracting");
        }