private void extractFile(fst_t fst, UInt16 entry, string parent) { UInt16 fat; int cluster_span = (int)(fst.size / 0x4000) + 1; byte[] cluster = new byte[0x4000], data = new byte[cluster_span * 0x4000]; string filename = Path.DirectorySeparatorChar + parent + Path.DirectorySeparatorChar + ASCIIEncoding.ASCII.GetString(fst.filename). Replace("\0", string.Empty). Replace(":", "-"); fireDebug("Extract {0}", filename); this.extractedSize += (int)fst.size; fireProgress((int)((float)this.extractedSize * 100 / (float)this.loc_fst)); BinaryWriter bw = null; try { bw = new BinaryWriter(File.Open(extractPath + filename, FileMode.Create, FileAccess.Write, FileShare.Read), Encoding.ASCII); fat = fst.sub; for (int i = 0; fat < 0xFFF0; i++) { Buffer.BlockCopy(getCluster(fat), 0, data, i * 0x4000, 0x4000); fat = getFAT(fat); } bw.Write(data, 0, (int)fst.size); } catch (ThreadAbortException taex) { throw taex; } catch { fireError("Can't open file: {0}", extractPath + filename); } finally { if (bw != null) { bw.Close(); } } }
private void extractDir(fst_t fst, UInt16 entry, string parent) { string filename = ASCIIEncoding.ASCII.GetString(fst.filename).Replace("\0", string.Empty); if (filename != "/") { if (parent != "/" && parent != "") { filename = parent + Path.DirectorySeparatorChar + filename; } Directory.CreateDirectory(extractPath + Path.DirectorySeparatorChar + filename); } if (fst.sub != 0xffff) { extractFST(fst.sub, filename); } }
private void extractFST(UInt16 entry, string parent) { fst_t fst = getFST(entry); if (fst.sib != 0xffff) { extractFST(fst.sib, parent); } switch (fst.mode) { case 0: extractDir(fst, entry, parent); break; case 1: extractFile(fst, entry, parent); break; default: break; } }
private fst_t getFST(UInt16 entry) { fst_t fst = new fst_t(); // compensate for 64 bytes of ecc data every 64 fst entries Int32[] n_fst = { 0, 2, 2 }; int loc_entry = (((entry / 0x40) * n_fst[type]) + entry) * 0x20; rom.BaseStream.Seek(loc_fst + loc_entry, SeekOrigin.Begin); fst.filename = rom.ReadBytes(0x0C); fst.mode = rom.ReadByte(); fst.attr = rom.ReadByte(); fst.sub = bswap(rom.ReadUInt16()); fst.sib = bswap(rom.ReadUInt16()); fst.size = bswap(rom.ReadUInt32()); fst.uid = bswap(rom.ReadUInt32()); fst.gid = bswap(rom.ReadUInt16()); fst.x3 = bswap(rom.ReadUInt32()); fst.mode &= 1; return(fst); }
private fst_t getFST(UInt16 entry) { fst_t fst = new fst_t(); // compensate for 64 bytes of ecc data every 64 fst entries Int32[] n_fst = { 0, 2, 2 }; int loc_entry = (((entry / 0x40) * n_fst[type]) + entry) * 0x20; rom.BaseStream.Seek(loc_fst + loc_entry, SeekOrigin.Begin); fst.filename = rom.ReadBytes(0x0C); fst.mode = rom.ReadByte(); fst.attr = rom.ReadByte(); fst.sub = bswap(rom.ReadUInt16()); fst.sib = bswap(rom.ReadUInt16()); fst.size = bswap(rom.ReadUInt32()); fst.uid = bswap(rom.ReadUInt32()); fst.gid = bswap(rom.ReadUInt16()); fst.x3 = bswap(rom.ReadUInt32()); fst.mode &= 1; return fst; }
private void extractFile(fst_t fst, UInt16 entry, string parent) { UInt16 fat; int cluster_span = (int)(fst.size / 0x4000) + 1; byte[] cluster = new byte[0x4000], data = new byte[cluster_span * 0x4000]; string filename = Path.DirectorySeparatorChar + parent + Path.DirectorySeparatorChar + ASCIIEncoding.ASCII.GetString(fst.filename). Replace("\0", string.Empty). Replace(":", "-"); fireDebug("Extract {0}", filename); this.extractedSize += (int)fst.size; fireProgress((int)((float)this.extractedSize * 100 / (float)this.loc_fst)); BinaryWriter bw = null; try { bw = new BinaryWriter(File.Open(extractPath + filename, FileMode.Create, FileAccess.Write, FileShare.Read), Encoding.ASCII); fat = fst.sub; for (int i = 0; fat < 0xFFF0; i++) { Buffer.BlockCopy(getCluster(fat), 0, data, i * 0x4000, 0x4000); fat = getFAT(fat); } bw.Write(data, 0, (int)fst.size); } catch (ThreadAbortException taex) { throw taex; } catch { fireError("Can't open file: {0}", extractPath + filename); } finally { if (bw != null) bw.Close(); } }
private void extractDir(fst_t fst, UInt16 entry, string parent) { string filename = ASCIIEncoding.ASCII.GetString(fst.filename).Replace("\0", string.Empty); if (filename != "/") { if (parent != "/" && parent != "") filename = parent + Path.DirectorySeparatorChar + filename; Directory.CreateDirectory(extractPath + Path.DirectorySeparatorChar + filename); } if (fst.sub != 0xffff) extractFST(fst.sub, filename); }