Beispiel #1
0
        public void Write(PacketStream header)
        {
            list.Clear();
            Search(list, new DirectoryInfo(Folder));
            if (list.Count > ushort.MaxValue)
            {
                throw new Exception("Pack has more than 65535 files/directories!");
            }

            using (FileStream fs = new FileStream(name + ".bin", FileMode.Create, FileAccess.Write))
            {
                foreach (PackFile file in list.Where(fi => fi is PackFile).OrderByDescending(fi => fi.Info.LastWriteTimeUtc).Cast <PackFile>())
                {
                    file.Write(fs);
                }
                header.Write((int)fs.Length);
            }

            header.WriteStringShort(URL);
            header.WriteUShort(list.Count);
            for (int i = 0; i < list.Count; i++)
            {
                list[i].WriteHeader(header);
            }
        }
Beispiel #2
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);
        }
Beispiel #3
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.");
            }
        }