aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMax Horn2010-06-15 12:09:51 +0000
committerMax Horn2010-06-15 12:09:51 +0000
commitdea38106f84873a62c4a342c564dbfe9f38ff480 (patch)
tree3939616118e930370c272898d8ebbb92dd954251 /engines
parent98e1f1a193a27cad12a888c8375c523420b25cbe (diff)
downloadscummvm-rg350-dea38106f84873a62c4a342c564dbfe9f38ff480.tar.gz
scummvm-rg350-dea38106f84873a62c4a342c564dbfe9f38ff480.tar.bz2
scummvm-rg350-dea38106f84873a62c4a342c564dbfe9f38ff480.zip
SCI: Change ResourceSource to a class, further OOPify it.
In particular, renamed location_name to _name and made it const and protected. Thus it cannot be changed after creation, and only read access is now possible, via a getter method. svn-id: r49810
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/resource.cpp62
-rw-r--r--engines/sci/resource.h2
-rw-r--r--engines/sci/resource_audio.cpp12
-rw-r--r--engines/sci/resource_intern.h11
4 files changed, 40 insertions, 47 deletions
diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index 0de1a3f2bd..0d7e435aa0 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -168,8 +168,8 @@ uint32 Resource::getAudioCompressionType() {
}
-ResourceSource::ResourceSource(ResSourceType type)
- : _sourceType(type) {
+ResourceSource::ResourceSource(ResSourceType type, const Common::String &name)
+ : _sourceType(type), _name(name) {
scanned = false;
resourceFile = 0;
volume_number = 0;
@@ -192,9 +192,8 @@ ResourceSource::~ResourceSource() {
// Resource source list management
ResourceSource *ResourceManager::addExternalMap(const char *file_name, int volume_nr) {
- ResourceSource *newsrc = new ResourceSource(kSourceExtMap);
+ ResourceSource *newsrc = new ResourceSource(kSourceExtMap, file_name);
- newsrc->location_name = file_name;
newsrc->volume_number = volume_nr;
_sources.push_back(newsrc);
@@ -202,9 +201,8 @@ ResourceSource *ResourceManager::addExternalMap(const char *file_name, int volum
}
ResourceSource *ResourceManager::addExternalMap(const Common::FSNode *mapFile, int volume_nr) {
- ResourceSource *newsrc = new ResourceSource(kSourceExtMap);
+ ResourceSource *newsrc = new ResourceSource(kSourceExtMap, mapFile->getName());
- newsrc->location_name = mapFile->getName();
newsrc->resourceFile = mapFile;
newsrc->volume_number = volume_nr;
@@ -213,9 +211,8 @@ ResourceSource *ResourceManager::addExternalMap(const Common::FSNode *mapFile, i
}
ResourceSource *ResourceManager::addSource(ResourceSource *map, ResSourceType type, const char *filename, int number) {
- ResourceSource *newsrc = new ResourceSource(type);
+ ResourceSource *newsrc = new ResourceSource(type, filename);
- newsrc->location_name = filename;
newsrc->volume_number = number;
newsrc->associated_map = map;
if (type == kSourceAudioVolume)
@@ -226,9 +223,8 @@ ResourceSource *ResourceManager::addSource(ResourceSource *map, ResSourceType ty
}
ResourceSource *ResourceManager::addSource(ResourceSource *map, ResSourceType type, const Common::FSNode *resFile, int number) {
- ResourceSource *newsrc = new ResourceSource(type);
+ ResourceSource *newsrc = new ResourceSource(type, resFile->getName());
- newsrc->location_name = resFile->getName();
newsrc->resourceFile = resFile;
newsrc->volume_number = number;
newsrc->associated_map = map;
@@ -240,9 +236,7 @@ ResourceSource *ResourceManager::addSource(ResourceSource *map, ResSourceType ty
}
ResourceSource *ResourceManager::addPatchDir(const char *dirname) {
- ResourceSource *newsrc = new ResourceSource(kSourceDirectory);
-
- newsrc->location_name = dirname;
+ ResourceSource *newsrc = new ResourceSource(kSourceDirectory, dirname);
_sources.push_back(newsrc);
return 0;
@@ -291,9 +285,9 @@ bool ResourceManager::loadPatch(Resource *res, Common::SeekableReadStream *file)
bool ResourceManager::loadFromPatchFile(Resource *res) {
Common::File file;
- const char *filename = res->_source->location_name.c_str();
+ const Common::String &filename = res->_source->getLocationName();
if (file.open(filename) == false) {
- warning("Failed to open patch file %s", filename);
+ warning("Failed to open patch file %s", filename.c_str());
res->unalloc();
return false;
}
@@ -309,7 +303,7 @@ Common::SeekableReadStream *ResourceManager::getVolumeFile(ResourceSource *sourc
if (source->resourceFile)
return source->resourceFile->createReadStream();
- const char *filename = source->location_name.c_str();
+ const char *filename = source->getLocationName().c_str();
// check if file is already opened
while (it != _volumeFiles.end()) {
@@ -365,7 +359,7 @@ void ResourceManager::loadResource(Resource *res) {
Common::SeekableReadStream *fileStream = getVolumeFile(res->_source);
if (!fileStream) {
- warning("Failed to open %s", res->_source->location_name.c_str());
+ warning("Failed to open %s", res->_source->getLocationName().c_str());
res->unalloc();
return;
}
@@ -896,7 +890,7 @@ ResourceManager::ResVersion ResourceManager::detectMapVersion() {
fileStream = rsrc->resourceFile->createReadStream();
} else {
Common::File *file = new Common::File();
- file->open(rsrc->location_name);
+ file->open(rsrc->getLocationName());
if (file->isOpen())
fileStream = file;
}
@@ -985,7 +979,7 @@ ResourceManager::ResVersion ResourceManager::detectVolVersion() {
fileStream = rsrc->resourceFile->createReadStream();
} else {
Common::File *file = new Common::File();
- file->open(rsrc->location_name);
+ file->open(rsrc->getLocationName());
if (file->isOpen())
fileStream = file;
}
@@ -1089,8 +1083,8 @@ void ResourceManager::processPatch(ResourceSource *source, ResourceType resource
fileStream = source->resourceFile->createReadStream();
} else {
Common::File *file = new Common::File();
- if (!file->open(source->location_name)) {
- warning("ResourceManager::processPatch(): failed to open %s", source->location_name.c_str());
+ if (!file->open(source->getLocationName())) {
+ warning("ResourceManager::processPatch(): failed to open %s", source->getLocationName().c_str());
return;
}
fileStream = file;
@@ -1098,7 +1092,7 @@ void ResourceManager::processPatch(ResourceSource *source, ResourceType resource
int fsize = fileStream->size();
if (fsize < 3) {
- debug("Patching %s failed - file too small", source->location_name.c_str());
+ debug("Patching %s failed - file too small", source->getLocationName().c_str());
return;
}
@@ -1108,7 +1102,7 @@ void ResourceManager::processPatch(ResourceSource *source, ResourceType resource
delete fileStream;
if (patchType != checkForType) {
- debug("Patching %s failed - resource type mismatch", source->location_name.c_str());
+ debug("Patching %s failed - resource type mismatch", source->getLocationName().c_str());
return;
}
@@ -1132,7 +1126,7 @@ void ResourceManager::processPatch(ResourceSource *source, ResourceType resource
if (patchDataOffset + 2 >= fsize) {
debug("Patching %s failed - patch starting at offset %d can't be in file of size %d",
- source->location_name.c_str(), patchDataOffset + 2, fsize);
+ source->getLocationName().c_str(), patchDataOffset + 2, fsize);
return;
}
@@ -1150,7 +1144,7 @@ void ResourceManager::processPatch(ResourceSource *source, ResourceType resource
newrsc->size = fsize - patchDataOffset - 2;
newrsc->_headerSize = patchDataOffset;
newrsc->_fileOffset = 0;
- debugC(1, kDebugLevelResMan, "Patching %s - OK", source->location_name.c_str());
+ debugC(1, kDebugLevelResMan, "Patching %s - OK", source->getLocationName().c_str());
}
void ResourceManager::readResourcePatchesBase36(ResourceSource *source) {
@@ -1230,8 +1224,7 @@ void ResourceManager::readResourcePatchesBase36(ResourceSource *source) {
delete stream;
}
- psrcPatch = new ResourceSource(kSourcePatch);
- psrcPatch->location_name = name;
+ psrcPatch = new ResourceSource(kSourcePatch, name);
processPatch(psrcPatch, (ResourceType)i, resourceNr, resource36.tuple);
}
}
@@ -1279,8 +1272,7 @@ void ResourceManager::readResourcePatches(ResourceSource *source) {
}
if (bAdd) {
- psrcPatch = new ResourceSource(kSourcePatch);
- psrcPatch->location_name = name;
+ psrcPatch = new ResourceSource(kSourcePatch, name);
processPatch(psrcPatch, (ResourceType)i, resourceNr);
}
}
@@ -1300,7 +1292,7 @@ int ResourceManager::readResourceMapSCI0(ResourceSource *map) {
return SCI_ERROR_RESMAP_NOT_FOUND;
} else {
Common::File *file = new Common::File();
- if (!file->open(map->location_name))
+ if (!file->open(map->getLocationName()))
return SCI_ERROR_RESMAP_NOT_FOUND;
fileStream = file;
}
@@ -1316,7 +1308,7 @@ int ResourceManager::readResourceMapSCI0(ResourceSource *map) {
if (fileStream->eos() || fileStream->err()) {
delete fileStream;
- warning("Error while reading %s", map->location_name.c_str());
+ warning("Error while reading %s", map->getLocationName().c_str());
return SCI_ERROR_RESMAP_NOT_FOUND;
}
if (offset == 0xFFFFFFFF)
@@ -1360,7 +1352,7 @@ int ResourceManager::readResourceMapSCI1(ResourceSource *map) {
return SCI_ERROR_RESMAP_NOT_FOUND;
} else {
Common::File *file = new Common::File();
- if (!file->open(map->location_name))
+ if (!file->open(map->getLocationName()))
return SCI_ERROR_RESMAP_NOT_FOUND;
fileStream = file;
}
@@ -1407,7 +1399,7 @@ int ResourceManager::readResourceMapSCI1(ResourceSource *map) {
}
if (fileStream->eos() || fileStream->err()) {
delete fileStream;
- warning("Error while reading %s", map->location_name.c_str());
+ warning("Error while reading %s", map->getLocationName().c_str());
return SCI_ERROR_RESMAP_NOT_FOUND;
}
resId = ResourceId((ResourceType)type, number);
@@ -1465,8 +1457,8 @@ static uint32 resTypeToMacTag(ResourceType type) {
int ResourceManager::readMacResourceFork(ResourceSource *source) {
assert(source->_macResMan);
- if (!source->_macResMan->open(source->location_name.c_str()))
- error("%s is not a valid Mac resource fork", source->location_name.c_str());
+ if (!source->_macResMan->open(source->getLocationName().c_str()))
+ error("%s is not a valid Mac resource fork", source->getLocationName().c_str());
Common::MacResTagArray tagArray = source->_macResMan->getResTagArray();
diff --git a/engines/sci/resource.h b/engines/sci/resource.h
index 822d1d31f4..7677209d2d 100644
--- a/engines/sci/resource.h
+++ b/engines/sci/resource.h
@@ -118,7 +118,7 @@ const char *getResourceTypeName(ResourceType restype);
class ResourceManager;
-struct ResourceSource;
+class ResourceSource;
class ResourceId {
public:
diff --git a/engines/sci/resource_audio.cpp b/engines/sci/resource_audio.cpp
index 85758e9ef0..f7f5077455 100644
--- a/engines/sci/resource_audio.cpp
+++ b/engines/sci/resource_audio.cpp
@@ -37,7 +37,7 @@ void ResourceManager::checkIfAudioVolumeIsCompressed(ResourceSource *source) {
Common::SeekableReadStream *fileStream = getVolumeFile(source);
if (!fileStream) {
- warning("Failed to open %s", source->location_name.c_str());
+ warning("Failed to open %s", source->getLocationName().c_str());
return;
}
@@ -155,15 +155,13 @@ void ResourceManager::addNewGMPatch(const Common::String &gameId) {
gmPatchFile = "TALEGM.PAT";
if (!gmPatchFile.empty() && Common::File::exists(gmPatchFile)) {
- ResourceSource *psrcPatch = new ResourceSource(kSourcePatch);
- psrcPatch->location_name = gmPatchFile;
+ ResourceSource *psrcPatch = new ResourceSource(kSourcePatch, gmPatchFile);
processPatch(psrcPatch, kResourceTypePatch, 4);
}
}
void ResourceManager::processWavePatch(ResourceId resourceId, Common::String name) {
- ResourceSource *resSrc = new ResourceSource(kSourceWave);
- resSrc->location_name = name;
+ ResourceSource *resSrc = new ResourceSource(kSourceWave, name);
Resource *newRes = 0;
@@ -352,7 +350,7 @@ int ResourceManager::readAudioMapSCI11(ResourceSource *map) {
int ResourceManager::readAudioMapSCI1(ResourceSource *map, bool unload) {
Common::File file;
- if (!file.open(map->location_name))
+ if (!file.open(map->getLocationName()))
return SCI_ERROR_RESMAP_NOT_FOUND;
bool oldFormat = (file.readUint16LE() >> 11) == kResourceTypeAudio;
@@ -364,7 +362,7 @@ int ResourceManager::readAudioMapSCI1(ResourceSource *map, bool unload) {
uint32 size = file.readUint32LE();
if (file.eos() || file.err()) {
- warning("Error while reading %s", map->location_name.c_str());
+ warning("Error while reading %s", map->getLocationName().c_str());
return SCI_ERROR_RESMAP_NOT_FOUND;
}
diff --git a/engines/sci/resource_intern.h b/engines/sci/resource_intern.h
index 89fde718d7..60cf1b99a4 100644
--- a/engines/sci/resource_intern.h
+++ b/engines/sci/resource_intern.h
@@ -34,10 +34,13 @@ namespace Common {
namespace Sci {
-struct ResourceSource {
+class ResourceSource {
+protected:
const ResSourceType _sourceType;
+ const Common::String _name;
+
+public:
bool scanned;
- Common::String location_name; // FIXME: Replace by FSNode ?
const Common::FSNode *resourceFile;
int volume_number;
ResourceSource *associated_map;
@@ -46,11 +49,11 @@ struct ResourceSource {
Common::MacResManager *_macResMan;
public:
-
- ResourceSource(ResSourceType type);
+ ResourceSource(ResSourceType type, const Common::String &name);
~ResourceSource();
ResSourceType getSourceType() const { return _sourceType; }
+ const Common::String &getLocationName() const { return _name; }
};