ScummVM API documentation
resources.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SHERLOCK_RESOURCES_H
23 #define SHERLOCK_RESOURCES_H
24 
25 #include "common/array.h"
26 #include "common/file.h"
27 #include "common/hashmap.h"
28 #include "common/hash-str.h"
29 #include "common/rect.h"
30 #include "common/str.h"
31 #include "common/str-array.h"
32 #include "common/stream.h"
33 #include "graphics/surface.h"
34 
35 namespace Sherlock {
36 
37 typedef Common::Array<byte> CacheEntry;
39 
40 struct LibraryEntry {
41  uint32 _offset, _size;
42  int _index;
43 
44  LibraryEntry() : _index(0), _offset(0), _size(0) {}
45  LibraryEntry(int index, uint32 offset, uint32 size) :
46  _index(index), _offset(offset), _size(size) {}
47 };
50 
51 class SherlockEngine;
52 
53 class Cache {
54 private:
55  SherlockEngine *_vm;
56  CacheHash _resources;
57 public:
58  Cache(SherlockEngine *_vm);
59 
63  bool isCached(const Common::Path &filename) const;
64 
70  void load(const Common::Path &name);
71 
75  void load(const Common::Path &name, Common::SeekableReadStream &stream);
76 
80  Common::SeekableReadStream *get(const Common::Path &filename) const;
81 };
82 
83 class Resources {
84 private:
85  SherlockEngine *_vm;
86  Cache _cache;
87  LibraryIndexes _indexes;
88  int _resourceIndex;
89 
93  void loadLibraryIndex(const Common::Path &libFilename, Common::SeekableReadStream *stream, bool isNewStyle);
94 public:
96 
101  void addToCache(const Common::Path &filename);
102 
106  void addToCache(const Common::Path &filename, const Common::Path &libFilename);
107 
111  void addToCache(const Common::Path &filename, Common::SeekableReadStream &stream);
112 
113  bool isInCache(const Common::Path &filename) const { return _cache.isCached(filename); }
114 
118  void decompressIfNecessary(Common::SeekableReadStream *&stream);
119 
123  Common::SeekableReadStream *load(const Common::Path &filename);
124 
128  Common::SeekableReadStream *load(const Common::Path &filename, const Common::Path &libraryFile, bool suppressErrors = false);
129 
133  bool exists(const Common::Path &filename) const;
134 
140  int resourceIndex() const;
141 
145  void getResourceNames(const Common::Path &libraryFile, Common::StringArray &names);
146 
151 
155  Common::SeekableReadStream *decompress(Common::SeekableReadStream &source, uint32 outSize);
156 
160  void decompress(Common::SeekableReadStream &source, byte *buffer, uint32 outSize);
161 
165  static Common::SeekableReadStream *decompressLZ(Common::SeekableReadStream &source, uint32 outSize);
166 
170  static void decompressLZ(Common::SeekableReadStream &source, byte *outBuffer, int32 outSize, int32 inSize);
171 };
172 
173 } // End of namespace Sherlock
174 
175 #endif
bool isCached(const Common::Path &filename) const
Definition: animation.h:29
Definition: path.h:52
Definition: stream.h:745
Definition: resources.h:83
Definition: sherlock.h:76
Definition: resources.h:53
Definition: resources.h:40