Ejemplo n.º 1
0
        public int GetCharacterDataSize(StringChunkInfo aChunkInfo, int aBytesAvailable)
        {
            if (aBytesAvailable <= 0)
            {
                aChunkInfo.Compressed = true;
                aChunkInfo.Data       = null;
                return(0);
            }
            int num = Math.Min(this.Cch - aChunkInfo.CharPos, aBytesAvailable);

            if (num == 0)
            {
                aChunkInfo.Compressed = true;
                aChunkInfo.Data       = null;
                return(0);
            }
            if (aChunkInfo.Compressed)
            {
                aChunkInfo.CharPos += num;
                return(num);
            }
            int num2 = Math.Min(this.Cch - aChunkInfo.CharPos, aBytesAvailable / 2);

            aChunkInfo.CharPos += num2;
            return(num2 * 2);
        }
Ejemplo n.º 2
0
        public int WriteCharacterData(Stream aOut, StringChunkInfo aChunkInfo, int aBytesAvailable)
        {
            if (aBytesAvailable <= 0)
            {
                aChunkInfo.Compressed = true;
                aChunkInfo.Data       = null;
                return(0);
            }
            int num = Math.Min(this.Cch - aChunkInfo.CharPos, aBytesAvailable);

            if (num == 0)
            {
                aChunkInfo.Compressed = true;
                aChunkInfo.Data       = null;
                return(0);
            }
            if (aChunkInfo.Compressed)
            {
                StringUtil.DecodeTo1Byte(aOut, this.m_rgb, aChunkInfo.CharPos, num);
                aChunkInfo.CharPos += num;
                return(num);
            }
            int num2 = Math.Min(this.Cch - aChunkInfo.CharPos, aBytesAvailable / 2);

            if (num2 != 0)
            {
                StringUtil.DecodeTo2ByteLE(aOut, this.m_rgb, aChunkInfo.CharPos, num2);
            }
            aChunkInfo.CharPos += num2;
            return(num2 * 2);
        }
Ejemplo n.º 3
0
 public void PrepareWriteCharacterData(StringChunkInfo aChunkInfo, int aBytesAvailable)
 {
     if (aBytesAvailable <= 0)
     {
         aChunkInfo.Compressed = true;
     }
     else
     {
         int num = Math.Min(this.Cch - aChunkInfo.CharPos, aBytesAvailable);
         if (num == 0)
         {
             aChunkInfo.Compressed = true;
         }
         else
         {
             aChunkInfo.Compressed = StringUtil.CanCompress(this.m_rgb, aChunkInfo.CharPos, num);
         }
     }
 }
Ejemplo n.º 4
0
        public byte[] GetCharacterData(StringChunkInfo aChunkInfo, int aBytesAvailable)
        {
            if (aBytesAvailable <= 0)
            {
                aChunkInfo.Compressed = true;
                aChunkInfo.Data       = null;
                return(aChunkInfo.Data);
            }
            int num = Math.Min(this.Cch - aChunkInfo.CharPos, aBytesAvailable);

            if (num == 0)
            {
                aChunkInfo.Compressed = true;
                aChunkInfo.Data       = null;
                return(aChunkInfo.Data);
            }
            string text = this.String.Substring(aChunkInfo.CharPos, aChunkInfo.CharPos + num - aChunkInfo.CharPos);

            if (StringUtil.CanCompress(text))
            {
                aChunkInfo.Compressed = true;
                aChunkInfo.Data       = StringUtil.DecodeTo1Byte(text);
                aChunkInfo.CharPos   += num;
                return(aChunkInfo.Data);
            }
            int num2 = Math.Min(this.Cch - aChunkInfo.CharPos, aBytesAvailable / 2);

            byte[] data;
            if (num2 != 0)
            {
                text = text.Substring(0, num2);
                data = StringUtil.DecodeTo2ByteLE(text);
            }
            else
            {
                data = new byte[0];
            }
            aChunkInfo.Compressed = false;
            aChunkInfo.Data       = data;
            aChunkInfo.CharPos   += num2;
            return(aChunkInfo.Data);
        }
