private void WriteBlockEntries(BinaryWriter writer, MemoryStream blockStream, bool flushAllData, byte[] compressorBufferCache)
        {
            int dataRemainder = 0;
            int readPosition  = 0;

            while (true)
            {
                dataRemainder = (int)Math.Min(blockStream.Length - readPosition, WriterBlockSizeThreshold);

                if (dataRemainder == 0 || (dataRemainder < WriterBlockSizeThreshold && !flushAllData))
                {
                    break;
                }

                var blockEntry = new BlockEntry()
                {
                    DecompressedOffset = WriterDecompressedBlockOffset,
                    DecompressedSize   = (uint)dataRemainder,
                    Offset             = (ulong)writer.BaseStream.Position,
                };

                // Compress
                long compressedSize = Utility.OodleLZ.Compress(blockStream.GetBuffer().AsSpan().Slice(readPosition, dataRemainder), compressorBufferCache);

                if (compressedSize == -1)
                {
                    throw new Exception("Buffer compression failed");
                }

                blockEntry.Size = (uint)compressedSize;

                // Encrypt
                if (Header.IsEncrypted)
                {
                    blockEntry.XorDataBuffer(compressorBufferCache);
                }

                // Write to disk
                writer.Write(compressorBufferCache, 0, (int)blockEntry.Size);

                WriterDecompressedBlockOffset += blockEntry.DecompressedSize;
                readPosition += dataRemainder;

                BlockEntries.Add(blockEntry);
            }

            // Free MemoryStream data that was already written to prevent excessive memory consumption
            if (readPosition > 0 && dataRemainder > 0)
            {
                Buffer.BlockCopy(blockStream.GetBuffer(), readPosition, blockStream.GetBuffer(), 0, dataRemainder);
                blockStream.SetLength(blockStream.Length - readPosition);
            }
        }
        private void WriteArchiveHeaders(BinaryWriter writer)
        {
            FileEntries.Sort((x, y) => x.PathHash.CompareTo(y.PathHash));
            Header.FileEntryCount = (uint)FileEntries.Count;

            BlockEntries.Sort((x, y) => x.DecompressedOffset.CompareTo(y.DecompressedOffset));
            Header.BlockEntryCount = (uint)BlockEntries.Count;

            Header.ToData(writer);

            foreach (var entry in FileEntries)
            {
                entry.ToData(writer, Header);
            }

            foreach (var entry in BlockEntries)
            {
                entry.ToData(writer, Header);
            }
        }
        private void WriteBlockEntries(BinaryWriter writer, ConcurrentBag <CompressBlock> blocks)
        {
            foreach (var block in blocks.OrderBy(x => x.DecompressedOffset))
            {
                var blockEntry = new BlockEntry()
                {
                    DecompressedOffset = block.DecompressedOffset,
                    DecompressedSize   = block.DecompressedSize,
                    Offset             = (ulong)writer.BaseStream.Position,
                    Size = block.Size
                };

                // Encrypt
                if (Header.IsEncrypted)
                {
                    blockEntry.XorDataBuffer(block.CompressBuffer);
                }

                // Write to disk
                writer.Write(block.CompressBuffer, 0, (int)blockEntry.Size);

                BlockEntries.Add(blockEntry);
            }
        }
Ejemplo n.º 4
0
        protected override void ShowPage()
        {
            if (usergroupinfo.Radminid == 0)
            {
                AddErrLine("您没有推荐主题的权限!");
                return;
            }
            if (tid == -1)
            {
                return;
            }
            DataTable postInfo = BlockEntries.GetPostInfoByTid(tid);

            title        = postInfo.Rows[0]["title"].ToString();
            summary      = Utils.RemoveHtml(Utils.ClearUBB(postInfo.Rows[0]["message"].ToString().Trim()));
            poster       = postInfo.Rows[0]["poster"].ToString();
            postdatetime = postInfo.Rows[0]["postdatetime"].ToString().Trim();
            //如果是提交...
            if (ispost)
            {
                blockid   = DNTRequest.GetFormInt("blockid", -1);
                blockName = DNTRequest.GetFormString("blockname");
                title     = DNTRequest.GetFormString("topicTitle");
                summary   = DNTRequest.GetFormString("summary");
                NormalValidate(blockName, blockid, title, summary);

                BlockEntryInfo blockEntries = new BlockEntryInfo();
                blockEntries.title             = title;
                blockEntries.blockid           = blockid;
                blockEntries.image             = DNTRequest.GetFormString("selectImage");
                blockEntries.summary           = summary;
                blockEntries.author            = DNTRequest.GetFormString("poster");
                blockEntries.postdatetime      = TypeConverter.StrToDateTime(DNTRequest.GetFormString("postdatetime"));
                blockEntries.link              = "showtopic.aspx?tid=" + tid;
                blockEntries.foretag           = "";
                blockEntries.reartag           = "";
                blockEntries.color             = "";
                blockEntries.html              = "";
                blockEntries.pushedbyuid       = userid;
                blockEntries.pubshedbyusername = username;
                blockEntries.pusheddatetime    = DateTime.Now;
                blockEntries.displayorder      = 1;
                BlockEntries.AddBlockEntry(blockEntries);
                AddMsgLine("推荐成功");
                SetUrl(Urls.ShowDebateAspxRewrite(topicid));
                #region 验证提交信息
                if (IsErr())
                {
                    return;
                }

                //// 如果用户上传了附件,则检测用户是否有上传附件的权限
                //if (ForumUtils.IsPostFile())
                //{
                //    if (Utils.StrIsNullOrEmpty(Attachments.GetAttachmentTypeArray(attachmentTypeSelect)))
                //        AddErrLine("系统不允许上传附件");

                //    if (!UserAuthority.PostAttachAuthority(forum, usergroupinfo, userid, ref msg))
                //        AddErrLine(msg);
                //}

                ////发悬赏校验
                //int topicprice = 0;
                //bool isbonus = type == "bonus";
                //ValidateBonus(ref topicprice, ref isbonus);

                ////发特殊主题校验
                //ValidatePollAndDebate();

                //if (IsErr())
                //    return;
                #endregion
                if (IsErr())
                {
                    return;
                }

                if (IsErr())
                {
                    return;
                }

                //如果已登录就不需要再登录
                if (needlogin && userid > 0)
                {
                    needlogin = false;
                }
            }
            else //非提交操作
            {
                AddLinkCss(BaseConfigs.GetForumPath + "templates/" + templatepath + "/editor.css", "css");
            }
        }