ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
file.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 SCUMM_FILE_H
23 #define SCUMM_FILE_H
24 
25 #include "common/file.h"
26 #include "common/stream.h"
27 
28 #include "scumm/detection.h"
29 
30 namespace Scumm {
31 
32 #ifdef ENABLE_SCUMM
33 class ScummEngine;
34 #endif
35 
37 protected:
38  byte _encbyte;
40  Common::String _debugName;
41 
42 public:
43  BaseScummFile() : _encbyte(0) {}
44  void setEnc(byte value) { _encbyte = value; }
45 
46  virtual bool open(const Common::Path &filename) = 0;
47  virtual bool openSubFile(const Common::Path &filename) = 0;
48  virtual void close();
49 
50  int64 pos() const override = 0;
51  int64 size() const override = 0;
52  bool seek(int64 offs, int whence = SEEK_SET) override = 0;
53 
54  Common::String getDebugName() const { return _debugName; }
55 
56  bool isOpen() const { return !!_baseStream; }
57 
58 // Unused
59 #if 0
60  virtual bool eos() const = 0;
61  virtual uint32 read(void *dataPtr, uint32 dataSize) = 0;
62 #endif
63 };
64 
65 #ifdef ENABLE_SCUMM
66 
67 class ScummFile : public BaseScummFile {
68 protected:
69  int64 _subFileStart;
70  int32 _subFileLen;
71  bool _myEos; // Have we read past the end of the subfile?
72  bool _isMac;
73 
74  void setSubfileRange(int64 start, int32 len);
75  void resetSubfile();
76 
77 public:
78  explicit ScummFile(const ScummEngine *vm);
79 
80  bool open(const Common::Path &filename) override;
81  bool openSubFile(const Common::Path &filename) override;
82 
83  void clearErr() override { _myEos = false; BaseScummFile::clearErr(); }
84 
85  bool eos() const override;
86  int64 pos() const override;
87  int64 size() const override;
88  bool seek(int64 offs, int whence = SEEK_SET) override;
89  uint32 read(void *dataPtr, uint32 dataSize) override;
90 };
91 
92 #endif
93 
94 class ScummDiskImage : public BaseScummFile {
95 private:
97  byte _roomDisks[59] = {}, _roomTracks[59] = {}, _roomSectors[59] = {};
98 
99  byte *_buf = nullptr;
100 
101  const GameSettings _game;
102 
103  const Common::String _disk1, _disk2;
104  int _openedDisk = 0;
105 
106  int _numGlobalObjects = 0;
107  int _numRooms = 0;
108  int _numCostumes = 0;
109  int _numScripts = 0;
110  int _numSounds = 0;
111  const int *_resourcesPerFile;
112 
113  bool openDisk(char num);
114 
115  bool generateIndex();
116  bool generateResource(int res);
117 
118  uint16 extractIndex(Common::WriteStream *out);
119  uint16 extractResource(Common::WriteStream *out, int res);
120 
121  byte fileReadByte();
122  uint16 fileReadUint16LE();
123 
124 public:
125  ScummDiskImage(const char *disk1, const char *disk2, GameSettings game);
126 
127  bool open(const Common::Path &filename) override;
128  bool openSubFile(const Common::Path &filename) override;
129 
130  void close() override;
131  bool eos() const override { return _stream->eos(); }
132  int64 pos() const override { return _stream->pos(); }
133  int64 size() const override { return _stream->size(); }
134  bool seek(int64 offs, int whence = SEEK_SET) override { return _stream->seek(offs, whence); }
135  uint32 read(void *dataPtr, uint32 dataSize) override;
136 };
137 
139  byte id;
140  Common::Platform platform;
141  const char *pattern;
142  const char *indexFileName;
143  const char *executableName;
144  int32 start;
145  int32 len;
146 };
147 
148 #ifdef ENABLE_SCUMM
149 
150 class ScummSteamFile : public ScummFile {
151 private:
152  const SteamIndexFile &_indexFile;
153 
154  bool openWithSubRange(const Common::Path &filename, int32 subFileStart, int32 subFileLen);
155 public:
156  ScummSteamFile(const ScummEngine *vm, const SteamIndexFile &indexFile) : ScummFile(vm), _indexFile(indexFile) {}
157 
158  bool open(const Common::Path &filename) override;
159 };
160 
161 struct PAKFile {
162  uint64 start;
163  uint32 len;
164 };
165 
166 typedef Common::HashMap<Common::String, PAKFile> PAKFileHashMap;
167 
168 class ScummPAKFile : public ScummFile {
169 private:
170  PAKFileHashMap _pakIndex;
171 
172  void readIndex(const Common::Path &containerFile, bool isFT);
173 
174 public:
175  ScummPAKFile(const ScummEngine *vm, bool indexFiles = true);
176  ~ScummPAKFile() override { _pakIndex.clear(); }
177 
178  bool openSubFile(const Common::Path &filePath) override;
179  PAKFile *getPAKFileIndex(Common::String fileName);
180  void setPAKFileIndex(Common::String fileName, const PAKFile &pakFile);
181 };
182 
183 #endif
184 
185 } // End of namespace Scumm
186 
187 #endif
bool eos() const override
Definition: file.h:131
bool seek(int64 offs, int whence=SEEK_SET) override
Definition: file.h:134
virtual int64 size() const =0
Definition: str.h:59
virtual int64 pos() const =0
Definition: stream.h:77
int64 size() const override
Definition: file.h:133
int64 pos() const override
Definition: file.h:132
virtual bool seek(int64 offset, int whence=SEEK_SET)=0
virtual void clearErr()
Definition: stream.h:71
virtual bool eos() const =0
Definition: path.h:52
Definition: stream.h:745
Definition: file.h:94
Definition: scumm.h:504
int64 size() const override=0
Definition: detection.h:45
Definition: file.h:138
Definition: hashmap.h:85
bool seek(int64 offs, int whence=SEEK_SET) override=0
int64 pos() const override=0
Definition: actor.h:30
Platform
Definition: platform.h:46
virtual uint32 read(void *dataPtr, uint32 dataSize)=0
Definition: file.h:36