Ejemplo n.º 1
0
        private bool Init()
        {
            //分析备用
            int totalL = (int)_stream.Length;

            if (totalL < 20)
            {
                JW.Common.Log.LogE("IFSFile InitWithData Error IFS File Length");
                return(false);
            }
            //获取签名
            byte[] bbs    = new byte[16];
            int    offset = 0;

            _stream.Read(bbs, 0, 16);
            uint sig = (uint)IFSArchiver.ConvertBytesToInt(bbs, ref offset);

            if (sig != IFSFile.IFSSignature)
            {
                JW.Common.Log.LogE("IFSFile InitWithData Error Signature ");
                return(false);
            }
            this.Signature = sig;
            //获取压缩方式
            this.CompressType = (IFSCompressType)IFSArchiver.ConvertBytesToInt(bbs, ref offset);
            //条目个数
            this.EntryCount = IFSArchiver.ConvertBytesToInt(bbs, ref offset);
            //名称长度
            int entryNameL = IFSArchiver.ConvertBytesToInt(bbs, ref offset);

            if (this.EntryCount == 0)
            {
                JW.Common.Log.LogE("IFSFile InitWithData Error  EntryCount");
                return(false);
            }
            //条目名称段
            this.Entrys    = new IFSEntry[this.EntryCount];
            this._entryDic = new JWObjDictionary <string, IFSEntry>(this.EntryCount);

            for (int i = 0; i < this.EntryCount; i++)
            {
                this.Entrys[i] = new IFSEntry();
            }
            //
            bbs = null;
            //
            byte[] names = new byte[entryNameL];
            _stream.Read(names, 0, entryNameL);
            offset = 0;
            //读取条目名称
            for (int i = 0; i < this.EntryCount; i++)
            {
                IFSEntry entry = this.Entrys[i];
                entry.Name = IFSArchiver.ConvertBytesToString(names, ref offset);
                if (_entryDic.ContainsKey(entry.Name))
                {
                    JW.Common.Log.LogE("IFSFile Repeat Entry:" + entry.Name);
                }
                else
                {
                    _entryDic.Add(entry.Name, entry);
                }
            }
            //条目数据位置
            offset = 0;
            names  = null;
            byte[] poss = new byte[this.EntryCount * 4];
            _stream.Read(poss, 0, this.EntryCount * 4);
            for (int i = 0; i < this.EntryCount; i++)
            {
                IFSEntry entry = this.Entrys[i];
                int      vv    = IFSArchiver.ConvertBytesToInt(poss, ref offset);
                entry.DataPos = vv;
            }
            offset = 0;
            poss   = null;
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取条目数据
        /// </summary>
        /// <param name="name">条目名称</param>
        /// <returns></returns>
        public byte[] GetEntryData(string name)
        {
            if (this.CompressType == IFSCompressType.LZMA)
            {
                JW.Common.Log.LogE("IFSFile GetEntryData Error No Support LZMA Entry TODO");
                return(null);
            }

            if (this.EntryCount <= 0)
            {
                JW.Common.Log.LogE("IFSFile GetEntryData Error No Init");
                return(null);
            }

            if (_stream == null)
            {
                JW.Common.Log.LogE("IFSFile GetEntryData Error No Init");
                return(null);
            }

            IFSEntry find = null;

            if (!_entryDic.TryGetValue(name, out find))
            {
                find = null;
            }
            //for (int i = 0; i < this.EntryCount; i++)
            //{
            //    IFSEntry e = Entrys[i];
            //    if (e.Name.Equals(name))
            //    {
            //        find = e;
            //        break;
            //    }
            //}
            if (find == null)
            {
                JW.Common.Log.LogE("IFSFile GetEntryData Error No Entry :" + name);
                return(null);
            }

            if (find.Data != null)
            {
                return(find.Data);
            }
            //读取
            _stream.Seek(find.DataPos, SeekOrigin.Begin);
            byte[] ll = new byte[4];
            _stream.Read(ll, 0, 4);
            int offset = 0;
            int vv     = IFSArchiver.ConvertBytesToInt(ll, ref offset);

            find.DataSize = vv;
            //
            if (vv == 0)
            {
                JW.Common.Log.LogE("IFSFile GetEntryData Error No Entry Data:" + name);
                return(null);
            }
            byte[] buffer = new byte[vv];
            _stream.Read(buffer, 0, buffer.Length);
            //
            find.Data = buffer;
            //
            return(buffer);
        }