public void OnUpadte(TransferStatusInfo transInfo)
        {
            Title = string.Format("ファイル転送 {0}", transInfo.Fname);
            ProgressBar.Minimum = transInfo.Min;
            ProgressBar.Maximum = transInfo.Max;
            ProgressBar.Value   = transInfo.Value;
            Status.Text         = string.Format("{0}... {1:#,0}/{2:#,0}", transInfo.Mode, transInfo.Value, transInfo.Max);
            //Label.Content = "ほげぷー";

            if (transInfo.finished)
            {
                Close();
            }
        }
Exemple #2
0
        public byte[] GetCompressedData(IProgress <TransferStatusInfo> p, CancellationToken token, TransferStatusInfo transInfo)
        {
            if (buf.Length == 0)
            {
                return(null);
            }

            hashHead    = new List <int> [hashSize];
            hashHist    = new int[(maxPos + 1)];
            hashHistPtr = 0;
            curHash     = 0;

            var outBuf       = new List <byte>();
            var compFlagByte = new byte[1];
            var bs           = new BitStream(compFlagByte);
            int outBits      = 0;
            int compFlagPos  = 0;

            outBuf.Add(0); // ビットフラグを追加
            compFlagPos = outBuf.Count - 1;
            bs.Seek(0, 0);

            curPtr = -minMatch;
            for (int i = 0; i < minMatch; i++)
            {
                ForwardPtrAddHash();
            }

            transInfo.Max = buf.Length;
            while (curPtr < buf.Length)
            {
                int pos, len;
                if (LongestMatch(out pos, out len) && len > minMatch)
                {
                    len = Math.Min(len, maxLen + minMatch);
                    // minMatchバイトより長くマッチしたのでpos,lenを追加
                    bs.WriteBit(1);
                    // pos
                    var writePos = (curPtr - minMatch) - pos; // curPtr-minMatchの位置が、ポジション0
                    outBuf.Add((byte)(writePos >> 8));
                    outBuf.Add((byte)(writePos & 0xff));
                    // len
                    outBuf.Add((byte)(len - minMatch)); // 0でminMatchバイト

                    // ハッシュを更新しつつ、注目点を進める
                    for (int i = 0; i < len; i++)
                    {
                        ForwardPtrAddHash();
                    }
                }
                else
                {
                    // 生データを追加
                    bs.WriteBit(0);
                    int ed = Math.Min(curPtr + minMatch, buf.Length);
                    while (curPtr < ed)
                    {
                        outBuf.Add(buf[curPtr]);
                        ForwardPtrAddHash();
                    }
                }
                if (++outBits == 8)
                {
                    bs.Seek(0, 0);
                    outBuf[compFlagPos] = bs.ReadByte(8); // ビットフラグ書き出し
                    bs.Seek(0, 0);
                    if (curPtr < buf.Length)
                    {
                        outBuf.Add(0); // 新しいビットフラグ追加
                        compFlagPos = outBuf.Count - 1;
                    }
                    outBits = 0;
                }
                transInfo.Value = curPtr;
                p.Report(transInfo);
                if (token.IsCancellationRequested)
                {
                    break;
                }
            }
            transInfo.Value = curPtr;
            p.Report(transInfo);

            if (outBits > 0)
            {
                bs.Seek(0, 0);
                outBuf[compFlagPos] = bs.ReadByte(8); // ビットフラグ書き出し
            }

            return(outBuf.ToArray());
        }