aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base/file/base_disk_file.cpp
diff options
context:
space:
mode:
authorEinar Johan Trøan Sømåen2012-07-22 07:24:48 +0200
committerEinar Johan Trøan Sømåen2012-07-22 07:24:48 +0200
commit742521c20db68e965761ba9309bb0a3dea379217 (patch)
treeb11b0da21b95260657f5bf13c1501d145266c24d /engines/wintermute/base/file/base_disk_file.cpp
parentf54f262bb56d251d131109a81cad7811e240ff4f (diff)
downloadscummvm-rg350-742521c20db68e965761ba9309bb0a3dea379217.tar.gz
scummvm-rg350-742521c20db68e965761ba9309bb0a3dea379217.tar.bz2
scummvm-rg350-742521c20db68e965761ba9309bb0a3dea379217.zip
WINTERMUTE: Redo base_file_manager, to use FSLists for registering/opening packages.
This is helpfull for consistency between registering and lookup, and allows for explicit removal/adding of sub_paths for the engine. But most importantly it keeps the loading consistent and non-duplicated for detection.
Diffstat (limited to 'engines/wintermute/base/file/base_disk_file.cpp')
-rw-r--r--engines/wintermute/base/file/base_disk_file.cpp57
1 files changed, 22 insertions, 35 deletions
diff --git a/engines/wintermute/base/file/base_disk_file.cpp b/engines/wintermute/base/file/base_disk_file.cpp
index 6c89fc22f1..b4653c2c80 100644
--- a/engines/wintermute/base/file/base_disk_file.cpp
+++ b/engines/wintermute/base/file/base_disk_file.cpp
@@ -36,6 +36,7 @@
#include "common/memstream.h"
#include "common/file.h"
#include "common/zlib.h"
+#include "common/archive.h"
namespace WinterMute {
@@ -50,27 +51,13 @@ Common::SeekableReadStream *openDiskFile(const Common::String &filename, BaseFil
uint32 prefixSize = 0;
Common::SeekableReadStream *file = NULL;
- for (uint32 i = 0; i < fileManager->_singlePaths.size(); i++) {
- sprintf(fullPath, "%s%s", fileManager->_singlePaths[i], filename.c_str());
- correctSlashes(fullPath);
- Common::File *tempFile = new Common::File();
- if (tempFile->open(fullPath)) {
- file = tempFile;
- } else {
- delete tempFile;
- }
- }
-
- // if we didn't find it in search paths, try to open directly
- if (!file) {
- strcpy(fullPath, filename.c_str());
- correctSlashes(fullPath);
-
- Common::File *tempFile = new Common::File();
- if (tempFile->open(fullPath)) {
- file = tempFile;
- } else {
- delete tempFile;
+ Common::ArchiveMemberList files;
+ SearchMan.listMatchingMembers(files, filename);
+
+ for (Common::ArchiveMemberList::iterator it = files.begin(); it != files.end(); it++) {
+ if ((*it)->getName() == filename) {
+ file = (*it)->createReadStream();
+ break;
}
}
@@ -83,38 +70,38 @@ Common::SeekableReadStream *openDiskFile(const Common::String &filename, BaseFil
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();
+ uint32 dataOffset, compSize, uncompSize;
+ dataOffset = file->readUint32LE();
+ compSize = file->readUint32LE();
+ uncompSize = file->readUint32LE();
- byte *CompBuffer = new byte[CompSize];
- if (!CompBuffer) {
+ 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];
+ byte *data = new byte[uncompSize];
if (!data) {
error("Error allocating buffer for file '%s'", filename.c_str());
- delete [] CompBuffer;
+ delete [] compBuffer;
delete file;
return NULL;
}
- file->seek(DataOffset + prefixSize, SEEK_SET);
- file->read(CompBuffer, CompSize);
+ file->seek(dataOffset + prefixSize, SEEK_SET);
+ file->read(compBuffer, compSize);
- if (Common::uncompress(data, (unsigned long *)&UncompSize, CompBuffer, CompSize) != true) {
+ if (Common::uncompress(data, (unsigned long *)&uncompSize, compBuffer, compSize) != true) {
error("Error uncompressing file '%s'", filename.c_str());
- delete [] CompBuffer;
+ delete [] compBuffer;
delete file;
return NULL;
}
- delete [] CompBuffer;
+ delete [] compBuffer;
- return new Common::MemoryReadStream(data, UncompSize, DisposeAfterUse::YES);
+ return new Common::MemoryReadStream(data, uncompSize, DisposeAfterUse::YES);
delete file;
file = NULL;
} else {