Beispiel #1
0
        private void ResolveAllEntries()
        {
            // get all file entries and clear array
            PboEntry[] entries = _entries.ToArray();
            _entries.Clear();

            // resolve any binded files
            for (int i = 0; i < entries.Length; i++)
            {
                if (entries[i].Resolver is PboStreamResolver)
                {
                    // get file resolver
                    PboStreamResolver resolver = entries[i].Resolver as PboStreamResolver;

                    // read data from file
                    Stream pboStream = resolver.Resolve();
                    byte[] data      = new byte[entries[i].Size];

                    if (resolver.Packing == PboPacking.Packed)
                    {
                        Console.WriteLine(entries[i].Name);
                    }
                    try {
                        pboStream.Read(data, 0, (int)entries[i].Size);
                        if (resolver.Packing == PboPacking.Packed)
                        {
                            Console.WriteLine(Encoding.ASCII.GetString(data));
                        }
                    } catch (Exception ex) {
                        if (resolver.Packing == PboPacking.Packed)
                        {
                            Console.WriteLine("Error: " + ex.Message);
                        }
                    }

                    // load into and convert to memory backed resolver
                    entries[i] = new PboEntry(entries[i].Name, entries[i].Size, entries[i].Timestamp, this, new PboDataResolver(data));
                }
            }

            // restore entries
            _entries = new List <PboEntry>(entries);
        }
Beispiel #2
0
        /// <summary>
        /// Loads entries into memory.
        /// </summary>
        private void Load()
        {
            // seek to begin
            _stream.Seek(0, SeekOrigin.Begin);

            // file structures
            List <FileEntry> fileEntries = new List <FileEntry>();

            // begin reading structs
            string     name;
            uint       originalSize, dataSize, timestamp;
            PboPacking packing;

            while (true)
            {
                name         = ReadStringNT(_reader);
                packing      = (PboPacking)_reader.ReadUInt32();
                originalSize = _reader.ReadUInt32();
                _reader.ReadUInt32();
                timestamp = _reader.ReadUInt32();
                dataSize  = _reader.ReadUInt32();

                if (packing == PboPacking.Uncompressed)
                {
                    originalSize = dataSize;
                }

                // handle eoh
                if (name == "" && packing != PboPacking.ProductEntry)
                {
                    break;
                }

                // handle product entries
                if (packing == PboPacking.ProductEntry)
                {
                    string str = ReadStringNT(_reader);

                    while (str != "")
                    {
                        _productEntries.Add(str);
                        str = ReadStringNT(_reader);
                    }
                }
                else
                {
                    fileEntries.Add(new FileEntry()
                    {
                        Name         = name,
                        DataSize     = dataSize,
                        OriginalSize = originalSize,
                        Timestamp    = DateTimeOffset.FromUnixTimeSeconds(timestamp),
                        Packing      = packing
                    });
                }
            }

            // compute final offsets
            long dataOffset = _stream.Position;

            foreach (FileEntry f in fileEntries)
            {
                // create entry
                PboEntry entry = new PboEntry(f.Name, f.OriginalSize, f.Timestamp, this, new PboStreamResolver(_stream, f.Packing, dataOffset, f.DataSize));

                _entries.Add(entry);
                dataOffset += f.OriginalSize;
            }
        }