예제 #1
0
파일: LingoesLd2.cs 프로젝트: muta6150/e
        /// <summary>
        /// 读取一个词汇的词和解释
        /// </summary>
        /// <param name="inflatedBytes"></param>
        /// <param name="offsetWords"></param>
        /// <param name="offsetXml"></param>
        /// <param name="dataLen"></param>
        /// <param name="wordStringDecoder"></param>
        /// <param name="xmlStringDecoder"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        private InternalWord ReadDefinitionData(byte[] inflatedBytes, int offsetWords,
                                                int offsetXml, int dataLen, Encoding wordStringDecoder,
                                                Encoding xmlStringDecoder, int i)
        {
            var idxData = new int[6];

            GetIdxData(inflatedBytes, dataLen * i, idxData);
            int lastWordPos       = idxData[0];
            int lastXmlPos        = idxData[1];
            int flags             = idxData[2];
            int refs              = idxData[3]; //这个词有多少种解释
            int currentWordOffset = idxData[4]; //词的Offset位置
            int currenXmlOffset   = idxData[5]; //解释XML的Offset位置

            InternalWord word = new InternalWord();

            string xml = xmlStringDecoder.GetString(inflatedBytes, offsetXml + lastXmlPos, currenXmlOffset - lastXmlPos);

            if (!string.IsNullOrEmpty(xml))
            {
                word.Descriptions.Add(currenXmlOffset, xml);
            }
            while (refs-- > 0)
            {
                int position = (offsetWords + lastWordPos);
                int ref1     = BitConverter.ToInt32(inflatedBytes, position);
                GetIdxData(inflatedBytes, dataLen * ref1, idxData);
                lastXmlPos      = idxData[1];
                currenXmlOffset = idxData[5];
                //if (string.IsNullOrEmpty(xml))
                //{
                xml = xmlStringDecoder.GetString(inflatedBytes, offsetXml + lastXmlPos, currenXmlOffset - lastXmlPos);
                word.Descriptions.Add(currenXmlOffset, xml);
                //}
                //else
                //{
                //    xml = xmlStringDecoder.GetString(inflatedBytes, offsetXml + lastXmlPos, currenXmlOffset - lastXmlPos);
                //}
                lastWordPos += 4;
            }
            //defData[1] = xml;

            int position1 = offsetWords + lastWordPos;

            byte[] w = BinFileHelper.ReadArray(inflatedBytes, position1, currentWordOffset - lastWordPos);
            word.Word = wordStringDecoder.GetString(w);
            //if (word == "buy" || word == "bought")
            //{
            //    Debug.Write("Refs:" + currenXmlOffset);
            //}
            //defData[0] = word;
            //return new KeyValuePair<string, string>(word, xml);
            return(word);
        }
예제 #2
0
        /// <summary>
        /// 读取一个词汇的词和解释
        /// </summary>
        /// <param name="inflatedBytes"></param>
        /// <param name="offsetWords"></param>
        /// <param name="offsetXml"></param>
        /// <param name="dataLen"></param>
        /// <param name="wordStringDecoder"></param>
        /// <param name="xmlStringDecoder"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        private InternalWord ReadDefinitionData(byte[] inflatedBytes, int offsetWords,
                                                                int offsetXml, int dataLen, Encoding wordStringDecoder,
                                                                Encoding xmlStringDecoder, int i)
        {
            var idxData = new int[6];
            GetIdxData(inflatedBytes, dataLen*i, idxData);
            int lastWordPos = idxData[0];
            int lastXmlPos = idxData[1];
            int flags = idxData[2];
            int refs = idxData[3];//这个词有多少种解释
            int currentWordOffset = idxData[4];//词的Offset位置
            int currenXmlOffset = idxData[5];//解释XML的Offset位置

            InternalWord word=new InternalWord();

            string xml = xmlStringDecoder.GetString(inflatedBytes, offsetXml + lastXmlPos, currenXmlOffset - lastXmlPos);
            if (!string.IsNullOrEmpty(xml))
            {
                word.Descriptions.Add(currenXmlOffset,xml);
            }
            while (refs-- > 0)
            {
                int position = (offsetWords + lastWordPos);
                int ref1 = BitConverter.ToInt32(inflatedBytes, position);
                GetIdxData(inflatedBytes, dataLen*ref1, idxData);
                lastXmlPos = idxData[1];
                currenXmlOffset = idxData[5];
                //if (string.IsNullOrEmpty(xml))
                //{
                xml = xmlStringDecoder.GetString(inflatedBytes, offsetXml + lastXmlPos, currenXmlOffset - lastXmlPos);
                word.Descriptions.Add(currenXmlOffset, xml);
                //}
                //else
                //{
                //    xml = xmlStringDecoder.GetString(inflatedBytes, offsetXml + lastXmlPos, currenXmlOffset - lastXmlPos);
                //}
                lastWordPos += 4;
            }
            //defData[1] = xml;

            int position1 = offsetWords + lastWordPos;

            byte[] w = BinFileHelper.ReadArray(inflatedBytes, position1, currentWordOffset - lastWordPos);
            word.Word= wordStringDecoder.GetString(w);
            //if (word == "buy" || word == "bought")
            //{
            //    Debug.Write("Refs:" + currenXmlOffset);
            //}
            //defData[0] = word;
            //return new KeyValuePair<string, string>(word, xml);
            return word;
        }