Exemple #1
0
        public Archive(string filename)
        {
            // Initialise
            this.filename = filename;
            dctFiles      = new Dictionary <string, ArchiveFile>();
            if (!File.Exists(filename))
            {
                return;
            }

            // Open the file to read
            using (var strm = File.OpenRead(filename))
            {
                var rdr = new BinaryReader(strm);

                // Read the header
                var filecnt = rdr.ReadUInt32();
                var offsets = new List <uint>();

                // Read the offsets
                for (int i = 0; i < filecnt; i++)
                {
                    uint offset = rdr.ReadUInt32();
                    if (offset == 0)
                    {
                        break;
                    }
                    offsets.Add(offset);
                }

                // Read the file entries
                for (int i = 0; i < filecnt; i++)
                {
                    strm.Seek(offsets[i], SeekOrigin.Begin);

                    var f = new ArchiveFile();
                    f.Size = rdr.ReadUInt32();
                    int pathsize = rdr.ReadInt32();
                    f.Filename = Encoding.ASCII.GetString(rdr.ReadBytes(pathsize));
                    f.Offset   = (uint)strm.Position;
                    dctFiles.Add(f.Filename, f);
                }
                rdr.Close();
            }
        }
Exemple #2
0
        public Archive(string filename)
        {
            // Initialise
            this.filename = filename;
            dctFiles = new Dictionary<string, ArchiveFile>();
            if (!File.Exists(filename)) return;

            // Open the file to read
            using (var strm = File.OpenRead(filename))
            {
                var rdr = new BinaryReader(strm);

                // Read the header
                var filecnt = rdr.ReadUInt32();
                var offsets = new List<uint>();

                // Read the offsets
                for (int i = 0; i < filecnt; i++)
                {
                    uint offset = rdr.ReadUInt32();
                    if (offset == 0) break;
                    offsets.Add(offset);
                }

                // Read the file entries
                for (int i = 0; i < filecnt; i++)
                {
                    strm.Seek(offsets[i], SeekOrigin.Begin);

                    var f = new ArchiveFile();
                    f.Size = rdr.ReadUInt32();
                    int pathsize = rdr.ReadInt32();
                    f.Filename = Encoding.ASCII.GetString(rdr.ReadBytes(pathsize));
                    f.Offset = (uint)strm.Position;
                    dctFiles.Add(f.Filename, f);
                }
                rdr.Close();
            }
        }