private static HeaderEntry[] ReadFilesInfo(StreamsInfo info, HeaderBuffer headerBytes) { var entries = headerBytes.CreateArray<HeaderEntry>(); int numEmptyStreams = 0; while (true) { var type = headerBytes.ReadProperty(); if (type == HeaderProperty.kEnd) { break; } var size = (int)headerBytes.ReadEncodedInt64(); switch (type) { case HeaderProperty.kName: { if (headerBytes.ReadByte() != 0) { throw new InvalidFormatException("Cannot be external"); } entries.ForEach(f => f.Name = headerBytes.ReadName()); break; } case HeaderProperty.kEmptyStream: { info.EmptyStreamFlags = headerBytes.ReadBoolFlags(entries.Length); numEmptyStreams = info.EmptyStreamFlags.Where(x => x).Count(); break; } case HeaderProperty.kEmptyFile: //just read bytes case HeaderProperty.kAnti: { info.EmptyFileFlags = headerBytes.ReadBoolFlags(numEmptyStreams); break; } default: { headerBytes.ReadBytes(size); break; } } } int emptyFileIndex = 0; int sizeIndex = 0; for (int i = 0; i < entries.Length; i++) { HeaderEntry file = entries[i]; file.IsAnti = false; if (info.EmptyStreamFlags == null) { file.HasStream = true; } else { file.HasStream = !info.EmptyStreamFlags[i]; } if (file.HasStream) { file.IsDirectory = false; file.Size = info.UnpackedStreams[sizeIndex].UnpackedSize; file.FileCRC = info.UnpackedStreams[sizeIndex].Digest; sizeIndex++; } else { if (info.EmptyFileFlags == null) { file.IsDirectory = true; } else { file.IsDirectory = !info.EmptyFileFlags[emptyFileIndex]; } emptyFileIndex++; file.Size = 0; } } return entries; }
private static HeaderEntry[] ReadFilesInfo(StreamsInfo info, HeaderBuffer headerBytes) { var entries = headerBytes.CreateArray <HeaderEntry>(); int numEmptyStreams = 0; while (true) { var type = headerBytes.ReadProperty(); if (type == HeaderProperty.kEnd) { break; } var size = (int)headerBytes.ReadEncodedInt64(); switch (type) { case HeaderProperty.kName: { if (headerBytes.ReadByte() != 0) { throw new InvalidFormatException("Cannot be external"); } entries.ForEach(f => f.Name = headerBytes.ReadName()); break; } case HeaderProperty.kEmptyStream: { info.EmptyStreamFlags = headerBytes.ReadBoolFlags(entries.Length); numEmptyStreams = info.EmptyStreamFlags.Where(x => x).Count(); break; } case HeaderProperty.kEmptyFile: //just read bytes case HeaderProperty.kAnti: { info.EmptyFileFlags = headerBytes.ReadBoolFlags(numEmptyStreams); break; } default: { headerBytes.ReadBytes(size); break; } } } int emptyFileIndex = 0; int sizeIndex = 0; for (int i = 0; i < entries.Length; i++) { HeaderEntry file = entries[i]; file.IsAnti = false; if (info.EmptyStreamFlags == null) { file.HasStream = true; } else { file.HasStream = !info.EmptyStreamFlags[i]; } if (file.HasStream) { file.IsDirectory = false; file.Size = info.UnpackedStreams[sizeIndex].UnpackedSize; file.FileCRC = info.UnpackedStreams[sizeIndex].Digest; sizeIndex++; } else { if (info.EmptyFileFlags == null) { file.IsDirectory = true; } else { file.IsDirectory = !info.EmptyFileFlags[emptyFileIndex]; } emptyFileIndex++; file.Size = 0; } } return(entries); }