Exemplo n.º 1
0
        internal int GetCharacterDataSize(StringChunkInfo aChunkInfo, int aBytesAvailable)
        {
            if (aBytesAvailable <= 0)
            {
                aChunkInfo.Compressed = true;
                aChunkInfo.Data       = null;
                return(0);
            }
            int num = Math.Min(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(Cch - aChunkInfo.CharPos, aBytesAvailable / 2);

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

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

            if (num2 != 0)
            {
                StringUtil.DecodeTo2ByteLE(aOut, m_rgb, aChunkInfo.CharPos, num2);
            }
            aChunkInfo.CharPos += num2;
            return(num2 * 2);
        }
Exemplo n.º 3
0
        internal void PrepareWriteCharacterData(StringChunkInfo aChunkInfo, int aBytesAvailable)
        {
            if (aBytesAvailable <= 0)
            {
                aChunkInfo.Compressed = true;
                return;
            }
            int num = Math.Min(Cch - aChunkInfo.CharPos, aBytesAvailable);

            if (num == 0)
            {
                aChunkInfo.Compressed = true;
            }
            else
            {
                aChunkInfo.Compressed = StringUtil.CanCompress(m_rgb, aChunkInfo.CharPos, num);
            }
        }
Exemplo n.º 4
0
        internal byte[] GetCharacterData(StringChunkInfo aChunkInfo, int aBytesAvailable)
        {
            if (aBytesAvailable <= 0)
            {
                aChunkInfo.Compressed = true;
                aChunkInfo.Data       = null;
                return(aChunkInfo.Data);
            }
            int num = Math.Min(Cch - aChunkInfo.CharPos, aBytesAvailable);

            if (num == 0)
            {
                aChunkInfo.Compressed = true;
                aChunkInfo.Data       = null;
                return(aChunkInfo.Data);
            }
            string text = 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(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);
        }
Exemplo n.º 5
0
        private int CalcSize()
        {
            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 m_stringOrder)
            {
                stringChunkInfo.CharsTotal = item.Cch;
                int headerSize = item.HeaderSize;
                int num5       = num4 - headerSize;
                if (num5 < 0 || (num5 == 0 && item.Cch != 0))
                {
                    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)
                    {
                        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)
                {
                    continue;
                }
                while (num6 > 0)
                {
                    if (num4 == 0)
                    {
                        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;
                    }
                }
            }
            m_recordSize.Add(num2);
            return(num3 + num2);
        }
Exemplo n.º 6
0
        internal void Write(Stream aOut)
        {
            CalcSize();
            m_count = 0;
            int num  = 8228;
            int num2 = 12;

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

            foreach (StringWrapperBIFF8 item in m_stringOrder)
            {
                stringChunkInfo.CharsTotal = item.Cch;
                int headerSize = item.HeaderSize;
                int num4       = num3 - headerSize;
                if (num4 < 0 || (num4 == 0 && item.Cch != 0))
                {
                    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)
                    {
                        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)
                {
                    continue;
                }
                byte[] formatRunsData = item.FormatRunsData;
                while (num5 > 0)
                {
                    if (num3 == 0)
                    {
                        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;
                    }
                }
            }
        }