Пример #1
0
        public byte[] GetRawResource(ResourceKey key)
        {
            if (this._Entries.ContainsKey(key) == false ||
                (this._Entries[key] is StreamEntry) == false)
            {
                throw new KeyNotFoundException();
            }

            var entry = (StreamEntry)this._Entries[key];

            this._Stream.Seek(this._BaseOffset + entry.Offset, SeekOrigin.Begin);

            var data = new byte[entry.CompressedSize];

            this._Stream.Read(data, 0, data.Length);
            return(data);
        }
Пример #2
0
        public void SetResource(ResourceKey key, byte[] data)
        {
            if (this._Stream.CanWrite == false)
            {
                throw new NotSupportedException();
            }

            if (this._Entries.ContainsKey(key) && this._Entries[key] is StreamEntry)
            {
                this._OriginalEntries[key] = (StreamEntry)this._Entries[key];
            }

            this._Entries[key] = new MemoryEntry
            {
                IsCompressed     = false,
                CompressedSize   = (uint)data.Length,
                UncompressedSize = (uint)data.Length,
                Data             = (byte[])(data.Clone()),
            };
        }
Пример #3
0
        public byte[] GetResource(ResourceKey key)
        {
            if (this._Entries.ContainsKey(key) == false)
            {
                throw new KeyNotFoundException();
            }

            var streamEntry = this._Entries[key] as StreamEntry;

            if (streamEntry != null)
            {
                this._Stream.Seek(this._BaseOffset + streamEntry.Offset, SeekOrigin.Begin);

                byte[] data;
                if (streamEntry.IsCompressed == true)
                {
                    data = this._Stream.RefPackDecompress();

                    if (data.Length != streamEntry.UncompressedSize)
                    {
                        throw new InvalidOperationException("decompressed data not same length as specified in index");
                    }
                }
                else
                {
                    data = new byte[streamEntry.UncompressedSize];
                    this._Stream.Read(data, 0, data.Length);
                }

                return(data);
            }

            var memoryEntry = this._Entries[key] as MemoryEntry;

            if (memoryEntry != null)
            {
                return((byte[])(memoryEntry.Data.Clone()));
            }

            throw new InvalidOperationException();
        }
Пример #4
0
        public void DeleteResource(ResourceKey key)
        {
            if (this._Stream.CanWrite == false)
            {
                throw new NotSupportedException();
            }

            if (this._Entries.ContainsKey(key) == false)
            {
                throw new KeyNotFoundException();
            }

            var entry = this._Entries[key] as StreamEntry;

            if (entry != null)
            {
                this._OriginalEntries[key] = entry;
            }

            this._Entries.Remove(key);
        }
Пример #5
0
 public Stream GetResourceStream(ResourceKey key)
 {
     return(new MemoryStream(this.GetResource(key)));
 }