示例#1
0
        public int Read(PacketStream header)
        {
            this.fileSize = header.ReadInt();
            this.URL      = header.ReadStringShort();

            list.Clear();
            checkList.Clear();

            int count = header.ReadUShort();

            return(ReadObjects(header, "", count, 0));
        }
示例#2
0
        public void Read(Stream stream, Action <UpdateUIEnum> UpdateUI, Action <float> SetPercent, Action <string> SetStatus)
        {
            Packs.Clear();

            using (DeflateStream ds = new DeflateStream(stream, CompressionMode.Decompress))
            {
                byte[] buf = new byte[4];
                stream.Read(buf, 0, 4);
                int fileSize = BitConverter.ToInt32(buf, 0) - 4;

                using (PacketStream header = new PacketStream(ds, fileSize, value => SetPercent(0.4f * value)))
                {
                    SetStatus("Reading website...");
                    this.Website = header.ReadStringShort();
                    UpdateUI(UpdateUIEnum.Website);

                    SetStatus("Reading information text...");
                    this.InfoText = header.ReadStringLong();
                    UpdateUI(UpdateUIEnum.InfoText);

                    SetStatus("Reading background image...");
                    int len = header.ReadInt();
                    ImageData = header.ReadBytes(len);
                    UpdateUI(UpdateUIEnum.Image);

                    int count      = header.ReadByte();
                    int checkBytes = 0;
                    for (int i = 0; i < count; i++)
                    {
                        SetStatus(string.Format("Reading data packs ({0}/{1})...", i + 1, count));
                        DataPack pack = new DataPack();
                        checkBytes += pack.Read(header);
                        Packs.Add(pack);
                    }

                    int doneBytes = 0;
                    for (int i = 0; i < count; i++)
                    {
                        SetStatus(string.Format("Checking data packs ({0}/{1})...", i + 1, count));
                        Packs[i].EndCheck(value =>
                        {
                            doneBytes += value;
                            SetPercent(0.4f + 0.6f * doneBytes / checkBytes);
                        });
                    }

                    SetPercent(1);
                }
            }
        }
示例#3
0
        public static PackObject ReadNew(PacketStream stream, string path)
        {
            int    type   = stream.ReadByte();
            string name   = Path.Combine(path, stream.ReadStringShort());
            bool   isLast = (type & 2) > 0;

            if ((type & ~2) == (int)PackObjectType.File)
            {
                PackFile file = new PackFile(new FileInfo(name));
                file.ReadHeader(stream);
                file.IsLast = isLast;
                return(file);
            }
            else
            {
                PackDir dir = new PackDir(new DirectoryInfo(name));
                dir.IsLast = isLast;
                return(dir);
            }
        }