Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        public string HashString()
        {
            string hash = CreationTime.ToBinary().ToString() +
                          (Description ?? "").GetHashCode().ToString() +
                          FileFlags.GetHashCode().ToString() +
                          MD5.GetHashCode().ToString() +
                          Size.GetHashCode().ToString() +
                          Version.GetHashCode().ToString();

            return(IO.MD5FromString(hash));
        }
Exemplo n.º 3
0
        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());
        }