Skip to content

Commit

Permalink
SCI: Resolve some resource related FIXMEs
Browse files Browse the repository at this point in the history
These were introduced in 4f6d42d.
The odd comment dates back to FreeSCI, as far as our history goes, and
seems to be a leftover from an old refactoring during FreeSCI's history
  • Loading branch information
bluegr committed May 15, 2012
1 parent ec7dfed commit c64a69c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
17 changes: 8 additions & 9 deletions engines/sci/resource.cpp
Expand Up @@ -93,20 +93,16 @@ const char *getSciVersionDesc(SciVersion version) {

//#define SCI_VERBOSE_RESMAN 1

// FIXME: This list is out of sync with the enum in resource.h with
// its indices.
static const char *const sci_error_types[] = {
static const char *const s_errorDescriptions[] = {
"No error",
"I/O error",
"Resource is empty (size 0)",
"resource.map entry is invalid",
"resource.map file not found",
"No resource files found",
"Unknown compression method",
"Decompression failed: Decompression buffer overflow",
"Decompression failed: Sanity check failed",
"Decompression failed: Resource too big",
"SCI version is unsupported"
"Decompression failed: Resource too big"
};

static const char *const s_resourceTypeNames[] = {
Expand Down Expand Up @@ -578,7 +574,7 @@ void ResourceSource::loadResource(ResourceManager *resMan, Resource *res) {
if (error) {
warning("Error %d occurred while reading %s from resource file %s: %s",
error, res->_id.toString().c_str(), res->getResourceLocation().c_str(),
sci_error_types[error]);
s_errorDescriptions[error]);
res->unalloc();
}

Expand Down Expand Up @@ -1878,6 +1874,9 @@ int Resource::readResourceInfo(ResVersion volVersion, Common::SeekableReadStream
uint32 wCompression, szUnpacked;
ResourceType type;

if (file->size() == 0)
return SCI_ERROR_EMPTY_RESOURCE;

switch (volVersion) {
case kResVersionSci0Sci1Early:
case kResVersionSci1Middle:
Expand Down Expand Up @@ -1922,7 +1921,7 @@ int Resource::readResourceInfo(ResVersion volVersion, Common::SeekableReadStream
break;
#endif
default:
return SCI_ERROR_INVALID_RESMAP_ENTRY;
return SCI_ERROR_RESMAP_INVALID_ENTRY;
}

// check if there were errors while reading
Expand Down Expand Up @@ -1963,7 +1962,7 @@ int Resource::readResourceInfo(ResVersion volVersion, Common::SeekableReadStream
compression = kCompUnknown;
}

return compression == kCompUnknown ? SCI_ERROR_UNKNOWN_COMPRESSION : 0;
return (compression == kCompUnknown) ? SCI_ERROR_UNKNOWN_COMPRESSION : SCI_ERROR_NONE;
}

int Resource::decompress(ResVersion volVersion, Common::SeekableReadStream *file) {
Expand Down
20 changes: 9 additions & 11 deletions engines/sci/resource.h
Expand Up @@ -54,19 +54,17 @@ enum ResourceStatus {
kResStatusLocked /**< Allocated and in use */
};

// FIXME: This enum is out of sync with its textual descriptions in resource.cpp
/** Initialization result types */
enum {
/** Resource error codes. Should be in sync with s_errorDescriptions */
enum ResourceErrorCodes {
SCI_ERROR_NONE = 0,
SCI_ERROR_IO_ERROR = 1,
SCI_ERROR_INVALID_RESMAP_ENTRY = 2, /**< Invalid resource.map entry */
SCI_ERROR_RESMAP_NOT_FOUND = 3,
SCI_ERROR_NO_RESOURCE_FILES_FOUND = 4, /**< No resource at all was found */
SCI_ERROR_UNKNOWN_COMPRESSION = 5,
SCI_ERROR_DECOMPRESSION_ERROR = 6, /**< sanity checks failed during decompression */
SCI_ERROR_EMPTY_RESOURCE = 2,
SCI_ERROR_RESMAP_INVALID_ENTRY = 3, /**< Invalid resource.map entry */
SCI_ERROR_RESMAP_NOT_FOUND = 4,
SCI_ERROR_NO_RESOURCE_FILES_FOUND = 5, /**< No resource at all was found */
SCI_ERROR_UNKNOWN_COMPRESSION = 6,
SCI_ERROR_DECOMPRESSION_ERROR = 7, /**< sanity checks failed during decompression */
SCI_ERROR_RESOURCE_TOO_BIG = 8 /**< Resource size exceeds SCI_MAX_RESOURCE_SIZE */

// FIXME: This comment makes no sense. Track down in history what it means:
/* the first critical error number */
};

enum {
Expand Down

0 comments on commit c64a69c

Please sign in to comment.