ScummVM API documentation
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 class ScummEngine;
33 
35 protected:
36  byte _encbyte;
38  Common::String _debugName;
39 
40 public:
41  BaseScummFile() : _encbyte(0) {}
42  void setEnc(byte value) { _encbyte = value; }
43 
44  virtual bool open(const Common::Path &filename) = 0;
45  virtual bool openSubFile(const Common::Path &filename) = 0;
46  virtual void close();
47 
48  int64 pos() const override = 0;
49  int64 size() const override = 0;
50  bool seek(int64 offs, int whence = SEEK_SET) override = 0;
51 
52  Common::String getDebugName() const { return _debugName; }
53 
54  bool isOpen() const { return !!_baseStream; }
55 
56 // Unused
57 #if 0
58  virtual bool eos() const = 0;
59  virtual uint32 read(void *dataPtr, uint32 dataSize) = 0;
60 #endif
61 };
62 
63 class ScummFile : public BaseScummFile {
64 protected:
65  int32 _subFileStart;
66  int32 _subFileLen;
67  bool _myEos; // Have we read past the end of the subfile?
68  bool _isMac;
69 
70  void setSubfileRange(int32 start, int32 len);
71  void resetSubfile();
72 
73 public:
74  explicit ScummFile(const ScummEngine *vm);
75 
76  bool open(const Common::Path &filename) override;
77  bool openSubFile(const Common::Path &filename) override;
78 
79  void clearErr() override { _myEos = false; BaseScummFile::clearErr(); }
80 
81  bool eos() const override;
82  int64 pos() const override;
83  int64 size() const override;
84  bool seek(int64 offs, int whence = SEEK_SET) override;
85  uint32 read(void *dataPtr, uint32 dataSize) override;
86 };
87 
88 class ScummDiskImage : public BaseScummFile {
89 private:
91  byte _roomDisks[59] = {}, _roomTracks[59] = {}, _roomSectors[59] = {};
92 
93  byte *_buf = nullptr;
94 
95  const GameSettings _game;
96 
97  const Common::String _disk1, _disk2;
98  int _openedDisk = 0;
99 
100  int _numGlobalObjects = 0;
101  int _numRooms = 0;
102  int _numCostumes = 0;
103  int _numScripts = 0;
104  int _numSounds = 0;
105  const int *_resourcesPerFile;
106 
107  bool openDisk(char num);
108 
109  bool generateIndex();
110  bool generateResource(int res);
111 
112  uint16 extractIndex(Common::WriteStream *out);
113  uint16 extractResource(Common::WriteStream *out, int res);
114 
115  byte fileReadByte();
116  uint16 fileReadUint16LE();
117 
118 public:
119  ScummDiskImage(const char *disk1, const char *disk2, GameSettings game);
120 
121  bool open(const Common::Path &filename) override;
122  bool openSubFile(const Common::Path &filename) override;
123 
124  void close() override;
125  bool eos() const override { return _stream->eos(); }
126  int64 pos() const override { return _stream->pos(); }
127  int64 size() const override { return _stream->size(); }
128  bool seek(int64 offs, int whence = SEEK_SET) override { return _stream->seek(offs, whence); }
129  uint32 read(void *dataPtr, uint32 dataSize) override;
130 };
131 
133  byte id;
134  Common::Platform platform;
135  const char *pattern;
136  const char *indexFileName;
137  const char *executableName;
138  int32 start;
139  int32 len;
140 };
141 
142 class ScummSteamFile : public ScummFile {
143 private:
144  const SteamIndexFile &_indexFile;
145 
146  bool openWithSubRange(const Common::Path &filename, int32 subFileStart, int32 subFileLen);
147 public:
148  ScummSteamFile(const ScummEngine *vm, const SteamIndexFile &indexFile) : ScummFile(vm), _indexFile(indexFile) {}
149 
150  bool open(const Common::Path &filename) override;
151 };
152 
153 } // End of namespace Scumm
154 
155 #endif
bool eos() const override
Definition: file.h:125
bool seek(int64 offs, int whence=SEEK_SET) override
Definition: file.h:128
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:127
int64 pos() const override
Definition: file.h:126
virtual bool seek(int64 offset, int whence=SEEK_SET)=0
virtual void clearErr()
Definition: stream.h:71
virtual bool eos() const =0
void clearErr() override
Definition: file.h:79
Definition: file.h:142
Definition: path.h:52
Definition: stream.h:745
Definition: file.h:88
Definition: scumm.h:518
int64 size() const override=0
Definition: detection.h:44
Definition: file.h:132
bool seek(int64 offs, int whence=SEEK_SET) override=0
int64 pos() const override=0
Definition: file.h:63
Definition: actor.h:30
Platform
Definition: platform.h:46
virtual uint32 read(void *dataPtr, uint32 dataSize)=0
Definition: file.h:34