diff options
Diffstat (limited to 'engines/wintermute/Base/file')
-rw-r--r-- | engines/wintermute/Base/file/BDiskFile.cpp | 22 | ||||
-rw-r--r-- | engines/wintermute/Base/file/BPkgFile.cpp | 32 |
2 files changed, 33 insertions, 21 deletions
diff --git a/engines/wintermute/Base/file/BDiskFile.cpp b/engines/wintermute/Base/file/BDiskFile.cpp index ce6a6a100c..c26b3f02c6 100644 --- a/engines/wintermute/Base/file/BDiskFile.cpp +++ b/engines/wintermute/Base/file/BDiskFile.cpp @@ -45,7 +45,7 @@ void correctSlashes(char *fileName) { }
}
-Common::SeekableReadStream *openDiskFile(const Common::String &Filename, CBFileManager *fileManager) {
+Common::SeekableReadStream *openDiskFile(const Common::String &Filename, CBFileManager *fileManager) {
char FullPath[MAX_PATH];
uint32 prefixSize = 0;
Common::SeekableReadStream *file = NULL;
@@ -60,7 +60,7 @@ Common::SeekableReadStream *openDiskFile(const Common::String &Filename, CBFileM delete tempFile;
}
}
-
+
// if we didn't find it in search paths, try to open directly
if (!file) {
strcpy(FullPath, Filename.c_str());
@@ -73,28 +73,28 @@ Common::SeekableReadStream *openDiskFile(const Common::String &Filename, CBFileM delete tempFile;
}
}
-
+
if (file) {
uint32 magic1, magic2;
magic1 = file->readUint32LE();
magic2 = file->readUint32LE();
-
+
bool compressed = false;
if (magic1 == DCGF_MAGIC && magic2 == COMPRESSED_FILE_MAGIC) compressed = true;
-
+
if (compressed) {
uint32 DataOffset, CompSize, UncompSize;
DataOffset = file->readUint32LE();
CompSize = file->readUint32LE();
UncompSize = file->readUint32LE();
-
+
byte *CompBuffer = new byte[CompSize];
if (!CompBuffer) {
error("Error allocating memory for compressed file '%s'", Filename.c_str());
delete file;
return NULL;
}
-
+
byte *data = new byte[UncompSize];
if (!data) {
error("Error allocating buffer for file '%s'", Filename.c_str());
@@ -104,16 +104,16 @@ Common::SeekableReadStream *openDiskFile(const Common::String &Filename, CBFileM }
file->seek(DataOffset + prefixSize, SEEK_SET);
file->read(CompBuffer, CompSize);
-
+
if (Common::uncompress(data, (unsigned long *)&UncompSize, CompBuffer, CompSize) != true) {
error("Error uncompressing file '%s'", Filename.c_str());
delete [] CompBuffer;
delete file;
return NULL;
}
-
+
delete [] CompBuffer;
-
+
return new Common::MemoryReadStream(data, UncompSize, DisposeAfterUse::YES);
delete file;
file = NULL;
@@ -121,7 +121,7 @@ Common::SeekableReadStream *openDiskFile(const Common::String &Filename, CBFileM file->seek(0, SEEK_SET);
return file;
}
-
+
return file;
}
diff --git a/engines/wintermute/Base/file/BPkgFile.cpp b/engines/wintermute/Base/file/BPkgFile.cpp index ed3a24f313..02aec3419f 100644 --- a/engines/wintermute/Base/file/BPkgFile.cpp +++ b/engines/wintermute/Base/file/BPkgFile.cpp @@ -45,12 +45,24 @@ class CBPkgFile : public Common::SeekableReadStream { Common::SeekableReadStream *_stream;
public:
CBPkgFile(Common::SeekableReadStream *stream, uint32 knownLength) : _size(knownLength), _stream(stream) {}
- virtual ~CBPkgFile() { delete _stream; }
- virtual uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); }
- virtual bool eos() const { return _stream->eos(); }
- virtual int32 pos() const { return _stream->pos(); }
- virtual int32 size() const { return _size; }
- virtual bool seek(int32 offset, int whence = SEEK_SET) { return _stream->seek(offset, whence); }
+ virtual ~CBPkgFile() {
+ delete _stream;
+ }
+ virtual uint32 read(void *dataPtr, uint32 dataSize) {
+ return _stream->read(dataPtr, dataSize);
+ }
+ virtual bool eos() const {
+ return _stream->eos();
+ }
+ virtual int32 pos() const {
+ return _stream->pos();
+ }
+ virtual int32 size() const {
+ return _size;
+ }
+ virtual bool seek(int32 offset, int whence = SEEK_SET) {
+ return _stream->seek(offset, whence);
+ }
};
Common::SeekableReadStream *openPkgFile(const Common::String &Filename, CBFileManager *fileManager) {
@@ -66,14 +78,14 @@ Common::SeekableReadStream *openPkgFile(const Common::String &Filename, CBFileMa fileEntry = fileManager->GetPackageEntry(fileName);
if (!fileEntry) return NULL;
-
+
file = fileEntry->_package->GetFilePointer();
if (!file) return NULL;
-
+
// TODO: Cleanup
bool compressed = (fileEntry->_compressedLength != 0);
/* _size = fileEntry->_length; */
-
+
if (compressed) {
// TODO: Really, most of this logic might be doable directly in the fileEntry?
// But for now, this should get us rolling atleast.
@@ -86,7 +98,7 @@ Common::SeekableReadStream *openPkgFile(const Common::String &Filename, CBFileMa }
file->seek(0);
-
+
return file;
}
|