-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresourceman.cpp
118 lines (95 loc) · 3.18 KB
/
resourceman.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "common/debug.h"
#include "common/stream.h"
#include "common/substream.h"
#include "common/textconsole.h"
#include "dgds/dgds.h"
#include "dgds/resourceman.h"
namespace Dgds {
#define FILENAME_LENGTH 12
ResourceManager::ResourceManager() {
const char* indexFiles[] = {
"volume.vga", // early Dragon versions
"volume.rmf", // Beamish / HoC
"volume.map" // Beamish CD
};
Common::File indexFile;
for (int i = 0; i < ARRAYSIZE(indexFiles); i++) {
if (Common::File::exists(indexFiles[i])) {
indexFile.open(indexFiles[i]);
break;
}
}
indexFile.skip(4); // header, TODO
int volumes = indexFile.readUint16LE();
for (int i = 0; i < volumes; i++) {
Common::String volumeName;
for (int j = 0; j < FILENAME_LENGTH; j++)
volumeName += indexFile.readByte();
volumeName.toLowercase();
_volumes[i].open(volumeName);
indexFile.skip(1); // unknown
int entries = indexFile.readUint16LE();
debug("File %s has %d entries", volumeName.c_str(), entries);
for (int j = 0; j < entries; j++) {
Resource res;
res.volume = i;
res.checksum = indexFile.readUint32LE();
res.pos = indexFile.readUint32LE();
_volumes[i].seek(res.pos, SEEK_SET);
res.pos += FILENAME_LENGTH + 1 + 4;
Common::String fileName;
for (int k = 0; k < FILENAME_LENGTH; k++)
fileName += _volumes[i].readByte();
fileName.toLowercase();
_volumes[i].skip(1); // unknown
res.size = _volumes[i].readUint32LE();
_resources[fileName] = res;
if (fileName == "" || res.size == 0)
continue;
debug(" - %s at %d, size: %d", fileName.c_str(), res.pos, res.size);
/*Common::DumpFile out;
Common::String outName = "dgds/";
out.open(outName + fileName);
byte *data = new byte[res.size];
_volumes[i].read(data, res.size);
out.write(data, res.size);
out.flush();
out.close();
delete[] data;*/
}
}
indexFile.close();
}
ResourceManager::~ResourceManager() {
for (int i = 0; i < MAX_VOLUMES; i++)
_volumes[i].close();
}
Common::SeekableReadStream *ResourceManager::getResource(Common::String name) {
name.toLowercase();
if (!_resources.contains(name))
return nullptr;
Resource res = _resources[name];
return new Common::SeekableSubReadStream(&_volumes[res.volume], res.pos, res.pos + res.size);
}
} // End of namespace Dgds