ScummVM API documentation
dataio.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  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, this code is also
23  * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24  * full text of the license.
25  *
26  */
27 
28 #ifndef GOB_DATAIO_H
29 #define GOB_DATAIO_H
30 
31 #include "common/endian.h"
32 #include "common/str.h"
33 #include "common/hashmap.h"
34 #include "common/array.h"
35 #include "common/file.h"
36 
37 namespace Common {
38 class SeekableReadStream;
39 }
40 
41 namespace Gob {
42 
43 struct ArchiveInfo {
44  Common::String name;
45  bool base;
46  uint32 fileCount;
47 };
48 
49 class DataIO {
50 public:
51  DataIO();
52  ~DataIO();
53 
54  void getArchiveInfo(Common::Array<ArchiveInfo> &info) const;
55 
56  bool openArchive(Common::String name, bool base);
57  bool closeArchive(bool base);
58 
59  bool hasFile(const Common::String &name);
60 
61  int32 fileSize(const Common::String &name);
62 
63  Common::SeekableReadStream *getFile(const Common::String &name);
64  byte *getFile(const Common::String &name, int32 &size);
65 
66  static byte *unpack(const byte *src, uint32 srcSize, int32 &size, uint8 compression = 1);
67  static Common::SeekableReadStream *unpack(Common::SeekableReadStream &src, uint8 compression = 1);
68 
69 private:
70  static const int kMaxArchives = 8;
71 
72  struct Archive;
73 
74  struct File {
75  Common::String name;
76  uint32 size;
77  uint32 offset;
78  uint8 compression;
79 
80  Archive *archive;
81 
82  File();
83  File(const Common::String &n, uint32 s, uint32 o, uint8 c, Archive &a);
84  };
85 
87 
88  struct Archive {
89  Common::String name;
90  Common::File file;
91 
92  FileMap files;
93 
94  bool base;
95  };
96 
97  Common::Array<Archive *> _archives;
98 
99  Archive *openArchive(const Common::Path &name);
100  bool closeArchive(Archive &archive);
101 
102  File *findFile(const Common::String &name);
103 
104  Common::SeekableReadStream *getFile(File &file);
105  byte *getFile(File &file, int32 &size);
106 
107  static byte *unpack(Common::SeekableReadStream &src, int32 &size, uint8 compression, bool useMalloc);
108 
109  static uint32 getSizeChunks(Common::SeekableReadStream &src);
110 
111  static void unpackChunks(Common::SeekableReadStream &src, byte *dest, uint32 size);
112  static void unpackChunk (Common::SeekableReadStream &src, byte *dest, uint32 size);
113 };
114 
115 } // End of namespace Gob
116 
117 #endif // GOB_DATAIO_H
Definition: str.h:59
Definition: array.h:52
Definition: path.h:52
Definition: stream.h:745
Definition: anifile.h:40
Definition: file.h:47
Definition: algorithm.h:29
Definition: dataio.h:43
Definition: dataio.h:49