[Scummvm-cvs-logs] SF.net SVN: scummvm:[49810] scummvm/trunk/engines/sci
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Tue Jun 15 14:09:51 CEST 2010
Revision: 49810
http://scummvm.svn.sourceforge.net/scummvm/?rev=49810&view=rev
Author: fingolfin
Date: 2010-06-15 12:09:51 +0000 (Tue, 15 Jun 2010)
Log Message:
-----------
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.
Modified Paths:
--------------
scummvm/trunk/engines/sci/resource.cpp
scummvm/trunk/engines/sci/resource.h
scummvm/trunk/engines/sci/resource_audio.cpp
scummvm/trunk/engines/sci/resource_intern.h
Modified: scummvm/trunk/engines/sci/resource.cpp
===================================================================
--- scummvm/trunk/engines/sci/resource.cpp 2010-06-15 12:09:30 UTC (rev 49809)
+++ scummvm/trunk/engines/sci/resource.cpp 2010-06-15 12:09:51 UTC (rev 49810)
@@ -168,8 +168,8 @@
}
-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 @@
// 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 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::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 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,10 +236,8 @@
}
ResourceSource *ResourceManager::addPatchDir(const char *dirname) {
- ResourceSource *newsrc = new ResourceSource(kSourceDirectory);
+ ResourceSource *newsrc = new ResourceSource(kSourceDirectory, dirname);
- newsrc->location_name = dirname;
-
_sources.push_back(newsrc);
return 0;
}
@@ -291,9 +285,9 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
if (bAdd) {
- psrcPatch = new ResourceSource(kSourcePatch);
- psrcPatch->location_name = name;
+ psrcPatch = new ResourceSource(kSourcePatch, name);
processPatch(psrcPatch, (ResourceType)i, resourceNr);
}
}
@@ -1300,7 +1292,7 @@
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 @@
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 @@
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 @@
}
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 @@
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();
Modified: scummvm/trunk/engines/sci/resource.h
===================================================================
--- scummvm/trunk/engines/sci/resource.h 2010-06-15 12:09:30 UTC (rev 49809)
+++ scummvm/trunk/engines/sci/resource.h 2010-06-15 12:09:51 UTC (rev 49810)
@@ -118,7 +118,7 @@
class ResourceManager;
-struct ResourceSource;
+class ResourceSource;
class ResourceId {
public:
Modified: scummvm/trunk/engines/sci/resource_audio.cpp
===================================================================
--- scummvm/trunk/engines/sci/resource_audio.cpp 2010-06-15 12:09:30 UTC (rev 49809)
+++ scummvm/trunk/engines/sci/resource_audio.cpp 2010-06-15 12:09:51 UTC (rev 49810)
@@ -37,7 +37,7 @@
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 @@
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::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 @@
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;
}
Modified: scummvm/trunk/engines/sci/resource_intern.h
===================================================================
--- scummvm/trunk/engines/sci/resource_intern.h 2010-06-15 12:09:30 UTC (rev 49809)
+++ scummvm/trunk/engines/sci/resource_intern.h 2010-06-15 12:09:51 UTC (rev 49810)
@@ -34,10 +34,13 @@
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 @@
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; }
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list