public bool ReadZfsFile(string ZfsFile) { try { FileStream fs = new FileStream(ZfsFile, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs); //文件头 r.ReadBytes(0x1d); int mapoffset = r.ReadInt32(); r.ReadInt32(); int cnt = r.ReadInt32(); mapoffset += 23; for (int i = 0; i < cnt; i++) { //文件表 fs.Seek(mapoffset, SeekOrigin.Begin); int namelen = r.ReadInt32(); char[] name = r.ReadChars(namelen); int fileoffset = r.ReadInt32(); int filesize = r.ReadInt32(); mapoffset += namelen + 44; //文件 fs.Seek(fileoffset, SeekOrigin.Begin); string file = new string(name); string dir = Path.GetDirectoryName(file); if (dir.Length > 0) Directory.CreateDirectory(dir); FileStream fw = new FileStream(file, FileMode.CreateNew); BinaryWriter w = new BinaryWriter(fw); byte[] con = r.ReadBytes(filesize); w.Write(con); w.Close(); fw.Close(); } fs.Close(); return true; } catch (Exception e) { MessageBox.Show(e.Message); return false; }
//用法:
if (ReadZfsFile("gameworld_server.pak")) { MessageBox.Show("成功"); }
|
请发表评论