public CompactProArchive(ImageLocation archiveLocation, IProcessorArchitecture arch, MacOSClassic platform) { this.Location = archiveLocation; this.Architecture = arch; this.Platform = platform; this.RootEntries = new List <ArchiveDirectoryEntry>(); this.updcrc = zip_updcrc; }
public List <ArchiveDirectoryEntry> Load(Stream infp) { CptHdr cpthdr; FileHdr filehdr; byte[] cptindex; int cptindsize; int cptptr; int i; updcrc = zip_updcrc; // crcinit = zip_crcinit; // cpt_crc = INIT_CRC; if (readcpthdr(infp, out cpthdr) == 0) { throw new ApplicationException("Can't read archive header.."); } cptindsize = cpthdr.entries * FILEHDRSIZE; if (cpthdr.commentsize > cptindsize) { cptindsize = cpthdr.commentsize; } cptindex = new byte[cptindsize]; cptptr = 0; // cptindex; if (infp.Read(cptindex, cptptr, cpthdr.commentsize) != cpthdr.commentsize) { throw new ApplicationException("Can't read comment.."); } cpt_crc = updcrc(cpt_crc, cptindex, cptptr, cpthdr.commentsize); for (i = 0; i < cpthdr.entries; i++) { cptindex[cptptr] = (byte)infp.ReadByte(); cpt_crc = updcrc(cpt_crc, cptindex, cptptr, 1); if ((cptindex[cptptr] & 0x80) == 0x80) { cptindex[cptptr + F_FOLDER] = 1; cptindex[cptptr] &= 0x3f; } else { cptindex[cptptr + F_FOLDER] = 0; } if (infp.Read(cptindex, cptptr + 1, cptindex[cptptr]) != cptindex[cptptr]) { throw new ApplicationException(string.Format("Can't read file header #{0}.", i + 1)); } cpt_crc = updcrc(cpt_crc, cptindex, cptptr + 1, cptindex[cptptr]); if (cptindex[cptptr + F_FOLDER] != 0) { if (infp.Read(cptindex, cptptr + F_FOLDERSIZE, 2) != 2) { throw new ApplicationException(string.Format("Can't read file header #{0}.", i + 1)); } cpt_crc = updcrc(cpt_crc, cptindex, cptptr + F_FOLDERSIZE, 2); } else { if (infp.Read(cptindex, cptptr + F_VOLUME, FILEHDRSIZE - F_VOLUME) != FILEHDRSIZE - F_VOLUME) { throw new ApplicationException(string.Format("Can't read file header #{0}.", i + 1)); } cpt_crc = updcrc(cpt_crc, cptindex, cptptr + F_VOLUME, FILEHDRSIZE - F_VOLUME); } cptptr += FILEHDRSIZE; } //if(cpt_crc != cpthdr.hdrcrc) { //Console.Error.WriteLine("Header CRC mismatch: got 0x{0:X8}, need 0x{1:X8}", // (int)cpthdr.hdrcrc, (int)cpt_crc); //exit(1); //} List <ArchiveDirectoryEntry> entries = new List <ArchiveDirectoryEntry>(); cptptr = 0; // cptindex; for (i = 0; i < cpthdr.entries; i++) { if (cpt_filehdr(out filehdr, cptindex, cptptr) == -1) { throw new ApplicationException(string.Format("Can't read file header #{0}", i + 1)); } if (filehdr.folder != 0) { entries.Add(cpt_folder(text !, filehdr, cptindex, cptptr)); i += filehdr.foldersize; cptptr += filehdr.foldersize * FILEHDRSIZE; } else { if ((filehdr.cptFlag & 1) == 1) { Console.Error.WriteLine("\tFile is password protected, skipping file"); } else { entries.Add(new MacFileEntry(this, filehdr)); } } cptptr += FILEHDRSIZE; } return(entries); }