void Finish()
        {
            // Console.WriteLine("BZip2:Finish");

            try
            {
                var totalBefore = this.bw.TotalBytesWrittenOut;
                this.compressor.CompressAndWrite();
                TraceOutput(TraceBits.Write, "out block length (bytes): {0} (0x{0:X})",
                            this.bw.TotalBytesWrittenOut - totalBefore);

                TraceOutput(TraceBits.Crc, " combined CRC (before): {0:X8}",
                            this.combinedCRC);
                this.combinedCRC  = (this.combinedCRC << 1) | (this.combinedCRC >> 31);
                this.combinedCRC ^= (uint)compressor.Crc32;
                TraceOutput(TraceBits.Crc, " block    CRC         : {0:X8}",
                            this.compressor.Crc32);
                TraceOutput(TraceBits.Crc, " combined CRC (final) : {0:X8}",
                            this.combinedCRC);

                EmitTrailer();
            }
            finally
            {
                this.output     = null;
                this.compressor = null;
                this.bw         = null;
            }
        }
示例#2
0
 public WorkItem(int ix, int blockSize)
 {
     this.ms         = new MemoryStream();
     this.bw         = new BitWriter(this.ms);
     this.Compressor = new BZip2Compressor(this.bw, blockSize);
     this.index      = ix;
 }
 public WorkItem(int ix, int blockSize)
 {
     // compressed data gets written to a MemoryStream
     this.ms         = new MemoryStream();
     this.bw         = new BitWriter(ms);
     this.Compressor = new BZip2Compressor(bw, blockSize);
     this.index      = ix;
 }
 private void Finish()
 {
     try
     {
         int totalBytesWrittenOut = this.bw.TotalBytesWrittenOut;
         this.compressor.CompressAndWrite();
         this.combinedCRC  = (this.combinedCRC << 1 | this.combinedCRC >> 31);
         this.combinedCRC ^= this.compressor.Crc32;
         this.EmitTrailer();
     }
     finally
     {
         this.output     = null;
         this.compressor = null;
         this.bw         = null;
     }
 }
 public BZip2OutputStream(Stream output, int blockSize, bool leaveOpen)
 {
     if (blockSize < BZip2.MinBlockSize || blockSize > BZip2.MaxBlockSize)
     {
         string message = string.Format("blockSize={0} is out of range; must be between {1} and {2}", blockSize, BZip2.MinBlockSize, BZip2.MaxBlockSize);
         throw new ArgumentException(message, "blockSize");
     }
     this.output = output;
     if (!this.output.CanWrite)
     {
         throw new ArgumentException("The stream is not writable.", "output");
     }
     this.bw            = new BitWriter(this.output);
     this.blockSize100k = blockSize;
     this.compressor    = new BZip2Compressor(this.bw, blockSize);
     this.leaveOpen     = leaveOpen;
     this.combinedCRC   = 0u;
     this.EmitHeader();
 }
示例#6
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            setStatusText("Starting...");
            progressBar.Value    = 0;
            progressBarNav.Value = 0;
            if (!sanitycheck())
            {
                return;
            }

            setStatusText("Reading prefix(es)...");
            string[] prefixArr = getPrefixArray();

            if (prefixArr.Length < 1)
            {
                DialogResult result = MessageBox.Show("No map prefix was given (all maps will be counted.)\n\nWould you like to cancel and add a map prefix?", "No map prefix given", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                if (result == DialogResult.Yes || result == DialogResult.Cancel)
                {
                    return;
                }
            }

            setStatusText("Getting .bsp files from /csgo/maps ...");
            DirectoryInfo di = new DirectoryInfo(textBoxServerpath.Text + @"\csgo\maps");

            int compressionLevel = trackBarCompressionLevel.Value;

            if (prefixArr.Length < 1) // Compress all .bsp files
            {
                FileInfo[] filesArr = di.GetFiles("*.bsp");
                progressBar.Maximum = filesArr.Length * progressBar.Step;

                Thread execThread = new Thread(delegate()
                {
                    BZip2Compressor.compressFiles(filesArr, textBoxFastDLpath.Text + @"\maps\", compressionLevel, labelStatusText, progressBar, this);
                });
                execThread.IsBackground = true;
                execThread.Start();
            }
            else // Compress .bsp files matching prefix
            {
                FileInfo[] matchingFiles = getMatchingFiles(di, prefixArr, "*.bsp");
                progressBar.Maximum = matchingFiles.Length * progressBar.Step;

                Thread execThread = new Thread(delegate()
                {
                    BZip2Compressor.compressFiles(matchingFiles, textBoxFastDLpath.Text + @"\maps\", compressionLevel, labelStatusText, progressBar, this);
                })
                {
                    IsBackground = true
                };
                execThread.Start();

                if (checkBoxIncNav.Checked)
                {
                    FileInfo[] matchingNavFiles = getMatchingFiles(di, prefixArr, "*.nav");
                    progressBarNav.Maximum = matchingNavFiles.Length * progressBarNav.Step;

                    Thread execNavThread = new Thread(delegate()
                    {
                        BZip2Compressor.compressFiles(matchingNavFiles, textBoxFastDLpath.Text + @"\maps\", compressionLevel, labelStatusNavText, progressBarNav, this);
                    })
                    {
                        IsBackground = true
                    };
                    execNavThread.Start();
                }
                else
                {
                    labelStatusNavText.Text = "Skipping .nav-files...";
                }
            }
        }