Ejemplo n.º 1
0
        private void WriteFolderBlocks(BinaryWriterEx bw, FolderEntry folder)
        {
            var allChilds      = folder.GetEntryHierarchy().ToList();
            var totalFilesSize = allChilds.OfType <FileEntry>().Sum(x => x.FileSize);
            var folderBlock    = new LIFFBlock
            {
                BlockHeader = 1,
                BlockType   = 3,
                BlockSize   = ((allChilds.Count() + 1) * LIFFBLOCK_SIZE) + (int)totalFilesSize
            };

            bw.WriteStruct(folderBlock);

            foreach (var entry in folder.Entries.OrderBy(x => x.Name))
            {
                if (entry is FileEntry file)
                {
                    var fileBlock = new LIFFBlock
                    {
                        BlockHeader = 1,
                        BlockType   = 4,
                        Spacing2    = 1,
                        BlockSize   = LIFFBLOCK_SIZE + (int)file.FileSize
                    };
                    bw.WriteStruct(fileBlock);
                    var fileStream = file.GetStream();
                    //fileStream.CopyTo(bw.BaseStream, 4096);

                    byte[] buffer    = new byte[4096];
                    int    bytesRead = 0;
                    while (bytesRead < file.FileSize)
                    {
                        int b = fileStream.Read(buffer, 0, buffer.Length);
                        bytesRead += b;
                        bw.Write(buffer, 0, b);
                        if (b == 0)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    WriteFolderBlocks(bw, (FolderEntry)entry);
                }
            }
        }
Ejemplo n.º 2
0
        private void WriteFolderEntries(BinaryWriterEx bw, FolderEntry folder)
        {
            var allChilds = folder.GetEntryHierarchy().ToList();

            var folderEntry = new LIFFFolderEntry()
            {
                EntryType  = 1,
                Filename   = folder.IsRootDirectory ? null : folder.Name,
                EntryCount = folder.Entries.Count,
                Reserved1  = folder.IsRootDirectory ? 0 : 7,
                BlockSize  = 20
            };

            bw.WriteStruct(folderEntry);

            foreach (var entry in folder.Entries.OrderBy(x => x.Name))
            {
                if (entry is FileEntry file)
                {
                    var fileEntry = new LIFFFileEntry()
                    {
                        EntryType = 2,
                        Filename  = file.Name,
                        FileSize  = (int)file.FileSize + LIFFBLOCK_SIZE,
                        Reserved1 = 7,
                        Created   = file.CreatedDate.ToFileTime(),
                        Modified  = file.ModifiedDate.ToFileTime(),
                        Accessed  = file.AccessedDate.ToFileTime()
                    };
                    bw.WriteStruct(fileEntry);
                }
                else
                {
                    WriteFolderEntries(bw, (FolderEntry)entry);
                }
            }
        }