diff options
| -rw-r--r-- | engines/titanic/image_decoders.cpp | 7 | ||||
| -rw-r--r-- | engines/titanic/simple_file.cpp | 49 | ||||
| -rw-r--r-- | engines/titanic/simple_file.h | 22 | ||||
| -rw-r--r-- | engines/titanic/string.cpp | 4 | ||||
| -rw-r--r-- | engines/titanic/string.h | 11 | ||||
| -rw-r--r-- | engines/titanic/video_surface.cpp | 4 | 
6 files changed, 79 insertions, 18 deletions
diff --git a/engines/titanic/image_decoders.cpp b/engines/titanic/image_decoders.cpp index 896155d7b8..bf941f83b5 100644 --- a/engines/titanic/image_decoders.cpp +++ b/engines/titanic/image_decoders.cpp @@ -24,8 +24,8 @@  namespace Titanic { -CJPEGDecode::CJPEGDecode(const CString &name): _file(name), -		_width(0), _height(0) { +CJPEGDecode::CJPEGDecode(const CString &name) : _width(0), _height(0) { +	_file.open(name);  }  void CJPEGDecode::decode(OSVideoSurface &surface) { @@ -35,8 +35,7 @@ void CJPEGDecode::decode(OSVideoSurface &surface) {  /*------------------------------------------------------------------------*/ -CTargaDecode::CTargaDecode(const CString &name) : _file(name), -		_width(0), _height(0) { +CTargaDecode::CTargaDecode(const CString &name) : _width(0), _height(0) {  }  void CTargaDecode::decode(OSVideoSurface &surface) { diff --git a/engines/titanic/simple_file.cpp b/engines/titanic/simple_file.cpp index f2fdf4effb..c975a27b28 100644 --- a/engines/titanic/simple_file.cpp +++ b/engines/titanic/simple_file.cpp @@ -25,6 +25,13 @@  namespace Titanic { +bool File::open(const Common::String &name) { +	if (!Common::File::open(name)) +		error("Could not open file - %s", name.c_str()); +} + +/*------------------------------------------------------------------------*/ +  SimpleFile::SimpleFile(): _inStream(nullptr), _outStream(nullptr), _lineCount(1) {  } @@ -333,11 +340,45 @@ void SimpleFile::writeClassEnd(int indent) {  /*------------------------------------------------------------------------*/ -StdCWadFile::StdCWadFile(const CString &name): SimpleFile() { -	if (!_file.open(name)) -		error("Could not open file - %s", name.c_str()); +void StdCWadFile::open(const CString &name) { +	File f; + +	// Check for whether it is indeed a file/resource pair +	int idx = name.indexOf('#'); + +	if (idx < 0) { +		// Nope, so open up file for standard reading +		assert(!name.empty()); +		f.open(name); + +		SimpleFile::open(f.readStream(f.size())); +		return; +	} -	open(&_file); +	// Split up the name and resource, and get the resource index +	CString filename = name.left(idx) + ".st"; +	int extPos = name.lastIndexOf('.'); +	CString resStr = name.mid(idx + 1, extPos - idx - 1); +	int resIndex = resStr.readInt(); + +	// Open up the index for access  +	f.open(filename); +	int indexSize = f.readUint32LE() / 4; +	assert(resIndex < indexSize); + +	// Get the specific resource's offset, and size by also +	// getting the offset of the following resource +	f.seek(resIndex * 4); +	uint resOffset = f.readUint32LE(); +	uint nextOffset = (resIndex == (indexSize - 1)) ? f.size() : +		f.readUint32LE(); + +	// Read in the resource +	f.seek(resOffset); +	Common::SeekableReadStream *stream = f.readStream(nextOffset - resOffset); +	SimpleFile::open(stream); + +	f.close();  }  } // End of namespace Titanic diff --git a/engines/titanic/simple_file.h b/engines/titanic/simple_file.h index 0a452e49cd..b779fd0a35 100644 --- a/engines/titanic/simple_file.h +++ b/engines/titanic/simple_file.h @@ -36,6 +36,15 @@ class Decompressor;  class DecompressorData;  /** + * Simple ScummVM File descendent that throws a wobbly if + * the file it tries to open isn't present + */ +class File : public Common::File { +public: +	virtual bool open(const Common::String &name); +}; + +/**   * This class implements basic reading and writing to files   */  class SimpleFile { @@ -203,11 +212,18 @@ public:  	}  }; +/** + * Derived file that handles WAD archives containing multiple files + */  class StdCWadFile : public SimpleFile { -private: -	Common::File _file;  public: -	StdCWadFile(const CString &name); +	StdCWadFile() : SimpleFile() {} +	virtual ~StdCWadFile() {} + +	/** +	 * Open up the specified file +	 */ +	void open(const CString &name);  };  } // End of namespace Titanic diff --git a/engines/titanic/string.cpp b/engines/titanic/string.cpp index 44e0e627f3..ed5379be65 100644 --- a/engines/titanic/string.cpp +++ b/engines/titanic/string.cpp @@ -48,12 +48,12 @@ CString CString::mid(uint start) const {  	return mid(start, strSize - start);  } -int CString::indexOf(char c) { +int CString::indexOf(char c) const {  	const char *charP = strchr(c_str(), c);  	return charP ? charP - c_str() : -1;  } -int CString::lastIndexOf(char c) { +int CString::lastIndexOf(char c) const {  	const char *charP = strrchr(c_str(), c);  	return charP ? charP - c_str() : -1;  } diff --git a/engines/titanic/string.h b/engines/titanic/string.h index 6b8e4b784e..08b5649dc9 100644 --- a/engines/titanic/string.h +++ b/engines/titanic/string.h @@ -69,12 +69,12 @@ public:  	/**  	 * Returns the index of the first occurance of a given character  	 */ -	int indexOf(char c); +	int indexOf(char c) const;  	/**  	 * Returns the index of the last occurance of a given character  	 */ -	int lastIndexOf(char c); +	int lastIndexOf(char c) const;  	/**  	 * Returns the type of a filename based on it's extension @@ -85,6 +85,13 @@ public:  	 * Returns the type of an image filename based on it's extension  	 */  	ImageType imageTypeSuffix() const; + +	/** +	 * Parses the string as an integer and returns the value +	 */ +	int readInt() const { +		return atoi(c_str()); +	}  };  } // End of namespace Titanic diff --git a/engines/titanic/video_surface.cpp b/engines/titanic/video_surface.cpp index 19dcf25610..840680070c 100644 --- a/engines/titanic/video_surface.cpp +++ b/engines/titanic/video_surface.cpp @@ -79,10 +79,8 @@ void OSVideoSurface::loadTarga(const CResourceKey &key) {  }  void OSVideoSurface::loadJPEG(const CResourceKey &key) { -	CString filename = key.exists(); -  	// Decode the image -	CJPEGDecode decoder(filename); +	CJPEGDecode decoder(key.getString());  	decoder.decode(*this);  	if (proc26() == 2)  | 
