示例#1
0
        private KeyValuePair <string, string>[] Read(ZeroPositionStreamPasser sp)
        {
            StreamEx s = sp.GetStream();

            s.Position = 0x0;
            Int32 header = s.ReadInt32BigEndian();

            int count = s.ReadInt32BigEndian();

            Int32[] keyaddresses = new Int32[count];
            Int32[] blockaddress = new Int32[count];

            for (int i = 0; i < count; i++)
            {
                keyaddresses[i] = (Int32)s.Position;
                Int32 addrread = s.ReadInt32BigEndian();
                keyaddresses[i] = addrread == 0 ? 0 : keyaddresses[i] + addrread;

                blockaddress[i] = (Int32)s.Position;
                addrread        = s.ReadInt32BigEndian();
                blockaddress[i] = addrread == 0 ? 0 : blockaddress[i] + addrread;
            }

            Encoding encoding = Encoding.GetEncoding("utf-8");

            KeyValuePair <string, string>[] result = new KeyValuePair <string, string> [count];
            for (int i = 0; i < count; i++)
            {
                string key = "";
                string txt = "";

                if (keyaddresses[i] != 0)
                {
                    s.Position = keyaddresses[i];
                    key        = s.ReadString((int)(s.Length - s.Position), encoding);
                }
//                     ((
//                     (blockaddress[i] == 0)
//                     ? (i + 1 == count ? (Int32)s.Length : keyaddresses[i + 1])
//                     : blockaddress[i])
//                     - keyaddresses[i],encoding);
                if (blockaddress[i] != 0)
                {
//                    txt = s.ReadString(((i + 1 == count) ? (Int32)s.Length : keyaddresses[i + 1]) - blockaddress[i], encoding);
                    s.Position = blockaddress[i];
                    txt        = s.ReadString((int)(s.Length - s.Position), encoding);

                    for (int k = 0; k < _convertChar.Count; k++)
                    {
                        txt = txt.Replace(_convertChar[k].Key, _convertChar[k].Value);
                    }
                }

                result[i] = new KeyValuePair <string, string>(key, txt);
            }
            return(result);
        }
示例#2
0
文件: DAT.cs 项目: HappyASR/pujia
    //使用离散文件包接口,表示文件数据不一定非要连续,即通过位置和长度来确定,连续文件一般只有长度一个数值

    //在构造函数中填入文件包读取的部分,对每个文件需要调用PushFile以构造路径信息和各种映射信息
    public DAT(ZeroPositionStreamPasser sp) : base(sp)
    {
        var s = sp.GetStream();

        //判断文件头部是否正常
        if (s.ReadSimpleString(12) != "NISPACK")
        {
            throw new InvalidDataException();
        }

        var NumFile = s.ReadInt32();

        RootValue = FileDB.CreateDirectory("", "");

        for (var n = 0; n < NumFile; n += 1)
        {
            //读取索引的各部分
            var Name    = s.ReadSimpleString(32);
            var Address = s.ReadInt32();
            var Length  = s.ReadInt32();
            var Unknown = s.ReadInt32();

            //创建一个文件描述信息,包括文件名、文件大小、文件地址
            var f = new FileDB(Name, FileDB.FileType.File, Length, Address, null);

            //将文件描述信息传递到框架内部
            //框架内部能够自动创建文件树(将文件名中以'\'或者'/'表示的文件路径拆开)
            //框架内部能够自动创建IndexOfFile映射表,能够将文件描述信息映射到文件索引的出现顺序
            //框架内部还记录一些数据用于寻找能放下数据的空洞
            PushFile(f);
        }

        //离散文件在打开的时候应该寻找空洞,以供导入文件使用
        //寻找的起始地址是从当前位置的下一个块开始的位置
        ScanHoles(GetSpace(s.Position));
    }