コード例 #1
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);
                }
            }
        }
コード例 #2
0
 public void ReadHeader(PacketStream header)
 {
     this.offset = header.ReadInt();
     this.hash   = header.ReadBytes(16);
 }