internal void Write(PexWriteMeta bw) { bw.Writer.Write(ModificationTime.ToUInt64()); bw.Writer.Write((ushort)Functions.Count); foreach (var debugFunction in Functions) { debugFunction.Write(bw); } //F04 only if (_gameCategory != GameCategory.Fallout4) { return; } bw.Writer.Write((ushort)PropertyGroups.Count); foreach (var propertyGroup in PropertyGroups) { propertyGroup.Write(bw); } bw.Writer.Write((ushort)StructOrders.Count); foreach (var structOrder in StructOrders) { structOrder.Write(bw); } }
public override byte[] GetBytes() { var idBytes = BitConverter.GetBytes(Id); var nameBytes = Encoding.UTF8.GetBytes(Name); var nameBlockLengthBytes = BitConverter.GetBytes(nameBytes.Length); var createTimeBytes = BitConverter.GetBytes(CreationTime.ToBinary()); var modifyTimeBytes = BitConverter.GetBytes(ModificationTime.ToBinary()); var directoryIdBytes = BitConverter.GetBytes(DirectoryId); var block = new List <byte> { (byte)Mark }; block.AddRange(idBytes); block.AddRange(nameBlockLengthBytes); block.AddRange(nameBytes); block.AddRange(createTimeBytes); block.AddRange(modifyTimeBytes); block.AddRange(directoryIdBytes); var blockLength = block.Count; var blockLengthBytes = BitConverter.GetBytes(blockLength); var retv = new List <byte>(); retv.AddRange(blockLengthBytes); retv.AddRange(block); return(retv.ToArray()); }
public override int GetHashCode() { unchecked { int hashCode = (NodeRef != null ? NodeRef.GetHashCode() : 0); hashCode = (hashCode * 397) ^ IsDeleted.GetHashCode(); hashCode = (hashCode * 397) ^ CreationTime.GetHashCode(); hashCode = (hashCode * 397) ^ ModificationTime.GetHashCode(); hashCode = (hashCode * 397) ^ (Properties != null ? Properties.GetHashCode() : 0); return(hashCode); } }
public bool Equals(Note other) { return(other != null && Id == other.Id && Title == other.Title && Content == other.Content && EqualityComparer <int?> .Default.Equals(CategoryId, other.CategoryId) && EqualityComparer <string[]> .Default.Equals(Keywords, other.Keywords) && CreationTime.Equals(other.CreationTime) && ModificationTime.Equals(other.ModificationTime) && UserId == other.UserId); }
public bool Equals(Node other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(NodeRef, other.NodeRef) && IsDeleted == other.IsDeleted && CreationTime.Equals(other.CreationTime) && ModificationTime.Equals(other.ModificationTime) && DictionaryEqualityComparer.Equals(Properties, other.Properties)); }
public override byte[] GetBytes() { var idBytes = BitConverter.GetBytes(Id); var nameBytes = Encoding.UTF8.GetBytes(Name); var nameBlockLengthBytes = BitConverter.GetBytes(nameBytes.Length); var createTimeBytes = BitConverter.GetBytes(CreationTime.ToBinary()); var modifyTimeBytes = BitConverter.GetBytes(ModificationTime.ToBinary()); var extBytes = Encoding.UTF8.GetBytes(Extension); var directoryIdBytes = BitConverter.GetBytes(DirectoryId); var extBlockLengthBytes = BitConverter.GetBytes(extBytes.Length); var chunksCountBytes = BitConverter.GetBytes(Blocks.Count); var chunkEntriesBytes = Blocks.Select(x => { var positionBytes = BitConverter.GetBytes(x.Position); var lengthBytes = BitConverter.GetBytes(x.Length); return(positionBytes.Concat(lengthBytes).ToArray()); }); var block = new List <byte> { (byte)Mark }; block.AddRange(idBytes); block.AddRange(nameBlockLengthBytes); block.AddRange(nameBytes); block.AddRange(createTimeBytes); block.AddRange(modifyTimeBytes); block.AddRange(extBlockLengthBytes); block.AddRange(extBytes); block.AddRange(directoryIdBytes); block.AddRange(chunksCountBytes); foreach (var chunkEntrysBytes in chunkEntriesBytes) { block.AddRange(chunkEntrysBytes); } var blockLength = block.Count; var blockLengthBytes = BitConverter.GetBytes(blockLength); var retv = new List <byte>(); retv.AddRange(blockLengthBytes); retv.AddRange(block); return(retv.ToArray()); }
// TODO: This method looks like ZipWriter.WriteHeader. Ideally the logic // has to be extracted into a common method and be called from both places // or better refactoring has to be done to keep the header info in a separate // class and use it in the reader and writer. public uint Write(Stream outputStream, ZipCompressionMethod compression) { byte[] encodedFilename = Encoding.UTF8.GetBytes(FileName); byte[] encodedComment = Encoding.UTF8.GetBytes(Comment); //constant sig, then version made by, compabitility, then version to extract outputStream.Write(new byte[] { 80, 75, 1, 2, 0x14, 0, 0x0A, 0 }, 0, 8); HeaderFlags flags = HeaderFlags.UTF8; if (IsEncrypted) { flags |= HeaderFlags.Encrypted; } if (!outputStream.CanSeek) { flags |= HeaderFlags.UsePostDataDescriptor; if (compression == ZipCompressionMethod.LZMA) { flags |= HeaderFlags.Bit1; // eos marker } } outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)flags), 0, 2); outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)compression), 0, 2); // zipping method outputStream.Write(DataConverter.LittleEndian.GetBytes(ModificationTime.DateTimeToDosTime()), 0, 4); // zipping date and time outputStream.Write(DataConverter.LittleEndian.GetBytes(Crc), 0, 4); // file CRC outputStream.Write(DataConverter.LittleEndian.GetBytes(Compressed), 0, 4); // compressed file size outputStream.Write(DataConverter.LittleEndian.GetBytes(Decompressed), 0, 4); // uncompressed file size outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)encodedFilename.Length), 0, 2); // Filename in zip outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0), 0, 2); // extra length outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)encodedComment.Length), 0, 2); outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0), 0, 2); // disk=0 outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0), 0, 2); // file type: binary outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0), 0, 2); // Internal file attributes outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0x8100), 0, 2); // External file attributes (normal/readable) outputStream.Write(DataConverter.LittleEndian.GetBytes(HeaderOffset), 0, 4); // Offset of header outputStream.Write(encodedFilename, 0, encodedFilename.Length); outputStream.Write(encodedComment, 0, encodedComment.Length); return((uint)(8 + 2 + 2 + 4 + 4 + 4 + 4 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 4 + encodedFilename.Length + encodedComment.Length)); }
internal uint Write(Stream outputStream) { byte[] encodedFilename = (forceEncoding ?? Encoding.UTF8).GetBytes(fileName); byte[] encodedComment = (forceEncoding ?? Encoding.UTF8).GetBytes(Comment); var zip64_stream = Compressed >= uint.MaxValue || Decompressed >= uint.MaxValue; var zip64 = zip64_stream || HeaderOffset >= uint.MaxValue || Zip64HeaderOffset != 0; var compressedvalue = zip64 ? uint.MaxValue : (uint)Compressed; var decompressedvalue = zip64 ? uint.MaxValue : (uint)Decompressed; var headeroffsetvalue = zip64 ? uint.MaxValue : (uint)HeaderOffset; var extralength = zip64 ? (2 + 2 + 8 + 8 + 8 + 4) : 0; var version = (byte)(zip64 ? 45 : 20); // Version 20 required for deflate/encryption HeaderFlags flags = (forceEncoding ?? Encoding.UTF8) == Encoding.UTF8 ? HeaderFlags.UTF8 : HeaderFlags.None; if (!outputStream.CanSeek) { // Cannot use data descriptors with zip64: // https://blogs.oracle.com/xuemingshen/entry/is_zipinput_outputstream_handling_of // We check that streams are not written too large in the ZipWritingStream, // so this extra guard is not required, but kept to simplify changing the code // once the zip64 post-data issue is resolved if (!zip64_stream) { flags |= HeaderFlags.UsePostDataDescriptor; } if (compression == ZipCompressionMethod.LZMA) { flags |= HeaderFlags.Bit1; // eos marker } } //constant sig, then version made by, then version to extract outputStream.Write(new byte[] { 80, 75, 1, 2, version, 0, version, 0 }, 0, 8); outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)flags), 0, 2); outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)compression), 0, 2); // zipping method outputStream.Write(DataConverter.LittleEndian.GetBytes(ModificationTime.DateTimeToDosTime()), 0, 4); // zipping date and time outputStream.Write(DataConverter.LittleEndian.GetBytes(Crc), 0, 4); // file CRC outputStream.Write(DataConverter.LittleEndian.GetBytes(compressedvalue), 0, 4); // compressed file size outputStream.Write(DataConverter.LittleEndian.GetBytes(decompressedvalue), 0, 4); // uncompressed file size outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)encodedFilename.Length), 0, 2); // Filename in zip outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)extralength), 0, 2); // extra length outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)encodedComment.Length), 0, 2); outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0), 0, 2); // disk=0 outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0), 0, 2); // file type: binary outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0), 0, 2); // Internal file attributes outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0x8100), 0, 2); // External file attributes (normal/readable) outputStream.Write(DataConverter.LittleEndian.GetBytes(headeroffsetvalue), 0, 4); // Offset of header outputStream.Write(encodedFilename, 0, encodedFilename.Length); if (zip64) { outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)0x0001), 0, 2); outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)(extralength - 4)), 0, 2); outputStream.Write(DataConverter.LittleEndian.GetBytes(Decompressed), 0, 8); outputStream.Write(DataConverter.LittleEndian.GetBytes(Compressed), 0, 8); outputStream.Write(DataConverter.LittleEndian.GetBytes(HeaderOffset), 0, 8); outputStream.Write(DataConverter.LittleEndian.GetBytes(0), 0, 4); // VolumeNumber = 0 } outputStream.Write(encodedComment, 0, encodedComment.Length); return((uint)(8 + 2 + 2 + 4 + 4 + 4 + 4 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 4 + encodedFilename.Length + extralength + encodedComment.Length)); }
internal uint Write(Stream outputStream) { byte[] encodedFilename = archiveEncoding.Encode(fileName); byte[] encodedComment = archiveEncoding.Encode(Comment ?? string.Empty); var zip64_stream = Compressed >= uint.MaxValue || Decompressed >= uint.MaxValue; var zip64 = zip64_stream || HeaderOffset >= uint.MaxValue; var usedCompression = compression; var compressedvalue = zip64 ? uint.MaxValue : (uint)Compressed; var decompressedvalue = zip64 ? uint.MaxValue : (uint)Decompressed; var headeroffsetvalue = zip64 ? uint.MaxValue : (uint)HeaderOffset; var extralength = zip64 ? (2 + 2 + 8 + 8 + 8 + 4) : 0; var version = (byte)(zip64 ? 45 : 20); // Version 20 required for deflate/encryption HeaderFlags flags = Equals(archiveEncoding.GetEncoding(), Encoding.UTF8) ? HeaderFlags.Efs : HeaderFlags.None; if (!outputStream.CanSeek) { // Cannot use data descriptors with zip64: // https://blogs.oracle.com/xuemingshen/entry/is_zipinput_outputstream_handling_of // We check that streams are not written too large in the ZipWritingStream, // so this extra guard is not required, but kept to simplify changing the code // once the zip64 post-data issue is resolved if (!zip64_stream) { flags |= HeaderFlags.UsePostDataDescriptor; } if (usedCompression == ZipCompressionMethod.LZMA) { flags |= HeaderFlags.Bit1; // eos marker } } // Support for zero byte files if (Decompressed == 0 && Compressed == 0) { usedCompression = ZipCompressionMethod.None; } byte[] intBuf = new byte[] { 80, 75, 1, 2, version, 0, version, 0 }; //constant sig, then version made by, then version to extract outputStream.Write(intBuf, 0, 8); BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)flags); outputStream.Write(intBuf, 0, 2); BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)usedCompression); outputStream.Write(intBuf, 0, 2); // zipping method BinaryPrimitives.WriteUInt32LittleEndian(intBuf, ModificationTime.DateTimeToDosTime()); outputStream.Write(intBuf, 0, 4); // zipping date and time BinaryPrimitives.WriteUInt32LittleEndian(intBuf, Crc); outputStream.Write(intBuf, 0, 4); // file CRC BinaryPrimitives.WriteUInt32LittleEndian(intBuf, compressedvalue); outputStream.Write(intBuf, 0, 4); // compressed file size BinaryPrimitives.WriteUInt32LittleEndian(intBuf, decompressedvalue); outputStream.Write(intBuf, 0, 4); // uncompressed file size BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)encodedFilename.Length); outputStream.Write(intBuf, 0, 2); // Filename in zip BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)extralength); outputStream.Write(intBuf, 0, 2); // extra length BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)encodedComment.Length); outputStream.Write(intBuf, 0, 2); BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 0); outputStream.Write(intBuf, 0, 2); // disk=0 BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)flags); outputStream.Write(intBuf, 0, 2); // file type: binary BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)flags); outputStream.Write(intBuf, 0, 2); // Internal file attributes BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 0x8100); outputStream.Write(intBuf, 0, 2); // External file attributes (normal/readable) BinaryPrimitives.WriteUInt32LittleEndian(intBuf, headeroffsetvalue); outputStream.Write(intBuf, 0, 4); // Offset of header outputStream.Write(encodedFilename, 0, encodedFilename.Length); if (zip64) { BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 0x0001); outputStream.Write(intBuf, 0, 2); BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)(extralength - 4)); outputStream.Write(intBuf, 0, 2); BinaryPrimitives.WriteUInt64LittleEndian(intBuf, Decompressed); outputStream.Write(intBuf, 0, 8); BinaryPrimitives.WriteUInt64LittleEndian(intBuf, Compressed); outputStream.Write(intBuf, 0, 8); BinaryPrimitives.WriteUInt64LittleEndian(intBuf, HeaderOffset); outputStream.Write(intBuf, 0, 8); BinaryPrimitives.WriteUInt32LittleEndian(intBuf, 0); outputStream.Write(intBuf, 0, 4); // VolumeNumber = 0 } outputStream.Write(encodedComment, 0, encodedComment.Length); return((uint)(8 + 2 + 2 + 4 + 4 + 4 + 4 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 4 + encodedFilename.Length + extralength + encodedComment.Length)); }