コード例 #1
0
        /// <summary>
        /// Creates a new archive based on the specified stream.
        /// </summary>
        public Archive(Stream stream)
        {
            if (!stream.CanRead)
            {
                throw new IOException("Archive stream must be readable.");
            }
            if (!stream.CanSeek)
            {
                throw new IOException("Archive stream must be seekable.");
            }
            this.stream = stream;

            br = new BinaryReader(stream);
            bw = new BinaryWriter(stream);

            if (stream.Length == 0)
            {
                bw.Write(Encoding.ASCII.GetBytes("Archive:"));
                Reserve();
                stream.Position = 8;
                bw.Write((short)5);
                bw.Write(0);
                bw.Write(-1);
                bw.Write("");
                bw.Flush();
            }
            stream.Position = 0;
            if (Encoding.ASCII.GetString(br.ReadBytes(8)) != "Archive:")
            {
                throw new Exception("Stream is not a valid archive.");
            }

            entries.Add(new FileInfo(this, "", 0, 1));
            AStream      a  = new AStream((FileInfo)entries[0]);
            BinaryReader ar = new BinaryReader(a);

            next_dir = ar.ReadInt32();
            string s;

            while ((s = ar.ReadString()) != "")
            {
                int i = ar.ReadInt32(), j = ar.ReadInt32();
                if (i < 0)
                {
                    entries.Add(new DirInfo(this, s, i, j));
                }
                else
                {
                    entries.Add(new FileInfo(this, s, i, j));
                }
            }
            a.Close();
        }
コード例 #2
0
        internal void UpdateDirs()
        {
            AStream      a  = new AStream((FileInfo)entries[0], FileAccess.ReadWrite);
            BinaryWriter aw = new BinaryWriter(a);

            aw.Write(next_dir);
            foreach (DirInfo di in entries)
            {
                if (di.Name == "")
                {
                    continue;
                }
                aw.Write(di.Name);
                aw.Write(di.Index);
                aw.Write(di.Parent);
            }
            aw.Write("");
            a.SetLength(a.Position);
            a.Close();
        }