Esempio n. 1
0
        private byte[] ExtractItem(CPKTable t)
        {
            CPKTable     entries = t as CPKTable;
            BinaryReader oldFile = new BinaryReader(File.OpenRead(myPackage.cpk_name));

            oldFile.BaseStream.Seek((long)entries.FileOffset, SeekOrigin.Begin);

            string isComp = Encoding.ASCII.GetString(oldFile.ReadBytes(8));

            oldFile.BaseStream.Seek((long)entries.FileOffset, SeekOrigin.Begin);

            byte[] chunk = oldFile.ReadBytes(Int32.Parse(entries.FileSize.ToString()));

            if (isComp == "CRILAYLA")
            {
                int size;
                if (entries.ExtractSize == 0)
                {
                    size = entries.FileSize;
                }
                else
                {
                    size = entries.ExtractSize;
                }

                if (size != 0)
                {
                    chunk = myPackage.cpk.DecompressLegacyCRI(chunk, size);
                }
            }
            oldFile.Close();
            return(chunk);
        }
Esempio n. 2
0
        private void dgitem1_Click(object sender, RoutedEventArgs e)
        {
            CPKTable t = this.datagrid_cpk.SelectedItem as CPKTable;

            if (t != null)
            {
                if (t.FileSize > 0 && t.FileType == "FILE")
                {
                    VistaSaveFileDialog saveFilesDialog = new VistaSaveFileDialog();
                    saveFilesDialog.InitialDirectory = myPackage.basePath;
                    saveFilesDialog.FileName         = myPackage.basePath + "/" + t._localName;
                    if (saveFilesDialog.ShowDialog().Value)
                    {
                        byte[] chunk = ExtractItem(t);

                        File.WriteAllBytes(saveFilesDialog.FileName, chunk);
                        MessageBox.Show(String.Format("Decompress to :{0}", saveFilesDialog.FileName));
                    }
                }
            }
        }
Esempio n. 3
0
        public cpkwrapper(string inFile)
        {
            string cpk_name = inFile;

            table         = new List <CPKTable>();
            myPackage.cpk = new CPK(new Tools());
            myPackage.cpk.ReadCPK(cpk_name, myPackage.encoding);
            myPackage.cpk_name = cpk_name;

            BinaryReader     oldFile = new BinaryReader(File.OpenRead(cpk_name));
            List <FileEntry> entries = myPackage.cpk.FileTable.OrderBy(x => x.FileOffset).ToList();
            int  i             = 0;
            bool bFileRepeated = Tools.CheckListRedundant(entries);

            while (i < entries.Count)
            {
                /*
                 * Console.WriteLine("FILE ID:{0},File Name:{1},File Type:{5},FileOffset:{2:x8},Extract Size:{3:x8},Chunk Size:{4:x8}", entries[i].ID,
                 *                                          (((entries[i].DirName != null) ? entries[i].DirName + "/" : "") + entries[i].FileName),
                 *                                          entries[i].FileOffset,
                 *                                          entries[i].ExtractSize,
                 *                                          entries[i].FileSize,
                 *                                          entries[i].FileType);
                 */


                if (entries[i].FileType != null)
                {
                    nums += 1;

                    CPKTable t = new CPKTable();
                    if (entries[i].ID == null)
                    {
                        t.id = -1;
                    }
                    else
                    {
                        t.id = Convert.ToInt32(entries[i].ID);
                    }
                    if (t.id >= 0 && bFileRepeated)
                    {
                        t.FileName = (((entries[i].DirName != null) ?
                                       entries[i].DirName + "/" : "") + string.Format("[{0}]", t.id.ToString()) + entries[i].FileName);
                    }
                    else
                    {
                        t.FileName = (((entries[i].DirName != null) ?
                                       entries[i].DirName + "/" : "") + entries[i].FileName);
                    }
                    t._localName = entries[i].FileName.ToString();

                    t.FileOffset  = Convert.ToUInt64(entries[i].FileOffset);
                    t.FileSize    = Convert.ToInt32(entries[i].FileSize);
                    t.ExtractSize = Convert.ToInt32(entries[i].ExtractSize);
                    t.FileType    = entries[i].FileType;
                    if (entries[i].FileType == "FILE")
                    {
                        t.Pt = (float)Math.Round((float)t.FileSize / (float)t.ExtractSize, 2) * 100f;
                    }
                    else
                    {
                        t.Pt = (float)1f * 100f;
                    }
                    table.Add(t);
                }
                i += 1;
            }
            oldFile.Close();
        }