Ejemplo n.º 5
0
        private int CalcSize()
        {
            this.m_recordSize = new List <int>();
            int             num             = 8228;
            int             num2            = 12;
            int             num3            = 0;
            int             num4            = num - num2;
            StringChunkInfo stringChunkInfo = new StringChunkInfo();

            foreach (StringWrapperBIFF8 item in this.m_stringOrder)
            {
                stringChunkInfo.CharsTotal = item.Cch;
                int headerSize = item.HeaderSize;
                int num5       = num4 - headerSize;
                if (num5 < 0 || (num5 == 0 && item.Cch != 0))
                {
                    this.m_recordSize.Add(num2);
                    num3 += num2;
                    num2  = 4;
                    num4  = num - num2;
                }
                int aBytesAvailable = num4 - headerSize;
                num2 += headerSize;
                item.PrepareWriteCharacterData(stringChunkInfo, aBytesAvailable);
                num2 += item.GetCharacterDataSize(stringChunkInfo, aBytesAvailable);
                num4  = ((!stringChunkInfo.HasMore) ? (num - num2) : 0);
                while (stringChunkInfo.HasMore)
                {
                    aBytesAvailable = num4;
                    item.PrepareWriteCharacterData(stringChunkInfo, aBytesAvailable);
                    int characterDataSize = item.GetCharacterDataSize(stringChunkInfo, aBytesAvailable);
                    num2 += characterDataSize;
                    if (characterDataSize == 0)
                    {
                        this.m_recordSize.Add(num2);
                        num3           += num2;
                        num2            = 5;
                        aBytesAvailable = 8223;
                        item.PrepareWriteCharacterData(stringChunkInfo, aBytesAvailable);
                        num2 += item.GetCharacterDataSize(stringChunkInfo, aBytesAvailable);
                    }
                    num4 = ((!stringChunkInfo.HasMore) ? (num - num2) : 0);
                }
                int num6 = item.FormatRunsDataSize;
                if (num6 > 0)
                {
                    while (num6 > 0)
                    {
                        if (num4 == 0)
                        {
                            this.m_recordSize.Add(num2);
                            num3 += num2;
                            num2  = 4;
                            num4  = num - num2;
                        }
                        int num7 = (num4 < num6) ? num4 : num6;
                        num7 -= num7 % 4;
                        if (num7 > 0)
                        {
                            num4 -= num7;
                            num6 -= num7;
                            num2 += num7;
                        }
                        else
                        {
                            num4 = 0;
                        }
                    }
                }
            }
            this.m_recordSize.Add(num2);
            return(num3 + num2);
        }
Ejemplo n.º 6
0
        public void Write(Stream aOut)
        {
            this.CalcSize();
            this.m_count = 0;
            int num  = 8228;
            int num2 = 12;

            this.StartRecord(aOut, 252);
            LittleEndianHelper.WriteIntU(aOut, this.m_totalStrings);
            LittleEndianHelper.WriteIntU(aOut, this.UniqueStrings);
            int             num3            = num - num2;
            StringChunkInfo stringChunkInfo = new StringChunkInfo();

            foreach (StringWrapperBIFF8 item in this.m_stringOrder)
            {
                stringChunkInfo.CharsTotal = item.Cch;
                int headerSize = item.HeaderSize;
                int num4       = num3 - headerSize;
                if (num4 < 0 || (num4 == 0 && item.Cch != 0))
                {
                    this.StartRecord(aOut, 60);
                    num2 = 4;
                    num3 = num - num2;
                }
                int aBytesAvailable = num3 - headerSize;
                num2 += headerSize;
                item.PrepareWriteCharacterData(stringChunkInfo, aBytesAvailable);
                item.WriteHeaderData(aOut, stringChunkInfo.Compressed);
                num2 += item.WriteCharacterData(aOut, stringChunkInfo, aBytesAvailable);
                num3  = ((!stringChunkInfo.HasMore) ? (num - num2) : 0);
                while (stringChunkInfo.HasMore)
                {
                    aBytesAvailable = num3;
                    int charPos           = stringChunkInfo.CharPos;
                    int characterDataSize = item.GetCharacterDataSize(stringChunkInfo, aBytesAvailable);
                    stringChunkInfo.CharPos = charPos;
                    if (characterDataSize == 0)
                    {
                        this.StartRecord(aOut, 60);
                        num2            = 5;
                        aBytesAvailable = 8223;
                        item.PrepareWriteCharacterData(stringChunkInfo, aBytesAvailable);
                        aOut.WriteByte((byte)((!stringChunkInfo.Compressed) ? 1 : 0));
                    }
                    else
                    {
                        item.PrepareWriteCharacterData(stringChunkInfo, aBytesAvailable);
                    }
                    num2 += item.WriteCharacterData(aOut, stringChunkInfo, aBytesAvailable);
                    num3  = ((!stringChunkInfo.HasMore) ? (num - num2) : 0);
                }
                int num5 = item.FormatRunsDataSize;
                if (num5 > 0)
                {
                    byte[] formatRunsData = item.FormatRunsData;
                    while (num5 > 0)
                    {
                        if (num3 == 0)
                        {
                            this.StartRecord(aOut, 60);
                            num2 = 4;
                            num3 = num - num2;
                        }
                        int num6 = (num3 < num5) ? num3 : num5;
                        num6 -= num6 % 4;
                        if (num6 > 0)
                        {
                            aOut.Write(formatRunsData, formatRunsData.Length - num5, num6);
                            num3 -= num6;
                            num5 -= num6;
                            num2 += num6;
                        }
                        else
                        {
                            num3 = 0;
                        }
                    }
                }
            }
        }