示例#1
0
        public virtual void WriteHeader(PacketStream header)
        {
            if (this.IsLast)
            {
                header.WriteByte((int)this.POType | 2);
            }
            else
            {
                header.WriteByte((int)this.POType);
            }

            header.WriteStringShort(this.Name);
        }
示例#2
0
        public void Build(Action <string> SetState = null)
        {
            if (SetState != null)
            {
                SetState("Writing header...");
            }

            using (MemoryStream ms = new MemoryStream(64000))
                using (PacketStream stream = new PacketStream(ms))
                {
                    stream.WriteStringShort(Website);
                    stream.WriteStringLong(InfoText);

                    stream.Write(ImageData.Length);
                    stream.WriteBytes(ImageData);

                    stream.WriteByte(Packs.Count);
                    for (int i = 0; i < Packs.Count; i++)
                    {
                        if (SetState != null)
                        {
                            SetState(string.Format("Writing '{0}' Pack ({1}/{2}) ...", Packs[i].Name, i + 1, Packs.Count));
                        }

                        Packs[i].Write(stream);
                    }

                    if (SetState != null)
                    {
                        SetState("Finishing header...");
                    }

                    ms.Position = 0;
                    using (FileStream fs = new FileStream("info.bin", FileMode.Create, FileAccess.Write))
                        using (DeflateStream ds = new DeflateStream(fs, CompressionLevel.Optimal))
                        {
                            fs.Write(BitConverter.GetBytes((int)ms.Length), 0, 4);
                            ms.CopyTo(ds);
                        }
                }

            GC.Collect();
            if (SetState != null)
            {
                SetState("Finished.");
            }
        }